Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"I am your density." -- George McFly in "Back to the Future"


devel / comp.lang.fortran / end-of-file IOSTAT / debugging

SubjectAuthor
* end-of-file IOSTAT / debuggingDave Tholen
+* Re: end-of-file IOSTAT / debuggingRobin Vowels
|+* Re: end-of-file IOSTAT / debuggingSteve Lionel
||+- Re: end-of-file IOSTAT / debuggingRobin Vowels
||`- Re: end-of-file IOSTAT / debuggingDave Tholen
|`* Re: end-of-file IOSTAT / debuggingDave Tholen
| `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|  `* Re: end-of-file IOSTAT / debuggingDave Tholen
|   +* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |`* Re: end-of-file IOSTAT / debuggingDave Tholen
|   | `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |  `* Re: end-of-file IOSTAT / debuggingDave Tholen
|   |   `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |    `* Re: end-of-file IOSTAT / debuggingDave Tholen
|   |     +* Re: end-of-file IOSTAT / debuggingLouis Krupp
|   |     |`- Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     +- Re: end-of-file IOSTAT / debuggingThomas Koenig
|   |     +* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |+* Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     ||+- Re: end-of-file IOSTAT / debuggingPeter Klausler US
|   |     ||+- Re: end-of-file IOSTAT / debuggingPeter Klausler US
|   |     ||+* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |||`* Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     ||| `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |||  `* Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     |||   `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |||    +- Re: end-of-file IOSTAT / debuggingJohn
|   |     |||    `* Re: end-of-file IOSTAT / debuggingJohn
|   |     |||     `- Re: end-of-file IOSTAT / debugginggah4
|   |     ||`* Re: end-of-file IOSTAT / debugginggah4
|   |     || `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     ||  `- Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     |+* Re: end-of-file IOSTAT / debuggingSteve Lionel
|   |     ||+* Re: end-of-file IOSTAT / debuggingRobert Corbett
|   |     |||`- Re: end-of-file IOSTAT / debugginggah4
|   |     ||`* Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     || +* Re: end-of-file IOSTAT / debugginggah4
|   |     || |`- Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     || +* Re: end-of-file IOSTAT / debuggingSteve Lionel
|   |     || |`- Re: end-of-file IOSTAT / debuggingRon Shepard
|   |     || `- Re: end-of-file IOSTAT / debuggingGary Scott
|   |     |`* Re: end-of-file IOSTAT / debuggingDave Tholen
|   |     | +- Re: end-of-file IOSTAT / debugginggah4
|   |     | `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |  `* Re: end-of-file IOSTAT / debuggingDave Tholen
|   |     |   +* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |   |`- Re: end-of-file IOSTAT / debuggingDave Tholen
|   |     |   `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |    `* Re: end-of-file IOSTAT / debuggingDave Tholen
|   |     |     `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |     |      `- Re: end-of-file IOSTAT / debuggingDave Tholen
|   |     `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|   |      `- Re: end-of-file IOSTAT / debuggingDave Tholen
|   `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|    `* Re: end-of-file IOSTAT / debuggingDave Tholen
|     +* Re: end-of-file IOSTAT / debuggingFortranFan
|     |`* Re: end-of-file IOSTAT / debuggingDave Tholen
|     | +- Re: end-of-file IOSTAT / debuggingFortranFan
|     | `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|     |  `* Re: end-of-file IOSTAT / debuggingDave Tholen
|     |   +* Re: end-of-file IOSTAT / debuggingRobin Vowels
|     |   |`* Re: end-of-file IOSTAT / debuggingDave Tholen
|     |   | +* Re: end-of-file IOSTAT / debuggingLouis Krupp
|     |   | |`* Re: end-of-file IOSTAT / debuggingDave Tholen
|     |   | | `* Re: end-of-file IOSTAT / debuggingLouis Krupp
|     |   | |  `* Re: end-of-file IOSTAT / debuggingDave Tholen
|     |   | |   `- Re: end-of-file IOSTAT / debuggingLouis Krupp
|     |   | `* Re: debuggingRobin Vowels
|     |   |  `* Re: debuggingDave Tholen
|     |   |   `* Re: debuggingRobin Vowels
|     |   |    `- Re: debuggingDave Tholen
|     |   `- Re: end-of-file IOSTAT / debuggingThomas Koenig
|     `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|      `* Re: end-of-file IOSTAT / debuggingDave Tholen
|       `* Re: end-of-file IOSTAT / debuggingRobin Vowels
|        `- Re: end-of-file IOSTAT / debuggingDave Tholen
+* Re: end-of-file IOSTAT / debuggingsteve kargl
|+* Re: end-of-file IOSTAT / debuggingDave Tholen
||`* Re: end-of-file IOSTAT / debuggingSteve Lionel
|| `- Re: end-of-file IOSTAT / debuggingFortranFan
|`* Re: end-of-file IOSTAT / debuggingLouis Krupp
| `* Re: end-of-file IOSTAT / debuggingDave Tholen
|  +* Re: end-of-file IOSTAT / debuggingFortranFan
|  |`* Re: end-of-file IOSTAT / debuggingRon Shepard
|  | `* Re: end-of-file IOSTAT / debuggingFortranFan
|  |  +- Re: end-of-file IOSTAT / debuggingJohn
|  |  `* Re: end-of-file IOSTAT / debugginggah4
|  |   `- Re: end-of-file IOSTAT / debuggingDick Hendrickson
|  +- Re: end-of-file IOSTAT / debuggingLouis Krupp
|  `- Re: end-of-file IOSTAT / debuggingRobin Vowels
+* Re: end-of-file IOSTAT / debugginggah4
|+- Re: end-of-file IOSTAT / debuggingRobin Vowels
|`- Re: end-of-file IOSTAT / debuggingRobin Vowels
`* Re: end-of-file IOSTAT / debugginggah4
 +- Re: end-of-file IOSTAT / debuggingjfh
 +* Re: end-of-file IOSTAT / debuggingDave Tholen
 |`* Re: end-of-file IOSTAT / debugginggah4
 | `* Re: end-of-file IOSTAT / debuggingRobin Vowels
 |  +* Re: end-of-file IOSTAT / debuggingLouis Krupp
 |  |+* Re: end-of-file IOSTAT / debugginggah4
 |  ||`- Re: end-of-file IOSTAT / debuggingDave Tholen
 |  |`- Re: end-of-file IOSTAT / debuggingDave Tholen
 |  +- Re: end-of-file IOSTAT / debuggingRon Shepard
 |  `- Re: end-of-file IOSTAT / debuggingDave Tholen
 `- Re: end-of-file IOSTAT / debuggingGary Scott

Pages:12345
end-of-file IOSTAT / debugging

<tark4g$5or$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2519&group=comp.lang.fortran#2519

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!iayahv1glVWjKlPuzXRjog.user.46.165.242.91.POSTED!not-for-mail
From: tholen@antispam.ham (Dave Tholen)
Newsgroups: comp.lang.fortran
Subject: end-of-file IOSTAT / debugging
Date: Fri, 15 Jul 2022 01:47:26 -1000
Organization: Aioe.org NNTP Server
Message-ID: <tark4g$5or$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="5915"; posting-host="iayahv1glVWjKlPuzXRjog.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dave Tholen - Fri, 15 Jul 2022 11:47 UTC

If you read (sequentially) past the end-of-file, gfortran sets the value
of IOSTAT to -1, but if you read a second time, gfortran sets the value
of IOSTAT to 5001. I discovered this situation after having written a
program expecting subsequent READs to all return a negative number, and
of course the program didn't behave as expected until I investigated the
problem. So I'm curious as to why the choice was made to have IOSTAT
set to something other than -1 on any READ attempt after the end-of-file
condition has been triggered. Isn't the file pointer still just beyond
the last record in the file, even after the first failed READ?

On a completely separate matter, I have a different program that
didn't behave as expected, and that misbehavior was totally repeatable.
In an attempt to debug the program, I added a WRITE statement to check
on the value of a variable during execution. However, once the WRITE
statement was added, the program started behaving properly, repeatably.
Comment out the added WRITE statement, and the program once again
misbehaves, repeatedly. Re-enable the WRITE statement, and everything
is once again hunky-dory. Damned frustrating. It's too easy to blame
the optimizer. Anybody have any generic advice on what to look for in
such a situation?

Re: end-of-file IOSTAT / debugging

<7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2520&group=comp.lang.fortran#2520

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:188:b0:31e:cdfc:5dca with SMTP id s8-20020a05622a018800b0031ecdfc5dcamr10648343qtw.111.1657896356593;
Fri, 15 Jul 2022 07:45:56 -0700 (PDT)
X-Received: by 2002:a05:6808:1596:b0:337:8c17:b17f with SMTP id
t22-20020a056808159600b003378c17b17fmr7559731oiw.294.1657896356355; Fri, 15
Jul 2022 07:45:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 15 Jul 2022 07:45:56 -0700 (PDT)
In-Reply-To: <tark4g$5or$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Fri, 15 Jul 2022 14:45:56 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2836
 by: Robin Vowels - Fri, 15 Jul 2022 14:45 UTC

On Friday, July 15, 2022 at 9:47:37 PM UTC+10, Dave Tholen wrote:
> If you read (sequentially) past the end-of-file, gfortran sets the value
> of IOSTAT to -1, but if you read a second time, gfortran sets the value
> of IOSTAT to 5001. I discovered this situation after having written a
> program expecting subsequent READs to all return a negative number, and
> of course the program didn't behave as expected until I investigated the
> problem. So I'm curious as to why the choice was made to have IOSTAT
> set to something other than -1 on any READ attempt after the end-of-file
> condition has been triggered. Isn't the file pointer still just beyond
> the last record in the file, even after the first failed READ?

