CALL statement in Fortran - Fortran

The CALL statement references a subroutine subprogram in a calling program unit.

CALL sub[( [a[,a]...] )]

sub is the symbolic name of the subroutine.
a is an actual argument, an expression, array name, array elements, record elements, record arrays, record array elements, Hollerith constants, or an alternate return specifier of the form *s, where s is a statement label, or &s, where s is a statement label.

Method of Operation
A CALL statement evaluates the actual arguments, association of the actual arguments with the corresponding dummy arguments, and execution of the statements in the subroutine. Return of control from the referenced subroutine completes the execution of the CALL statement.

Rules for Use

  • The actual arguments a form an argument list and must agree in order, number, and type with the corresponding dummy arguments in the referenced subroutine.
  • A subroutine that has been defined without an argument can be referenced by a CALL statement of the following forms:
  • CALL sub
    CALL sub()

  • If a dummy procedure name is specified as a dummy argument in the referenced subroutine, then the actual argument must be an external procedure name, a dummy procedure name, or one of the allowed specific intrinsic names. An intrinsic name or an external procedure name used as an actual argument must appear in an INTRINSIC or EXTERNAL statement, respectively.
  • If an asterisk is specified as a dummy argument, an alternate return specifier must be supplied in the corresponding position in the argument list of the CALL statement.
  • If a Hollerith constant is used as an actual argument in a CALL statement, the corresponding dummy argument must not be a dummyarray and must be of arithmetic or logical data type. This rule is anexception to the first rule above.
  • A subroutine can call itself directly or indirectly (recursion).

Note: Recursion is an extension to Fortran 77. Fortran 77 does not allow a subroutine to reference itself.

In the following example, the main routine calls PAGEREAD, passing the parameters LWORDCOUNT, PAGE, and NSWITCH. After execution of PAGEREAD, control returns to the main program, which stops.

program MakeIndex
character*50 page
dimension page (100)
nswitch = 0
111 lwordcount = inwords1*2
call pageread (lwordcount,page,nswitch)
subroutine pageread (lwordcount,page,nswitch)
character*50 page
dimension page (100)
icount = 100

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Fortran Topics