HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
MODULE
Chapter 10 399
MODULE
Introduces a module.
Syntax
MODULE
module-name
module-name
is a unique module name.
Description
Modules are nonexecutable program units that can 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 those
program units that specify the module in a USE statement. Modules provide a convenient
sharing and encapsulation mechanism for data, types, procedures, and procedure interfaces.
Examples
! Make data objects and a data type sharable via a module
MODULE shared
COMPLEX gtx (100, 6)
REAL, ALLOCATABLE :: y(:), z(:,:)
TYPE peak_item
REAL peak_val, energy
TYPE(peak_item), POINTER :: next
END TYPE peak_item
END MODULE shared
! Define a data abstraction for rational arithmetic via a module
MODULE rational_arithmetic
TYPE rational
PRIVATE
INTEGER numerator, denominator
END TYPE rational ! Generic extension of =
INTERFACE ASSIGNMENT (=)
MODULE PROCEDURE eqrr, eqri, eqir
END INTERFACE
INTERFACE OPERATOR (+) ! Generic extension of +
MODULE PROCEDURE addrr, addri, addir
END INTERFACE
...
CONTAINS
FUNCTION eqrr (. . .) ! A specific definition of =