subroutine ESMF_ParseDurString(timeintervalString, &
yy_i8, mm_i8, d_i8, d_r8, &
h_r8, m_r8, s_i8, s_r8, rc)
character(*), intent(in) :: timeIntervalString
integer(ESMF_KIND_I8), intent(out) :: yy_i8
integer(ESMF_KIND_I8), intent(out) :: mm_i8
integer(ESMF_KIND_I8), intent(out) :: d_i8
real(ESMF_KIND_R8), intent(out) :: d_r8
real(ESMF_KIND_R8), intent(out) :: h_r8
real(ESMF_KIND_R8), intent(out) :: m_r8
integer(ESMF_KIND_I8), intent(out) :: s_i8
real(ESMF_KIND_R8), intent(out) :: s_r8
integer, intent(out), optional :: rc
integer :: localrc
integer :: beg_loc, end_loc
integer :: t_loc
! Init output to 0
! NOTE: Need to do all of these here in case date or time parsing isn't done below
yy_i8=0
mm_i8=0
d_i8=0
d_r8=0.0
h_r8=0.0
m_r8=0.0
s_r8=0.0
s_i8=0
! Make sure P is there and find beginning of string
beg_loc=INDEX(timeIntervalString,"P")
! Complain if it doesn't start with P
if (beg_loc < 1) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" ISO 8601 duration strings need to begin with: P", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Advance to slot after P
beg_loc=beg_loc+1
! See if T is there and if so where
t_loc=0
t_loc=INDEX(timeIntervalString,"T")
! Figure out end_loc
if (t_loc == 0) then
! No times, so end is the end of the string
end_loc=LEN(timeIntervalString)
else
! There are times so end is right before t
end_loc=t_loc-1
endif
! If not empty, parse just the date part of the string
if (beg_loc <= end_loc) then
call ESMF_ParseDurDateString(timeintervalString(beg_loc:end_loc), &
yy_i8, mm_i8, d_i8, d_r8, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
! If there are times, then parse those
if (t_loc > 0) then
! Begin is after t
beg_loc=t_loc+1
! End is end of string
end_loc=LEN(timeIntervalString)
! If not empty, parse just the time part of the string
if (beg_loc <= end_loc) then
call ESMF_ParseDurTimeString(timeintervalString(beg_loc:end_loc), &
h_r8, m_r8, s_i8, s_r8, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
endif
! Return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_ParseDurString