# 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 line takes the following form:

INCLUDE 'filename[/[NO]LIST]'

filename | 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. You can only use /[NO]LIST if you specify compiler option vms (which sets OpenVMS defaults).

## Description

An INCLUDE line can appear anywhere within a scoping unit. The line 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 Statements.

Included files or text modules can contain additional INCLUDE lines, but they must not be recursive. INCLUDE lines 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 line.

You can use modules instead of include files to achieve encapsulation of related data types and procedures. For example, one module can contain derived type definitions as well as special operators and procedures that apply to those types. For information on how to use modules, see Program Units and Procedures.

## Example

In the following example, a file named COMMON.FOR (in the current working directory) is included and read as input.

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.

The following example program declares its common data in an include file. The contents of the file INCLUDE.INC are inserted in the source code in place of every INCLUDE 'INCLUDE.INC' line. This guarantees that all references to common storage variables are consistent.

    INTEGER i
    REAL x
    INCLUDE 'INCLUDE.INC'

    DO i = 1, 5
      READ (*, '(F10.5)') x
      CALL Push (x)
    END DO

Parent topic: H to I

## See Also

MODULE
USE