On Tuesday, March 29, 2022 at 10:48:12 PM UTC-7, Ron Shepard wrote:
> On 3/29/22 8:19 PM, Beliavsky wrote:
(snip)
> > with gfortran and Intel Fortran. Section 10.4 of Metcalf/Reid/Cohen (2018) says
> > "However, no element of the array may appear more than once in an input item."
> I was not aware of this restriction. I checked the standard, and the
> restriction is there, so MRC is correct. The example given in the
> standard is an array referenced with a vector subscript, not with
> literal constants, but I do not see any exception for that latter case.
Yes, I also found the restriction.
Note that there are a number of different ways to use array element that
can complicate I/O. Note, for example, (though I haven't looked recently)
to do something like:
READ(1) N, (X(I), Y(I), I=1,N)
Input items can be used in later items in the I/O list. I believe there is
a restriction on things like:
READ(1) (X(I), I=1,X(3))
where an input item is otherwise used in the same implied-DO group.
Now you get to things like:
READ(1) I, X(I), J, X(J)
which we know is legal when the read-in I is different from the read-in J.
The discussed restriction suggests that it isn't if I equals J, even
though it doesn't look so much harder to process.
(snip)
> > is non-standard. What about reading a scalar twice, as in
> > read (text,*) i,i
> > The reason to read a variable more than once is to skip over data.
> I do not see a similar restriction on repeated scalar variables in the
> i/o list. I certainly see this done in practice for the reason you give,
> to skip over items in the file and to ignore their values.
Note that the standard also doesn't say what the result should be.
By the way, C has a way to skip items in formatted input, with a *.
You can say, for example:
scanf("%*f");
such that it will read, and ignore, one f format item, following the normal rules
for f format, except for storing the data. This can be part of a larger list:
scanf("%f%*f%f", &x, &z);
Since C format items don't have the fixed width that Fortran items do,
it isn't so easy to ignore by length. Using, for example, 9X would traditionally
be used to ignore some columns, but that doesn't work for UNFORMATTED.
But as your example shows, in the case of list directed, you do need a way
to ignore something.