File: example_stream_of_strings_to_numbers.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (23 lines) | stat: -rw-r--r-- 776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
program example_stream_of_strings_to_numbers
    use stdlib_kinds, only: dp
    use stdlib_str2num, only: to_num_from_stream
    implicit none
    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 `to_num_from_stream`
    cptr => chain
    do i =1, 6
        r(i) = to_num_from_stream( cptr , r(i) ) !> the pointer is shifted within the function
    end do
    read(chain,*) p
    print *, "Reading with to_num_from_stream"
    print *, r
    print *, "Reading with formatted read"
    print *, p

end program example_stream_of_strings_to_numbers