test_convert_NetCDF_DateTime_to_ESMF_integer Subroutine

public subroutine test_convert_NetCDF_DateTime_to_ESMF_integer()

Arguments

None

Calls

proc~~test_convert_netcdf_datetime_to_esmf_integer~~CallsGraph proc~test_convert_netcdf_datetime_to_esmf_integer test_convert_NetCDF_DateTime_to_ESMF_integer ESMF_TimeGet ESMF_TimeGet proc~test_convert_netcdf_datetime_to_esmf_integer->ESMF_TimeGet ESMF_TimeSet ESMF_TimeSet proc~test_convert_netcdf_datetime_to_esmf_integer->ESMF_TimeSet asserttrue asserttrue proc~test_convert_netcdf_datetime_to_esmf_integer->asserttrue interface~get_esmf_time_from_netcdf_datetime get_ESMF_Time_from_NetCDF_DateTime proc~test_convert_netcdf_datetime_to_esmf_integer->interface~get_esmf_time_from_netcdf_datetime proc~esmf_times_equal ESMF_Times_Equal proc~test_convert_netcdf_datetime_to_esmf_integer->proc~esmf_times_equal proc~esmf_times_equal->ESMF_TimeGet proc~rational_equals rational_equals proc~esmf_times_equal->proc~rational_equals

Source Code

   subroutine test_convert_NetCDF_DateTime_to_ESMF_integer()
      integer :: duration
      integer :: yy, mm, dd, h, m, s, m_time
      character(len=*), parameter :: UNITS = 'seconds' 
      character(len=*), parameter :: NOT_EQUAL = ' /= '
      character(len=:), allocatable :: tunit, units_string
      type(ESMF_Time) :: time, etime, btime, ebtime
      type(ESMF_TimeInterval) :: time_interval
      character(len=ESMF_MAXSTR) :: expected_base_datetime_string
      character(len=ESMF_MAXSTR) :: expected_datetime_string
      character(len=ESMF_MAXSTR) :: actual_base_datetime_string
      character(len=ESMF_MAXSTR) :: actual_datetime_string
      character(len=:), allocatable :: msg_time, msg_base_time, msg_tunit
      integer :: status

      yy = 1999
      mm = 12
      dd = 31
      h = 23
      m = 29
      m_time = 59
      s = 59
      duration = ( m_time - m ) * SECONDS_PER_MINUTE
      units_string = UNITS // ' since 1999-12-31 23:29:59'

      call ESMF_TimeSet(etime, yy=yy, mm=mm, dd=dd, h=h, m=m_time, s=s, rc=status)
      @assertTrue(status == _SUCCESS, 'Unable to create expected ESMF_Time')
      call ESMF_TimeGet(etime, timeString = expected_datetime_string, rc=status)

      call ESMF_TimeSet(ebtime, yy=yy, mm=mm, dd=dd, h=h, m=m, s=s, rc=status)
      @assertTrue(status == _SUCCESS, 'Unable to create expected base ESMF_Time')
      call ESMF_TimeGet(ebtime, timeString = expected_base_datetime_string, rc=status)

      call get_ESMF_Time_from_NetCDF_DateTime(duration, units_string, time_interval, btime, &
         time = time, time_unit = tunit, rc = status)
      @assertTrue(status == _SUCCESS, 'Conversion failed')
      call ESMF_TimeGet(btime, timeString = actual_base_datetime_string, rc=status)
      call ESMF_TimeGet(time, timeString = actual_datetime_string, rc=status)
      msg_time = trim(actual_datetime_string) // NOT_EQUAL // trim(expected_datetime_string)
      msg_base_time = trim(actual_base_datetime_string) // NOT_EQUAL // trim(expected_base_datetime_string)
      msg_tunit = trim(tunit) // NOT_EQUAL // trim(UNITS)

      @assertTrue(ESMF_Times_Equal(ebtime, btime), 'base ESMF_Time values do not match: ' // msg_base_time)
      @assertTrue(trim(tunit) == trim(UNITS), "Time units don't match: " // msg_tunit)
      @assertTrue(ESMF_Times_Equal(etime, time), 'ESMF_Time values do not match: ' // msg_time)

   end subroutine test_convert_NetCDF_DateTime_to_ESMF_integer