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

Last reviewed: September 16, 1997
Article ID: Q74690
5.10 | 5.10 MS-DOS | OS/2 kbprg kbfixlist kbbuglist

The information in this article applies to:

  • Microsoft FORTRAN for MS-DOS, version 5.1
  • Microsoft FORTRAN for OS/2, version 5.1

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 "nam1" 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 "nam1" 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 "nam2" 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 "nam1", followed by the EOF marker (e'), where an EOF error message will be generated.


Additional reference words: 5.10
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: FORTLngIss
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.