-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo_aton.f90
30 lines (26 loc) · 1.13 KB
/
demo_aton.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
program demo_aton
use M_strings, only: aton
implicit none
character(len=14),allocatable :: strings(:)
doubleprecision :: dv
integer :: iv
real :: rv
integer :: i
! different strings representing INTEGER, REAL, and DOUBLEPRECISION
strings=[&
&' 10.345 ',&
&'+10 ',&
&' -3 ',&
&' -4.94e-2 ',&
&'0.1 ',&
&'12345.678910d0',&
&' ',& ! Note: will return zero without an error message
&'1 2 1 2 1 . 0 ',& ! Note: spaces will be ignored
&'WHAT? '] ! Note: error messages will appear, zero returned
do i=1,size(strings)
write(*,'(a)',advance='no')'STRING:',strings(i)
if(aton(strings(i),iv)) write(*,'(g0)',advance='no')':INTEGER ',iv
if(aton(strings(i),rv)) write(*,'(g0)',advance='no')':INTEGER ',rv
if(aton(strings(i),dv)) write(*,'(g0)',advance='no')':INTEGER ',dv
enddo
end program demo_aton