You are expected to test for IOSTAT and deal with the end-of-file condition.
You are not expected to continue reading the file.
>
>
> On a completely separate matter, I have a different program that
> didn't behave as expected, and that misbehavior was totally repeatable.
> In an attempt to debug the program, I added a WRITE statement to check
> on the value of a variable during execution. However, once the WRITE
> statement was added, the program started behaving properly, repeatably.

That suggests that there is a bug in your program. Possibly something has
been overwritten.
Turn on subscript bounds checking (if available).
And while you're at it, turn on all checks.

> Comment out the added WRITE statement, and the program once again
> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
> is once again hunky-dory. Damned frustrating. It's too easy to blame
> the optimizer. Anybody have any generic advice on what to look for in
> such a situation?

Re: end-of-file IOSTAT / debugging

<tas99e$3423t$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2522&group=comp.lang.fortran#2522

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: sgk@REMOVEtroutmask.apl.washington.edu (steve kargl)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: Fri, 15 Jul 2022 17:48:30 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <tas99e$3423t$1@dont-email.me>
References: <tark4g$5or$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 15 Jul 2022 17:48:30 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ad1297fb719379b6c0a7236f5d16c061";
logging-data="3278973"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+L+YAMeVXgvNhwG80NSkmk"
User-Agent: XPN/1.2.6 (Street Spirit ; FreeBSD)
Cancel-Lock: sha1:ud/plLLVfzbwLdhfcP7iMtawo4Q=
 by: steve kargl - Fri, 15 Jul 2022 17:48 UTC

Dave Tholen wrote:

> If you read (sequentially) past the end-of-file, gfortran sets the value
> of IOSTAT to -1, but if you read a second time, gfortran sets the value
> of IOSTAT to 5001. I discovered this situation after having written a
> program expecting subsequent READs to all return a negative number, and
> of course the program didn't behave as expected until I investigated the
> problem. So I'm curious as to why the choice was made to have IOSTAT
> set to something other than -1 on any READ attempt after the end-of-file
> condition has been triggered. Isn't the file pointer still just beyond
> the last record in the file, even after the first failed READ?

What version of the compiler and operating system?

What does IOMSG tell you? Likely, you have hit two different errors.

> On a completely separate matter, I have a different program that
> didn't behave as expected, and that misbehavior was totally repeatable.
> In an attempt to debug the program, I added a WRITE statement to check
> on the value of a variable during execution. However, once the WRITE
> statement was added, the program started behaving properly, repeatably.
> Comment out the added WRITE statement, and the program once again
> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
> is once again hunky-dory. Damned frustrating. It's too easy to blame
> the optimizer. Anybody have any generic advice on what to look for in
> such a situation?

Remove the write statement and compile with -Wall -fcheck=all. This
might find where you are stomping on memory.

--
steve

Re: end-of-file IOSTAT / debugging

<312dfeaf-4ab4-4d94-86f5-d94f8cf62ac2n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2523&group=comp.lang.fortran#2523

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:2903:b0:6af:41a4:3f71 with SMTP id m3-20020a05620a290300b006af41a43f71mr11147679qkp.350.1657916405839;
Fri, 15 Jul 2022 13:20:05 -0700 (PDT)
X-Received: by 2002:a0d:dbc3:0:b0:31d:f1e:7e8e with SMTP id
d186-20020a0ddbc3000000b0031d0f1e7e8emr17747697ywe.180.1657916405683; Fri, 15
Jul 2022 13:20:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 15 Jul 2022 13:20:05 -0700 (PDT)
In-Reply-To: <tark4g$5or$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:c5c1:b8c1:5462:1ee4;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:c5c1:b8c1:5462:1ee4
References: <tark4g$5or$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <312dfeaf-4ab4-4d94-86f5-d94f8cf62ac2n@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: gah4@u.washington.edu (gah4)
Injection-Date: Fri, 15 Jul 2022 20:20:05 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 25
 by: gah4 - Fri, 15 Jul 2022 20:20 UTC

On Friday, July 15, 2022 at 4:47:37 AM UTC-7, Dave Tholen wrote:
> If you read (sequentially) past the end-of-file, gfortran sets the value
> of IOSTAT to -1, but if you read a second time, gfortran sets the value
> of IOSTAT to 5001. I discovered this situation after having written a
> program expecting subsequent READs to all return a negative number, and
> of course the program didn't behave as expected until I investigated the
> problem. So I'm curious as to why the choice was made to have IOSTAT
> set to something other than -1 on any READ attempt after the end-of-file
> condition has been triggered. Isn't the file pointer still just beyond
> the last record in the file, even after the first failed READ?

I haven't thought about this in a lot of years, but in the days of
magnetic tapes, some systems allowed one to read the EOF,
and then go on to the next file on the tape.

Though Fortran 66 has no method for detecting EOF, you are just
supposed to stop reading before it happens.

I believe for tapes in Unix, when you get to the end, the system
call return 0 bytes, as the sign of the EOF, and then you go onto
the next file. (That is, past the tape mark.)

Disk files don't do that, though.

Re: end-of-file IOSTAT / debugging

<jje18mFtcl0U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2524&group=comp.lang.fortran#2524

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: steve@seesignature.invalid (Steve Lionel)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: 15 Jul 2022 20:33:26 GMT
Lines: 35
Message-ID: <jje18mFtcl0U1@mid.individual.net>
References: <tark4g$5or$1@gioia.aioe.org>
<7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net J3Rplfd3x2rCttVFpEf/CwEMmb1ZcMH4pl5M/5D6fmirWFv0ws
Cancel-Lock: sha1:8vXuZzG557MkW8epEcAZYFYKs9w=
User-Agent: Pan/0.146 (Hic habitat felicitas; d7a48b4
gitlab.gnome.org/GNOME/pan.git)
 by: Steve Lionel - Fri, 15 Jul 2022 20:33 UTC

On Fri, 15 Jul 2022 07:45:56 -0700, Robin Vowels wrote:

> You are expected to test for IOSTAT and deal with the end-of-file
> condition.
> You are not expected to continue reading the file.

MIL-STD-1753 specified that you could, when reading magnetic tape (see
https://stevelionel.com/drfortran/2020/05/16/doctor-fortran-in-military-
strength/).

The Fortran standard says (12.11.1), that when an "endfile record is
encountered during the reading of a file connected for sequential access",
"if the file specified in the input statement is an external record file,
it is positioned after the endfile record;" (12.11.3). What happens after
that is not specified, though you are allowed to BACKSPACE over the
endfile record. Note that there doesn't need to be any physical
representation of an endfile record.

gfortran is within its rights to give you a different IOSTAT value in this
case, and I could make an argument that -1 is NOT the correct thing to
return here. I tried ifort and nagfor - ifort returns -1 on the read past
the EOF, nagfor uses 210, corresponding to "READ/WRITE attempted after
ENDFILE on unit 1". (I can't get too worked up over ifort returning -1,
however...)

--
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

Re: end-of-file IOSTAT / debugging

<tat4bt$1ndf$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2527&group=comp.lang.fortran#2527

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!iayahv1glVWjKlPuzXRjog.user.46.165.242.91.POSTED!not-for-mail
From: tholen@antispam.ham (Dave Tholen)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: Fri, 15 Jul 2022 15:30:36 -1000
Organization: Aioe.org NNTP Server
Message-ID: <tat4bt$1ndf$1@gioia.aioe.org>
References: <tark4g$5or$1@gioia.aioe.org>
<7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="56751"; posting-host="iayahv1glVWjKlPuzXRjog.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dave Tholen - Sat, 16 Jul 2022 01:30 UTC

>> If you read (sequentially) past the end-of-file, gfortran sets the value
>> of IOSTAT to -1, but if you read a second time, gfortran sets the value
>> of IOSTAT to 5001. I discovered this situation after having written a
>> program expecting subsequent READs to all return a negative number, and
>> of course the program didn't behave as expected until I investigated the
>> problem. So I'm curious as to why the choice was made to have IOSTAT
>> set to something other than -1 on any READ attempt after the end-of-file
>> condition has been triggered. Isn't the file pointer still just beyond
>> the last record in the file, even after the first failed READ?

> You are expected to test for IOSTAT and deal with the end-of-file condition.
> You are not expected to continue reading the file.

I actually do test for IOSTAT and deal with the end-of-file condition by
exiting the DO loop with the READ statement. But once the DO loop has
been exited, the program is in an outer DO loop, which can also read the
file. It also tests IOSTAT to deal with the end-of-file condition, but
it tested for a negative number, which IOSTAT was no longer set to.

And if you must know why the nested DO loops, one loop dealt with data
while the other loop dealt with metadata. It was easily fixable. My
question here was not about how to fix the problem, but rather to find
out the rationale for changing the value of IOSTAT in such a situation.
My expectation was that IOSTAT would remain negative. My expectation
was wrong, hence the curiosity.

>> On a completely separate matter, I have a different program that
>> didn't behave as expected, and that misbehavior was totally repeatable.
>> In an attempt to debug the program, I added a WRITE statement to check
>> on the value of a variable during execution. However, once the WRITE
>> statement was added, the program started behaving properly, repeatably.

> That suggests that there is a bug in your program.

Brilliant.

> Possibly something has
> been overwritten.

I already thought about that, hence the WRITE statement to examine
the values of the array indices. The values were within range and
the program worked properly with the WRITE statement enabled. Comment
out the WRITE statement, and the misbehavior returned. Hence the
frustration.

> Turn on subscript bounds checking (if available).
> And while you're at it, turn on all checks.

