Intel® Fortran Compiler 16.0 User and Reference Guide

Rules for Namelist Sequential READ Statement

Namelist, sequential READ statements translate data from external to internal form by using the data types of the objects in the corresponding NAMELIST statement to determine the form of the data. The translated data is assigned to the specified objects in the namelist group in the order in which they appear, from left to right.

If a slash ( / ) is encountered during execution, the READ statement is terminated, and any remaining input list items are unchanged. An ampersand (&) encountered during input is treated the same as a slash (/).

If the file is connected for unformatted I/O, namelist data transfer is prohibited.

Namelist Records

A namelist external record takes the following form:

&group-name object = value [, object = value] .../

group-name

Is the name of the group containing the objects to be given values. The name must have been previously defined in a NAMELIST statement in the scoping unit. The name cannot contain embedded blanks and must be contained within a single record.

object

Is the name (or subobject designator) of an entity defined in the NAMELIST declaration of the group name. The object name must not contain embedded blanks except within the parentheses of a subscript or substring specifier. Each object must be contained in a single record.

value

Is any of the following:

  • A constant

    Each constant must be a literal constant of type integer, real, complex, logical, or character; or a nondelimited character string. Binary, octal, hexadecimal, Hollerith, and named constants are not permitted.

    In general, the form of the constant must be acceptable for the type of the list item. The data type of the constant determines the data type of the value and the translation from external to internal form. The following rules also apply:

    • A numeric list item can correspond only to a numeric constant, and a character list item can correspond only to a character constant. If the data types of a numeric list element and its corresponding numeric constant do not match, conversion is performed according to the rules for arithmetic assignment (see the table in Numeric Assignment Statements). Logical list items and logical constants are not considered numeric, unless the compiler option assume old_logical_ldio is specified.

    • A complex constant has the form of a pair of real or integer constants separated by a comma and enclosed in parentheses. Blanks can appear 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 values (.TRUE. or any value beginning with T, .T, t, or .t) or false values (.FALSE. or any value beginning with F, .F, f, or .f).

    A character string does not need delimiting apostrophes or quotation marks if the corresponding NAMELIST item is of type default character, and the following is true:

    • The character string does not contain a blank, comma (,), slash ( / ), exclamation point(!), ampersand (&), dollar sign ($), left parenthesis, equal sign (=), percent sign (%), or period (.).

      The character string is not continued across a record boundary.

    • The first nonblank character in the string is not an apostrophe or a quotation mark.

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

    A nondelimited character string is terminated by the first blank, comma, slash, end-of-record, exclamation, ampersand, or dollar sign encountered. Apostrophes and quotation marks within nondelimited character strings are transferred as is.

    If an equal sign, percent sign, or period is encountered while scanning for a nondelimited character string, the string is treated as a variable name (or part of one) and not as a nondelimited character string.

  • A null value

    A null value is specified by two consecutive value separators (such as two adjacent commas ",,") or a nonblank initial value separator. (A value separator before the end of the record does not signify a null value.)

    A null value indicates that the corresponding list element remains unchanged. A null value can represent an entire complex constant, but cannot be used for either part of a complex constant.

  • A repetition of a null value (r*) or a constant (r*constant), where r is an unsigned, nonzero, integer literal constant with no kind parameter, and no embedded blanks.

Blanks can precede or follow the beginning ampersand (&), follow the group name, precede or follow the equal sign, or precede the terminating slash.

Comments (beginning with ! only) can appear anywhere in namelist input. The comment extends to the end of the source line.

If an entity appears more than once within the input record for a namelist data transfer, the last value is the one that is used.

If there is more than one object = value pair, they must be separated by value separators.

A value separator is any number of blanks, or a comma or slash, preceded or followed by any number of blanks. When any of these appear in a character constant, they are considered part of the constant, not value separators.

The end of a record is equivalent to a blank character, except when it occurs in a character constant. In this case, 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 immediately followed by the first character of the next record).

Blanks at the beginning of a record are ignored unless they are part of a character constant continued from the previous record. In this case, the blanks at the beginning of the record are considered part of the constant.

