From 0bef1673da218368750b1759100f160661d54f55 Mon Sep 17 00:00:00 2001
From: Jessica F Needham <need138@compy-e.pnl.gov>
Date: Fri, 14 Oct 2022 17:19:51 -0700
Subject: [PATCH 1/8] Add two new history variables - aboveground woody
 mortality and aboveground woody productivity for comparison of FATES with
 forest plot data.

---
 biogeochem/EDCohortDynamicsMod.F90 |  5 ++++
 biogeochem/EDPatchDynamicsMod.F90  | 14 +++++++++
 main/EDInitMod.F90                 |  8 +++++
 main/EDTypesMod.F90                |  5 ++++
 main/FatesHistoryInterfaceMod.F90  | 47 ++++++++++++++++++++++++++++++
 main/FatesRestartInterfaceMod.F90  | 41 +++++++++++++++++++++++---
 6 files changed, 116 insertions(+), 4 deletions(-)

diff --git a/biogeochem/EDCohortDynamicsMod.F90 b/biogeochem/EDCohortDynamicsMod.F90
index 2d796a9048..b1f4b98b44 100644
--- a/biogeochem/EDCohortDynamicsMod.F90
+++ b/biogeochem/EDCohortDynamicsMod.F90
@@ -864,6 +864,11 @@ subroutine terminate_cohort(currentSite, currentPatch, currentCohort, bc_in)
             currentCohort%n * (struct_c+sapw_c+leaf_c+fnrt_c+store_c+repro_c)
    end if
 
+   currentSite%term_bagw_flux(currentCohort%size_class, currentCohort%pft) = &
+        currentSite%term_bagw_flux(currentCohort%size_class, currentCohort%pft) + &
+        currentCohort%n * (struct_c+sapw_c)
+  
+
    ! put the litter from the terminated cohorts
    ! straight into the fragmenting pools
 
diff --git a/biogeochem/EDPatchDynamicsMod.F90 b/biogeochem/EDPatchDynamicsMod.F90
index 141aaad52e..c67a42b0ba 100644
--- a/biogeochem/EDPatchDynamicsMod.F90
+++ b/biogeochem/EDPatchDynamicsMod.F90
@@ -722,6 +722,13 @@ subroutine spawn_patches( currentSite, bc_in)
                                        (nc%n * ED_val_understorey_death / hlm_freq_day ) * &
                                        total_c * g_per_kg * days_per_sec * years_per_day * ha_per_m2
 
+                                  currentSite%imort_bagw_flux(currentCohort%size_class, currentCohort%pft) = &
+                                       currentSite%imort_bagw_flux(currentCohort%size_class, currentCohort%pft) + &
+                                       (nc%n * ED_val_understorey_death / hlm_freq_day ) * &
+                                       (sapw_c + struct_c) * prt_params%allom_agb_frac(currentCohort%pft) * &
+                                       g_per_kg * days_per_sec * years_per_day * ha_per_m2
+
+
                                   ! Step 2:  Apply survivor ship function based on the understory death fraction
                                   ! remaining of understory plants of those that are knocked over
                                   ! by the overstorey trees dying...
@@ -810,6 +817,13 @@ subroutine spawn_patches( currentSite, bc_in)
                                     total_c * g_per_kg * days_per_sec * ha_per_m2
                             end if
 
+                            currentSite%fmort_bagw_flux(currentCohort%size_class, currentCohort%pft) = &
+                                 currentSite%fmort_bagw_flux(currentCohort%size_class, currentCohort%pft) + &
+                                 (nc%n * currentCohort%fire_mort) * &
+                                 (sapw_c + struct_c) * prt_params%allom_agb_frac(currentCohort%pft) * &
+                                 g_per_kg * days_per_sec * ha_per_m2
+                            
+
                             currentSite%fmort_rate_cambial(currentCohort%size_class, currentCohort%pft) = &
                                  currentSite%fmort_rate_cambial(currentCohort%size_class, currentCohort%pft) + &
                                  nc%n * currentCohort%cambial_mort / hlm_freq_day
diff --git a/main/EDInitMod.F90 b/main/EDInitMod.F90
index d3177ca72a..fb7bc67219 100644
--- a/main/EDInitMod.F90
+++ b/main/EDInitMod.F90
@@ -135,6 +135,10 @@ subroutine init_site_vars( site_in, bc_in, bc_out )
     allocate(site_in%fmort_carbonflux_canopy(1:numpft))
     allocate(site_in%fmort_carbonflux_ustory(1:numpft))
     
+    allocate(site_in%term_bagw_flux(1:nlevsclass,1:numpft))
+    allocate(site_in%imort_bagw_flux(1:nlevsclass,1:numpft))
+    allocate(site_in%fmort_bagw_flux(1:nlevsclass,1:numpft))
+    
     site_in%nlevsoil   = bc_in%nlevsoil
     allocate(site_in%rootfrac_scr(site_in%nlevsoil))
     allocate(site_in%zi_soil(0:site_in%nlevsoil))
@@ -245,6 +249,10 @@ subroutine zero_site( site_in )
     site_in%fmort_carbonflux_ustory(:) = 0._r8
     site_in%fmort_rate_cambial(:,:) = 0._r8
     site_in%fmort_rate_crown(:,:) = 0._r8
+    site_in%term_bagw_flux(:,:) = 0._r8
+    site_in%imort_bagw_flux(:,:) = 0._r8
+    site_in%fmort_bagw_flux(:,:) = 0._r8
+
 
     ! fusoin-induced growth flux of individuals
     site_in%growthflux_fusion(:,:) = 0._r8
diff --git a/main/EDTypesMod.F90 b/main/EDTypesMod.F90
index 86bb36e31e..de5d87051d 100644
--- a/main/EDTypesMod.F90
+++ b/main/EDTypesMod.F90
@@ -796,6 +796,11 @@ module EDTypesMod
      real(r8), allocatable :: fmort_carbonflux_canopy(:) ! biomass of canopy indivs killed due to fire per year. [gC/m2/sec]
      real(r8), allocatable :: fmort_carbonflux_ustory(:) ! biomass of understory indivs killed due to fire per year [gC/m2/sec] 
 
+     real(r8), allocatable :: term_bagw_flux(:,:)          ! aboveground woody biomass lost due to termination mortality x size x pft
+     real(r8), allocatable :: imort_bagw_flux(:,:)         ! aboveground woody biomass lost due to impact mortality x size x pft
+     real(r8), allocatable :: fmort_bagw_flux(:,:)         ! aboveground woody biomass lost due to fire mortality x size x pft
+
+
      real(r8) :: demotion_carbonflux                     ! biomass of demoted individuals from canopy to understory [kgC/ha/day]
      real(r8) :: promotion_carbonflux                    ! biomass of promoted individuals from understory to canopy [kgC/ha/day]
      real(r8) :: recruitment_rate(1:maxpft)              ! number of individuals that were recruited into new cohorts
diff --git a/main/FatesHistoryInterfaceMod.F90 b/main/FatesHistoryInterfaceMod.F90
index 391d5f87d9..5af9512088 100644
--- a/main/FatesHistoryInterfaceMod.F90
+++ b/main/FatesHistoryInterfaceMod.F90
@@ -417,6 +417,9 @@ module FatesHistoryInterfaceMod
   integer :: ih_crownfiremort_si_scpf
   integer :: ih_cambialfiremort_si_scpf
 
+  integer :: ih_bagw_mortality_si_scpf
+  integer :: ih_bagw_productivity_si_scpf
+
   integer :: ih_m10_si_capf
   integer :: ih_nplant_si_capf
 
