Converted document

FORTRAN 90+: MODULES

Modules provide a method of defining global variables and connecting multiple programs, subroutines and functions. The global definition of a set of variables means that allof the code routines or functions that use the module use a single statement to define this set of variables. Modules are defined by typing
MODULE module_name
   IMPLICIT NONE
  [declaration  of variables]
END MODULE module_name
A more complex version that includes subprograms would be
MODULE module_name
   IMPLICIT NONE
   [declaration  of variables]
   CONTAINS
   [internal_functions]
END MODULE module_name
The internal functions section allows the definition of a function or subroutine in the module and use it in all the following programs, functions and subroutines. in that section one can define another module for use in specific set of internal functions.
Variables and functions can be set to only exist inside the Module for use by the module. To do this set the access for a variable of function to PUBLIC or PRIVATE by writing
PUBLIC :: variable_names_already_defined_in_usual_way 
!only in the Module
PRIVATE :: variable_names_already_defined_in_usual_way 
!everywhere
The format of the module has the USE statement followed by the name of the module. Once can also restrict which variables the program will use through an ONLY statement that would look like
USE module_name, ONLY: var1, var2,...,var_n
USE module_name !If want to use whole module
The programs that are the main focus of the file would follow the END MODULE module_name statement.