• Re: With OPEN, unspecified STATUS behaves the same as STATUS = "replace

    From Arjen Markus@21:1/5 to Beliavsky on Tue Mar 15 07:14:53 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Beliavsky@21:1/5 to arjen.m...@gmail.com on Tue Mar 15 07:21:07 2022
    On Tuesday, March 15, 2022 at 10:14:56 AM UTC-4, arjen.m...@gmail.com wrote:
    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 meant for the question to apply to the case of action="write" but did not want to make the subject line too long. For the case of action="read" I would use status="old", and either leave out the iostat and let the program terminate if the file does not
    exist or set and handle iostat.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to Beliavsky on Tue Mar 15 16:54:17 2022
    Beliavsky <beliavsky@aol.com> schrieb:
    I think the answer to the question in the topic is yes --

    Not generally.

    Looking at the standard:

    12.5.6.18 STATUS= specifier in the OPEN statement

    [...]

    If UNKNOWN is specified, the status is processor dependent. If
    this specifier is omitted, the default value is UNKNOWN.

    Seems like gfortran actually does not document exactly what
    it does (it does for ACTION). Something to be cleared up
    in the documentation.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Steve Lionel on Wed Mar 16 14:54:29 2022
    On Wednesday, March 16, 2022 at 2:49:35 PM UTC-7, Steve Lionel wrote:

    (snip)

    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.

    But the important thing, is that it is true in some cases.

    That is, you could accidentally delete your "once in a lifetime" file
    if you didn't think about this in advance. Of course it is good to
    put read-only protection on those files, and presumably it
    won't override that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Steve Lionel@21:1/5 to Beliavsky on Wed Mar 16 17:49:30 2022
    On 3/15/2022 9:53 AM, Beliavsky wrote:
    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.

    --
    Steve Lionel
    ISO/IEC JTC1/SC22/WG5 (Fortran) Convenor
    Retired Intel Fortran developer/support
    Email: firstname at firstnamelastname dot com
    Twitter: @DoctorFortran
    LinkedIn: https://www.linkedin.com/in/stevelionel
    Blog: https://stevelionel.com/drfortran
    WG5: https://wg5-fortran.org

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ron Shepard@21:1/5 to Steve Lionel on Thu Mar 17 02:03:17 2022
    On 3/16/22 4:49 PM, Steve Lionel wrote:
    [...]
    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.

    $.02 -Ron Shepard

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Ron Shepard on Thu Mar 17 00:41:43 2022
    On Thursday, March 17, 2022 at 12:03:22 AM UTC-7, Ron Shepard wrote:

    (snip)

    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.

    It still does. Well, VAX/VMS is pretty much unsupported now, but
    Alpha/VMS and IA64/VMS still exist and are still supported.

    DECnet has support for remote files based on DEC file systems.
    I am not sure about using NFS to/from VMS based systems.

    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.

    I always tried to have my Fortran programs that read files open them
    in a read only mode, to avoid confusion by the OS, and accidentally
    deleting one.

    Before Fortran 77, the rules were somewhat complicated by the
    system figuring out what you meant, with the first I/O statement
    being READ or WRITE.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ron Shepard@21:1/5 to All on Fri Mar 18 01:54:09 2022
    On 3/17/22 2:41 AM, gah4 wrote:
    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.

    Ah yes, the version number was delimited with a ; not a period as I said
    in my post. It has been a while since I used a vax.

    I also remember something like a directory= keyword in open statements,
    that allowed you to open files in different directories than the default.

    And I also remember something like carriagecontrol='list', because the
    default was to use ASA formatting, which you almost never really wanted.

    Those things didn't make it into the standard, probably because they
    were all too specific to the DEC operating systems and file systems.

    $.02 -Ron Shepard

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)