Fortran 95: open statement, status variable: unknown vs. replace
Asked Answered
R

1

5

I would like to know what is the different between this statement:

open(unit=11,file="something.TXT",status="unknown"), which is Fortran's default status (i.e., the previous statement is the same as open(unit=11,file="something.TXT")

and this statement:

open(unit=11,file="something.TXT",status="replace")

I have the impression that the unknown status behave exactly as I would expect with replace: if the file doesn't exist, it creates it. If it does exist, then it replaces it.

Remorse answered 25/3, 2014 at 13:24 Comment(0)
H
8

The Fortran standard lays down that the interpretation of status='unknown' is processor-dependent. That is, your impression is subtly incorrect.

In the draft of the 1995 standard I have at hand this is explained in section 9.3.4.2.

In the draft of the 2003 standard I have at hand this is explained in section 9.4.5.15.

Handbill answered 25/3, 2014 at 13:28 Comment(2)
What exactly processor-dependency means? But regardless of that, this then implies that in order to maximize portability, I must absolutely always assign a value to status when opening a file?Remorse
You got it right. Processor-dependent means that your compiler / run-time get to make the choice for you, if you want to be sure of the behaviour of the open statement you have to specify one of the other options for status=.Handbill

© 2022 - 2024 — McMap. All rights reserved.