next up previous contents
Next: Module Global Data Example Up: Modules Previous: Modules - General Form

 

Modules - Global Data

  COMMON blocks have long been regarded as an unsafe feature of Fortran. In FORTRAN 77 they were the only way to achieve global storage; Fortran 90 implements a new mechanism to allow specific procedures to have access to global data. This can be done by:

For example, to declare pi as a global constant

  MODULE  Pye
   REAL, SAVE :: pi = 3.142
  END MODULE Pye

  PROGRAM Area
   USE Pye
   IMPLICIT NONE
   REAL :: r
    READ*, r
    PRINT*, "Area= ",pi*r*r
  END PROGRAM Area

In the example the module Pye defines global data (the constant Pi). Its value can be accessed by USE ing the module.

Name clashes caused by the above can be avoided by using the object renaming facility, (see Section 5.2.5).

If the use of a COMMON block is absolutely essential then a single instance of it should be placed in a MODULE and then usedgif. This will have the effect of ensuring that each time the COMMON block is accessed it will be laid out in exactly the same way and mimics the techniques of placing COMMON blocks in INCLUDE files (a common FORTRAN 77 technique).




next up previous contents
Next: Module Global Data Example Up: Modules Previous: Modules - General Form

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.