PARAMETER STATEMENTS

COMMON STATEMENTS

INCLUDE

DATA STATEMENT

                                                                                                                                                                                                  (Back to topic index)
Parameter Statements: The parameter statement defines constants. The value of the constant can not be changed in the program. It is useful for physical constants and defining memory.

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.

                                                                                                                                                                                                                       (start)
Common Statements: The COMMON statement is used to define memory that is shared between program units. There are two types of COMMON. 1) Blank common: This is a list of variables which can be shared by any program unit, e.g., COMMON A, B, C.

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.

2) Labeled common: This is defined by a name, i.e. the label, followed by the list of variables to be held in ‘common.’ Only program units that contain this labeled COMMON have access to the memory defined, e.g., COMMON/SHARE/A, B, 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

                                                                                                                                                                                                                 (start)
Include: includes a text file in your program

If 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.

                                                                                                                                                                                                                 (start)
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

                                                                                                                                                                                                           (start)