 |
» |
|
|
 |
Invokes a subroutine. SyntaxCALL subr-name[([ subr-act-arg-spec-list ])] - subr-name
is the name of the subroutine being invoked. - subr-act-arg-spec-list
is a comma-separated list of subr-act-arg-spec. - subr-act-arg-spec
is [keyword
=]subr-act-arg. - subr-act-arg
is one of the following: - keyword
is
one of the dummy argument names of the subroutine being invoked.
If any keyword is specified, the subroutine
interface must be explicit.
DescriptionA
CALL statement
is used to invoke (call) a subroutine, and to specify actual arguments,
if any. Execution of the subroutine begins with the first executable
statement. The sequence of events when a CALL
statement is executed is as follows: Actual arguments that are expressions are evaluated. The actual arguments are associated with the corresponding
dummy arguments. Control transfers to the subroutine being called,
and the subroutine executes. Control returns from the subroutine, normally to
the statement following the CALL
statement, or to a statement label indicated by an alternate return
specifier argument (of the form * label).
The correspondence between actual and dummy arguments is primarily
by position: the first actual argument corresponds to the first
dummy argument, the second to the second, and so on. The positional
correspondence may be overridden by
argument keywords, where a keyword name attached to an actual argument
specifies a correspondence to the dummy argument of the same name.
The following conditions govern the use of argument keywords: If an argument keyword is used, all
subsequent arguments in the CALL
statement must also be accompanied by keywords. If an
optional argument is omitted, the keyword form is required for any
following arguments. If an argument keyword is used, the
procedure interface must be explicit; that is, the procedure must
be an intrinsic procedure, an internal procedure, a module procedure,
or an external procedure with an interface block accessible to the
program unit making the call.
A subroutine can call itself, directly or indirectly; in this
case the keyword RECURSIVE
must be added to the SUBROUTINE
statement of the subroutine definition. The
%VAL and %REF
built-in functions are provided as HP extensions. These allow cross-calling
between languages by enabling arguments to be passed by value and
by reference, respectively. %VAL
causes its argument to be passed by value, as if to a C function;
it is sign-extended to a 32-bit value if it is less than 32 bits.
%REF causes its
argument to be passed by reference, similar to the default Fortran
90 behavior, except that the hidden length parameter of a CHARACTER
string is not passed. The only subroutine invocation other than by the CALL
statement in Fortran 90 is through "defined assignment",
where a defined type assignment operator that has been defined by
means of a subroutine is used. See the INTERFACE
statement in this chapter for more information. Examples! Interface for subroutine draw |
SUBROUTINE draw (x_start, y_start, x_end, & |
REAL x_start, y_start, x_end, y_end |
CHARACTER (LEN = 6), OPTIONAL :: form |
CALL draw (5., -4., 2., .6, "DASHED") |
! Arguments given by position. |
! Optional argument scale omitted. |
CALL draw (scale=.4, x_end=0., y_end=0., & |
! Arguments given by keyword. |
! Optional argument form omitted. |
Related statementsINTERFACE
and SUBROUTINE Related conceptsThe correspondence between the dummy arguments of a subroutine
and the actual arguments specified in its invocation ("Argument
association") is discussed in detail in Chapter 7, as are
the other methods of association between a program unit and a subroutine
called by it.
|