Skip to content

Commit e13b29b

Browse files
Merge pull request #8 from jacobwilliams/develop
Develop
2 parents d496ee4 + 5e49a75 commit e13b29b

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/csv_module.F90

+23-7
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,38 @@ end subroutine read_csv_file
323323
!
324324
! Use `initialize` to set options for the CSV file.
325325

326-
subroutine open_csv_file(me,filename,n_cols,status_ok)
326+
subroutine open_csv_file(me,filename,n_cols,status_ok,append)
327327

328328
implicit none
329329

330-
class(csv_file),intent(inout) :: me
331-
character(len=*),intent(in) :: filename !! the CSV file to open
332-
integer,intent(in) :: n_cols !! number of columns in the file
333-
logical,intent(out) :: status_ok !! status flag
330+
class(csv_file),intent(inout) :: me
331+
character(len=*),intent(in) :: filename !! the CSV file to open
332+
integer,intent(in) :: n_cols !! number of columns in the file
333+
logical,intent(out) :: status_ok !! status flag
334+
logical,intent(in),optional :: append !! append if file exists
334335

335-
integer :: istat !! open `iostat` flag
336+
integer :: istat !! open `iostat` flag
337+
logical :: append_flag !! local copy of `append` argument
338+
logical :: file_exists !! if the file exists
336339

337340
call me%destroy()
338341

339342
me%n_cols = n_cols
340343

341-
open(newunit=me%iunit,file=filename,status='REPLACE',iostat=istat)
344+
! optional append argument:
345+
append_flag = .false.
346+
file_exists = .false.
347+
if (present(append)) then
348+
append_flag = append
349+
if (append) inquire(file=filename, exist=file_exists)
350+
end if
351+
352+
if (append_flag .and. file_exists) then
353+
open(newunit=me%iunit,file=filename,status='OLD',position='APPEND',iostat=istat)
354+
else
355+
open(newunit=me%iunit,file=filename,status='REPLACE',iostat=istat)
356+
end if
357+
342358
if (istat==0) then
343359
status_ok = .true.
344360
else

0 commit comments

Comments
 (0)