@@ -226,7 +226,10 @@ subroutine read_csv_file(me,filename,header_row,skip_rows,status_ok)
226
226
! ! (0 if no header specified)
227
227
character (len= 1 ) :: tmp ! ! for skipping a row
228
228
229
+ ! clear existing data:
229
230
arrays_allocated = .false.
231
+ if (allocated (me% csv_data)) deallocate (me% csv_data)
232
+ if (allocated (me% header)) deallocate (me% header)
230
233
231
234
open (newunit= iunit, file= filename, status= ' OLD' , iostat= istat)
232
235
@@ -286,9 +289,7 @@ subroutine read_csv_file(me,filename,header_row,skip_rows,status_ok)
286
289
! columns.
287
290
n_cols = size (row_data)
288
291
me% n_cols = n_cols
289
- if (allocated (me% csv_data)) deallocate (me% csv_data)
290
292
allocate (me% csv_data(n_rows,n_cols))
291
- if (allocated (me% header)) deallocate (me% header)
292
293
if (iheader/= 0 ) allocate (me% header(n_cols))
293
294
arrays_allocated = .true.
294
295
end if
@@ -340,6 +341,10 @@ subroutine open_csv_file(me,filename,n_cols,status_ok,append)
340
341
logical :: append_flag ! ! local copy of `append` argument
341
342
logical :: file_exists ! ! if the file exists
342
343
344
+ ! clear existing data:
345
+ if (allocated (me% csv_data)) deallocate (me% csv_data)
346
+ if (allocated (me% header)) deallocate (me% header)
347
+
343
348
me% n_cols = n_cols
344
349
345
350
! optional append argument:
0 commit comments