Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29236 Discussions

Filling a 3-D array in an unusual way

TommyCee
Beginner
382 Views

Suppose you have an integer array iTime(4,4,5) which is initially filled as follows (where nSeason = 5):

do iSeason = 1,nSeason
  read(5,*) (iTime(1,J,iSeason), iTime(2,J,iSeason), J = 1,4)
enddo

Now supposed that you set the J=2 elements of this array upstream of this read loop and only wish to read in 3 pairs of integers.  In this way, you'd like to control distribution of the read integer values by setting the the J-index as 1, 3-4.  I hope my description is clear.

I've never tried to do this before.  Is there an easy way to do this?  Is there any way to do this?

 

0 Kudos
4 Replies
IanH
Honored Contributor III
382 Views
integer, parameter :: the_ones_i_want(3) = [ 1, 3, 4 ]
do iSeason = 1,nSeason
  read(5,*) ( iTime(1,the_ones_i_want(J),iSeason),  &
      iTime(2,the_ones_i_want(J),iSeason),  &
      J = 1,size(the_ones_i_want) )
enddo

 

0 Kudos
TommyCee
Beginner
382 Views

Hmmm ...

Stunning.

I'll give that a shot.  Thanks so much, Ian.

0 Kudos
TommyCee
Beginner
382 Views

Just posting back to say that I transposed your code suggestion and incorporated it into my system.  It worked like top.

Sweet.

0 Kudos
jimdempseyatthecove
Honored Contributor III
382 Views

TommyCee,

FYI,

The operation you are performing is a scatter operation. If the collection of input data are in a sequential array as opposed to read file, then you can use:

OutArray(the_ones_I_want) = InArray ! or InArray(1:nItems), or InArray(1:size(the_ones_I_want))

Where you use the array "the_ones_I_want" as the index positions in OutArray

You can use the same trick on the other side of = for a gather operation.

Jim Dempsey

0 Kudos
Reply