RE: Re: SAVE attribute for automatic shaped arrays?

RE: Re: SAVE attribute for automatic shaped arrays?

Thanks for your reply. I'll try to explain what I need to do. Concentrate on the variable et. Look at the following

SUBROUTINE mysub(y)
REAL(KIND=dp), DIMENSION( : ) :: y
REAL(KIND=dp), SAVE :: et=0.0D0

et = et +1.0_dp

END SUBROUTINE mysub

The very first time I call mysub, the variable et is set to zero. During the procedure it is updated and the value et is saved for the next time I call the subroutine.
Now I want to reproduce exactly the same effect with an array, say ey. Here is my solution

SUBROUTINE mysub(y)
REAL(KIND=dp), DIMENSION( : ) :: y
REAL(KIND=dp), SAVE :: et=0.0D0
REAL(KIND=dp), DIMENSION( : ), ALLOCATABLE :: ey

et = et +1.0_dp

IF (.NOT.ALLOCATED(ey)) THEN
ALLOCATE (ey(SIZE(y,1)))
ey = 0.0_dp
ENDIF

ey = ey + 1.0_dp

END SUBROUTINE mysub

This is what I have written to obtain this effect. What I don't like in this approach is that when I return back to the main program, the variable ey cannot be DEALLOCATED. That's why I was asking for something different from an allocatable array. What do you mean by considering a module variable?

Cheers

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.