XL Fortran for AIX 8.1

Language Reference


Namelist Formatting

In Fortran 90, namelist formatting can only be used with sequential files.

+-------------------------------IBM Extension--------------------------------+

XLF also allows namelist formatting to be used with internal files.

+----------------------------End of IBM Extension----------------------------+

Namelist Input Data

The form of input for namelist input is:

  1. Optional blanks
  2. The ampersand (&) character, followed immediately by the namelist group name specified in the NAMELIST statement
  3. One or more blanks
  4. A sequence of zero or more name-value subsequences, separated by value separators
  5. A slash to terminate the namelist input

Blanks at the beginning of an input record that continues a delimited character constant are considered part of the constant.

+-------------------------------IBM Extension--------------------------------+

If the NAMELIST run-time option has the value OLD, input for a NAMELIST statement consists of:

  1. Optional blanks
  2. An ampersand (&) or dollar sign ($), followed immediately by the namelist group name specified in the NAMELIST statement
  3. One or more blanks
  4. A sequence of zero or more name-value subsequences separated from each other by a single comma. A comma may be specified after the last name-value subsequence.
  5. &END or $END to signal the end of the data group
  6. The first character of each input record must be blank, including those records that continue a delimited character constant.

+----------------------------End of IBM Extension----------------------------+

+---------------------------------Fortran 95---------------------------------+

In Fortran 95, comments can be used in namelists.

Depending on whether a value of NEW or OLD is specified for the NAMELIST runtime option, different rules apply.

If a value of NEW is specified for the NAMELIST runtime option, the rules for namelist comments are:

+-----------------------------End of Fortran 95------------------------------+

+-------------------------------IBM Extension--------------------------------+

If a value of OLD is specified for the NAMELIST runtime option, the rules for namelist comments are:

+----------------------------End of IBM Extension----------------------------+

The form of a name-value subsequence in an input record is:



>>-name-- = --constant_list------------------------------------><
 
 

name
is a variable

constant
has the following forms:



>>-+----+--literal_constant------------------------------------><
   '-r*-'
 
 

r
is an unsigned, nonzero, scalar, integer literal constant specifying the number of times the literal_constant is to occur. r cannot specify a kind type parameter.

literal_constant
is a scalar literal constant of intrinsic type that cannot specify a kind type parameter, or it is a null value. The constant is treated as if it had the same kind type parameter as the corresponding list item. If literal_constant is of type character, it must be delimited by apostrophes or quotation marks. If literal_constant is of type logical, it can be specified as T or F.

Any subscripts, strides, and substring range expressions used to qualify name must be integer literal constants with no kind type parameter specified.

For information on the type of noncharacter input data, see List-Directed Input.

If name is neither an array nor an object of derived type, constant_list must contain only a single constant.

Variable names specified in the input file must appear in the namelist list, but the order of the input data is not significant. A name that has been made equivalent to name cannot be substituted for that name in the namelist list. See NAMELIST for details on what can appear in a namelist list.

In each name-value subsequence, the name must be the name of a namelist group item with an optional qualification. The name with the optional qualification must not be a zero-sized array, zero-sized array section, or zero-length character string. The optional qualification, if specified, must not contain a vector subscript.

If name is an array or array section without vector subscripts, it is expanded into a list of all the elements of the array, in the order that they are stored. If name is a structure, it is expanded into a list of ultimate components of intrinsic type, in the order specified in the derived-type definition. The ultimate components of the derived type can not be pointers or allocatables.

If name is an array or structure, the number of constants in constant_list must be less than or equal to the number of items specified by the expansion of name. If the number of constants is less than the number of items, the remaining items retain their former values.

A null value is specified by:

A null value has no effect on the definition status of the corresponding input list item. If the namelist group object list item is defined, it retains its previous value; if it is undefined, it remains undefined. A null value must not be used as either the real or imaginary part of a complex constant, but a single null value can represent an entire complex constant.

The end of a record following a value separator, with or without intervening blanks, does not specify a null value.

+-------------------------------IBM Extension--------------------------------+

When the LANGLVL run-time option is set to EXTENDED, XL Fortran allows multiple input values to be specified in conjunction with a single array element. The array element cannot specify subobject designators. When this occurs, the values are assigned to successive elements of the array, in array element order. For example, suppose that array A is declared as follows:

      INTEGER A(100)
      NAMELIST /FOO/ A
      READ (5, FOO)

and that the following input appears in unit 5:

 &FOO
 A(3) = 2, 10, 15, 16
 /

During execution of the READ statement, the value 2 is assigned to A(3), 10 is assigned to A(4), 15 is assigned to A(5), and 16 is assigned to A(6).

If multiple values are specified in conjunction with a single array element, any logical constant must be specified with a leading period (for example, .T).

If the NAMELIST run-time option is specified with the value OLD, the BLANK= specifier determines how embedded and trailing blanks between noncharacter constants are treated.

If the -qmixed compiler option is specified, the namelist group name and list item names are treated in a case-sensitive manner.

+----------------------------End of IBM Extension----------------------------+

A slash encountered as a value separator during the execution of a namelist input statement causes termination of execution of that input statement after assignment of the previous value. If there are additional items in the namelist group object being transferred, the effect is as if null values had been supplied for them.

Example of Namelist Input Data

File NMLEXP contains the following data before the READ statement is executed:

Character position:

         1         2         3
1...+....0....+....0....+....0

File contents:

 &NAME1
 I=5,
 SMITH%P_AGE=40
 /

The above file contains four data records. The program contains the following:

TYPE PERSON
  INTEGER P_AGE
  CHARACTER(20) P_NAME
