scoping unit); subprograms (which among other things replaces the use of ENTRY from Fortran 77); interface blocks (another scoping unit, see Interface blocks); namelist groups (see any textbook). An example of a module containing a type definition, interface block and function subprogram is MODULE interval_arithmetic TYPE interval REAL lower, upper END TYPE interval INTERFACE OPERATOR(+) MODULE PROCEDURE add_intervals END INTERFACE : CONTAINS FUNCTION add_intervals(a,b) TYPE(interval), INTENT(IN) :: a, b TYPE(interval) add_intervals add_intervals%lower = a%lower + b%lower add_intervals%upper = a%upper + b%upper END FUNCTION add_intervals ! FUNCTION mandatory : END MODULE interval_arithmetic and the simple statement USE interval_arithmetic provides use association to all the module's entities. Module subprograms may, in turn, contain internal subprograms. Controlling accessibility The PUBLIC and PRIVATE attributes are used in specifications in modules to limit the scope of entities. The attribute form is REAL, PUBLIC :: x, y, z ! default INTEGER, PRIVATE :: u, v, w and the statement form is PUBLIC :: x, y, z, OPERATOR(.add.) PRIVATE :: u, v, w, ASSIGNMENT(=), OPERATOR(*) The statement form has to be used to limit access to operators, and can also be used to change the overall default: PRIVATE ! sets default for module PUBLIC :: only_this For derived types there are three possibilities: the type and its components are all PUBLIC, the type is PUBLIC and its components PRIVATE (the type only is visible and one can change its details easily), or all of it is PRIVATE (for internal use in the module only): MODULE mine PRIVATE TYPE, PUBLIC :: list REAL x, y TYPE(list), POINTER :: next END TYPE list TYPE(list) :: tree : END MODULE mine The USE statement's purpose is to gain access to entities in a module. It has options to resolve name clashes if an imported name is the same as a local one: USE mine, local_list => list or to restrict the used entities to a specified set: USE mine, ONLY : list These may be combined: USE mine, ONLY : local_list => list Arguments We may specify the intent of dummy arguments: SUBROUTINE shuffle (ncards, cards) INTEGER, INTENT(IN) :: ncards INTEGER, INTENT(OUT), DIMENSION(ncards) :: cards Also, INOUT is possible: here the actual argument must be a variable (unlike the default case where it may be a constant). Arguments may be optional: SUBROUTINE mincon(n, f, x, upper, lower, equalities, inequalities, convex, xstart) REAL, OPTIONAL, DIMENSION :: upper, lower : IF (PRESENT(lower))