FIX: Problem Reading Direct-Access File When RECL > BLOCKSIZE

Last reviewed: September 11, 1997
Article ID: Q68030
4.01 4.10 5.00 | 4.10 5.00
MS-DOS         | OS/2
kbprg kbbuglist kbfixlist

The information in this article applies to:

  • Microsoft FORTRAN for MS-DOS, versions 4.01, 4.1, 5.0
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0

SYMPTOMS

An 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.

CAUSE

The application opens a direct access file with BLOCKSIZE set to a value that is less than the RECL (record length).

RESOLUTION

Perform one of the following three methods to work around this problem:

  • Modify the source code to use a record length less than or equal to the BLOCKSIZE (the default BLOCKSIZE value is 1024 bytes).
  • Modify the source code to access the direct-access file with a variable or group of variables, the length of which in bytes matches the record length. This technique avoids partial record access.
  • Modify the source code to specify a REWIND statement following any partial access to a record. The REWIND statement realigns the file pointer to the beginning of the file. (The BACKSPACE statement does not appear to solve this problem.)

STATUS

Microsoft 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 INFORMATION

The 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 Code

C 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(*, *) ALINE
20 CONTINUE 30 FORMAT(A)
      END


Additional reference words: 4.01 4.10 5.00 buglist4.01 buglist4.10
buglist5.00 fixlist5.10
KBCategory: kbprg kbbuglist kbfixlist
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 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.