Modules are new to Fortran 90. They have a very wide range of applications and their use should be encouraged. They allow the user to write object based code which is generally accepted to more reliable, reusable and easier the write than regular code.
A MODULE is a program unit whose functionality can be exploited by any other program unit which attaches it (via the USE statement). A module can contain the following:
Modules should be used in place of FORTRAN 77 COMMON and INCLUDE statements. If global data is required, for example, to cut down on argument passing, then objects declared in a module can be made visible wherever desired by simply attaching the module. Objects in a module can be given a static storage class so will retain their values between uses.
Sets of variable declarations which are not globally visible can also be placed in a module and used at various places in the code; this mimics the functionality of the INCLUDE statement.
It is sometimes advantageous to package INTERFACE definitions into a module and then use the module whenever an explicit interface is needed. This should be done in conjunction with the ONLY clause but is only really useful when module procedures cannot be used.
Procedures can be encapsulated into a module which will make them visible to any program unit which uses the module. This approach has the advantage that all the module procedures, and hence their interfaces, are explicit within the module so there will be no need for any INTERFACE blocks to be written.
Variables, procedures and operator declarations can have their visibility controlled by access statements within the module. It is possible for specified objects to be visible only inside the module. This technique is often used to provide security against a user meddling with the values of module objects which are purely internal to the module.
Derived types, operators, procedures and generic interfaces can be defined and packaged to provide simple object oriented capabilities.
A semantic extension module is a collection of user-defined type declarations, access routines and overloaded operators and intrinsics which, when attached to a program unit, allow the user to use the functionality as if it were part of the language.
Return to corresponding overview page