Easier said than done, as the program was built from dozens of separately
written and compiled subprograms. It has not always been obvious to me
whether a compilation flag needs to be applied to every single subprogram
in order to accomplish a goal.

>> Comment out the added WRITE statement, and the program once again
>> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
>> is once again hunky-dory. Damned frustrating. It's too easy to blame
>> the optimizer. Anybody have any generic advice on what to look for in
>> such a situation?

Re: end-of-file IOSTAT / debugging

<tat59t$1v1c$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2528&group=comp.lang.fortran#2528

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!iayahv1glVWjKlPuzXRjog.user.46.165.242.91.POSTED!not-for-mail
From: tholen@antispam.ham (Dave Tholen)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: Fri, 15 Jul 2022 15:46:36 -1000
Organization: Aioe.org NNTP Server
Message-ID: <tat59t$1v1c$1@gioia.aioe.org>
References: <tark4g$5or$1@gioia.aioe.org> <tas99e$3423t$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="64556"; posting-host="iayahv1glVWjKlPuzXRjog.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dave Tholen - Sat, 16 Jul 2022 01:46 UTC

>> If you read (sequentially) past the end-of-file, gfortran sets the value
>> of IOSTAT to -1, but if you read a second time, gfortran sets the value
>> of IOSTAT to 5001. I discovered this situation after having written a
>> program expecting subsequent READs to all return a negative number, and
>> of course the program didn't behave as expected until I investigated the
>> problem. So I'm curious as to why the choice was made to have IOSTAT
>> set to something other than -1 on any READ attempt after the end-of-file
>> condition has been triggered. Isn't the file pointer still just beyond
>> the last record in the file, even after the first failed READ?

> What version of the compiler and operating system?

Unfortunately, I'm not sitting in front of the computer in question at
the moment, but I am sitting in front of a different computer that was
purchased at the same time and loaded with the same software, so there's
a good chance it's gfortran 7.1.0. The operating system is Windows 10 Pro
version 21H2. I'm expecting Windows Update to reboot the system any day
now to install the July patches (as happened last night to the system
I'm using at the moment).

> What does IOMSG tell you?

I'm unfamiliar with IOMSG. Sounds like an intrinsic that returns a
text description of an IOSTAT numerical value, but I don't see it listed
among the intrinsic procedures for gfortran. Could you elaborate?

> Likely, you have hit two different errors.

Yeah, the first being end-of-file and the second being past-end-of-file.
As I noted in an earlier response, my expectation was that both would
return negative numbers, but that expectation was wrong, at least for
gfortran. I would have been just fine with ifort, thanks to Steve
Lionel's test.

>> On a completely separate matter, I have a different program that
>> didn't behave as expected, and that misbehavior was totally repeatable.
>> In an attempt to debug the program, I added a WRITE statement to check
>> on the value of a variable during execution. However, once the WRITE
>> statement was added, the program started behaving properly, repeatably.
>> Comment out the added WRITE statement, and the program once again
>> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
>> is once again hunky-dory. Damned frustrating. It's too easy to blame
>> the optimizer. Anybody have any generic advice on what to look for in
>> such a situation?

> Remove the write statement and compile with -Wall -fcheck=all. This
> might find where you are stomping on memory.

I'll give that a try over the weekend.

Re: end-of-file IOSTAT / debugging

<8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2529&group=comp.lang.fortran#2529

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:2aac:b0:473:421d:d457 with SMTP id js12-20020a0562142aac00b00473421dd457mr14191977qvb.61.1657937057001;
Fri, 15 Jul 2022 19:04:17 -0700 (PDT)
X-Received: by 2002:a81:7284:0:b0:31d:4c3:a3cc with SMTP id
n126-20020a817284000000b0031d04c3a3ccmr18750103ywc.319.1657937056864; Fri, 15
Jul 2022 19:04:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 15 Jul 2022 19:04:16 -0700 (PDT)
In-Reply-To: <tark4g$5or$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:a877:1d7:9da8:23ec;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:a877:1d7:9da8:23ec
References: <tark4g$5or$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: gah4@u.washington.edu (gah4)
Injection-Date: Sat, 16 Jul 2022 02:04:16 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 29
 by: gah4 - Sat, 16 Jul 2022 02:04 UTC

On Friday, July 15, 2022 at 4:47:37 AM UTC-7, Dave Tholen wrote:
> If you read (sequentially) past the end-of-file, gfortran sets the value
> of IOSTAT to -1, but if you read a second time, gfortran sets the value
> of IOSTAT to 5001. I discovered this situation after having written a
> program expecting subsequent READs to all return a negative number, and
> of course the program didn't behave as expected until I investigated the
> problem. So I'm curious as to why the choice was made to have IOSTAT
> set to something other than -1 on any READ attempt after the end-of-file
> condition has been triggered. Isn't the file pointer still just beyond
> the last record in the file, even after the first failed READ?

If I understand it right, you should test for not zero, and act accordingly.

It is negative for EOF, but positive for I/O errors, which most likely you
should also exit your loop, and/or handle appropriately.

Otherwise, it makes some sense. In the first case, there is actual EOF.
In the second, reading after EOF, is an I/O error, and so reported.

Unless you plan to test for and take appropriate action for different
I/O errors, taking action for any non-zero value makes sense.

I believe this is a not unusual error in some other languages,
which I won't mention.

Re: end-of-file IOSTAT / debugging

<0ea66ddf-7739-4c59-b323-88d8620e7f96n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2530&group=comp.lang.fortran#2530

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:1453:b0:31d:4c06:4a04 with SMTP id v19-20020a05622a145300b0031d4c064a04mr14184889qtx.432.1657941112731;
Fri, 15 Jul 2022 20:11:52 -0700 (PDT)
X-Received: by 2002:a81:14e:0:b0:31e:1:dd9b with SMTP id 75-20020a81014e000000b0031e0001dd9bmr4991944ywb.63.1657941112506;
Fri, 15 Jul 2022 20:11:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 15 Jul 2022 20:11:52 -0700 (PDT)
In-Reply-To: <8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=115.189.84.49; posting-account=KnYfEgoAAAD1tUJTvdAUZ3XojNa5tezZ
NNTP-Posting-Host: 115.189.84.49
References: <tark4g$5or$1@gioia.aioe.org> <8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0ea66ddf-7739-4c59-b323-88d8620e7f96n@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: harperjf2@gmail.com (jfh)
Injection-Date: Sat, 16 Jul 2022 03:11:52 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 40
 by: jfh - Sat, 16 Jul 2022 03:11 UTC

On Saturday, July 16, 2022 at 2:04:18 PM UTC+12, gah4 wrote:
> On Friday, July 15, 2022 at 4:47:37 AM UTC-7, Dave Tholen wrote:
> > If you read (sequentially) past the end-of-file, gfortran sets the value
> > of IOSTAT to -1, but if you read a second time, gfortran sets the value
> > of IOSTAT to 5001. I discovered this situation after having written a
> > program expecting subsequent READs to all return a negative number, and
> > of course the program didn't behave as expected until I investigated the
> > problem. So I'm curious as to why the choice was made to have IOSTAT
> > set to something other than -1 on any READ attempt after the end-of-file
> > condition has been triggered. Isn't the file pointer still just beyond
> > the last record in the file, even after the first failed READ?
> If I understand it right, you should test for not zero, and act accordingly.
>
> It is negative for EOF, but positive for I/O errors, which most likely you
> should also exit your loop, and/or handle appropriately.
>
> Otherwise, it makes some sense. In the first case, there is actual EOF.
> In the second, reading after EOF, is an I/O error, and so reported.
>
> Unless you plan to test for and take appropriate action for different
> I/O errors, taking action for any non-zero value makes sense.
>
> I believe this is a not unusual error in some other languages,
> which I won't mention.

In an open, inquire, read or write statement you may include iomsg=msg as well as iostat=ios if you have a scalar variable of type character that's long enough for the error messge, and you write msg if ios was nonzero. The length of msg will depend on what compiler you used, what ios was, and how long the name of the offending file was. Iomsg and iostat are not intrinsics but specifiers in those 4 kinds of statement.

Re: end-of-file IOSTAT / debugging

<8b37c6e6-a152-4dc0-b77e-63b383ddf5den@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2531&group=comp.lang.fortran#2531

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:dca:b0:473:bde:8495 with SMTP id 10-20020a0562140dca00b004730bde8495mr14511748qvt.40.1657956809374;
Sat, 16 Jul 2022 00:33:29 -0700 (PDT)
X-Received: by 2002:a25:6a06:0:b0:66f:a81:d865 with SMTP id
f6-20020a256a06000000b0066f0a81d865mr7446495ybc.392.1657956809149; Sat, 16
Jul 2022 00:33:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 00:33:28 -0700 (PDT)
In-Reply-To: <jje18mFtcl0U1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org> <7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
<jje18mFtcl0U1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8b37c6e6-a152-4dc0-b77e-63b383ddf5den@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Sat, 16 Jul 2022 07:33:29 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 27
 by: Robin Vowels - Sat, 16 Jul 2022 07:33 UTC

On Saturday, July 16, 2022 at 6:33:31 AM UTC+10, Steve Lionel wrote:
> On Fri, 15 Jul 2022 07:45:56 -0700, Robin Vowels wrote:
>
> > You are expected to test for IOSTAT and deal with the end-of-file
> > condition.
> > You are not expected to continue reading the file.
> MIL-STD-1753 specified that you could, when reading magnetic tape
..
That's irrelevant.

> (see
> https://stevelionel.com/drfortran/2020/05/16/doctor-fortran-in-military-
> strength/).
> The Fortran standard says (12.11.1), that when an "endfile record is
> encountered during the reading of a file connected for sequential access",
> "if the file specified in the input statement is an external record file,
> it is positioned after the endfile record;" (12.11.3). What happens after
> that is not specified, though you are allowed to BACKSPACE over the
> endfile record. Note that there doesn't need to be any physical
> representation of an endfile record.
>
> gfortran is within its rights to give you a different IOSTAT value in this
> case, and I could make an argument that -1 is NOT the correct thing to
> return here. I tried ifort and nagfor - ifort returns -1 on the read past
> the EOF, nagfor uses 210, corresponding to "READ/WRITE attempted after
> ENDFILE on unit 1". (I can't get too worked up over ifort returning -1,
> however...)

