The CALL statement branches to the specified subroutine, executes the subroutine, and returns to the calling program after finishing the subroutine.
Name of the subroutine to be called
Actual argument to be passed to the subroutine
Arguments are separated by commas.
The FORTRAN 77 Standard requires that actual arguments in a CALL statement must agree in order, number, and type with the corresponding formal arguments of the referenced subroutine. The compiler checks this only when the -XlistE option is on.
Recursion is allowed. A subprogram can call itself directly, or indirectly by calling another subprogram that in turns calls this subroutine. Such recursion is nonstandard. @
An actual argument, ar, must be one of the following:
An intrinsic function permitted to be passed as an argument; for a list of the intrinsics that cannot be actual arguments, see Table 4-2.
An external function name
A subroutine name
An alternate return specifier, * or &,followed by a statement number. The & is nonstandard. @
The simplest expressions, and most frequently used, include such constructs as:
Formal argument, if the CALL statement is inside a subroutine
If a subroutine has no arguments, then a CALL statement that references that subroutine must not have any actual arguments. A pair of empty matching parentheses can follow the subroutine name.
Execution of the CALL statement proceeds as follows:
All expressions (arguments) are evaluated.
All actual arguments are associated with the corresponding formal arguments, and the body of the subroutine is executed.
Normally, the control is transferred back to the statement following the CALL statement upon executing a RETURN statement or an END statement in the subroutine. If an alternate return in the form of RETURN n is executed, then control is transferred to the statement specified by the n alternate return specifier in the CALL statement.
A CALL to a subprogram defined as a FUNCTION rather than as a SUBROUTINE will cause unexpected results and is not recommended. The compiler does not automatically detect such inappropriate CALLs and no warning is issued unless the -Xlist option is specified.
CHARACTER *25 TEXT TEXT = 'Some kind of text string' CALL OOPS ( TEXT ) END SUBROUTINE OOPS ( S ) CHARACTER S*(*) WRITE (*,*) S END
CALL RANK ( N, *8, *9 ) WRITE (*,*) 'OK - Normal Return' STOP 8 WRITE (*,*) 'Minor - 1st alternate return' STOP 9 WRITE (*,*) 'Major - 2nd alternate return' STOP END SUBROUTINE RANK ( N, *, * ) IF ( N .EQ. 0 ) RETURN IF ( N .EQ. 1 ) RETURN 1 RETURN 2 END
CALL RANK ( N, &8, &9 )
REAL M(100,100), Q(2,2), Y CALL SBRX ( M, Q(1,2), Y ) ... END SUBROUTINE SBRX ( A, D, E ) REAL A(100,100), D, E ... RETURN END
In this example, the real array M matches the real array, A, and the real array element Q(1,2) matches the real variable, D.
STRUCTURE /PRODUCT/ INTEGER*4 ID CHARACTER*16 NAME CHARACTER*8 MODEL REAL*4 COST REAL*4 PRICE END STRUCTURE RECORD /PRODUCT/ CURRENT, PRIOR CALL SBRX ( CURRENT, PRIOR.ID ) ... END SUBROUTINE SBRX ( NEW, K ) STRUCTURE /PRODUCT/ INTEGER*4 ID CHARACTER*16 NAME CHARACTER*8 MODEL REAL*4 COST REAL*4 PRICE END STRUCTURE RECORD /PRODUCT/ NEW ... RETURN END
In the above example, the record NEW matches the record CURRENT, and the integer variable, K, matches the record field, PRIOR.OLD.