FIX: Erroneous Data File with FORM=UNFORMATTED, ACCESS=APPENDLast reviewed: September 16, 1997Article ID: Q74690 |
5.10 | 5.10
MS-DOS | OS/2
kbprg kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSWhen 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 STATUSMicrosoft 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 INFORMATIONThe 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 endThis 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |