FIX: Problem Reading Direct-Access File When RECL > BLOCKSIZELast reviewed: September 11, 1997Article ID: Q68030 |
4.01 4.10 5.00 | 4.10 5.00
MS-DOS | OS/2kbprg kbbuglist kbfixlist The information in this article applies to:
SYMPTOMSAn application that reads records from a file produces incorrect results. This problem does not occur when the application is compiled with Microsoft FORTRAN versions 4.0 or 4.0a for MS-DOS.
CAUSEThe application opens a direct access file with BLOCKSIZE set to a value that is less than the RECL (record length).
RESOLUTIONPerform one of the following three methods to work around this problem:
STATUSMicrosoft has confirmed this to be a problem in FORTRAN versions 4.01, 4.1, and 5.0 for MS-DOS and versions 4.1 and 5.0 for OS/2. This problem was corrected in FORTRAN version 5.1 for MS-DOS and OS/2.
MORE INFORMATIONThe code sample below demonstrates this problem. The first DO-loop in the application constructs a direct-access scratch file that contains four records. Then the application performs a partial read of record 3 from the scratch file. Finally, a DO-loop reads the file from record 1 to record 4 and writes the results on the screen. The program output indicates that the READ statement in the DO-loop improperly accesses the information in the scratch file. Because the RECL (record length) exceeds the BLOCKSIZE (buffer size), each READ statement causes the buffer to fill twice. Because the extra information is not flushed from the buffer, it is read into the ALINE variable each time the code executes a READ statement after the initial partial READ of record 3.
Sample CodeC Compile options needed: None
CHARACTER*514 ALINE CHARACTER*10 SHORT OPEN(9, ACCESS = 'DIRECT', RECL = 514, + FORM = 'FORMATTED', BLOCKSIZE = 512) ! NOTE: BLOCKSIZE < RECL DO 10 J = 1, 4 ! Create a file to read. ALINE = 'TEST ' // CHAR(#30 + J) ! Put the record number WRITE(9, 30, REC = J) ALINE ! into each record.10 CONTINUE
READ(9, 30, REC = 3) SHORT ! This is the partial READ ! of record 3. DO 20 I = 1, 4 READ(9, 30, REC = I) ALINE WRITE(*, *) ALINE20 CONTINUE 30 FORMAT(A) END |
Additional reference words: 4.01 4.10 5.00 buglist4.01 buglist4.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |