Array Pass

advertisement
Array Pass
At present the code can not be made to fail. I spent a good deal of 2/14/07
working with failure modes in which the variables in WINVT were not those called from
EXTR. The problem occurred both in watcom and watfor. I have found documentation
for this method of offsetting variables in a subroutine call.
Arrays as Dummy Arguments - fbooks.hlp Watcom
A dummy argument that is an array may be associated with an actual argument that is an
array, array element or array element substring. The number and size of the dimensions
in the actual argument array declarator may be different from the number and size of the
dimensions in the dummy argument array declarator.
If the actual argument is a non-character array name, then the size of the dummy
argument array must not exceed the size of the actual argument array. An element of the
actual array becomes associated with the element in the dummy array with the same
subscript value. Association by array element of character arrays exists only if the
lengths of the array elements are the same. If their lengths are not the same, the dummy
and actual array elements will not consist of the same characters.
If the actual argument is a non-character array element name whose subscript value is asv
the size of the dummy argument array must not exceed the size of the actual argument
array less asv - 1. Furthermore, the dummy argument array element whose subscript
value is dsv becomes associated with the actual argument array element whose subscript
value is asv + dsv - 1. Consider the following example.
Example:
DIMENSION A(10)
CALL SAM( A(3) )
END
SUBROUTINE SAM( B )
DIMENSION B(5)
.
.
.
END
In the previous example, array A is an actual argument and the array B is the dummy
argument. Suppose we wanted to know which element of A is associated with the 4th
element of B. Then asv would have value 3 since the array element
A(3) is the actual argument, and dsv is 4. Then the 4th element in B is 3 + 4 - 1 = 6th
element of A.
If the actual argument is a character array name, character array element name or
character array element substring which begins at character storage unit ach, then the
character storage unit dch of the dummy argument array is associated with the character
storage unit ach + dch - 1 of the actual array. The size of the dummy character array
must not exceed the size of the actual argument array.
The notion is to pass the middle part of an array by calling a subroutine with an
offset array. The working version is in ApassW.zip. This includes a lot of extraneous
code since the error occurred in real work. The calling routine has arrays WF, WFINV,
and WT. The array in WINVT is supposed to act as though it had been equivalenced to
WF starting at NB. Since NB is a variable, direct equivalencing is not possible.
COMPLEX*16 wt(Nt),WF(Nt),wtinv(Nt),WFINV(Nt),XT
…
CALL WINVT(WF(NB),WFINV(NB),WT)
WRITE(1,*)' from main ',WFINV(NB)
The subroutine is
SUBROUTINE WINVT(WF,Wfinv,WT)
IMPLICIT REAL*8 (A-H,O-Z)
COMPLEX*16 WF(*),Wfinv(*),WT(*)
C Wf is the data to be inverted, It is offset in the call to winv
C wt is the symmetric Fourier transform of Wf, it is a temporary vector
C DPASS is a scratch vector used by FFT.
WRITE(1,*)'from winvt WFINV(1) = ',WFINV(1)
WFINV(1)=7
RETURN
END
The output is
BEG END
1
512
FROM EXTR NB =
1
from winvt WFINV(1) =
(17.0000000000000000,0.0000000000000000)
from main
(7.0000000000000000,0.0000000000000000)
A subtle change in order threw this off before, but not now
BEG END
129
384
FROM EXTR NB =
129
from winvt WFINV(1) =
(17.000000000000000,0.000000000000000)
from main
(7.000000000000000,0.000000000000000)
Download