subroutine ESMF_ParseDurDateString(timeintervalString, &
yy_i8, mm_i8, d_i8, d_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
integer, intent(out), optional :: rc
integer :: localrc
integer :: beg_loc, end_loc
integer :: t_loc
integer :: ioStatus
! Init output to 0
yy_i8=0
mm_i8=0
d_i8=0
d_r8=0.0
! Start at the beginning of the string
beg_loc=1
! Look for Y (year), and if it exists process it
end_loc=INDEX(timeIntervalString,"Y")
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=" Y value missing in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Read year value
read(timeIntervalString(beg_loc:end_loc), *, ioStat=ioStatus) yy_i8
if (ioStatus /=0) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" An error occurred while reading Y 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 (month), and if it exists process it
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) mm_i8
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 D (days), and if it exists process it
end_loc=INDEX(timeIntervalString,"D")
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=" D value missing in ISO duration string.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Read day 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) d_i8
else
read(timeIntervalString(beg_loc:end_loc), *, ioStat=ioStatus) d_r8
endif
if (ioStatus /=0) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_VALUE, &
msg=" An error occurred while reading D 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(*,*) "Year value=",yy_i8
! write(*,*) "Month value=",mm_i8
! write(*,*) "Days value (I8)=",d_i8
! write(*,*) "Days value (R8)=",d_r8
! Return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_ParseDurDateString