This is my simple code:
Program Example_Code
Implicit none
Integer :: iERR
Open( Unit = 15, File = 'Read_Something.txt', Action = 'Read', Status = 'Unknown', iostat = iERR )
If ( iERR /= 0 ) stop ( "There is no file Read_Something.txt !!!")
Close( 15, Status = 'Keep')
End Program Example_Code
In the project directory I did not create any .txt file( because I want to test opening file with iostat) and afther the program ends I find Read_Something.txt
in the project folder.
What is wrong in this example? Why does this obvious error occur?
IDE: Code::Blocks 17.12, TDM_GCC_5.0.1 - 03
OS: Win 10 X64
You use
status="unknown"
, that means the compiler can create the file for you so that you can read from it. If you want to open a file only when it exist, usestatus="old"
.BTW, I find it quite useless to explicitly specify any
="unknown"
, just leave the argument out completely. But that is my personal style.