Examples:
REAL PI
PARAMETER (PI = 3.14159)
INTEGER MX
PARAMETER (MX = 1000)
REAL X(MX)
You should always use the parameter statement to define memory allocations.
Common Statements: The COMMON statement is used to define memory that is shared between program units. There are two types of COMMON.If the above statement appears in the main program, then any other program unit (subroutine or function) can have the same statement and will have access to what is in the memory defined by A, B and C.
A more realistic example:
INTEGER, MX, MY
PARAMETER (MX = 1000, MY = 2000)
INTEGER NX, NY
REAL X, Y
COMMON /CXY/ X(MX), Y(MY), NX, NY
Include: includes a text file in your programIf the above statements are always going to appear in your subroutines, we can put them into a file, e.g., xydef.h. Then, the following statement results in the contents of xydef.h being placed into your program at compile time.
INCLUDE ‘xydef.h’
This is very useful when the number of definitions for variables and their memory requirements is large and must be used in many program units.
Data Statement: used to define the initial values for variables not in COMMON.Example:
LOGICAL FIRST
DATA FIRST/.TRUE./
:
:
IF (FIRST) then
:
:
FIRST = .FALSE.
END IF
:
:
Example:
REAL X(1000)
DATA X(1) /1000*0.0/
:
Remember to define the variable before assigning it a value by data statement. For variables that are in COMMON blocks, no program unit can use a data statement to initialize these variables. Instead, a special program unit, the block data subprogram, is available:
BLOCK DATA CINIT
INCLUDE ‘XYDEF.H’
DATA X(1)/MX*0.0/
:
:
END