@@ -1923,6 +1926,9 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                hio_crownfiremort_si_scpf     => this%hvars(ih_crownfiremort_si_scpf)%r82d, &
                hio_cambialfiremort_si_scpf   => this%hvars(ih_cambialfiremort_si_scpf)%r82d, &
 
+               hio_bagw_mortality_si_scpf    => this%hvars(ih_bagw_mortality_si_scpf)%r82d, &
+               hio_bagw_productivity_si_scpf => this%hvars(ih_bagw_productivity_si_scpf)%r82d, &
+               
                hio_fire_c_to_atm_si  => this%hvars(ih_fire_c_to_atm_si)%r81d, &
                hio_burn_flux_elem    => this%hvars(ih_burn_flux_elem)%r82d, &
 
@@ -2534,6 +2540,10 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                hio_npp_stor_si_scpf(io_si,scpf) = hio_npp_stor_si_scpf(io_si,scpf) + &
                   store_m_net_alloc*n_perm2 / days_per_year / sec_per_day
 
+               hio_bagw_productivity_si_scpf(io_si,scpf) = hio_bagw_productivity_si_scpf(io_si,scpf) + &
+                    (sapw_m_net_alloc + struct_m_net_alloc) * n_perm2 * (prt_params%allom_agb_frac(ccohort%pft)) / &
+                  days_per_year / sec_per_day
+
                ! Woody State Variables (basal area growth increment)
                if ( prt_params%woody(ft) == itrue) then
 
@@ -2584,6 +2594,17 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                      ccohort%asmort*ccohort%n / m2_per_ha
                end if
 
+               hio_bagw_mortality_si_scpf(io_si,scpf) = hio_bagw_mortality_si_scpf(io_si,scpf) + &
+                    (ccohort%bmort + ccohort%hmort + ccohort%cmort + &
+                    ccohort%frmort + ccohort%smort + ccohort%asmort) * &
+                    (sapw_m + struct_m) * prt_params%allom_agb_frac(ccohort%pft) * &
+                    ccohort%n * days_per_sec * years_per_day * ha_per_m2 + &
+                    (ccohort%lmort_direct + ccohort%lmort_collateral + ccohort%lmort_infra) * &
+                    (sapw_m + struct_m) * prt_params%allom_agb_frac(ccohort%pft) * &
+                    ccohort%n * ha_per_m2
+
+
+
                hio_m1_si_scls(io_si,scls) = hio_m1_si_scls(io_si,scls) + ccohort%bmort*ccohort%n / m2_per_ha
                hio_m2_si_scls(io_si,scls) = hio_m2_si_scls(io_si,scls) + ccohort%hmort*ccohort%n / m2_per_ha
                hio_m3_si_scls(io_si,scls) = hio_m3_si_scls(io_si,scls) + ccohort%cmort*ccohort%n / m2_per_ha
@@ -3094,6 +3115,17 @@ subroutine update_history_dyn(this,nc,nsites,sites)
          hio_firemortality_carbonflux_si_pft(io_si,i_pft) = sites(s)%fmort_carbonflux_canopy(i_pft) / g_per_kg
       end do
 
+      ! add imort and fmort to aboveground woody mortality 
+      do i_pft = 1, numpft
+         do i_scls = 1,nlevsclass
+            i_scpf = (i_pft-1)*nlevsclass + i_scls
+            hio_bagw_mortality_si_scpf(io_si,i_scpf) = hio_bagw_mortality_si_scpf(io_si,i_scpf) + &
+                 (sites(s)%fmort_bagw_flux(i_scls,i_pft) / g_per_kg ) + &
+                 (sites(s)%imort_bagw_flux(i_scls,i_pft)  / g_per_kg) + &
+                 (sites(s)%term_bagw_flux(i_scls,i_pft)  * days_per_sec * ha_per_m2 ) ! jfn
+         end do
+      end do
+
       sites(s)%term_nindivs_canopy(:,:) = 0._r8
       sites(s)%term_nindivs_ustory(:,:) = 0._r8
       sites(s)%imort_carbonflux(:) = 0._r8
@@ -3105,6 +3137,9 @@ subroutine update_history_dyn(this,nc,nsites,sites)
       sites(s)%fmort_rate_cambial(:,:) = 0._r8
       sites(s)%fmort_rate_crown(:,:) = 0._r8
       sites(s)%growthflux_fusion(:,:) = 0._r8
+      sites(s)%fmort_bagw_flux(:,:) = 0._r8
+      sites(s)%imort_bagw_flux(:,:) = 0._r8
+      sites(s)%term_bagw_flux(:,:) = 0._r8
 
       ! pass the recruitment rate as a flux to the history, and then reset the recruitment buffer
       do i_pft = 1, numpft
@@ -5563,6 +5598,18 @@ subroutine define_history_vars(this, initialize_variables)
          upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
          index=ih_cstarvmortality_carbonflux_si_pft)
 
+    call this%set_history_var(vname='FATES_ABOVEGROUND_MORTALITY_SZPF', units='kg m-2 s-1',    &
+         long='Aboveground woody flux of carbon from AGB to necromass due to mortality', &
+         use_default='inactive', avgflag='A', vtype=site_size_pft_r8, hlms='CLM:ALM', &
+         upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
+         index=ih_bagw_mortality_si_scpf)
+
+    call this%set_history_var(vname='FATES_ABOVEGROUND_PRODUCTIVITY_SZPF', units='kg m-2 s-1',    &
+         long='Aboveground woody carbon productivity', &
+         use_default='inactive', avgflag='A', vtype=site_size_pft_r8, hlms='CLM:ALM', &
+         upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
+         index=ih_bagw_productivity_si_scpf)
+
     ! size class by age dimensioned variables
 
     call this%set_history_var(vname='FATES_NPLANT_SZAP', units = 'm-2',        &
diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90
index d17759220a..e028b8ab23 100644
--- a/main/FatesRestartInterfaceMod.F90
+++ b/main/FatesRestartInterfaceMod.F90
@@ -211,6 +211,9 @@ module FatesRestartInterfaceMod
   integer :: ir_imortcflux_sipft
   integer :: ir_fmortcflux_cano_sipft
   integer :: ir_fmortcflux_usto_sipft
+  integer :: ir_bagw_term_flux_siscpf
+  integer :: ir_bagw_imort_flux_siscpf
+  integer :: ir_bagw_fmort_flux_siscpf
   integer :: ir_cwdagin_flxdg
   integer :: ir_cwdbgin_flxdg
   integer :: ir_leaflittin_flxdg
@@ -1246,7 +1249,22 @@ subroutine define_restart_vars(this, initialize_variables)
    call this%set_restart_var(vname='fates_termcflux_ustory', vtype=cohort_r8, &
          long_name='fates diagnostic term carbon flux understory', &
          units='', flushval = flushzero, &
-         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index =   ir_termcflux_usto_sipft )
+         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_termcflux_usto_sipft )
+
+   call this%set_restart_var(vname='fates_bagw_term_flux', vtype=cohort_r8, &
+         long_name='fates aboveground biomass loss from termination mortality', &
+         units='', flushval = flushzero, &
+         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_bagw_term_flux_siscpf )
+
+   call this%set_restart_var(vname='fates_bagw_imort_flux', vtype=cohort_r8, &
+         long_name='fates aboveground biomass loss from impact mortality', &
+         units='', flushval = flushzero, &
+         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_bagw_imort_flux_siscpf )
+
+   call this%set_restart_var(vname='fates_bagw_fmort_flux', vtype=cohort_r8, &
+         long_name='fates aboveground biomass loss from fire mortality', &
+         units='', flushval = flushzero, &
+         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_bagw_fmort_flux_siscpf )
 
    call this%set_restart_var(vname='fates_democflux', vtype=site_r8, &
          long_name='fates diagnostic demotion carbon flux', &
@@ -1825,8 +1843,11 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
            rio_promcflux_si            => this%rvars(ir_promcflux_si)%r81d, &
            rio_imortcflux_sipft        => this%rvars(ir_imortcflux_sipft)%r81d, &
            rio_fmortcflux_cano_sipft   => this%rvars(ir_fmortcflux_cano_sipft)%r81d, &
-           rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d)
-
+           rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d, &
+           rio_bagw_imort_flux_siscpf => this%rvars(ir_bagw_imort_flux_siscpf)%r81d, &
+           rio_bagw_fmort_flux_siscpf => this%rvars(ir_bagw_fmort_flux_siscpf)%r81d, &
+           rio_bagw_term_flux_siscpf  => this%rvars(ir_bagw_term_flux_siscpf)%r81d )
+           
 
        totalCohorts = 0
 
