Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
E77790.pdf
Скачиваний:
2
Добавлен:
16.05.2024
Размер:
1.29 Mб
Скачать

4.9 Module Files

deprecated as obsolete. The OpenMP directives and parallelization model are preferred. OpenMP parallelization is described in the Oracle Developer Studio 12.6: OpenMP API User’s Guide.

4.9Module Files

Compiling a file containing a Fortran 95 MODULE generates a module interface file (.mod file) for every MODULE encountered in the source. The file name is derived from the name of the MODULE; file xyz.mod (all lowercase) will be created for MODULE xyz.

Compilation also generates a .o module implementation object file for the source file containing the MODULE statements. Link with the module implementation object file along with the all other object files to create an executable.

The compiler creates module interface files and implementation object files in the directory specified by the -moddir=dir flag or the MODDIR environment variable. If not specified, the compiler writes .mod files in the current working directory.

The compiler looks in the current working directory for the interface files when compiling USE modulename statements. The- Mpath option allows you to give the compiler an additional path to search. Module implementation object files must be listed explicitly on the command line for the link step.

Typically, programmers define one MODULE per file and assign the same name to the MODULE and the source file containing it. However, this is not a requirement.

In this example, all the files are compiled at once. The module source files appear first before their use in the main program.

demo% cat mod_one.f90

MODULE one

...

END MODULE

demo% cat mod_two.f90

MODULE two

...

END MODULE

demo% cat main.f90

USE one USE two

...

END

192 Oracle Developer Studio 12.6: Fortran User's Guide • July 2017

4.9 Module Files

demo% f95 -o main mod_one.f90 mod_two.f90 main.f90

Compilation creates the files:

mainmain.oone.modmod_one.otwo.modmod_two.o

The next example compiles each unit separately and links them together.

demo% f95

-c mod_one.f90

mod_two.f90

demo%

f95

-c

main.f90

 

demo%

f95

-o

main main.o

mod_one.o mod_two.o

When compiling main.f90, the compiler searches the current directory for one.mod and two. mod. These must be compiled before compiling any files that reference the modules on USE statements. The link step requires the module implementation object files mod_one.o and mod_two.o appear along with all other object files to create the executable.

4.9.1Searching for Modules

With the release of the version 7.0 of the Fortran compiler, .mod files can be stored into an archive (.a) file. An archive must be explicitly specified in a -Mpath flag on the command line for it to be searched for modules. The compiler does not search archive files by default.

Only .mod files with the same names that appear on USE statements will be searched. For example, the Fortran statement USE mymod causes the compiler to search for the module file mymod.mod by default.

While searching, the compiler gives higher priority to the directory where the module files are being written. This can be controlled by the -moddir=dir option flag and the MODDIR environment variable. This implies that if only the -Mpath option is specified, the current

directory will be searched for modules first, before the directories and files listed on the -M flag.

4.9.2The -use=list Option Flag

The -use=list flag forces one or more implicit USE statements into each subprogram or module subprogram compiled with this flag. By using the flag, it is not necessary to modify source programs when a module or module file is required for some feature of a library or application.

Compiling with -use=module_name has the effect of adding a USE module_name to each subprogram or module being compiled. Compiling with -use=module_file_name has the effect of adding a USE module_name for each of the modules contained in the module_file_name file.

Chapter 4 • Oracle Developer Studio Fortran Features and Extensions

193

Соседние файлы в предмете Информационные и сетевые технологии