Re: end-of-file IOSTAT / debugging

<9e943aae-25f8-4d26-a9e0-4d59e22fbe58n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2533&group=comp.lang.fortran#2533

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:5711:0:b0:31e:c76e:3017 with SMTP id 17-20020ac85711000000b0031ec76e3017mr14611331qtw.192.1657957876605;
Sat, 16 Jul 2022 00:51:16 -0700 (PDT)
X-Received: by 2002:a25:23c8:0:b0:66e:c79b:8d2f with SMTP id
j191-20020a2523c8000000b0066ec79b8d2fmr17795696ybj.319.1657957876377; Sat, 16
Jul 2022 00:51:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 00:51:16 -0700 (PDT)
In-Reply-To: <tat4bt$1ndf$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org> <7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
<tat4bt$1ndf$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9e943aae-25f8-4d26-a9e0-4d59e22fbe58n@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Sat, 16 Jul 2022 07:51:16 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 71
 by: Robin Vowels - Sat, 16 Jul 2022 07:51 UTC

On Saturday, July 16, 2022 at 11:30:41 AM UTC+10, Dave Tholen wrote:
> >> If you read (sequentially) past the end-of-file, gfortran sets the value
> >> of IOSTAT to -1, but if you read a second time, gfortran sets the value
> >> of IOSTAT to 5001. I discovered this situation after having written a
> >> program expecting subsequent READs to all return a negative number, and
> >> of course the program didn't behave as expected until I investigated the
> >> problem. So I'm curious as to why the choice was made to have IOSTAT
> >> set to something other than -1 on any READ attempt after the end-of-file
> >> condition has been triggered. Isn't the file pointer still just beyond
> >> the last record in the file, even after the first failed READ?
>
> > You are expected to test for IOSTAT and deal with the end-of-file condition.
> > You are not expected to continue reading the file.
..
> I actually do test for IOSTAT and deal with the end-of-file condition by
> exiting the DO loop with the READ statement. But once the DO loop has
> been exited, the program is in an outer DO loop, which can also read the
> file.
..
You need to fix the logic.
..
> It also tests IOSTAT to deal with the end-of-file condition,
..
The program has already hit the end of file.
Now you are trying to read read the same file at the same place.
..
> but
> it tested for a negative number, which IOSTAT was no longer set to.
..
You need to avoid reading after end of file has been detected.
..
> And if you must know why the nested DO loops, one loop dealt with data
> while the other loop dealt with metadata. It was easily fixable. My
> question here was not about how to fix the problem, but rather to find
> out the rationale for changing the value of IOSTAT in such a situation.
> My expectation was that IOSTAT would remain negative. My expectation
> was wrong, hence the curiosity.
> >> On a completely separate matter, I have a different program that
> >> didn't behave as expected, and that misbehavior was totally repeatable.
> >> In an attempt to debug the program, I added a WRITE statement to check
> >> on the value of a variable during execution. However, once the WRITE
> >> statement was added, the program started behaving properly, repeatably.
>
> > That suggests that there is a bug in your program.
> Brilliant.
> > Possibly something has
> > been overwritten.
> I already thought about that, hence the WRITE statement to examine
> the values of the array indices.
..
In every program unit, subroutine and function in the entire program?
..
> The values were within range and
> the program worked properly with the WRITE statement enabled. Comment
> out the WRITE statement, and the misbehavior returned. Hence the
> frustration.
> > Turn on subscript bounds checking (if available).
> > And while you're at it, turn on all checks.
..
> Easier said than done, as the program was built from dozens of separately
> written and compiled subprograms. It has not always been obvious to me
> whether a compilation flag needs to be applied to every single subprogram
> in order to accomplish a goal.
..
Obviously, program checking needs to be specified for every separate compilation,
as the apparent overwriting could be in any one or more subroutine and function.
..
> >> Comment out the added WRITE statement, and the program once again
> >> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
> >> is once again hunky-dory. Damned frustrating. It's too easy to blame
> >> the optimizer. Anybody have any generic advice on what to look for in
> >> such a situation?

Re: end-of-file IOSTAT / debugging

<39744386-5043-4029-98dd-502a4f096f5fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2534&group=comp.lang.fortran#2534

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:bd4:b0:6ab:8874:4cdc with SMTP id s20-20020a05620a0bd400b006ab88744cdcmr12194178qki.415.1657960522858;
Sat, 16 Jul 2022 01:35:22 -0700 (PDT)
X-Received: by 2002:a25:7e43:0:b0:66e:58ca:ae7c with SMTP id
z64-20020a257e43000000b0066e58caae7cmr17436434ybc.180.1657960522679; Sat, 16
Jul 2022 01:35:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 01:35:22 -0700 (PDT)
In-Reply-To: <312dfeaf-4ab4-4d94-86f5-d94f8cf62ac2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org> <312dfeaf-4ab4-4d94-86f5-d94f8cf62ac2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <39744386-5043-4029-98dd-502a4f096f5fn@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Sat, 16 Jul 2022 08:35:22 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2581
 by: Robin Vowels - Sat, 16 Jul 2022 08:35 UTC

On Saturday, July 16, 2022 at 6:20:07 AM UTC+10, gah4 wrote:
> On Friday, July 15, 2022 at 4:47:37 AM UTC-7, Dave Tholen wrote:
> > If you read (sequentially) past the end-of-file, gfortran sets the value
> > of IOSTAT to -1, but if you read a second time, gfortran sets the value
> > of IOSTAT to 5001. I discovered this situation after having written a
> > program expecting subsequent READs to all return a negative number, and
> > of course the program didn't behave as expected until I investigated the
> > problem. So I'm curious as to why the choice was made to have IOSTAT
> > set to something other than -1 on any READ attempt after the end-of-file
> > condition has been triggered. Isn't the file pointer still just beyond
> > the last record in the file, even after the first failed READ?
> I haven't thought about this in a lot of years, but in the days of
> magnetic tapes, some systems allowed one to read the EOF,
> and then go on to the next file on the tape.
>
> Though Fortran 66 has no method for detecting EOF, you are just
> supposed to stop reading before it happens.
..
IBM FORTRAN IV of 1966 had EOF and ERR options in the
..
> I believe for tapes in Unix, when you get to the end, the system
> call return 0 bytes, as the sign of the EOF, and then you go onto
> the next file. (That is, past the tape mark.)
>
> Disk files don't do that, though.

Re: end-of-file IOSTAT / debugging

<848414a6-9bf8-4871-8832-8ab55376b5c7n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2535&group=comp.lang.fortran#2535

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:f13:b0:6b5:b956:c1f1 with SMTP id v19-20020a05620a0f1300b006b5b956c1f1mr11560754qkl.691.1657960784670;
Sat, 16 Jul 2022 01:39:44 -0700 (PDT)
X-Received: by 2002:a81:8841:0:b0:31d:a90f:73e2 with SMTP id
y62-20020a818841000000b0031da90f73e2mr20410822ywf.54.1657960784495; Sat, 16
Jul 2022 01:39:44 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 01:39:44 -0700 (PDT)
In-Reply-To: <312dfeaf-4ab4-4d94-86f5-d94f8cf62ac2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org> <312dfeaf-4ab4-4d94-86f5-d94f8cf62ac2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <848414a6-9bf8-4871-8832-8ab55376b5c7n@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Sat, 16 Jul 2022 08:39:44 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 22
 by: Robin Vowels - Sat, 16 Jul 2022 08:39 UTC

On Saturday, July 16, 2022 at 6:20:07 AM UTC+10, gah4 wrote:
> On Friday, July 15, 2022 at 4:47:37 AM UTC-7, Dave Tholen wrote:
> > If you read (sequentially) past the end-of-file, gfortran sets the value
> > of IOSTAT to -1, but if you read a second time, gfortran sets the value
> > of IOSTAT to 5001. I discovered this situation after having written a
> > program expecting subsequent READs to all return a negative number, and
> > of course the program didn't behave as expected until I investigated the
> > problem. So I'm curious as to why the choice was made to have IOSTAT
> > set to something other than -1 on any READ attempt after the end-of-file
> > condition has been triggered. Isn't the file pointer still just beyond
> > the last record in the file, even after the first failed READ?
> I haven't thought about this in a lot of years, but in the days of
> magnetic tapes, some systems allowed one to read the EOF,
> and then go on to the next file on the tape.
>
> Though Fortran 66 has no method for detecting EOF, you are just
> supposed to stop reading before it happens.
..
IBM FORTRAN IV of 1966 had EOF= and ERR= options
for the READ statement.
..
PL/I (F) of 1966 raised the ENDFILE condition on attempting to
read after the final data item in the file.

Re: end-of-file IOSTAT / debugging

