next up previous contents index
Next: Linking Block Data Program Up: Common Blocks Previous: COMMON Statement

BLOCK DATA Program Units

 

The block data program unit is a special form of program unit which is required only if it is necessary to specify initial values for variables and arrays in named common blocks. The program unit starts with a BLOCK DATA statement, ends with an END statement, and contains only specification and DATA statements. Comment lines are also permitted. The block data program unit is not executable and it is not a procedure.

The next example initialises the items in the common block for the plotting package used in section 12.1, so that the initial pen position is at the origin, the scaling factor starts at one, and so on. Thus a suitable program unit would be:

 
       BLOCK DATA SETPLT 
*SETPLT initialises the values used in the plotting package. 
       COMMON /PLOT/ OPENED, ORIGIN(2), PSCALE, NUMPEN 
       LOGICAL OPENED 
       INTEGER NUMPEN 
       REAL PSCALE, ORIGIN 
       SAVE /PLOT/ 
       DATA OPENED/.FALSE./, ORIGIN/2*0.0/, PSCALE/1.0/ 
       DATA NUMPEN/-1/ 
       END

A block data unit can specify initial values for any number of named common blocks (blank common cannot be initialised). Each common block must be complete but it is not necessary to specify initial values for all of the items within it. There can be more than one block data program unit, but a given common block cannot appear in more than one of them.

For compatibility with Fortran66 it is also possible to have one un-named block data program unit in a program.



Mario Storti
Wed Nov 4 19:32:56 ART 1998