Chapter 2. Input and Output (I/O) Editing

Usually, data is stored in memory as the values of variables in some binary form. On the other hand, formatted data records in a file consist of characters. Thus, when data is read from a formatted record, it must be converted from characters to the internal representation. When data is written to a formatted record, it must be converted from the internal representation into a string of characters.

A format specification provides the information necessary to determine how these conversions are to be performed. The format specification is basically a list of edit descriptors, of which there are three general types: data edit descriptors, control edit descriptors, and string edit descriptors. There is a data edit descriptor for each data value in the input/output (I/O) list of the data transfer statement. Control edit descriptors specify the spacing and position within a record, new records, interpretation of blanks, and plus sign suppression. String edit descriptors transfer strings of characters represented in format specifications to output records.

The format reference that indicates where to find the format can be a statement label that identifies a FORMAT statement, or it can be a character expression giving the format directly. Using either method is called explicit formatting.

There are two other cases where formatting of a different sort applies. These are list-directed and namelist formatting. Formatting (that is, conversion) occurs without specifically providing the editing information usually contained in a format specification. In these cases, the editing or formatting is implicit; that is, the details about the width of fields, forms of output values, and location of output fields within the records is determined by the type of each data value in the I/O list.

This chapter describes the following information:

Table 2-1 and Table 2-2, list the control and data edit descriptors and provide a brief description of each.

Table 2-1. Summary of control edit descriptors

Descriptor

Description

BN

Ignore nonleading blanks in numeric input fields

BZ

Treat nonleading blanks in numeric input fields as zeros

S

Do not print optional plus sign

SP

Print plus sign

SS

Do not print plus sign

T

Tab to specified position

TL

Tab left the specified number of positions

TR

Tab right the specified number of positions

X

Tab right the specified number of positions

$ or \

Suppress carriage control (EXTENSION)

/

End current record and move to beginning of next record

:

Stop format processing if no further input/output list items exist

P

Interpret certain real numbers with a specified scale factor



Note: The Fortran standard does not specify the $ or \ control edit descriptors.


Table 2-2. Summary of data edit descriptors

Descriptor

Description

A

Convert data of type character

B

Convert data of type integer to/from a binary base

D

Convert data of type real; same as E edit descriptor

E

Convert data of type real with an exponent

EN

Convert data of type real to engineering notation

ES

Convert data of type real to scientific notation

F

Convert data of type real with no exponent on output

G

Convert data of all intrinsic types

I

Convert data of type integer

L

Convert data of type logical

O

Convert data of type integer to/from an octal base

Q

Return number of characters left in record (EXTENSION)

R

Convert data of type Hollerith (EXTENSION)

Z

Convert data of type integer to/from a hexadecimal base



Note: The Fortran standard does not specify the Q or R edit descriptors.

Table 2-3, Table 2-4, Table 2-5, and Table 2-6, show the use of the CF90 and MIPSpro 7 Fortran 90 compilers' edit descriptors with all intrinsic data types. In these tables:

Table 2-3. Default compatibility between data types and data edit descriptors

Data types

Q

Z

R

O

L

I

G

F

ES

EN

E

D

B

A

Integer

I

I,O

I,O

I,O

NA

I,O

I,O

NA

NA

NA

NA

NA

I,O

I,O

Real

NA

I,O

I,O

I,O

NA

NA

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

Complex

NA

I,O

I,O

I,O

NA

NA

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

Logical

NA

I,O

I,O

I,O

I,O

NA

I,O

NA

NA

NA

NA

NA

I,O

I,O

Character

NA

NA

NA

NA

NA

NA

I,O

NA

NA

NA

NA

NA

NA

I,O

Table 2-4 shows the restrictions for the various data types that are allowed when you set the FORMAT_TYPE_CHECKING environment variable to RELAXED. Not all data edit descriptors support all data sizes; for example, you cannot read/write a 16-byte real variable with an I edit descriptor.

Table 2-4. RELAXED compatibility between data types and data edit descriptors

Data types

Q

Z

R

O

L

I

G

F

ES

EN

E

D

B

A

Integer

I

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

NA

I,O

I,O

Real

NA

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

Complex

NA

I,O

I,O

I,O

NA

NA

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

Logical

NA

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

I,O

NA

I,O

I,O

Character

NA

NA

NA

NA

NA

NA

I,O

NA

NA

NA

NA

NA

NA

I,O

Table 2-5, shows the restrictions for the various data types that are allowed when you set the FORMAT_TYPE_CHECKING environment variable to STRICT77.

Table 2-5. STRICT77 compatibility between data types and data edit descriptors

Data types

Q

Z

R

O

L

I

G

F

ES

EN

E

D

B

A

Integer

NA

I,O

NA

I,O

NA

I,O

NA

NA

NA

NA

NA

NA

I,O

NA

Real

NA

NA

NA

NA

NA

NA

I,O

I,O

NA

NA

I,O

I,O

NA

NA

Complex

NA

NA

NA

NA

NA

NA

I,O

I,O

NA

NA

I,O

I,O

NA

NA

Logical

NA

NA

NA

NA

I,O

NA

NA

NA

NA

NA

NA

NA

NA

NA

Character

NA

NA

NA

NA

NA

NA

NA

NA

NA

NA

NA

NA

NA

I,O

Table 2-6, shows the restrictions for the various data types that are allowed when you set the FORMAT_TYPE CHECKING environment variable to STRICT90 or STRICT95.

Table 2-6. STRICT90 and STRICT95 compatibility between data types and data edit descriptors

Data types

Q

Z

R

O

L

I

G

F

ES

EN

E

D

B

A

Integer

NA

I,O

NA

I,O

NA

I,O

I,O

NA

NA

NA

NA

NA

I,O

NA

Real

NA

NA

NA

NA

NA

NA

I,O

I,O

I,O

I,O

I,O

I,O

NA

NA

Complex

NA

NA

NA

NA

NA

NA

I,O

I,O

I,O

I,O

I,O

I,O

NA

NA

Logical

NA

NA

NA

NA

I,O

NA

I,O

NA

NA

NA

NA

NA

NA

NA

Character

NA

NA

NA

NA

NA

NA

I,O

NA

NA

NA

NA

NA

NA

I,O



Note: The Fortran standard does not describe the FORMAT_TYPE_CHECKING environment variable. The FORMAT_TYPE_CHECKING environment variable is examined only upon program startup. Changing the value of this environment variable during program execution has no effect.


Explicit Formatting

Explicit formatting information can be provided in one of the following ways:

  • Contained in a FORMAT statement, as follows:

        WRITE (6, 100) LIGHT, AND, HEAVY
    100 FORMAT (F10.2, I5, E16.8)

  • Given as the value of a character expression, as follows:

    WRITE (6, '(F10.2, I5, E16.8)' ) LIGHT, AND, HEAVY

FORMAT Statement

The FORMAT statement is defined as follows:

 

format_stmt

is

FORMAT format_specification

 

format_specification

is

([format_item_list])

As the following sample format shows, the FORMAT statement must be labeled. The label is used in the I/O statement to reference a particular FORMAT statement.

label FORMAT ([format_item_list])

Each I/O statement in a program can reference a unique FORMAT statement, or a FORMAT statement can be used in more than one I/O statement.

Character Expression Format Specifications

A character expression can be used in the I/O statement as a format specification. The leading part of the character expression must be a valid format specification including the parentheses; that is, the value of the expression must be such that the first nonblank character is a left parenthesis, followed by a list of valid format items, followed by a right parenthesis.

All variables in the character expression must be defined when the I/O statement is executed.

Characters can appear following the last right parenthesis in the character expression; they have no effect.

If the expression is a character array, the format is scanned in array element order. For example, the following format specification is valid (where A is a character array of length at least 8 and size at least 2):

A(1) = '(1X,I3,'
A(2) = ' I7, I9)'
PRINT  A, MUTT, AND, JEFF

If the expression is an array element, the format must be entirely contained within that element.

If the expression is a character variable, it or any part of it must not be redefined or become undefined during the execution of the I/O statement.

If the expression is a character constant delimited by apostrophes, two apostrophes must be written to represent each apostrophe in the format specification. If a format specification contains, in turn, a character constant delimited by apostrophes, there must be two apostrophes for each of the apostrophe delimiters, and each apostrophe within the character constant must be represented by four apostrophes (see the example below). If quotes are used for the string delimiters and quotes are used within the string, a similar doubling of the quote marks is required. One way to avoid nested delimiter problems is to use delimiters different from the characters within the format specification, if possible. Another way to avoid the problem is to put the character expression in the I/O list instead of the format specification. This is shown in the second line of the following example, where A16 is a character edit descriptor specifying a field width of 16 positions:

