Self-Printing Fortran Program
DATA F/8H(7X,11HR,8HEAL*8F(1,8H7)/7X,7H,8HDATA F/,,8H5(2H8H,A,
The program declares an array of 8 byte real numbers "F" 17 elements long and then initializes them using a 3-line DATA statement. I have highlighted the initialization values in orange above. The variable F essentially has the string value:
The program then very craftily uses the array itself as the format statement to output the array.
FORTRAN neophytes, note that:
- The first 5 characters of a statement are line numbers, which are not used at all in this program. Column 6 is a continuation indicator. Any non-blank value (traditionally an ascending sequence such as the 1 and 2 used in this program) means that the remainder of the line is a continuation of the previous statement.
- a Hollerith constant is of the form nHabc.., that is, a number followed immediately by an upper-case H, followed by the text string. for example, the first one that occurs in this program is 8H(7X,11HR. It is equivalent to what would be expressed in other computer languages as "(7X,11HR". All 17 values of the REAL array are each initialized to 8 bytes of alphanumeric values.
- nX in a FORMAT statement causes n spaces to be output.
- / in a FORMAT statement causes a new line.
- A8 is a specifier to output a value as 8 alphanumeric characters.
- The output processor always strips the first column of output away as "carriage-control". A blank in this position just means to output the line normally.