parse_real_sp_char Subroutine

private subroutine parse_real_sp_char(str, value, err)

Parse a character string into a single precision real.

The conversion is done in double precision and then range checked, so a value that is finite in dp but too large for sp is reported as an error instead of becoming infinity.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
real(kind=sp), intent(out) :: value
type(error_t), intent(out) :: err

Calls

proc~~parse_real_sp_char~~CallsGraph proc~parse_real_sp_char parse_real_sp_char interface~strip strip proc~parse_real_sp_char->interface~strip proc~error_has_error error_t%error_has_error proc~parse_real_sp_char->proc~error_has_error proc~error_set error_t%error_set proc~parse_real_sp_char->proc~error_set proc~parse_real_wide parse_real_wide proc~parse_real_sp_char->proc~parse_real_wide proc~strip_char strip_char interface~strip->proc~strip_char proc~strip_string strip_string interface~strip->proc~strip_string proc~parse_real_wide->interface~strip proc~parse_real_wide->proc~error_has_error proc~parse_real_wide->proc~error_set proc~check_exponent check_exponent proc~parse_real_wide->proc~check_exponent proc~skip_sign skip_sign proc~parse_real_wide->proc~skip_sign proc~check_exponent->proc~error_set proc~check_exponent->proc~skip_sign proc~strip_string->interface~strip

Called by

proc~~parse_real_sp_char~~CalledByGraph proc~parse_real_sp_char parse_real_sp_char interface~parse_real parse_real interface~parse_real->proc~parse_real_sp_char proc~parse_real_sp_string parse_real_sp_string interface~parse_real->proc~parse_real_sp_string proc~parse_real_sp_string->proc~parse_real_sp_char proc~cli_get_real_dp cli_t%cli_get_real_dp proc~cli_get_real_dp->interface~parse_real proc~cli_get_real_sp cli_t%cli_get_real_sp proc~cli_get_real_sp->interface~parse_real

Variables

Type Visibility Attributes Name Initial
real(kind=dp), private :: wide

Source Code

   subroutine parse_real_sp_char(str, value, err)
      !! Parse a character string into a single precision real.
      !!
      !! The conversion is done in double precision and then range checked, so
      !! a value that is finite in `dp` but too large for `sp` is reported as
      !! an error instead of becoming infinity.
      character(len=*), intent(in) :: str
      real(sp), intent(out) :: value
      type(error_t), intent(out) :: err

      real(dp) :: wide

      value = 0.0_sp
      call parse_real_wide(str, wide, err)
      if (err%has_error()) return

      if (abs(wide) > real(huge(value), dp)) then
         call err%set(ERROR_PARSE, "real out of range for single precision: '"//strip(str)//"'")
         return
      end if
      value = real(wide, sp)

   end subroutine parse_real_sp_char