DIGITAL Fortran 90
User Manual for
DIGITAL UNIX Systems


Previous Contents Index

2.1.3 Specifying Files and Options

You can use an f90 command to specify multiple options and multiple file names, separated by spaces. If appropriate, the file names can have a different suffix. The file name suffix can result in the following actions:

When a file is not in your current working directory, specify the directory path before the file name.

2.1.4 Creating and Using Module Files

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

2.1.4.1 Creating Module Files

When you compile a DIGITAL Fortran 90 source file that contains module declarations, DIGITAL Fortran 90 creates a separate file for each module declaration. The name declared in a MODULE statement becomes the base prefix of the file name and is followed by the .mod suffix.

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


MODULE MOD1 

The compiler creates a post-compiled module file mod1.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 only need to create module files, specify the -c option to prevent linking.

An object file is not needed if there are only INTERFACE or constant (PARAMETER) declarations. It is needed for all other types of declarations including variables.

2.1.4.2 Using Module Files

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


 USE MOD1 

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

To locate module files specified in USE statements, the DIGITAL Fortran 90 compiler searches the following directories:

Suppose you need to compile a main program proj_main that contains one or more USE statements. To request that the compiler look for module files in the additional directories /usr/proj_module/f90 and then /usr/common/f90 (after looking in the current directory), type the following command line:


% f90 proj_main.f90 -I/usr/proj_module/f90 -I/usr/common/f90

If you specify multiple directories, the order of -idir options on the f90 command line determines the directory search order.

You cannot specify a .mod file directly on the f90 command line.

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

For More Information:

2.1.5 The INCLUDE Statement and Using Include Files

You can create include files with a text editor. If needed, you can copy include files 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:

Include files have a file name suffix like other DIGITAL Fortran 90 source files (such as .f90 , .f , and .for ). Use an INCLUDE statement to request that the specified file containing source lines be included by the compiler in place of the INCLUDE statement.

The INCLUDE statement has the following form:

INCLUDE 'name'
INCLUDE 'name.typ'

You can also include a file with a pathname specified with the following form:

INCLUDE '/pathname/name'
INCLUDE '/pathname/name.typ'

If you specify the -vms option, you can specify /LIST or /NOLIST after the file name. For example:

INCLUDE '/pathname/name/LIST'
INCLUDE 'name.f90/NOLIST'

You can also specify the -show include option to request that source lines from included files appear in the listing file (see Section 3.69).

When the INCLUDE Statement Specifies a Pathname

Specifying pathname limits the directory searching done for the named file. For example, pathname might specify a directory /usr/users/proj for the file named common_proj.f90 :


 INCLUDE 'usr/users/proj/common_proj.f90' 

If a directory pathname is specified, only the specified directory is searched.

When the INCLUDE Statement Omits a Pathname

When the INCLUDE statement omits a pathname, one or more directories are searched for the specified file name.

To locate include files specified in INCLUDE statements without a pathname, the DIGITAL Fortran 90 compiler searches directories in the following order:

  1. The directory that the source file resides in ( -vms option was omitted) or the current process default directory ( -vms option was specified)
  2. Each directory specified by one or more -idir options.
  3. The /usr/include directory (unless the -noinclude option was specified)

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

2.1.6 Output Files: Executable, Object, and Temporary

The output produced by the f90 command includes:

You control the production of these files by specifying the appropriate options on the f90 command line. Unless you specify the -c option, the compiler generates a single temporary object file (see Section 2.1.6.2), whether you specify one source file or multiple source files separated by blanks. The ld linker is then invoked to link the object file into one executable program file.

If fatal errors are encountered during compilation, or if you specify certain options such as -c , linking does not occur.

2.1.6.1 Naming Output Files

To specify a file name for the executable program file (other than a.out ), use the -o output option, where output specifies the file name. The following command requests a file name of prog1.out for the source file test1.f :


% f90 -o prog1.out test1.f

If you specify the -c option with the -o output option, you rename the object file (not the executable program file). If you specify -c and omit the -o output option, the compiler names the object file using the first specified file name (with a .o suffix substituted for the source file suffix).

You can also use the mv command to rename a file.

2.1.6.2 Temporary Files

