|
1 |
| -program csv_test3 |
2 |
| - |
3 |
| -use csv_module |
4 |
| -use iso_fortran_env, only: wp => real64 |
5 |
| - |
6 |
| -implicit none |
7 |
| - |
8 |
| -type(csv_file) :: f |
9 |
| -logical :: status_ok |
10 |
| -character(len=30),dimension(:),allocatable :: header, col1 |
11 |
| -integer :: i |
12 |
| -character(len=100) :: tmp_str |
13 |
| - |
14 |
| -! set optional inputs: |
15 |
| -call f%initialize(verbose = .true.) |
16 |
| - |
17 |
| -! open the file |
18 |
| -call f%open('test.csv',n_cols=4,status_ok=status_ok) |
19 |
| - |
20 |
| -! add header |
21 |
| -call f%add(['x','y','z','t']) |
22 |
| -call f%next_row() |
23 |
| - |
24 |
| -! add some data: |
25 |
| -call f%add([1.0_wp,2.0_wp,3.0_wp],real_fmt='(F5.3)') |
26 |
| -call f%add(.true.) |
27 |
| -call f%next_row() |
28 |
| -call f%add([2.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
29 |
| -call f%add(.false.) |
30 |
| -call f%next_row() |
31 |
| -call f%add([3.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
32 |
| -call f%add(.false.) |
33 |
| -call f%next_row() |
34 |
| -call f%add([4.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
35 |
| -call f%add(.false.) |
36 |
| -call f%next_row() |
37 |
| -call f%add([5.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
38 |
| -call f%add(.false.) |
39 |
| -call f%next_row() |
40 |
| - |
41 |
| -! finished |
42 |
| -call f%close(status_ok) |
43 |
| -if (.not. status_ok) error stop 'error closing file' |
44 |
| - |
45 |
| -! read the file |
46 |
| -call f%read('test.csv',header_row=1,status_ok=status_ok) |
47 |
| -if (.not. status_ok) error stop 'error reading file' |
48 |
| - |
49 |
| -! get the header and type info |
50 |
| -call f%get_header(header,status_ok) |
51 |
| - |
52 |
| -print "(*(g0))", "HEADER:" |
53 |
| -do i = 1, size(header) |
54 |
| - print "(*(g0))", ">"//trim(header(i))//"<" |
55 |
| -end do |
56 |
| -if (.not. all(header == ['x','y','z','t'])) error stop 'error reading header' |
57 |
| - |
58 |
| -call f%get(1,col1,status_ok) |
59 |
| -print "(*(g0))", "col1:" |
60 |
| -do i = 1, size(col1) |
61 |
| - print "(*(g0))", ">",trim(col1(i)),"<" |
62 |
| -end do |
63 |
| - |
64 |
| -do i = 1, 5 |
65 |
| - write(tmp_str,'(F5.3)') real(i,wp) |
66 |
| - if (col1(i) /= tmp_str) error stop 'error converting cell to string:'//tmp_str |
67 |
| -end do |
68 |
| - |
69 |
| -! destroy the file |
70 |
| -call f%destroy() |
71 |
| - |
72 |
| -end program csv_test3 |
| 1 | +!***************************************************************************************** |
| 2 | +!> |
| 3 | +! Test of string conversions that uncover bugs in Gfortran. |
| 4 | + |
| 5 | + program csv_test3 |
| 6 | + |
| 7 | + use csv_module |
| 8 | + use iso_fortran_env, only: wp => real64 |
| 9 | + |
| 10 | + implicit none |
| 11 | + |
| 12 | + type(csv_file) :: f |
| 13 | + logical :: status_ok |
| 14 | + character(len=30),dimension(:),allocatable :: header, col1 |
| 15 | + integer :: i |
| 16 | + character(len=100) :: tmp_str |
| 17 | + |
| 18 | + write(*,*) '' |
| 19 | + write(*,*) '============================' |
| 20 | + write(*,*) ' csv_test_3 ' |
| 21 | + write(*,*) '============================' |
| 22 | + write(*,*) '' |
| 23 | + |
| 24 | + ! set optional inputs: |
| 25 | + call f%initialize(verbose = .true.) |
| 26 | + |
| 27 | + ! open the file |
| 28 | + call f%open('test.csv',n_cols=4,status_ok=status_ok) |
| 29 | + |
| 30 | + ! add header |
| 31 | + call f%add(['x','y','z','t']) |
| 32 | + call f%next_row() |
| 33 | + |
| 34 | + ! add some data: |
| 35 | + call f%add([1.0_wp,2.0_wp,3.0_wp],real_fmt='(F5.3)') |
| 36 | + call f%add(.true.) |
| 37 | + call f%next_row() |
| 38 | + call f%add([2.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
| 39 | + call f%add(.false.) |
| 40 | + call f%next_row() |
| 41 | + call f%add([3.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
| 42 | + call f%add(.false.) |
| 43 | + call f%next_row() |
| 44 | + call f%add([4.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
| 45 | + call f%add(.false.) |
| 46 | + call f%next_row() |
| 47 | + call f%add([5.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)') |
| 48 | + call f%add(.false.) |
| 49 | + call f%next_row() |
| 50 | + |
| 51 | + ! finished |
| 52 | + call f%close(status_ok) |
| 53 | + if (.not. status_ok) error stop 'error closing file' |
| 54 | + |
| 55 | + ! read the file |
| 56 | + call f%read('test.csv',header_row=1,status_ok=status_ok) |
| 57 | + if (.not. status_ok) error stop 'error reading file' |
| 58 | + |
| 59 | + ! get the header and type info |
| 60 | + call f%get_header(header,status_ok) |
| 61 | + |
| 62 | + print "(*(g0))", "HEADER:" |
| 63 | + do i = 1, size(header) |
| 64 | + print "(*(g0))", ">"//trim(header(i))//"<" |
| 65 | + end do |
| 66 | + if (.not. all(header == ['x','y','z','t'])) error stop 'error reading header' |
| 67 | + |
| 68 | + call f%get(1,col1,status_ok) |
| 69 | + print "(*(g0))", "col1:" |
| 70 | + do i = 1, size(col1) |
| 71 | + print "(*(g0))", ">",trim(col1(i)),"<" |
| 72 | + end do |
| 73 | + |
| 74 | + do i = 1, 5 |
| 75 | + write(tmp_str,'(F5.3)') real(i,wp) |
| 76 | + if (col1(i) /= tmp_str) error stop 'error converting cell to string:'//tmp_str |
| 77 | + end do |
| 78 | + |
| 79 | + ! destroy the file |
| 80 | + call f%destroy() |
| 81 | + |
| 82 | + end program csv_test3 |
0 commit comments