FORTRAN 77 Language Reference

CALL

The CALL statement branches to the specified subroutine, executes the subroutine, and returns to the calling program after finishing the subroutine.

CALL sub [([ar[, ar]])]

Parameter 

Description 

sub

Name of the subroutine to be called  

ar

Actual argument to be passed to the subroutine 

Description

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:

The simplest expressions, and most frequently used, include such constructs as:

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:

  1. All expressions (arguments) are evaluated.

  2. All actual arguments are associated with the corresponding formal arguments, and the body of the subroutine is executed.

  3. 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.


    Note -

    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.


Examples

Example 1: Character string:


       CHARACTER *25 TEXT 
       TEXT = 'Some kind of text string' 
       CALL OOPS ( TEXT )
       END
       SUBROUTINE OOPS ( S )
              CHARACTER S*(*) 
              WRITE (*,*) S 
       END

Example 2: Alternate return:


       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 

Example 3: Another form of alternate return; the & is nonstandard:


       CALL RANK ( N, &8, &9 )

@

Example 4: Array, array element, and variable:


       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.

Example 5: A structured record and field; the record is nonstandard: @


       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.