The CALL statement invokes a subroutine and passes it an arguments list.
SyntaxCALL subroutine-name [( [actual-arg-list] )]
Where:subroutine-name is the name of a subroutine.actual-arg-list is [[keyword =] actual-arg] [, ...]keyword is the name of a dummy argument to subroutine-name.actual-arg is an expression, a variable, a procedure name, or an alternate-return-spec.alternate-return-spec is *labellabel is a statement label.
actual-arg-list defines the correspondence between the actual-args supplied and the dummy arguments of the subroutine.
If keyword= is present, the actual argument is passed to the dummy argument whose name is the same as keyword. If keyword= is absent, the actual argument is passed to the dummy argument in the corresponding position in the dummy argument list.
keyword= must appear with an actual-arg unless no previous keyword= has appeared in the actual-arg-list
keyword= can only appear if the interface of the procedure is explicit in the scoping unit.
An actual-arg can be omitted if the corresponding dummy argument has the OPTIONAL attribute. Each actual-arg must be associated with a corresponding dummy argument.
An actual argument must be of the same kind as the corresponding dummy argument.
If the dummy argument is an assumed-shape array of type default CHARACTER, its length must agree with that of the corresponding actual argument.
The total length of a dummy argument of type default CHARACTER must be less than or equal to that of the corresponding actual argument.
If the dummy argument is a pointer, the actual argument must also be a pointer of the same type, attributes, and rank. At the invocation of the subroutine, the dummy argument pointer receives the pointer association status of the actual argument. At the end of the subroutine, the actual argument receives the pointer association status of the dummy argument.
If the actual argument has the TARGET attribute, any pointers associated with it remain associated with the actual argument. If the dummy argument has the TARGET attribute, any pointers associated with it become undefined when the subroutine completes.
The ranks of dummy arguments and corresponding actual arguments must agree unless the actual argument is an element of an array that is not an assumed-shape or pointer array, or a substring of such an element.
If an actual argument has the INTENT(OUT) attribute, and its value is not set within the subroutine, upon return from the subroutine, its value will be undefined.
If a dummy argument is a dummy procedure, the associated actual argument must be the specific name of an external, module, dummy, or intrinsic procedure.
The intrinsic functions AMAX0, AMAX1, AMIN0, AMIN1, CHAR, DMAX1, DMIN1, FLOAT, ICHAR, IDINT, IFIX, INT, LGE, LGT, LLE, LLT, MAX0, MAX1, MIN0, MIN1, REAL, and SNGL may not be associated with a dummy procedure. The results of these functions may be used as actual arguments.
If a generic intrinsic function name is also a specific name, only the specific procedure is associated with the dummy argument.
If a dummy procedure has an implicit interface either the name of the dummy argument is explicitly typed or the procedure is referenced as a function. The dummy procedure must not be called as a subroutine and the actual argument must be a function or dummy procedure.
If a dummy procedure has an implicit interface and the procedure is called as a subroutine, the actual argument must be a subroutine or a dummy procedure.
If a dummy argument is an asterisk, the corresponding actual argument must be an alternate-return-spec. The label in the alternate-return-spec must identify an executable construct in the scoping unit containing the procedure reference.
Example 1! basic calling syntax real :: x=1.,y=2. call alpha(x,y) end program subroutine alpha(a,b) real :: a,b write(*,*) a,b end subroutine alpha
Example 2! calling with optional arguments interface subroutine alpha(a,b) ! define keywords here real :: a ! use of optional arguments real,optional :: b ! requires an interface end subroutine end interface real :: x=1., y=2. call alpha(x) ! call with no options call alpha(x,y) ! positional call call alpha(b=x, a=y) ! keyword call end program subroutine alpha (a,b) real :: a real,optional :: b if(present(b)) then ! b must not appear unless it write(*,*) a,b ! is inside a construct that else ! tests for its presence write(*,*) a end if end subroutine alpha
Example 3! calling with a procedure argument real,external :: euler call alpha(euler) end program subroutine alpha(f) real,external :: f write(*,*) f() end subroutine alpha real function euler() euler=exp(cmplx(0.,atan2(0.,-1.))) end function euler
Example 4! calling with the intent attribute real :: x=1.,y=2. call alpha(x,y) write(*,*) x,y end program subroutine alpha(a,b) real,intent(in) :: a ! a cannot be changed inside alpha real,intent(out) :: b ! b must be initialized before b=a ! the dummy argument or actual end subroutine alpha ! argument is referenced