Passing an array of derived type containing an array as a component



Hello group:

I'm having a problem passing an array in a library procedure argument.

I've created the following derived type
TYPE cashe
DOUBLE PRECISION ::expctdV
INTEGER, DIMENSION(:), ALLOCATABLE ::shrs
END TYPE cashe
and the following array of that type
TYPE(cashe), DIMENSION(:), ALLOCATABLE ::history

I can allocate and initialize using
ALLOCATE(history(1:nSteps))
DO i=1,nSteps
ALLOCATE(history(i)%shrs(1:nA))
END DO
DO i=1,nSteps
CALL SelectPort()
history(i)%expctdV=v0*EXP(DOT_PRODUCT(portfolio%w,r))
history(i)%shrs=portfolio%shares
END DO

I also have no problem accessing array elements using expressions such as
history(minlocation)%expctdV=expctdV
history(minlocation)%shrs=portfolio%shares

The problem I have is with the following:
CALL DSORT(history%expctdV,history%shrs,nSteps,-2)
where DSORT is a library procedure.
The error I get is:
CALL DSORT(history%expctdV,history%shrs,nSteps,-2)
1
Error: Component to the right of a part reference with nonzero rank must not
have the ALLOCATABLE attribute at (1)
(In case this does not print correctly, the reference is to the array
history%shrs)

I've confirmed that history%shrs is correctly allocated (nSteps*nA).
Also, I don't get the error if I make a copy of the array and use the copy
as in:
FORALL(i=1:nSteps,j=1:nA)test(i,j)=history(i)%shrs(j)
CALL DSORT(history%expctdV,test,nSteps,-2)

DSORT was a f77 subroutine that I recompiled from source code using
gfortran. I've used it before.

I've tried various forms of history%shrs (using explicit array sections for
example) but I still get the error.
Can anyone see where I am going wrong?
Thanks,
Mike




.



Relevant Pages