A module contains specifications and definitions that can be accessed from other program units. These definitions include data object definitions, namelist groups, derived-type definitions, procedure interface blocks and procedure definitions.
+-------------------------------IBM Extension--------------------------------+
Fortran 90 modules define global data, which, like COMMON data, is shared across threads and is therefore thread-unsafe. To make an application thread-safe, you must declare the global data as THREADPRIVATE or THREADLOCAL. See COMMON, THREADLOCAL, and THREADPRIVATE for more information.
+----------------------------End of IBM Extension----------------------------+
>>-MODULE_statement-------------------------------------------->< >>-+--------------------+-------------------------------------->< '-specification_part-' >>-+------------------------+---------------------------------->< '-module_subprogram_part-' >>-END_MODULE_statement---------------------------------------->< |
>>-CONTAINS_statement------------------------------------------>< .-------------------. V | >>---module_subprogram-+--------------------------------------->< |
A module subprogram is contained in a module but is not an internal subprogram. Module subprograms must follow a CONTAINS statement, and can contain internal procedures. A module procedure is defined by a module subprogram or an entry in a module subprogram.
Executable statements within a module can only be specified in module subprograms.
The declaration of a module function name of type character cannot have an asterisk as a length specification.
specification_part cannot contain statement function statements, ENTRY statements, or FORMAT statements, although these statements can appear in the specification part of a module subprogram.
Automatic objects and objects with the AUTOMATIC attribute cannot appear in the scope of a module.
An accessible module procedure can be invoked by another subprogram in the module or by any scoping unit outside the module through use association (that is, by using the USE statement). See USE for details.
+-------------------------------IBM Extension--------------------------------+
Integer pointers cannot appear in specification_part if the pointee specifies a dimension declarator with nonconstant bounds.
All objects in the scope of a module retain their association status, allocation status, definition status, and value when any procedure that accesses the module through use association executes a RETURN or END statement. See point 4 under Events Causing Undefinition for more information.
+----------------------------End of IBM Extension----------------------------+
A module is a host to any module procedures or derived-type definitions it contains, which can access entities in the scope of the module through host association.
A module procedure can be used as an actual argument associated with a dummy procedure argument.
The name of a module procedure is local to the scope of the module and cannot be the same as the name of any entity in the module, except for a common block name.
Migration Tips:
FORTRAN 77 source: COMMON /BLOCK/A, B, C, NAME, NUMBER REAL A, B, C A = 3 CALL CALLUP(D) PRINT *, NAME, NUMBER END SUBROUTINE CALLUP (PARM) COMMON /BLOCK/A, B, C, NAME, NUMBER REAL A, B, C ... NAME = 3 NUMBER = 4 END Fortran 90 or Fortran 95 source: MODULE FUNCS REAL A, B, C ! Common block no longer needed INTEGER NAME, NUMBER ! Global data CONTAINS SUBROUTINE CALLUP (PARM) ... NAME = 3 NUMBER = 4 END SUBROUTINE END MODULE FUNCS PROGRAM MAIN USE FUNCS A = 3 CALL CALLUP(D) PRINT *, NAME, NUMBER END |
MODULE M INTEGER SOME_DATA CONTAINS SUBROUTINE SUB() ! Module subprogram INTEGER STMTFNC STMTFNC(I) = I + 1 SOME_DATA = STMTFNC(5) + INNER(3) CONTAINS INTEGER FUNCTION INNER(IARG) ! Internal subprogram INNER = IARG * 2 END FUNCTION END SUBROUTINE SUB END MODULE PROGRAM MAIN USE M ! Main program accesses CALL SUB() ! module M END PROGRAM