XL Fortran for AIX 8.1

Language Reference

FORMAT

Purpose

The FORMAT statement provides format specifications for input/output statements.

Format



>>-FORMAT--(--+------------------+--)--------------------------><
              '-format_item_list-'
 
 

format_item



>>-+-+---+--data_edit_desc---------+---------------------------><
   | '-r-'                         |
   +-control_edit_desc-------------+
   +-+---+--(--format_item_list--)-+
   | '-r-'                         |
   '-char_string_edit_desc---------'
 
 

r
is an unsigned, positive, integer literal constant that cannot specify a kind type parameter, or it is a scalar integer expression enclosed by angle brackets (< and >). It is called a repeat specification. It specifies the number of times to repeat the format_item_list or the data_edit_desc. The default is 1.

data_edit_desc
is a data edit descriptor

control_edit_desc
is a control edit descriptor

char_string_edit_desc
is a character string edit descriptor

Data Edit Descriptors

Forms Use Page
A
Aw
Edits character values "A (Character) Editing"
Bw
Bw.m
Edits binary values "B (Binary) Editing"
Ew.d
Ew.dEe
Ew.dDe *
Ew.dQe *
Dw.d
ENw.d
ENw.dEe
ESw.d
ESw.dEe
Qw.d *
Edits real and complex numbers with exponents "E, D, and Q (Extended Precision) Editing"
Fw.d Edits real and complex numbers without exponents "F (Real without Exponent) Editing"
Gw.d
Gw.dEe
Gw.dDe *
Gw.dQe *
Edits data fields of any intrinsic type, with the output format adapting to the type of the data and, if the data is of type real, the magnitude of the data "G (General) Editing"
Iw
Iw.m
Edits integer numbers "I (Integer) Editing"
Lw Edits logical values "L (Logical) Editing"
Ow
Ow.m
Edits octal values "O (Octal) Editing"
Q * Returns the count of characters remaining in an input record * "Q (Character Count) Editing"
Zw
Zw.m
Edits hexadecimal values "Z (Hexadecimal) Editing"
Note:
* IBM Extensions

where:

w
specifies the width of a field, including all blanks. It must be positive except in FORTRAN 95 Begins Fortran 95, where it can be zero for I, B, O, Z, and F edit descriptors on output. FORTRAN 95 Ends

m
specifies the number of digits to be printed

d
specifies the number of digits to the right of the decimal point

e
specifies the number of digits in the exponent field

w, m, d, and e can be:

You cannot specify kind parameters for w, m, d, or e.

+-------------------------------IBM Extension--------------------------------+

Note:

There are two types of Q data edit descriptor (Qw.d and Q):

extended precision Q
is the Q edit descriptor whose syntax is Qw.d

character count Q
is the Q edit descriptor whose syntax is Q

+----------------------------End of IBM Extension----------------------------+

Control Edit Descriptors

Forms Use Page
/
r /
Specifies the end of data transfer on the current record "/ (Slash) Editing"
: Specifies the end of format control if there are no more items in the input/output list ": (Colon) Editing"
$ * Suppresses end-of-record in output * "$ (Dollar) Editing" *
BN Ignores nonleading blanks in numeric input fields "BN (Blank Null) and BZ (Blank Zero) Editing"
BZ Interprets nonleading blanks in numeric input fields as zeros "BN (Blank Null) and BZ (Blank Zero) Editing"
kP Specifies a scale factor for real and complex items "P (Scale Factor) Editing"
S SS
Specifies that plus signs are not to be written "S, SP, and SS (Sign Control) Editing"
SP Specifies that plus signs are to be written "S, SP, and SS (Sign Control) Editing"
Tc Specifies the absolute position in a record from which, or to which, the next character is transferred "T, TL, TR, and X (Positional) Editing"
TLc Specifies the relative position (backward from the current position in a record) from which, or to which, the next character is transferred "T, TL, TR, and X (Positional) Editing"
TRc Specifies the relative position (forward from the current position in a record) from which, or to which, the next character is transferred "T, TL, TR, and X (Positional) Editing"
oX Specifies the relative position (forward from the current position in a record) from which, or to which, the next character is transferred "T, TL, TR, and X (Positional) Editing"
Note:
* IBM Extension

