Skip to content

Commit b110f61

Browse files
committed
update for MR #27
Fixers #28
1 parent 097f876 commit b110f61

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/csv_module.F90

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ subroutine read_csv_file(me,filename,header_row,skip_rows,status_ok)
226226
!! (0 if no header specified)
227227
character(len=1) :: tmp !! for skipping a row
228228

229+
! clear existing data:
229230
arrays_allocated = .false.
231+
if (allocated(me%csv_data)) deallocate(me%csv_data)
232+
if (allocated(me%header)) deallocate(me%header)
230233

231234
open(newunit=iunit, file=filename, status='OLD', iostat=istat)
232235

@@ -286,9 +289,7 @@ subroutine read_csv_file(me,filename,header_row,skip_rows,status_ok)
286289
! columns.
287290
n_cols = size(row_data)
288291
me%n_cols = n_cols
289-
if(allocated(me%csv_data)) deallocate(me%csv_data)
290292
allocate(me%csv_data(n_rows,n_cols))
291-
if(allocated(me%header)) deallocate(me%header)
292293
if (iheader/=0) allocate(me%header(n_cols))
293294
arrays_allocated = .true.
294295
end if
@@ -340,6 +341,10 @@ subroutine open_csv_file(me,filename,n_cols,status_ok,append)
340341
logical :: append_flag !! local copy of `append` argument
341342
logical :: file_exists !! if the file exists
342343

344+
! clear existing data:
345+
if (allocated(me%csv_data)) deallocate(me%csv_data)
346+
if (allocated(me%header)) deallocate(me%header)
347+
343348
me%n_cols = n_cols
344349

345350
! optional append argument:

0 commit comments

Comments
 (0)