FORTRAN 77 Language Reference

Examples

Example 1: Character function:


       CHARACTER*5 FUNCTION BOOL(ARG) 
       BOOL = 'TRUE' 
       IF (ARG .LE. 0) BOOL = 'FALSE' 
       RETURN 
       END 

In the above example, BOOL is defined as a function of type CHARACTER with a length of 5 characters. This function when called returns the string, TRUE or FALSE, depending on the value of the variable, ARG.

Example 2: Real function:


       FUNCTION SQR (A) 
       SQR = A*A 
       RETURN 
       END 

In the above example, the function SQR is defined as function of type REAL by default, and returns the square of the number passed to it.

Example 3: Size of function, alternate syntax: @


       INTEGER FUNCTION FCN*2 ( A, B, C ) 

The above nonstandard form is treated as:


       INTEGER*2 FUNCTION FCN ( A, B, C )