subroutine ESMF_ParseDurTimeString(timeintervalString, &
h_r8, m_r8, s_i8, s_r8, rc)
character(*), intent(in) :: timeIntervalString
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
integer :: ioStatus
! Init output to 0
h_r8=0.0
m_r8=0.0
s_r8=0.0
s_i8=0
! Start at the beginning of the string
beg_loc=1
! Look for H (hours), and if it exists process it
! Use R8 for both real and integer, since R8 can exactly represent I4
end_loc=INDEX(timeIntervalString,"H")
if (end_loc > 0) then
! Shift position before Y for end loc
end_loc=end_loc-1
! Make sure that it isn't empty
if (end_loc < beg_loc) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" H value missing in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Read year value
read(timeIntervalString(beg_loc:end_loc), *, ioStat=ioStatus) h_r8
if (ioStatus /=0) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" An error occurred while reading H value in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! New beg_loc is after indicator
beg_loc=end_loc+2
endif
! Look for M (minutes), and if it exists process it
! Use R8 for both real and integer, since R8 can exactly represent I4
end_loc=INDEX(timeIntervalString,"M")
if (end_loc > 0) then
! Shift position before M for end loc
end_loc=end_loc-1
! Make sure that it isn't empty
if (end_loc < beg_loc) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" M value missing in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Read year value
read(timeIntervalString(beg_loc:end_loc), *, ioStat=ioStatus) m_r8
if (ioStatus /=0) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" An error occurred while reading M value in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! New beg_loc is after indicator
beg_loc=end_loc+2
endif
! Look for S (seconds), and if it exists process it
end_loc=INDEX(timeIntervalString,"S")
if (end_loc > 0) then
! Shift position before M for end loc
end_loc=end_loc-1
! Make sure that it isn't empty
if (end_loc < beg_loc) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" S value missing in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Read second value depending on if it looks like an integer or a real
if (VERIFY(timeIntervalString(beg_loc:end_loc),"+-0123456789") == 0) then
read(timeIntervalString(beg_loc:end_loc), *, ioStat=ioStatus) s_i8
else
read(timeIntervalString(beg_loc:end_loc), *, ioStat=ioStatus) s_r8
endif
if (ioStatus /=0) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" An error occurred while reading S value in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! New beg_loc is after indicator
beg_loc=end_loc+2
endif
! DEBUG OUTPUT
! write(*,*) "Hour value=",h_r8
! write(*,*) "Minute value=",m_r8
! write(*,*) "Seconds value=",s_r8
! write(*,*) "Seconds value=",s_i8
! Return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_ParseDurTimeString