Skip to content

Commit

Permalink
Proposal for a reference string to number
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvesz committed Oct 31, 2023
1 parent 27e928a commit c0f38d4
Show file tree
Hide file tree
Showing 4 changed files with 639 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/strings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ ADD_EXAMPLE(starts_with)
ADD_EXAMPLE(strip)
ADD_EXAMPLE(to_string)
ADD_EXAMPLE(zfill)
ADD_EXAMPLE(str2num)
22 changes: 22 additions & 0 deletions example/strings/example_str2num.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
program example_str2num
use stdlib_kinds, only: dp
use stdlib_str2num
character(:), allocatable, target :: chain
character(len=:), pointer :: cptr
real(dp), allocatable :: r(:), p(:)
integer :: i

chain = " 1.234 1.E1 1e0 0.1234E0 12.21e+001 -34.5E1"
allocate( r(6), p(6) )
!> Example for streamline conversion using `str2float_p`
cptr => chain
do i =1, 6
r(i) = str2float_p( cptr ) !> the pointer is shifted within the function
end do
read(chain,*) p
print *, "Reading with str2num"
print *, r
print *, "Reading with formatted read"
print *, p

end program
Loading

0 comments on commit c0f38d4

Please sign in to comment.