Microsoft KB Archive/81326

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

Article ID: 81326

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft FORTRAN Compiler 4.0
 * Microsoft FORTRAN Compiler 4.01
 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1

-



This article was previously published under Q81326



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 query words: 4.00 4.01 4.10 5.00 5.10 buglist5.00 buglist5.10 fixlist1.00

Keywords: kbfix KB81326

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.