Intel® Fortran Compiler 16.0 User and Reference Guide
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.
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. |
Is any of the following:
|
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.
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 /
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< > < > < > <