FORMAT statement
Standard: (F77) (F90) F95 F2003 F2008   Example Program
<Syntax>
FORMAT ( [ format-list ] [ infinite-repeat-item ] )

format-list ::= format-item [ , format-item ]...
format-item::=[ repeat ] data-edit
 | [ repeat ] ( format-list )
 | other-edit
infinite-repeat-item ::= * ( format-list )
data-edit::=iboz-edit w [ . m ]
 | fd-edit w [ . d ]
 | eg-edit w . d [ E e ]
 | L w
 | A [ w ]
 | G0 [ . d ]
other-edit::=t-edit digit-string
 | digit-string px-edit
 | digit-stringHtext
 | character-string
 | rounding-edit
 | misc-edit

repeat, w, m, d and e are all digit-string.
iboz-edit ::= I  |  B  |  O  |  Z
fd-edit ::= F  |  D
eg-edit ::= E  |  EN  |  ES  |  G
t-edit ::= T  |  TR  |  TL
px-edit ::= P  |  X  |  /
rounding-edit ::= RC  |  RD  |  RN  |  RP  |  RU  |  RZ
misc-edit ::= BN  |  BZ  |  DC  |  DP  |  S  |  SP  |  SS  |  /  |  :

In digit-stringHtext, the text following the H has exactly the number of characters specified by its digit-string; this edit descriptor was deleted in Fortran 95 because it is error-prone and less convenient than simply using a character string.

Note: the comma between adjacent format-items may be omitted only as follows:
  • between a P descriptor and a following D, E, EN, ES, F or G descriptor (prior to Fortran 2003, this is only allowed when the optional repeat is not present);
  • before a / descriptor that has no preceding digit-string;
  • after a / descriptor;
  • before or after a : descriptor.

    The field width w is used to indicate minimal width editing for the B, F, I, O and Z edit descriptors. In all other cases, w must be positive.

  • <Semantics>

    The FORMAT statement specifies a format, which may be used in a data transfer statement (PRINT, READ and WRITE) for formatted input/output. The FORMAT statement must be labelled, and it is this label that is specified in the FMT= specifier. The interpretation of each edit descriptor is given in the table below.

    Note that an explicit format may also be specified as a character string; in this case the character string is interpreted in the same way as the FORMAT statement. Also, list-directed (FMT=*) and namelist formatting (NML=namelist-name) is possible instead of explicit formatting. These two cases leave the formatting details up to the compiler and are not under user control.

    In Fortran 2008, an infinite-repeat-item can appear at the end of the format specification. As the name implies, this acts the same as an infinite repeat count — it repeats until terminated by exhaustion of the list of effective items on a colon or data edit descriptor; a data edit descriptor such as I must appear inside the infinite repetition.

    Format Item Semantics Example
    Character string Output of specified character string 'abc'
    / Advance to next record /
    : Finish if no data items left in input list :
    A Character type data transfer A10
    B Integer type data transfer, binary radix B8
    BN Blanks in numeric input are null (ignored) BN
    BZ Blanks in numeric input are treated as zeros BZ
    D Real type data transfer, exponential form with letter D D12.4
    DC Change decimal edit mode to 'COMMA' DC
    DP Change decimal edit mode to 'POINT' DP
    E Real type data transfer, exponential form E12.4
    EN Real type data transfer, engineering notation (exponent divisible by 3) EN12.4
    ES Real type data transfer, scientific notation (first digit non-zero) ES12.4
    F Real type data transfer, no exponent F6.3
    G Generalised data transfer, form varies G16.8
    G0 Generalised minimal width data transfer, form varies G0.7
    H Output of specified text nHa1a2...an
    I Integer type data transfer, decimal radix I9
    L Logical type data transfer L1
    O Integer type data transfer, octal radix O3
    P Set scale factor to k kP
    RC Compatible rounding (halves away from zero) RC
    RD Round down (towards −∞) RC
    RN Round to nearest (halves to even) RN
    RP Processor-dependent rounding RP
    RU Round up (towards +∞) RU
    RZ Round towards zero RZ
    S Processor-dependent “+” on positive values S
    SP Produce “+” on positive values SP
    SS Suppress “+” on positive values SS
    T Move to position n in the current record T10
    TL Move n positions to the left in the current record T10
    TR Move n positions to the right in the current record TR10
    X Move right n places 6X
    Z Integer type data transfer, hexadecimal radix Z8
    <Related>
    ASSIGN statement, BACKSPACE statement, CLOSE statement, DECIMAL= specifier, ENDFILE statement, NML= specifier, OPEN statement, PRINT statement, READ statement, REWIND statement, SIGN= specifier, WRITE statement