@@ -9,7 +9,7 @@ module EDPatchDynamicsMod
99 use EDPftvarcon , only : EDPftvarcon_inst
1010 use EDPftvarcon , only : GetDecompyFrac
1111 use PRTParametersMod , only : prt_params
12- use EDCohortDynamicsMod , only : fuse_cohorts, sort_cohorts, insert_cohort
12+ use EDCohortDynamicsMod , only : fuse_cohorts
1313 use EDTypesMod , only : area_site = > area
1414 use ChecksBalancesMod , only : PatchMassStock
1515 use FatesLitterMod , only : ncwd
@@ -516,17 +516,13 @@ subroutine spawn_patches( currentSite, bc_in)
516516 type (fates_patch_type) , pointer :: currentPatch
517517 type (fates_cohort_type), pointer :: currentCohort
518518 type (fates_cohort_type), pointer :: nc
519- type (fates_cohort_type), pointer :: storesmallcohort
520- type (fates_cohort_type), pointer :: storebigcohort
521519 real (r8 ) :: site_areadis_primary ! total area disturbed (to primary forest) in m2 per site per day
522520 real (r8 ) :: site_areadis_secondary ! total area disturbed (to secondary forest) in m2 per site per day
523521 real (r8 ) :: patch_site_areadis ! total area disturbed in m2 per patch per day
524522 real (r8 ) :: site_areadis ! total site area disturbed in m2 per day
525523 real (r8 ) :: age ! notional age of this patch in years
526524 integer :: el ! element loop index
527525 integer :: pft ! pft loop index
528- integer :: tnull ! is there a tallest cohort?
529- integer :: snull ! is there a shortest cohort?
530526 integer :: levcan ! canopy level
531527 real (r8 ) :: leaf_c ! leaf carbon [kg]
532528 real (r8 ) :: fnrt_c ! fineroot carbon [kg]
@@ -562,9 +558,6 @@ subroutine spawn_patches( currentSite, bc_in)
562558 logical :: buffer_patch_used
563559 !- --------------------------------------------------------------------
564560
565- storesmallcohort = > null () ! storage of the smallest cohort for insertion routine
566- storebigcohort = > null () ! storage of the largest cohort for insertion routine
567-
568561 if (hlm_use_nocomp .eq. itrue) then
569562 min_nocomp_pft = 0
570563 max_nocomp_pft = numpft
@@ -1249,30 +1242,7 @@ subroutine spawn_patches( currentSite, bc_in)
12491242 ! if some plants in the new temporary cohort survived the transfer to the new patch,
12501243 ! then put the cohort into the linked list.
12511244 cohort_n_gt_zero: if (nc% n > 0.0_r8 ) then
1252- storebigcohort = > newPatch% tallest
1253- storesmallcohort = > newPatch% shortest
1254- if (associated (newPatch% tallest))then
1255- tnull = 0
1256- else
1257- tnull = 1
1258- newPatch% tallest = > nc
1259- nc% taller = > null ()
1260- endif
1261-
1262- if (associated (newPatch% shortest))then
1263- snull = 0
1264- else
1265- snull = 1
1266- newPatch% shortest = > nc
1267- nc% shorter = > null ()
1268- endif
1269-
1270- call insert_cohort(newPatch, nc, newPatch% tallest, newPatch% shortest, &
1271- tnull, snull, storebigcohort, storesmallcohort)
1272-
1273- newPatch% tallest = > storebigcohort
1274- newPatch% shortest = > storesmallcohort
1275-
1245+ call newPatch% InsertCohort(nc)
12761246 else
12771247 ! sadly, no plants in the cohort survived. on the bright side, we can deallocate their memory.
12781248 call nc% FreeMemory()
@@ -1285,8 +1255,10 @@ subroutine spawn_patches( currentSite, bc_in)
12851255
12861256 currentCohort = > currentCohort% taller
12871257 enddo cohortloop
1258+ call newPatch% ValidateCohorts()
12881259
1289- call sort_cohorts(currentPatch)
1260+ call currentPatch% SortCohorts()
1261+ call currentPatch% ValidateCohorts()
12901262
12911263 ! update area of donor patch
12921264 oldarea = currentPatch% area
@@ -1317,7 +1289,8 @@ subroutine spawn_patches( currentSite, bc_in)
13171289 call terminate_cohorts(currentSite, currentPatch, 1 ,16 ,bc_in)
13181290 call fuse_cohorts(currentSite,currentPatch, bc_in)
13191291 call terminate_cohorts(currentSite, currentPatch, 2 ,16 ,bc_in)
1320- call sort_cohorts(currentPatch)
1292+ call currentPatch% SortCohorts()
1293+ call currentPatch% ValidateCohorts()
13211294
13221295 end if areadis_gt_zero_if ! if ( newPatch%area > nearzero ) then
13231296
@@ -1344,7 +1317,8 @@ subroutine spawn_patches( currentSite, bc_in)
13441317 call terminate_cohorts(currentSite, newPatch, 1 ,17 , bc_in)
13451318 call fuse_cohorts(currentSite,newPatch, bc_in)
13461319 call terminate_cohorts(currentSite, newPatch, 2 ,17 , bc_in)
1347- call sort_cohorts(newPatch)
1320+ call newPatch% SortCohorts()
1321+ call newPatch% ValidateCohorts()
13481322 endif
13491323
13501324
@@ -1675,11 +1649,7 @@ subroutine split_patch(currentSite, currentPatch, new_patch, fraction_to_keep, a
16751649 ! !LOCAL VARIABLES:
16761650 integer :: el ! element loop index
16771651 type (fates_cohort_type), pointer :: nc
1678- type (fates_cohort_type), pointer :: storesmallcohort
1679- type (fates_cohort_type), pointer :: storebigcohort
16801652 type (fates_cohort_type), pointer :: currentCohort
1681- integer :: tnull ! is there a tallest cohort?
1682- integer :: snull ! is there a shortest cohort?
16831653 integer :: pft
16841654 real (r8 ) :: temp_area
16851655
@@ -1746,34 +1716,14 @@ subroutine split_patch(currentSite, currentPatch, new_patch, fraction_to_keep, a
17461716 ! loss of individuals from source patch due to area shrinking
17471717 currentCohort% n = currentCohort% n * fraction_to_keep
17481718
1749- storebigcohort = > new_patch% tallest
1750- storesmallcohort = > new_patch% shortest
1751- if (associated (new_patch% tallest))then
1752- tnull = 0
1753- else
1754- tnull = 1
1755- new_patch% tallest = > nc
1756- nc% taller = > null ()
1757- endif
1758-
1759- if (associated (new_patch% shortest))then
1760- snull = 0
1761- else
1762- snull = 1
1763- new_patch% shortest = > nc
1764- nc% shorter = > null ()
1765- endif
1766-
1767- call insert_cohort(new_patch, nc, new_patch% tallest, new_patch% shortest, &
1768- tnull, snull, storebigcohort, storesmallcohort)
1769-
1770- new_patch% tallest = > storebigcohort
1771- new_patch% shortest = > storesmallcohort
1719+ call new_patch% InsertCohort(nc)
17721720
17731721 currentCohort = > currentCohort% taller
17741722 enddo ! currentCohort
1723+ call new_patch% ValidateCohorts()
17751724
1776- call sort_cohorts(currentPatch)
1725+ call currentPatch% SortCohorts()
1726+ call currentPatch% ValidateCohorts()
17771727
17781728 ! update area of donor patch
17791729 currentPatch% area = currentPatch% area - temp_area
@@ -3116,7 +3066,8 @@ subroutine fuse_patches( csite, bc_in )
31163066 tmpptr = > currentPatch% older
31173067 call fuse_2_patches(csite, currentPatch, tpp)
31183068 call fuse_cohorts(csite,tpp, bc_in)
3119- call sort_cohorts(tpp)
3069+ call tpp% SortCohorts()
3070+ call tpp% ValidateCohorts()
31203071 currentPatch = > tmpptr
31213072
31223073 !- -----------------------------------------------------------------------!
@@ -3238,10 +3189,7 @@ subroutine fuse_2_patches(csite, dp, rp)
32383189 ! !LOCAL VARIABLES:
32393190 type (fates_cohort_type), pointer :: currentCohort ! Current Cohort
32403191 type (fates_cohort_type), pointer :: nextc ! Remembers next cohort in list
3241- type (fates_cohort_type), pointer :: storesmallcohort
3242- type (fates_cohort_type), pointer :: storebigcohort
32433192 integer :: c,p ! counters for pft and litter size class.
3244- integer :: tnull,snull ! are the tallest and shortest cohorts associated?
32453193 integer :: el ! loop counting index for elements
32463194 integer :: pft ! loop counter for pfts
32473195 type (fates_patch_type), pointer :: youngerp ! pointer to the patch younger than donor
@@ -3321,31 +3269,8 @@ subroutine fuse_2_patches(csite, dp, rp)
33213269 endif
33223270
33233271 do while (associated (dp% shortest))
3324-
3325- storebigcohort = > rp% tallest
3326- storesmallcohort = > rp% shortest
3327-
3328- if (associated (rp% tallest))then
3329- tnull = 0
3330- else
3331- tnull = 1
3332- rp% tallest = > currentCohort
3333- endif
3334-
3335- if (associated (rp% shortest))then
3336- snull = 0
3337- else
3338- snull = 1
3339- rp% shortest = > currentCohort
3340- endif
3341-
3342- call insert_cohort(rp, currentCohort, rp% tallest, rp% shortest, &
3343- tnull, snull, storebigcohort, storesmallcohort)
3344-
3345- rp% tallest = > storebigcohort
3346- rp% shortest = > storesmallcohort
3347-
3348- ! currentCohort%patchptr => rp
3272+
3273+ call rp% InsertCohort(currentCohort)
33493274
33503275 currentCohort = > nextc
33513276
@@ -3356,6 +3281,7 @@ subroutine fuse_2_patches(csite, dp, rp)
33563281 endif
33573282
33583283 enddo ! cohort
3284+ call rp% ValidateCohorts()
33593285 endif ! are there any cohorts?
33603286
33613287 call patch_pft_size_profile(rp) ! Recalculate the patch size profile for the resulting patch
0 commit comments