## 14.1 INCLUDE Statement

The INCLUDE statement directs the compiler to stop reading statements from the current file and read statements in an included file or text module.

The INCLUDE statement takes one of the following forms:

  INCLUDE 'file-name [/[NO]LIST]'
  INCLUDE '[text-lib] (module-name) [/[NO]LIST]' (VMS only)
  file-name
  Is a character string specifying the name of the file to be included; it must not be a named constant.

  The form of the file name must be acceptable to the operating system, as described in your system documentation.

  /[NO]LIST
  Specifies whether the incorporated code is to appear in the compilation source listing. In the listing, a number precedes each incorporated statement. The number indicates the "include" nesting depth of the code. The default is /NOLIST. /LIST and /NOLIST must be spelled completely.

  On Tru64 UNIX, Linux, WNT, and W9* systems, you can only use /[NO]LIST if you specify the compiler option that sets OpenVMS defaults.

  text-lib (VMS only)
  Is a character string specifying the file name of the text library to be searched.

  The form of the file name must be acceptable to the operating system, as described in your system documentation.

  module-name (VMS only)
  Is a character string specifying the name of the text library module to be included. The name of the text module must be enclosed in parentheses. It can be up to 31 characters long and can contain any alphanumeric character and the special characters dollar sign ($) and underscore ( _ ).

Rules and Behavior

An INCLUDE statement can appear anywhere within a scoping unit. The statement can span more than one source line, but no other statement can appear on the same line. The source line cannot be labeled.

An included file or text module cannot begin with a continuation line, and each Fortran statement must be completely contained within a single file.

An included file or text module can contain any source text, but it cannot begin or end with an incomplete Fortran statement.

The included statements, when combined with the other statements in the compilation, must satisfy the statement-ordering restrictions shown in Figure 2-1.

Included files or text modules can contain additional INCLUDE statements, but they must not be recursive. INCLUDE statements can be nested until system resources are exhausted.

When the included file or text module completes execution, compilation resumes with the statement following the INCLUDE statement.

Examples

In Example 14-1, a file named COMMON.FOR (in the current working directory) is included and read as input.

Example 14-1 Including Text from a File

    Main Program File                COMMON.FOR File

    PROGRAM
      INCLUDE 'COMMON.FOR'           INTEGER, PARAMETER :: M=100
      REAL, DIMENSION(M) :: Z        REAL, DIMENSION(M) :: X, Y
      CALL CUBE                      COMMON X, Y
      DO I = 1, M
        Z(I) = X(I) + SQRT(Y(I))
        ...
      END DO
    END

    SUBROUTINE CUBE
      INCLUDE 'COMMON.FOR'
      DO I=1,M
        X(I) = Y(I)**3
      END DO
      RETURN
    END

The file COMMON.FOR defines a named constant M, and defines arrays X and Y as part of blank common.

For More Information:

- On compiler options, see your user manual or programmer's guide.
- On using text libraries, see your user manual.

Previous Page Next Page Table of Contents