### 7.2.1.3 Namelist Sequential READ Statement

The namelist sequential READ statement performs the following operations:

- It reads data from external records accessed under the sequential mode of access until it finds the specified group- name.

- It translates the data from external to internal form by using the data types of the entities in the corresponding NAMELIST statement, and the forms of the data, to provide editing.

- It assigns the translated data to the specified namelist entities in the order in which the entities appear in the input records.

The input for a namelist READ consists of a record or records delimited by the special symbol dollar sign ($), which starts in the second column of the first record.

Namelist input takes the following form:

    column 2

    |

    $group-name entity = value [,entity = value , . . . ] $[END]

$
  Is the special symbol used to indicate the beginning or end of input. The ampersand (&) can be used in place of the dollar sign.
group-name
  Is the name of the namelist that contains the entity or entities to be given values. The namelist must have been previously defined in a NAMELIST statement in the program unit.
entity
  Is a namelist-defined entity. The entity can be a variable, array name, subscripted variable, variable with a substring, or subscripted variable with a substring.
value
  Is a constant, a list of constants, a repetition of constants in the form r*c, or a repetition of values in the form r*.
END
  Is an optional part of the last delimiter.

Information on rules for namelist input, prompting for current values, and assigning values is presented separately under the headings that follow.

Rules and Behavior

The following rules apply to namelist input:

- The group-name cannot contain spaces or tabs and must be contained within a single record.

- The entities appearing on the left side of the equal sign in a value assignment cannot contain spaces or tabs except within the parentheses of a subscript or substring specifier. Each entity must be contained in a single record.

- Each constant that appears in a value assignment has the form of the corresponding Fortran constant. Input constants can be any of the following data types: integer, real, logical, complex, and character.

- A complex constant has the form of a pair of real or integer constants separated by a comma and enclosed in parentheses. Spaces can occur between the opening parenthesis and the first constant, before and after the separating comma, and between the second constant and the closing parenthesis.

- A logical constant represents true or false values: .TRUE. (or any value beginning with T, .T, t, or .t) or .FALSE. (or any value beginning with F, .F, f, or .f).

- A character constant is enclosed in apostrophes. An apostrophe within a character constant is represented by two consecutive apostrophes.

- Hollerith and bit constants are not permitted.

- The valid separators in a list of constants or value assignments are spaces, tabs, and commas. Except within a character constant, any number of consecutive spaces and tabs is equivalent to a single space. A separating comma preceded or followed by spaces is equivalent to a single comma.

- A null value is specified by two consecutive commas, by an initial comma, or by a trailing comma. A null value indicates that the corresponding namelist array element is unchanged. A null value can represent an entire complex constant, but it cannot be used for either part of a complex constant.

- The form r*c indicates r occurrences of c, where r is a nonzero, unsigned integer constant and c is a constant. Spaces are not permitted except within the constant c in complex or character constants.

- The form r* indicates r occurrences of a null value, where r is an unsigned integer constant.

- The equal sign in a value assignment can be preceded and followed by any number of spaces or tabs.

- The end of a record in namelist input is equivalent to a space character except when the end of the record occurs in a character constant. If this occurs, the end of the record is ignored, and the character constant is continued with the next record (the last character in the previous record is followed immediately by the second character of the next record). The first character is used for carriage control.

Prompting for Namelist Group Information

During execution of a program containing a namelist READ statement, you can specify a question mark character (?) or a question mark character preceded by an equal sign (=?) to get information about the namelist group. The ? or =? must follow one or more blanks.

If specified for a unit capable of both input and output, the ? causes display of the group name and the entities in that group. The =? causes display of the group name, entities within that group, and the current values for those entities (in namelist output form). If specified for another type of unit, the symbols are ignored.

For example, consider the following statements:

    NAMELIST /NLIST/ A,B,C

    REAL A /1.5/

    INTEGER B /2/

    CHARACTER*5 C /'ABCDE'/

    READ (5,NML=NLIST)

    WRITE (6,NML=NLIST)

    END

During execution, if ? is entered in column 2 of a terminal device, the following values are displayed:

     $NLIST

     A

     B

     C

     $END

If a blank followed by =? is entered, the following values are displayed:

     $NLIST

     A       =   1.500000    ,

     B       =           2,

     C       = 'abcde'

     $END

For more information on namelist output, see Section 7.3.1.3.

Assigning Values

Input values can be assigned in any order by using an assignment of the form: entity=value. Each new line of input can begin in column 2 or in any column thereafter. Column 1 of each record is assumed to contain a Compaq Fortran 77 carriage-control character. Any data placed in that column is ignored.

Assigned values, array subscripts, and substring specifiers must be constant values. Symbolic (PARAMETER) constants are not permitted.

Input values can be any of the following data types: integer, real, logical, complex, and character. If the data type of a namelist entity and its assigned constant value do not match, conversion is performed according to the rules for arithmetic assignment (see Figure 3-1). Conversion between numeric and character data types is not permitted.

Examples

In the first example, the NAMELIST statement associates the group- name CONTROL with a list of five entities. The corresponding READ statement reads input data and assigns values to specified namelist entities.

    NAMELIST /CONTROL/ TITLE, RESET, START, STOP, INTERVAL

    CHARACTER*10 TITLE

    REAL*8 START, STOP

    LOGICAL*4 RESET

    INTEGER*4 INTERVAL

    READ (UNIT=1,NML=CONTROL)

In the following example, values are assigned to all of the namelist entities previously associated with the group-name CONTROL.

    column 2

    |

    $CONTROL

    <TAB> TITLE='TESTT002AA',

    <TAB> INTERVAL=1,

    <TAB> RESET=.TRUE.,

    <TAB> START=10.2,

    <TAB> STOP =14.5

    $END

Upon program execution, values are assigned to list entities as follows:

Entity | Value
--- | ---
TITLE | TESTT002AA
RESET | T
START | 10.2
STOP | 14.5
INTERVAL | 1

It is not necessary to assign values to all of the list entities defined in the corresponding NAMELIST group-name.

The namelist READ statement does not change the values of namelist entities that do not appear in the input data. Similarly, when character substrings and array elements are specified, only the values of the specified variable substrings and array elements are changed. For example, the next input to the character variable TITLE (used in the last example) contains the following statement:

    column 2

    |

    $CONTROL TITLE(9:10)='BB' $END

Its new value is TESTT002BB; the first eight positions of the variable do not change.

When a list of values is assigned to an array name, the first value in that list is assigned to the first element of the array, the second value is assigned to the second element of the array, and so on. The number of array elements assigned must be less than or equal to the size of the array. Consecutive commas within a list indicate that the values of the array elements remain unchanged.

For example, a program unit contains the following statements:

    DIMENSION ARRAY(20)

    NAMELIST /ELEM/ ARRAY

    READ (UNIT=1,NML=ELEM)

The input contains the following:

    column 2

    |

    $ELEM

    ARRAY=1.1, 1.2, , 1.4

    $END

Upon program execution, the READ statement assigns values to array elements as follows:

Array Element | Value
--- | ---
ARRAY(1) | 1.1
ARRAY(2) | 1.2
ARRAY(3) | unchanged
ARRAY(4) | 1.4
ARRAY(5)-ARRAY(20) | unchanged

When a list of values is assigned to an array element, the assignment begins with the specified array element, rather than with the first element of the array. Consider the following input to ARRAY:

    column 2

    |

    $ELEM

    ARRAY(3)=34.54,  45.34, 87.63, 3*20.00

    $END

Upon program execution, the READ statement assigns new values only to ARRAY elements 3 through 8. It does not alter unspecified elements.

Previous Page Next Page Table of Contents