The CALL statement transfers control to a subroutine subprogram. It takes the following form:
Each actual argument must be a variable, an expression, the name of a procedure, or an alternate return specifier. (It must not be the name of an internal procedure, statement function, or the generic name of a procedure.)
An alternate return specifier is an asterisk (*), or ampersand (&) followed by the label of an executable branch target statement in the same scoping unit as the CALL statement. (An alternate return is an obsolescent feature in Fortran 95 and Fortran 90.)
When the CALL statement is executed, any expressions in the actual argument list are evaluated, then control is passed to the first executable statement or construct in the subroutine. When the subroutine finishes executing, control returns to the next executable statement following the CALL statement, or to a statement identified by an alternate return label (if any).
If an argument list appears, each actual argument is associated with the corresponding dummy argument by its position in the argument list or by the name of its keyword. The arguments must agree in type and kind parameters.
If positional arguments and argument keywords are specified, the argument keywords must appear last in the actual argument list.
If a dummy argument is optional, the actual argument can be omitted.
An actual argument associated with a dummy procedure must be the specific name of a procedure, or be another dummy procedure. Certain specific intrinsic function names must not be used as actual arguments (see Table 9-1).
You can use a CALL statement to invoke a function as long as the function is not one of the following types:
The following example shows valid CALL statements:
CALL CURVE(BASE,3.14159+X,Y,LIMIT,R(LT+2))
CALL PNTOUT(A,N,'ABCD')
CALL EXIT
CALL MULT(A,B,*10,*20,C) ! The asterisks and ampersands denote
CALL SUBA(X,&30,&50,Y) ! alternate returns
The following example shows a subroutine with argument keywords:
PROGRAM KEYWORD_EXAMPLE
INTERFACE
SUBROUTINE TEST_C(I, L, J, KYWD2, D, F, KYWD1)
INTEGER I, L(20), J, KYWD1
REAL, OPTIONAL :: D, F
COMPLEX KYWD2
...
END SUBROUTINE TEST_C
END INTERFACE
INTEGER I, J, K
INTEGER L(20)
COMPLEX Z1
CALL TEST_C(I, L, J, KYWD1 = K, KYWD2 = Z1)
...
The first three actual arguments are associated with their corresponding dummy arguments by position. The argument keywords are associated by keyword name, so they can appear in any order.
Note that the interface to subroutine TEST has two optional arguments that have been omitted in the CALL statement.
The following is another example of a subroutine call with argument keywords:
CALL TEST(X, Y, N, EQUALITIES = Q, XSTART = X0)
The first three arguments are associated by position.
For More Information: