Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

FORMAT

Statement: Specifies the form of data being transferred and the data conversion (editing) required to achieve that form.

FORMAT (format-list)

format-list

Is a list of one or more of the following edit descriptors, separated by commas or slashes (/):

Data edit descriptors:

I, B, O, Z, F, E, EN, ES, D, G, L, and A.

Control edit descriptors:

T, TL, TR, X, S, SP, SS, BN, BZ, P, :, /, $, \, and Q.

String edit descriptors:

H, 'c', and "c", where c is a character constant.

A comma can be omitted in the following cases:

  • Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor

  • Before a slash (/) edit descriptor when the optional repeat specification is not present

  • After a slash (/) edit descriptor

  • Before or after a colon (:) edit descriptor

Edit descriptors can be nested and a repeat specification can precede data edit descriptors, the slash edit descriptor, or a parenthesized list of edit descriptors.

Description

A FORMAT statement must be labeled.

Named constants are not permitted in format specifications.

If the associated I/O statement contains an I/O list, the format specification must contain at least one data edit descriptor or the control edit descriptor Q.

Blank characters can precede the initial left parenthesis, and additional blanks can appear anywhere within the format specification. These blanks have no meaning unless they are within a character string edit descriptor.

When a formatted input statement is executed, the setting of the BLANK specifier (for the relevant logical unit) determines the interpretation of blanks within the specification. If the BN or BZ edit descriptors are specified for a formatted input statement, they supersede the default interpretation of blanks. (For more information on BLANK defaults, see the OPEN statement.

For formatted input, you can use the comma as an external field separator. The comma terminates the input of fields (for noncharacter data types) that are shorter than the number of characters expected. It can also designate null (zero-length) fields.

The first character of a record transmitted to a line printer or terminal is typically used for carriage control; it is not printed. The first character of such a record should be a blank, 0, 1, $,+, or ASCII NUL. Any other character is treated as a blank.

A format specification cannot specify more output characters than the external record can contain. For example, a line printer record cannot contain more than 133 characters, including the carriage control character.

Whenever an edit descriptor requires an integer constant, you can specify an expression enclosed in angle brackets (< and >). For more information, see Variable Format Expressions.

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

  • Expressions cannot be used with the H edit descriptor.

  • Expressions cannot contain graphical relational operators (such as > and <).

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.

The following tables summarize the different kinds of edit descriptors:

Data Edit Descriptors

Code

Form 1

Effect

A

A[w]

Transfers character or Hollerith values.

B

Bw[.m]

Transfers binary values.

D

Dw.d

Transfers real values with D exponents.

E

Ew.d[Ee]

Transfers real values with E exponents.

EN

ENw.d[Ee]

Transfers real values with engineering notation.

ES

ESw.d[Ee]

Transfers real values with scientific notation.

F

Fw.d

Transfers real values with no exponent.

G

Gw.d[Ee]

Transfers values of all intrinsic types.

I

Iw[.m]

Transfers decimal integer values.

L

Lw

Transfers logical values: on input, transfers characters; on output, transfers T or F.

O

Ow[.m]

Transfers octal values.

Z

Zw[.m]

Transfers hexadecimal values.

1w is the field width.

m is the minimum number of digits that must be in the field (including zeros).

d is the number of digits to the right of the decimal point.

E is the exponent field.

e is the number of digits in the exponent.

Control Edit Descriptors

Code

Form

Effect

BN

BN

Ignores embedded and trailing blanks in a numeric input field.

BZ

BZ

Treats embedded and trailing blanks in a numeric input field as zeros.

P

kP

Interprets certain real numbers with a specified scale factor.

Q

Q

Returns the number of characters remaining in an input record.

S

S

Reinvokes optional plus sign (+) in numeric output fields; counters the action of SP and SS.

SP

SP

Writes optional plus sign (+) into numeric output fields.

SS

SS

Suppresses optional plus sign (+) in numeric output fields.

T

Tn

Tabs to specified position.

TL

TLn

Tabs left the specified number of positions.

TR

TRn

Tabs right the specified number of positions.

X

nX

Skips the specified number of positions.

$

$

Suppresses trailing carriage return during interactive I/O.

:

:

Terminates format control if there are no more items in the I/O list.

/

[r]/

Terminates the current record and moves to the next record.

\

\

Continues the same record; same as $.

String Edit Descriptors

Code

Form

Effect

H

nHch[ch...]

Transfers characters following the H edit descriptor to an output record.

'c' 2

'c'

Transfers the character literal constant (between the delimiters) to an output record.

2 These delimiters can also be quotation marks (").

Example

   INTEGER width, value
   width = 2
   read (*,1) width, value
!  if the input is 3123, prints 123, not 12
1  format ( i1, i<width>)
   print *, value
   END