7.2.1.3 Namelist Sequential READ Statement

The namelist sequential READ statement performs the following operations:

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:

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