A module is a way to store variables and functions/subroutines that are available everywhere in the program and modifiable from anywhere in the program.
To store variables that must be accessible everywhere in a program, you need to create a file called (for example)
mymodule.f90which contains the following
real :: a
real :: b
a = 5
b = 6
real :: x, y, functionInModule
functionInModule = x-y
And the main program becomes
real :: w, z
some code here
w = 2
z = functionInModule(w,w)
use mymoduleat the beginning of the program before the
implicit none. Because of this line, all the variables and functions/subroutines declared in the module can be used in the program.
One can also use
use mymodule, only: variable/function/subroutineto make only part of the variables or functions available. For example
use mymodule, only: functionInModule
real :: w,z,r
w = 1
r = 2
z = functionInModule(w,r)
This can be done to make sure that other parameters contained in the module are not inadvertently modified in the program.