PRINT '(''I can''''t hear you'')'
PRINT "(A16)", "I can't hear you"

The preceding example can be written without a field width (character count), as in the following example:

PRINT "(A)", "I can't hear you"

When a character expression is used as a format specification, errors in the format specification might not be detected until the program is executed because the format specification may not be complete or known until the data transfer statement is executed.

Format Specifications

Each item in the format item list of a format specification is an edit descriptor, which can be a data edit descriptor, control edit descriptor, or character string edit descriptor. Each data list item must have a corresponding data edit descriptor.

Blanks can be used freely in format specifications without affecting the interpretation of the edit descriptors, both in the free and fixed source forms. Named constants are not allowed in format specifications because they would create ambiguities in the interpretation of the format specifications. For example, if N12 were a named integer constant with value 15, the engineering format edit descriptor E N12.4 could be interpreted as the edit descriptor EN12.4 or E15.4.

The format_item is defined as follows:

 

format_item

is

[r]data_edit_desc

 

 

or

control_edit_desc

 

 

or

char_string_edit_desc

 

 

or

[r] (format_item_list)

 

r

is

int_literal_constant

In the preceding format, r must be a default integer literal constant and is called a repeat factor. If a repeat factor is not present, it is as if it were present with the value of 1.

r must not have a kind value specified for it. r must be a positive integer.

The comma between edit descriptors can be omitted in the following cases:

  • Between the scale factor (P) and the numeric edit descriptors F, E, EN, ES, D, or G

  • Before a new record indicated by a slash when there is no repeat factor present

  • After the slash for a new record

  • Before or after the colon edit descriptor

Blanks can be used in the following cases:

  • Before the first left parenthesis.

  • Anywhere in the format specification. Blanks within a character edit descriptor are significant. Blanks outside of a character edit descriptor are not significant.

Edit descriptors can be nested within parentheses, or an edit descriptor can be preceded by a repeat factor indicating that the edit descriptor is repeated. A parenthesized list of edit descriptors can also be preceded by a repeat factor; this indicates that the entire list is to be repeated.

The following examples illustrate many of the edit descriptors that are described in the following sections:

100 FORMAT (2(5E10.1, I10) / (1X, SP, I7, ES15.2))
110 FORMAT (I10, F14.1, EN10.2)
120 FORMAT (TR4, L4, 15X, A20)
130 FORMAT ('MORE SNOW')
140 FORMAT (9X, 3A5, 7/ 10X, 3L4)

Data Edit Descriptor Form

Data edit descriptors specify the conversion of values to and from the internal representation to the character representation in the formatted record of a file. The data edit descriptors are defined as follows:

 

data_edit_desc

is

Iw[.m]

 

 

or

Bw[.m]

 

 

or

Ow[.m]

 

 

or

Zw[.m]

 

 

or

Fw.d

 

 

or

Ew.d[Ee]

 

 

or

ENw.d[Ee]

 

 

or

ESw.d[Ee]

 

 

or

Gw.d[Ee]

 

 

or

Lw

 

 

or

A[w]

 

 

or

Dw.d

EXT

 

or

Dw.dEe

EXT

 

or

Rw

EXT

 

or

Q

 

m

is

int_literal_constant

 

d

is

int_literal_constant

 

e

is

int_literal_constant



Note: The Fortran standard does not specify the Dw.dEe, Rw, or Q data edit descriptors.

The w, m, d, and e descriptors must be default integer literal constants. They have the following meanings:

Descriptor

Specification

w

The width of the field.

m

The least number of digits in the field.

d

The number of fractional digits in the field.

e

The number of digits in the exponent. Must be a positive number.

The w, m, d, and e descriptors must not have a kind value specified for them.

The I, B, O, Z, F, E, EN, ES, G, L, A, D, R, and Q edit descriptors indicate the manner of editing.

The meanings of the data edit descriptors are described in “File Positioning by Format Control”, through “Logical Editing”.

Control Edit Descriptor Form

Control edit descriptors determine the position, form, layout, and interpretation of characters transferred to and from formatted records in a file. The control edit descriptors are defined as follows:

 

control_edit_desc

is

position_edit_desc

 

 

or

[ r ] /

 

 

or

:

 

 

or

sign_edit_desc

 

 

or

k P

 

 

or

blank_interp_edit_desc

 

k

is

signed_int_literal_constant

 

position_edit_desc

is

T n

 

 

or

TL n

 

 

or

TR n

 

 

or

n X

EXT

 

or

$

EXT

 

or

\

 

n

is

int_literal_constant

 

sign_edit_desc

is

S

 

 

or

SP

 

 

or

SS

 

blank_interp_edit_desc

is

BN

 

 

or

BZ

The n and r descriptors must be default integer literal constants. k must be a signed default integer literal constant. n, k, and r must not have a kind value specified for them. k, n, and r have the following meanings:

Descriptor

Specification

k

A scale factor.

n

A position in the record to move, relative to the left tab limit, for descriptor T. Specifies the number of spaces to move for descriptors X, TR, and TL. n must be positive.

r

The repeat factor.

The control edit descriptors T, TL, TR, X, the dollar sign ($), and the backslash (\) are called position edit descriptors. The control edit descriptors S, SP, and SS are called sign edit descriptors. The control edit descriptors BN and BZ are called blank interpretation edit descriptors.


Note: The Fortran standard does not describe the dollar sign ($) or the backslash (\) as position edit descriptors.

In k P, k is called the scale factor.

T, TL, TR, X, $, slash (/), backslash (\), colon (:), S, SP, SS, P, BN, and BZ indicate the manner of editing and are described in detail in “Control Edit Descriptors”.

Character String Edit Descriptor Form

Character string edit descriptors specify character strings to be transmitted to the formatted output record of a file. The character string edit descriptors are defined as follows:

 

char_string_edit_desc

is

char_literal_constant

 

c

or

int_literal_constant

c must be a default integer literal constant and is a character count. c must not have a kind value specified for it. c must be positive.

The second form of the character edit descriptor is obsolescent.

The character string edit descriptors are described in detail in “Character String Edit Descriptors”.

Formatted Data Transfer

The format specification indicates how data is transferred by READ, WRITE, and PRINT statements. The data transfer typically involves a conversion of a data value. The particular conversion depends on the next data input or output item, along with the current edit descriptor in the format specification.

    READ (*, '(A7, I10, E16.8)' )  X, Y, Z
    WRITE (*, 100)  X, Y, Z
100 FORMAT (A7, I10, E16.3)

An empty format specification ( )is restricted to I/O statements with no items in the I/O data item list or a list of items all of which have zero size. A zero-length character string requires an A edit descriptor.

The effect on I/O of an empty format specification depends on whether the data transfer is advancing or nonadvancing, and on whether there is a current record. The effect is described by the following cases.

When the data transfer is advancing:

  • If there is no current record, then:

    • On input, skip the next record

    • On output, write an empty record

  • If there is a current record, then:

    • On input, skip to the end of the current record

    • On output, terminate the current record

When the data transfer is nonadvancing:

  • If there is no current record, then:

    • On input, move to the initial point of the next record

    • On output, create an empty record and move to its initial point

  • If there is a current record, then:

    • On input, there is no effect

    • On output, there is no effect

The following example program segment reads N character strings, each of length M, from a single record and then advances to the beginning of the next record:

DO I = 1, N
   READ (5, '(A1)', ADVANCE='NO') &
      (CHARS(I)(J:J), J = 1, M)
ENDDO
READ (5, '()', ADVANCE = 'YES')

The data and the edit descriptors are converted in a left-to-right fashion, except for repeated items, which are repeated until either the data items are exhausted or the repeat number is reached. A complex data item requires two data edit descriptors for data items of type real; that is, two of the edit descriptors E, F, D, ES, EN, or G. The two edit descriptors may be different.

Control edit descriptors and character edit descriptors do not require a corresponding data item in the list. The effect is directly on the record transferred. When the data items are completed, no further change is made to record on output, and no change is made to the position in the file on input.

Parentheses Usage

The effect of parentheses in a format specification depends on the nesting level of the parentheses.

When the rightmost right parenthesis of a complete format specification is encountered and there are no more data items, the I/O data transfer terminates. Remember that the format specification can also be given by a character string expression. In such a case, the right parenthesis matching the leftmost left parenthesis can be followed by any characters, including parentheses. None of these trailing characters are relevant to the rules and restrictions in this chapter. For example, the following character string can be used as a format specification in a character string, and the part after the first right parenthesis is ignored:

'(I5,E16.8,A5)  (This part is ignored)'

If there are more data items when the rightmost right parenthesis is encountered, format control continues beginning at the left parenthesis corresponding to the last preceding right parenthesis in the specification, if there is one, with an implied slash (/) to cause a new record to begin. If there is no preceding right parenthesis, the reversion is to the beginning of the format.

If there is a repeat factor encountered when reverting, the repeat before the parenthesis is reused.

Reversion does not affect the scale factors, the sign control edit descriptor, or blank interpretation. These remain in effect for the duration of the format action. Example:

CHR_FMT = '(I5, 4(3F10.2, 10X), E20.4)'

In the previous example, if the character string were used in a formatted output data transfer statement, the first output data item must be an integer. The remaining items must be of type real (or complex); 13 real values are written on the first record after the integer, and the next real values are written in each new record, 13 at a time, until the data items are exhausted. All but the last record will have 13 real values written, 3 real values using the F10.2 edit descriptor, 10 blanks, followed by 3 more real values and 10 blanks repeated 4 times in total, followed by a real value using the E20.4 edit descriptor. This behavior is described in more detail in the next section.

Correspondence between a Data-edit Descriptor and a List Item

The best way to describe how this correspondence is determined is to think of two markers, one beginning at the first item of the I/O data item list and the other beginning at the first left parenthesis of the format specification. Before describing how each marker proceeds through each list, the I/O data item list is considered to be expanded by writing out each element of an array, each component of a structure, each part (real and imaginary) of each item of type complex, and each iteration of each implied-DO list. The expanded item list is called the effective data item list, and each item in the list is called an effective item. Note that zero-sized arrays yield no effective items, but zero-length character objects yield effective items. Also, the format specification is considered expanded for each repeat factor preceding any data or slash edit descriptor but not a parenthesized format item list. If the data item list is nonempty, there must be at least one data edit descriptor in the format specification. Given the effective data item list and expanded format specification, the markers proceed as follows:

  1. The marker proceeds through the format specification until the first data edit descriptor or right parenthesis is encountered. Any control edit descriptor or string edit descriptor encountered before the first data edit descriptor is encountered is interpreted according to its definition, each possibly changing the position within the record or the position within the file, or changing the interpretation of data in the record or conversion of data to the record.

  2. If a data edit descriptor is encountered first, the effective data item pointed to by the marker in the data item list is transferred and converted according to the data edit descriptor, and the marker in the data item list proceeds to the next effective data item.

  3. If a right parenthesis is encountered and the right parenthesis is not the outermost one of the format specification, the repeat factor in front of the matching left parenthesis is reduced by one. If the reduced factor is nonzero, the marker scans right from this left parenthesis, looking for a data edit descriptor as above. If the repeat factor becomes zero, the format specification marker then proceeds right from the right parenthesis, again looking for a data edit descriptor. If the right parenthesis is the outermost right parenthesis, the marker reverts to the left parenthesis corresponding to the last preceding right parenthesis, if there is one; if there is no preceding right parenthesis, it reverts to the first left parenthesis of the format specification. Upon reversion, a slash edit descriptor is interpreted implicitly, and the format marker proceeds right from this left parenthesis, honoring any repeat factor in front of it.

  4. If no effective data item remains when a data edit descriptor is encountered or when a colon edit descriptor is encountered, the I/O operation terminates.

To illustrate how this works, consider the following example:

INTEGER  A(3)
COMPLEX  C
TYPE RATIONAL
   INTEGER  N, D
END TYPE
TYPE(RATIONAL)  R
   . . .
WRITE (*, &
     "('A and C appear on line 1, R appears on line 2' &
      / (1X, 3I5, 2F5.2) )" )  A, C, R

The data item list is first expanded as described above. The expanded data item list becomes the following:

A(1), A(2), A(3), REAL(C), AIMAG(C), R%N, R%D

The format specification is also expanded and becomes the following:

('A and C appear on line 1, R appears on line 2' &
   / (1X, I5, I5, I5, F5.2, F5.2) )

A marker is established in the data item list, which initially points at the item A(1). A marker is also established in the format specification and initially points to the first left parenthesis. The marker in the format specification proceeds right to the first edit descriptor, which is the first I5. In so doing, it sees the string edit descriptor (which is transferred to the output record), the slash edit descriptor (which causes the previous record to terminate and to begin a new record), and the position edit descriptor (which positions the record at the second character, blank filling the first character). The item A(1) is then converted according to the I5 specification and the converted value is transferred to the output record. The marker in the data item list is moved to A(2). The format specification marker is moved right to the second I5 edit descriptor, and A(2) is converted and transferred to the output record. Similarly, A(3), the real part of C, and the imaginary part of C are converted and transferred to the output record.

At this point, the data item list marker is pointing at R%N, and the format specification marker begins scanning after the second F5.2 edit descriptor looking for the next edit descriptor. The first right parenthesis is encountered and the scan reverts back to the corresponding left parenthesis. The repeat factor in front of this parenthesis is 1 by default and is reduced by 1 to 0. The marker in the format specification proceeds right from the first right parenthesis, encountering the outermost right parenthesis and then reverts to the left parenthesis before the edit descriptor 1X. As a result, an implicit slash edit descriptor is interpreted, causing the previous output record to be completed and a new record to be started. The format specification marker scans right looking for a data edit descriptor, which is the first I5. In the process of the scan right, the position edit descriptor is interpreted, which positions the file at the second character of the next record (and blank fills the skipped character).

Finally, the N and D components of R are converted and transferred to the output record, using the first two I5 edit descriptors. The data item list marker finds no further items, so the output operation terminates.

The following is an example of writing a zero-sized array and zero-length character string using formatted output data transfer:

REAL  A(10)
CHARACTER(4)  CHR
   . . .
WRITE(6, '()')  A(1:0)
WRITE(6, '(A4)')  CHR(4:3)

An empty format specification is allowed for the first WRITE statement, because the array to be printed is a zero-sized array section. The format specification in the second WRITE statement is required to have at least one A edit descriptor because the effective data item is a zero-length character string, not a zero-sized array. In the first case, an empty record is written, and in the second case, a record consisting of four blank characters is written.

File Positioning by Format Control

Assume that there is a current record being processed. After each data edit descriptor is used, the file position within that record is following the last character read or written by the particular edit descriptor. On output, after a string edit descriptor is used, the file is positioned within that record following the last character written. (See the description of the control edit descriptors T, TL, TR, X, backslash (\), and the dollar sign ($) for any special positioning within the current record; see the description of the slash edit descriptor for special positioning within the file.)

The remaining control edit descriptors do not affect the position within a record or within the file; they affect only the interpretation of the input characters or the form of the output character string or how subsequent edit descriptors are interpreted. The interpretation of the edit descriptors is not affected by whether the operation is an advancing or nonadvancing I/O operation.

Numeric Editing

There following edit descriptors cover numeric editing: B, D, E, EN, ES, F, G, I, O, and Z. The following rules apply to all of them:

On input:

  • Leading blanks are never significant.

  • Plus signs can be omitted in the input data.

  • A blank field is considered to be zero, regardless of the BN edit descriptor or the BLANK= specifier in effect.

  • Within a field, blanks are interpreted in a manner that depends on the BLANK= specifier default for preconnected files, the BLANK= specifier provided in an OPEN statement for the unit, or if there is a BN or BZ blank edit descriptor in effect.

  • In numeric fields that have a decimal point and correspond to F, E, EN, ES, D, or G edit descriptors, the decimal point in the input field overrides the placement of the decimal point specified by the edit descriptor specification.

  • Data input is permitted to have more digits of significance than can be used to represent a number.

  • The lowercase exponent letters e and d are equivalent to the corresponding uppercase exponent letters.

On output:

  • A positive or zero value may have a plus sign, depending on the sign edit descriptors used.

  • Negative floating-point values have a negative sign on systems that support IEEE floating-point arithmetic. Negative values on other systems have a negative sign unless the printed value would be zero.

    For example, suppose variable SMALL has the value -0.000314. On output, the characters transferred to output unit 6 by the following statements will contain a negative sign on systems that support IEEE floating-point arithmetic:

        WRITE(6,10)  SMALL
    10  FORMAT(F5.2)

    The field will be as follows on systems that support IEEE floating-point arithmetic:

    -0.00

    On other systems, the field will not contain a negative sign, and the output will be:

    b0.00

    On UNICOS and UNICOS/mk systems that support IEEE floating-point arithmetic, the field contains a negative sign. On IRIX systems, the field does not contain a negative sign.

    The following assign(1) command option can be specified for one or more external files to control the writing of the negative sign:

    assign -Z ON | OFF

    Example 1: The following assign(1) command specifies that a negative sign should not be written:

    assign -Z ON u:9

    Example 2: The following assign(1) command specifies that a negative sign should be written:

    assign -Z OFF u:9

    For more information, see assign(1).

  • The number is right justified in the field. Leading blanks may be inserted.

  • If the number or the exponent is too large for the field width specified in the edit descriptor, the entire output field is filled with asterisks.

  • Asterisks are not produced when the optional characters can be omitted and the output character string fits in the output field.


Caution: Certain machine instructions and compiler optimizations on IRIX systems can return an unexpected -0.0 if the operations involve the value 0.0.


Integer Editing

The Fortran standard states that the I/O list item corresponding to an integer edit descriptor must be of type integer, except for the G edit descriptor. The integer edit descriptors are as follows:

I[w[.m]]
B[w[.m]]
O[w[.m]]
Z[w[.m]]
G[w.d[Ee]]

w, m, d, and e have the following meanings:

Descriptor

Specification

w

The width of the field

m

The minimum number of digits in the field

d

The number of fractional digits in the field

e

The number of digits in the exponent

For both input and output:

  • The value of m must not exceed the value of w unless w is zero.

  • For an integer I/O list item, the edit descriptor Gw.d[Ee] follows the same rules as the Iw edit descriptor for the given value of w.


Note: The Fortran standard does not allow w to be zero for the G edit descriptor, nor does it permit w to be omitted for the I, B, O, Z, or G edit descriptors.

On input:

  • m has no effect on an input field.

  • For the I edit descriptor, the character string in the file must be an optionally signed integer constant, but it cannot have an underscore or a kind parameter value.

  • For the B, O, or Z edit descriptors, the character string must be a string of blanks, a sign, and digits of binary, octal, or hexadecimal base, respectively. For example, the character string corresponding to a B edit descriptor must not contain digits 2 through 9. The character string corresponding to an O edit descriptor must not contain the digits 8 or 9. The character string corresponding to a Z edit descriptor may consist of the digits 0 through 9, the letters A through F, or the letters a through f.


Note: The Fortran standard does not allow signed binary, octal, or hexadecimal values as input.

On output:

  • If m is not present, each edit descriptor behaves as if it were present with the value 1.

  • For the Iw.m edit descriptor with m positive, the field is w characters wide and consists of zero or more leading blanks, followed by an optional sign, followed by an unsigned integer consisting of at least m digits. Leading zeros pad an integer field until there are m digits.

  • For the Bw.0, Iw.0, Ow.0, and Zw.0 edit descriptors, if the output list item has the value 0, the field consists entirely of blanks.

  • For the B0.0, I0.0, O0.0, and Z0.0 edit descriptors, if the output list item has the value 0, the field consists of exactly one blank.

  • If m is not present and the value of the output list item is nonzero, the first digit will be nonzero; otherwise, the field consists of only one 0 digit with no sign character. Negative zero is never produced.

  • For the B, O, or Z edit descriptors, the rules for forming the output field for the values w and m are the same as for the I edit descriptor except that the signed integer must consist of digits from the binary, octal, or hexadecimal base, respectively. A negative value is indicated in the encoding of the digits written; that is, a minus sign is never written.

If the field width (w) is zero or is omitted, a default field width is used. Table 2-7, describes the default widths. The default field width is equal to the number of digits (binary, octal, decimal, or hexadecimal) necessary to display the largest possible value plus one for a leading blank and (I and G only) one for an optional sign.

Table 2-7. Default field widths for integer formats

Edit

Kind (or data size in bytes):

Descriptor

1

2

4

8

16

B

9

17

33

65

130

I

5

7

12

21

NA

G (for integer)

5

7

12

21

NA

O

5

8

13

24

45

Z

3

5

9

17

33

If the minimum digits (m) field is specified, the default field width is increased, if necessary, to allow for that minimum width.


Note: Not all data sizes are supported on all architectures. UNICOS systems do not support 1-, 2-, or 4-byte data types. UNICOS/mk systems do not support 1- or 2-byte data types. 16-byte data are printed with a space separating the two halves.


Real Editing

The F, E, EN, ES, and D edit descriptors specify editing for real and complex I/O list items. The G edit descriptor may also be used for real and complex items. Two such edit descriptors are required for each complex data item.

The forms of the edit descriptors for real values are as follows:

F[w.d]
E[w.d[Ee]]
EN[w.d[Ee]]
ES[w.d[Ee]]
D[w.d]
G[w.d[Ee]]
D[w.dEe] (EXTENSION)

Note: The Fortran standard does not describe the D[w.dEe] edit descriptor.

w, d, and e have the following meanings:

Descriptor

Specification

w

The width of the field

d

The number of fractional digits in the field

e

The number of digits in the exponent

If the field width, w, is zero or is omitted, the default field width is equal to the number of fractional digits plus the number of exponent digits plus six. This is the maximum number of additional characters added to the representation, and it includes a leading blank, an optional sign, an optional leading zero, a decimal point, the E exponent designator, and the exponent sign.

As Table 2-8, shows, the default number of fractional and exponent digits in the field depends on the data size and representation used.

Table 2-8. Default fractional and exponent digits

Data size and representation

w

d

e

4-byte (32-bit) IEEE

17

9

2

8-byte (64-bit) IEEE

26

17

3

8-byte (64-bit) Cray floating-point

26

16

4

16-byte (128-bit) IEEE

46

36

4

16-byte (128-bit) double double IEEE

43

34

3

16-byte (128-bit) Cray floating-point

40

30

4

The default values of d and e shown in Table 2-8, ensure that floating-point numbers can be read and written with no loss of precision and that the exponent fields are large enough for the largest possible exponents. Note that for F edit descriptors, an exponent is never printed, and the field width is not automatically adjusted for variables of larger magnitude.

Thus, a format specification of E, when used with a 4-byte (32-bit) IEEE floating-point value, is interpreted as E17.9E2.

The size of the fractional and exponent fields can, however, still be selected. For example, a format specification of E0.3E2 is interpreted as E11.3E2.

The default size of the fractional field can also be modified using the ZERO_WIDTH_PRECISION environment variable. This environment variable accepts the following values:

Value 

Action

PRECISION 

Sets the default fractional field width to the decimal precision of a number in the real number model as described on the MODELS(3i) man page.

HALF 

Sets the default fractional field width to half of the maximum precision shown in Table 2-8. Specifically, (d + 1)/2.


Note: The Fortran standard does not describe the ZERO_WIDTH_PRECISION environment variable. This environment variable is examined only upon program startup. Changing the value of the environment variable during program execution has no effect.


F Editing

The Fw.d editing converts to or from a string occupying w positions.

For both input and output:

  • d must not exceed w unless w is zero.

  • The value in the input field or the value transferred to the output field may be signed.


Note: The Fortran standard does not allow w to be zero or omitted for the D, E, EN, ES, or G edit descriptors.

On input:

  • d specifies the number of decimal places in the input value if a decimal point is not present in the input field.

  • The input field may be one of the following:

    • A signed integer or real literal constant but without an underscore and kind parameter value

    • A signed digit string followed by a sign followed by an unsigned digit string treated as an exponent

    • A signed digit string containing a decimal point followed by a sign followed by an unsigned digit string treated as an exponent

      Blanks may be freely inserted anywhere in the input field.

  • If the input field contains a decimal point, the value of d has no effect.

  • If there is no decimal point, a decimal point is inserted in front of the rightmost d digits of the nonexponent part, treating blanks as 0 digits or as if they were not present, according to the BLANK= specifier or the BZ or BN edit descriptor currently in effect.

    Consider the format specification F5.1. The following input data item is treated as the real number 19.9, if the BLANK= specifier is NULL or the BN edit descriptor is in effect, and is treated as the real number 1009.9 if the BLANK= specifier is ZERO or the BZ edit descriptor is in effect:

    1bb99

  • There might be more digits in the number than the internal representation can contain.

  • The number can contain an E or D indicating an exponent value; a field with a D exponent letter is processed identically to the same field with an E exponent letter. If there is no exponent field on input, the assumption is that the character string is followed by an exponent with the value -k where k is the scale factor established by a previous kP edit descriptor.

On output:

  • d specifies the number of digits after the decimal point.

  • The form of the output field consists of w positions comprised of leading blanks, if necessary, and an optionally signed real constant with a decimal point, rounded to d digits after the decimal point but with no exponent, underscore, or kind parameter value.

  • Leading zeros are not written unless the number is less than 1.

  • At least one zero is written if no other digits would appear.

  • The scale factor has no effect on F editing on output.

  • Negative zero is produced on UNICOS and UNICOS/mk systems that support IEEE floating-point arithmetic, but it is not produced on other systems. For more information on negative zero, see “Numeric Editing”.

  • An exponent is not printed, so large-magnitude variables require correspondingly larger field widths. If a variable is too large for the field width, a field of asterisks (*) is printed.

Example:

    READ (5, 100)  X, Y
100 FORMAT (F10.2, F10.3)

Assume the following input field:

bbbb6.42181234567890

The values assigned to X and Y are 6.4218 and 1234567.89, respectively. The value of d is ignored for X because the input field contains a decimal point.

E and D Editing

The Ew.d[Ee] , Dw.dEe, and Dw.d edit descriptors convert to and from a string occupying w positions. For the edit descriptors Ew.d[Ee], Dw.dEe, and Dw.d, the field representing the floating point number contains w characters, including an exponent.

For both input and output:

  • w is the field width, d is the number of places after the decimal, and e is the exponent width.

  • d and e must not exceed w unless w is zero.

On input:

  • The forms Ew.d[Ee], Dw.dEe, and Dw.d are the same as for Fw.d editing, where either E or D in the input data record may indicate an exponent. e has no effect on input.

On output:

  • The form of the output field for a scale factor of zero is as follows:

    [+ | -][0] . x1x2 ... xdexp

    The [+ | -] notation signifies a plus or a minus.

    x1x2... xd are the d most significant digits of the data value after rounding.

    exp is a decimal exponent having one of the forms specified in Table 2-9, where each zi is a decimal digit.

    Table 2-9. Forms for the exponent exp in E and D editing

    Edit descriptor

    Absolute value of exponent

    Form of exponent

    E[w.d]

    | exp | .LE. 99

    E[+ | -]z1z2

     

    99 < | exp | .LE. 999

    [+ | -]z1z2z3

     

    999 < | exp | .LE. 2466

    [+ | -]z1z2z3z4

    Ew.dEe

    | exp | .LE. 10e - 1

    E[+ | -]z1z2. . . ze

    Dw.d

    | exp | .LE. 99

    E[+ | -]z1z2

     

    99 < | exp | .LE. 999

    [+ | -]z1z2z3

     

    999 < | exp | .LE. 2466

    [+ | -]z1z2z3z4

    Dw.dEe

    | exp | .LE. 10e - 1

    E[+ | -]z1z2. . . ze



Note: The Fortran standard restricts the use of Ew.d and Dw.d to an exponent less than or equal to 999. The Ew.dEe form must be used.


  • The sign in the exponent is always written.

  • Plus is used for zero exponents.

  • A scale factor kP can be used to specify the number of digits to the left of the decimal point, with the exponent adjusted accordingly; that is, the scale factor k controls the decimal normalization. If -d < k .LE. 0, the output field contains the decimal point, exactly | k | leading zeros, and d - | k | significant digits. If 0 < k < d < + 2, the output field contains exactly k significant digits to the left of the decimal point and d - k + 1 significant digits to the right of the decimal point. Other values of k are not permitted; that is, those values of k that will produce no digits to the left of the decimal point or specify fewer than zero digits to the right of the decimal point. The output field will contain w asterisks.

  • The form of zero on output always contains a decimal point, d zero digits, and an exponent of 4 characters whose digits are zero.

Consider the following example:

    WRITE (6, 105)  Y, Z
105 FORMAT (E15.3,4PD15.3)

If the values of Y and Z are -21.2 and 26542.1232 respectively, the output record produced is as follows:

bbbbb-0.212E+02bbb2654.212E+01

Engineering Edit Descriptor EN

The EN edit descriptor converts to or from a string using engineering notation for a value occupying w positions.

On input:

  • The form ENw.d[Ee] is the same as for Fw.d editing.

On output:

  • The output of the number is in the form of engineering notation, where the exponent is divisible by 3 and the absolute value of the significand is 1000 > | significand | .GE. 1. This is the same form as the E edit descriptor, except for these exponent and significand differences.

        WRITE (6, 110)  B
    110 FORMAT (EN13.3)

    If the value of B is 0.212, the output record produced is as follows:

    bb212.000E-03

  • The form of zero is the same as noted for the E edit descriptor except that there is exactly one zero digit before the decimal point.

  • The form of the output field is as follows:

    [+ | -]yyy.x1x2 ... xdexp

The [+ | -] notation signifies a plus or a minus.

yyy are the 1 to 3 decimal digits representing the most significant digits of the value of the data after rounding (yyy is an integer such that 1 .LE. yyy < 1000 or, if the output value is zero, yyy = 0).

x1x2 ... xdexp are the d next most significant digits of the value of the data after rounding. If the output value is zero, the xi are all 0.

exp is a decimal integer, divisible by 3, representing the exponent and must have one of the forms shown in Table 2-10, where each zi is a decimal digit.

Table 2-10. Forms for the exponent exp in EN editing

Edit descriptor

Absolute value of exponent

Form of exponent

ENw.d

| exp | .LE. 99

E[+ | -]z1z2

 

99 < | exp | < 999

[+ | -]z1z2z3

 

999 < | exp | .LE. 2466

[+ | -]z1z2z3z4

ENw.dEe

| exp | .LE. 10 e - 1

E[+ | -]z1z2. . . ze


  • The sign in the exponent is always written. A plus sign is written if the exponent value is zero. The form ENw.dEe must be used with a sufficiently large value of e if |exp| > 999.

    Internal value 

    Output field using SS, EN12.3

    6.421 

    6.421E+00

    -.5 

    -500.000E-03

    .00217 

    2.170E-03

    4721.3 

    4.721E+03

Scientific Edit Descriptor ES

The scientific edit descriptor ES converts to or from a string using scientific notation for a value occupying w positions.

On input:

  • The form ESw.d[Ee] is the same as for Fw.d editing.

On output:

  • The output of the number is in the form of scientific notation, where the absolute value of the significand is 10 > | significand | .GE. 1. This is the same form as the E edit descriptor, except for the significand difference. Example:

        WRITE (6, 110)  B
    110 FORMAT (ES12.3)

    If the value of B is 0.12345678, the output record produced is as follows:

    bbb1.235E-01

  • The form of zero is the same as noted for the EN edit descriptor.

  • The form of the output field is as follows:

    [+ | -]y.x1x2 ... xdexp

    The [+ | -] notation signifies a plus or a minus.

    y is a decimal digit representing the most significant digit of the value of the data after rounding (y is an integer such that 1 .LE. y < 10 or, if the output value is zero, y = 0).

    x1x2 ... xd are the d next most significant decimal digits of the value of the data after rounding. If the output value is zero, the xi are all 0.

    exp is a decimal exponent of one of the forms, given in Table 2-11, where each zi is a decimal digit.

    Table 2-11. Forms for the exponent exp in ES editing

    Edit descriptor

    Absolute value of exponent

    Form of exponent

    ESw.d

    | exp | .LE. 99

    E[+ | -]z1z2

     

    99 < | exp | .LE. 999

    [+ | -]z1z2z3

     

    999 < | exp | .LE. 2466

    [+ | -]z1z2z3z4

    ESw.dEe

    | exp | .LE. 10e - 1

    E[+ | -]z1z2. . . ze


  • The sign in the exponent is always written.

  • A plus sign is written if the exponent value is zero.

  • The form ESw.dEe must be used with a sufficiently large value of e if |exp| > 999.

    Internal value 

    Output field using SS, ES12.3

    6.421 

    6.421E+00

    -.5 

    -5.000E-01

    .00217 

    2.170E-03

    4721.3 

    4.721E+03

Complex Editing

Complex editing follows the rules for numeric editing. Editing of complex numbers requires two real edit descriptors, the first one for the real part and the second one for the imaginary part. Different edit descriptors may be used for the two parts. Control and character string edit descriptors can be inserted between the edit descriptors for the real and imaginary parts. Example:

COMPLEX CM(2)
READ(5, "(4E7.2)") (CM(I), I = 1, 2)

Assume that the input record is as follows:

bb55511bbb2146bbbb100bbbb621

The values assigned to CM(1) and CM(2) are 555.11 + 21.46i and 1.0 + 6.21i, respectively.

Generalized Editing of Real Data

Gw.d[Ee] converts to or from a string using generalized editing. The form for generalized editing is determined by the magnitude of the value of the number.

On input:

  • The Gw.d[Ee] edit descriptor is the same as the Fw.d edit descriptor.

On output:

  • Assume that N is the magnitude of a number to be printed using a G edit descriptor. If N = 0 and d is not zero, or if N is approximately between 0.1 and 10Table 2-12, specifies the form of the output, where n is 4 for Gw.d and n is e + 2 for Gw.dEe. A kP scale factor has no effect.

  • If N is outside this range, or if N is identically zero and d is zero, output editing with the edit descriptor kPGw.d[Ee] is the same as that with kPEw.d[Ee] .

Table 2-12. The form of the output using a G edit descriptor for a number of magnitude N

Magnitude of data[a]

s

t

N = 0

w - n[b]

d - 1

0.1 - 0.5 x 10-d-1 .LE. N < 1 - 0.5 x 10-d

w - n

d

1 - 0.5 x 10-d .LE. N < 10 - 0.5 x 10-d+1

w - n

d - 1

10 - 0.5 x 10-d+1 .LE. N < 100 - 0.5 x 10-d+2

w - n

d - 2

...

...

 

10d-2 - 0.5 x 10-2 .LE. N < 10d-1 - 0.5 x 10-1

w - n

1

10d-1 - 0.5 x 10-1 .LE. N < 10d - 0.5

w - n

0

[a] Assume that the equivalent conversion for all is Fs.t, nX, where X indicates blanks.

[b] n is 4 for Gw.d edit descriptors, and n is e + 2 for Gw.dEe edit descriptors.

Example 1:

PRINT "(G10.1)", 8.76E1

The preceding statement produces the following output:

bbb0.9E+02

The magnitude of N is outside the range for an F edit descriptor; it yields the format E10.1.

Example 2:

PRINT "(G10.3)", 8.76E1

The preceding statement produces the following output:

bb87.6bbbb

With the G10.3 edit descriptor, n is 4, and the format reduces to F6.1,4X (the fourth line in Table 2-12) because of the magnitude of the number.

Example 3:

PRINT "(G10.3E1)", 8.76E1

The preceding statement produces the following output because n is 3 (=1+2), and the format reduces to F7.1,3X:

bbb87.6bbbb

Logical Editing

The logical edit descriptors convert to or from a string representing a logical value that is true or false. The edit descriptors used for logical editing are as follows:

L[w]
G[w.d[Ee]]

w, d, and e have the following meanings:

Descriptor

Specification

w

The width of the field.

d

The number of fractional digits in the field. d is ignored when G is used for logical data.

e

The number of digits in the exponent. e is ignored when G is used for logical data.

For both input and output:

  • Generalized logical editing Gw.d[Ee] follows the rules for Lw editing.

On input:

  • The input field for a logical value consists of zero or more blanks, followed by an optional period, followed by T or F, for a true or false value respectively, followed by zero or more characters.

  • The T or F and any following letters can be in lowercase. They are treated the same as the uppercase letters.

    For example, if you use the following READ statement:

    READ(5, "(2L8)")  L1, L2

    to read the following input record:

    .TRUE.bb.Falseb

    L1 and L2 will have the values true and false, respectively. The result would be the same if the input record were as follows:

    TUESDAYbFRIDAYbb

On output:

  • The output field consists of w - 1 leading blanks, followed by T or F, for a true or false value, respectively.

    WRITE(6, "(2L7)")  L1, L2

    If L1 and L2 are true and false, respectively, the output record will be as follows:

    bbbbbbTbbbbbbF

If the field width is zero or is omitted, a default field width of two is used.


Note: The Fortran standard does not allow w to be zero or omitted on the L or G edit descriptors.


Character Editing

Character editing converts to or from a string of characters. The edit descriptors for character editing are as follows:

A[w]
G[w.d[Ee]]

w, d, and e have the following meanings:

Descriptor

Specification

w

The width of the field

d

The number of fractional digits in the field. d is ignored when G is used for character editing.

e

The number of digits in the exponent. e is ignored when G is used for character editing.

For both input and output:

  • w is the field width measured in characters.

  • A Gw.d[Ee] general edit descriptor is the same as an Aw edit descriptor for character data.

  • If w is omitted from the A or G format, the length of the character data object being transferred is used as the field width.


Note: The Fortran standard does not allow w to be zero or omitted on the G edit descriptor.

On input:

  • If w is greater than or equal to the length len of the character data read, len rightmost characters of the input field are read.

  • If w is less than the length len of the character data read, the w characters of the character data will be read from the input field and placed left justified in the character list item followed by len-w trailing blanks.

On output:

  • If w exceeds the length len of the character data written, w-len blank padding characters are written followed by len characters of the character data.

  • If w is less than or equal to the length len of the character data written, the w leftmost characters of the character data will appear in the output field.

    CHARACTER(LEN = 14), PARAMETER :: &amp;
          SLOGAN = "SAVE THE RIVER"
    WRITE (*, "(A)")  SLOGAN

The preceding lines produce the following output record:

SAVE THE RIVER

Character Editing

This type of character editing transfers a string of characters to or from noncharacter data types. It is available primarily for programs that were written before a true character type was available. It provides the ability to read, or write, ASCII data into, or from, noncharacter, typically integer, data.

The character edit descriptors are as follows:

A[w]
R[w]

In the preceding format, w represents the width of the field.

For both input and output:

  • w is the field width measured in characters/bytes.

  • If w is omitted, the length of the character data object being transferred is used as the field width.

On input:

  • If w is greater than or equal to the length, len, of the variable being read, the len rightmost characters of the input field are read.

  • If w is less then the len of the variable being read, then w characters of the data are read from the input field. For the A edit descriptor, they are placed left-justified in the input list item followed by len - w blanks. For the R edit descriptor, they are left-justified in the input list item preceded by binary zeros.

On output:

  • If w is greater than or equal to the len of the variable being written, then w - len blank padding characters are written, followed by len characters of the output list item.

  • If w is less than the len of the output list item, then for the A edit descriptor, the w leftmost characters of the data appear in the output field. For the R edit descriptor, the w rightmost characters of the data appear in the output field.


Note: The Fortran standard does not specify the R edit descriptor, nor does it specify the ability to use the A edit descriptor on noncharacter data types.


Q Editing

The Q edit descriptor is used to determine the number of characters remaining in the input record. It has the following format:

Q

When a Q edit descriptor is encountered during execution of an input statement, the corresponding input list item must be of type integer. Interpretation of the Q edit descriptor causes the input list item to be defined with a value that represents the number of characters remaining to be read in the formatted record.

For example, if c is the character position within the current record of the next character to be read, and the record consists of n characters, then the item is defined with the following value MAX(n-c+1,0).

If no characters have yet been read, then the item is defined as n (the length of the record). If all the characters of the record have been read (c>n), then the item is defined as zero.

The Q edit descriptor must not be encountered during the execution of an output statement.

The following example code uses Q on input:

INTEGER N
CHARACTER LINE * 80
READ (*, FMT='(Q,A)') N, LINE(1:N)


Note: The Fortran standard does not specify the Q edit descriptor.


Control Edit Descriptors

No data is transferred or converted with the control edit descriptors. Control edit descriptors affect skipping, tabbing, scale factors, and printing of optional signs. These edit descriptors may affect how the data is input or output using the subsequent data edit descriptors in the format specification.

Position Editing

Position edit descriptors control relative tabbing left or right in the record before the next list item is processed. The edit descriptors for tabbing, where n is a positive integer, are as follows:

Descriptor

Meaning

Tn

Tab to position n

TLn

Tab left n positions

TRn

Tab right n positions

nX

Tab right n positions

$ or \

Carriage control


Note: The Fortran standard does not specify the dollar sign ($) or the backslash (\) edit descriptors.

The tabbing operations to the left are limited by a position called the left tabbing limit. This position is normally the first position of the current record but, if the previous operation on the file was a nonadvancing formatted data transfer, the left tabbing limit is the current position within the record before the data transfer begins. If the file is positioned to another record during the data transfer, the left tabbing limit changes to the first position of the new record.

The Tn edit descriptor positions the record just before the character in position n relative to the left tabbing limit. TRn and nX move right n characters from the current position. TLn moves left n characters from the current position, but is limited by the left tabbing limit.

For both input and output:

  • n must be a positive integer constant with no kind parameter value specified for it.

  • Left tabbing is always limited so that even if left tabbing specifies a position to the left of the left tabbing limit, the record position is set to the left tabbing limit in the record.

  • The left tabbing limit in the record is determined by the position in the record before any data transfer begins for a particular data transfer statement.

  • If a file is positioned to another record during a particular data transfer statement, the left tabbing limit is the first position of the record.

On input:

  • The T descriptor might move the position within a record either left or right from the current position.

  • Moving to a position left of the current position allows input to be processed twice, provided the same input statement is performing the processing for advancing input, or provided nonadvancing input is in effect.

  • The X descriptor always moves the position to the right and skips characters.

On output:

  • The positioning does not transmit characters, and does not by itself cause the record to be shorter or longer.

  • Positions that are skipped and have not been filled previously behave as if they are blank filled.

  • Positions previously filled can be replaced with new characters, but are not blank filled when they are skipped using any of the position edit descriptors.

For example, assume that DISTANCE and VELOCITY have the values 12.66 and -8654.123.

    PRINT 100, DISTANCE, VELOCITY
100 FORMAT (F9.2, 6X, F9.3)

The preceding code produces the following record:

bbbb12.66bbbbbb-8654.123

Continue to assume that DISTANCE and VELOCITY have the values 12.66 and -8654.123.

    PRINT 100, DISTANCE, VELOCITY
100 FORMAT(F9.2, T7, F9.3)

The preceding code produces the following record because T7 specifies the first position for VELOCITY as the seventh character in the record:

bbbb12-8654.123

A dollar sign character ($) or a backslash character (\) in a format specification modifies the carriage control specified by the first character of the record. In an output statement, the $ and \ descriptors suppress the carriage return or line feed. In an input statement, the $ and \ descriptors are ignored. It is intended primarily for interactive output.

Slash Editing

The slash edit descriptor consists of the single slash character (/). The current record is ended when a slash is encountered in a format specification.

On input:

  • If the file is connected for sequential access, the file is positioned at the beginning of the next record. The effect is to skip the remainder of the current record.

  • For direct access, the record number is increased by one, and the file is positioned at the beginning of the record with this increased record number, if it exists; it becomes the current record.

  • A record can be skipped entirely on input.

On output:

  • If the file is connected for sequential access, the current record is written. The current record can be an empty record.

  • For direct access, the current record is blank filled, if necessary, the record number is increased by one, and this record becomes the current record.

  • For an internal file that is a scalar, the current record is blank-filled, if necessary. No other action is taken until a check of the contents of the format is done; that is, the format determines what happens next.

  • For an internal file that is an array, the current record is blank filled, and the file is positioned at the beginning of the next array element.

Assume in the following code that ALTER, POSITION, and CHANGE have the values 1.1, 2.2, and 3.3, respectively:

PRINT "(F5.1, /, 2F6.1)", ALTER, POSITION, CHANGE

The preceding code produces the following two records:

bb1.1
bbb2.2bbb3.3

Colon Editing

The colon edit descriptor consists of the character colon (:). If the list of items in a formatted READ or WRITE statement is exhausted, a colon stops format processing at that point. If the list is not exhausted, the colon edit descriptor has no effect.

For example, assume in the following code that ALTER, POSITION, and CHANGE have the values 1.1, 2.2, and 3.3, respectively:

WRITE(6, 100)  ALTER, POSITION, CHANGE
100 FORMAT(3F5.2, :, "STOP")

The preceding code produces the following:

bb1.1bb2.2bb3.3

The characters STOP are not printed because the output list is exhausted when the colon edit descriptor is processed. If the colon edit descriptor were not present in the above format, the string "STOP" would be printed.

Sign Editing

Sign editing applies to the output data transfer of positive integer and real values only. It controls the writing of the optional plus sign when the edit descriptor I, F, E, EN, ES, D, or G is used. The sign edit descriptors are as follows:

Descriptor

Meaning

SP

The plus sign is always written

S, SS

The plus sign is not written

The descriptors remain in effect until another sign edit descriptor is encountered in the format specification. The descriptors have no effect during formatted input data transfers.

For example, assume in the following code that SPEED(1) and SPEED(2) are 1.46 and 2.3412 respectively:

    WRITE(6, 110)  (SPEED(K), K = 1, 2)
110 FORMAT(SP, 2F10.2)

The preceding code produces the following:

bbbbb+1.46bbb+234.12

Scale Factors

The kP edit descriptor indicates scaling, where the scale factor k is a signed integer literal constant.

The scale factor is zero at the beginning of a formatted I/O statement. When a kP descriptor occurs, the scale factor becomes k, and all succeeding numeric fields processed with an F, E, EN, ES, D, or G edit descriptor may be affected by this scale factor until another kP edit descriptor occurs.

On input:

  • If the input field has no exponent, the scale factor effect is that the external number equals the internal number multiplied by a scale factor 10k.

  • The scale factor has no effect if the input field has an exponent.

Input example:

Assume that the input record contains 10.12:

    READ (5,100) MASS
100 FORMAT (3PF15.3)

The preceding code gives MASS the value 10120.0.

On output:

  • For the F edit descriptor, the value is multiplied by 10k.

  • For the E and D edit descriptors, the significand of the value is multiplied by 10k and the exponent is reduced by k.

  • The G edit descriptor is not affected by the scale factor if the number will print correctly with the appropriate F edit descriptor as described in Table 2-12. Otherwise, the scale factor for the G edit descriptor has the same effect as for the E edit descriptor.

  • EN and ES edit descriptors are not affected by a scale factor.

Assume that TREE has the value 12.96:

    WRITE(6,200) TREE
200 FORMAT(2PG10.1)

The preceding code produces the following:

b1296.E-02

Blanks in Numeric Fields

Blanks other than leading blanks are ignored or interpreted as zero characters in numeric input fields as determined by the blank edit descriptors:

Descriptor

Meaning

BN

Treat nonleading blanks in numeric input fields as nonexistent

BZ

Treat nonleading blanks in numeric input fields as zeros

The interpretation is for input fields only when the field is processed using an I, B, O, Z, F, E, EN, ES, D, or G edit descriptor; output fields are not affected. The BLANK= specifier in the OPEN statement affects the interpretation of blanks if no BN or BZ descriptor is used.

On input:

  • The BLANK= specifier for an internal file is NULL.

  • If the BLANK= specifier is NULL, or a BN edit descriptor is in effect, the nonleading blanks are ignored in succeeding numeric fields.

  • If the BLANK= specifier is ZERO, or a BZ edit descriptor is in effect, the nonleading blanks are interpreted as zeros in succeeding numeric fields.

  • The BN and BZ edit descriptors override the effect of the BLANK= specifier during the execution of a particular input data transfer statement.

Example:

    READ (5, 100)  N1, N2
100 FORMAT (I5, BZ, I5)

Considering the preceding code, if the input record is as follows, and unit 5 has been opened with a BLANK= specifier equal to NULL, the values assigned to N1 and N2 are 99 and 90909, respectively:

b9b9b9b9b9

Character String Edit Descriptors

Character string edit descriptors are used to transfer characters to an output record. They must not be used on input. The character string edit descriptors are apostrophe, quote, and Hollerith. They have the following format:

'characters'
"characters"
cHcharacters

Note: The Fortran standard has declared the Hollerith string edit descriptor to be obsolescent.

On output:

  • The apostrophe and quote edit descriptors have the form of literal character constants with no kind parameter values. They cause those constants to be placed in the output.

  • The Hollerith descriptor cH . . . may be used to print the c characters following the H. c must be a positive integer and must not have a kind value specified for it.

  • To write a quote in the output field when a quote is the delimiting character, use two consecutive quotes; to write an apostrophe in the output field when an apostrophe is the delimiting character, use two consecutive apostrophes.

  • The field width is the length of the character constant, but doubled apostrophes or quotes count as one character.

For example, assume in the following code that TEMP has the value 32.120001:

    WRITE (6, 120)  TEMP
120 FORMAT (' TEMPERATURE = ', F13.6)

The preceding code produces the following record:

bTEMPERATUREb=bbbbb32.120001

List-directed Formatting

List-directed formatting is one of the implicit formatting methods in Fortran. Conversion from characters in READ statements to characters in PRINT and WRITE statements does not use an explicit format specification. The editing occurs based on the type of the list item. Data is separated by commas or blanks. The I/O statement uses an asterisk (*) instead of an explicit format specification, as follows:

READ (5, *)  HOT, COLD, WARM

For both input and output:

  • A list-directed record consists of values and value separators.

  • c and r must be specified without any kind type parameter.

  • The values allowed in a list-directed input record are as follows:

    Value

    Content

    null

    A null value. Specified, for example, by two consecutive commas (,,).

    c

    Either 1) A literal constant or 2) a nondelimited character string with no embedded blanks. See “Requirements for Nondelimited Character Strings As Values”, for the requirements for nondelimited character constants.

    r*c

    r repetitions of the constant c. r must be an unsigned, nonzero integer.

    r*

    r repetitions of the null value, where r is nonzero. r must be an unsigned, nonzero integer.

    Embedded blanks are allowed only within values as specified for each data type. For example, embedded blanks are allowed within a delimited character constant or at certain positions within a complex value.

  • The value separators allowed in a list-directed input record are as follows:

    Separator

    Meaning

    ,

    A comma, optionally preceded or followed by contiguous blanks.

    /

    A slash, optionally preceded or followed by contiguous blanks.

    <blank>

    One or more contiguous blanks between two nonblank values or following the last nonblank value, where a nonblank value is a constant, an r*c form, or an r* form.

  • List-directed formatting must not be specified for direct access or nonadvancing sequential data transfer.

  • If there are no list items and there is no current record, an input record is skipped or an output record that is empty is written. If there are no list items and there is a current record, the current record is skipped (the file is positioned at the end of the current record) or the current record is terminated at the current position. Recall that a current record exists only if the previous I/O data transfer to the unit was nonadvancing. An empty record is either a blank-filled record or a record with no characters in it, depending on the file structure used. If you are using UNICOS or UNICOS/mk systems, see the Application Programmer's I/O Guide, for more information on file structures.

  • The end of a record has the same effect as a blank, unless it occurs within a delimited character literal constant. Similarly, a sequence of two or more consecutive blanks is treated as a single blank.

List-directed Input

Input values are generally accepted as list-directed input if they are the same as those required for explicit formatting with an edit descriptor. The exceptions are as follows:

  • When the data list item is of type integer, the constant must be of a form suitable for the I edit descriptor. The CF90 and MIPSpro 7 Fortran 90 compilers permit binary, octal, and hexadecimal based values in a list-directed input record to correspond to I edit descriptors.


    Note: The Fortran standard specifies that binary, octal, and hexadecimal values must not be used in a list-directed input record.


  • When the data list item is of type real, the constant must be of a form suitable for the F edit descriptor. If no decimal point appears in the constant, the constant has no fractional digits specified for it.

  • Blanks are never zeros.

  • Embedded blanks are allowed within a delimited character constant. Values of type complex include the parentheses for a complex constant. Blanks may occur before or after the comma and before or after the parentheses. The following are input examples:

    "NICE DAY"
    (1.2, 5.666 )
    TODAY

  • Logical items must not use value separators as the optional characters following the T or F. TUESDAY is allowed. Specifying T,TOO is not allowed because the value TOO will be used as the next input value.

  • An end-of-record cannot occur within a constant, except a complex constant or a delimited character constant. For a complex constant, the end of record can occur between the real part and the comma, or between the comma and the imaginary part. For a character constant, the end-of-record can occur anywhere in the constant except between any consecutive (doubled) quotes or apostrophes in the constant. The end-of-record does not cause a blank or any other character to become part of the character value. A complex or character constant can be continued on as many records as needed.

  • Value separators may appear in any delimited character constant. They are, however, not interpreted as value separators, but are characters in the delimited character constant.

  • Assume that len is the length of the corresponding input list item and w is the number of effective characters in the character value. If lenw, the leftmost len characters of the constant are used. If len > w, the w characters of the constant are left justified in the input list item and the list item is blank filled on the right.

    For example, consider the following code:

    CHARACTER (2) NAME
       . . .
    READ (5,*)  NAME

    Assume that the input record is as follows:

    JONES

    After the READ statement, the value in NAME is JO, because len (=2) is less than w (=5).

Requirements for Nondelimited Character Strings As Values

In certain cases, the delimiters are not required for character values on input. However, nondelimited character strings impose the following requirements:

  • The corresponding data list item must be of type character.

  • The character string must not contain any value separator.

  • The character string must not be continued across a record boundary.

  • The first nonblank character is neither an apostrophe (') nor a quote ( ").

  • The leading characters are not a string of digits followed immediately by an asterisk.

In any of these cases, the character constant represented by the character string is terminated by the first value separator or end-of-record, and apostrophes (') and quotes (") are not doubled.

Null Values

Null values are used to specify no change of the items in the input item list. Null values have the following forms:

  • No value between separators, such as ,,

  • A nonblank value separator as the first entity in the record; for example, a record beginning with slash as the first nonblank character represents a null value, as in /4.56.

  • r* followed by a value separator as in the following:

    7*,'TODAY'

An end-of-record does not signify a null value.

The null value does not affect the definition status or value of the corresponding list item.

For a complex constant, the entire constant can be null, but not one of the parts.

If a slash terminates input, the remaining characters in the record are ignored, and the remaining list items are treated as though null values had been read. This applies to any remaining items in an implied-DO or to any remaining elements of an array. Example:

REAL AVERAGE(2)
READ (5, *) NUMBER, AVERAGE

If the input record is the following, the result is that NUMBER = 6, AVERAGE(1) is unchanged, and AVERAGE(2) = 2.418:

b6,,2.418

List-directed Output

List-directed output uses similar conventions to those used for list-directed input. The following rules and restrictions apply to both input and output:

  • Except for nondelimited character values, a comma, optionally preceded or followed by a blank, is used as a separator.

  • New records are begun as needed, at any point in the list of output items. A new record does not begin in the middle of a value, except as noted below for character values. Each new record begins with a blank for carriage control, except for delimited character constants.

  • Slashes and null values are not written.

  • If two or more consecutive values from an array are identical, they can be written using the repeat factor r*c.

There are a few exceptions. These are noted as follows for each of the intrinsic types:

  • Integer. The effect is as though an Iw edit descriptor were used, using a suitable value for w.

  • Real. The effect is as though an 0PFw.d or an 1PEw.dEe edit descriptor were used, using suitable values for w, d, and e. The edit descriptor chosen depends on the magnitude of the number written.

  • Complex. The real and imaginary parts are enclosed in parentheses and separated by a comma. A complex value must fit within one record.

  • Logical. List-directed output prints T or F depending on the value of the logical data item.

  • Character. The form of the output for character values depends on the value of the DELIM= specifier in the OPEN statement for that unit.

    • The following are true if there is no DELIM= specifier, if the value of the DELIM= specifier is NONE, or if the file is an internal file:

      • Character values are not delimited

      • Character values are not surrounded by value separators

      • Only one quote or apostrophe is needed for each quote or apostrophe in the string transferred

      • A blank is inserted at the beginning of new records for a continued character value

    • The following are true if the DELIM= specifier is QUOTE or APOSTROPHE:

      • Character values are delimited with the specified delimiter

      • All values are surrounded by value separators

      • A character that is the same as the specified delimiter is doubled when written to the output record

      • No blank is inserted at the beginning of a continued record for carriage control in the case of a character value continued between records

List-directed output of real values uses either an F or an E format with a number of decimal digits of precision that assures full-precision printing of the real values. This allows later formatted or list-directed input of real values to result in the generation of a bit-identical binary floating-point representation, which allows a value to be written and reread without changing the stored value.

You can set the LISTIO_PRECISION environment variable to control the number of digits of precision printed by list-directed output. The following values can be assigned to LISTIO_PRECISION:

Value

Result

FULL

Prints full precision (default).

PRECISION

Prints x or x +1 decimal digits, where x is value of the PRECISION intrinsic function for a given real value. This is a smaller number of digits, which usually ensures that the last decimal digit is accurate to within 1 unit. This number of digits is usually insufficient to assure that subsequent input will restore a bit-identical floating-point value.

YMP80

Causes list-directed and namelist output of real values to be of the format used in UNICOS 8.0 and previous library versions on CRAY Y-MP systems. The YMP80 specification is available in UNICOS 8.0 libraries, but this functionality will be removed in a later UNICOS release.


Note: The Fortran standard does not specify full-precision printing or environment variables.

Example:

REAL                    :: TEMPERATURE = -7.6
INTEGER                 :: COUNT = 3
CHARACTER(*), PARAMETER :: PHRASE = "This isn't so"
OPEN(10, DELIM = 'NONE')
WRITE(10, *)  TEMPERATURE, COUNT, PHRASE

The output record on unit 10 would be:

-7.6    3     This isn't so

The -U option on the assign(1) command controls three other assign(1) options: -y, -S, and -W, as follows:

Option

Purpose

-y

Suppress repeat count in list-directed output.

-S

Suppress use of comma as a separator in list-directed output.

-W

Suppress compressed width in list-directed output.

Namelist Formatting

In some programs, it is convenient to create a list of variables that can be read or written by referencing the name of the list. The term namelist denotes this kind of data transfer. Before input or output can begin using this facility, the NAMELIST specification statement is used to define the list and give it a group name. In the following example, the NAMELIST statement defines the group name MEETING made up of the data objects JAKE, JOE, and JANE:

NAMELIST /MEETING/ JOE, JAKE, JANE

The namelist input and output records consist of an ampersand (&) followed by a namelist group name followed by a sequence of name-value pairs followed by a slash (/). A name-value pair is a name or a subobject designator, an equal sign, and one or more values separated by value separators; that is, name=value or name=value,value, .... The name in a name-value pair must appear in the NAMELIST statement specifying the namelist group name. The name-value pairs provide a convenient form of documentation.

For example, consider the following input data transfer statement:

READ (*, NML = MEETING)

The preceding statement sets the variables JAKE and JOE when the input record is as follows:

&MEETING  JAKE = 3505,  JOE = 1 /

It does not change the value of the variable JANE.

Namelist output is convenient for debugging or writing values in a form that can later be read by a READ statement referencing the same namelist group name. All variables in the namelist group name appear in the output record and they must all be defined when the output statement is executed. For example, consider the following WRITE statement:

WRITE (*, NML = MEETING)

The preceding statement creates the following output record (assuming JANE is defined with the value 0):

&MEETING  JAKE = 3505, JOE = 1, JANE = 0 /

In namelist I/O records, blanks can appear before the ampersand, after the namelist group name, before or after the equal sign in the name-value pairs, or before the slash terminating the namelist records.

The rules and restrictions for a blank and an end-of-record in a character constant are the same as for delimited character constants in list-directed formatting. Nondelimited character strings are not permitted in namelist input records.

Namelist Input

Namelist input consists of the following items, in order:

  • Optional blanks and namelist comments.

  • An ampersand (&).

  • The group name.

  • One or more blanks.

  • A sequence of zero or more name-value pairs whose names are in the namelist group and whose values are described in the following sections. These must be separated by value separators and followed by a slash, which terminates the namelist input.

The name-value pairs are separated by value separators that are composed of the following characters:

  • A comma, optionally preceded or followed by contiguous blanks

  • A slash, optionally preceded or followed by contiguous blanks

  • One or more contiguous blanks between two name-value pairs

Blanks can precede the ampersand (&) or the slash (/).

When the name in the name-value pair is a subobject designator, it must not be a zero-sized array, zero-sized array section, or a zero-length character string.

A lowercase letter is the same as an uppercase letter and vice versa when used in the group name.

A namelist comment can appear after any value separator except a slash (/). A namelist comment can start in the first nonblank position of an input record except within a character constant.

An example of namelist input is as follows:

READ (*, NML = MEETING)

The input record for the preceding statement might be as follows:

&MEETING JAKE = 3500, JOE = 100, JANE = 0/

Names in Name-value Pairs

This section describes the rules and restrictions for the names used in the name-value pairs in the namelist records.

  • The name-value pairs can appear in any order in the input records.

  • The name-value pairs are evaluated serially, in left-to-right order.

  • A name in the namelist group can be omitted.

  • Each name must correspond with a name in the designated namelist group; a component name, if any, must also be the name of a component of a structure named in the namelist group.

  • Optionally-signed integer literal constants with no kind parameter values must be used in all expressions that appear in subscripts, section designators, or substring designators.

  • The name of a structure or a subobject designator can be the name in a name-value pair.

  • A name in an input record must not contain embedded blanks. A name in the name-value pair can be preceded or followed by one or more blanks.

  • A lowercase letter is the same as an uppercase letter and vice versa when used in the name of a name-value pair.

  • A namelist group object name or subobject designator can appear in more than one name-value pair in a sequence.

Recall that each name must not be the name of an array dummy argument with nonconstant bounds, an automatic object, a character variable with nonconstant length, a pointer, or a structure variable of a type with a component that is a pointer, or an allocatable array.

Values in Name-value Pairs

The value in a name-value pair must be in a form acceptable for a format specification for the type of the name, except for restrictions noted below.

Null values can have the following forms:

  • No value between value separators

  • No value between the equal sign and the first value separator

  • The r* form, followed by one or more blanks

Null values do not change the value of the named item or its definition status. An entire complex constant can be null; neither of the parts can be. The end of a record following a value separator does not specify a null value.

Each value is a null value or one of the following forms. In these forms, r is assumed to be a repeat factor and is nonzero. c and r must be specified without any kind type parameter. The forms are as follows:

Value

Representation

c

Indicates a literal constant, which must be unsigned

r*c

Indicates r successive literal constants c

r*

Indicates r successive null values

The form of a value must be acceptable to a format specification for an entity of the type of the corresponding list item, except as noted below; for example, the value c corresponding to a list item of type real can be of the following forms:

1
1.0E0

The value c corresponding to a list item of type real cannot be of the following forms:

(1.0,0.0)
A0
1.0EN-3
2.2_QUAD

Blanks are never treated as zeros, and embedded blanks must not appear in numeric or logical constants. The exception is that a blank can appear as a character in a character constant, or preceding or following the real or imaginary parts of a complex constant.

The number of values following the equal sign must not be larger than the number of elements of the array when the name in the name-value pair is an array, or must not be larger than the ultimate number of components when the name in the name-value pair is that of a structure. Any array or component that is an array is filled in array element order.

Consider the following example:

TYPE PERSON
     INTEGER LEN
     CHARACTER(10) :: NAME
END TYPE PERSON
TYPE(PERSON) PRESIDENT, VICE_PRES
NAMELIST /PERSON_LIST/ PRESIDENT, VICE_PRES
READ (5, NML = PERSON_LIST)

The input record for the preceding code might be as follows:

&PERSON_LIST PRESIDENT%LEN=10,
PRESIDENT%NAME="WASHINGTON",
             VICE_PRES%LEN=5, VICE_PRES%NAME="ADAMS"/

If there are fewer values in the expanded sequence than array elements or structure components, null values are supplied for the missing values.

If a slash occurs in the input, it is as if null values were supplied for the remaining list items, and the namelist input data transfer is terminated. The remaining values after the slash within the current record are ignored. The namelist input record can be terminated by the characters &END.

An integer value is interpreted as if the data edit descriptor were Iw for a suitable value of w.

A complex value consists of a pair of parentheses surrounding the real and imaginary parts, separated by a comma. Blanks can appear before and after these values.

A logical value must not contain slashes, commas, or blanks as part of the optional characters permitted for logical values. The required characters for logical values include the first few characters, such as the initial:

  • .T

  • .F

  • T

  • F

The optional characters on logical values, which include ALSE., RUE., and so on, cannot include slashes, commas, or blanks.

A character literal constant may contain slashes, commas, or blanks as part of the constant. On namelist input, the DELIM= specifier is ignored.

Blanks

Blanks are part of the value separator except when used in the following situations:

  • In a character constant

  • Before or after the parts of a complex constant

  • Before or after an equal sign, unless after the equal sign the blanks are followed immediately by a comma or slash

  • Before the ampersand indicating the namelist group name and after the namelist group name

Namelist Comments

An exclamation point (!) character initiates a namelist comment. Namelist comments are not recognized within a character literal constant, but they can appear after a value separator or in the first nonblank position of a namelist input record. The comment extends to the end of the current input record and can contain any graphic character allowed by the system.

The comment is ignored. A slash (/) within the namelist comment does not terminate the execution of the namelist input statement.

Example:

PROGRAM NML_COMMENTS
NAMELIST /NMLA/RVALUE,IVALUE
RVALUE = 100.0
IVALUE = 90
READ(9,NMLA)
PRINT *,'IVALUE =',IVALUE
PRINT *,'RVALUE =',RVALUE
END

For the preceding code, assume that the input records contain the following:

!THIS IS COMMENT ZERO
$NMLA !THIS IS COMMENT ONE
!THIS IS COMMENT TWO, IVALUE = 1
IVALUE = 2 !THIS IS COMMENT THREE IVALUE = 3
RVALUE = !THIS IS COMMENT FOUR 4.0
5.0 !THIS IS COMMENT FIVE RVALUE = 6.0
/

Output from this program is as follows:

IVALUE = 2
RVALUE = 5.

Use of Namelist Input

Namelist input skips blank records and records that begin with namelist comments. Namelist input requires a namelist group name, preceded by an ampersand, to be on the first nonblank uncommented record read by the namelist READ statement.

The following is an example of namelist input:

REAL A(3), B(3)
CHARACTER(LEN = 3) CHAR
COMPLEX X
LOGICAL LL
NAMELIST /TOKEN/ I, A, CHAR, X, LL, B
READ (*, NML = TOKEN)

Assume that the input record for the preceding is as follows:

&TOKEN A(1:2) = 2*1.0  CHAR = "NOP" B = ,3.13,,
       X = (2.4,0.0)  LL = T /

The results of the READ statement are as follows:

Name

Value

I

Unchanged

A(1)

1.0

A(2)

1.0

A(3)

Unchanged

B(1)

Unchanged

B(2)

3.13

B(3)

Unchanged

CHAR

"NOP"

X

(2.4, 0.0)

LL

True

On UNICOS and UNICOS/mk systems, the input namelist group name must match the group name specified in the READ statement.

On IRIX systems, the input namelist group is skipped if the group name does not match the group name specified in the READ statement. You can use the assign(1) command's -Y ON|OFF option to change this default behavior.

Namelist Output

Value separators can be blanks, commas, or a combination of blanks and commas. A new record can begin anywhere, except within a name or value, unless the value is a character constant or a complex constant; a record can begin anywhere within a character constant, or can begin before or after the comma, or left or right parenthesis of a complex constant. A blank can occur anywhere, except in a name or a noncharacter value.

Use of Namelist Output

A number of rules, similar to those for list-directed formatting, apply for namelist output. They are as follows:

  • Namelist output consists of a series of records. The first nonblank record begins with an ampersand, followed by the namelist group name, followed by a sequence of name-value pairs, one pair for each variable name in the namelist group object list of the NAMELIST statement, and ends with a slash.

  • A logical value is either T or F.

  • An integer value is one that would be produced by an Iw edit descriptor using a suitable value of w.

  • For real output, the rules for list-directed output are followed using reasonable values for the w, e, and d that appear in real data edit descriptors and are appropriate for the output value.

  • Parentheses enclose the value of a complex constant, and the parts are separated by a comma. A complex value must fit within one record. Blanks can be embedded after the comma and before the end of the record.

  • Character constants follow the rules for list-directed output.

  • Repeat factors of the form r*c are allowed on output for successive identical values.

  • An output record does not contain null values.

  • Each record begins with a blank for carriage control.

  • No values are written for zero-sized arrays.

  • For zero-length character strings, the name is written, followed by an equal sign, followed by a zero-length character string, and followed by a value separator or slash.

           NAMELIST /CALC/ DEPTH, PRESSURE
           DIMENSION DEPTH(3), PRESSURE(3)
           FLOAT1 = 0.2
           FLOAT2 = 3.0
           DO 10 I=1,3
             DEPTH(I) = FLOAT1 + FLOAT(I)
             PRESSURE(I) = FLOAT2 + (FLOAT(I-1) * 0.1)
    10     CONTINUE
           WRITE(6,NML=CALC)
           END

This program produces the following output:

&CALC  DEPTH = 1.2, 2.2, 3.2,  PRESSURE = 3., 3.1, 3.2 /

The -U option on the assign(1) command controls three other assign(1) options: -y, -S, and -W, as follows:

Option 

Purpose

-y 

Suppress repeat count in list-directed output.

-S 

Suppress use of comma as a separator in list-directed output.

-W 

Suppress compressed width in list-directed output.

DELIM= Specifier for Character Constants

The form of the output for character values depends on the value of the DELIM= specifier in the OPEN statement for that unit.

If there is no DELIM= specifier or if the value of the DELIM= specifier is NONE, the following actions occur:

  • Character values are not delimited.

  • Character values are not surrounded by value separators.

  • Only one quote or apostrophe is needed for each quote or apostrophe in the string transferred.

  • A blank is inserted in new records for a continued character value to allow for carriage control.

If the DELIM= specifier is QUOTE or APOSTROPHE, the following actions occur:

  • Character values are delimited with the specified delimiter.

  • A character that is the same as the specified delimiter is doubled when written to the output record.

For example, in the following code, assume LEFT and RIGHT with values "SOUTH" and "NORTH". The program has a DELIM= specifier of QUOTE for unit 10:

CHARACTER(5) LEFT, RIGHT
NAMELIST /TURN/ LEFT,RIGHT
LEFT = 'SOUTH'
RIGHT = 'NORTH'
WRITE(10,NML=TURN)
END

The preceding code produces the following output record:

&TURN  LEFT = SOUTH, RIGHT = NORTH /

Note that if the DELIM= specifier is NONE in an OPEN statement, namelist output might not be usable as namelist input when character values are transferred, because namelist input of character values requires delimited character values.

Namelist Distinctions

The CF90 and MIPSpro 7 Fortran 90 compilers have extended the namelist feature. The following additional rules govern namelist processing:

  • An ampersand (&) or dollar sign ($) can precede the namelist group name or terminate namelist group input. If an ampersand precedes the namelist group name, either the slash (/) or the ampersand must terminate the namelist group input. If the dollar sign precedes the namelist group name, either the slash or the dollar sign must terminate the namelist group input.

  • Octal and hexadecimal constants are allowed as input to integer and single-precision real namelist group items. An error is generated if octal and hexadecimal constants are specified as input to character, complex, or double-precision real namelist group items.

    Octal constants must be of the following form:

    • O"123"

    • O'123'

    • o"123"

    • o'123'

    Hexadecimal constants must be of the following form:

    • Z"1a3"

    • Z'1a3'

    • z"1a3"

    • z'1a3'


Note: The Fortran standard does not specify the namelist distinctions described in this section.