@@ -45,14 +45,15 @@ module csv_module
4545
4646 character (len= 1 ) :: quote = ' "' ! ! quotation character
4747 character (len= 1 ) :: delimiter = ' ,' ! ! delimiter character
48+
49+ ! for reading a csv file:
4850 integer :: n_rows = 0 ! ! number of rows in the file
4951 integer :: n_cols = 0 ! ! number of columns in the file
5052 integer :: chunk_size = 100 ! ! for expanding vectors
51-
5253 type (csv_string),dimension (:),allocatable :: header ! ! the header
5354 type (csv_string),dimension (:,:),allocatable :: csv_data ! ! the data in the file
5455
55- ! for writing a csv file:
56+ ! for writing a csv file:
5657 integer :: icol = 0 ! ! last column written in current row
5758 integer :: iunit = 0 ! ! file unit for writing
5859 logical :: enclose_strings_in_quotes = .true. ! ! if true, all string cells
@@ -124,7 +125,7 @@ module csv_module
124125
125126! *****************************************************************************************
126127! >
127- ! Constructor .
128+ ! Initialize a [[csv_file(type)]] .
128129
129130 subroutine initialize_csv_file (me ,quote ,delimiter ,&
130131 enclose_strings_in_quotes ,&
@@ -183,18 +184,11 @@ end subroutine initialize_csv_file
183184! >
184185! Destroy the data in a CSV file.
185186
186- pure subroutine destroy_csv_file (me )
187+ subroutine destroy_csv_file (me )
187188
188189 implicit none
189190
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
198192
199193 end subroutine destroy_csv_file
200194! *****************************************************************************************
@@ -348,7 +342,8 @@ subroutine open_csv_file(me,filename,n_cols,status_ok)
348342 if (istat== 0 ) then
349343 status_ok = .true.
350344 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)
352347 status_ok = .false.
353348 end if
354349
@@ -482,8 +477,6 @@ end subroutine add_cell
482477! *****************************************************************************************
483478! >
484479! 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.
487480
488481 subroutine add_vector (me ,val ,int_fmt ,real_fmt ,trim_str )
489482
@@ -500,7 +493,19 @@ subroutine add_vector(me,val,int_fmt,real_fmt,trim_str)
500493 integer :: i ! ! counter
501494
502495 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
503506 call me% add(val(i),int_fmt,real_fmt,trim_str)
507+ #endif
508+
504509 end do
505510
506511 end subroutine add_vector
0 commit comments