MOM6
MOM_time_manager.F90
Go to the documentation of this file.
1 !> Wraps the FMS time manager functions
3 
4 ! This file is part of MOM6. See LICENSE.md for the license.
5 
6 use time_manager_mod, only : time_type, get_time, set_time
7 use time_manager_mod, only : time_type_to_real, real_to_time_type
8 use time_manager_mod, only : operator(+), operator(-), operator(*), operator(/)
9 use time_manager_mod, only : operator(>), operator(<), operator(>=), operator(<=)
10 use time_manager_mod, only : operator(==), operator(/=), operator(//)
11 use time_manager_mod, only : set_ticks_per_second , get_ticks_per_second
12 use time_manager_mod, only : get_date, set_date, increment_date
13 use time_manager_mod, only : days_in_month, month_name
14 use time_manager_mod, only : set_calendar_type, get_calendar_type
15 use time_manager_mod, only : julian, noleap, thirty_day_months, gregorian
16 use time_manager_mod, only : no_calendar
17 use time_interp_external_mod, only : init_external_field, time_interp_external, time_interp_external_init
18 use time_interp_external_mod, only : get_external_field_size
19 use time_interp_external_mod, only : get_external_field_axes, get_external_field_missing
20 
21 implicit none ; private
22 
23 public :: time_type, get_time, set_time
24 public :: time_type_to_real, real_to_time_type, real_to_time
25 public :: set_ticks_per_second, get_ticks_per_second
26 public :: operator(+), operator(-), operator(*), operator(/)
27 public :: operator(>), operator(<), operator(>=), operator(<=)
28 public :: operator(==), operator(/=), operator(//)
29 public :: get_date, set_date, increment_date, month_name, days_in_month
30 public :: julian, noleap, thirty_day_months, gregorian, no_calendar
31 public :: set_calendar_type, get_calendar_type
32 public :: init_external_field
33 public :: time_interp_external
34 public :: time_interp_external_init
35 public :: get_external_field_size
36 public :: get_external_field_axes
37 public :: get_external_field_missing
38 
39 contains
40 
41 !> This is an alternate implementation of the FMS function real_to_time_type that is accurate over
42 !! a larger range of input values. With 32 bit signed integers, this version should work over the
43 !! entire valid range (2^31 days or ~5.8835 million years) of time_types, whereas the standard
44 !! version in the FMS time_manager stops working for conversions of times greater than 2^31 seconds,
45 !! or ~68.1 years.
46 function real_to_time(x, err_msg)
47  type(time_type) :: real_to_time !< The output time as a time_type
48  real, intent(in) :: x !< The input time in real seconds.
49  character(len=*), intent(out), optional :: err_msg !< An optional returned error message.
50 
51  ! Local variables
52  integer :: seconds, days, ticks
53  real :: real_subsecond_remainder
54 
55  days = floor(x/86400.)
56  seconds = floor(x - 86400.*days)
57  real_subsecond_remainder = x - (days*86400. + seconds)
58  ticks = nint(real_subsecond_remainder * get_ticks_per_second())
59 
60  real_to_time = set_time(seconds=seconds, days=days, ticks=ticks, err_msg=err_msg)
61 end function real_to_time
62 
63 
64 end module mom_time_manager
mom_time_manager
Wraps the FMS time manager functions.
Definition: MOM_time_manager.F90:2
mom_time_manager::real_to_time
type(time_type) function, public real_to_time(x, err_msg)
This is an alternate implementation of the FMS function real_to_time_type that is accurate over a lar...
Definition: MOM_time_manager.F90:47