I have the following line of Fortran code early in my app:
OPEN(UNIT = FILDBGNUM, FILE = FILDBG, STATUS = 'REPLACE')
All arguments are appropriate. I am getting the error forrtl: severe (602): file not found.
Wait a second. The STATUS = 'REPLACE'. How could that error be generated?
Some things to check:
Question 1: Yes.
Question 2: Yes.
Question 3: Yes.
The OPEN statement is the first one encountered in the executable. This app is QuickWin and the OPEN is coming as part of command-line processing. Here is its routine:
SUBROUTINE OPEN_DEBUG_FILE() INTEGER DOT_POS DOT_POS = SCAN(FILIN, '.', BACK = .TRUE.) FILDBG = FILIN(1:DOT_POS) // 'dbg' OPEN(UNIT = FILDBGNUM, FILE = FILDBG, STATUS = 'REPLACE') END SUBROUTINE OPEN_DEBUG_FILE
FILIN is input as part of the command line. FILIN (CHARACTER string), FILDBG (CHARACTER string) and FILDBGNUM (INTEGER) are MODULE level variables. When the code is run in the VS debugger, the error occurs which is "OKed" and then the cursor is left on the OPEN statement with the claim of an Exception.
I take the opportunity of this thread about OPEN to add the following case/error experienced some weeks ago:
The remark is that an OPEN statement (with the IOSTAT parameter defined) should never crash unless the memory was corrupted.
Undoubtedly such a case would be caught by the Microsoft C++ compiler.
>>FILDBG (CHARACTER string) and FILDBGNUM (INTEGER) are MODULE level variables.
I do not see USE YourModuleName in the subroutine, nor do I see IMPLICIT NONE, therefore FILDBG, FILDBGNUM, ... are local implicit variables (undefined by the way).
The module where the SUBROUTINE lies is INPUTOUTPUTFILE. Within the module are the following definitions:
USE IFPORT, ONLY : MAXPATH IMPLICIT NONE CHARACTER (LEN = MAXPATH), PRIVATE :: FILIN CHARACTER (LEN = MAXPATH), PRIVATE :: FILDBG ! *.dbg INTEGER, PUBLIC, PARAMETER :: FILDBGNUM = 21 PRIVATE OPEN_DEBUG_FILE
Hope this clarifies.
Something is very weird here. The normal "file not found" error is 29, not 602, and the message includes the unit number and the name of the file it tried to open.
Can you put together a small, self-contained example that demonstrates the problem?
There is a discrepancy between the rather incomplete error reports in this thread and the full expansion of Error 602. The online documentation of the error, which you can see at https://software.intel.com/en-us/node/691978, is
602severe (602): File not foundFOR$IOS_F6416. An OPEN statement specified STATUS='OLD' for a specified file or a directory path that does not exist.
"The main program in the "reproducer" has no executable statements. How are any of the OPEN statements in the subroutines ever reached?"
I was wondering about that, but thought it was probably just my ignorance of Windozy Fortran.
The executable is QuickWin. The file open is happening as part of the INITIALSETTINGS FUNCTION call. No executable statements necessary.
Typical command line arguments are
0 0 "File_name"
I had this in the Debug command from Visual Studio. I assumed that was saved with the project, but I guess not. I suppose I should have saved my own user settings.
I created a text file called zzz.dbg containing a few text lines. When I invoke the program from the command line like this:
reproducer 0 0 zzz.dbg
or like this
reproducer 0 0 "zzz.dbg"
it immediately terminates with exit code 0. No window is displayed. The behaviour is the same with Debug and Release builds. Is this what is expected?
By the way I have a very old version of Intel Fortran, 11.0.075.
The program needs 4 arguments, not 3. With:
reproducer 0 0 zzz.dbg 0
a window is opened. If I write FILDBG to a log file, just before the OPEN statement in OPEN_DEBUG_FILE(), I see the correct file name in the log file. zzz.dbg is replaced as expected (it becomes an empty file.)
Presumably this is the desired behaviour.