Copyright (c) 1994 J. Adams, W. Brainerd, J. Martin, and B. Smith. All rights reserved. This file may not be copied without permission of the authors.
Modules are nonexecutable program units that contain type definitions, object declarations, procedure definitions (module procedures), external procedure interfaces, user-defined generic names, and user-defined operators and assignments. Any such definitions not specified to be private to the module containing them are available to be shared with those programs that use the module. Thus modules provide a convenient sharing and encapsulation mechanism for data, types, procedures, and procedure interfaces.
MODULE SHARED ! Making data objects
COMPLEX GTX (100, 6) ! and a data type
REAL, ALLOCATABLE :: Y(:), Z(:,:) ! sharable via a module
TYPE PEAK_ITEM
REAL PEAK_VAL, ENERGY
TYPE(PEAK_ITEM), POINTER :: NEXT
END TYPE PEAK_ITEM
END MODULE SHARED
MODULE RATIONAL_ARITHMETIC ! Defining a data
TYPE RATIONAL; PRIVATE ! abstraction for
INTEGER NUMERATOR,DENOMINATOR ! rational arithmetic
END TYPE RATIONAL ! via a module
INTERFACE ASSIGNMENT (=) ! Generic extension of =
MODULE PROCEDURE ERR, ERI, EIR
END INTERFACE
INTERFACE OPERATOR (+) ! Generic extension of +
MODULE PROCEDURE ARR, ARI, AIR
END INTERFACE
. . .
CONTAINS
SUBROUTINE ERR (. . .) ! A specific definition of =
. . .
FUNCTION ARR (. . .) ! A specific definition of +
. . .
END MODULE RATIONAL_ARITHMETIC
Defined Type: Operators and Assignment
Defined Type: Objects
Host Association
Module Procedures
Program Units
PUBLIC and PRIVATE Attributes and Statements
USE Statement and Use Association
ISO 1539 : 1991, Fortran Standard, 2.2.4, 11.3, C.11.4
Fortran 90 Handbook, 0, 11.6
Programmer's Guide to Fortran 90, 7
A module is:
MODULE module-name
[ specification-part ]
[ CONTAINS
module-subprogram
[ module-subprogram ]...]