Skip to content

Commit

Permalink
CharacterStringType cleanup not based on fortran final
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and mjreno committed Nov 26, 2024
1 parent 22dde9b commit aef9a65
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Utilities/CharString.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ module CharacterStringModule
procedure :: charstring_eq_charstring
procedure :: write_unformatted
procedure :: strlen
procedure :: destroy
generic :: assignment(=) => assign_to_charstring, assign_from_charstring
generic :: operator(==) => character_eq_charstring, &
charstring_eq_character, &
charstring_eq_charstring
! not supported by gfortran 5 and 6
! disable for now
! generic :: write (unformatted) => write_unformatted
final :: destruct
end type CharacterStringType

contains
Expand Down Expand Up @@ -128,9 +128,9 @@ function strlen(this) result(length)
end if
end function strlen

subroutine destruct(this)
type(CharacterStringType), intent(inout) :: this
subroutine destroy(this)
class(CharacterStringType), intent(inout) :: this
if (allocated(this%charstring)) deallocate (this%charstring)
end subroutine destruct
end subroutine destroy

end module CharacterStringModule
2 changes: 1 addition & 1 deletion src/Utilities/Idm/mf6blockfile/Mf6FileGridInput.f90
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ end subroutine bndgrid_rp
subroutine bndgrid_destroy(this)
class(BoundGridInputType), intent(inout) :: this !< Mf6FileGridInputType
!
! deallocate objects
! deallocate tasmanager
call this%tasmanager%da()
deallocate (this%tasmanager)
nullify (this%tasmanager)
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Idm/mf6blockfile/Mf6FileListInput.f90
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ end subroutine bndlist_rp
subroutine bndlist_destroy(this)
class(BoundListInputType), intent(inout) :: this !< BoundListInputType
!
! deallocate objects
! deallocate tsmanager
call this%tsmanager%da()
deallocate (this%tsmanager)
nullify (this%tsmanager)
Expand Down
2 changes: 2 additions & 0 deletions src/Utilities/Idm/mf6blockfile/StructArray.f90
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ subroutine load_deferred_vector(this, icol)
this%mempath)
do i = 1, this%nrow
p_charstr1d(i) = this%struct_vectors(icol)%charstr1d(i)
call this%struct_vectors(icol)%charstr1d(i)%destroy()
end do
end if

Expand Down Expand Up @@ -668,6 +669,7 @@ subroutine check_reallocate(this)

do i = 1, this%struct_vectors(j)%size
p_charstr1d(i) = this%struct_vectors(j)%charstr1d(i)
call this%struct_vectors(j)%charstr1d(i)%destroy()
end do

deallocate (this%struct_vectors(j)%charstr1d)
Expand Down
8 changes: 7 additions & 1 deletion src/Utilities/Memory/Memory.f90
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ end function mt_associated

subroutine mt_deallocate(this)
class(MemoryType) :: this
integer(I4B) :: n

if (associated(this%strsclr)) then
if (this%master) deallocate (this%strsclr)
Expand Down Expand Up @@ -156,7 +157,12 @@ subroutine mt_deallocate(this)
end if

if (associated(this%acharstr1d)) then
if (this%master) deallocate (this%acharstr1d)
if (this%master) then
do n = 1, size(this%acharstr1d)
call this%acharstr1d(n)%destroy()
end do
deallocate (this%acharstr1d)
end if
nullify (this%acharstr1d)
end if
end subroutine mt_deallocate
Expand Down
6 changes: 6 additions & 0 deletions src/Utilities/Memory/MemoryManager.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ subroutine reallocate_charstr1d(acharstr1d, ilen, nrow, name, mem_path)
! -- copy existing values
do n = 1, nrow_old
astrtemp(n) = acharstr1d(n)
call acharstr1d(n)%destroy()
end do
!
! -- fill new values with missing values
Expand All @@ -1242,6 +1243,7 @@ subroutine reallocate_charstr1d(acharstr1d, ilen, nrow, name, mem_path)
! -- fill the reallocated character array
do n = 1, nrow
acharstr1d(n) = astrtemp(n)
call astrtemp(n)%destroy()
end do
!
! -- deallocate temporary storage
Expand Down Expand Up @@ -2009,6 +2011,7 @@ subroutine deallocate_charstr1d(astr1d, name, mem_path)
type(MemoryType), pointer :: mt
logical(LGP) :: found
type(MemoryContainerIteratorType), allocatable :: itr
integer(I4B) :: n
! -- code
!
! -- process optional variables
Expand All @@ -2033,6 +2036,9 @@ subroutine deallocate_charstr1d(astr1d, name, mem_path)
terminate=.TRUE.)
else
if (mt%master) then
do n = 1, size(astr1d)
call astr1d(n)%destroy()
end do
deallocate (astr1d)
else
nullify (astr1d)
Expand Down

0 comments on commit aef9a65

Please sign in to comment.