Skip to content

Commit

Permalink
Moved deallocation to outside of conditional.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgknox committed Apr 27, 2018
1 parent b92e726 commit f25e25d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 54 deletions.
52 changes: 26 additions & 26 deletions biogeochem/EDCohortDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ subroutine terminate_cohorts( currentSite, currentPatch, level )
!----------------------------------------------------------------------


currentCohort => currentPatch%shortest
currentCohort => currentPatch%shortest
do while (associated(currentCohort))

terminate = 0
Expand Down Expand Up @@ -525,30 +525,30 @@ subroutine terminate_cohorts( currentSite, currentPatch, level )
currentSite%root_litter_diagnostic_input_carbonflux(currentCohort%pft) + &
currentCohort%n * (currentCohort%br+currentCohort%bstore) * hlm_days_per_year / AREA


! Set pointers and remove the current cohort from the list

shorterCohort => currentCohort%shorter

if (.not. associated(tallerCohort)) then
currentPatch%tallest => shorterCohort
if(associated(shorterCohort)) shorterCohort%taller => null()
else
tallerCohort%shorter => shorterCohort
endif

if (.not. associated(shorterCohort)) then
currentPatch%shortest => tallerCohort
if(associated(tallerCohort)) tallerCohort%shorter => null()
else
shorterCohort%taller => tallerCohort
endif

! At this point, nothing should be pointing to current Cohort
if (hlm_use_planthydro.eq.itrue) call DeallocateHydrCohort(currentCohort)
deallocate(currentCohort)

end if

! Set pointers and remove the current cohort from the list
shorterCohort => currentCohort%shorter

if (.not. associated(tallerCohort)) then
currentPatch%tallest => shorterCohort
if(associated(shorterCohort)) shorterCohort%taller => null()
else
tallerCohort%shorter => shorterCohort
endif

if (.not. associated(shorterCohort)) then
currentPatch%shortest => tallerCohort
if(associated(tallerCohort)) tallerCohort%shorter => null()
else
shorterCohort%taller => tallerCohort
endif

! At this point, nothing should be pointing to current Cohort
if (hlm_use_planthydro.eq.itrue) call DeallocateHydrCohort(currentCohort)
deallocate(currentCohort)
nullify(currentCohort)

endif
currentCohort => tallerCohort
enddo
Expand Down Expand Up @@ -624,7 +624,7 @@ subroutine fuse_cohorts(currentPatch, bc_in)
nextc => currentPatch%tallest

do while (associated(nextc))
nextnextc => nextc%shorter
nextnextc => nextc%shorter
diff = abs((currentCohort%dbh - nextc%dbh)/(0.5*(currentCohort%dbh + nextc%dbh)))

!Criteria used to divide up the height continuum into different cohorts.
Expand Down Expand Up @@ -843,7 +843,7 @@ subroutine fuse_cohorts(currentPatch, bc_in)
! At this point, nothing should be pointing to current Cohort
if (hlm_use_planthydro.eq.itrue) call DeallocateHydrCohort(nextc)
deallocate(nextc)

nullify(nextc)

endif ! if( currentCohort%isnew.eqv.nextc%isnew ) then
endif !canopy layer
Expand Down
45 changes: 17 additions & 28 deletions biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1690,12 +1690,6 @@ subroutine terminate_patches(currentSite)
! !DESCRIPTION:
! Terminate Patches if they are too small
!
! Note that we are not going to apply this to the youngest patch
! We do this because the youngest patches are constantly being created
! and fused with other new patches each day, each with small areas. If we
! terminate them immediately, then we will constantly be culling off
! these new areas before they can contribute to the pool.
! This is really intended for older, established patches.
!
! !ARGUMENTS:
type(ed_site_type), target, intent(inout) :: currentSite
Expand All @@ -1709,41 +1703,36 @@ subroutine terminate_patches(currentSite)
!---------------------------------------------------------------------

currentPatch => currentSite%youngest_patch
if(associated(currentPatch%older)) then


! We ignore the youngest patch, immediately go to the next
! If it is not associated (DNE..) then we are done.

currentPatch => currentPatch%older
do while(associated(currentPatch))
do while(associated(currentPatch))

if(currentPatch%area <= min_patch_area)then

if(currentPatch%area <= min_patch_area)then
if ( .not.associated(currentPatch,currentSite%youngest_patch) ) then

if(associated(currentPatch%older) )then

if(debug) &
write(fates_log(),*) 'fusing to older patch because this one is too small',&
currentPatch%area, &
currentPatch%older%area

! We set a pointer to this patch, because
! it will be returned by the subtoutine as de-referenced

! it will be returned by the subroutine as de-referenced
olderPatch => currentPatch%older
call fuse_2_patches(currentSite, olderPatch, currentPatch)

! The fusion process has updated the "older" pointer on currentPatch
! for us.

! This logic checks to make sure that the younger patch is not the youngest
! patch. As mentioned earlier, we try not to fuse it.

elseif( .not. associated(currentPatch%younger,currentSite%youngest_patch) ) then

if(debug) &
write(fates_log(),*) 'fusing to younger patch because oldest one is too small', &
currentPatch%area
write(fates_log(),*) 'fusing to younger patch because oldest one is too small', &
currentPatch%area

youngerPatch => currentPatch%younger
call fuse_2_patches(currentSite, youngerPatch, currentPatch)
Expand All @@ -1752,12 +1741,12 @@ subroutine terminate_patches(currentSite)

endif
endif
endif

currentPatch => currentPatch%older

enddo
end if

currentPatch => currentPatch%older

enddo

!check area is not exceeded
areatot = 0._r8
currentPatch => currentSite%oldest_patch
Expand Down

0 comments on commit f25e25d

Please sign in to comment.