string_to_double Function

private function string_to_double(str) result(rval)

Arguments

Type IntentOptional AttributesName
character(kind=CK,len=*), intent(in) :: str

Return Value real(kind=RK)

Description

Convert a string into a double.

History

  • Jacob Williams, 10/27/2015 : Now using fmt=*, rather than fmt=real_fmt, since it doesn't work for some unusual cases (e.g., when str='1E-5').

Calls

proc~~string_to_double~~CallsGraph proc~string_to_double string_to_double interface~throw_exception throw_exception proc~string_to_double->interface~throw_exception proc~json_throw_exception json_throw_exception interface~throw_exception->proc~json_throw_exception
Help

Called By

proc~~string_to_double~~CalledByGraph proc~string_to_double string_to_double proc~parse_number parse_number proc~parse_number->proc~string_to_double proc~parse_value parse_value proc~parse_value->proc~parse_number proc~parse_object parse_object proc~parse_value->proc~parse_object proc~parse_array parse_array proc~parse_value->proc~parse_array proc~json_parse_string json_parse_string proc~json_parse_string->proc~parse_value proc~json_parse_file json_parse_file proc~json_parse_file->proc~parse_value proc~parse_object->proc~parse_value proc~parse_object->proc~parse_object proc~parse_array->proc~parse_value proc~wrap_json_parse_string wrap_json_parse_string proc~wrap_json_parse_string->proc~json_parse_string interface~json_parse json_parse interface~json_parse->proc~json_parse_string interface~json_parse->proc~json_parse_file proc~test_14 test_14 proc~test_14->interface~json_parse proc~test_8 test_8 proc~test_8->interface~json_parse proc~json_file_load json_file_load proc~json_file_load->interface~json_parse proc~json_file_load_from_string json_file_load_from_string proc~json_file_load_from_string->interface~json_parse program~jf_test_14 jf_test_14 program~jf_test_14->proc~test_14 program~jf_test_8 jf_test_8 program~jf_test_8->proc~test_8 proc~wrap_json_file_load_from_string wrap_json_file_load_from_string proc~wrap_json_file_load_from_string->proc~json_file_load_from_string
Help

Variables

TypeVisibility AttributesNameInitial
integer(kind=IK), public :: ierr

Source Code

    function string_to_double(str) result(rval)

    implicit none

    real(RK)                            :: rval
    character(kind=CK,len=*),intent(in) :: str

    integer(IK) :: ierr

    if (.not. exception_thrown) then

        !string to double
        read(str,fmt=*,iostat=ierr) rval

        if (ierr/=0) then    !if there was an error
            rval = 0.0_RK
            call throw_exception('Error in string_to_double:'//&
                                 ' string cannot be converted to a double: '//trim(str))
        end if

    end if

    end function string_to_double