I am try to link a file to a unit in an OPEN statement. I get an a error message that the system could not find the default file.
statement in program
forrt1: severe(29): file not found, unit 20, file C:\users\my.name\source\repos\console9\console9\fort.20
it appears to be looking for the default file name , which does not exist - rather than the file I created
The error message you report is typically a message you get when the program does not execute an explicit OPEN statement. Another giveaway is that your OPEN statement has an IOSTAT= keyword. If that is present, you are yourself responsible for checking the error and take the appropriate action if something is wrong.
Advice: check that your OPEN statement is actually executed. With the statement in isolation we cannot say much more than that, I am afraid. You would have to post a - preferably small - complete example exhibiting the problem, if we are to give more specific advice.
thanks for the response. I checked the IOSTAT value, it is 29 - the error message I get. What puzzles me is that I am able to open and use the output file, which is in the same directory. The actual code I just ran is below:
Filename='C:\clients\UNCC\METR 4105\homework\#6\CHS_Oct2_2015_raob_soundings1.txt\' status=0 OPEN(UNIT=10,FILE=filename,STATUS='OLD',ACTION='READ',IOSTAT=Ierror) write(*,*) 'input file IOSTAT= ',Ierror OPEN(Unit=11,FILE='C:\clients\UNCC\METR 4105\homework\#6\Ogden_homework6_output.txt',STATUS='OLD',ACTION='WRITE',IOSTAT=Ierror) write(*,*) 'output file IOSTAT= ', Ierror
Ierror after the first OPEN statement = 29, after the second OPEN statement = 0 . I am able to Write to the Output file, but the program appears to not be able to find the input file. I have gotten the program to execute successfully by copying my input to the default file name. The backslash ('\') at the end of the READ file name has no effect, I just tried removing it and I get the same error
Ah, that is clear then :)
Your OPEN statement is failing for some reason. But the program can continue (courtesy of the IOSTAT= keyword) and therefore reaches a write statement to unit 20 at some point. Fortran programs will use a default file name for units that are not currently connected to a file via the OPEN statement and that is what is now going on.
The simplest way to see what is going on is to temporarily remove the IOSTAT= keyword from your OPEN statement. The program will then fail with a hopefully detailed message. (You an get that message with the ERRMSG= keyword too, but this is the simplest solution ;)).
The error message -- the directory where the file is being sought, as well as the name "file.20" -- indicates that the problem may be that the READ statement is executed before the OPEN statement. The traceback printout should indicate the source line that caused the error, and you should be able to start investigating what happened. Look for "READ(20,..." or "READ(iu,...)" where iu has the value 20, or the possibility that "10" was meant but "20" was typed in an I/O statement or assignment of a value to a unit number.
The OPEN statement is executed, I printed the IOSTAT value immediately afterwards and it equals 29. The IOSTAT from the OPEN statement immediately after ward equals 0.
Apparently I misspelled the name, I simplified it and it now works. I'm sorry to have taken up your time with something so stupid (though all too common). I at least have learned some things.