Cast string to real (R16P).
use penf
type(string) :: astring
real(R16P) :: real_
logical :: test_passed(1)
astring = '3.4e9'
real_ = astring%to_number(kind=1._R16P)
test_passed(1) = real_==3.4e9_R16P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
real(kind=R16P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
elemental function to_real_R16P(self, kind) result(to_number)
!< Cast string to real (R16P).
!<
!<```fortran
!< use penf
!< type(string) :: astring
!< real(R16P) :: real_
!< logical :: test_passed(1)
!< astring = '3.4e9'
!< real_ = astring%to_number(kind=1._R16P)
!< test_passed(1) = real_==3.4e9_R16P
!< print '(L1)', all(test_passed)
!<```
!=> T <<<
class(string), intent(in) :: self !< The string.
real(R16P), intent(in) :: kind !< Mold parameter for kind detection.
real(R16P) :: 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_R16P