Re: Efficient way to pass different shaped arrays?





Peter wrote:

I'm attempting to use an array argument of a subroutine for two
different purposes. One, which works fine, has the caller declare an
identical explicit shape array. The other, shown below, has the caller
(A) passing a small number of reals in the same memory space.
Subroutine B knows, via other arguments not shown, which kind of array
argument is being received.

In subroutine A:

REAL, DIMENSION(3) :: array
CALL B(array)

SUBROUTINE B(array)
REAL, DIMENSION(28,0:10001), INTENT(INOUT) :: array
How about
real, dimension(28,0:*), intent(inout) :: array

You'll have to do the right thing with the array, but I
think the subscripting might be legal. Unfortunately, I've
got to leave the office and can't think now.

*** Hendrickson



Under CVF6, this worked as expected, but using IVF9, the compiler flags
an error because the extent of 'array' as a dummy argument for B
exceeds the size of the real argument 'array' in A; presumably this is
an error because B could write memory beyond the size of 'array'
declared by the caller.

So, my question is, what is a simple and efficient way to pass in the
3-element array? I don't really want to create a huge 28x10002 array in
the caller, and for efficiency it would be better not to add another
argument (subroutine B gets called many times).


.


Quantcast