subroutine ESMF_TimeIntervalSetStr(timeinterval, timeIntervalString, rc)
! !ARGUMENTS:
type(ESMF_TimeInterval), intent(inout) :: timeinterval
character(*), intent(in) :: timeIntervalString
integer, intent(out), optional :: rc
!
!
! !DESCRIPTION:
! Sets the value of an {\tt ESMF\_TimeInterval} using a
! string in ISO 8601 duration format P[y]Y[mm]M[d]DT[h]H[m]M[s]S. See ~\cite{ISO} and ~\cite{ISOnotes} for information about the format. In ESMF's implementation the time values can have the following types:
! \begin{description}
! \item[y] - the number of years expressed in up to a 64-bit integer
! \item[mm] - the number of months expressed in up to a 64-bit integer
! \item[d] - the number of days expressed in up to a 64-bit integer or a 64-bit floating point value (double)
! \item[h] - the number of hours expressed in up to a 32-bit integer or a 64-bit floating point value (double)
! \item[m] - the number of minutes expressed in up to a 32-bit integer or a 64-bit floating point value (double)
! \item[s] - the number of seconds expressed in up to a 64-bit integer or a 64-bit floating point value (double)
! \end{description}
!
! As with the ISO format, in ESMF's implementation the specifier and value can be left out if the value is 0. For example, P1YT1H3M4S is a valid format if the number of months and
! days are both 0. The time part including the T can also be left off if the time values are all 0, so P1Y is a valid string if just 1 year is being specified.
!
! The arguments are:
! \begin{description}
! \item[timeinterval]
! The object instance to initialize.
! \item[timeIntervalString]
! ISO 8601 format duration string (e.g. P[y]Y[mm]M[d]DT[h]H[m]M[s]S).
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
! !REQUIREMENTS:
! TMGn.n.n
integer :: localrc ! local return code
integer(ESMF_KIND_I8) :: yy_i8
integer(ESMF_KIND_I8) :: mm_i8
integer(ESMF_KIND_I8) :: d_i8
integer(ESMF_KIND_I8) :: s_i8
real(ESMF_KIND_R8) :: d_r8
real(ESMF_KIND_R8) :: h_r8
real(ESMF_KIND_R8) :: m_r8
real(ESMF_KIND_R8) :: s_r8
! Assume failure until success
if (present(rc)) rc = ESMF_RC_NOT_IMPL
localrc = ESMF_RC_NOT_IMPL
! Parse string into values for each time unit
call ESMF_ParseDurString(timeintervalString, &
yy_i8=yy_i8, mm_i8=mm_i8, d_i8=d_i8, d_r8=d_r8, &
h_r8=h_r8, m_r8=m_r8, s_i8=s_i8, s_r8=s_r8, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Set time interval using time unit values parsed above
! NOTE: Just use I8 for integer values, since it looks like integer values
! are stored that way anyway. Also, for times (h,m,s), it looks like both R8
! and I8 are added together, so you can just
! use both and whichever isn't needed set to 0.
! An R8 can exactly represent an I4, so just use R8 for hours and minutes
! where an I4 is all that's available.
call ESMF_TimeIntervalSetDur(timeinterval, &
yy_i8=yy_i8, &
mm_i8=mm_i8, &
d_i8=d_i8, &
s_i8=s_i8, &
d_r8=d_r8, &
h_r8=h_r8, &
m_r8=m_r8, &
s_r8=s_r8, &
rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_TimeIntervalSetStr