From: glen herrmannsfeldt on
Arjen Markus <arjen.markus895(a)gmail.com> wrote:
> On 13 apr, 10:10, m_b_metcalf <michaelmetc...(a)compuserve.com> wrote:
>> On Apr 13, 8:50?am, Woody <ols6...(a)sbcglobal.net> wrote:

>> > When a READ statement is executed, it stores a value in each variable
>> > name in its I/O list. Does the standard specify that the values are
>> > stored in order, left-to-right?

I don't believe that is specified. For example, in mutlithreaded
systems you probably can't count on that.

>> > Is it legal to use a value stored by a
>> > previous variable in the list?

This one, the standard does specify is allowed.

>> > For example

>> > INTEGER :: seq,n,v(20),u
>> > ! File is opened on unit u for formatted sequential access
>> > READ(UNIT=u,"(I3,1X,I3,20I5)") seq,n,(v(i),i=1,n)

>> > uses the value of n read in by the same statement.

>> Yes, that is legal (see also 'Fortran 95/2003 Explained', Section
>> 9.15).

I remember doing this with unformatted I/O in the Fortran 66 days.

> Mind you: you do not check that n is within a valid range then.

> You could achieve that via:

> READ(UNIT=u,"(I3,1X,I3,20I5)") seq,n,( v(i), i=1,min(n,size(v)) )

Fortran 66 only allowed variables (not expressions) for DO
statements, or implied DO, and many compilers kept that restriction.

One of the more common extensions to Fortran 66, though, was
allowing general expressions for subscripts. In that case,

READ(1) seq,n,( v(min(100,i)), i=1,n)

(or other maximum value) would work. In this case, it depends
on the program writing the file to stay within range.

For newer Fortran versions, it does have the disadvanatage that
you can't ALLOCATE the array based on the size.
(Well, with careful use of BACKSPACE you might be able to do it.)

-- glen
From: Arjen Markus on
On 13 apr, 13:31, glen herrmannsfeldt <g...(a)ugcs.caltech.edu> wrote:
> Arjen Markus <arjen.markus...(a)gmail.com> wrote:
> > On 13 apr, 10:10, m_b_metcalf <michaelmetc...(a)compuserve.com> wrote:
> >> On Apr 13, 8:50?am, Woody <ols6...(a)sbcglobal.net> wrote:
> >> > When a READ statement is executed, it stores a value in each variable
> >> > name in its I/O list. Does the standard specify that the values are
> >> > stored in order, left-to-right?
>
> I don't believe that is specified.  For example, in mutlithreaded
> systems you probably can't count on that.
>
> >> > Is it legal to use a value stored by a
> >> > previous variable in the list?
>
> This one, the standard does specify is allowed.
>
> >> > For example
> >> > INTEGER :: seq,n,v(20),u
> >> > ! File is opened on unit u for formatted sequential access
> >> > READ(UNIT=u,"(I3,1X,I3,20I5)") seq,n,(v(i),i=1,n)
> >> > uses the value of n read in by the same statement.
> >> Yes, that is legal (see also 'Fortran 95/2003 Explained', Section
> >> 9.15).
>
> I remember doing this with unformatted I/O in the Fortran 66 days.
>
> > Mind you: you do not check that n is within a valid range then.
> > You could achieve that via:
> > READ(UNIT=u,"(I3,1X,I3,20I5)") seq,n,( v(i), i=1,min(n,size(v)) )
>
> Fortran 66 only allowed variables (not expressions) for DO
> statements, or implied DO, and many compilers kept that restriction.
>
> One of the more common extensions to Fortran 66, though, was
> allowing general expressions for subscripts.  In that case,
>
>       READ(1) seq,n,( v(min(100,i)), i=1,n)
>
> (or other maximum value) would work.   In this case, it depends
> on the program writing the file to stay within range.
>
> For newer Fortran versions, it does have the disadvanatage that
> you can't ALLOCATE the array based on the size.  
> (Well, with careful use of BACKSPACE you might be able to do it.)
>
> -- glen

(I love it that such seemingly haphazard limitations are gone)

You could use non-advancing I/O to read up to but not including
the start of the array, allocate it and then read on ...

Regards,

Arjen
From: robin on
"Arjen Markus" <arjen.markus895(a)gmail.com> wrote in message
news:240a2e9a-7c4a-42ae-bce1-de7e51a4b8ba(a)35g2000yqm.googlegroups.com...
On 13 apr, 13:31, glen herrmannsfeldt <g...(a)ugcs.caltech.edu> wrote:

>> READ(1) seq,n,( v(min(100,i)), i=1,n)
>
>> (or other maximum value) would work. In this case, it depends
>> on the program writing the file to stay within range.
>>
>> For newer Fortran versions, it does have the disadvanatage that
>> you can't ALLOCATE the array based on the size.
>> (Well, with careful use of BACKSPACE you might be able to do it.)
>
>> -- glen

>You could use non-advancing I/O to read up to but not including
>the start of the array, allocate it and then read on ...

Not with unformatted READ, as here.

>Regards,
>Arjen


From: robin on
"glen herrmannsfeldt" <gah(a)ugcs.caltech.edu> wrote in message news:hq1klk$hbj$1(a)naig.caltech.edu...
| Arjen Markus <arjen.markus895(a)gmail.com> wrote:
| > On 13 apr, 10:10, m_b_metcalf <michaelmetc...(a)compuserve.com> wrote:
| >> On Apr 13, 8:50?am, Woody <ols6...(a)sbcglobal.net> wrote:
|
| >> > When a READ statement is executed, it stores a value in each variable
| >> > name in its I/O list. Does the standard specify that the values are
| >> > stored in order, left-to-right?
|
| I don't believe that is specified. For example, in mutlithreaded
| systems you probably can't count on that.

They are stored in left-to-right order, as distinct from right-to-left order,
or any other order.

| >> > Is it legal to use a value stored by a
| >> > previous variable in the list?
|
| This one, the standard does specify is allowed.


From: Woody on
On Apr 13, 1:10 am, m_b_metcalf <michaelmetc...(a)compuserve.com> wrote:
> see also 'Fortran 95/2003 Explained', Section 9.15.

Darn! That's the first place I looked, but I didn't notice that little
section at the end. I was looking in 9.3. Maybe add a x-ref in the
next edition?