(j3.2006) Actual argument rank 2 array X(1, 4) associated with dummy rank 1 array - is that allowed ?

Robert Corbett Robert.Corbett
Wed Dec 23 06:48:34 EST 2009


Toon Moene wrote:
> I came upon a piece of code in our Weather Forecasting system that 
> roughly did the following:
> 
> SUBROUTINE A(X, N)
> REAL X(N, 4), Y(N)
> ...
> CALL B(Y, N)
> DO I = 1, N
>    X(I,4) = Y
> ENDDO
> ...
> END
> SUBROUTINE B(Z, N)
> REAL Z(N)
> ...
> DO I = 1, N
>    Z(I) = ... some expression ...
> ENDDO
> END
> 
> This is of course correct, but probably overly so.  I thought it would 
> be possible to code this as:
> 
> SUBROUTINE A(X, N)
> REAL X(N, 4)
> ...
> CALL B(X(1,4), N)
> ...
> END
> SUBROUTINE B(Z, N)
> REAL Z(N)
> ...
> DO I = 1, N
>    Z(I) = ... some expression ...
> ENDDO
> END
> 
> i.e., without the auxiliary array Y and the copy loop.
> 
> Now the hard part is to find where the Standard (I'm looking at N1782) 
> allows this.  The closest that I can find is 12.5.2.4 par. 14 where it 
> says that for assumed-shape arrays the rank of actual and dummy should 
> be the same (this almost implies that for non-assumed-shape arrays they 
> don't have to - then, by virtue of the way arrays are laid out [16.5.3.2 
> par 2, point 7] Z would correspond to the fourth column of X).
> 
> Is this reasoning correct ?

It is.  In the N1791 document, Section 12.5.2.11 paragraph 4 spells it
out explicitly.  It states

     An actual argument that represents an element sequence and
     corresponds to a dummy argument that is an array is sequence
     associated with the dummy argument if the dummy argument is
     an explicit-shape or assumed-size array.  The rank and shape
     of the actual argument need not agree with the rank and shape
     of the dummy argument, but the number of elements in the
     dummy argument shall not exceed the number of elements in the
     element sequence of the actual argument.

Note that the actual argument is not required to be contiguous.

Bob Corbett



More information about the J3 mailing list