Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Rules for Namelist Sequential WRITE Statements

Namelist, sequential WRITE statements translate data from internal to external 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 then written to an external file.

In general, values transferred as output have the same forms as values transferred as input. However, there is no guarantee that a REAL internal value transferred as output and then transferred as input as a REAL value will be the same internal value.

By default, character constants are not delimited by apostrophes or quotation marks, and each internal apostrophe or quotation mark is represented externally by one apostrophe or quotation mark.

This behavior can be changed by the DELIM specifier (in an OPEN statement) as follows:

  • If the file is opened with the DELIM='QUOTE' specifier, character constants are delimited by quotation marks and each internal quotation mark is represented externally by two consecutive quotation marks.

  • If the file is opened with the DELIM='APOSTROPHE' specifier, character constants are delimited by apostrophes and each internal apostrophe is represented externally by two consecutive apostrophes.

Each output statement writes one or more complete records.

If DECIMAL='POINT', the decimal point in a numeric value is displayed as a period, values are separated by commas, and the separator between the real and imaginary parts of a complex value is a comma. If DECIMAL='COMMA', the decimal point is displayed as a comma, values are separated by semicolons, and the separator between the real and imaginary parts of a complex value is a semicolon.

A literal character constant or complex constant can be longer than an entire record. For complex constants, the end of the record can occur between the comma or semicolon and the imaginary part, if the imaginary part and closing right parenthesis cannot fit in the current record. For literal constants that are longer than an entire record, the constant is continued onto as many records as necessary.

Each output record begins with a blank character for carriage control, except for literal character constants that are continued from the previous record.

Slashes, octal values, null values, and repeated forms of values are not output.

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

Examples

Consider the following statements:


CHARACTER*19 NAME(2)/2*' '/
REAL PITCH, ROLL, YAW, POSITION(3)
LOGICAL DIAGNOSTICS
INTEGER ITERATIONS
TYPE MYTYPE
   INTEGER X
   REAL Y
   CHARACTER(5)Z
END TYPE MYTYPE
TYPE(MYTYPE) :: TYPEVAR = MYTYPE(1,2.0,'ABCDE')
NAMELIST /PARAM/ NAME, PITCH, ROLL, TYPEVAR, YAW, POSITION,        &
         DIAGNOSTICS, ITERATIONS
... 
READ (UNIT=1,NML=PARAM)
WRITE (UNIT=2,NML=PARAM) 

Suppose the following input is read:

&PARAM
    NAME(2)(10:)='HEISENBERG',
    PITCH=5.0, YAW=0.0, ROLL=5.0,
    DIAGNOSTICS=.TRUE.
    ITERATIONS=10
/ 

The following is then written to the file connected to unit 2:

&PARAM
NAME    = '                         ', '        HEISENBERG',
PITCH   =    5.000000,
ROLL    =    5.000000,
TYPEVAR = 1, 2.0, 'ABCDE'
YAW     =   0.0000000E+00,
POSITION        = 3*0.0000000E+00,
DIAGNOSTICS     = T,
ITERATIONS      =                10
/

Note that character values are not enclosed in apostrophes unless the output file is opened with DELIM='APOSTROPHE'. The value of POSITION is not defined in the namelist input, so the current value of POSITION is written.

The following example declares a number of variables, which are placed in a namelist, initialized, and then written to the screen with namelist I/O:


       INTEGER(1) int1
       INTEGER    int2, int3, array(3)
       LOGICAL(1) log1
       LOGICAL log2, log3
       REAL    real1
       REAL(8) real2
       COMPLEX z1, z2
       CHARACTER(1)  char1
       CHARACTER(10) char2

       NAMELIST /example/ int1, int2, int3, log1, log2, log3,       &
      &          real1, real2, z1, z2, char1, char2, array

       int1     = 11
       int2     = 12
       int3     = 14
       log1     = .TRUE.
       log2     = .TRUE.
       log3     = .TRUE.
       real1    = 24.0
       real2    = 28.0d0
       z1       = (38.0,0.0)
       z2       = (316.0d0,0.0d0)
       char1    = 'A'
       char2    = '0123456789'
       array(1) = 41
       array(2) = 42
       array(3) = 43
       WRITE (*, example)

The preceding example produces the following output:


 &EXAMPLE
 INT1  =   11,
 INT2  =          12,
 INT3  =          14,
 LOG1  = T,
 LOG2  = T,
 LOG3  = T,
 REAL1 =   24.00000,
 REAL2 =   28.0000000000000,
 Z1    = (38.00000,0.0000000E+00),
 Z2    = (316.0000,0.0000000E+00),
 CHAR1 = A,
 CHAR2 = 0123456789,
 ARRAY =          41,          42,          43
 /