MOM6
time_utils_mod Module Reference

Detailed Description

Set of time utilities for converting between FMS and ESMF time type.

Data Types

interface  esmf2fms_time
 Converts time from FMS to ESMF format. More...
 
interface  fms2esmf_cal
 Converts calendar from FMS to ESMF format. More...
 

Functions/Subroutines

type(esmf_calkind_flag) function fms2esmf_cal_c (calendar)
 Sets fms2esmf_cal_c to the corresponding ESMF calendar type. More...
 
type(esmf_calkind_flag) function fms2esmf_cal_i (calendar)
 Sets fms2esmf_cal_i to the corresponding ESMF calendar type. More...
 
type(time_type) function esmf2fms_time_t (time)
 Converts date from ESMF format to FMS format. More...
 
type(time_type) function esmf2fms_timestep (timestep)
 Converts time-interval from ESMF format to FMS format. More...
 
type(esmf_time) function, public fms2esmf_time (time, calkind)
 Converts date from FMS format to ESMF format. More...
 
type(time_type) function, public string_to_date (string, rc)
 Converts a string (I4.4,I2.2,I2.2,".",I2.2,I2.2,I2.2) that represents yr, mon, day, hr, min, sec to a FMS data format. More...
 

Function/Subroutine Documentation

◆ esmf2fms_time_t()

type(time_type) function time_utils_mod::esmf2fms_time_t ( type(esmf_time), intent(in)  time)
private

Converts date from ESMF format to FMS format.

Returns
FMS time structure
Parameters
[in]timeESMF time structure

Definition at line 82 of file time_utils.F90.

82  type(Time_type) :: esmf2fms_time_t !< FMS time structure
83  type(ESMF_Time), intent(in) :: time !< ESMF time structure
84 
85  ! Local Variables
86  integer :: yy, mm, dd, h, m, s
87  type(ESMF_CALKIND_FLAG) :: calkind
88 
89  integer :: rc
90 
91  call esmf_timeget(time, yy=yy, mm=mm, dd=dd, h=h, m=m, s=s, &
92  calkindflag=calkind, rc=rc)
93  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
94  line=__line__, &
95  file=__file__)) &
96  return ! bail out
97 
98  esmf2fms_time_t = set_date(yy, mm, dd, h, m, s)
99 

◆ esmf2fms_timestep()

type(time_type) function time_utils_mod::esmf2fms_timestep ( type(esmf_timeinterval), intent(in)  timestep)
private

Converts time-interval from ESMF format to FMS format.

Returns
FMS time structure
Parameters
[in]timesteptime-interval following ESMF format [s]

Definition at line 104 of file time_utils.F90.

104  type(Time_type) :: esmf2fms_timestep !< FMS time structure
105  type(ESMF_TimeInterval), intent(in):: timestep !< time-interval following
106  !! ESMF format [s]
107  ! Local Variables
108  integer :: s
109  type(ESMF_CALKIND_FLAG) :: calkind
110 
111  integer :: rc
112 
113  call esmf_timeintervalget(timestep, s=s, calkindflag=calkind, rc=rc)
114  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
115  line=__line__, &
116  file=__file__)) &
117  return ! bail out
118 
119  esmf2fms_timestep = set_time(s, 0)
120 

◆ fms2esmf_cal_c()

type(esmf_calkind_flag) function time_utils_mod::fms2esmf_cal_c ( character(len=*), intent(in)  calendar)
private

Sets fms2esmf_cal_c to the corresponding ESMF calendar type.

Returns
ESMF calendar type
Parameters
[in]calendarType of calendar

Definition at line 41 of file time_utils.F90.

