Convert a string into a double.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CK,len=*), | intent(in) | :: | str |
function string_to_double(json,str) result(rval)
implicit none
class(json_core),intent(inout) :: json
character(kind=CK,len=*),intent(in) :: str
real(RK) :: rval
integer(IK) :: ierr !! read iostat error code
if (.not. json%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 json%throw_exception('Error in string_to_double: '//&
'string cannot be converted to a double: '//&
trim(str))
end if
else
rval = 0.0_RK
end if
end function string_to_double