When the name in the input record is an array variable or a variable of derived type, the effect is as if the variable represented were expanded into a sequence of scalar list items of intrinsic data types. Each input value following the equal sign must comply with format specifications for the intrinsic type of the list item in the corresponding position in the expanded sequence.

The number of values following the equal sign must be equal to or less than the number of list items in the expanded sequence. In the latter case (less than), the effect is as if null values have been added to match any remaining list items in the expanded sequence.

In Intel® Fortran, a list of values may follow the equal sign when the object is a single array element. In this case, values are assigned to the specified array element and subsequent elements, in element sequence order. For example, suppose the following input is read:

&ELEM
ARRAY_A(3)=34.54, 45.34, 87.63, 3*20.00
/

New values are assigned only to array ARRAY_A elements 3 through 8. The other element values are unchanged.

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 objects in that group. The =? causes display of the group name, objects within that group, and the current values for those objects (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 a blank followed by ? is entered on a terminal device, the following values are displayed:

  &NLIST
     A
     B
     C
  /

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

  &NLIST
      A  =   1.500000,
      B  =           2,
      C  = ABCDE
  /

Examples

Suppose the following statements are specified:

  NAMELIST /CONTROL/ TITLE, RESET, START, STOP, INTERVAL
  CHARACTER*10 TITLE
  REAL(KIND=8) START, STOP
  LOGICAL(KIND=4) RESET
  INTEGER(KIND=4) INTERVAL
  READ (UNIT=1, NML=CONTROL)

The NAMELIST statement associates the group name CONTROL with a list of five objects. The corresponding READ statement reads the following input data from unit 1:

  &CONTROL
         TITLE='TESTT002AA',
         INTERVAL=1,
         RESET=.TRUE.,
         START=10.2,
         STOP =14.5
 /

The following values are assigned to objects in group CONTROL:

Namelist Object

Value Assigned

TITLE

TESTT002AA

RESET

T

START

10.2

STOP

14.5

INTERVAL

1

It is not necessary to assign values to all of the objects declared in the corresponding NAMELIST group. If a namelist object does not appear in the input statement, its value (if any) is unchanged.

Similarly, when character substrings and array elements are specified, only the values of the specified variable substrings and array elements are changed. For example, suppose the following input is read:

&CONTROL TITLE(9:10)='BB' /

The new value for TITLE is TESTT002BB; only the last two characters in the variable change.

The following example shows an array as an object:

  DIMENSION ARRAY_A(20)
  NAMELIST /ELEM/ ARRAY_A
  READ (UNIT=1,NML=ELEM)

Suppose the following input is read:

&ELEM
ARRAY_A=1.1, 1.2,, 1.4
/

The following values are assigned to the ARRAY_A elements:

Array Element

Value Assigned

ARRAY_A(1)

1.1

ARRAY_A(2)

1.2

ARRAY_A(3)

Unchanged

ARRAY_A(4)

1.4

ARRAY_A(5)...ARRAY(20)

Unchanged

Nondelimited character strings that are written out by using a NAMELIST write may not be read in as expected by a corresponding NAMELIST read. Consider the following:

NAMELIST/TEST/ CHARR
CHARACTER*3 CHARR(4)
DATA CHARR/'AAA', 'BBB', 'CCC', 'DDD'/
OPEN (UNIT=1, FILE='NMLTEST.DAT')
WRITE (1, NML=TEST)
END

The output file NMLTEST.DAT will contain:

&TEST CHARR   = AAABBBCCCDDD/

If an attempt is then made to read the data in NMLTEST.DAT with a NAMELIST read using nondelimited character strings, as follows:

NAMELIST/TEST/ CHARR
CHARACTER*3 CHARR(4)
DATA CHARR/4*'   '/
OPEN (UNIT=1, FILE='NMLTEST.DAT')
READ (1, NML=TEST)
PRINT *, 'CHARR read in >', CHARR(1),'<  >',CHARR(2),'<  >',
1       CHARR(3), '<  >', CHARR(4), '<'
END

The result is the following:

CHARR read in >AAA<  >   <  >   <  >   <

See Also