Fortran 90 has two main program units:
The place where execution begins and where control should eventually return before the program terminates. The main program may contain any number of procedures.
A program unit which can also contain procedures and declarations. It is intended to be attached to any other program unit where the entities defined within it become accessible. A module is similar to a C++ class.
MODULE program units are new to Fortran 90 and are supposed to replace the unsafe FORTRAN 77 features such as COMMON, INCLUDE, BLOCK DATA as well as adding a much needed (limited) `object oriented' aspect to the language. Their importance cannot be overstressed and they should be used whenever possible.
There are two classes of procedure:
A parameterised named sequence of code which performs a specific task and can be invoked from within other program units by the use of a CALL\ statement, for example,
CALL PrintReportSummary(CurrentFigures)
Here, control will pass into the SUBROUTINE named PrintReportSummary, after the SUBROUTINE has terminated control will pass abck to the line following the CALL.
As a SUBROUTINE but returns a result in the function name (of any specified type and kind). This can be compared to a mathematical function, say, f(x). An example of a FUNCTION call could be:
PRINT*, "The result is", f(x)
Here, the value of the function f (with the argument x) is substituted at the appropriate point in the output.
Procedures are generally contained within a main program or a module. It is also possible to have `stand alone' or EXTERNAL procedures, these will be discussed later (see Section 14).
Return to corresponding overview page