HP Fortran for OpenVMS
User Manual


Previous Contents Index

2.2.3 Creating and Using Module Files

HP Fortran creates module files for each module declaration and automatically searches for a module file referenced by a USE statement (introduced in Fortran 90). A module file contains the equivalent of the module source declaration in a post-compiled, binary form.

2.2.3.1 Creating Module Files

When you compile an HP Fortran source file that contains module declarations, HP Fortran creates a separate file for each module declaration in the current process default device and directory. The name declared in a MODULE statement becomes the base prefix of the file name and is followed by the F90$MOD file type.

For example, consider a file that contains the following statement:


MODULE MOD1 

The compiler creates a post-compiled module file MOD1.F90$MOD in the current directory. An object file is also created for the module.

Compiling a source file that contains multiple module declarations will create multiple module files, but only a single object file. If you need a separate object file for each module, place only one module declaration in each file.

If a source file does not contain the main program and you need to create module files only, specify the /NOOBJECT qualifier to prevent object file creation.

To specify a directory other than the current directory for the module file(s) to be placed, use the /MODULE qualifier (see Section 2.3.31).

Note that an object file is not needed if there are only INTERFACE or constant (PARAMETER) declarations; however, it is needed for all other types of declarations including variables.

2.2.3.2 Using Module Files

Once you create a module file, you can copy module files into an appropriate shared or private directory. You reference a module file by specifying the module name in a USE statement (use association). For example:


USE MOD1 

By default, the compiler searches for a module file named MOD1.F90$MOD in the current directory.

When selecting a directory location for a set of module files, consider how your application gets built, including:

HP Fortran allows you to use multiple methods to specify which directories are searched for module files:

To locate modules referenced by USE statements, the compiler searches directories in the following order:

  1. The current process device and directory
  2. Each directory specified by the /INCLUDE qualifier
  3. The directory specified by the logical name FORT$INCLUDE (unless /NOINCLUDE was specified).

You cannot specify a module (.F90$MOD) file directly on the FORTRAN command line.

Suppose you need to compile a main program PROJ_M.F90 that contains one or more USE statements. To request that the compiler look for module files in the additional directories DISKA:[PROJ_MODULE.F90] and then DISKB:[COMMON.FORT] (after looking in the current directory), enter the following command line:


$ FORTRAN PROJ_M.F90 /INCLUDE=(DISKA:[PROJ_MODULE.F90],DISKB:[COMMON.FORT])

If you specify multiple directories with the /INCLUDE qualifier, the order of the directories in the /INCLUDE qualifier determines the directory search order.

Module nesting depth is unlimited. If you will use many modules in a program, check the process and system file limits (see Section 1.2).

For More Information:

2.2.4 Using Include Files and Include Text Library Modules

You can create include files with a text editor. The include files can be placed in a text library. If needed, you can copy include files or include text library to a shared or private directory.

When selecting a directory location for a set of include files or text libraries, consider how your application is to be built, including:

2.2.4.1 Using Include Files and INCLUDE Statement Forms

Include files have a file type like other HP Fortran source files (F90, FOR, or F). Use an INCLUDE statement to request that the specified file containing source lines be included in place of the INCLUDE statement.

To include a file, the INCLUDE statement has the following form:

INCLUDE 'name'
INCLUDE 'name.typ'

You can specify /LIST or /NOLIST after the file name. You can also specify the /SHOW=INCLUDE or /SHOW=NOINCLUDE qualifier to control whether source lines from included files or library modules appear in the listing file (see Section 2.3.43).

You can also include a file with a directory (and optionally the device name) specified with the following form:

INCLUDE '[directory]name'
INCLUDE '[directory]name.typ'

If a directory is specified, only the specified directory is searched. The remainder of this section addresses an INCLUDE statement where the directory has not been specified.

HP Fortran allows you to use multiple methods to specify which directories are searched for include files:

To locate include files specified in INCLUDE statements (without a device or directory name), the HP Fortran compiler searches directories in the following order:

  1. The current process default directory or the directory that the source file resides in (depending on whether /ASSUME=SOURCE_INCLUDE was specified)
  2. Each directory specified by the /INCLUDE qualifier
  3. The directory specified by the logical name FORT$INCLUDE (unless /NOINCLUDE was specified).

