From 74742cf9f9f887cfd62c775f2b4ef82dfdcb4307 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 27 Feb 2024 12:33:21 -0500 Subject: [PATCH] Changed the netcdf IO routine to set a flag indicating whether c_lm exists or not. --- src/netcdf_io/netcdf_io_module.f90 | 2 ++ src/swiftest/swiftest_coarray.f90 | 1 + src/swiftest/swiftest_io.f90 | 13 ++++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/netcdf_io/netcdf_io_module.f90 b/src/netcdf_io/netcdf_io_module.f90 index c9d0df68e..2c072186f 100644 --- a/src/netcdf_io/netcdf_io_module.f90 +++ b/src/netcdf_io/netcdf_io_module.f90 @@ -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 diff --git a/src/swiftest/swiftest_coarray.f90 b/src/swiftest/swiftest_coarray.f90 index c8e4da943..60912902f 100644 --- a/src/swiftest/swiftest_coarray.f90 +++ b/src/swiftest/swiftest_coarray.f90 @@ -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 diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index a7a341e96..0bbd4c7cd 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -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, & @@ -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" ) @@ -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)