END TYPE PERSON
TYPE(PERSON) SMITH
NAMELIST /NAME1/ I,J,K,SMITH
I=1
J=2
K=3
SMITH=PERSON(20,'John Smith')
OPEN(7,FILE='NMLEXP')
READ(7,NML=NAME1)
! Only the value of I and P_AGE in SMITH are
! altered (I = 5, SMITH%P_AGE = 40).
! J, K and P_NAME in SMITH remain the same.
END

Note:
In the previous example, the data items appear in separate data records. The following example is a file with the same data items, but they are in one data record:

Character position:

         1         2         3         4
1...+....0....+....0....+....0....+....0

File contents:

 &NAME1 I= 5, SMITH%P_AGE=40 /

+---------------------------------Fortran 95---------------------------------+

An example of a NAMELIST comment when NAMELIST=NEW is specified and the NAMELIST comment appears after the value separator space.

&TODAY I=12345         ! This is a comment. /
X(1)=12345, X(3:4)=2*1.5, I=6,
P="!ISN'T_BOB'S", Z=(123,0)/

+-----------------------------End of Fortran 95------------------------------+

+-------------------------------IBM Extension--------------------------------+

An example of a NAMELIST comment when NAMELIST=OLD is specified and the NAMELIST comment appears after a comma separator.

&TODAY I=12345,        ! This is a comment.
X(1)=12345, X(3:4)=2*1.5, I=6,
P="!ISN'T_BOB'S", Z=(123,0) &END

+----------------------------End of IBM Extension----------------------------+

Namelist Output Data

When output data is written using a namelist list, it is written in a form that can be read using a namelist list (except for character data that is not delimited). All variables specified in the namelist list and their values are written out, each according to its type. Character data is delimited as specified by the DELIM= specifier. The fields for the data are made large enough to contain all the significant digits. (See Table 13 for information on the fields.) The values of a complete array are written out in column-major order.

+-------------------------------IBM Extension--------------------------------+

A WRITE statement with a namelist list produces a minimum of three output records: one record containing the namelist name, followed by one or more records containing output data items, and a final record containing the slash (/) end marker. An internal file meant to receive namelist output must be a character array containing at least three elements. More than three array elements may be required, depending on the amount of data transferred in the WRITE statement. You cannot use one long character variable, even if it is large enough to hold all of the data. If the length of the array element to hold the data is not sufficient, it will be necessary to specify an array with more than three array elements.

+----------------------------End of IBM Extension----------------------------+

If the NAMELIST run-time option is not specified or if NAMELIST=NEW, the namelist group name and namelist item names are output in uppercase.

+-------------------------------IBM Extension--------------------------------+

If NAMELIST=OLD is specified, the namelist group name and namelist item names are output in lower case. If the -qmixed compiler option is specified, the name is case sensitive, regardless of the value of the NAMELIST run-time option.

If NAMELIST=OLD is specified, the end of the output record will be signaled by &end.

If the NAMELIST run-time option is specified with the value OLD and the DELIM= specifier is not specified, character data is delimited by apostrophes. Non-delimited character strings will be delimited by apostrophes and will be separated from each other by commas. Also, blanks will not be added to the beginning of a record that starts with the continuation of a character string from the previous record.

+----------------------------End of IBM Extension----------------------------+

Character constants produced for a file opened without a DELIM= specifier or with a DELIM= specifier with a value of NONE:

Nondelimited character data that has been written out cannot be read as character data.

+-------------------------------IBM Extension--------------------------------+

For internal files, character constants are written with a value of APOSTROPHE for the DELIM= specifier.

+----------------------------End of IBM Extension----------------------------+

Character constants produced for a file opened with a DELIM= specifier with a value of QUOTE are delimited by double quotation marks, are preceded and followed by a value separator, and have each internal quotation mark represented on the external medium by two contiguous quotation marks.

Character constants produced for a file opened with a DELIM= specifier with a value of APOSTROPHE are delimited by apostrophes, are preceded and followed by a value separator, and have each internal apostrophe represented on the external medium by two contiguous apostrophes.

+-------------------------------IBM Extension--------------------------------+

To restrict namelist output records to a given width, specify the RECL= specifier (in the OPEN statement) or the NLWIDTH run-time option. See the User's Guide for information on the NLWIDTH run-time option.

+----------------------------End of IBM Extension----------------------------+

Except for continuation of delimited character constants, each output record begins with a blank character to provide carriage control when the record is printed.

+-------------------------------IBM Extension--------------------------------+

For external files, by default, all of the output items appear in a single output record wide enough to contain them. To have the record output on separate lines, use the RECL= specifier (in the OPEN statement) or the NLWIDTH run-time option.

+----------------------------End of IBM Extension----------------------------+

For information on the type of noncharacter output data, see List-Directed Output.

Example of Namelist Output Data

TYPE PERSON
  INTEGER P_AGE
  CHARACTER(20) P_NAME
END TYPE PERSON
TYPE(PERSON) SMITH
NAMELIST /NL1/ I,J,C,SMITH
CHARACTER(5) :: C='BACON'
INTEGER I,J
I=12046
J=12047
SMITH=PERSON(20,'John Smith')
WRITE(6,NL1)
END

After execution of the WRITE statement with NAMELIST=NEW, the output data is:

    1         2         3         4
1...+....0....+....0....+....0....+....0
 &NL1
 I=12046, J=12047, C=BACON, SMITH=20, John Smith
 /

+-------------------------------IBM Extension--------------------------------+

After execution of the WRITE statement with NAMELIST=OLD, the output data is:

    1         2         3         4
1...+....0....+....0....+....0....+....0
 &nl1
 i=12046, j=12047, c='BACON', smith=20, 'John Smith          '
 &end

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]