# 8.7 Internal Procedures

Internal procedures are functions or subroutines that follow a CONTAINS statement in a program unit. The program unit in which the internal procedure appears is called its host.

Internal procedures can appear in the main program, in an external subprogram, or in a module subprogram.

An internal procedure takes the following form:

  CONTAINS
  internal-subprogram
  [internal-subprogram]...
  internal-subprogram
  Is a function or subroutine subprogram that defines the procedure. An internal subprogram must not contain any other internal subprograms.

Rules and Behavior

Internal procedures are the same as external procedures, except for the following:

- Only the host program unit can use an internal procedure.
- An internal procedure has access to host entities by host association; that is, names declared in the host program unit are useable within the internal procedure.
- In Fortran 95/90, the name of an internal procedure must not be passed as an argument to another procedure. However, Compaq Fortran allows an internal procedure name to be passed as an actual argument to another procedure.
- An internal procedure must not contain an ENTRY statement.

An internal procedure can reference itself (directly or indirectly); it can be referenced in the execution part of its host and in the execution part of any internal procedure contained in the same host (including itself).

The interface of an internal procedure is always explicit.

Every HPF internal subprogram must be of the same extrinsic kind as its host, and any internal subprogram whose extrinsic kind is not given explicitly is assumed to be of that extrinsic kind.

Examples

The following example shows an internal procedure:

    PROGRAM COLOR_GUIDE
    ...
    CONTAINS
      FUNCTION HUE(BLUE)   ! An internal procedure
      ...
      END FUNCTION HUE
    END PROGRAM

For More Information:

- On function and subroutine subprograms, see Section 8.5.
- On host association, see Section 16.4.1.2.
- On procedure interfaces, see Section 8.9.

Previous Page Next Page Table of Contents