HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Internal procedures
Chapter 7 167
Internal procedures
An internal procedure is similar to an external procedure except that:
It must be defined within a hosting program unit—a main, external, or module program
unit—following the CONTAINS statement.
It can be referenced by the host only.
It can access other entities by host association within the host.
It cannot have an ENTRY statement.
It cannot be passed as an argument.
It cannot contain an internal procedure.
The syntax of an internal procedure definition is the same as for an external procedure (see
“Procedure definition” on page 161), except that it has no internal procedure part. The
reference to an internal procedure is the same as for an external procedure; see “Procedure
reference” on page 162.
The following example, int_func.f90, declares and references an internal function. Note that
both the external procedure and the internal procedure have an assumed-shape array as a
dummy argument, which requires the procedure to have an explicit interface (see “Procedure
interface” on page 181). External procedures must be declared in an interface block to make
their interface explicit; the interface of internal procedures is explicit by default.
Example 7-2 int_func.f90
PROGRAM main
! declare and initialize an array to pass to an external
! procedure
REAL, DIMENSION(3) :: values = (/2.0, 5.0, 7.0/)
! Because the dummy argument to print_avg is an assumed-shape
! array (see the definition of print_avg below), the
! procedure interface of print_avg must
! be made explicit within the calling program unit.
INTERFACE
SUBROUTINE print_avg(x)
REAL :: x(:)
END SUBROUTINE print_avg
END INTERFACE
CALL print_avg(values)