@@ -2199,6 +2220,10 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
                 rio_termnindiv_usto_siscpf(io_idx_si_scpf) = sites(s)%term_nindivs_ustory(i_scls,i_pft)
                 rio_growflx_fusion_siscpf(io_idx_si_scpf)  = sites(s)%growthflux_fusion(i_scls, i_pft)
 
+                rio_bagw_term_flux_siscpf(io_idx_si_scpf) = sites(s)%term_bagw_flux(i_scls, i_pft)
+                rio_bagw_imort_flux_siscpf(io_idx_si_scpf) = sites(s)%imort_bagw_flux(i_scls, i_pft)
+                rio_bagw_fmort_flux_siscpf(io_idx_si_scpf) = sites(s)%fmort_bagw_flux(i_scls, i_pft)
+
                 io_idx_si_scpf = io_idx_si_scpf + 1
              end do
 
@@ -2658,7 +2683,10 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
           rio_promcflux_si            => this%rvars(ir_promcflux_si)%r81d, &
           rio_imortcflux_sipft        => this%rvars(ir_imortcflux_sipft)%r81d, &
           rio_fmortcflux_cano_sipft   => this%rvars(ir_fmortcflux_cano_sipft)%r81d, &
-          rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d)
+          rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d, &
+          rio_bagw_term_flux_siscpf   => this%rvars(ir_bagw_term_flux_siscpf)%r81d, &
+          rio_bagw_imort_flux_siscpf  => this%rvars(ir_bagw_imort_flux_siscpf)%r81d, &
+          rio_bagw_fmort_flux_siscpf  => this%rvars(ir_bagw_fmort_flux_siscpf)%r81d )
 
 
        totalcohorts = 0
@@ -3068,6 +3096,11 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
                 sites(s)%term_nindivs_canopy(i_scls,i_pft) = rio_termnindiv_cano_siscpf(io_idx_si_scpf)
                 sites(s)%term_nindivs_ustory(i_scls,i_pft) = rio_termnindiv_usto_siscpf(io_idx_si_scpf)
                 sites(s)%growthflux_fusion(i_scls, i_pft)  = rio_growflx_fusion_siscpf(io_idx_si_scpf)
+
+                sites(s)%term_bagw_flux(i_scls,i_pft) = rio_bagw_term_flux_siscpf(io_idx_si_scpf)
+                sites(s)%imort_bagw_flux(i_scls,i_pft) = rio_bagw_imort_flux_siscpf(io_idx_si_scpf)
+                sites(s)%fmort_bagw_flux(i_scls,i_pft) = rio_bagw_fmort_flux_siscpf(io_idx_si_scpf)
+
                 io_idx_si_scpf = io_idx_si_scpf + 1
              end do
 

From f8910dc39279a685c9e1c4e42c704cd05dc69d7c Mon Sep 17 00:00:00 2001
From: Jessica Needham <jessiefneedham@gmail.com>
Date: Tue, 18 Oct 2022 16:42:44 -0700
Subject: [PATCH 2/8] [ Shorten history names - too many characters was causing
 an error ]

[ Change aboveground to agw (aboveground woody) in history variable
names ]

Fixes: [NGT-ED Github issue #]

User interface changes?: [Yes (describe what changes), No]

Code review: [Names]

Test suite: [suite name, machine, compilers]
Test baseline:
Test namelist changes:
Test answer changes: [bit for bit, roundoff, climate changing]
Test summary:no testing
---
 main/FatesHistoryInterfaceMod.F90 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/main/FatesHistoryInterfaceMod.F90 b/main/FatesHistoryInterfaceMod.F90
index 5af9512088..6457c2ac5d 100644
--- a/main/FatesHistoryInterfaceMod.F90
+++ b/main/FatesHistoryInterfaceMod.F90
@@ -5598,18 +5598,18 @@ subroutine define_history_vars(this, initialize_variables)
          upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
          index=ih_cstarvmortality_carbonflux_si_pft)
 