2.2.4.2 INCLUDE Statement Forms for Including Text Library Modules

HP Fortran provides certain include library modules in the text library FORSYSDEF.TLB. Users can create a text library and populate it with include library modules (see Section 2.4). Within a library, text library modules are identified by a library module name (no file type).

To include a text library module, the INCLUDE statement specifies the name of the library module within parentheses, as follows:

INCLUDE '(name)'

You can specify the library name before the library module name in the INCLUDE statement. For example:


INCLUDE 'MYLIB(PROJINC)' 

Use one of the following methods to access a source library module in a text library:

2.2.4.3 Using Include Text Library Modules for a Specified Library Name

When the library is named in the INCLUDE statement, the FORTRAN command searches various directories for the named library, similar to the search for an include file.

HP Fortran allows you to use multiple methods to specify which directories are searched for named text libraries:

The HP Fortran compiler searches directories in the following order:

  1. The current process default directory or the directory that the source file resides in (depending on whether /ASSUME=SOURCE_INCLUDE was specified)
  2. Each directory specified by the /INCLUDE qualifier
  3. The directory specified by the logical name FORT$INCLUDE (unless /NOINCLUDE was specified).

You can specify /LIST or /NOLIST after the library module name. For example:


INCLUDE 'PROJLIB(MYINC)/LIST' 

You can also specify the /SHOW=INCLUDE or /SHOW=NOINCLUDE qualifier to control whether source lines from included files or library modules appear in the listing file (see Section 2.3.43).

For More Information:

2.2.4.4 Using Include Text Library Modules for an Unspecified Library Name

When the INCLUDE statement does not specify the library, you can specify additional text libraries to be searched on the FORTRAN command line or by defining a logical name. The order in which the compiler searches for a library file follows:

You can specify /LIST or /NOLIST after the library module name. For example:


INCLUDE '(MYINC)/NOLIST' 

You can also specify the /SHOW=INCLUDE or /SHOW=NOINCLUDE qualifier to control whether source lines from included files or library modules appear in the listing file (see Section 2.3.43).

For More Information:

2.2.5 Specifying Output Files

The output produced by the compiler includes the object and listing files. You can control the production of these files by using the appropriate qualifiers on the FORTRAN command line.

The production of listing files depends on whether you are operating in interactive mode or batch mode:

For command procedures that compile the application in either batch or interactive mode, consider explicitly specifying /NOLIST (or /LIST).

The compiler generates an object file by default. During the early stages of program development, you may find it helpful to use the /SYNTAX_ONLY or /NOOBJECT qualifiers to prevent the creation of object files until your source program compiles without errors. If you omit /NOOBJECT, the compiler generates object files as follows:

You can use both commas and plus signs in the same command line to produce different combinations of concatenated and separate object files (see the examples of the FORTRAN command at the end of this section).

To name an object file, use the /OBJECT qualifier in the form /OBJECT=file-spec. Otherwise, the object file has the file name of its corresponding source file and a file type of OBJ. By default, the object file produced from concatenated source files has the name of the first source file. All other file specification fields (node, device, directory, and version) assume the default values.

When creating object files that will be placed in an object library, consider using the /SEPARATE_COMPILATION qualifier, which places individual compilation units in a source file as separate components in the object file. This minimizes the size of the routines included by the linker as it creates the executable image. However, to allow more interprocedure optimizations, use the default /NOSEPARATE_COMPILATION.

For More Information:

2.2.6 Examples of the FORTRAN Command

The following examples show the use of the FORTRAN command.

2.2.6.1 Naming the Object File

The following FORTRAN command compiles the HP Fortran free-form source file (CIRCLE.F90) into an object file:


$ FORTRAN /OBJECT=[BUILD]SQUARE /NOLIST [Return]
_File: CIRCLE

The source file CIRCLE.F90 is compiled, producing an object file named SQUARE.OBJ in the [BUILD] directory, but no listing file.


Previous Next Contents Index