Visible to Intel only — GUID: GUID-AC565E56-7F17-4502-9B74-3EFBEF45B129
Visible to Intel only — GUID: GUID-AC565E56-7F17-4502-9B74-3EFBEF45B129
CALL
Statement: Transfers control to a subroutine subprogram.
CALL sub[( [a-arg[,a-arg]...] )]
sub |
Is the name of the subroutine subprogram or other external procedure, or a dummy argument or procedure pointer associated with a subroutine subprogram or other external procedure. |
a-arg |
Is an actual argument optionally preceded by [keyword=], where keyword is the name of a dummy argument in the explicit interface for the subroutine. The keyword is assigned a value when the procedure is invoked. Each actual argument must be a variable, an expression, the name of a procedure, a procedure pointer, 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 Standard Fortran.) |
Description
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 or a procedure pointer dummy argument must be the specific name of a procedure, an associated procedure pointer, or it must be another dummy procedure. Certain specific intrinsic function names must not be used as actual arguments (see table Specific Functions Not Allowed as Actual Arguments in Intrinsic Procedures). Specific names for intrinsic procedures are an obsolescent feature in the Fortran standard.
The procedure invoked by the CALL statement must be a subroutine subprogram and not a function. Calling a function as if it was a subroutine can cause unpredictable results.
Example
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 shows 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.
The following shows another example:
!Variations on a subroutine call
REAL S,T,X
INTRINSIC NINT
S=1.5
T=2.5
X=14.7
!This calls SUB1 using keywords. NINT is an intrinsic function.
CALL SUB1(B=X,C=S*T,FUNC=NINT,A=4.0)
!Here is the same call using an implicit reference
CALL SUB1(4.0,X,S*T,NINT)
CONTAINS
SUBROUTINE sub1(a,b,c,func)
INTEGER func
REAL a,b,c
PRINT *, a,b,c, func(b)
END SUBROUTINE
END