Temporary files created by the compiler or a preprocessor reside in the /tmp directory. For example, when an f90 command requests that the compiler create an object file and pass it to the linker, the file is created in, and later deleted from, the /tmp directory (unless you specified the -k option).

You can set the environment variable TMPDIR to specify a directory to contain temporary files if /tmp is not acceptable. For performance reasons, use a local disk (rather than a NFS mounted disk) to contain the temporary files.

For information about the commands used to set and unset environment variables, see Appendix B.

To view the file name and directory where each temporary file is created, use the -v option. To create (and retain) object files in your current working directory, use the -c option. Any object files ( .o files) that you specify on the f90 command line are retained.

The TMPDIR environment variable is also used during program execution (run-time) to specify which directory to contain any scratch files your program creates.

2.1.7 Using Multiple Input Files: Effect on Output Files

When you specify multiple source files, the following options control the production of output files and also influence whether DIGITAL Fortran 90 can apply certain levels of optimizations:

A description of the interaction of these options follows:

When you request a listing file ( -v option), a single listing file is created unless you specify the -c option. If you specify the -c option and the -v option, separate listing files are created.

2.1.8 Examples of the f90 Command

The following examples show the use of the f90 command.

2.1.8.1 Compiling and Linking Multiple Files

The following f90 command compiles the DIGITAL Fortran 90 free format source files ( aaa.f90 , bbb.f90 , ccc.f90 ) into a single temporary object file:


% f90 -V aaa.f90 bbb.f90 ccc.f90

This f90 command invokes the ld linker and passes the temporary object file to ld , which it uses to produce the executable file a.out . The DIGITAL Fortran 90 compiler ( -v option) creates the listing file aaa.l .

The following f90 command compiles all DIGITAL Fortran 90 fixed-format (or tab-format) source files with file names that end with .f into a temporary object file:


% f90 -V *.f

The ld linker produces the a.out file. The listing file (produced when the -v option is specified) assumes the name of the first file, aaa.l .

2.1.8.2 Retaining an Object File and Preventing Linking

The following f90 command compiles, but does not link, the free-format source file typedefs_1.f90 , which contains a MODULE TYPEDEFS_1 statement:


% f90 -c typedefs_1.f90

This command creates files typedefs_1.mod and typedefs_1.o . Specifying the -c option retains the object file typedefs_1.o and prevents linking.

2.1.8.3 Compiling Fortran 90 and C Source Files and Linking an Object File

The following f90 command compiles the free-format DIGITAL Fortran 90 main program ( myprog.f90 ). The main program calls a function written in C and references the module TYPEDEFS_1 with a USE TYPEDEFS_1 statement (uses the object file created in the previous example). The C routine named utilityx_ is declared in a file named utilityx.c . All sources files are compiled and the object files are passed to the linker:


% f90 myprog.f90 typedefs_1.o utilityx.c

This command does the following:

  1. Compiles myprog.f90 with the DIGITAL Fortran 90 compiler. The module file typedefs_1.mod is read from the current directory.
  2. The C compiler compiles utilityx.c .
  3. The ld linker links all three object files together into the executable program named a.out .

2.1.8.4 Renaming the Output File

The following f90 command compiles the free-format DIGITAL Fortran 90 source files circle-calc.f90 and sub.f90 together, producing one object file named circle.o :


% f90 -c -o circle.o circle-calc.f90 sub.f90

The default optimization level ( -o4 ) applies to both source files during compilation and uses the default loop unrolling. Because the -c option is specified, the object file is not passed to the ld linker and is not deleted. In this case, the named output file is the object file.

Like the previous command, the following f90 command compiles multiple source files:


% f90 -o circle.out circle-calc.f90 sub.f90

Because the -c option was omitted, an executable program named circle.out is created.

2.1.8.5 Specifying an Additional Linker Library

The following f90 command compiles a free-format source file myprog.f90 using default optimization, and passes an additional library for the linker to search:


% f90 typedefs_1.o myprog.f90 -ldxml

The file is processed at optimization level -o4 and then linked with the object file typedefs_1.o . The -ldxml option instructs the linker to search in the libdxml library for unresolved references (in addition to the standard list of libraries the f90 command passes to the linker).


Previous Next Contents Index