Microsoft KB Archive/74690

= FIX: Erroneous Data File with FORM=UNFORMATTED, ACCESS=APPEND =

Article ID: 74690

Article Last Modified on 10/23/2003

-

APPLIES TO


 * Microsoft FORTRAN Compiler 5.1
 * Microsoft FORTRAN Compiler 5.1

-



This article was previously published under Q74690



SYMPTOMS
When a data file is opened as FORM='UNFORMATTED' and ACCESS='APPEND' in Microsoft FORTRAN version 5.1, extra copies of the data file, including beginning-of-file (BOF) and end-of-file (EOF) markers, are added to the file between the existing BOF and EOF markers. This can cause unpredictable or erroneous results during run-time. The following is the most common error message encountered:

run-time error F6501: READ(filename)

- end of file encountered



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



MORE INFORMATION
The following code reproduces the problem: character*4 nam1,nam2 nam1='nam1' nam2='nam2'

open(1,file='test.dat',form='unformatted',    + access='append') write(1) nam1 close(1)

open(1,file='test.dat',form='unformatted',    + access='append') write(1) nam2 rewind(1)

read(1) nam1 print*,nam1 read(1) nam2 print*,nam2 end This program creates an unformatted data file, which causes a BOF marker (K) to be written to the file, then writes &quot;nam1&quot; to the file. This causes the ASCII code for the number of bytes contained in the next record to be written, as appropriate for unformatted files, then word &quot;nam1&quot; is written and another length byte. An EOF marker (e') is written to the data file when the file is closed.

When the file is opened a second time, the file pointer is positioned just before the EOF marker, then the entire data file is copied out at that position. The data file now contains two EOF and BOF markers, in addition to two copies of the actual data already written to the file. The run-time then encounters the WRITE statement, and the word &quot;nam2&quot; is written to the file. The data file appears as follows:

K*nam1*K*nam1*e'*nam2*e'

where * represents char(4), the byte length inserted in unformatted files indicating the record is 4 bytes long. K is the BOF marker, and e' is the EOF marker.

In this case, closing or rewinding the file causes the file pointer to be positioned following the second beginning-of-file marker (the second K). Any subsequent READ will then read the word &quot;nam1&quot;, followed by the EOF marker (e'), where an EOF error message will be generated.

Additional query words: 5.10

Keywords: kbfix KB74690

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.