- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page