Skip to content

Commit 5e49a75

Browse files
committed
some code cleanups.
1 parent fbd7417 commit 5e49a75

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/csv_module.F90

+20-17
Original file line numberDiff line numberDiff line change
@@ -327,31 +327,34 @@ 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
334-
logical,intent(in),optional :: append !! Append if file exists
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
335335

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

340340
call me%destroy()
341341

342342
me%n_cols = n_cols
343343

344-
if (present(append)) append_flag = append
345-
if (append_flag) then
346-
inquire (file=filename, exist=file_exists)
347-
if (file_exists) then
348-
open(newunit=me%iunit,file=filename,status='OLD',position='APPEND',iostat=istat)
349-
else
350-
open(newunit=me%iunit,file=filename,status='REPLACE',iostat=istat)
351-
end if
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)
352354
else
353-
open(newunit=me%iunit,file=filename,status='REPLACE',iostat=istat)
355+
open(newunit=me%iunit,file=filename,status='REPLACE',iostat=istat)
354356
end if
357+
355358
if (istat==0) then
356359
status_ok = .true.
357360
else

0 commit comments

Comments
 (0)