A statement function statement is a function-like declaration, made in a single statement.
Name of statement function being defined
Statement function dummy argument
Expression. e can be any of the types arithmetic, logical, or character.
If a statement function is referenced, the defined calculations are inserted.
ROOT( A, B, C ) = (-B + SQRT(B**2-4.0*A*C))/(2.0*A)
The statement function argument list indicates the order, number, and type of arguments for the statement function.
A statement function is referenced by using its name, along with its arguments, as an operand in an expression.
Execution proceeds as follows:
If they are expressions, actual arguments are evaluated.
Actual arguments are associated with corresponding dummy arguments.
The expression e, the body of a statement function, is evaluated.
If the type of the above result is different from the type of the function name, then the result is converted.
Return the value.
The resulting value is thus available to the expression that referenced the function.
Note these restrictions:
A statement function must appear only after the specification statements and before the first executable statement of the program unit in which it is referenced.
A statement function is not executed at the point where it is specified. It is executed, as any other, by the execution of a function reference in an expression.
The type conformance between fun and e are the same as those for the assignment statement. The type of fun and e can be different, in which case e is converted to the type of fun.
The actual arguments must agree in order, number, and type with corresponding dummy arguments.
If a dummy argument is defined as a structure, the corresponding actual argument must be similarly defined as the same structure.
A dummy argument cannot be an array or function name, or have the same name as the function.
The same argument cannot be specified more than once in the argument list.
The statement function may be referenced only in the program unit that contains it.
The name of a statement function cannot be an actual argument. Nor can it appear in an EXTERNAL statement.
The type of the argument is determined as if the statement function were a whole program unit in itself.
Even if the name of a statement function argument is the same as that of another local variable, the reference is considered a dummy argument of the statement function, not the local variable of the same name.
The length specification of a character statement function or its dummy argument of type CHARACTER must be an integer constant expression.
A statement function cannot be invoked recursively.
PARAMETER ( PI=3.14159 ) REAL RADIUS, VOLUME SPHERE ( R ) = 4.0 * PI * (R**3) / 3.0 READ *, RADIUS VOLUME = SPHERE( RADIUS ) ...
LOGICAL OKFILE INTEGER STATUS OKFILE ( I ) = I .LT. 1 READ( *, *, IOSTAT=STATUS ) X, Y IF ( OK FILE(STATUS) ) CALL CALC ( X, Y, A ) ...
CHARACTER FIRST*1, STR*16, S*1 FIRST(S) = S(1:1) READ( *, * ) STR IF ( FIRST(STR) .LT. " " ) CALL CONTROL ( S, A ) ...