I am currently trying to encode a small routine in Fortran to free all allocated variables in memory when my program arrives at an error, that is, it was not possible to load a file or a nonexistent file. At this stage, the execution should be completed, but not all distributed attributes are necessarily distributed (it depends on where the error appeared in the code), so I can not do the cleaning, freeing all of them.
My current approach is this:
SUBROUTINE Cleanup(A) REAL(8), ALLOCATABLE, DIMENSION(:) :: A IF (ALLOCATED(A)) THEN DEALLOCATE(A) END IF END SUBROUTINE
and call "Cleanup" for each highlighted. The problem is that not all of my variables are dimension-1. Some of them have up to three dimensions.
At first I thought about writing 3 different routines for different dimensions and using overload, but that doesn't seem very elegant.
Then it occurred to me that maybe I can pass a pointer instead of the actall argument, but I have googled, and it looks like you cannot release the target variable through the pointer.
Any ideas on how to do this correctly?
Thanks.
source share