Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | string | |||
type(ESMF_KeywordEnforcer), | optional | :: | keywordEnforcer | |||
integer, | intent(out), | optional | :: | rc |
function ESMF_UtilString2Double(string, keywordEnforcer, rc) ! !RETURN VALUE: real(ESMF_KIND_R8) :: ESMF_UtilString2Double ! !ARGUMENTS: character(len=*), intent(in) :: string type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below integer, intent(out), optional :: rc ! !DESCRIPTION: ! Return the numerical real value represented by the {\tt string}. ! ! Leading and trailing blanks in {\tt string} are ignored when directly ! converting into integers. ! ! This procedure may fail when used in an expression in a {\tt write} statement ! with some older, pre-Fortran 2003, compiler environments that do not support ! re-entrant I/O calls. ! ! The arguments are: ! \begin{description} ! \item[string] ! The string to be converted ! \item[{[rc]}] ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors. ! \end{description} ! !EOPI !----------------------------------------------------------------------------- ! local variables integer :: ioerr if (present(rc)) rc = ESMF_SUCCESS ESMF_UtilString2Double = 0 ! initialize if (verify(trim(adjustl(string)),".-+0123456789de") == 0) then ! should convert to real just fine read (string, *, iostat=ioerr) ESMF_UtilString2Double if (ioerr /= 0) then call ESMF_LogSetError(ESMF_RC_ARG_BAD, & msg="The string '"//trim(string)//"' could not be converted to double.", & line=__LINE__, & file=ESMF_FILENAME, & rcToReturn=rc) return ! bail out end if else ! the string contains characters besides numbers call ESMF_LogSetError(ESMF_RC_ARG_BAD, & msg="The string '"//trim(string)//"' contains characters besides "// & "numbers, cannot convert to double.", & line=__LINE__, & file=ESMF_FILENAME, & rcToReturn=rc) return ! bail out endif end function ESMF_UtilString2Double