-    call this%set_history_var(vname='FATES_ABOVEGROUND_MORTALITY_SZPF', units='kg m-2 s-1',    &
+    call this%set_history_var(vname='FATES_AGW_MORTALITY_SZPF', units='kg m-2 s-1',    &
          long='Aboveground woody flux of carbon from AGB to necromass due to mortality', &
          use_default='inactive', avgflag='A', vtype=site_size_pft_r8, hlms='CLM:ALM', &
          upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
          index=ih_bagw_mortality_si_scpf)
 
-    call this%set_history_var(vname='FATES_ABOVEGROUND_PRODUCTIVITY_SZPF', units='kg m-2 s-1',    &
+    call this%set_history_var(vname='FATES_AGW_PRODUCTIVITY_SZPF', units='kg m-2 s-1',    &
          long='Aboveground woody carbon productivity', &
          use_default='inactive', avgflag='A', vtype=site_size_pft_r8, hlms='CLM:ALM', &
          upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
          index=ih_bagw_productivity_si_scpf)
-
+    
     ! size class by age dimensioned variables
 
     call this%set_history_var(vname='FATES_NPLANT_SZAP', units = 'm-2',        &

From f972400a4a1313e18132780e3196e18ad263c576 Mon Sep 17 00:00:00 2001
From: Jessica Needham <jessiefneedham@gmail.com>
Date: Fri, 21 Oct 2022 10:38:21 -0700
Subject: [PATCH 3/8] [ Tidy up names, add leaves ]

[ Since AWM and AWP are fluxes of AGB, and AGB includes leaves,
add leaves to AWP and AWM calculations. Tidy up names as a result
of this change.  ]

Fixes: [NGT-ED Github issue #]

User interface changes?: [Yes (describe what changes), No]

Code review: [Names]

Test suite: [suite name, machine, compilers]
Test baseline:
Test namelist changes:
Test answer changes: [bit for bit, roundoff, climate changing]
Test summary: no testing
---
 biogeochem/EDCohortDynamicsMod.F90 |  7 +--
 biogeochem/EDPatchDynamicsMod.F90  | 16 ++++---
 main/EDInitMod.F90                 | 12 +++---
 main/EDTypesMod.F90                |  6 +--
 main/FatesHistoryInterfaceMod.F90  | 68 +++++++++++++++++-------------
 main/FatesRestartInterfaceMod.F90  | 42 +++++++++---------
 6 files changed, 82 insertions(+), 69 deletions(-)

diff --git a/biogeochem/EDCohortDynamicsMod.F90 b/biogeochem/EDCohortDynamicsMod.F90
index b1f4b98b44..121c902616 100644
--- a/biogeochem/EDCohortDynamicsMod.F90
+++ b/biogeochem/EDCohortDynamicsMod.F90
@@ -864,9 +864,10 @@ subroutine terminate_cohort(currentSite, currentPatch, currentCohort, bc_in)
             currentCohort%n * (struct_c+sapw_c+leaf_c+fnrt_c+store_c+repro_c)
    end if
 
-   currentSite%term_bagw_flux(currentCohort%size_class, currentCohort%pft) = &
-        currentSite%term_bagw_flux(currentCohort%size_class, currentCohort%pft) + &
-        currentCohort%n * (struct_c+sapw_c)
+   currentSite%term_abg_flux(currentCohort%size_class, currentCohort%pft) = &
+        currentSite%term_abg_flux(currentCohort%size_class, currentCohort%pft) + &
+        currentCohort%n * ( (struct_c+sapw_c+store_c) * prt_params%allom_agb_frac(currentCohort%pft) + &
+        leaf_c )
   
 
    ! put the litter from the terminated cohorts
diff --git a/biogeochem/EDPatchDynamicsMod.F90 b/biogeochem/EDPatchDynamicsMod.F90
index c67a42b0ba..0e2d618ceb 100644
--- a/biogeochem/EDPatchDynamicsMod.F90
+++ b/biogeochem/EDPatchDynamicsMod.F90
@@ -399,6 +399,7 @@ subroutine spawn_patches( currentSite, bc_in)
     real(r8) :: sapw_c                       ! sapwood carbon [kg]
     real(r8) :: store_c                      ! storage carbon [kg]
     real(r8) :: struct_c                     ! structure carbon [kg]
+    real(r8) :: repro_c                      ! reproductive carbon [kg]
     real(r8) :: total_c                      ! total carbon of plant [kg]
     real(r8) :: leaf_burn_frac               ! fraction of leaves burned in fire
                                              ! for both woody and grass species
@@ -662,6 +663,7 @@ subroutine spawn_patches( currentSite, bc_in)
                          leaf_c   = currentCohort%prt%GetState(leaf_organ, all_carbon_elements)
                          fnrt_c   = currentCohort%prt%GetState(fnrt_organ, all_carbon_elements)
                          store_c  = currentCohort%prt%GetState(store_organ, all_carbon_elements)
+                         repro_c  = currentCohort%prt%GetState(repro_organ, all_carbon_elements)
                          total_c  = sapw_c + struct_c + leaf_c + fnrt_c + store_c
 
                          ! treefall mortality is the current disturbance
@@ -722,10 +724,11 @@ subroutine spawn_patches( currentSite, bc_in)
                                        (nc%n * ED_val_understorey_death / hlm_freq_day ) * &
                                        total_c * g_per_kg * days_per_sec * years_per_day * ha_per_m2
 
-                                  currentSite%imort_bagw_flux(currentCohort%size_class, currentCohort%pft) = &
-                                       currentSite%imort_bagw_flux(currentCohort%size_class, currentCohort%pft) + &
+                                  currentSite%imort_abg_flux(currentCohort%size_class, currentCohort%pft) = &
+                                       currentSite%imort_abg_flux(currentCohort%size_class, currentCohort%pft) + &
                                        (nc%n * ED_val_understorey_death / hlm_freq_day ) * &
-                                       (sapw_c + struct_c) * prt_params%allom_agb_frac(currentCohort%pft) * &
+                                       ( (sapw_c + struct_c + store_c) * prt_params%allom_agb_frac(currentCohort%pft) + &
+                                       leaf_c ) * &
                                        g_per_kg * days_per_sec * years_per_day * ha_per_m2
 
 
@@ -817,10 +820,11 @@ subroutine spawn_patches( currentSite, bc_in)
                                     total_c * g_per_kg * days_per_sec * ha_per_m2
                             end if
 
-                            currentSite%fmort_bagw_flux(currentCohort%size_class, currentCohort%pft) = &
-                                 currentSite%fmort_bagw_flux(currentCohort%size_class, currentCohort%pft) + &
+                            currentSite%fmort_abg_flux(currentCohort%size_class, currentCohort%pft) = &
+                                 currentSite%fmort_abg_flux(currentCohort%size_class, currentCohort%pft) + &
                                  (nc%n * currentCohort%fire_mort) * &
-                                 (sapw_c + struct_c) * prt_params%allom_agb_frac(currentCohort%pft) * &
+                                 ( (sapw_c + struct_c + store_c) * prt_params%allom_agb_frac(currentCohort%pft) + &
+                                 leaf_c ) * &
                                  g_per_kg * days_per_sec * ha_per_m2
                             
 
diff --git a/main/EDInitMod.F90 b/main/EDInitMod.F90
index fb7bc67219..5a72c854e1 100644
--- a/main/EDInitMod.F90
+++ b/main/EDInitMod.F90
@@ -135,9 +135,9 @@ subroutine init_site_vars( site_in, bc_in, bc_out )
     allocate(site_in%fmort_carbonflux_canopy(1:numpft))
     allocate(site_in%fmort_carbonflux_ustory(1:numpft))
     
-    allocate(site_in%term_bagw_flux(1:nlevsclass,1:numpft))
-    allocate(site_in%imort_bagw_flux(1:nlevsclass,1:numpft))
-    allocate(site_in%fmort_bagw_flux(1:nlevsclass,1:numpft))
+    allocate(site_in%term_abg_flux(1:nlevsclass,1:numpft))
+    allocate(site_in%imort_abg_flux(1:nlevsclass,1:numpft))
+    allocate(site_in%fmort_abg_flux(1:nlevsclass,1:numpft))
     
     site_in%nlevsoil   = bc_in%nlevsoil
     allocate(site_in%rootfrac_scr(site_in%nlevsoil))
@@ -249,9 +249,9 @@ subroutine zero_site( site_in )
     site_in%fmort_carbonflux_ustory(:) = 0._r8
     site_in%fmort_rate_cambial(:,:) = 0._r8
     site_in%fmort_rate_crown(:,:) = 0._r8
-    site_in%term_bagw_flux(:,:) = 0._r8
-    site_in%imort_bagw_flux(:,:) = 0._r8
-    site_in%fmort_bagw_flux(:,:) = 0._r8
+    site_in%term_abg_flux(:,:) = 0._r8
+    site_in%imort_abg_flux(:,:) = 0._r8
+    site_in%fmort_abg_flux(:,:) = 0._r8
 
 
     ! fusoin-induced growth flux of individuals
diff --git a/main/EDTypesMod.F90 b/main/EDTypesMod.F90
index de5d87051d..4f15098155 100644
--- a/main/EDTypesMod.F90
+++ b/main/EDTypesMod.F90
@@ -796,9 +796,9 @@ module EDTypesMod
      real(r8), allocatable :: fmort_carbonflux_canopy(:) ! biomass of canopy indivs killed due to fire per year. [gC/m2/sec]
      real(r8), allocatable :: fmort_carbonflux_ustory(:) ! biomass of understory indivs killed due to fire per year [gC/m2/sec] 
 
-     real(r8), allocatable :: term_bagw_flux(:,:)          ! aboveground woody biomass lost due to termination mortality x size x pft
-     real(r8), allocatable :: imort_bagw_flux(:,:)         ! aboveground woody biomass lost due to impact mortality x size x pft
-     real(r8), allocatable :: fmort_bagw_flux(:,:)         ! aboveground woody biomass lost due to fire mortality x size x pft
+     real(r8), allocatable :: term_abg_flux(:,:)          ! aboveground biomass lost due to termination mortality x size x pft
+     real(r8), allocatable :: imort_abg_flux(:,:)         ! aboveground biomass lost due to impact mortality x size x pft
+     real(r8), allocatable :: fmort_abg_flux(:,:)         ! aboveground biomass lost due to fire mortality x size x pft
 
 
      real(r8) :: demotion_carbonflux                     ! biomass of demoted individuals from canopy to understory [kgC/ha/day]
diff --git a/main/FatesHistoryInterfaceMod.F90 b/main/FatesHistoryInterfaceMod.F90
index 6457c2ac5d..4620555de2 100644
--- a/main/FatesHistoryInterfaceMod.F90
+++ b/main/FatesHistoryInterfaceMod.F90
@@ -417,8 +417,8 @@ module FatesHistoryInterfaceMod
   integer :: ih_crownfiremort_si_scpf
   integer :: ih_cambialfiremort_si_scpf
 
-  integer :: ih_bagw_mortality_si_scpf
-  integer :: ih_bagw_productivity_si_scpf
+  integer :: ih_abg_mortality_cflux_si_scpf
+  integer :: ih_abg_productivity_cflux_si_scpf
 
   integer :: ih_m10_si_capf
   integer :: ih_nplant_si_capf
@@ -1926,8 +1926,8 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                hio_crownfiremort_si_scpf     => this%hvars(ih_crownfiremort_si_scpf)%r82d, &
                hio_cambialfiremort_si_scpf   => this%hvars(ih_cambialfiremort_si_scpf)%r82d, &
 
-               hio_bagw_mortality_si_scpf    => this%hvars(ih_bagw_mortality_si_scpf)%r82d, &
-               hio_bagw_productivity_si_scpf => this%hvars(ih_bagw_productivity_si_scpf)%r82d, &
+               hio_abg_mortality_cflux_si_scpf    => this%hvars(ih_abg_mortality_cflux_si_scpf)%r82d, &
+               hio_abg_productivity_cflux_si_scpf => this%hvars(ih_abg_productivity_cflux_si_scpf)%r82d, &
                
                hio_fire_c_to_atm_si  => this%hvars(ih_fire_c_to_atm_si)%r81d, &
                hio_burn_flux_elem    => this%hvars(ih_burn_flux_elem)%r82d, &
@@ -2540,10 +2540,7 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                hio_npp_stor_si_scpf(io_si,scpf) = hio_npp_stor_si_scpf(io_si,scpf) + &
                   store_m_net_alloc*n_perm2 / days_per_year / sec_per_day
 
-               hio_bagw_productivity_si_scpf(io_si,scpf) = hio_bagw_productivity_si_scpf(io_si,scpf) + &
-                    (sapw_m_net_alloc + struct_m_net_alloc) * n_perm2 * (prt_params%allom_agb_frac(ccohort%pft)) / &
-                  days_per_year / sec_per_day
-
+              
                ! Woody State Variables (basal area growth increment)
                if ( prt_params%woody(ft) == itrue) then
 
@@ -2594,15 +2591,7 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                      ccohort%asmort*ccohort%n / m2_per_ha
                end if
 
-               hio_bagw_mortality_si_scpf(io_si,scpf) = hio_bagw_mortality_si_scpf(io_si,scpf) + &
-                    (ccohort%bmort + ccohort%hmort + ccohort%cmort + &
-                    ccohort%frmort + ccohort%smort + ccohort%asmort) * &
-                    (sapw_m + struct_m) * prt_params%allom_agb_frac(ccohort%pft) * &
-                    ccohort%n * days_per_sec * years_per_day * ha_per_m2 + &
-                    (ccohort%lmort_direct + ccohort%lmort_collateral + ccohort%lmort_infra) * &
-                    (sapw_m + struct_m) * prt_params%allom_agb_frac(ccohort%pft) * &
-                    ccohort%n * ha_per_m2
-
+              
 
 
                hio_m1_si_scls(io_si,scls) = hio_m1_si_scls(io_si,scls) + ccohort%bmort*ccohort%n / m2_per_ha
@@ -2655,6 +2644,25 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                hio_cstarvmortality_carbonflux_si_pft(io_si,ccohort%pft) = hio_cstarvmortality_carbonflux_si_pft(io_si,ccohort%pft) + &
                     ccohort%cmort * total_m * ccohort%n * days_per_sec * years_per_day * ha_per_m2
 
+               ! Aboveground woody mortality
+               hio_abg_mortality_cflux_si_scpf(io_si,scpf) = hio_abg_mortality_cflux_si_scpf(io_si,scpf) + &
+                    (ccohort%bmort + ccohort%hmort + ccohort%cmort + &
+                    ccohort%frmort + ccohort%smort + ccohort%asmort) * &
+                    ( (sapw_m + struct_m + store_m ) * prt_params%allom_agb_frac(ccohort%pft) + &
+                    leaf_m ) * &
+                    ccohort%n * days_per_sec * years_per_day * ha_per_m2 + &
+                    (ccohort%lmort_direct + ccohort%lmort_collateral + ccohort%lmort_infra) * &
+                    ( (sapw_m + struct_m + store_m ) * prt_params%allom_agb_frac(ccohort%pft) + &
+                    leaf_m ) * &
+                    ccohort%n * ha_per_m2
+
+               ! Aboveground woody productivity
+               hio_abg_productivity_cflux_si_scpf(io_si,scpf) = hio_abg_productivity_cflux_si_scpf(io_si,scpf) + &
+                    ( (sapw_m_net_alloc + struct_m_net_alloc + store_m_net_alloc) * prt_params%allom_agb_frac(ccohort%pft) + &
+                    leaf_m_net_alloc ) * n_perm2 / &
+                    days_per_year / sec_per_day
+
+               
                ! number density by size and biomass
                hio_agb_si_scls(io_si,scls) = hio_agb_si_scls(io_si,scls) + &
                   total_m * ccohort%n * prt_params%allom_agb_frac(ccohort%pft) * AREA_INV
@@ -3119,10 +3127,10 @@ subroutine update_history_dyn(this,nc,nsites,sites)
       do i_pft = 1, numpft
          do i_scls = 1,nlevsclass
             i_scpf = (i_pft-1)*nlevsclass + i_scls
-            hio_bagw_mortality_si_scpf(io_si,i_scpf) = hio_bagw_mortality_si_scpf(io_si,i_scpf) + &
-                 (sites(s)%fmort_bagw_flux(i_scls,i_pft) / g_per_kg ) + &
-                 (sites(s)%imort_bagw_flux(i_scls,i_pft)  / g_per_kg) + &
-                 (sites(s)%term_bagw_flux(i_scls,i_pft)  * days_per_sec * ha_per_m2 ) ! jfn
+            hio_abg_mortality_cflux_si_scpf(io_si,i_scpf) = hio_abg_mortality_cflux_si_scpf(io_si,i_scpf) + &
+                 (sites(s)%fmort_abg_flux(i_scls,i_pft) / g_per_kg ) + &
+                 (sites(s)%imort_abg_flux(i_scls,i_pft)  / g_per_kg) + &
+                 (sites(s)%term_abg_flux(i_scls,i_pft)  * days_per_sec * ha_per_m2 ) ! jfn
          end do
       end do
 
@@ -3137,9 +3145,9 @@ subroutine update_history_dyn(this,nc,nsites,sites)
       sites(s)%fmort_rate_cambial(:,:) = 0._r8
       sites(s)%fmort_rate_crown(:,:) = 0._r8
       sites(s)%growthflux_fusion(:,:) = 0._r8
-      sites(s)%fmort_bagw_flux(:,:) = 0._r8
-      sites(s)%imort_bagw_flux(:,:) = 0._r8
-      sites(s)%term_bagw_flux(:,:) = 0._r8
+      sites(s)%fmort_abg_flux(:,:) = 0._r8
+      sites(s)%imort_abg_flux(:,:) = 0._r8
+      sites(s)%term_abg_flux(:,:) = 0._r8
 
       ! pass the recruitment rate as a flux to the history, and then reset the recruitment buffer
       do i_pft = 1, numpft
@@ -5598,17 +5606,17 @@ subroutine define_history_vars(this, initialize_variables)
          upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
          index=ih_cstarvmortality_carbonflux_si_pft)
 
-    call this%set_history_var(vname='FATES_AGW_MORTALITY_SZPF', units='kg m-2 s-1',    &
-         long='Aboveground woody flux of carbon from AGB to necromass due to mortality', &
+    call this%set_history_var(vname='FATES_ABOVEGROUND_MORT_SZPF', units='kg m-2 s-1',    &
+         long='Aboveground flux of carbon from AGB to necromass due to mortality', &
          use_default='inactive', avgflag='A', vtype=site_size_pft_r8, hlms='CLM:ALM', &
          upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
-         index=ih_bagw_mortality_si_scpf)
+         index=ih_abg_mortality_cflux_si_scpf)
 
-    call this%set_history_var(vname='FATES_AGW_PRODUCTIVITY_SZPF', units='kg m-2 s-1',    &
-         long='Aboveground woody carbon productivity', &
+    call this%set_history_var(vname='FATES_ABOVEGROUND_PROD_SZPF', units='kg m-2 s-1',    &
+         long='Aboveground carbon productivity', &
          use_default='inactive', avgflag='A', vtype=site_size_pft_r8, hlms='CLM:ALM', &
          upfreq=1, ivar=ivar, initialize=initialize_variables,                 &
-         index=ih_bagw_productivity_si_scpf)
+         index=ih_abg_productivity_cflux_si_scpf)
     
     ! size class by age dimensioned variables
 
diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90
index e028b8ab23..6cb63489be 100644
--- a/main/FatesRestartInterfaceMod.F90
+++ b/main/FatesRestartInterfaceMod.F90
@@ -211,9 +211,9 @@ module FatesRestartInterfaceMod
   integer :: ir_imortcflux_sipft
   integer :: ir_fmortcflux_cano_sipft
   integer :: ir_fmortcflux_usto_sipft
-  integer :: ir_bagw_term_flux_siscpf
-  integer :: ir_bagw_imort_flux_siscpf
-  integer :: ir_bagw_fmort_flux_siscpf
+  integer :: ir_abg_term_flux_siscpf
+  integer :: ir_abg_imort_flux_siscpf
+  integer :: ir_abg_fmort_flux_siscpf
   integer :: ir_cwdagin_flxdg
   integer :: ir_cwdbgin_flxdg
   integer :: ir_leaflittin_flxdg
@@ -1251,20 +1251,20 @@ subroutine define_restart_vars(this, initialize_variables)
          units='', flushval = flushzero, &
          hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_termcflux_usto_sipft )
 
-   call this%set_restart_var(vname='fates_bagw_term_flux', vtype=cohort_r8, &
+   call this%set_restart_var(vname='fates_abg_term_flux', vtype=cohort_r8, &
          long_name='fates aboveground biomass loss from termination mortality', &
          units='', flushval = flushzero, &
-         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_bagw_term_flux_siscpf )
+         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_abg_term_flux_siscpf )
 
-   call this%set_restart_var(vname='fates_bagw_imort_flux', vtype=cohort_r8, &
+   call this%set_restart_var(vname='fates_abg_imort_flux', vtype=cohort_r8, &
          long_name='fates aboveground biomass loss from impact mortality', &
          units='', flushval = flushzero, &
-         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_bagw_imort_flux_siscpf )
+         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_abg_imort_flux_siscpf )
 
-   call this%set_restart_var(vname='fates_bagw_fmort_flux', vtype=cohort_r8, &
+   call this%set_restart_var(vname='fates_abg_fmort_flux', vtype=cohort_r8, &
          long_name='fates aboveground biomass loss from fire mortality', &
          units='', flushval = flushzero, &
-         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_bagw_fmort_flux_siscpf )
+         hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_abg_fmort_flux_siscpf )
 
    call this%set_restart_var(vname='fates_democflux', vtype=site_r8, &
          long_name='fates diagnostic demotion carbon flux', &
@@ -1844,9 +1844,9 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
            rio_imortcflux_sipft        => this%rvars(ir_imortcflux_sipft)%r81d, &
            rio_fmortcflux_cano_sipft   => this%rvars(ir_fmortcflux_cano_sipft)%r81d, &
            rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d, &
-           rio_bagw_imort_flux_siscpf => this%rvars(ir_bagw_imort_flux_siscpf)%r81d, &
-           rio_bagw_fmort_flux_siscpf => this%rvars(ir_bagw_fmort_flux_siscpf)%r81d, &
-           rio_bagw_term_flux_siscpf  => this%rvars(ir_bagw_term_flux_siscpf)%r81d )
+           rio_abg_imort_flux_siscpf => this%rvars(ir_abg_imort_flux_siscpf)%r81d, &
+           rio_abg_fmort_flux_siscpf => this%rvars(ir_abg_fmort_flux_siscpf)%r81d, &
+           rio_abg_term_flux_siscpf  => this%rvars(ir_abg_term_flux_siscpf)%r81d )
            
 
        totalCohorts = 0
@@ -2220,9 +2220,9 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
                 rio_termnindiv_usto_siscpf(io_idx_si_scpf) = sites(s)%term_nindivs_ustory(i_scls,i_pft)
                 rio_growflx_fusion_siscpf(io_idx_si_scpf)  = sites(s)%growthflux_fusion(i_scls, i_pft)
 
-                rio_bagw_term_flux_siscpf(io_idx_si_scpf) = sites(s)%term_bagw_flux(i_scls, i_pft)
-                rio_bagw_imort_flux_siscpf(io_idx_si_scpf) = sites(s)%imort_bagw_flux(i_scls, i_pft)
-                rio_bagw_fmort_flux_siscpf(io_idx_si_scpf) = sites(s)%fmort_bagw_flux(i_scls, i_pft)
+                rio_abg_term_flux_siscpf(io_idx_si_scpf) = sites(s)%term_abg_flux(i_scls, i_pft)
+                rio_abg_imort_flux_siscpf(io_idx_si_scpf) = sites(s)%imort_abg_flux(i_scls, i_pft)
+                rio_abg_fmort_flux_siscpf(io_idx_si_scpf) = sites(s)%fmort_abg_flux(i_scls, i_pft)
 
                 io_idx_si_scpf = io_idx_si_scpf + 1
              end do
@@ -2684,9 +2684,9 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
           rio_imortcflux_sipft        => this%rvars(ir_imortcflux_sipft)%r81d, &
           rio_fmortcflux_cano_sipft   => this%rvars(ir_fmortcflux_cano_sipft)%r81d, &
           rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d, &
-          rio_bagw_term_flux_siscpf   => this%rvars(ir_bagw_term_flux_siscpf)%r81d, &
-          rio_bagw_imort_flux_siscpf  => this%rvars(ir_bagw_imort_flux_siscpf)%r81d, &
-          rio_bagw_fmort_flux_siscpf  => this%rvars(ir_bagw_fmort_flux_siscpf)%r81d )
+          rio_abg_term_flux_siscpf   => this%rvars(ir_abg_term_flux_siscpf)%r81d, &
+          rio_abg_imort_flux_siscpf  => this%rvars(ir_abg_imort_flux_siscpf)%r81d, &
+          rio_abg_fmort_flux_siscpf  => this%rvars(ir_abg_fmort_flux_siscpf)%r81d )
 
 
        totalcohorts = 0
