Home > Archive > Fortran > February 2005 > non-advancing I/O question and EOR
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
non-advancing I/O question and EOR
|
|
| Thomas Koenig 2005-02-01, 8:58 pm |
| What should the following program print?
program main
open(87,pad='YES')
write(87,'(A)') '10','20'
rewind(87)
i2=100
read(87,'(I4)',advance='NO') i1,i2
print *,"i1 = ",i1,
print *,"i2 = ",i2
read(87,'(I4)') i3
print *,"i3 = ",i3
end program main
The way I interpret it, something similar to
i1 = 10
i2 = 100
i3 = 20
Rationale: The first read statement runs into an eor condition and
is terminated befor assigning anything to i2. Then, the second read
statements reads the second record. I also think ifort 8.1 gets
this wrong (Issue number 287783, if anybody at Intel is reading
this :-)
Correct?
| |
| Richard E Maine 2005-02-01, 8:58 pm |
| In article <ctonlp$4qr$1@meiner.onlinehome.de>,
Thomas Koenig <Thomas.Koenig@online.de> wrote:
....
> read(87,'(I4)',advance='NO') i1,i2
....
> Rationale: The first read statement runs into an eor condition and
> is terminated befor assigning anything to i2.
I disagree.
Advancing vs nonadvancing makes a difference *ONLY* at the end of the
i/o statement in question. Just because you are doing a nonadvancing
read does not mean that there are no conditions under which multiple
records will be read. Explicit slashes in the format will still be
honored. And format reversion still works as normal. (Format reversion
is what causes your (i4) to be used again on a new record).
This should read values for both i1 and i2, leaving the file position
after i2 in the second record.
Format reversion is described in 10.3 (same section number in f95 and in
f2003). I don't think you will find the words "advancing" or
"nonadvancing" in that section - in particular, you won't find anything
that says it operates differently in the case of nondavancing.
See also the description of the eor condition in 9.10.0 of f2003 (or
9.4.3.0 of f95). It talks about "attempts to transfer data from a
position beyond the end of the current record..". The code sample shown
doesn't do that; the format reversion makes it transfer data from the
next record instead of from later in the current one.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| Herman D. Knoble 2005-02-01, 8:58 pm |
| Thomas: Indeed, (after removing the comma at the end of the first
print statement), Lahey LF95 prints what you show.
However, Salford complains correctly that I4 exceeds the record length
(which is 2); that is, the WRITE(87,..writes two records of 2 characters
each; the READ(87,..'s read four characters.
PAD=YES pads INPUT records; that is if you read less
than the record length, it will pad the read variable with blanks.
In your case you are reading MORE than (4 characters) the output
record length (2 characters). So I think Salford FTN95 is giving
the correct diagnostic; and Lahey LF95, while forgiving, is not.
Skip Knoble
On Tue, 1 Feb 2005 21:09:29 +0100 (CET), Thomas Koenig <Thomas.Koenig@online.de> wrote:
-|What should the following program print?
-|
-|program main
-| open(87,pad='YES')
-| write(87,'(A)') '10','20'
-| rewind(87)
-| i2=100
-| read(87,'(I4)',advance='NO') i1,i2
-| print *,"i1 = ",i1,
-| print *,"i2 = ",i2
-| read(87,'(I4)') i3
-| print *,"i3 = ",i3
-|end program main
-|
-|The way I interpret it, something similar to
-|
-| i1 = 10
-| i2 = 100
-| i3 = 20
-|
-|Rationale: The first read statement runs into an eor condition and
-|is terminated befor assigning anything to i2. Then, the second read
-|statements reads the second record. I also think ifort 8.1 gets
-|this wrong (Issue number 287783, if anybody at Intel is reading
-|this :-)
-|
-|Correct?
| |
| Richard E Maine 2005-02-01, 8:58 pm |
| In article <6dpvv0db6b2delnojipugprut8vsubu6p8@4ax.com>,
Herman D. Knoble <SkipKnobleLESS@SPAMpsu.DOT.edu> wrote:
> PAD=YES pads INPUT records; that is if you read less
> than the record length, it will pad the read variable with blanks.
> In your case you are reading MORE than (4 characters) the output
> record length (2 characters).
Ah. I overlooked the fact that the record was shorter than the i4 field.
I was thinking that you expected nonadvancing would cause format
reversion to not happen (I've seen people who expect that). The
interactions between PAD and nonadvancing are a bit strange to me, so I
have to go check.... Hmm.. yes, I think you (well, the OP) are probably
right after all.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
|
|
|
|
|