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.

<strong>Language</strong> <strong>Reference</strong><br />

Example:<br />

INTEGER MARKS(40), N<br />

REAL AVG, STDDEV, MEAN<br />

PRINT *, ’Enter number of marks’<br />

READ( 5, * ) N<br />

PRINT *, ’Enter marks’<br />

READ( 5, * ) (MARKS(I), I = 1, N)<br />

AVG = MEAN( MARKS, N, STDDEV )<br />

PRINT *, ’Mean = ’, AVG,<br />

$ ’ Standard Deviation = ’, STDDEV<br />

END<br />

*<br />

* Define function MEAN to return the average by<br />

* defining the function name and return the standard<br />

* deviation by defining a dummy argument.<br />

*<br />

REAL FUNCTION MEAN( A, N, STDDEV )<br />

INTEGER A, N, I<br />

REAL STDDEV<br />

DIMENSION A(N)<br />

MEAN = 0<br />

DO 10 I = 1, N<br />

MEAN = MEAN + A(I)<br />

10 CONTINUE<br />

MEAN = MEAN / N<br />

STDDEV = 0<br />

DO 20 I = 1, N<br />

STDDEV = STDDEV + ( A(I) - MEAN )**2<br />

20 CONTINUE<br />

STDDEV = SQRT( STDDEV / (N - 1) )<br />

END<br />

12.4.1 Referencing an External Function<br />

When an external function is referenced in an expression or a CALL statement, the following steps are<br />

performed.<br />

1. The actual arguments are evaluated.<br />

2. The actual arguments are associated with the corresponding dummy arguments.<br />

3. The external function is executed.<br />

The type of the external function reference must be the same as the type of the function name in the<br />

external function subprogram. If the external function is of type CHARACTER, the length must also<br />

match.<br />

12.4.2 Actual Arguments for an External Function<br />

An actual argument must be one of the following.<br />

272 External Functions<br />

1. Any expression except a character expression involving the concatenation of an operand whose<br />

length specification is (*) unless the operand is a symbolic constant.<br />

2. An array name.<br />

3. An intrinsic function name (must be the specific name) that has appeared in an INTRINSIC<br />

statement.

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

Saved successfully!

Ooh no, something went wrong!