@@ -3097,9 +3097,9 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
                 sites(s)%term_nindivs_ustory(i_scls,i_pft) = rio_termnindiv_usto_siscpf(io_idx_si_scpf)
                 sites(s)%growthflux_fusion(i_scls, i_pft)  = rio_growflx_fusion_siscpf(io_idx_si_scpf)
 
-                sites(s)%term_bagw_flux(i_scls,i_pft) = rio_bagw_term_flux_siscpf(io_idx_si_scpf)
-                sites(s)%imort_bagw_flux(i_scls,i_pft) = rio_bagw_imort_flux_siscpf(io_idx_si_scpf)
-                sites(s)%fmort_bagw_flux(i_scls,i_pft) = rio_bagw_fmort_flux_siscpf(io_idx_si_scpf)
+                sites(s)%term_abg_flux(i_scls,i_pft) = rio_abg_term_flux_siscpf(io_idx_si_scpf)
+                sites(s)%imort_abg_flux(i_scls,i_pft) = rio_abg_imort_flux_siscpf(io_idx_si_scpf)
+                sites(s)%fmort_abg_flux(i_scls,i_pft) = rio_abg_fmort_flux_siscpf(io_idx_si_scpf)
 
                 io_idx_si_scpf = io_idx_si_scpf + 1
              end do

