From 92bcf3a7aacb113d9c8c45a86b0f5e95b20fcc54 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 26 Jun 2018 18:46:52 +0200 Subject: [PATCH] function to free elements of the string list. Note: Pointers that are allocated will never go out of scope. Pointers that are assigned (=>) will be deallocated/disaccociated like allocatables that go out of scope --- src/config.f90 | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/config.f90 b/src/config.f90 index 5674612eb..6c53dc5e4 100644 --- a/src/config.f90 +++ b/src/config.f90 @@ -24,6 +24,7 @@ module config contains procedure :: add => add procedure :: show => show + procedure :: free => free procedure :: keyExists => keyExists procedure :: countKeys => countKeys @@ -166,8 +167,9 @@ subroutine config_init() end subroutine config_init + !-------------------------------------------------------------------------------------------------- -!> @brief parses the homogenization part in the material configuration file +!> @brief parses the material.config file !-------------------------------------------------------------------------------------------------- subroutine parseFile(line,& sectionNames,part,fileUnit) @@ -229,6 +231,7 @@ subroutine parseFile(line,& call part(s)%show() end do end if + end subroutine parseFile !-------------------------------------------------------------------------------------------------- @@ -283,23 +286,24 @@ end subroutine show !-------------------------------------------------------------------------------------------------- -!> @brief deallocates all elements of a given list -!> @details Strings are printed in order of insertion (FIFO) +!> @brief cleans entire list +!> @details list head is remains alive !-------------------------------------------------------------------------------------------------- -! subroutine free_all() -! implicit none -! -! type(node), pointer :: item -! -! do -! item => first -! -! if (associated(item) .eqv. .FALSE.) exit -! -! first => first%next -! deallocate(item) -! end do -! end subroutine free_all +subroutine free(this) + + implicit none + class(tPartitionedStringList), target, intent(in) :: this + type(tPartitionedStringList), pointer :: new, item + + item => this%next + do while (associated(item%next)) + new => item + deallocate(item) + item => new%next + enddo + deallocate(item) + +end subroutine free !--------------------------------------------------------------------------------------------------