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

Commit

Permalink
Changed the netcdf IO routine to set a flag indicating whether c_lm e…
Browse files Browse the repository at this point in the history
…xists or not.
  • Loading branch information
daminton committed Feb 27, 2024
1 parent dfa48e1 commit 74742cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/netcdf_io/netcdf_io_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ module netcdf_io
!! ID for the id of the other body involved in the discard
logical :: lpseudo_vel_exists = .false.
!! Logical flag to indicate whether or not the pseudovelocity vectors were present in an old file.
logical :: lc_lm_exists = .false.
!! Logical flag to indicate whether or not the c_lm array was present in an old file.
contains
procedure :: close => netcdf_io_close
!! Closes an open NetCDF file
Expand Down
1 change: 1 addition & 0 deletions src/swiftest/swiftest_coarray.f90
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ module subroutine swiftest_coarray_coclone_nc(self)
call coclone(self%discard_vh_varid)
call coclone(self%discard_body_id_varname)
call coclone(self%lpseudo_vel_exists)
call coclone(self%lc_lm_exists)
return
end subroutine swiftest_coarray_coclone_nc

Expand Down
13 changes: 8 additions & 5 deletions src/swiftest/swiftest_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ module subroutine swiftest_io_netcdf_initialize_output(self, param)
nc%vh_varid), "netcdf_io_initialize_output nf90_def_var vh_varid" )

!! When GR is enabled, we need to save the pseudovelocity vectors in addition to the true heliocentric velocity vectors,
!! otherwise !! we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors
!! otherwise we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors
!! during the conversion.
if (param%lgr) then
call netcdf_io_check( nf90_def_var(nc%id, nc%gr_pseudo_vh_varname, nc%out_type, &
Expand Down Expand Up @@ -1008,11 +1008,10 @@ module subroutine swiftest_io_netcdf_initialize_output(self, param)
call netcdf_io_check( nf90_def_var(nc%id, nc%j4rp4_varname, nc%out_type, nc%time_dimid, nc%j4rp4_varid), &
"netcdf_io_initialize_output nf90_def_var j4rp4_varid" )

! status = nf90_inq_varid(nc%id, nc%c_lm_varname, nc%c_lm_varid)
! if (status == NF90_NOERR) then
call netcdf_io_check( nf90_def_var(nc%id, nc%c_lm_varname, nc%out_type, [nc%m_dimid, nc%l_dimid, nc%sign_dimid], &
if (nc%lc_lm_exists) then
call netcdf_io_check( nf90_def_var(nc%id, nc%c_lm_varname, nc%out_type, [nc%m_dimid, nc%l_dimid, nc%sign_dimid], &
nc%c_lm_varid), "netcdf_io_initialize_output nf90_def_var c_lm_varid" )
! end if
end if

! Set fill mode to NaN for all variables
call netcdf_io_check( nf90_inquire(nc%id, nVariables=nvar), "netcdf_io_initialize_output nf90_inquire nVariables" )
Expand Down Expand Up @@ -1576,6 +1575,10 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier
call netcdf_io_check( nf90_get_var(nc%id, nc%c_lm_varid, cb%c_lm, count = [m_dim_max, l_dim_max, 2]), "netcdf_io_read_frame_system nf90_getvar c_lm_varid")

! ordering of dimensions above seen to stackoverflow to prevent error 'NetCDF: Start + count exceeds dimension bound'
nc%lc_lm_exists = .true.
else
if (allocated(cb%c_lm)) deallocate(cb%c_lm)
nc%lc_lm_exists = .false.
end if

call self%read_particle_info(nc, param, plmask, tpmask)
Expand Down

0 comments on commit 74742cf

Please sign in to comment.