From 8a07cbd2de7a96856cd8114861d14fa0df26336e Mon Sep 17 00:00:00 2001
From: Jessica Needham <jessiefneedham@gmail.com>
Date: Fri, 21 Oct 2022 11:39:46 -0700
Subject: [PATCH 4/8] [ Add termination mortality to total carbon flux
 mortality ]

[ ]

Fixes: [NGT-ED Github issue #]

User interface changes?: [Yes (describe what changes), No]

Code review: [Names]

Test suite: [suite name, machine, compilers]
Test baseline:
Test namelist changes:
Test answer changes: [bit for bit, roundoff, climate changing]
Test summary:no testing
---
 main/FatesHistoryInterfaceMod.F90 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/main/FatesHistoryInterfaceMod.F90 b/main/FatesHistoryInterfaceMod.F90
index 4620555de2..f46490a8b9 100644
--- a/main/FatesHistoryInterfaceMod.F90
+++ b/main/FatesHistoryInterfaceMod.F90
@@ -2644,7 +2644,7 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                hio_cstarvmortality_carbonflux_si_pft(io_si,ccohort%pft) = hio_cstarvmortality_carbonflux_si_pft(io_si,ccohort%pft) + &
                     ccohort%cmort * total_m * ccohort%n * days_per_sec * years_per_day * ha_per_m2
 
-               ! Aboveground woody mortality
+               ! Aboveground mortality
                hio_abg_mortality_cflux_si_scpf(io_si,scpf) = hio_abg_mortality_cflux_si_scpf(io_si,scpf) + &
                     (ccohort%bmort + ccohort%hmort + ccohort%cmort + &
                     ccohort%frmort + ccohort%smort + ccohort%asmort) * &
@@ -3118,7 +3118,9 @@ subroutine update_history_dyn(this,nc,nsites,sites)
          hio_mortality_carbonflux_si_pft(io_si,i_pft) = hio_mortality_carbonflux_si_pft(io_si,i_pft) + &
               (sites(s)%fmort_carbonflux_canopy(i_pft) + &
               sites(s)%fmort_carbonflux_ustory(i_pft) + &
-              sites(s)%imort_carbonflux(i_pft) ) / g_per_kg !cdk
+              sites(s)%imort_carbonflux(i_pft) ) / g_per_kg + &  ! cdk
+              (sites(s)%term_carbonflux_canopy(i_pft) + &
+              sites(s)%term_carbonflux_ustory(i_pft) ) * days_per_sec * ha_per_m2
 
          hio_firemortality_carbonflux_si_pft(io_si,i_pft) = sites(s)%fmort_carbonflux_canopy(i_pft) / g_per_kg
       end do