<0nvAK.562469$JVi.534899@fx17.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2536&group=comp.lang.fortran#2536

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Subject: Re: end-of-file IOSTAT / debugging
Content-Language: en-US
Newsgroups: comp.lang.fortran
References: <tark4g$5or$1@gioia.aioe.org> <tas99e$3423t$1@dont-email.me>
From: lkrupp@invalid.pssw.com.invalid (Louis Krupp)
In-Reply-To: <tas99e$3423t$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 33
Message-ID: <0nvAK.562469$JVi.534899@fx17.iad>
X-Complaints-To: abuse(at)newshosting.com
NNTP-Posting-Date: Sat, 16 Jul 2022 09:17:48 UTC
Organization: Newshosting.com - Highest quality at a great price! www.newshosting.com
Date: Sat, 16 Jul 2022 03:17:48 -0600
X-Received-Bytes: 2441
 by: Louis Krupp - Sat, 16 Jul 2022 09:17 UTC

On 7/15/2022 11:48 AM, steve kargl wrote:
> Dave Tholen wrote:
<snip>
>> On a completely separate matter, I have a different program that
>> didn't behave as expected, and that misbehavior was totally repeatable.
>> In an attempt to debug the program, I added a WRITE statement to check
>> on the value of a variable during execution. However, once the WRITE
>> statement was added, the program started behaving properly, repeatably.
>> Comment out the added WRITE statement, and the program once again
>> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
>> is once again hunky-dory. Damned frustrating. It's too easy to blame
>> the optimizer. Anybody have any generic advice on what to look for in
>> such a situation?
> Remove the write statement and compile with -Wall -fcheck=all. This
> might find where you are stomping on memory.
>

I would add -Werror. If you always compile without warnings, your life
will be simpler.

If the presumably unlikely event that you're not already using IMPLICIT
NONE in every program unit, I would do that, too.

Among the other things mentioned, a WRITE statement might mask problems
caused by a variable that's not assigned a value before it's used.

If all else fails, the debugger is your friend. If you haven't
experienced the thrill of stepping through assembler instructions
finding where your wayward variable is stored and examining its value
and figuring out how it got to be what it is, this could be your chance.

Louis

Re: end-of-file IOSTAT / debugging

<tau5lg$hp1$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2537&group=comp.lang.fortran#2537

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!iayahv1glVWjKlPuzXRjog.user.46.165.242.91.POSTED!not-for-mail
From: tholen@antispam.ham (Dave Tholen)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: Sat, 16 Jul 2022 00:58:55 -1000
Organization: Aioe.org NNTP Server
Message-ID: <tau5lg$hp1$1@gioia.aioe.org>
References: <tark4g$5or$1@gioia.aioe.org>
<7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
<tat4bt$1ndf$1@gioia.aioe.org>
<9e943aae-25f8-4d26-a9e0-4d59e22fbe58n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="18209"; posting-host="iayahv1glVWjKlPuzXRjog.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dave Tholen - Sat, 16 Jul 2022 10:58 UTC

>>>> If you read (sequentially) past the end-of-file, gfortran sets the value
>>>> of IOSTAT to -1, but if you read a second time, gfortran sets the value
>>>> of IOSTAT to 5001. I discovered this situation after having written a
>>>> program expecting subsequent READs to all return a negative number, and
>>>> of course the program didn't behave as expected until I investigated the
>>>> problem. So I'm curious as to why the choice was made to have IOSTAT
>>>> set to something other than -1 on any READ attempt after the end-of-file
>>>> condition has been triggered. Isn't the file pointer still just beyond
>>>> the last record in the file, even after the first failed READ?

>>> You are expected to test for IOSTAT and deal with the end-of-file condition.
>>> You are not expected to continue reading the file.

>> I actually do test for IOSTAT and deal with the end-of-file condition by
>> exiting the DO loop with the READ statement. But once the DO loop has
>> been exited, the program is in an outer DO loop, which can also read the
>> file.

> You need to fix the logic.

Apparently I haven't been clear. The program has already been fixed.
It was fixed before I even posted on this forum. The question is not
how to fix the problem. The question is why the value of IOSTAT was
changed. There must be some rationale.

>> It also tests IOSTAT to deal with the end-of-file condition,

> The program has already hit the end of file.
> Now you are trying to read read the same file at the same place.

That's just it: same file, same place, same action, yet a different
IOSTAT result. Not what I had expected.

>> but
>> it tested for a negative number, which IOSTAT was no longer set to.

> You need to avoid reading after end of file has been detected.

Why? IOSTAT was added so that a program could handle error conditions.
My program was designed to deal with the error condition. Had gfortran
consistently returned a negative IOSTAT for every attempt to READ past
the end-of-file, my program would have worked exactly as intended. Had
I used ifort, my program would have worked exactly as intended.

>> And if you must know why the nested DO loops, one loop dealt with data
>> while the other loop dealt with metadata. It was easily fixable. My
>> question here was not about how to fix the problem, but rather to find
>> out the rationale for changing the value of IOSTAT in such a situation.
>> My expectation was that IOSTAT would remain negative. My expectation
>> was wrong, hence the curiosity.

>>>> On a completely separate matter, I have a different program that
>>>> didn't behave as expected, and that misbehavior was totally repeatable.
>>>> In an attempt to debug the program, I added a WRITE statement to check
>>>> on the value of a variable during execution. However, once the WRITE
>>>> statement was added, the program started behaving properly, repeatably.

>>> That suggests that there is a bug in your program.

>> Brilliant.

>>> Possibly something has
>>> been overwritten.

>> I already thought about that, hence the WRITE statement to examine
>> the values of the array indices.

> In every program unit, subroutine and function in the entire program?

I usually sprinkle WRITE statements around to isolate where the crash
is happening. As I narrow things down, unnecessary WRITE statements are
either removed or commented out. In this particular case, I got it down
to a single WRITE statement that could trigger proper behavior.

>> The values were within range and
>> the program worked properly with the WRITE statement enabled. Comment
>> out the WRITE statement, and the misbehavior returned. Hence the
>> frustration.

>>> Turn on subscript bounds checking (if available).
>>> And while you're at it, turn on all checks.
..
>> Easier said than done, as the program was built from dozens of separately
>> written and compiled subprograms. It has not always been obvious to me
>> whether a compilation flag needs to be applied to every single subprogram
>> in order to accomplish a goal.

> Obviously, program checking needs to be specified for every separate compilation,
> as the apparent overwriting could be in any one or more subroutine and function.

So, you're saying that if my program has subprograms A, B, C, D, and E,
and the crash occurs while it's executing subprogram C, the apparent
overwriting could be in A, B, D, or E?

>>>> Comment out the added WRITE statement, and the program once again
>>>> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
>>>> is once again hunky-dory. Damned frustrating. It's too easy to blame
>>>> the optimizer. Anybody have any generic advice on what to look for in
>>>> such a situation?

Re: end-of-file IOSTAT / debugging

<tau5pg$hp1$2@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2538&group=comp.lang.fortran#2538

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!aioe.org!iayahv1glVWjKlPuzXRjog.user.46.165.242.91.POSTED!not-for-mail
From: tholen@antispam.ham (Dave Tholen)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: Sat, 16 Jul 2022 01:01:04 -1000
Organization: Aioe.org NNTP Server
Message-ID: <tau5pg$hp1$2@gioia.aioe.org>
References: <tark4g$5or$1@gioia.aioe.org>
<7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
<jje18mFtcl0U1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="18209"; posting-host="iayahv1glVWjKlPuzXRjog.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dave Tholen - Sat, 16 Jul 2022 11:01 UTC

>> You are expected to test for IOSTAT and deal with the end-of-file
>> condition.
>> You are not expected to continue reading the file.
>
> MIL-STD-1753 specified that you could, when reading magnetic tape (see
> https://stevelionel.com/drfortran/2020/05/16/doctor-fortran-in-military-
> strength/).
>
> The Fortran standard says (12.11.1), that when an "endfile record is
> encountered during the reading of a file connected for sequential access",
> "if the file specified in the input statement is an external record file,
> it is positioned after the endfile record;" (12.11.3). What happens after
> that is not specified, though you are allowed to BACKSPACE over the
> endfile record. Note that there doesn't need to be any physical
> representation of an endfile record.
>
> gfortran is within its rights to give you a different IOSTAT value in this
> case, and I could make an argument that -1 is NOT the correct thing to
> return here.

That argument you could make is precisely what I was hoping to get out of
this thread.

> I tried ifort and nagfor - ifort returns -1 on the read past
> the EOF, nagfor uses 210, corresponding to "READ/WRITE attempted after
> ENDFILE on unit 1". (I can't get too worked up over ifort returning -1,
> however...)

Re: end-of-file IOSTAT / debugging

<tau84d$1h01$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2539&group=comp.lang.fortran#2539

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!iayahv1glVWjKlPuzXRjog.user.46.165.242.91.POSTED!not-for-mail
From: tholen@antispam.ham (Dave Tholen)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: Sat, 16 Jul 2022 01:40:59 -1000
Organization: Aioe.org NNTP Server
Message-ID: <tau84d$1h01$1@gioia.aioe.org>
References: <tark4g$5or$1@gioia.aioe.org>
<8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="50177"; posting-host="iayahv1glVWjKlPuzXRjog.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dave Tholen - Sat, 16 Jul 2022 11:40 UTC

>> If you read (sequentially) past the end-of-file, gfortran sets the value
>> of IOSTAT to -1, but if you read a second time, gfortran sets the value
>> of IOSTAT to 5001. I discovered this situation after having written a
>> program expecting subsequent READs to all return a negative number, and
>> of course the program didn't behave as expected until I investigated the
>> problem. So I'm curious as to why the choice was made to have IOSTAT
>> set to something other than -1 on any READ attempt after the end-of-file
>> condition has been triggered. Isn't the file pointer still just beyond
>> the last record in the file, even after the first failed READ?

> If I understand it right, you should test for not zero, and act accordingly.
>
> It is negative for EOF, but positive for I/O errors, which most likely you
> should also exit your loop, and/or handle appropriately.

