Passing a 3-D array as a 2-D array 
Author Message
 Passing a 3-D array as a 2-D array


I forgot how to do this, and I could not find answers from the
library since the books are very elementary(?)

Here is the problem:

c     dimension c(3,6,6)
      call func(c(1,1,1)
      subroutine func(c)
      dimension c(6,6)

From the calling part, I want the array returned from func() goes
to c(1,6,6) in the MAIN.  There is a way to do it, but I just forgot it.

Your helpis greatly appreciated.

Ji Wang

    /\    /\    / Department  of   Civil   Engineering  & Operations  Research
   /  \  /  \  / Princeton University WWW: http://www.*-*-*.com/ :80/~jiwang
__/    \/    \/ Princeton NJ 08544-5263  Tel:(609)258-6239 Fax:(609)258-1270

Sun, 25 Jan 1998 03:00:00 GMT  
 Passing a 3-D array as a 2-D array


>c     dimension c(3,6,6)
>      .....
>      .....
>      call func(c(1,1,1)
>      .....
>      stop
>      and
>      subroutine func(c)
>      dimension c(6,6)
>      ....
>      ....
>      return
>      end

>From the calling part, I want the array returned from func() goes
>to c(1,6,6) in the MAIN.  There is a way to do it, but I just forgot it.

The only straightforward way to do it is to pass an array section
(which is a fortran 90 feature):

        call func(c(1,:,:))

If you are stuck with Fortran 77, the problem is that func expects the
array to occupy consecutive memory locations, while the calling program
has the desired array elements in nonconsecutive locations.  If you
compare the corresponding locations, you find:

        locations in main       locations in func
        -----------------       -----------------
             c(1,1,1)               c(1,1)
             c(2,1,1)                 ?
             c(3,1,1)                 ?
             c(1,2,1)               c(2,1)
             c(2,2,1)                 ?
             c(3,2,1)                 ?
             c(1,3,1)               c(3,1)
              ...                    ...

Short of copying the elements you want to another array, about the only
other way out of this mess in Fortran 77 is to reverse the order of the

        dimension c(6,6,3)
        call func(c(1,1,1))

        subroutine func(c)
        dimension c(6,6)

This way, the elements that are seen by func are the first 36 elements
of c in the main program, and they are consecutive locations (no

Dave Seaman

Mon, 26 Jan 1998 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. ds ds

2. Can't pass boolean array into Array Subset in a For loop

3. Problem with with Array of U8 to Array of Array of Boolean

4. convert 2d array to 1d array without using shift registers and build array

5. Arrays: Build array in multiple for loops or replace array elements

6. Multidimensional array vs. array of array

7. Question about array ops on arrays of types of arrays of ...(ack)

8. adjustable-array-p, adjust-array and array-destruction

9. Seek examples of BFS or DFS and implementation of tree DS

10. Is DS capable of writing business applications fast?

11. TGen for DS 4.01

12. DC and DS in load modules?


Powered by phpBB® Forum Software