41  type(ESMF_CALKIND_FLAG) :: fms2esmf_cal_c !< ESMF calendar type
42  character(len=*), intent(in) :: calendar !< Type of calendar
43 
44  select case( uppercase(trim(calendar)) )
45  case( 'GREGORIAN' )
46  fms2esmf_cal_c = esmf_calkind_gregorian
47  case( 'JULIAN' )
48  fms2esmf_cal_c = esmf_calkind_julian
49  case( 'NOLEAP' )
50  fms2esmf_cal_c = esmf_calkind_noleap
51  case( 'THIRTY_DAY' )
52  fms2esmf_cal_c = esmf_calkind_360day
53  case( 'NO_CALENDAR' )
54  fms2esmf_cal_c = esmf_calkind_nocalendar
55  case default
56  call mpp_error(fatal, &
57  'ocean_solo: ocean_solo_nml entry calendar must be one of GREGORIAN|JULIAN|NOLEAP|THIRTY_DAY|NO_CALENDAR.' )
58  end select

◆ fms2esmf_cal_i()

type(esmf_calkind_flag) function time_utils_mod::fms2esmf_cal_i ( integer, intent(in)  calendar)
private

Sets fms2esmf_cal_i to the corresponding ESMF calendar type.

Returns
ESMF calendar structure
Parameters
[in]calendarType of calendar

Definition at line 63 of file time_utils.F90.

63  type(ESMF_CALKIND_FLAG) :: fms2esmf_cal_i !< ESMF calendar structure
64  integer, intent(in) :: calendar !< Type of calendar
65 
66  select case(calendar)
67  case(thirty_day_months)
68  fms2esmf_cal_i = esmf_calkind_360day
69  case(gregorian)
70  fms2esmf_cal_i = esmf_calkind_gregorian
71  case(julian)
72  fms2esmf_cal_i = esmf_calkind_julian
73  case(noleap)
74  fms2esmf_cal_i = esmf_calkind_noleap
75  case(no_calendar)
76  fms2esmf_cal_i = esmf_calkind_nocalendar
77  end select

◆ fms2esmf_time()

type(esmf_time) function, public time_utils_mod::fms2esmf_time ( type(time_type), intent(in)  time,
type(esmf_calkind_flag), intent(in), optional  calkind 
)

Converts date from FMS format to ESMF format.

Returns
ESMF time structure
Parameters
[in]timeFMS time structure
[in]calkindESMF calendar structure

Definition at line 125 of file time_utils.F90.

125  type(ESMF_Time) :: fms2esmf_time !< ESMF time structure
126  type(time_type), intent(in) :: time !< FMS time structure
127  type(ESMF_CALKIND_FLAG), intent(in), optional :: calkind !< ESMF calendar structure
128 
129  ! Local Variables
130  integer :: yy, mm, d, h, m, s
131  type(ESMF_CALKIND_FLAG) :: l_calkind
132 
133  integer :: rc
134 
135  if(present(calkind)) then
136  l_calkind = calkind
137  else
138  l_calkind = fms2esmf_cal(fms_get_calendar_type())
139  endif
140 
141  call get_date(time, yy, mm, d, h, m, s)
142 
143  call esmf_timeset(fms2esmf_time, yy=yy, mm=mm, d=d, h=h, m=m, s=s, &
144  calkindflag=l_calkind, rc=rc)
145  if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
146  line=__line__, &
147  file=__file__)) &
148  return ! bail out
149 

◆ string_to_date()

type(time_type) function, public time_utils_mod::string_to_date ( character(len=15), intent(in)  string,
integer, intent(out), optional  rc 
)

Converts a string (I4.4,I2.2,I2.2,".",I2.2,I2.2,I2.2) that represents yr, mon, day, hr, min, sec to a FMS data format.

Parameters
[in]stringString representing a date
[out]rcESMF error handler
Returns
FMS time structure

Definition at line 155 of file time_utils.F90.

155  character(len=15), intent(in) :: string !< String representing a date
156  integer, intent(out), optional :: rc !< ESMF error handler
157  type(time_type) :: string_to_date!< FMS time structure
158 
159  ! Local variables
160  integer :: yr,mon,day,hr,min,sec
161 
162  if(present(rc)) rc = esmf_success
163 
164  read(string, '(I4.4,I2.2,I2.2,".",I2.2,I2.2,I2.2)') yr, mon, day, hr, min, sec
165  string_to_date = set_date(yr, mon, day, hr, min, sec)
166