Not in this particular case. In older versions of the data file I'm
processing, they used csv format to present dozens and dozens of
quantities for each object in the database, and when a value wasn't
available, they simply omitted it, leading to consecutive commas,
and gfortran's list-directed READ statement handled it splendidly.
However, in the latest version of the data file, a missing value is
now represented as "null". For example, five values might be in
this file as:

18,97.43,null,-4.31,102

but attempting to read the characters "null" into an INTEGER or REAL
variable triggers an I/O error. I do NOT want to exit the READ loop.
However, once the end-of-file is reached, I do want to exit the READ
loop.

> Otherwise, it makes some sense. In the first case, there is actual EOF.
> In the second, reading after EOF, is an I/O error, and so reported.

So, prior to the READ that triggers the end-of-file condition, the
file pointer is after the last record of the file, but before the EOF,
and after the READ that triggers the end-of-file condition, the file
pointer is now after some imaginary EOF? There is no physical EOF
associated with the file. Does the compiler give the file a logical
EOF marker and is able to position the file pointer before and after it?

> Unless you plan to test for and take appropriate action for different
> I/O errors, taking action for any non-zero value makes sense.

I've written numerous programs where different actions are taken for
different I/O errors. A hypothetical (and trivial) example: A
program that converts Fahrenheit to Celsius. DO loop with WRITE
statement that prompts the user to enter a temperature in Fahrenheit
and a READ statement that accepts the user's input. Type in "abc"
and rather than crashing or exiting the loop, the program can say
"try again" and wait for another entry. But enter a CTRL-Z (an
EOF on Windows), and the loop can exit gracefully.

> I believe this is a not unusual error in some other languages,
> which I won't mention.

Re: end-of-file IOSTAT / debugging

<jjfvfcF8c41U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2540&group=comp.lang.fortran#2540

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: steve@seesignature.invalid (Steve Lionel)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: 16 Jul 2022 14:15:08 GMT
Lines: 15
Message-ID: <jjfvfcF8c41U1@mid.individual.net>
References: <tark4g$5or$1@gioia.aioe.org> <tas99e$3423t$1@dont-email.me>
<tat59t$1v1c$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net OpnmKarcrTtHGMpMT9UevQBc1m+nqQA5fMUDAypXJTEbGzK7nS
Cancel-Lock: sha1:aIraJnixDITb4jlBELz9IQhC69Y=
User-Agent: Pan/0.146 (Hic habitat felicitas; d7a48b4
gitlab.gnome.org/GNOME/pan.git)
 by: Steve Lionel - Sat, 16 Jul 2022 14:15 UTC

On Fri, 15 Jul 2022 15:46:36 -1000, Dave Tholen wrote:

> I'm unfamiliar with IOMSG. Sounds like an intrinsic that returns a text
> description of an IOSTAT numerical value, but I don't see it listed
> among the intrinsic procedures for gfortran. Could you elaborate?

It's not an intrinsic, it's another keyword for the I/O statement, like
IOSTAT. It was new in Fortran 2018.

--
Steve Lionel
Email: firstname at firstnamelastname dot com
Twitter: @DoctorFortran
Blog: https://stevelionel.com/drfortran

Re: end-of-file IOSTAT / debugging

<bb213159-8ce6-4fbb-b661-94de45f493bdn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2541&group=comp.lang.fortran#2541

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ad4:4ea7:0:b0:473:444c:d522 with SMTP id ed7-20020ad44ea7000000b00473444cd522mr16236837qvb.44.1657984216033;
Sat, 16 Jul 2022 08:10:16 -0700 (PDT)
X-Received: by 2002:a0d:f607:0:b0:31b:b1d2:37bf with SMTP id
g7-20020a0df607000000b0031bb1d237bfmr22113357ywf.313.1657984215707; Sat, 16
Jul 2022 08:10:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 08:10:15 -0700 (PDT)
In-Reply-To: <jjfvfcF8c41U1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=165.225.39.113; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 165.225.39.113
References: <tark4g$5or$1@gioia.aioe.org> <tas99e$3423t$1@dont-email.me>
<tat59t$1v1c$1@gioia.aioe.org> <jjfvfcF8c41U1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bb213159-8ce6-4fbb-b661-94de45f493bdn@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Sat, 16 Jul 2022 15:10:16 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: FortranFan - Sat, 16 Jul 2022 15:10 UTC

On Saturday, July 16, 2022 at 10:15:12 AM UTC-4, Steve Lionel wrote:

> On Fri, 15 Jul 2022 15:46:36 -1000, Dave Tholen wrote:
>
> > I'm unfamiliar with IOMSG. Sounds like an intrinsic that returns a text
> > description of an IOSTAT numerical value, but I don't see it listed
> > among the intrinsic procedures for gfortran. Could you elaborate?
> It's not an intrinsic, it's another keyword for the I/O statement, like
> IOSTAT. It was new in Fortran 2018.
>

You must mean Fortran 2003 standard revision given it is the data transfer (READ) statement being discussed here?

Fortran 2018 introduced an optional argument `ERRMSG` to fetch the messages involving intrinsics that interact with the processor environment, correct? Such as get_command, get_environment_variable, etc.

Re: end-of-file IOSTAT / debugging

<tauqb3$3dva6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2542&group=comp.lang.fortran#2542

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: garylscott@sbcglobal.net (Gary Scott)
Newsgroups: comp.lang.fortran
Subject: Re: end-of-file IOSTAT / debugging
Date: Sat, 16 Jul 2022 11:51:46 -0500
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <tauqb3$3dva6$1@dont-email.me>
References: <tark4g$5or$1@gioia.aioe.org>
<8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Jul 2022 16:51:47 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="5f03958187768a37c1e6ac9b3983c3da";
logging-data="3603782"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18b/QVCP0m7DWpBlCC7RrnIjH4bE4PY5jA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Cancel-Lock: sha1:kukEoEzASoukZoIN3awwWAm0dx0=
Content-Language: en-US
In-Reply-To: <8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
 by: Gary Scott - Sat, 16 Jul 2022 16:51 UTC

On 7/15/2022 9:04 PM, gah4 wrote:
> On Friday, July 15, 2022 at 4:47:37 AM UTC-7, Dave Tholen wrote:
>> If you read (sequentially) past the end-of-file, gfortran sets the value
>> of IOSTAT to -1, but if you read a second time, gfortran sets the value
>> of IOSTAT to 5001. I discovered this situation after having written a
>> program expecting subsequent READs to all return a negative number, and
>> of course the program didn't behave as expected until I investigated the
>> problem. So I'm curious as to why the choice was made to have IOSTAT
>> set to something other than -1 on any READ attempt after the end-of-file
>> condition has been triggered. Isn't the file pointer still just beyond
>> the last record in the file, even after the first failed READ?
>
> If I understand it right, you should test for not zero, and act accordingly.
>
> It is negative for EOF, but positive for I/O errors, which most likely you
> should also exit your loop, and/or handle appropriately.
>
> Otherwise, it makes some sense. In the first case, there is actual EOF.
> In the second, reading after EOF, is an I/O error, and so reported.
>
> Unless you plan to test for and take appropriate action for different
> I/O errors, taking action for any non-zero value makes sense.
>
> I believe this is a not unusual error in some other languages,
> which I won't mention.
>
>
>
>
>
>
I know of at least one operating system that included the concept of EOT
within disk files as well. So you could have multiple files in the same
"disk area". You got and EOF return at end of the current file and if
you read again and there wasn't another file present, you got an EOT
return value. It was convenient for some things.

Re: end-of-file IOSTAT / debugging

<161f88c5-bf36-4643-bbec-d698addd85c6n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2543&group=comp.lang.fortran#2543

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:213:b0:31e:c569:220e with SMTP id b19-20020a05622a021300b0031ec569220emr16432226qtx.436.1657993253606;
Sat, 16 Jul 2022 10:40:53 -0700 (PDT)
X-Received: by 2002:a05:6902:724:b0:66e:8c2b:ef78 with SMTP id
l4-20020a056902072400b0066e8c2bef78mr21387876ybt.313.1657993253311; Sat, 16
Jul 2022 10:40:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 10:40:53 -0700 (PDT)
In-Reply-To: <tau84d$1h01$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:7971:6678:84a:fc2e;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:7971:6678:84a:fc2e
References: <tark4g$5or$1@gioia.aioe.org> <8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
<tau84d$1h01$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <161f88c5-bf36-4643-bbec-d698addd85c6n@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: gah4@u.washington.edu (gah4)
Injection-Date: Sat, 16 Jul 2022 17:40:53 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 65
 by: gah4 - Sat, 16 Jul 2022 17:40 UTC

On Saturday, July 16, 2022 at 4:41:04 AM UTC-7, Dave Tholen wrote:

(snip, I wrote)
> > If I understand it right, you should test for not zero, and act accordingly.
> > It is negative for EOF, but positive for I/O errors, which most likely you
> > should also exit your loop, and/or handle appropriately.

> Not in this particular case. In older versions of the data file I'm
> processing, they used csv format to present dozens and dozens of
> quantities for each object in the database, and when a value wasn't
> available, they simply omitted it, leading to consecutive commas,
> and gfortran's list-directed READ statement handled it splendidly.
> However, in the latest version of the data file, a missing value is
> now represented as "null". For example, five values might be in
> this file as:
> 18,97.43,null,-4.31,102
> but attempting to read the characters "null" into an INTEGER or REAL
> variable triggers an I/O error. I do NOT want to exit the READ loop.
> However, once the end-of-file is reached, I do want to exit the READ
> loop.

On either EOF or I/O error, there is no guarantee as to what
is actually stored, or where the file is positioned.

