FIX: READ Does Not Pause or F6501 Error After CTRL+Z

Last reviewed: September 16, 1997
Article ID: Q81326
4.00 4.01 4.10 5.00 5.10 MS-DOS kbprg kbbuglist kbfixlist kberrmsg

The information in this article applies to:

  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, 5.1

SYMPTOMS

In an application compiled with Microsoft FORTRAN, when the user responds to a keyboard READ statement with a CTRL+Z character, subsequent READ statements do not pause for input or the run-time library generates the following message:

   run-time error F6501: READ(CON)
   - end of file encountered

CAUSE

When the user enters a CTRL+Z character to signify the end-of-file (EOF) condition, the run-time library sets an internal variable to indicate that the EOF has occurred. This variable remains set until the application executes a PRINT or WRITE statement. When the READ statement includes the END modifier and the internal EOF variable is set, execution branches immediately to the statement specified in the END modifier. When the READ statement does not include the END modifier and the internal EOF variable is set, the F6501 error occurs.

RESOLUTION

To address this problem, use the PRINT or WRITE statement to send information to the screen and to reset the internal EOF flag prior to each READ that may receive the CTRL+Z. Using the graphics function OUTTEXT to send output to the screen does not clear the internal EOF flag.

STATUS

Microsoft has confirmed this to be a problem in FORTRAN versions 4.0, 4.01, 4.1, 5.0 and 5.1 for MS-DOS. This problem was corrected in FORTRAN PowerStation, version 1.0.

MORE INFORMATION

The following code sample demonstrates this problem. If the user enters a CTRL+Z for the first READ statement, the application goes into an infinite loop.

Sample Code #1

C Compile options needed: None

      INCLUDE 'FGRAPH.FI'
      INCLUDE 'FGRAPH.FD'
      CHARACTER*1 CHR

10 READ (*, '(A)', END = 20) CHR 20 CALL OUTTEXT('Fill the screen!')
      READ (*, '(A)', END = 10) CHR
      PRINT *, CHR
      END

The following code example uses the WRITE statement to clear the internal EOF flag before the application encounters any EOF condition. When the user enters CTRL+Z, the application immediately resets the EOF flag and the each READ statement in the application pauses for input as expected.

Sample Code #2

C Compile options needed: None

      INCLUDE 'FGRAPH.FI'
      INCLUDE 'FGRAPH.FD'
      CHARACTER*1 CHR

      WRITE (*, *)
10 READ (*, '(A)', END = 20) CHR 20 CALL OUTTEXT('WRITES ONE LINE!')
      READ (*, '(A)', END = 10) CHR
      PRINT *, CHR
      END


Additional reference words: 4.00 4.01 4.10 5.00 5.10 buglist5.00
buglist5.10 fixlist1.00
KBCategory: kbprg kbbuglist kbfixlist kberrmsg
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.