The interface block provides a means of specifying an explicit interface for external procedures and dummy procedures. You can also use an interface block to define generic identifiers. An interface body in an interface block specifies the explicit specific interface for an existing external procedure or dummy procedure.
>>-INTERFACE_statement----------------------------------------->< .--------------------------------. V | >>---+----------------------------+-+-------------------------->< +-FUNCTION_interface_body----+ +-SUBROUTINE_interface_body--+ '-MODULE_PROCEDURE_statement-' >>-END_INTERFACE_statement------------------------------------->< |
FUNCTION_interface_body
>>-FUNCTION_statement------------------------------------------>< >>-+--------------------+-------------------------------------->< '-specification_part-' >>-end_function_statement-------------------------------------->< |
SUBROUTINE_interface_body
>>-SUBROUTINE_statement---------------------------------------->< >>-+--------------------+-------------------------------------->< '-specification_part-' >>-end_subroutine_statement------------------------------------>< |
In an interface body, you specify all the characteristics of the procedure. See Interface Concepts. The characteristics must be consistent with those specified in the subprogram definition, except that:
The specification_part of an interface body can contain statements that specify attributes or define values for data objects that do not determine characteristics of the procedure. Such specification statements have no effect on the interface. Interface blocks do not specify the characteristics of module procedures, whose characteristics are defined in the module subprogram definitions.
An interface body cannot contain ENTRY statements, DATA statements, FORMAT statements, statement function statements, or executable statements. You can specify an entry interface by using the entry name as the procedure name in an interface body.
An interface body does not access named entities by host association. It is treated as if it had a host with the default implicit rules. See How Type Is Determined for a discussion of the implicit rules.
An interface block can be generic or nongeneric. A generic interface block must specify a generic specification in the INTERFACE statement, while a nongeneric interface block must not specify such a generic specification. See INTERFACE for details.
The interface bodies within a nongeneric interface block can contain interfaces for both subroutines and functions.
A generic name specifies a single name to reference all of the procedures in the interface block. At most, one specific procedure is invoked each time there is a procedure reference with a generic name.
The MODULE PROCEDURE statement is allowed only if the interface block has a generic specification and is contained in a scoping unit where each procedure name is accessible as a module procedure.
A procedure name used in a MODULE PROCEDURE statement must not have been previously specified in any module procedure statement with the same generic identifier in the same specification part.
+-------------------------------IBM Extension--------------------------------+
For an interface to a non-Fortran subprogram, the dummy argument list in the FUNCTION or SUBROUTINE statement can explicitly specify the passing method. See Dummy Arguments for details.
+----------------------------End of IBM Extension----------------------------+
MODULE M CONTAINS SUBROUTINE S1(IARG) IARG = 1 END SUBROUTINE S1 SUBROUTINE S2(RARG) RARG = 1.1 END SUBROUTINE S2 SUBROUTINE S3(LARG) LOGICAL LARG LARG = .TRUE. END SUBROUTINE S3 END
USE M INTERFACE SS SUBROUTINE SS1(IARG,JARG) END SUBROUTINE MODULE PROCEDURE S1,S2,S3 END INTERFACE CALL SS(II) ! Calls subroutine S1 from M CALL SS(I,J) ! Calls subroutine SS1 END
SUBROUTINE SS1(IARG,JARG) IARG = 2 JARG = 3 END SUBROUTINE
You can always reference a procedure through its specific interface. If a generic interface exists for a procedure, the procedure can also be referenced through the generic interface.
Within an interface body, if a dummy argument is intended to be a dummy procedure, it must have the EXTERNAL attribute or there must be an interface for the dummy argument.