FORTRAN 77 Language Reference

FORMAT

The FORMAT statement specifies the layout of the input or output records.

label FORMAT (f)

Parameter 

Description 

label

Statement number 

f

Format specification list  

The items in f have the form: label FORMAT ( f )

[r] desc

[r] (f)

r

A repeat factor 

desc

An edit descriptor (repeatable or nonrepeatable). If r is present, then d must be repeatable.

The repeatable edit descriptors are:

I

Iw

Iw.d

O

Ow

Ow.d

Z

Zw

Zw.d

F

Fw

Fw.d

A

Aw

L

Lw

E

Ew

Ew.d

Ew.d.e

Eew.dE

D

Dw

Dw.d

Dw.d.e

Dw.dEe

G

Gw

Gw.d

Gw.d.e

Gw.dEe

Here is a summary:

The nonrepeatable edit descriptors are:

See "Formatted I/O" for full details of these edit descriptors.

Description

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.

Repeat Factor

r must be a nonzero, unsigned, integer constant.

Repeatable Edit Descriptors

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.

Nonrepeatable Edit Descriptors

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:

Item Separator

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

Variable Format Expressions @

In general, any integer constant in a format can be replaced by an arbitrary expression enclosed in angle brackets:

1 FORMAT( < e > )

The n in an nH... edit descriptor cannot be a variable format expression.

Restrictions

The FORMAT statement label cannot be used in a GO TO, IF-arithmetic, DO, or alternate return.

Warnings

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.

Examples

Example 1: Some A, I, and F formats:


       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 ) 

Example 2: Variable format expressions:


       DO 100 N = 1, 50 
       ... 
1      FORMAT( 2X, F<N+1>.2 )