From: monir on
Hello;

1) I've the following 1D arrays written in a sequential data file:
np = nx * nr * nt
do i =1, nrecords
write (80) (x(m), r(m), t(m), m=1, np)
write (80) (vx(m), vr(m), vt(m), m=1, np)
end do

2) Somewhere in the program, I'd like to read all the records and
assign an index to each one. THEN, for a given record, convert each
array variable to its nx, nr, nt dims.

For example:
(with arrays x, r, t DO not differ in this exercise; but the v's
arrays DO)
do ii =1, nrecord
Read (80) (((xb(i,j,k), rb(i,j,k),tb(i,j,k), k=1, nt), j=1, nr),
i=1, np)
Read (80) (vxi(ii,m), vri(ii,m), vti(ii,m), m=1, np)
end do

THEN:
For a desired record, say, ii=5, I need to convert:
vxi(5,m), vri(5,m), vti(5,m), m=1, np
to:
vxx(i,j,k), vrr(i,j,k), vtt(i,j,k), i=1, nx, j=1,nr, k=1,nt

Can this be done without using 4D arrays or Equivalence (F77/g95) ??

Regards.
Monir
From: e p chandler on
On Feb 18, 11:54 am, monir <mon...(a)mondenet.com> wrote:
> Hello;
>
> 1) I've the following 1D arrays written in a sequential data file:
> np = nx * nr * nt
> do i =1, nrecords
>     write (80) (x(m), r(m), t(m), m=1, np)
>     write (80) (vx(m), vr(m), vt(m), m=1, np)
> end do
>
> 2) Somewhere in the program, I'd like to read all the records and
> assign an index to each one. THEN, for a given record, convert each
> array variable to its nx, nr, nt dims.
>
> For example:
> (with arrays x, r, t DO not differ in this exercise; but the v's
> arrays DO)
> do ii =1, nrecord
>     Read (80) (((xb(i,j,k), rb(i,j,k),tb(i,j,k), k=1, nt), j=1,  nr),
> i=1, np)
>     Read (80) (vxi(ii,m), vri(ii,m), vti(ii,m), m=1, np)
> end do
>
> THEN:
> For a desired record, say, ii=5, I need to convert:
>    vxi(5,m), vri(5,m), vti(5,m), m=1, np
> to:
>    vxx(i,j,k), vrr(i,j,k), vtt(i,j,k), i=1, nx, j=1,nr, k=1,nt
>
> Can this be done without using 4D arrays or Equivalence (F77/g95) ??
>
> Regards.
> Monir

How was the data written to the sequential data file? What was the
order of the subscripts for x, r and t used when the file was written?

Just read the data file one record at a time into temporary variables.
Next figure out what the I,J and K indices must be. Then assign each
value to FOO(I,J,K), BAR(I,J,K), BAZ(I,J,K) etc.

--- e


From: monir on
On Feb 18, 4:11 pm, e p chandler <e...(a)juno.com> wrote:
> On Feb 18, 11:54 am, monir <mon...(a)mondenet.com> wrote:
> > Monir
>
> e p chandler wrote:
> How was the data written to the sequential data file? What was the
> order of the subscripts for x, r and t used when the file was written?
>

The data was written to the sequential file with "t" changing faster,
then "r", and then "x".
The same for vt, vr, vx.

Regards.
Monir
From: e p chandler on

"monir" <monirg(a)mondenet.com> wrote in message
news:f4014600-20a5-4865-a1a6-7ffa3e7595cd(a)c5g2000vbh.googlegroups.com...
On Feb 18, 4:11 pm, e p chandler <e...(a)juno.com> wrote:
> On Feb 18, 11:54 am, monir <mon...(a)mondenet.com> wrote:
> > Monir
>
> e p chandler wrote:
> How was the data written to the sequential data file? What was the
> order of the subscripts for x, r and t used when the file was written?
>

The data was written to the sequential file with "t" changing faster,
then "r", and then "x".
The same for vt, vr, vx.

Regards.
Monir

But you seem to want to read it back in as var(x_index,r_index,t_index).
Unfortunately in Fortran, the first subscript varies the most rapidly, not
the last. So you have written out the data as a higher dimensional transpose
of the natural order in which Fortran would want to read it.

--- e


From: monir on
On Feb 18, 8:16 pm, "e p chandler" <e...(a)juno.com> wrote:
> "monir" <mon...(a)mondenet.com> wrote in message
>
> On Feb 18, 4:11 pm, e p chandler <e...(a)juno.com> wrote:
>
> But you seem to want to read it back in as var(x_index,r_index,t_index).
> Unfortunately in Fortran, the first subscript varies the most rapidly, not
> the last. So you have written out the data as a higher dimensional transpose
> of the natural order in which Fortran would want to read it.
>
> --- e

That's correct, and would've caused serious problems if the write/read
arrays are multidimensional.
The difference here is that I've the arrays written and read as 1D,
and simply assigned each read element to a particular position in 2D
or 3D arrays, as the case may be.

The answer to my inquiry in the OP appears to be much simpler than I
had originally thought.
Here's what appears to be working fine for me:
Data is written to the sequential file with "t" changing faster, then
"r", and then "x".
Same for vt, vr, vx.

!.........................
!The 1D arrays are written in a continuous sequence
np = nx * nr * nt
do i =1, nrecords
Write (80) (x(m), r(m), t(m), m=1, np)
Write (80) (vx(m), vr(m), vt(m), m=1, np)
end do

!.........................
!Read the 1D arrays and in the process assign each read element to 2D
and 3D arrays; as the case may be
!Arrays x, r, t DO not differ in this example from record to record,
while the v's arrays DO
do ii =1, nrecords
Read (80) (((xb(i,j,k), rb(i,j,k),tb(i,j,k), k=1,nt), j=1,nr),
i=1,nx)
Read (80) (vxi(ii,m), vri(ii,m), vti(ii,m), m=1,np)
end do

!.........................
!For a desired record index "ind", convert the 2D "v" arrays to 3D "v"
arrays with subscripts i=1,nx, j=1,nr, k=1,nt
!consistent with the written data
ind = 5
kount = 0
do i=1, nx
do j=1, nr
do k=1, nt
kount = kount+1
vxx(i,j,k) = vxi(ind,kount)
vrr(i,j,k) = vri(ind,kount)
vtt(i,j,k) = vti(ind,kount)
end do

I'm sure you experts can easily accomplish same in a more compact and
more efficient way, but ...

Any comments ??

Regards.
Monir
 |  Next  |  Last
Pages: 1 2
Prev: Hourly mean
Next: virtual memory issue