


BLOCK DATA Program Units 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 |
For compatibility with Fortran66 it is also possible to have one un-named block data program unit in a program.
Linking Block Data Program Units
If, when linking a program, one of the modules containing a procedure is accidentally omitted the linker is almost certain to produce an error message. But, unless additional precautions are taken, this will not occur if a block data subprogram unit is omitted. The program may even appear to work without it, but is likely to produce the wrong answer.
There is a simple way to guard against this possibility: the name of the block data
unit should be specified in an EXTERNAL statement in at least some of the
program units in which the common block is used. There is no harm in
declaring it in all of them. This ensures that a link-time reference will be
generated if any of these other program units are used. There is a slight snag to
this technique if an INCLUDE statement is used to bring the common block
definition into each program unit including the block data unit. In order
to avoid a self-reference, the include-file should not contain the EXTERNAL
statement.
Despite this slight complication, this is a simple and valuable precaution. It also makes is possible to hold block data units on object libraries and retrieve them automatically when they are required, just like all other types of subprogram unit.