I need to pass a set of arrays to a program that does the work (e.g. an ODe solver). Now the way this is written is it allows a parameter array RPAR which is a 1-d double precision array
However, the parameters that must be passed are a number of multidimensional arrays, and in once case a complex *16 array. As far as I know 2D arrays in Fortran are always stored by columns and a complex *16 value is two contiguous double precision reals. The minimal example showing the problem is this:
However, the parameters that must be passed are a number of multidimensional arrays, and in once case a complex *16 array. As far as I know 2D arrays in Fortran are always stored by columns and a complex *16 value is two contiguous double precision reals. The minimal example showing the problem is this:
implicit double precision(a-h,o-z)
complex*16, DIMENSION ,, ALLOCATABLE :: evecs
double precision, dimension ), allocatable :: evals,rpar
n=3
c allocate spaceallocate (evecs(N,n ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate evecs '
stop 1
end if
allocate (evals(N ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate evals '
stop 1
end if
allocate (rpar(N*(2*N+1) ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate rpar '
stop 1
end if
c fill the data structures we will work withdo 1 i=1,n
evals(i)=1.d0*i
write(6,*)'evals(',i,')=',evals(i)
do 2 j=1,n
evecs(j,i)=dcmplx(i*1.d0,-j*1.d0)
write(6,*)'evecs(',j,i,')=',evecs(j,i)
2 continue
1 continue
c because the processing routine wants all parameters in a single double precision array rpar, do thatDO 11 I=1,N
RPAR(I)=EVALS(I)
11 CONTINUE
indx=n
DO 12 I=1,N
DO 13 J=1,N
INDX=INDX+1
RPAR(INDX)=DREAL(EVECS(J,I))
INDX=INDX+1
RPAR(INDX)=DIMAG(EVECS(J,I))
13 CONTINUE
12 CONTINUE
call bigroutine(n,rpar)
deallocate (rpar, stat=IALLOCATEstatus)
deallocate (evals, stat=IALLOCATEstatus)
deallocate (evecs, stat=IALLOCATEstatus)
end
subroutine bigroutine(n,rpar)
double precision rpar(*)
c here the main work is none. But it needs to work with evals ane evecscall process(n,rpar)
return
end
subroutine process(n,evals,evecs)
complex*16 evecs(n,n)
double precision evals
do 1 i=1,n
write(6,*)'evals(',i,')=',evals(i)
1 continue
indx=n
do 2 i=1,n*n
c row:icol=1+(i-irow)/n
irow=mod(i,n)
if(irow.eq.0)then
irow=n
icol=i/n
endif
write(6,*)'evecs(',irow,icol,')=',evecs(irow,icol)
2 continue
return
end