24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12 Functions and Subroutines<br />

12.1 Introduction<br />

Functions and subroutines are procedures that fall into one of the following categories.<br />

1. Statement functions<br />

2. Intrinsic functions<br />

3. External functions<br />

4. Subroutines<br />

First let us introduce some terminology.<br />

A program unit is a collection of <strong>Open</strong> <strong>Watcom</strong> <strong>FORTRAN</strong> <strong>77</strong> statements and comments that can be either<br />

a main program or a subprogram.<br />

A main program identifies the program unit where execution is to begin. A main program is a program<br />

unit which has as its first statement a PROGRAM statement or one which does not have a PROGRAM,<br />

FUNCTION, SUBROUTINE or BLOCK DATA statement as its first statement. Complete execution of the<br />

main program implies the complete execution of the program. Each executable program can contain only<br />

one main program.<br />

A subprogram is a program unit that either has a FUNCTION, SUBROUTINE or BLOCK DATA statement<br />

as its first statement. This chapter will only deal with subprograms that have a FUNCTION or<br />

SUBROUTINE statement as its first statement.<br />

12.2 Statement Functions<br />

A statement function is a procedure defined by a single statement. Its definition must follow all<br />

specification statements and precede the first executable statement. The statement defining a statement<br />

function is not an executable statement.<br />

A statement function has the following form.<br />

<br />

sf ( [d [,d] ...] ) = e<br />

where:<br />

sf<br />

d<br />

is the name of the statement function.<br />

is a statement function dummy argument.<br />

Statement Functions 243

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!