Modules

Modules are containers for variables and subprograms. Modules are useful for creating global variables and grouping related subprograms

Modules consist of variables, data type definitions, subroutines, and functions. The form of a module is

module test
Variables, data type definitions
contains
Subroutines,functions
end module test
A module is included in a file with the statement use modulename All the variables defined in the module are available, as well as the subroutines and functions (Not quite true, see the public and private keywords).

Putting variables in a module replaces common statements as a mechanism for global variables.

A object oriented use for modules is to declare a particular derived data type and the functions and subroutines that operate on that type.

Public and private

By default, all the variables, subprograms, etc. are public - any program that includes the module can see them. The keyword private means that only variables and subprograms with the public attribute are available to the including program.


Return to Fortran 90 index