Skip to content

Commit

Permalink
Merge pull request #1 from glemieux/ckoven-fates_landuse-model-day-fix
Browse files Browse the repository at this point in the history
Reinstate hlm_model_day fix from CTSM PR 820
  • Loading branch information
ckoven authored Jul 23, 2020
2 parents c59f7d6 + d39224c commit c2d497d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Externals_CLM.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local_path = src/fates
protocol = git
repo_url = https://github.com/NGEET/fates
tag = sci.1.36.0_api.11.2.0
tag = sci.1.40.0_api.13.0.0
required = True

[PTCLM]
Expand Down
105 changes: 72 additions & 33 deletions src/utils/clmfates_interfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ module CLMFatesInterfaceMod
! developer will at least question its usage (RGK)
private :: hlm_bounds_to_fates_bounds

! The GetAndSetTime function is used to get the current time from the CLM
! time procedures and then set to the fates global time variables during restart,
! init_coldstart, and dynamics_driv function calls
private :: GetAndSetTime

logical :: debug = .false.

character(len=*), parameter, private :: sourcefile = &
Expand Down Expand Up @@ -659,22 +664,8 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
integer :: g ! gridcell index (HLM)
integer :: ifp ! patch index
integer :: p ! HLM patch index
integer :: yr ! year (0, ...)
integer :: mon ! month (1, ..., 12)
integer :: day ! day of month (1, ..., 31)
integer :: sec ! seconds of the day
integer :: nlevsoil ! number of soil layers at the site
integer :: nld_si ! site specific number of decomposition layers
integer :: current_year
integer :: current_month
integer :: current_day
integer :: current_tod
integer :: current_date
integer :: jan01_curr_year
integer :: reference_date
integer :: days_per_year
real(r8) :: model_day
real(r8) :: day_of_year
integer :: begg,endg
real(r8) :: harvest_rates(bounds_clump%begg:bounds_clump%endg,num_harvest_inst)
logical :: after_start_of_harvest_ts
Expand All @@ -692,30 +683,16 @@ subroutine dynamics_driv(this, nc, bounds_clump, &

begg = bounds_clump%begg; endg = bounds_clump%endg

days_per_year = get_days_per_year()
call get_curr_date(current_year,current_month,current_day,current_tod)
current_date = current_year*10000 + current_month*100 + current_day
jan01_curr_year = current_year*10000 + 100 + 1

call get_ref_date(yr, mon, day, sec)
reference_date = yr*10000 + mon*100 + day

call timemgr_datediff(reference_date, sec, current_date, current_tod, model_day)

call timemgr_datediff(jan01_curr_year,0,current_date,sec,day_of_year)

call SetFatesTime(current_year, current_month, &
current_day, current_tod, &
current_date, reference_date, &
model_day, floor(day_of_year), &
days_per_year, 1.0_r8/dble(days_per_year))
! Set the FATES global time and date variables
call GetAndSetTime

if (get_do_harvest()) then
call dynHarvest_interp_resolve_harvesttypes(bounds_clump, &
harvest_rates=harvest_rates(begg:endg,1:num_harvest_inst), &
after_start_of_harvest_ts=after_start_of_harvest_ts)
endif


do s=1,this%fates(nc)%nsites

c = this%f2hmap(nc)%fcolumn(s)
Expand Down Expand Up @@ -1097,6 +1074,9 @@ subroutine restart( this, bounds_proc, ncid, flag, waterstate_inst, &
! I think that is it...
! ---------------------------------------------------------------------------------

! Set the FATES global time and date variables
call GetAndSetTime

if(.not.initialized) then

initialized=.true.
Expand Down Expand Up @@ -1300,8 +1280,6 @@ subroutine restart( this, bounds_proc, ncid, flag, waterstate_inst, &
this%fates(nc)%sites, &
this%fates(nc)%bc_out)



! ------------------------------------------------------------------------
! Update history IO fields that depend on ecosystem dynamics
! ------------------------------------------------------------------------
Expand Down Expand Up @@ -1343,6 +1321,10 @@ subroutine init_coldstart(this, waterstate_inst, canopystate_inst, soilstate_ins
integer :: s
integer :: c


! Set the FATES global time and date variables
call GetAndSetTime

nclumps = get_proc_clumps()

!$OMP PARALLEL DO PRIVATE (nc,bounds_clump,s,c,j,vol_ice,eff_porosity)
Expand Down Expand Up @@ -2576,4 +2558,61 @@ subroutine hlm_bounds_to_fates_bounds(hlm, fates)

end subroutine hlm_bounds_to_fates_bounds

! ======================================================================================

subroutine GetAndSetTime()

! CLM MODULES
use clm_time_manager , only : get_days_per_year, &
get_curr_date, &
get_ref_date, &
timemgr_datediff

! FATES MODULES
use FatesInterfaceMod , only : SetFatesTime

! LOCAL VARIABLES
integer :: yr ! year (0, ...)
integer :: mon ! month (1, ..., 12)
integer :: day ! day of month (1, ..., 31)
integer :: sec ! seconds of the day
integer :: current_year
integer :: current_month
integer :: current_day
integer :: current_tod
integer :: current_date
integer :: jan01_curr_year
integer :: reference_date
integer :: days_per_year
real(r8) :: model_day
real(r8) :: day_of_year


! Get the current date and determine the set the start of the current year
call get_curr_date(current_year,current_month,current_day,current_tod)
current_date = current_year*10000 + current_month*100 + current_day
jan01_curr_year = current_year*10000 + 100 + 1

! Get the reference date components and compute the date
call get_ref_date(yr, mon, day, sec)
reference_date = yr*10000 + mon*100 + day

! Get the defined number of days per year
days_per_year = get_days_per_year()

! Determine the model day
call timemgr_datediff(reference_date, sec, current_date, current_tod, model_day)

! Determine the current DOY
call timemgr_datediff(jan01_curr_year,0,current_date,sec,day_of_year)

! Set the FATES global time variables
call SetFatesTime(current_year, current_month, &
current_day, current_tod, &
current_date, reference_date, &
model_day, floor(day_of_year), &
days_per_year, 1.0_r8/dble(days_per_year))

end subroutine GetAndSetTime

end module CLMFatesInterfaceMod

0 comments on commit c2d497d

Please sign in to comment.