INCLUDE

Purpose

The INCLUDE compiler directive inserts a specified statement or a group of statements into a program unit.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-INCLUDE--+-char_literal_constant-+--+---+-------------------><
            '-(--name--)------------'  '-n-'   

name, char_literal_constant (delimiters are optional)
specifies filename, the name of an include file

You are not required to specify the full path of the wanted file, but must specify the file suffix if one exists.

name must contain only characters allowable in the XL Fortran character set. See Characters for the character set supported by XL Fortran.

char_literal_constant is a character literal constant.

n
is the value the compiler uses to decide whether to include the file during compilation. It can be any number from 1 through 255, and cannot specify a kind type parameter. If you specify n, the compiler includes the file only if the number appears as a suboption in the -qci (conditional include) compiler option. If you do not specify n, the compiler always includes the file.

Conditional include allows you to selectively activate INCLUDE directives within Fortran source during compilation. Specify the files to include using the -qci compiler option.

In fixed source form, the INCLUDE compiler directive must start after column 6, and can have a label.

You can add an inline comment to the INCLUDE line.

Rules

An included file can contain any complete Fortran source statements and compiler directives, including other INCLUDE compiler directives. Recursive INCLUDE compiler directives are not allowed. An END statement can be part of the included group. The first and last included lines must not be continuation lines. The statements in the include file are processed with the source form of the including file.

If the SOURCEFORM directive appears in an include file, the source form reverts to that of the including file once processing of the include file is complete. After the inclusion of all groups, the resulting Fortran program must follow all of the Fortran rules for statement order.

For an INCLUDE compiler directive with the left and right parentheses syntax, XL Fortran translates the file name to lowercase unless the -qmixed compiler option is on.

The file system locates the specified filename as follows:
  • If the first nonblank character of filename is /, filename specifies an absolute file name.
  • If the first nonblank character is not /, the operating system searches directories in order of decreasing priority:
    • If you specify any -I compiler option, filename is searched for in the directories specified.
    • If the operating system cannot find filename then it searches:
      • the current directory for file filename.
      • the resident directory of the compiling source file for file filename.
      • directory /usr/include for file filename.

Examples

INCLUDE '/u/userid/dc101'     ! full absolute file name specified
INCLUDE '/u/userid/dc102.inc' ! INCLUDE file name has an extension
INCLUDE 'userid/dc103'        ! relative path name specified
INCLUDE (ABCdef)              ! includes file abcdef
INCLUDE '../Abc'              ! includes file Abc from parent directory
                              ! of directory being searched

Related information