From 4010842cd4602b9672c0c6378488d93b4699f2e8 Mon Sep 17 00:00:00 2001
From: Jessica Needham <jessiefneedham@gmail.com>
Date: Fri, 21 Oct 2022 14:41:51 -0700
Subject: [PATCH 5/8] [ Tidy up spacing ]

[  ]

Fixes: [NGT-ED Github issue #]

User interface changes?: [Yes (describe what changes), No]

Code review: [Names]

Test suite: [suite name, machine, compilers]
Test baseline:
Test namelist changes:
Test answer changes: [bit for bit, roundoff, climate changing]
Test summary: no testing
---
 main/FatesHistoryInterfaceMod.F90 | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/main/FatesHistoryInterfaceMod.F90 b/main/FatesHistoryInterfaceMod.F90
index f46490a8b9..9c11ef5b02 100644
--- a/main/FatesHistoryInterfaceMod.F90
+++ b/main/FatesHistoryInterfaceMod.F90
@@ -2638,6 +2638,7 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                     (ccohort%lmort_direct + ccohort%lmort_collateral + ccohort%lmort_infra) * total_m * &
                     ccohort%n * ha_per_m2
 
+               
                hio_hydraulicmortality_carbonflux_si_pft(io_si,ccohort%pft) = hio_hydraulicmortality_carbonflux_si_pft(io_si,ccohort%pft) + &
                     ccohort%hmort * total_m * ccohort%n * days_per_sec * years_per_day * ha_per_m2
 
@@ -2649,13 +2650,11 @@ subroutine update_history_dyn(this,nc,nsites,sites)
                     (ccohort%bmort + ccohort%hmort + ccohort%cmort + &
                     ccohort%frmort + ccohort%smort + ccohort%asmort) * &
                     ( (sapw_m + struct_m + store_m ) * prt_params%allom_agb_frac(ccohort%pft) + &
-                    leaf_m ) * &
-                    ccohort%n * days_per_sec * years_per_day * ha_per_m2 + &
+                    leaf_m ) * ccohort%n * days_per_sec * years_per_day * ha_per_m2 + &
                     (ccohort%lmort_direct + ccohort%lmort_collateral + ccohort%lmort_infra) * &
                     ( (sapw_m + struct_m + store_m ) * prt_params%allom_agb_frac(ccohort%pft) + &
-                    leaf_m ) * &
-                    ccohort%n * ha_per_m2
-
+                    leaf_m ) * ccohort%n * ha_per_m2
+   
                ! Aboveground woody productivity
                hio_abg_productivity_cflux_si_scpf(io_si,scpf) = hio_abg_productivity_cflux_si_scpf(io_si,scpf) + &
                     ( (sapw_m_net_alloc + struct_m_net_alloc + store_m_net_alloc) * prt_params%allom_agb_frac(ccohort%pft) + &
@@ -2994,6 +2993,7 @@ subroutine update_history_dyn(this,nc,nsites,sites)
          cpatch => cpatch%younger
       end do patchloop !patch loop
 
+    
       ! divide basal-area-weighted height by basal area to get mean
       if ( sum(hio_ba_si_scpf(io_si,:)) .gt. nearzero ) then
          hio_ba_weighted_height_si(io_si) = hio_ba_weighted_height_si(io_si) / sum(hio_ba_si_scpf(io_si,:))
@@ -3118,10 +3118,8 @@ subroutine update_history_dyn(this,nc,nsites,sites)
          hio_mortality_carbonflux_si_pft(io_si,i_pft) = hio_mortality_carbonflux_si_pft(io_si,i_pft) + &
               (sites(s)%fmort_carbonflux_canopy(i_pft) + &
               sites(s)%fmort_carbonflux_ustory(i_pft) + &
-              sites(s)%imort_carbonflux(i_pft) ) / g_per_kg + &  ! cdk
-              (sites(s)%term_carbonflux_canopy(i_pft) + &
-              sites(s)%term_carbonflux_ustory(i_pft) ) * days_per_sec * ha_per_m2
-
+              sites(s)%imort_carbonflux(i_pft) ) / g_per_kg  ! cdk
+   
          hio_firemortality_carbonflux_si_pft(io_si,i_pft) = sites(s)%fmort_carbonflux_canopy(i_pft) / g_per_kg
       end do
 
