Fortran Wiki article on submodules: http://fortranwiki.org/fortran/show/Submodules
Summary
- Modules are special program units that allow you to define functions, subroutines, and variables in one place.
- Fortran comes with a few built-in modules, such as
iso_fortran_envandiso_c_binding. - The built-in module
iso_fortran_envprovides, among other things, functions that return information about the compiler and the options used to compile the program, as well as type kind parameters that allow you to declare variables in a portable way. - Compiling modules produces special
.modfiles, which must be included in the compiler path when building other Fortran code that accesses the modules. - Accessing a module with just the
usestatement imports all public entities from the module into the current scope. You can use an expanded variant,use...,only:..., to import only specific entities. - Entities defined in a module can be public or private. Public entities are available for use to any program or procedure that uses that module. Private entities can only be accessed within the module itself.
- You can set public and private properties of module entities using the
publicandprivateattributes, respectively. - Variables and procedures with conflicting names can be imported from modules but can’t be referenced. To work around the name conflict, use the
=>operator to rename a variable or procedure on import.
Further reading