From: Woody on
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? Is it legal to use a value stored by a
previous variable in the list?

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.
From: m_b_metcalf on
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? Is it legal to use a value stored by a
> previous variable in the list?
>
> 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).

Regards,

Mike Metcalf
From: Arjen Markus on
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? Is it legal to use a value stored by a
> > previous variable in the list?
>
> > 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).
>
> Regards,
>
> Mike Metcalf

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

Regards,

Arjen
From: robin on
"Woody" <ols6000(a)sbcglobal.net> wrote in message
news:89b43a65-4fce-4a0f-8ccf-3755148348a6(a)k33g2000yqc.googlegroups.com...
| 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?

Yes. You couldn't get anywhere otherwise.

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

Yes. Values are stored as soon as requested bt Format control.

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

That is a traditional way to read an array.


From: robin on
"Arjen Markus" <arjen.markus895(a)gmail.com> wrote in message
news:ff82905d-ace2-4cd9-84f9-b995ca6f4da2(a)35g2000yqm.googlegroups.com...
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? Is it legal to use a value stored by a
> > previous variable in the list?
>
> > 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).
>
> Regards,
>
> Mike Metcalf

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

In his example, yes; but in general, no, of course.

It would be still necessary to include an explicit check on the value of N
not exceeding the declared upper limit,
otherwise some subsequent array reference would come to grief.