Skip to content

Commit

Permalink
Merge pull request #820 from glemieux/fates_next_api-model-day-fix
Browse files Browse the repository at this point in the history
Fates next api uninitialized hlm_model_day fix
  • Loading branch information
rgknox authored Dec 16, 2019
2 parents 9c12e40 + f6f871b commit 978068a
Showing 1 changed file with 72 additions and 34 deletions.
106 changes: 72 additions & 34 deletions src/utils/clmfates_interfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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 @@ -579,22 +584,9 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
integer :: c ! column 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

!-----------------------------------------------------------------------

! ---------------------------------------------------------------------------------
Expand All @@ -606,24 +598,8 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
! and it keeps all the boundaries in one location
! ---------------------------------------------------------------------------------

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

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

Expand Down Expand Up @@ -989,6 +965,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 @@ -1176,8 +1155,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 @@ -1219,6 +1196,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 @@ -2406,4 +2387,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 978068a

Please sign in to comment.