@@ -45,14 +45,15 @@ module csv_module
45
45
46
46
character (len= 1 ) :: quote = ' "' ! ! quotation character
47
47
character (len= 1 ) :: delimiter = ' ,' ! ! delimiter character
48
+
49
+ ! for reading a csv file:
48
50
integer :: n_rows = 0 ! ! number of rows in the file
49
51
integer :: n_cols = 0 ! ! number of columns in the file
50
52
integer :: chunk_size = 100 ! ! for expanding vectors
51
-
52
53
type (csv_string),dimension (:),allocatable :: header ! ! the header
53
54
type (csv_string),dimension (:,:),allocatable :: csv_data ! ! the data in the file
54
55
55
- ! for writing a csv file:
56
+ ! for writing a csv file:
56
57
integer :: icol = 0 ! ! last column written in current row
57
58
integer :: iunit = 0 ! ! file unit for writing
58
59
logical :: enclose_strings_in_quotes = .true. ! ! if true, all string cells
@@ -124,7 +125,7 @@ module csv_module
124
125
125
126
! *****************************************************************************************
126
127
! >
127
- ! Constructor .
128
+ ! Initialize a [[csv_file(type)]] .
128
129
129
130
subroutine initialize_csv_file (me ,quote ,delimiter ,&
130
131
enclose_strings_in_quotes ,&
@@ -183,18 +184,11 @@ end subroutine initialize_csv_file
183
184
! >
184
185
! Destroy the data in a CSV file.
185
186
186
- pure subroutine destroy_csv_file (me )
187
+ subroutine destroy_csv_file (me )
187
188
188
189
implicit none
189
190
190
- class(csv_file),intent (inout ) :: me
191
-
192
- if (allocated (me% csv_data)) deallocate (me% csv_data)
193
- if (allocated (me% header)) deallocate (me% header)
194
-
195
- me% n_cols = 0
196
- me% n_rows = 0
197
- me% icol = 0
191
+ class(csv_file),intent (out ) :: me
198
192
199
193
end subroutine destroy_csv_file
200
194
! *****************************************************************************************
@@ -348,7 +342,8 @@ subroutine open_csv_file(me,filename,n_cols,status_ok)
348
342
if (istat== 0 ) then
349
343
status_ok = .true.
350
344
else
351
- if (me% verbose) write (error_unit,' (A)' ) ' Error opening file: ' // trim (filename)
345
+ if (me% verbose) write (error_unit,' (A)' ) &
346
+ ' Error opening file: ' // trim (filename)
352
347
status_ok = .false.
353
348
end if
354
349
@@ -482,8 +477,6 @@ end subroutine add_cell
482
477
! *****************************************************************************************
483
478
! >
484
479
! Add a vector to a CSV file. Each element is added as a cell to the current line.
485
- !
486
- ! @warning There is some bug here with GFortran 6.1 when `val` is a character string.
487
480
488
481
subroutine add_vector (me ,val ,int_fmt ,real_fmt ,trim_str )
489
482
@@ -500,7 +493,19 @@ subroutine add_vector(me,val,int_fmt,real_fmt,trim_str)
500
493
integer :: i ! ! counter
501
494
502
495
do i= 1 ,size (val)
496
+
497
+ #if defined __GFORTRAN__
498
+ ! This is a stupid workaround for gfortran bugs (tested with 7.2.0)
499
+ select type (val)
500
+ type is (character (len=* ))
501
+ call me% add(val(i),int_fmt,real_fmt,trim_str)
502
+ class default
503
+ call me% add(val(i),int_fmt,real_fmt,trim_str)
504
+ end select
505
+ #else
503
506
call me% add(val(i),int_fmt,real_fmt,trim_str)
507
+ #endif
508
+
504
509
end do
505
510
506
511
end subroutine add_vector
0 commit comments