@@ -3131,11 +3129,12 @@ subroutine update_history_dyn(this,nc,nsites,sites)
             i_scpf = (i_pft-1)*nlevsclass + i_scls
             hio_abg_mortality_cflux_si_scpf(io_si,i_scpf) = hio_abg_mortality_cflux_si_scpf(io_si,i_scpf) + &
                  (sites(s)%fmort_abg_flux(i_scls,i_pft) / g_per_kg ) + &
-                 (sites(s)%imort_abg_flux(i_scls,i_pft)  / g_per_kg) + &
+                 (sites(s)%imort_abg_flux(i_scls,i_pft) / g_per_kg) + &
                  (sites(s)%term_abg_flux(i_scls,i_pft)  * days_per_sec * ha_per_m2 ) ! jfn
          end do
       end do
 
+      
       sites(s)%term_nindivs_canopy(:,:) = 0._r8
       sites(s)%term_nindivs_ustory(:,:) = 0._r8
       sites(s)%imort_carbonflux(:) = 0._r8

From 9f228fd2ce0f48011213b6fe24096f83edee72bd Mon Sep 17 00:00:00 2001
From: Jessica Needham <jessiefneedham@gmail.com>
Date: Fri, 21 Oct 2022 15:08:45 -0700
Subject: [PATCH 6/8] [ Remove repro_m that wasn't needed ]

[ To be consistent with AGB reproductive carbon isn't included
so no need to add it here.  ]

Fixes: [NGT-ED Github issue #]

User interface changes?: [Yes (describe what changes), No]

Code review: [Names]

Test suite: [suite name, machine, compilers]
Test baseline:
Test namelist changes:
Test answer changes: [bit for bit, roundoff, climate changing]
Test summary: no testing
---
 biogeochem/EDPatchDynamicsMod.F90 | 2 --
 1 file changed, 2 deletions(-)

diff --git a/biogeochem/EDPatchDynamicsMod.F90 b/biogeochem/EDPatchDynamicsMod.F90
index 0e2d618ceb..099c658a06 100644
--- a/biogeochem/EDPatchDynamicsMod.F90
+++ b/biogeochem/EDPatchDynamicsMod.F90
@@ -399,7 +399,6 @@ subroutine spawn_patches( currentSite, bc_in)
     real(r8) :: sapw_c                       ! sapwood carbon [kg]
     real(r8) :: store_c                      ! storage carbon [kg]
     real(r8) :: struct_c                     ! structure carbon [kg]
-    real(r8) :: repro_c                      ! reproductive carbon [kg]
     real(r8) :: total_c                      ! total carbon of plant [kg]
     real(r8) :: leaf_burn_frac               ! fraction of leaves burned in fire
                                              ! for both woody and grass species
@@ -663,7 +662,6 @@ subroutine spawn_patches( currentSite, bc_in)
                          leaf_c   = currentCohort%prt%GetState(leaf_organ, all_carbon_elements)
                          fnrt_c   = currentCohort%prt%GetState(fnrt_organ, all_carbon_elements)
                          store_c  = currentCohort%prt%GetState(store_organ, all_carbon_elements)
-                         repro_c  = currentCohort%prt%GetState(repro_organ, all_carbon_elements)
                          total_c  = sapw_c + struct_c + leaf_c + fnrt_c + store_c
 
                          ! treefall mortality is the current disturbance

From 47c539a7e34ecf5045c6771cc3d4ce918fce4aa2 Mon Sep 17 00:00:00 2001
From: Gregory Lemieux <glemieux@users.noreply.github.com>
Date: Tue, 31 Jan 2023 09:21:52 -0800
Subject: [PATCH 7/8] remove extra closing paranthesis in associate statement

---
 main/FatesRestartInterfaceMod.F90 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90
index 4741af0526..a115aee798 100644
--- a/main/FatesRestartInterfaceMod.F90
+++ b/main/FatesRestartInterfaceMod.F90
@@ -1978,8 +1978,7 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
            rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d, &
            rio_abg_imort_flux_siscpf => this%rvars(ir_abg_imort_flux_siscpf)%r81d, &
            rio_abg_fmort_flux_siscpf => this%rvars(ir_abg_fmort_flux_siscpf)%r81d, &
-           rio_abg_term_flux_siscpf  => this%rvars(ir_abg_term_flux_siscpf)%r81d )
-           
+           rio_abg_term_flux_siscpf  => this%rvars(ir_abg_term_flux_siscpf)%r81d
 
            rio_imortrate_sicdpf        => this%rvars(ir_imortrate_sicdpf)%r81d, &
            rio_imortcflux_sicdsc       => this%rvars(ir_imortcflux_sicdsc)%r81d, &

From 64226688962473cf2dad17d3aad3c157d18ddf7b Mon Sep 17 00:00:00 2001
From: Gregory Lemieux <glemieux@users.noreply.github.com>
Date: Tue, 31 Jan 2023 17:07:17 -0800
Subject: [PATCH 8/8] add missing line continuation in restart

---
 main/FatesRestartInterfaceMod.F90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90
index a115aee798..a0509ac015 100644
--- a/main/FatesRestartInterfaceMod.F90
+++ b/main/FatesRestartInterfaceMod.F90
@@ -1978,7 +1978,7 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
            rio_fmortcflux_usto_sipft   => this%rvars(ir_fmortcflux_usto_sipft)%r81d, &
            rio_abg_imort_flux_siscpf => this%rvars(ir_abg_imort_flux_siscpf)%r81d, &
            rio_abg_fmort_flux_siscpf => this%rvars(ir_abg_fmort_flux_siscpf)%r81d, &
-           rio_abg_term_flux_siscpf  => this%rvars(ir_abg_term_flux_siscpf)%r81d
+           rio_abg_term_flux_siscpf  => this%rvars(ir_abg_term_flux_siscpf)%r81d, &
 
            rio_imortrate_sicdpf        => this%rvars(ir_imortrate_sicdpf)%r81d, &
            rio_imortcflux_sicdsc       => this%rvars(ir_imortcflux_sicdsc)%r81d, &