Skip to content

Commit

Permalink
Fix time overflow issue with redsea gulf bay timing "fix" (mom-ocean#246
Browse files Browse the repository at this point in the history
)

* Fix overflow in time in redsea gulf bay salinity fix
  • Loading branch information
aidanheerdegen authored Sep 4, 2018
1 parent 2572982 commit afe80bf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 25 deletions.
36 changes: 26 additions & 10 deletions src/accesscm_coupler/ocean_solo.F90
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ program main
use mpp_mod, only: MPP_CLOCK_DETAILED, CLOCK_COMPONENT, MAXPES
use time_interp_external_mod, only: time_interp_external_init
use time_manager_mod, only: set_calendar_type, time_type, increment_date
use time_manager_mod, only: set_time, set_date, get_time, get_date, month_name
use time_manager_mod, only: set_time, set_date, get_time, get_date, month_name, print_time
use time_manager_mod, only: GREGORIAN, JULIAN, NOLEAP, THIRTY_DAY_MONTHS, NO_CALENDAR
use time_manager_mod, only: operator( <= ), operator( < ), operator( >= )
use time_manager_mod, only: operator( + ), operator( - ), operator( / )
Expand Down Expand Up @@ -367,17 +367,33 @@ program main
call ocean_model_init(Ocean_sfc, Ocean_state, Time_init, Time)

#ifdef ACCESS
! This must be called after ocean_model_init so sfix_hours is read in from namelist
sfix_seconds = sfix_hours * SECONDS_PER_HOUR
! Get current model time from Time_init in seconds (must be done like this otherwise
! can get an overflow in seconds)
call get_time(Time-Time_init,seconds)
! The last sfix time has to be determined from absolute model time, to ensure reproducibility
! across restarts
Time_last_sfix = set_time(seconds=int(seconds/sfix_seconds)*sfix_seconds) + Time_init
Time_sfix = set_time(seconds=int(sfix_seconds))
if (redsea_gulfbay_sfix) then
! This must be called after ocean_model_init so sfix_hours is read in from namelist
sfix_seconds = sfix_hours * SECONDS_PER_HOUR
! Get current model time from Time_init in seconds (must be done like this otherwise
! can get an overflow in seconds)
call get_time(Time-Time_init,seconds=seconds,days=days)
! The last sfix time has to be determined from absolute model time, to ensure reproducibility
! across restarts

! Current time to nearest hour
hours = days*24 + int(seconds/SECONDS_PER_HOUR)

! Time of last sfix
hours = int(hours / sfix_hours) * sfix_hours

! Convert to days + hours
days = int(hours / 24)
hours = hours - days*24

Time_last_sfix = set_time(days=int(days),seconds=int(hours*SECONDS_PER_HOUR)) + Time_init
Time_sfix = set_time(seconds=int(sfix_seconds))

call print_time(Time_last_sfix,'Time_last_sfix: ')
end if
#endif


call data_override_init(Ocean_domain_in = Ocean_sfc%domain)

override_clock = mpp_clock_id('Override', flags=flags,grain=CLOCK_COMPONENT)
Expand Down
47 changes: 32 additions & 15 deletions src/accessom_coupler/ocean_solo.F90
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,30 @@ program main
accessom2%get_ice_ocean_timestep())

#ifdef ACCESS
! This must be called after ocean_model_init so sfix_hours is read in from namelist
sfix_seconds = sfix_hours * SECONDS_PER_HOUR
! Get current model time from Time_init in seconds (must be done like this otherwise
! can get an overflow in seconds)
call get_time(Time-Time_init,seconds)
! The last sfix time has to be determined from absolute model time, to ensure reproducibility
! across restarts
Time_last_sfix = set_time(seconds=int(seconds/sfix_seconds)*sfix_seconds) + Time_init
Time_sfix = set_time(seconds=int(sfix_seconds))
if (redsea_gulfbay_sfix) then
! This must be called after ocean_model_init so sfix_hours is read in from namelist
sfix_seconds = sfix_hours * SECONDS_PER_HOUR
! Get current model time from Time_init in seconds (must be done like this otherwise
! can get an overflow in seconds)
call get_time(Time-Time_init,seconds=seconds,days=days)
! The last sfix time has to be determined from absolute model time, to ensure reproducibility
! across restarts

! Current time to nearest hour
hours = days*24 + int(seconds/SECONDS_PER_HOUR)

! Time of last sfix
hours = int(hours / sfix_hours) * sfix_hours

! Convert to days + hours
days = int(hours / 24)
hours = hours - days*24

Time_last_sfix = set_time(days=int(days),seconds=int(hours*SECONDS_PER_HOUR)) + Time_init
Time_sfix = set_time(seconds=int(sfix_seconds))

call print_time(Time_last_sfix,'Time_last_sfix: ')
end if
#endif

call data_override_init(Ocean_domain_in = Ocean_sfc%domain)
Expand Down Expand Up @@ -427,12 +442,14 @@ program main
endif

#ifdef ACCESS
if ((Time - Time_last_sfix) >= Time_sfix) then
do_sfix_now = .true.
Time_last_sfix = Time
else
do_sfix_now = .false.
end if
if (redsea_gulfbay_sfix) then
if ((Time - Time_last_sfix) >= Time_sfix) then
do_sfix_now = .true.
Time_last_sfix = Time
else
do_sfix_now = .false.
end if
end if
#endif

call update_ocean_model(Ice_ocean_boundary, Ocean_state, Ocean_sfc, Time, Time_step_coupled)
Expand Down

0 comments on commit afe80bf

Please sign in to comment.