string_to_real Subroutine

public subroutine string_to_real(str, rval, status_ok)

Convert a string into a real(RK).

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').
  • Jacob Williams : 2/6/2017 : moved core logic to this routine.

Arguments

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

the string to convert to a real

real(kind=RK), intent(out) :: rval

str converted to a real value

logical(kind=LK), intent(out) :: status_ok

true if there were no errors


Called by

proc~~string_to_real~~CalledByGraph proc~string_to_real string_to_real proc~json_get_double json_get_double proc~json_get_double->proc~string_to_real proc~string_to_dble string_to_dble proc~string_to_dble->proc~string_to_real

Contents

Source Code


Source Code

    subroutine string_to_real(str,rval,status_ok)

    implicit none

    character(kind=CK,len=*),intent(in) :: str        !! the string to convert to a real
    real(RK),intent(out)                :: rval       !! `str` converted to a real value
    logical(LK),intent(out)             :: status_ok  !! true if there were no errors

    integer(IK) :: ierr  !! read iostat error code

    read(str,fmt=*,iostat=ierr) rval
    status_ok = (ierr==0)
    if (.not. status_ok) rval = 0.0_RK

    end subroutine string_to_real