Skip to content

Commit fbdf870

Browse files
committed
autodoc and examples for str2num improvement
1 parent 89f0015 commit fbdf870

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

doc/specs/stdlib_str2num.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,7 @@ Return a scalar of numerical type (i.e., `integer`, or `real`).
3535
### Example
3636

3737
```fortran
38-
program example_string_to_number
39-
use stdlib_kinds, only: dp
40-
use stdlib_str2num, only: to_num
41-
implicit none
42-
character(:), allocatable :: txt
43-
real(dp) :: x
44-
45-
txt = ' 8.8541878128e−12 '
46-
x = to_num( txt , x )
47-
end program example_string_to_number
38+
{!example/strings/example_string_to_number.f90!}
4839
```
4940

5041
## `to_num_p` - conversion of a stream of values in a string to numbers
@@ -74,20 +65,7 @@ Return a scalar of numerical type (i.e., `integer` or `real`).
7465
### Example
7566

7667
```fortran
77-
program example_to_num_p
78-
use stdlib_kinds, only: dp
79-
use stdlib_str2num, only: to_num_p
80-
character(:), allocatable, target :: chain
81-
character(len=:), pointer :: cptr
82-
real(dp) :: r(6)
83-
integer :: i
84-
85-
chain = " 1.234 1.E1 1e0 0.1234E0 12.21e+001 -34.5E1"
86-
cptr => chain
87-
do i = 1, 6
88-
r(i) = to_num_p( cptr , r(i) ) !> the cptr pointer is shifted within the function
89-
end do
90-
end program example_to_num_p
68+
{!example/strings/example_stream_of_strings_to_numbers.f90!}
9169
```
9270

9371
## Note

example/strings/example_str2num.f90 renamed to example/strings/example_stream_of_strings_to_numbers.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
program example_str2num
1+
program example_stream_of_strings_to_numbers
22
use stdlib_kinds, only: dp
33
use stdlib_str2num, only: to_num_p
44
character(:), allocatable, target :: chain
@@ -14,9 +14,9 @@ program example_str2num
1414
r(i) = to_num_p( cptr , r(i) ) !> the pointer is shifted within the function
1515
end do
1616
read(chain,*) p
17-
print *, "Reading with to_num"
17+
print *, "Reading with to_num_p"
1818
print *, r
1919
print *, "Reading with formatted read"
2020
print *, p
2121

22-
end program
22+
end program example_stream_of_strings_to_numbers
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
program example_string_to_number
2+
use stdlib_kinds, only: dp
3+
use stdlib_str2num, only: to_num
4+
implicit none
5+
character(:), allocatable :: txt
6+
real(dp) :: x
7+
8+
txt = ' 8.8541878128e−12 '
9+
x = to_num( txt , x )
10+
end program example_string_to_number

0 commit comments

Comments
 (0)