I think the answer to the question in the topic is yes -- a Stack Overflow link is https://stackoverflow.com/questions/22635990/fortran-95-open-statement-status-variable-unknown-vs-replace . So I plan to tweet the following:
On Tuesday, March 15, 2022 at 2:53:18 PM UTC+1, Beliavsky wrote:
I think the answer to the question in the topic is yes -- a Stack Overflow link is https://stackoverflow.com/questions/22635990/fortran-95-open-statement-status-variable-unknown-vs-replace . So I plan to tweet the following:
That does not seem quite right: it presumes that you are going to write to the file, whereas you can open an existing file that way if you merely want to read it.
Regards,
Arjen
I think the answer to the question in the topic is yes --
To answer the question in the subject, I would say "Not necessarily".
The standard says that if STATUS is not specified, the value used is "UNKNOWN". In the implementations I am familiar with, this value does
behave the same as "REPLACE", but I'd be hesitant about generalizing that.
Writing a test case to determine behavior for a given implementation is
one thing, but then saying this is the behavior for all implementations
is unwarranted.
I think the answer to the question in the topic is yes -- a Stack Overflow link ishttps://stackoverflow.com/questions/22635990/fortran-95-open-statement-status-variable-unknown-vs-replace . So I plan to tweet the following:
open(unit=10,file="foo.txt",action="write",status="replace")
overwrites an existing file or creates a new file. Compilers usually treat
an unspecified STATUS the same way, but this is not mandated. STATUS="new" prevents overwriting a file.
To answer the question in the subject, I would say "Not necessarily".
The standard says that if STATUS is not specified, the value used is "UNKNOWN". In the implementations I am familiar with, this value does
behave the same as "REPLACE", but I'd be hesitant about generalizing that.
Writing a test case to determine behavior for a given implementation is
one thing, but then saying this is the behavior for all implementations
is unwarranted.
I think this might depend on more than just the compiler, it might also depend on the file system characteristics. An OS can support many file systems these days, including network file systems hosted by a different remote OS.
For another example, the VAX/VMS system had a file naming convention
that included version numbers, xxx.yyy.n.
If you opened a file with
'UNKNOWN', then you opened the file with the highest version number if
it existed, or you opened the xxx.yyy.1 file if it didn't. If you opened
the file with 'NEW', then you would get a new file with an incremented version number, and the old files were still there. This was before
'REPLACE' was one of the options. I think before the VAX, the DECSYSTEM
had a similar convention, but those OPEN() statements had a slightly different set of keywords because that was before f77 standardized that behavior.
It is supposed to work such that if you open without a ;(the version qualifier)
for reading you get the most recent, and for writing you get a new version. Exactly how that works with Fortran, I am not so sure.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 159 |
Nodes: | 16 (0 / 16) |
Uptime: | 99:24:22 |
Calls: | 3,209 |
Files: | 10,563 |
Messages: | 3,009,786 |