@@ -805,6 +805,7 @@ subroutine set_inventory_edcohort_type1(csite,bc_in,css_file_unit,npatches, &
805805 real (r8 ) :: b_dead
806806 real (r8 ) :: b_store
807807 real (r8 ) :: a_sapwood ! area of sapwood at reference height [m2]
808+ integer :: i_pft, ncohorts_to_create
808809
809810
810811 character (len= 128 ),parameter :: wr_fmt = &
@@ -853,9 +854,9 @@ subroutine set_inventory_edcohort_type1(csite,bc_in,css_file_unit,npatches, &
853854 call endrun(msg= errMsg(sourcefile, __LINE__))
854855 end if
855856
856- if (c_pft <= 0 ) then
857+ if (c_pft < 0 ) then
857858 write (fates_log(), * ) ' inventory pft: ' ,c_pft
858- write (fates_log(), * ) ' The inventory produced a cohort with <= 0 pft index'
859+ write (fates_log(), * ) ' The inventory produced a cohort with <0 pft index'
859860 call endrun(msg= errMsg(sourcefile, __LINE__))
860861 end if
861862
@@ -882,62 +883,89 @@ subroutine set_inventory_edcohort_type1(csite,bc_in,css_file_unit,npatches, &
882883 write (fates_log(), * ) ' The inventory produced a cohort with very large density /m2'
883884 call endrun(msg= errMsg(sourcefile, __LINE__))
884885 end if
885-
886- allocate (temp_cohort) ! A temporary cohort is needed because we want to make
887- ! use of the allometry functions
888- ! Don't need to allocate leaf age classes (not used)
889886
890- temp_cohort% pft = c_pft
891- temp_cohort% n = c_nplant * cpatch% area
892- temp_cohort% dbh = c_dbh
893- call h_allom(c_dbh,c_pft,temp_cohort% hite)
894- temp_cohort% canopy_trim = 1.0_r8
887+ if (c_pft .eq. 0 ) then
888+ write (fates_log(), * ) ' inventory pft: ' ,c_pft
889+ write (fates_log(), * ) ' SPECIAL CASE TRIGGERED: PFT == 0 and therefore this subroutine'
890+ write (fates_log(), * ) ' will assign a cohort with n = n_orig/numpft to every cohort in range 1 to numpft'
891+ ncohorts_to_create = numpft
892+ else
893+ ncohorts_to_create = 1
894+ end if
895895
896- ! Calculate total above-ground biomass from allometry
896+ do i_pft = 1 ,ncohorts_to_create
897+ allocate (temp_cohort) ! A temporary cohort is needed because we want to make
898+ ! use of the allometry functions
899+ ! Don't need to allocate leaf age classes (not used)
897900
898- call bagw_allom(temp_cohort% dbh,c_pft,b_agw)
899- ! Calculate coarse root biomass from allometry
900- call bbgw_allom(temp_cohort% dbh,c_pft,b_bgw)
901-
902- ! Calculate the leaf biomass (calculates a maximum first, then applies canopy trim
903- ! and sla scaling factors)
904- call bleaf(temp_cohort% dbh,c_pft,temp_cohort% canopy_trim,b_leaf)
905-
906- ! Calculate fine root biomass
907- call bfineroot(temp_cohort% dbh,c_pft,temp_cohort% canopy_trim,b_fineroot)
908-
909- ! Calculate sapwood biomass
910- call bsap_allom(temp_cohort% dbh,c_pft,temp_cohort% canopy_trim, a_sapwood, b_sapwood)
911-
912- call bdead_allom( b_agw, b_bgw, b_sapwood, c_pft, b_dead )
913901
914- call bstore_allom(temp_cohort% dbh, c_pft, temp_cohort% canopy_trim, b_store)
915-
916- temp_cohort% laimemory = 0._r8
917- cstatus = leaves_on
918-
919- if ( EDPftvarcon_inst% season_decid(c_pft) == itrue .and. csite% is_cold ) then
920- temp_cohort% laimemory = b_leaf
921- b_leaf = 0._r8
922- cstatus = leaves_off
923- endif
924-
925- if ( EDPftvarcon_inst% stress_decid(c_pft) == itrue .and. csite% is_drought ) then
926- temp_cohort% laimemory = b_leaf
927- b_leaf = 0._r8
928- cstatus = leaves_off
929- endif
930-
931- ! Since spread is a canopy level calculation, we need to provide an initial guess here.
932- call create_cohort(csite, cpatch, c_pft, temp_cohort% n, temp_cohort% hite, temp_cohort% dbh, &
933- b_leaf, b_fineroot, b_sapwood, b_dead, b_store, &
934- temp_cohort% laimemory, cstatus, rstatus, temp_cohort% canopy_trim, &
935- 1 , csite% spread, equal_leaf_aclass, bc_in)
902+ if (c_pft .ne. 0 ) then
903+ ! normal case: assign each cohort to its specified PFT
904+ temp_cohort% pft = c_pft
905+ else
906+ ! special case, make an identical cohort for each PFT
907+ temp_cohort% pft = i_pft
908+ endif
936909
937-
938- deallocate (temp_cohort) ! get rid of temporary cohort
910+ temp_cohort% n = c_nplant * cpatch% area / real (ncohorts_to_create,r8 )
911+ temp_cohort% dbh = c_dbh
912+
913+ call h_allom(c_dbh,temp_cohort% pft,temp_cohort% hite)
914+ temp_cohort% canopy_trim = 1.0_r8
915+
916+ ! Calculate total above-ground biomass from allometry
917+
918+ call bagw_allom(temp_cohort% dbh,temp_cohort% pft,b_agw)
919+ ! Calculate coarse root biomass from allometry
920+ call bbgw_allom(temp_cohort% dbh,temp_cohort% pft,b_bgw)
921+
922+ ! Calculate the leaf biomass (calculates a maximum first, then applies canopy trim
923+ ! and sla scaling factors)
924+ call bleaf(temp_cohort% dbh,temp_cohort% pft,temp_cohort% canopy_trim,b_leaf)
925+
926+ ! Calculate fine root biomass
927+ call bfineroot(temp_cohort% dbh,temp_cohort% pft,temp_cohort% canopy_trim,b_fineroot)
928+
929+ ! Calculate sapwood biomass
930+ call bsap_allom(temp_cohort% dbh,temp_cohort% pft,temp_cohort% canopy_trim, a_sapwood, b_sapwood)
931+
932+ call bdead_allom( b_agw, b_bgw, b_sapwood, temp_cohort% pft, b_dead )
933+
934+ call bstore_allom(temp_cohort% dbh, temp_cohort% pft, temp_cohort% canopy_trim, b_store)
935+
936+ temp_cohort% laimemory = 0._r8
937+ cstatus = leaves_on
938+
939+ if ( EDPftvarcon_inst% season_decid(temp_cohort% pft) == itrue .and. csite% is_cold ) then
940+ temp_cohort% laimemory = b_leaf
941+ b_leaf = 0._r8
942+ cstatus = leaves_off
943+ endif
944+
945+ if ( EDPftvarcon_inst% stress_decid(temp_cohort% pft) == itrue .and. csite% is_drought ) then
946+ temp_cohort% laimemory = b_leaf
947+ b_leaf = 0._r8
948+ cstatus = leaves_off
949+ endif
950+
951+ ! Since spread is a canopy level calculation, we need to provide an initial guess here.
952+ if ( debug_inv) then
953+ write (fates_log(),* ) ' calling create_cohort: ' , temp_cohort% pft, temp_cohort% n, &
954+ temp_cohort% hite, temp_cohort% dbh, &
955+ b_leaf, b_fineroot, b_sapwood, b_dead, b_store, &
956+ temp_cohort% laimemory, cstatus, rstatus, temp_cohort% canopy_trim, &
957+ 1 , csite% spread
958+ endif
959+
960+ call create_cohort(csite, cpatch, temp_cohort% pft, temp_cohort% n, temp_cohort% hite, &
961+ temp_cohort% dbh, b_leaf, b_fineroot, b_sapwood, b_dead, b_store, &
962+ temp_cohort% laimemory, cstatus, rstatus, temp_cohort% canopy_trim, &
963+ 1 , csite% spread, equal_leaf_aclass, bc_in)
964+
965+ deallocate (temp_cohort) ! get rid of temporary cohort
966+ end do
939967
940968 return
941- end subroutine set_inventory_edcohort_type1
969+ end subroutine set_inventory_edcohort_type1
942970
943971end module FatesInventoryInitMod
0 commit comments