> > Otherwise, it makes some sense. In the first case, there is actual EOF.
> > In the second, reading after EOF, is an I/O error, and so reported.

> So, prior to the READ that triggers the end-of-file condition, the
> file pointer is after the last record of the file, but before the EOF,
> and after the READ that triggers the end-of-file condition, the file
> pointer is now after some imaginary EOF? There is no physical EOF
> associated with the file. Does the compiler give the file a logical
> EOF marker and is able to position the file pointer before and after it?

The standard does have some discussion on that imaginary
EOF record, while indicating that it might not be an actual
physical anything. I am not sure if some historical system
had a physical EOF record that the standard emulates.

In any case, EOF is not an error, and so actual error is different.

> > Unless you plan to test for and take appropriate action for different
> > I/O errors, taking action for any non-zero value makes sense.

> I've written numerous programs where different actions are taken for
> different I/O errors. A hypothetical (and trivial) example: A
> program that converts Fahrenheit to Celsius. DO loop with WRITE
> statement that prompts the user to enter a temperature in Fahrenheit
> and a READ statement that accepts the user's input. Type in "abc"
> and rather than crashing or exiting the loop, the program can say
> "try again" and wait for another entry. But enter a CTRL-Z (an
> EOF on Windows), and the loop can exit gracefully.

I suppose you can do that, I am not sure that there is any
standard behavior, especially as to file position.

Reminds me, Unix, and at least Unix C compilers, all for one
to keep reading after EOF, such that tail -f works. That is,
if the file increases in length then the EOF goes away,
and you can keep reading. I do remember years ago
finding that C in OS/2 allowed that.

Re: end-of-file IOSTAT / debugging

<c49da26a-85bb-400d-a9ae-c961c7fcd303n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2544&group=comp.lang.fortran#2544

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:7fc1:0:b0:31e:c575:a56c with SMTP id b1-20020ac87fc1000000b0031ec575a56cmr16322023qtk.11.1657993859796;
Sat, 16 Jul 2022 10:50:59 -0700 (PDT)
X-Received: by 2002:a05:6902:706:b0:66e:ef10:1f7 with SMTP id
k6-20020a056902070600b0066eef1001f7mr20912643ybt.610.1657993859549; Sat, 16
Jul 2022 10:50:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 10:50:59 -0700 (PDT)
In-Reply-To: <tau5lg$hp1$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org> <7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
<tat4bt$1ndf$1@gioia.aioe.org> <9e943aae-25f8-4d26-a9e0-4d59e22fbe58n@googlegroups.com>
<tau5lg$hp1$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c49da26a-85bb-400d-a9ae-c961c7fcd303n@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Sat, 16 Jul 2022 17:50:59 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 109
 by: Robin Vowels - Sat, 16 Jul 2022 17:50 UTC

On Saturday, July 16, 2022 at 8:59:00 PM UTC+10, Dave Tholen wrote:
> >>>> If you read (sequentially) past the end-of-file, gfortran sets the value
> >>>> of IOSTAT to -1, but if you read a second time, gfortran sets the value
> >>>> of IOSTAT to 5001. I discovered this situation after having written a
> >>>> program expecting subsequent READs to all return a negative number, and
> >>>> of course the program didn't behave as expected until I investigated the
> >>>> problem. So I'm curious as to why the choice was made to have IOSTAT
> >>>> set to something other than -1 on any READ attempt after the end-of-file
> >>>> condition has been triggered. Isn't the file pointer still just beyond
> >>>> the last record in the file, even after the first failed READ?
>
> >>> You are expected to test for IOSTAT and deal with the end-of-file condition.
> >>> You are not expected to continue reading the file.
> >> I actually do test for IOSTAT and deal with the end-of-file condition by
> >> exiting the DO loop with the READ statement. But once the DO loop has
> >> been exited, the program is in an outer DO loop, which can also read the
> >> file.
..
> > You need to fix the logic.
..
> Apparently I haven't been clear.
> The program has already been fixed.
..
But it hasn't been fixed. You admitted it.
You said that after detecting end of file using IOSTAT, you exited the loop,
and the outer loop then proceeded to execute READs on the same file.
..
> It was fixed before I even posted on this forum. The question is not
> how to fix the problem. The question is why the value of IOSTAT was
> changed.
..
That has already been explained to you.
..
> There must be some rationale.
> >> It also tests IOSTAT to deal with the end-of-file condition,
> > The program has already hit the end of file.
> > Now you are trying to read read the same file at the same place.
> That's just it: same file, same place, same action, yet a different
> IOSTAT result. Not what I had expected.
..
Again, that has been explained to you.
..
> >> but
> >> it tested for a negative number, which IOSTAT was no longer set to.
> > You need to avoid reading after end of file has been detected.
> Why? IOSTAT was added so that a program could handle error conditions.
..
Provided that you deal with the condition and do not do silly things like reading
the same file again, after detecting end-of file.
..
> My program was designed to deal with the error condition. Had gfortran
> consistently returned a negative IOSTAT for every attempt to READ past
> the end-of-file, my program would have worked exactly as intended.

Listen up. Your program is in error. Fix it.
..
> Had I used ifort, my program would have worked exactly as intended.
> >> And if you must know why the nested DO loops, one loop dealt with data
> >> while the other loop dealt with metadata. It was easily fixable. My
> >> question here was not about how to fix the problem, but rather to find
> >> out the rationale for changing the value of IOSTAT in such a situation.
> >> My expectation was that IOSTAT would remain negative. My expectation
> >> was wrong, hence the curiosity.
>
> >>>> On a completely separate matter, I have a different program that
> >>>> didn't behave as expected, and that misbehavior was totally repeatable.
> >>>> In an attempt to debug the program, I added a WRITE statement to check
> >>>> on the value of a variable during execution. However, once the WRITE
> >>>> statement was added, the program started behaving properly, repeatably.
>
> >>> That suggests that there is a bug in your program.
>
> >> Brilliant.
>
> >>> Possibly something has
> >>> been overwritten.
>
> >> I already thought about that, hence the WRITE statement to examine
> >> the values of the array indices.
> > In every program unit, subroutine and function in the entire program?
> I usually sprinkle WRITE statements around to isolate where the crash
> is happening. As I narrow things down, unnecessary WRITE statements are
> either removed or commented out. In this particular case, I got it down
> to a single WRITE statement that could trigger proper behavior.
..
You program has errors. Find them with the help of debug options
such as subscript bound errors, substring errors, and the like.
..
> >> The values were within range and
> >> the program worked properly with the WRITE statement enabled. Comment
> >> out the WRITE statement, and the misbehavior returned. Hence the
> >> frustration.
>
> >>> Turn on subscript bounds checking (if available).
> >>> And while you're at it, turn on all checks.
> .
> >> Easier said than done, as the program was built from dozens of separately
> >> written and compiled subprograms. It has not always been obvious to me
> >> whether a compilation flag needs to be applied to every single subprogram
> >> in order to accomplish a goal.
> > Obviously, program checking needs to be specified for every separate compilation,
> > as the apparent overwriting could be in any one or more subroutine and function.
> So, you're saying that if my program has subprograms A, B, C, D, and E,
> and the crash occurs while it's executing subprogram C, the apparent
> overwriting could be in A, B, D, or E?
> >>>> Comment out the added WRITE statement, and the program once again
> >>>> misbehaves, repeatedly. Re-enable the WRITE statement, and everything
> >>>> is once again hunky-dory. Damned frustrating. It's too easy to blame
> >>>> the optimizer. Anybody have any generic advice on what to look for in
> >>>> such a situation?

Re: end-of-file IOSTAT / debugging

<11a1e837-7cde-4db0-86c9-8cc065b92f7cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2545&group=comp.lang.fortran#2545

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:ccb:b0:472:f2a2:dd73 with SMTP id 11-20020a0562140ccb00b00472f2a2dd73mr16512287qvx.0.1657994054692;
Sat, 16 Jul 2022 10:54:14 -0700 (PDT)
X-Received: by 2002:a81:9209:0:b0:31c:b1b7:b063 with SMTP id
j9-20020a819209000000b0031cb1b7b063mr22099820ywg.383.1657994054390; Sat, 16
Jul 2022 10:54:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 10:54:14 -0700 (PDT)
In-Reply-To: <tau5lg$hp1$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org> <7f870d41-15f0-4e21-9fef-f73a72f5519an@googlegroups.com>
<tat4bt$1ndf$1@gioia.aioe.org> <9e943aae-25f8-4d26-a9e0-4d59e22fbe58n@googlegroups.com>
<tau5lg$hp1$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <11a1e837-7cde-4db0-86c9-8cc065b92f7cn@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Sat, 16 Jul 2022 17:54:14 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 6056
 by: Robin Vowels - Sat, 16 Jul 2022 17:54 UTC

