Skip to content

Commit

Permalink
Cleanup: update_history_hifrq2_ageclass().
Browse files Browse the repository at this point in the history
- Use descriptive weight names
- Remove unused variable ipa
- Fix indentation
  • Loading branch information
samsrabin committed Oct 13, 2024
1 parent 309086c commit d249965
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions main/FatesHistoryInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5689,10 +5689,11 @@ subroutine update_history_hifrq2_ageclass(this,nsites,sites,dt_tstep)

type(fates_cohort_type), pointer :: ccohort
type(fates_patch_type), pointer :: cpatch
integer :: s, io_si, ipa
integer :: s, io_si
real(r8) :: site_canopy_area
real(r8) :: weight
real(r8) :: dt_tstep_inv ! Time step in frequency units (/s)
real(r8) :: patch_canarea_div_site_canarea ! Weighting based on patch canopy area relative to site canopy area
real(r8) :: cohort_n_div_site_area ! Weighting based on cohort density relative to site area

associate( &
hio_c_lblayer_si_age => this%hvars(ih_c_lblayer_si_age)%r82d, &
Expand All @@ -5714,46 +5715,43 @@ subroutine update_history_hifrq2_ageclass(this,nsites,sites,dt_tstep)
end do !patch loop

io_si = sites(s)%h_gid
ipa = 0

! Get ageclass-stratified variables
cpatch => sites(s)%oldest_patch
do while(associated(cpatch))
ipa = ipa + 1

! Canopy resistance terms
if (site_canopy_area .gt. nearzero) then
weight = cpatch%total_canopy_area / site_canopy_area

hio_c_stomata_si_age(io_si,cpatch%age_class) = &
hio_c_stomata_si_age(io_si,cpatch%age_class) + &
cpatch%c_stomata * mol_per_umol &
* weight

hio_c_lblayer_si_age(io_si,cpatch%age_class) = &
hio_c_lblayer_si_age(io_si,cpatch%age_class) + &
cpatch%c_lblayer * mol_per_umol &
* weight
else
hio_c_stomata_si_age(io_si,cpatch%age_class) = 0._r8
hio_c_lblayer_si_age(io_si,cpatch%age_class) = 0._r8
end if
patch_canarea_div_site_canarea = cpatch%total_canopy_area / site_canopy_area

! Canopy resistance terms
if (site_canopy_area .gt. nearzero) then
hio_c_stomata_si_age(io_si,cpatch%age_class) = &
hio_c_stomata_si_age(io_si,cpatch%age_class) + &
cpatch%c_stomata * mol_per_umol &
* patch_canarea_div_site_canarea

hio_c_lblayer_si_age(io_si,cpatch%age_class) = &
hio_c_lblayer_si_age(io_si,cpatch%age_class) + &
cpatch%c_lblayer * mol_per_umol &
* patch_canarea_div_site_canarea
else
hio_c_stomata_si_age(io_si,cpatch%age_class) = 0._r8
hio_c_lblayer_si_age(io_si,cpatch%age_class) = 0._r8
end if

ccohort => cpatch%shortest
do while(associated(ccohort))
if (ccohort%isnew) then
ccohort => ccohort%taller
cycle
end if
cohort_n_div_site_area = ccohort%n * AREA_INV

weight = ccohort%n * AREA_INV
hio_gpp_si_age(io_si,cpatch%age_class) = hio_gpp_si_age(io_si,cpatch%age_class) &
+ ccohort%gpp_tstep * dt_tstep_inv &
* weight
* cohort_n_div_site_area

hio_npp_si_age(io_si,cpatch%age_class) = hio_npp_si_age(io_si,cpatch%age_class) &
+ ccohort%npp_tstep * dt_tstep_inv &
* weight
* cohort_n_div_site_area

ccohort => ccohort%taller
end do ! cohort loop
Expand Down

0 comments on commit d249965

Please sign in to comment.