FIX: Read-Only UNFORMATTED Files Hang the Machine (77505)
The information in this article applies to:
- Microsoft FORTRAN Compiler for MS-DOS 5.0
- Microsoft FORTRAN Compiler for MS-DOS 5.1
- Microsoft FORTRAN compiler for OS/2 5.0
- Microsoft FORTRAN compiler for OS/2 5.1
This article was previously published under Q77505 SYMPTOMS
If a program compiled under Microsoft FORTRAN version 5.0 or 5.1 writes to
a file that has the READ-ONLY attribute set and is OPENed
FORM='UNFORMATTED', the run-time system may return the following
message:
run-time error F6421: CLOSE(Test.DAT)
- File READ-ONLY or locked against writing.
This message may be displayed several times under MS-DOS before the machine
finally hangs. Under OS/2, the same error message may be displayed several
times before a protection violation is generated. Sample code 1 below
illustrates this problem.
When attempting to read from a non-existent file OPENed with MODE='READ'
and FORM='UNFORMATTED', this same error message may be generated several
times and the machine may hang. In OS/2, a protection violation may be
generated after the message is displayed several times. Sample code 2 below
illustrates this problem.
If a file is OPENed MODE='READ' and the program attempts to WRITE to that
file, the same run-time error F6421 is generated several times and then the
machine may hang. Under OS/2, the same message may be generated several
times before producing a protection violation. Sample code 3 below
illustrates this problem.
CAUSE
Normally, if the run-time system performs an OPEN statement, it first tries
to open the file with the READWRITE attribute; if it fails, it will try
again with MODE='READ'. If the run-time system fails again, it tries to
open the file with MODE='WRITE'. If it fails each time, it will generate a
run-time error or it will run the instructions in the line specified in the
ERR label.
In the case of the UNFORMATTED file, the OPEN statement is not checking the
file attributes unless the file is OPENed in a specific mode. The OPEN
command is ignoring the ERR label unless the MODE is set to READWRITE,
READ, or WRITE. Writing to READ-ONLY DIRECT access, BINARY, and FORMATTED
files does not produce this problem.
RESOLUTION
A solution to this problem is to set the MODE attribute in the OPEN
statement for unformatted files. If the user is not sure of the present
status of the file to be accessed, the status can be requested using the
INQUIRE statement before attempting to open the desired file.
However, when OPENing a file with MODE='READ' in addition to
FORM='UNFORMATTED' and then attempting to WRITE to that file or READ from a
non-existent file, the same run-time error F6421 and machine hang or
protection violation will be generated. There is no known work-around for
this problem at this time.
STATUS
Microsoft has confirmed this to be a problem in Microsoft FORTRAN versions
5.0 and 5.1. This problem was corrected in FORTRAN PowerStation, version
1.0.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | KB77505 |
---|
|