HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
CONTAINS
Chapter 10308
CONTAINS
Introduces an internal procedure or a module procedure.
Syntax
CONTAINS
Description
The CONTAINS statement introduces an internal procedure or a module procedure, separating
it from the program unit that contains it. The statement can be used in:
A main program, external subprogram, or module subprogram; in each case, it precedes
one or more internal procedures.
A module, where it precedes any module procedures.
When a CONTAINS statement is present, at least one subprogram must follow it.
Examples
The first example illustrates CONTAINS introducing an internal subroutine. It also illustrates
how the internal subroutine mechanism can provide an alternative to the FORTRAN 77
statement function mechanism.
PRINT *, double_real(6.6)
CONTAINS
FUNCTION double_real (x); REAL x
double_real = 2.0 * x
END FUNCTION
END
The next example illustrates a main program with an internal procedure part.
PROGRAM electric ! Program header
REAL current ! Specification part
current = 100.5 ! Execution part begins
CALL compute_resistance( voltage, current, resistance )
CONTAINS ! Internal procedure part
SUBROUTINE compute_resistance( v, i, r )
REAL i
r = v / i
END SUBROUTINE
END PROGRAM electric