An
INCLUDE line
inserts text into a program during compilation. The INCLUDE
line is a directive to the compiler; it is not a Fortran 90 statement.
The format of an INCLUDE
line is:
INCLUDE char-literal-const |
Title not available (INCLUDE line)
- char-literal-const
is the name of a file containing the text to be
included. The character literal constant must not have a kind parameter
that is a named constant.
If
char-literal-const is only a filename
(in other words, no pathname is specified), the compiler searches
a user specified path. See Chapter 13 for information about the
-Idir
option, which tells the compiler to search directories specified
by dir to locate files to be included.
The contents of the specified file are substituted for the
INCLUDE line
before compilation and are treated as if they were part of the original
program source text.
Use
of the INCLUDE
line provides a convenient way to include source text that is the
same in several program units. For example, interface blocks or
common blocks may constitute a file that is referenced in the INCLUDE
line.
Modules provide access to data, types, and procedures that
can be shared among procedures and thus provide a more effective
way to accomplish most of what an INCLUDE
line can do. However, as illustrated by the last INCLUDE
line in the examples that follow, it is possible to use an INCLUDE
line to include a portion of a subprogram; this is not possible
with a module.
The INCLUDE
line must appear on one line with no other text except possibly
a trailing comment. There must be no statement label. This means,
for example, that it is not possible to branch to it, and it cannot
be the action statement that is part of an IF
statement. Putting a second INCLUDE
or another Fortran 90 statement on the same line using ";"
as a separator is not permitted. Continuing an INCLUDE
line using "&"
is also not permitted.
Following are example INCLUDE
lines:
INCLUDE "MY_COMMON_BLOCKS" |
INCLUDE "/usr/include/machine_parameters.h" |
You may also insert the INCLUDE
line in the executable part of a program to include program. In
the following segment, the READ statement gets an input value that
will be used by the code provided by the INCLUDE
line:
INCLUDE "FUNCTION_CALCULATION" |
INCLUDE
lines may also be nested. That is, a second INCLUDE
line may appear within the text to be included, and the text that
it includes may also have an INCLUDE
line, and so on. HP Fortran 90 has a maximum INCLUDE
line nesting level of 10. However, the text inclusion must not be
recursive at any level; for example, included text A must not include
text B if B includes text A.
The text of the file to be included must consist of complete
Fortran 90 statements.