On Saturday, July 16, 2022 at 8:59:00 PM UTC+10, Dave Tholen wrote:
> >>>> If you read (sequentially) past the end-of-file, gfortran sets the value
> >>>> of IOSTAT to -1, but if you read a second time, gfortran sets the value
> >>>> of IOSTAT to 5001. I discovered this situation after having written a
> >>>> program expecting subsequent READs to all return a negative number, and
> >>>> of course the program didn't behave as expected until I investigated the
> >>>> problem. So I'm curious as to why the choice was made to have IOSTAT
> >>>> set to something other than -1 on any READ attempt after the end-of-file
> >>>> condition has been triggered. Isn't the file pointer still just beyond
> >>>> the last record in the file, even after the first failed READ?
>
> >>> You are expected to test for IOSTAT and deal with the end-of-file condition.
> >>> You are not expected to continue reading the file.
> >> I actually do test for IOSTAT and deal with the end-of-file condition by
> >> exiting the DO loop with the READ statement. But once the DO loop has
> >> been exited, the program is in an outer DO loop, which can also read the
> >> file.
> > You need to fix the logic.
> Apparently I haven't been clear. The program has already been fixed.
> It was fixed before I even posted on this forum. The question is not
> how to fix the problem. The question is why the value of IOSTAT was
> changed. There must be some rationale.
> >> It also tests IOSTAT to deal with the end-of-file condition,
> > The program has already hit the end of file.
> > Now you are trying to read read the same file at the same place.
> That's just it: same file, same place, same action, yet a different
> IOSTAT result. Not what I had expected.
> >> but
> >> it tested for a negative number, which IOSTAT was no longer set to.
> > You need to avoid reading after end of file has been detected.
> Why? IOSTAT was added so that a program could handle error conditions.
> My program was designed to deal with the error condition. Had gfortran
> consistently returned a negative IOSTAT for every attempt to READ past
> the end-of-file, my program would have worked exactly as intended. Had
> I used ifort, my program would have worked exactly as intended.
> >> And if you must know why the nested DO loops, one loop dealt with data
> >> while the other loop dealt with metadata. It was easily fixable. My
> >> question here was not about how to fix the problem, but rather to find
> >> out the rationale for changing the value of IOSTAT in such a situation.
> >> My expectation was that IOSTAT would remain negative. My expectation
> >> was wrong, hence the curiosity.
>
> >>>> On a completely separate matter, I have a different program that
> >>>> didn't behave as expected, and that misbehavior was totally repeatable.
> >>>> In an attempt to debug the program, I added a WRITE statement to check
> >>>> on the value of a variable during execution. However, once the WRITE
> >>>> statement was added, the program started behaving properly, repeatably.
>
> >>> That suggests that there is a bug in your program.
>
> >> Brilliant.
>
> >>> Possibly something has
> >>> been overwritten.
>
> >> I already thought about that, hence the WRITE statement to examine
> >> the values of the array indices.
> > In every program unit, subroutine and function in the entire program?
> I usually sprinkle WRITE statements around to isolate where the crash
> is happening. As I narrow things down, unnecessary WRITE statements are
> either removed or commented out. In this particular case, I got it down
> to a single WRITE statement that could trigger proper behavior.
> >> The values were within range and
> >> the program worked properly with the WRITE statement enabled. Comment
> >> out the WRITE statement, and the misbehavior returned. Hence the
> >> frustration.
>
> >>> Turn on subscript bounds checking (if available).
> >>> And while you're at it, turn on all checks.
> .
> >> Easier said than done, as the program was built from dozens of separately
> >> written and compiled subprograms. It has not always been obvious to me
> >> whether a compilation flag needs to be applied to every single subprogram
> >> in order to accomplish a goal.
> > Obviously, program checking needs to be specified for every separate compilation,
> > as the apparent overwriting could be in any one or more subroutine and function.
..
> So, you're saying that if my program has subprograms A, B, C, D, and E,
> and the crash occurs while it's executing subprogram C, the apparent
> overwriting could be in A, B, D, or E?
..
The error could be in any of A, B, C, D, E, and/or the main program.

Re: end-of-file IOSTAT / debugging

<be4466c7-f962-4a44-908c-9fb16793d6fdn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2546&group=comp.lang.fortran#2546

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:31c:b0:6b5:d5a5:687f with SMTP id s28-20020a05620a031c00b006b5d5a5687fmr4113225qkm.375.1657994697054;
Sat, 16 Jul 2022 11:04:57 -0700 (PDT)
X-Received: by 2002:a25:33c4:0:b0:668:cc8d:bc43 with SMTP id
z187-20020a2533c4000000b00668cc8dbc43mr19366585ybz.467.1657994696220; Sat, 16
Jul 2022 11:04:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 16 Jul 2022 11:04:56 -0700 (PDT)
In-Reply-To: <161f88c5-bf36-4643-bbec-d698addd85c6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tark4g$5or$1@gioia.aioe.org> <8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
<tau84d$1h01$1@gioia.aioe.org> <161f88c5-bf36-4643-bbec-d698addd85c6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <be4466c7-f962-4a44-908c-9fb16793d6fdn@googlegroups.com>
Subject: Re: end-of-file IOSTAT / debugging
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Sat, 16 Jul 2022 18:04:57 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4044
 by: Robin Vowels - Sat, 16 Jul 2022 18:04 UTC

On Sunday, July 17, 2022 at 3:40:55 AM UTC+10, gah4 wrote:
> On Saturday, July 16, 2022 at 4:41:04 AM UTC-7, Dave Tholen wrote:
>
> (snip, I wrote)
> > > If I understand it right, you should test for not zero, and act accordingly.
>
> > > It is negative for EOF, but positive for I/O errors, which most likely you
> > > should also exit your loop, and/or handle appropriately.
>
> > Not in this particular case. In older versions of the data file I'm
> > processing, they used csv format to present dozens and dozens of
> > quantities for each object in the database, and when a value wasn't
> > available, they simply omitted it, leading to consecutive commas,
> > and gfortran's list-directed READ statement handled it splendidly.
> > However, in the latest version of the data file, a missing value is
> > now represented as "null". For example, five values might be in
> > this file as:
>
> > 18,97.43,null,-4.31,102
>
> > but attempting to read the characters "null" into an INTEGER or REAL
> > variable triggers an I/O error.
..
Characters are characters, and cannot be read into an integer or real variable.
An appropriate variable would be a CHARACTER variable, but then the
characters NULL would need to be enclosed in apostrophes.
A better approach might be to read the entire line into a CHARACTER variable,
and then to scan it for 'null, and then to delete the word. Finally read the
altered line.
..
> I do NOT want to exit the READ loop.
> > However, once the end-of-file is reached, I do want to exit the READ
> > loop.
> On either EOF or I/O error, there is no guarantee as to what
> is actually stored, or where the file is positioned.
> > > Otherwise, it makes some sense. In the first case, there is actual EOF.
> > > In the second, reading after EOF, is an I/O error, and so reported.
>
> > So, prior to the READ that triggers the end-of-file condition, the
> > file pointer is after the last record of the file, but before the EOF,
> > and after the READ that triggers the end-of-file condition, the file
> > pointer is now after some imaginary EOF? There is no physical EOF
> > associated with the file. Does the compiler give the file a logical
> > EOF marker and is able to position the file pointer before and after it?
> The standard does have some discussion on that imaginary
> EOF record, while indicating that it might not be an actual
> physical anything. I am not sure if some historical system
> had a physical EOF record that the standard emulates.
>
> In any case, EOF is not an error, and so actual error is different.
> > > Unless you plan to test for and take appropriate action for different
> > > I/O errors, taking action for any non-zero value makes sense.

Re: end-of-file IOSTAT / debugging

<IeEAK.376383$ssF.201777@fx14.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2547&group=comp.lang.fortran#2547

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Subject: Re: end-of-file IOSTAT / debugging
Content-Language: en-US
Newsgroups: comp.lang.fortran
References: <tark4g$5or$1@gioia.aioe.org>
<8786602f-050c-4da4-84a1-c91eb6aea5adn@googlegroups.com>
<tau84d$1h01$1@gioia.aioe.org>
<161f88c5-bf36-4643-bbec-d698addd85c6n@googlegroups.com>
<be4466c7-f962-4a44-908c-9fb16793d6fdn@googlegroups.com>
From: lkrupp@invalid.pssw.com.invalid (Louis Krupp)
In-Reply-To: <be4466c7-f962-4a44-908c-9fb16793d6fdn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 35
Message-ID: <IeEAK.376383$ssF.201777@fx14.iad>
X-Complaints-To: abuse(at)newshosting.com
NNTP-Posting-Date: Sat, 16 Jul 2022 19:23:20 UTC
Organization: Newshosting.com - Highest quality at a great price! www.newshosting.com
Date: Sat, 16 Jul 2022 13:23:20 -0600
X-Received-Bytes: 2783
 by: Louis Krupp - Sat, 16 Jul 2022 19:23 UTC

On 7/16/2022 12:04 PM, Robin Vowels wrote:
> On Sunday, July 17, 2022 at 3:40:55 AM UTC+10, gah4 wrote:
>> On Saturday, July 16, 2022 at 4:41:04 AM UTC-7, Dave Tholen wrote:
>>
>> (snip, I wrote)
>>>> If I understand it right, you should test for not zero, and act accordingly.
>>>> It is negative for EOF, but positive for I/O errors, which most likely you
>>>> should also exit your loop, and/or handle appropriately.
>>> Not in this particular case. In older versions of the data file I'm
>>> processing, they used csv format to present dozens and dozens of
>>> quantities for each object in the database, and when a value wasn't
>>> available, they simply omitted it, leading to consecutive commas,
>>> and gfortran's list-directed READ statement handled it splendidly.
>>> However, in the latest version of the data file, a missing value is
>>> now represented as "null". For example, five values might be in
>>> this file as:
>>> 18,97.43,null,-4.31,102
>>> but attempting to read the characters "null" into an INTEGER or REAL
>>> variable triggers an I/O error.
> .
> Characters are characters, and cannot be read into an integer or real variable.
> An appropriate variable would be a CHARACTER variable, but then the
> characters NULL would need to be enclosed in apostrophes.
> A better approach might be to read the entire line into a CHARACTER variable,
> and then to scan it for 'null, and then to delete the word. Finally read the
> altered line.
> .
>

If each READ statement is definitely reading one and only one line, then
reading each line into a character variable, deleting each instance of
the word 'null', and then reading data from the character variable seems
like the easiest solution by far.

Louis

Pages:12345
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor