The FORMAT statement specifies the layout of the input or output records.
Format specification list
The items in f have the form: label FORMAT ( f )
A repeat factor
An edit descriptor (repeatable or nonrepeatable). If r is present, then d must be repeatable.
Here is a summary:
I, O, Z are for integers (decimal, octal, hex)
F, E, D, G are for reals (fixed-point, exponential, double, general)
A is for characters
L is for logicals
The nonrepeatable edit descriptors are:
'a1a2 an' single quote-delimited character string
"a1a2 ... an" double quote-delimited character string
nHa1a2 ... an Hollerith string
[k]R (k defaults to 10)
[k]P (k defaults to 0)
B, BN, and BZ
S, SU, SP, and SS
Tn and nT
TL[n] and TR[n] (n defaults to 1)
[n]X (n defaults to 1)
See "Formatted I/O" for full details of these edit descriptors.
The FORMAT statement includes the explicit editing directives to produce or use the layout of the record. It is used with formatted input/output statements and ENCODE/DECODE statements.
r must be a nonzero, unsigned, integer constant.
The descriptors I, O, Z, F, E, D, G, L, and A indicate the manner of editing and are repeatable.
w and e are nonzero, unsigned integer constants.
d and m are unsigned integer constants.
The descriptors are the following:
("), ($), ('), (/), (:), B, BN, BZ, H, P, R, Q, S, SU, SP, SS, T, TL, TR, X
These descriptors indicate the manner of editing and are not repeatable:
Each ai is any ASCII character.
n is a nonzero, unsigned integer constant.
k is an optionally signed integer constant.
Items in the format specification list are separated by commas. A comma can be omitted before or after the slash and colon edit descriptors, between a P edit descriptor, and the immediately following F, E, D, or G edit descriptors.
In some sense, the comma can be omitted anywhere the meaning is clear without it, but, other than those cases listed above, this is nonstandard. u
1 FORMAT( < e > )
The n in an nH... edit descriptor cannot be a variable format expression.
The FORMAT statement label cannot be used in a GO TO, IF-arithmetic, DO, or alternate return.
For explicit formats, invalid format strings cause warnings or error messages at compile time.
For formats in variables, invalid format strings cause warnings or error messages at runtime.
For variable format expressions, of the form <e>, invalid format strings cause warnings or error messages at compile time or runtime.
See "Runtime Formats " for details.
READ( 2, 1 ) PART, ID, HEIGHT, WEIGHT 1 FORMAT( A8, 2X, I4, F8.2, F8.2 ) WRITE( 9, 2 ) PART, ID, HEIGHT, WEIGHT 2 FORMAT( 'Part:', A8, ' Id:', I4, ' Height:', F8.2, & ' Weight:', F8.2 )
DO 100 N = 1, 50 ... 1 FORMAT( 2X, F<N+1>.2 )