Procedure arguments provide a way for different program units to access the same data.
When a procedure is referenced in an executable program, the program unit invoking the procedure can use one or more actual arguments to pass values to the procedure's dummy arguments. The dummy arguments are associated with their corresponding actual arguments when control passes to the subprogram.
In general, when control is returned to the calling program unit, the last value assigned to a dummy argument is assigned to the corresponding actual argument.
An actual argument can be a variable, expression, or procedure name. The type and kind parameters, and rank of the actual argument must match those of its associated dummy argument.
A dummy argument is either a dummy data object, a dummy procedure, or an alternate return specifier (*). Except for alternate return specifiers, dummy arguments can be optional.
If argument keywords are not used, argument association is positional. The first dummy argument becomes associated with the first actual argument, and so on. If argument keywords are used, arguments are associated by the keyword name, so actual arguments can be in a different order than dummy arguments.
A keyword is required for an argument only if a preceding optional argument is omitted or if the argument sequence is changed.
A scalar dummy argument can be associated with only a scalar actual argument.
If a dummy argument is an array, it must be no larger than the array that is the actual argument. You can use adjustable arrays to process arrays of different sizes in a single subprogram.
A dummy argument referenced as a subprogram must be associated with an actual argument that has been declared EXTERNAL or INTRINSIC in the calling routine.
If a scalar dummy argument is of type character, its length must not be greater than the length of its associated actual argument.
If the character dummy argument's length is specified as *(*) (assumed length), it uses the length of the associated actual argument.
Once an actual argument has been associated with a dummy argument, no action can be taken that affects the value or availability of the actual argument, except indirectly through the dummy argument. For example, if the following statement is specified:
CALL SUB_A (B(2:6), B(4:10))
B(4:6) must not be defined, redefined, or become undefined through either dummy argument, since it is associated with both arguments. However, B(2:3) is definable through the first argument, and B(7:10) is definable through the second argument.
Similarly, if any part of the actual argument is defined through a dummy argument, the actual argument can only be referenced through that dummy argument during execution of the procedure. For example, if the following statements are specified:
MODULE MOD_A REAL :: A, B, C, D END MODULE MOD_A PROGRAM TEST USE MOD_A CALL SUB_1 (B) ... END PROGRAM TEST SUBROUTINE SUB_1 (F) USE MOD_A ... WRITE (*,*) F END SUBROUTINE SUB_1
Variable B must not be directly referenced during the execution of SUB_1 because it is being defined through dummy argument F. However, B can be indirectly referenced through F (and directly referenced when SUB_1 completes execution).
The following sections provide more details on arguments:
For More Information: