to_real_R8P Function

private elemental function to_real_R8P(self, kind) result(to_number)

Cast string to real (R8P).

 use penf
 type(string) :: astring
 real(R8P)    :: real_
 logical      :: test_passed(1)
 astring = '3.4e9'
 real_ = astring%to_number(kind=1._R8P)
 test_passed(1) = real_==3.4e9_R8P
 print '(L1)', all(test_passed)

Type Bound

string

Arguments

Type IntentOptional Attributes Name
class(string), intent(in) :: self

The string.

real(kind=R8P), intent(in) :: kind

Mold parameter for kind detection.

Return Value real(kind=R8P)

The number into the string.


Calls

proc~~to_real_r8p~~CallsGraph proc~to_real_r8p stringifor_string_t::string%to_real_R8P proc~is_real stringifor_string_t::string%is_real proc~to_real_r8p->proc~is_real

Contents

Source Code


Source Code

   elemental function to_real_R8P(self, kind) result(to_number)
   !< Cast string to real (R8P).
   !<
   !<```fortran
   !< use penf
   !< type(string) :: astring
   !< real(R8P)    :: real_
   !< logical      :: test_passed(1)
   !< astring = '3.4e9'
   !< real_ = astring%to_number(kind=1._R8P)
   !< test_passed(1) = real_==3.4e9_R8P
   !< print '(L1)', all(test_passed)
   !<```
   !=> T <<<
   class(string), intent(in) :: self      !< The string.
   real(R8P),     intent(in) :: kind      !< Mold parameter for kind detection.
   real(R8P)                 :: to_number !< The number into the string.

   if (allocated(self%raw)) then
     if (self%is_real()) read(self%raw, *) to_number
   endif
   endfunction to_real_R8P