Skip to content

Commit

Permalink
Share idpp calculation code.
Browse files Browse the repository at this point in the history
Between CropPhenology()and get_tillage_multipliers(). New function DaysPastPlanting() shared from CNPhenologyMod to TillageMod.
  • Loading branch information
samsrabin committed Aug 21, 2023
1 parent 9063873 commit f01adc6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
41 changes: 35 additions & 6 deletions src/biogeochem/CNPhenologyMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module CNPhenologyMod
public :: CNPhenologyInit ! Initialization
public :: CNPhenology ! Update
public :: CropPhase ! Get the current phase of each crop patch
public :: DaysPastPlanting ! Get how many days it's been since crop was planted

! !PUBLIC for unit testing
public :: CNPhenologySetNML ! Set the namelist setttings explicitly for unit tests
Expand Down Expand Up @@ -2117,12 +2118,7 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
end if

! days past planting may determine harvest

if (jday >= idop(p)) then
idpp = jday - idop(p)
else
idpp = int(dayspyr) + jday - idop(p)
end if
idpp = DaysPastPlanting(idop(p), jday)

! onset_counter initialized to zero when .not. croplive
! offset_counter relevant only at time step of harvest
Expand Down Expand Up @@ -2664,6 +2660,39 @@ subroutine PlantCrop(p, leafcn_in, jday, kyr, do_plant_normal, &

end subroutine PlantCrop

!-----------------------------------------------------------------------
function DaysPastPlanting(idop, jday_in)
! !USES:
use clm_time_manager, only : get_prev_calday, get_curr_days_per_year
!
! !ARGUMENTS:
integer, intent(in) :: idop ! patch day of planting
integer, optional, intent(in) :: jday_in ! julian day of the year
!
! !LOCAL VARIABLES
integer :: DaysPastPlanting
integer :: jday

! Must use separate jday_in and jday because we can't redefine an intent(in)
! variable, even if it wasn't provided in the function call.
if (present(jday_in)) then
jday = jday_in
else
! Use prev instead of curr to avoid jday=1 in last timestep of year
jday = get_prev_calday()
end if

if (jday >= idop) then
DaysPastPlanting = jday - idop
else
! As long as crops have at most a 365-day growing season, using get_curr_days_per_year()
! should give the same result of this function as using get_prev_days_per_year().
! TODO: Test identicality when using get_prev_days_per_year().
DaysPastPlanting = jday - idop + get_curr_days_per_year()
end if

end function DaysPastPlanting

!-----------------------------------------------------------------------
subroutine vernalization(p, &
canopystate_inst, temperature_inst, waterdiagnosticbulk_inst, cnveg_state_inst, crop_inst, &
Expand Down
20 changes: 5 additions & 15 deletions src/soilbiogeochem/TillageMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ subroutine get_tillage_multipliers(tillage_mults, idop)
!
! Modified by Sam Rabin to fix a bug where idpp wasn't actually used, which
! would affect growing seasons that crossed over into a new calendar year.
! Also avoids day=1 in last timestep of year by using DaysPastPlanting(), which
! uses get_prev_calday() instead of get_curr_calday().
! Previous behavior can be requested with namelist variable use_original_tillage.
!
! Original code had two versions depending on cell's GDP, but this seems to
Expand All @@ -187,6 +189,7 @@ subroutine get_tillage_multipliers(tillage_mults, idop)
! !USES:
use clm_time_manager, only : get_curr_calday, get_curr_days_per_year
use pftconMod , only : ntmp_corn, nirrig_tmp_corn, ntmp_soybean, nirrig_tmp_soybean
use CNPhenologyMod , only : DaysPastPlanting
! !ARGUMENTS:
real(r8) , intent(inout) :: tillage_mults(:) ! tillage multipliers for this patch
integer , intent(in) :: idop ! patch day of planting
Expand All @@ -199,28 +202,14 @@ subroutine get_tillage_multipliers(tillage_mults, idop)
real(r8) dayspyr ! days per year
!-----------------------------------------------------------------------

!get info from externals
day = get_curr_calday()
dayspyr = get_curr_days_per_year() !Add by MWG for IDPP-based routine

! days past planting may determine harvest/tillage
if (day >= idop) then
idpp = day - idop
else
idpp = int(dayspyr) + day - idop
end if

! -----------------------------------------------------
! 3) assigning tillage practices and mapping to the
! effect on soil C decomposition
! -----------------------------------------------------
! info from DAYCENT (Melannie Hartman CSU)
! temp. cereals: P 30 d bef, C 15 d bef, D on day of planting
! corn, soy : P C D & HW-7 30 d aftr

phase = 0

if (use_original_tillage) then
day = get_curr_calday()
if (day >= idop .and. day < idop+15) then ! based on Point Chisel Tandem Disk multipliers
phase = 1
else if (day >= idop+15 .and. day < idop+45) then ! based on Field and Row Cultivator multipliers
Expand All @@ -229,6 +218,7 @@ subroutine get_tillage_multipliers(tillage_mults, idop)
phase = 3
end if
else
idpp = DaysPastPlanting(idop)
if (idpp < 15) then ! based on Point Chisel Tandem Disk multipliers
phase = 1
else if (idpp < 45) then ! based on Field and Row Cultivator multipliers
Expand Down

0 comments on commit f01adc6

Please sign in to comment.