FIX: Incorrect Results Using a COMPLEX Array in a NAMELIST (71186)



The information in this article applies to:

  • Microsoft FORTRAN Compiler for MS-DOS 5.0
  • Microsoft FORTRAN compiler for OS/2 5.0

This article was previously published under Q71186

SYMPTOMS

An application that uses a NAMELIST-directed READ statement to initialize an array of COMPLEX values generates incorrect results.

CAUSE

This error occurs when the data in the input file has one element per line.

RESOLUTION

To work around this problem, modify the data in the input file to place the data for all array elements on one line.

STATUS

Microsoft has confirmed this to be a problem in FORTRAN version 5.0 for MS-DOS and OS/2. This problem was corrected in FORTRAN version 5.1 for MS-DOS and OS/2.

MORE INFORMATION

The following code example reads the NAMELIST data file TEST.DAT.

Sample Code

C Compile options needed: None

      COMPLEX MYDATA(5)
      NAMELIST /XX/ MYDATA
      OPEN (1, FILE = 'TEST.DAT')
      READ (1, XX)
      WRITE (*, *) MYDATA
      END
				

NAMELIST Input File #1

&xx
mydata(1) = (1.0, 2.0)
mydata(2) = (3.0, 4.0)
mydata(3) = (5.0, 6.0)
mydata(4) = (7.0, 8.0)
mydata(5) = (9.0, 10.0)
/ 
				
Using NAMELIST Input File #1, the code example produces the following output.

(1.000000,3.000000) (5.000000,7.000000)
(9.000000,10.000000) (0.000000E+00,0.000000E+00)
(0.000000E+00,0.000000E+00)

The output should be as follows.

(1.000000,2.000000) (3.000000,4.000000)
(5.000000,6.000000) (7.000000,8.000000)
(9.000000,10.000000)

To work around this problem, rearrange the data in the input file to place all the elements on one line. The following input file demonstrates this solution.

NAMELIST Input File #2

&xx
mydata = (1.0, 2.0) (3.0, 4.0) (5.0, 6.0) (7.0, 8.0) (9.0, 10.0)
/ 
				
Note: A data file can contain repeat factors if the data contains more than one element with the same value. The following input file demonstrates this technique.

NAMELIST Input File #3

&xx
mydata = 2*(1.0, 2.0) (3.0, 4.0) (5.0, 6.0)
/ 
				

Modification Type:MajorLast Reviewed:10/23/2003
Keywords:kbfix KB71186