where:

r
is a repeat specifier. It is an unsigned, positive, integer literal constant.

k
specifies the scale factor to be used. It is an optionally signed, integer literal constant.

c
specifies the character position in a record. It is an unsigned, nonzero, integer literal constant.

o
is the relative character position in a record. It is an unsigned, nonzero, integer literal constant.

+-------------------------------IBM Extension--------------------------------+

r, k, c, and o can also be expressed as an arithmetic expression enclosed by angle brackets (< and >) that evaluates into an integer value.

+----------------------------End of IBM Extension----------------------------+

Kind type parameters cannot be specified for r, k, c, or o.

Character String Edit Descriptors

Forms Use Page
nHstr Outputs a character string (str) "H Editing"
'str'
"str"
Outputs a character string (str) "Apostrophe/Double Quotation Mark Editing (Character-String Edit Descriptor)"

n
is the number of characters in a literal field. It is an unsigned, positive, integer literal constant. Blanks are included in character count. A kind type parameter cannot be specified.

Rules

When a format identifier in a formatted READ, WRITE, or PRINT statement is a statement label or a variable that is assigned a statement label, the statement label identifies a FORMAT statement.

The FORMAT statement must have a statement label. FORMAT statements cannot appear in block data program units, interface blocks, the scope of a module, or derived-type definitions.

Commas separate edit descriptors. You can omit the comma between a P edit descriptor and an F, E, EN, ES, D, G, or Q (both extended precision and character count) edit descriptor immediately following it, before a slash edit descriptor when the optional repeat specification is not present, after a slash edit descriptor, and before or after a colon edit descriptor.

FORMAT specifications can also be given as character expressions in input/output statements.

XL Fortran treats uppercase and lowercase characters in format specifications the same, except in character string edit descriptors.

Character Format Specification

When a format identifier (see READ) in a formatted READ, WRITE, or PRINT statement is a character array name or character expression, the value of the array or expression is a character format specification.

If the format identifier is a character array element name, the format specification must be completely contained within the array element. If the format identifier is a character array name, the format specification can continue beyond the first element into following consecutive elements.

Blanks can precede the format specification. Character data can follow the right parenthesis that ends the format specification without affecting the format specification.

+-------------------------------IBM Extension--------------------------------+

Variable Format Expressions

Wherever an integer constant is required by an edit descriptor, you can specify an integer expression in a FORMAT statement. The integer expression must be enclosed by angle brackets (< and >). You cannot use a sign outside of a variable format expression. The following are valid format specifications:

      WRITE(6,20) INT1
20    FORMAT(I<MAX(20,5)>)
 
      WRITE(6,FMT=30) INT2, INT3
30    FORMAT(I<J+K>,I<2*M>)

The integer expression can be any valid Fortran expression, including function calls and references to dummy arguments, with the following restrictions:

The value of the expression is reevaluated each time an input/output item is processed during the execution of the READ, WRITE, or PRINT statement.

+----------------------------End of IBM Extension----------------------------+

Examples

      CHARACTER*32 CHARVAR
      CHARVAR="('integer: ',I2,'  binary: ',B8)"  ! Character format specification
      M = 56
      J = 1                                       !     OUTPUT:
      X = 2355.95843                              !
      WRITE (6,770) M,X                           !  56   2355.96
      WRITE (6,CHARVAR) M,M                       ! integer: 56  binary: 00111000
      WRITE (6,880) J,M                           !  1
                                                  ! 56
770   FORMAT(I3, 2F10.2)
880   FORMAT(I<J+1>)
      END

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]