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.
If the file is connected for unformatted I/O, namelist data transfer is prohibited.
A namelist external record takes the following form:
&group-name object = value [,object = value].../
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 null value is specified by two consecutive value separators (such as ,,) 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.
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.
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:
During execution, if a blank followed by ? is entered on a terminal
device, the following values are displayed:
If a blank followed by =? is entered, the following values are
displayed:
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
&NLIST
A
B
C
/
&NLIST
A = 1.500000 ,
B = 2,
C = ABCDE
/
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 |
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. 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.