## 1.6.2 INCLUDE Statement

The INCLUDE statement directs the compiler to stop reading statements from the current file and read the statements in the included file or module. When it reaches the end of the included file or module, the compiler resumes compilation with the next statement after the INCLUDE statement.

The INCLUDE statement takes one of the following forms:

    INCLUDE 'full-file-name [/[NO]LIST]'

    INCLUDE '[text-lib] (module-name) [/[NO]LIST]' (VMS only)

full-file-name
  Is a character string that specifies the file to be included. The form of the file name must be acceptable to the operating system, as shown in Table 1 and described in your user manual.
/[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 systems, you must specify the compiler option VMS to use /[NO]LIST.
text-lib (VMS only)
  Is a character string specifying the full-file-name of the text library to be searched. Its form must be acceptable to the operating system, as described in your user manual.
module-name (VMS only)
  Is the name of the text module, located in a text library, that is to be included. The name of the 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

The following rules apply to the INCLUDE statement and included files:

- An included file or module cannot begin with a continuation line. Each Fortran statement must be completely contained within a single file or module.

- An included file or module can contain an INCLUDE statement.

- The INCLUDE statement can appear anywhere within a program unit.

- Any Fortran statement can appear in an included file or module. However, the included statements, when combined with the other statements in the compilation, must satisfy the statement-ordering restrictions shown in Figure 1-1.

- The limits on nesting depth are as follows:

  - On VAX processors, the limit is 10.

  - On Alpha processors, the limit is when system resources are exhausted.

In Example 1-1, the file COMMON.FOR defines a parameter constant M, and defines arrays X and Y as part of the blank common block.

### Example 1-1 Using INCLUDE Within a Program

    Main Program File                      COMMON.FOR File

        INCLUDE 'COMMON.FOR'               PARAMETER (M=100)

        DIMENSION Z(M)                     COMMON X(M),Y(M)

        CALL CUBE

        DO 5, I=1,M

     5  Z(I) = X(I)+SQRT(Y(I))

         . . .

        END

        SUBROUTINE CUBE

        INCLUDE 'COMMON.FOR'

        DO 10, I=1,M

    10  X(I) = Y(I)**3

        RETURN

        END

For More Information:

For details on using text libraries, see your user manual.

Previous Page Next Page Table of Contents