Skip to content

Commit

Permalink
Merge pull request ESCOMP#12 from billsacks/agsys
Browse files Browse the repository at this point in the history
Add subroutine to determine when planting happens
  • Loading branch information
pengbinpeluo authored Nov 15, 2019
2 parents ec6b5f0 + 7d60fbb commit 0132c9f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/agsys/ctsm_interface/AgSysInterface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module AgSysInterface
use AgSysRuntimeConstants, only : InitRuntimeConstants
use AgSysCropTypeGeneric, only : agsys_cultivars_of_crop_type
use AgSysRoot, only : get_soil_condition
use AgSysPhenology, only : AgSysRunPhenology
use AgSysPhenology, only : AgSysDeterminePlanting, AgSysRunPhenology
!
implicit none
private
Expand Down Expand Up @@ -113,15 +113,25 @@ subroutine AgSysDriver(this, num_pcropp, filter_pcropp, &
c = patch%column(p)
cultivar_type = this%agsys_inst%cultivar_patch(p)

call this%agsys_inst%agsys_environmental_inputs%SetSpatiallyVaryingValues( &
photoperiod = grc%dayl(g), &
tair_max = temperature_inst%t_ref2m_max_patch(p), &
tair_min = temperature_inst%t_ref2m_min_patch(p), &
tc_24hr = temperature_inst%t_veg24_patch(p), &
h2osoi_liq_24hr = this%agsys_inst%h2osoi_liq_24hr_col(c, 1:nlevsoi))

if (.not. this%agsys_inst%crop_alive_patch(p)) then
call AgSysDeterminePlanting( &
! Inputs
env = this%agsys_inst%agsys_environmental_inputs, &
latdeg = grc%latdeg(g), &

! Outputs
crop_alive = this%agsys_inst%crop_alive_patch(p), &
current_stage = this%agsys_inst%current_stage_patch(p))
end if

if (this%agsys_inst%crop_alive_patch(p)) then
call this%agsys_inst%agsys_environmental_inputs%SetSpatiallyVaryingValues( &
photoperiod = grc%dayl(g), &
tair_max = temperature_inst%t_ref2m_max_patch(p), &
tair_min = temperature_inst%t_ref2m_min_patch(p), &
tc_24hr = temperature_inst%t_veg24_patch(p), &
h2osoi_liq_24hr = this%agsys_inst%h2osoi_liq_24hr_col(c, 1:nlevsoi))

call get_soil_condition( &
crop = this%crops(crop_type)%cultivars(cultivar_type), &
Expand Down
37 changes: 37 additions & 0 deletions src/agsys/science/AgSysPhenology.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,49 @@ module AgSysPhenology
implicit none
private

public :: AgSysDeterminePlanting
public :: AgSysRunPhenology

contains
!---------------------------------------------------------------
!Some subroutines
!
subroutine AgSysDeterminePlanting(env, latdeg, &
crop_alive, current_stage)
!!---------------------------------------------------------
!!Determine if it's time to plant; if so, set crop_alive and current_stage
!!
!!This should only be called if crop_alive is currently false
!
!!The logic here assumes this is called once per day, so that there will be a day
!!that falls exactly on a given threshold value
!!---------------------------------------------------------
!!INPUTS: time varying forcing variables from hosting land model
type (agsys_environmental_inputs_type), intent(in) :: env
real(r8), intent(in) :: latdeg ! latitude (degrees)

!!OUTPUTS: state variables
logical, intent(inout) :: crop_alive !!whether the crop is alive (true between planting and sowing)
real(r8), intent(inout) :: current_stage !!current stage number
!-------------------------------
logical :: time_to_plant

time_to_plant = .false.
if (latdeg >= 0._r8) then
if (env%calday == 135) then
time_to_plant = .true.
end if
else
if (env%calday == 318) then
time_to_plant = .true.
end if
end if

if (time_to_plant) then
crop_alive = .true.
current_stage = 1._r8
end if
end subroutine AgSysDeterminePlanting

subroutine AgSysRunPhenology(crop, env, soil_cond, &
crop_alive, days_after_sowing, current_stage, days_in_phase, tt_in_phase, &
Expand Down

0 comments on commit 0132c9f

Please sign in to comment.