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:
Syntax
On Windows, Tru64 UNIX, and Linux systems, you can only use /[NO]LIST if you specify the /vms compiler option (which sets OpenVMS defaults).
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 Statements.
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.
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.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
Examples
In the following example, a file named COMMON.FOR (in the current working directory) is included and read as input.
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' statement. 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