From 16b0801a0c46a6f81293db848a2314036ea4a842 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Thu, 22 Jan 2026 15:00:00 -0700 Subject: [PATCH 1/3] CropPhase: Factor out new subroutine CropPhase_OnePatch. --- src/biogeochem/CNPhenologyMod.F90 | 63 ++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/src/biogeochem/CNPhenologyMod.F90 b/src/biogeochem/CNPhenologyMod.F90 index fb43c37804..c54766d1c8 100644 --- a/src/biogeochem/CNPhenologyMod.F90 +++ b/src/biogeochem/CNPhenologyMod.F90 @@ -2629,13 +2629,7 @@ subroutine CropPhase(bounds, num_pcropp, filter_pcropp, & ! !DESCRIPTION: ! Get the current phase of each crop patch. ! - ! The returned values (in crop_phase) are from the set of cphase_* values defined in - ! CropType. The returned values in crop_phase are only valid for patches where - ! croplive is true; the values are undefined where croplive is false and should not be - ! used there! - ! - ! This has logic similar to that in CropPhenology. If you make changes here, you - ! should also check if similar changes need to be made in CropPhenology. + ! See CropPhase_OnePatch for more information. ! ! !ARGUMENTS: type(bounds_type) , intent(in) :: bounds @@ -2662,20 +2656,7 @@ subroutine CropPhase(bounds, num_pcropp, filter_pcropp, & do fp = 1, num_pcropp p = filter_pcropp(fp) - - if (croplive(p)) then - ! Start with cphase_planted, but this might get changed in the later - ! conditional blocks. - crop_phase(p) = cphase_planted - if (leafout(p) >= huileaf(p) .and. hui(p) < huigrain(p)) then - crop_phase(p) = cphase_leafemerge - else if (hui(p) >= huigrain(p)) then - ! Since we know croplive is true, any hui greater than huigrain implies that - ! we're in the grainfill stage: if we were passt gddmaturity then croplive - ! would be false. - crop_phase(p) = cphase_grainfill - end if - end if + call CropPhase_OnePatch(crop_phase(p), croplive(p), leafout(p), hui(p), huileaf(p), huigrain(p)) end do end associate @@ -2683,6 +2664,46 @@ subroutine CropPhase(bounds, num_pcropp, filter_pcropp, & end subroutine CropPhase + !----------------------------------------------------------------------- + subroutine CropPhase_OnePatch( & + crop_phase, croplive, leafout, hui, huileaf, huigrain & + ) + ! + ! !DESCRIPTION: + ! Get the current phase of a crop patch. + ! + ! The returned values (in crop_phase) are from the set of cphase_* values defined in + ! CropType. The returned values in crop_phase are only valid for patches where + ! croplive is true; the values are undefined where croplive is false and should not be + ! used there! + ! + ! This has logic similar to that in CropPhenology. If you make changes here, you + ! should also check if similar changes need to be made in CropPhenology. + ! + ! !ARGUMENTS: + real(r8), intent(inout) :: crop_phase ! In/out: [real(r8)] crop phase + logical , intent(in) :: croplive ! Input: [logical] Flag, true if planted, not harvested + real(r8), intent(in) :: leafout ! Input: [real(r8)] gdd from top soil layer temperature + real(r8), intent(in) :: hui ! Input: [real(r8)] gdd since planting (gddplant) + real(r8), intent(in) :: huileaf ! Input: [real(r8)] heat unit index needed from planting to leaf emergence + real(r8), intent(in) :: huigrain ! Input: [real(r8)] same to reach vegetative maturity + + if (croplive) then + ! Start with cphase_planted, but this might get changed in the later + ! conditional blocks. + crop_phase = cphase_planted + if (leafout >= huileaf .and. hui < huigrain) then + crop_phase = cphase_leafemerge + else if (hui >= huigrain) then + ! Since we know croplive is true, any hui greater than huigrain implies that + ! we're in the grainfill stage: if we were passt gddmaturity then croplive + ! would be false. + crop_phase = cphase_grainfill + end if + end if + end subroutine CropPhase_OnePatch + + !----------------------------------------------------------------------- subroutine CropPhenologyInit(bounds) ! From b870b8bcd34e010451dbbe51c8185b09e28507f9 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Thu, 22 Jan 2026 16:14:52 -0700 Subject: [PATCH 2/3] CropPhase(): Remove associate(). --- src/biogeochem/CNPhenologyMod.F90 | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/biogeochem/CNPhenologyMod.F90 b/src/biogeochem/CNPhenologyMod.F90 index c54766d1c8..2151b331e6 100644 --- a/src/biogeochem/CNPhenologyMod.F90 +++ b/src/biogeochem/CNPhenologyMod.F90 @@ -2646,21 +2646,17 @@ subroutine CropPhase(bounds, num_pcropp, filter_pcropp, & !----------------------------------------------------------------------- SHR_ASSERT_ALL_FL((ubound(crop_phase) == [bounds%endp]), sourcefile, __LINE__) - associate( & - croplive => crop_inst%croplive_patch , & ! Input: [logical (:) ] Flag, true if planted, not harvested - hui => crop_inst%hui_patch , & ! Input: [real(r8) (:) ] gdd since planting (gddplant) - leafout => crop_inst%gddtsoi_patch , & ! Input: [real(r8) (:) ] gdd from top soil layer temperature - huileaf => cnveg_state_inst%huileaf_patch , & ! Input: [real(r8) (:) ] heat unit index needed from planting to leaf emergence - huigrain => cnveg_state_inst%huigrain_patch & ! Input: [real(r8) (:) ] same to reach vegetative maturity - ) - do fp = 1, num_pcropp p = filter_pcropp(fp) - call CropPhase_OnePatch(crop_phase(p), croplive(p), leafout(p), hui(p), huileaf(p), huigrain(p)) + call CropPhase_OnePatch( & + crop_phase(p), & + crop_inst%croplive_patch(p), & + crop_inst%gddtsoi_patch(p), & + crop_inst%hui_patch(p), & + cnveg_state_inst%huileaf_patch(p), & + cnveg_state_inst%huigrain_patch(p)) end do - end associate - end subroutine CropPhase From 023631eb4110751afdb1e0fcc02bac3db1ebf81c Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 23 Jan 2026 15:40:46 -0700 Subject: [PATCH 3/3] Fix pre-existing typo. Co-authored-by: Samuel Levis --- src/biogeochem/CNPhenologyMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biogeochem/CNPhenologyMod.F90 b/src/biogeochem/CNPhenologyMod.F90 index 2151b331e6..e4b9c01abd 100644 --- a/src/biogeochem/CNPhenologyMod.F90 +++ b/src/biogeochem/CNPhenologyMod.F90 @@ -2692,7 +2692,7 @@ subroutine CropPhase_OnePatch( & crop_phase = cphase_leafemerge else if (hui >= huigrain) then ! Since we know croplive is true, any hui greater than huigrain implies that - ! we're in the grainfill stage: if we were passt gddmaturity then croplive + ! we're in the grainfill stage: if we were past gddmaturity then croplive ! would be false. crop_phase = cphase_grainfill end if