CONTAINS
Purpose
The CONTAINS statement separates the body of a main program, external subprogram, or module subprogram from any internal subprograms that it may contain. Similarly, it separates the specification part of a module or submodule from any module subprograms.
The CONTAINS statement also introduces the procedure part of a derived-type definition.
Rules
For a CONTAINS statement
associated with subprograms, the following rules apply:
- The CONTAINS statement cannot appear in a block data program unit or in an internal subprogram.
- Any label of a CONTAINS statement is considered as part of the main program, subprogram, module, or submodule that contains the CONTAINS statement.
Examples
An example of a CONTAINS statement
MODULE A
...
CONTAINS ! Module subprogram must follow
SUBROUTINE B(X)
...
CONTAINS ! Internal subprogram must follow
FUNCTION C(Y)
...
END FUNCTION
END SUBROUTINE
END MODULE
An example of a CONTAINS statement in a derived type definition
TYPE CUST
INTEGER :: CUST_NUMBER
CONTAINS
PROCEDURE, PASS :: GET_CUST => GET_CUST_NUMBER
END TYPE CUST