Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Rearranged file io so that NetCDF all binary files are deleted upon i…
Browse files Browse the repository at this point in the history
…nitialization and streamlined the first frame writing call
  • Loading branch information
daminton committed Sep 24, 2021
1 parent a2d4bdb commit d497a30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
19 changes: 5 additions & 14 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ module function io_get_old_t_final_system(self, param) result(old_t_final)
class(swiftest_nbody_system), allocatable :: tmpsys
class(swiftest_parameters), allocatable :: tmpparam
integer(I4B) :: ierr, iu = LUN
character(len=STRMAX) :: errmsg
character(len=STRMAX) :: errmsg

old_t_final = 0.0_DP
allocate(tmpsys, source=self)
Expand Down Expand Up @@ -2105,26 +2105,17 @@ module subroutine io_write_frame_system(self, param)
errmsg = param%outfile // " not found! You must specify OUT_STAT = NEW, REPLACE, or UNKNOWN"
goto 667
end if
call param%nciu%open(param)
case('NEW')
if (fileExists) then
errmsg = param%outfile // " Alread Exists! You must specify OUT_STAT = OLD, REPLACE, or UNKNOWN"
errmsg = param%outfile // " Alread Exists! You must specify OUT_STAT = APPEND, REPLACE, or UNKNOWN"
goto 667
end if
call param%nciu%initialize(param)
case('REPLACE', 'UNKNOWN')
if (fileExists) then
open(file=param%outfile, unit=iu, status='OLD')
close (unit=BINUNIT, status="delete")
end if
end select

select case(param%out_stat)
case('APPEND')
call param%nciu%open(param)
case('NEW', 'REPLACE', 'UNKNOWN')
call param%nciu%initialize(param)
call param%nciu%close(param)
call param%nciu%open(param)
end select

lfirst = .false.
else
call param%nciu%open(param)
Expand Down
15 changes: 11 additions & 4 deletions src/netcdf/netcdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ module subroutine netcdf_initialize_output(self, param)
integer(I4B) :: old_mode, nvar, varid, vartype, old_unit
real(DP) :: dfill
real(SP) :: sfill
logical :: fileExists
character(len=STRMAX) :: errmsg

dfill = ieee_value(dfill, IEEE_QUIET_NAN)
sfill = ieee_value(sfill, IEEE_QUIET_NAN)

!! Create the new output file, deleting any previously existing output file of the same name
if (any(DUMP_NC_FILE == param%outfile)) then
open(file=param%outfile, unit=old_unit, status='OLD')
close(unit=old_unit, status='delete')
! Check if the file exists, and if it does, delete it
inquire(file=param%outfile, exist=fileExists)
if (fileExists) then
open(unit=LUN, file=param%outfile, status="old", err=667, iomsg=errmsg)
close(unit=LUN, status="delete")
end if

call check( nf90_create(param%outfile, NF90_NETCDF4, self%ncid) )
Expand Down Expand Up @@ -198,6 +201,10 @@ module subroutine netcdf_initialize_output(self, param)
call check( nf90_enddef(self%ncid) )

return

667 continue
write(*,*) "Error creating NetCDF output file. " // trim(adjustl(errmsg))
call util_exit(FAILURE)
end subroutine netcdf_initialize_output


Expand Down

0 comments on commit d497a30

Please sign in to comment.