diff --git a/examples/Fragmentation/Fragmentation_Movie.py b/examples/Fragmentation/Fragmentation_Movie.py index 9c3e3bc56..1d0e21bd2 100755 --- a/examples/Fragmentation/Fragmentation_Movie.py +++ b/examples/Fragmentation/Fragmentation_Movie.py @@ -143,7 +143,8 @@ def encounter_combiner(sim): ds = xr.combine_nested([data,enc],concat_dim='time').sortby("time").interpolate_na(dim="time") # Interpolate in time to make a smooth, constant time step dataset - smooth_time = np.linspace(start=tgood.isel(time=0), stop=ds.time[-1], num=num_movie_frames) + # Add a bit of padding to the time, otherwise there are some issues with the interpolation in the last few frames. + smooth_time = np.linspace(start=tgood.isel(time=0), stop=ds.time[-1], num=int(1.2*num_movie_frames)) ds = ds.interp(time=smooth_time) return ds @@ -154,7 +155,6 @@ class AnimatedScatter(object): def __init__(self, sim, animfile, title, style, nskip=1): self.ds = encounter_combiner(sim) - nframes = int(self.ds['time'].size) self.sim = sim self.title = title self.body_color_list = {'Initial conditions': 'xkcd:windows blue', @@ -168,7 +168,7 @@ def __init__(self, sim, animfile, title, style, nskip=1): self.fig, self.ax = self.setup_plot() # Then setup FuncAnimation. - self.ani = animation.FuncAnimation(self.fig, self.update_plot, interval=1, frames=range(0,nframes,nskip), blit=True) + self.ani = animation.FuncAnimation(self.fig, self.update_plot, interval=1, frames=range(0,num_movie_frames,nskip), blit=True) self.ani.save(animfile, fps=60, dpi=300, extra_args=['-vcodec', 'libx264']) print(f"Finished writing {animfile}") diff --git a/src/collision/collision_io.f90 b/src/collision/collision_io.f90 index 012230648..bd556fd7a 100644 --- a/src/collision/collision_io.f90 +++ b/src/collision/collision_io.f90 @@ -394,8 +394,11 @@ module subroutine collision_io_netcdf_write_frame_snapshot(self, history, param) allocate(pl, source=after%pl) end select npl = pl%nbody + + ! This ensures that there first idslot will have the first body in it, not id 0 which is the default for a new idvals array + if (.not.allocated(nc%idvals)) allocate(nc%idvals, source=pl%id) do i = 1, npl - idslot = findloc(history%idvals,pl%id(i),dim=1) + call nc%find_idslot(pl%id(i), idslot) call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, pl%id(i), start=[ idslot ]), "collision_io_netcdf_write_frame_snapshot nf90_put_var id_varid" ) charstring = trim(adjustl(pl%info(i)%name)) call netcdf_io_check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot ], count=[NAMELEN, 1]), "collision_io_netcdf_write_frame_snapshot nf90_put_var name_varid" ) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 37e784c41..32cabe8b5 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -248,8 +248,10 @@ module subroutine encounter_io_netcdf_write_frame_snapshot(self, history, param) call netcdf_io_check( nf90_put_var(nc%id, nc%time_varid, self%t, start=[tslot]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var time_varid" ) npl = pl%nbody + ! This ensures that there first idslot will have the first body in it, not id 0 which is the default for a new idvals array + if (.not.allocated(nc%idvals)) allocate(nc%idvals, source=pl%id) do i = 1, npl - idslot = findloc(history%idvals,pl%id(i),dim=1) + call nc%find_idslot(pl%id(i), idslot) call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, pl%id(i), start=[idslot]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var pl id_varid" ) call netcdf_io_check( nf90_put_var(nc%id, nc%rh_varid, pl%rh(:,i), start=[1,idslot,tslot], count=[NDIM,1,1]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var pl rh_varid" ) call netcdf_io_check( nf90_put_var(nc%id, nc%vh_varid, pl%vh(:,i), start=[1,idslot,tslot], count=[NDIM,1,1]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var pl vh_varid" ) @@ -269,8 +271,9 @@ module subroutine encounter_io_netcdf_write_frame_snapshot(self, history, param) end do ntp = tp%nbody + if (.not.allocated(nc%idvals)) allocate(nc%idvals, source=tp%id) do i = 1, ntp - idslot = findloc(history%idvals,tp%id(i),dim=1) + call nc%find_idslot(tp%id(i), idslot) call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, tp%id(i), start=[idslot]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var tp id_varid" ) call netcdf_io_check( nf90_put_var(nc%id, nc%rh_varid, tp%rh(:,i), start=[1,idslot,tslot], count=[NDIM,1,1]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var tp rh_varid" ) call netcdf_io_check( nf90_put_var(nc%id, nc%vh_varid, tp%vh(:,i), start=[1,idslot,tslot], count=[NDIM,1,1]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var tp vh_varid" ) diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index d489ab2ff..941ed6e16 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -248,7 +248,7 @@ module subroutine encounter_util_get_vals_storage(self, idvals, tvals) allocate(idvals(ntotal)) nlo = 1 - ! Second pass to store all ids get all of the ids stored + ! Second pass to get all of the ids stored do i = 1, nsnaps if (allocated(self%frame(i)%item)) then select type(snapshot => self%frame(i)%item) diff --git a/src/netcdf_io/netcdf_io_implementations.f90 b/src/netcdf_io/netcdf_io_implementations.f90 index 77cc3119c..c59acd0fc 100644 --- a/src/netcdf_io/netcdf_io_implementations.f90 +++ b/src/netcdf_io/netcdf_io_implementations.f90 @@ -47,7 +47,7 @@ module subroutine netcdf_io_close(self) end subroutine netcdf_io_close - module subroutine netcdf_io_find_tslot(self, t) + module subroutine netcdf_io_find_tslot(self, t, tslot) !! author: David A. Minton !! !! Given an open NetCDF file and a value of time t, finds the index of the time value (aka the time slot) to place a new set of data. @@ -56,12 +56,13 @@ module subroutine netcdf_io_find_tslot(self, t) ! Arguments class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset real(DP), intent(in) :: t !! The value of time to search for + integer(I4B), intent(out) :: tslot !! The index of the time slot where this data belongs ! Internals real(DP), dimension(:), allocatable :: tvals - self%tslot = 0 if (.not.self%lfile_is_open) return + tslot = 0 call netcdf_io_check( nf90_inquire_dimension(self%id, self%time_dimid, self%time_dimname, len=self%max_tslot), "netcdf_io_find_tslot nf90_inquire_dimension max_tslot" ) if (self%max_tslot > 0) then @@ -72,19 +73,54 @@ module subroutine netcdf_io_find_tslot(self, t) tvals(1) = -huge(1.0_DP) end if - self%tslot = findloc(tvals, t, dim=1) - if (self%tslot == 0) self%tslot = self%max_tslot + 1 - self%max_tslot = max(self%max_tslot, self%tslot) + tslot = findloc(tvals, t, dim=1) + if (tslot == 0) tslot = self%max_tslot + 1 + self%max_tslot = max(self%max_tslot, tslot) + self%tslot = tslot return end subroutine netcdf_io_find_tslot - module subroutine netcdf_io_get_idvals(self) + module subroutine netcdf_io_find_idslot(self, id, idslot) !! author: David A. Minton !! !! Given an open NetCDF file and a value of id, finds the index of the id value (aka the id slot) to place a new set of data. - !! The returned value of idslot will correspond to the first index value where the value of id is equal to a saved id value. If none are found, it is the next available index. + !! The returned value of idslot will correspond to the first index value where the value of id is greater than or equal to the saved id value. + implicit none + ! Arguments + class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + integer(I4B), intent(in) :: id !! The value of id to search for + integer(I4B), intent(out) :: idslot !! The index of the id slot where this data belongs + ! Internals + integer(I4B), dimension(:), allocatable :: idvals + + if (.not.self%lfile_is_open) return + + if (.not.allocated(self%idvals)) call self%get_idvals() + self%max_idslot = size(self%idvals) + idslot = findloc(self%idvals, id, dim=1) + if (idslot == 0) then + self%max_idslot = self%max_idslot + 1 + idslot = self%max_idslot + + ! Update the idvals array + allocate(idvals(idslot)) + idvals(1:idslot-1) = self%idvals(1:idslot-1) + idvals(idslot) = id + call move_alloc(idvals, self%idvals) + end if + + self%idslot = idslot + + return + end subroutine netcdf_io_find_idslot + + + module subroutine netcdf_io_get_idvals(self) + !! author: David A. Minton + !! + !! Gets a full list of id values implicit none ! Arguments class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset @@ -99,7 +135,7 @@ module subroutine netcdf_io_get_idvals(self) call netcdf_io_check( nf90_get_var(self%id, self%id_varid, self%idvals(:), start=[1]), "netcdf_io_find_idslot get_var" ) else allocate(self%idvals(1)) - self%idvals(1) = -huge(1) + self%idvals(1) = 0 end if return diff --git a/src/netcdf_io/netcdf_io_module.f90 b/src/netcdf_io/netcdf_io_module.f90 index 87a675efe..b8eb21d5d 100644 --- a/src/netcdf_io/netcdf_io_module.f90 +++ b/src/netcdf_io/netcdf_io_module.f90 @@ -27,6 +27,7 @@ module netcdf_io integer(I4B) :: tslot = 1 !! The current time slot that gets passed to the NetCDF reader/writer integer(I4B) :: max_tslot = 0 !! Records the last index value of time in the NetCDF file integer(I4B), dimension(:), allocatable :: idvals !! Array of id values in this NetCDF file + integer(I4B) :: idslot = 1 !! The current id slot that gets passed to the NetCDF reader/writer integer(I4B) :: max_idslot = 0 !! Records the last index value of id in the NetCDF file ! Dimension ids and variable names @@ -142,10 +143,11 @@ module netcdf_io integer(I4B) :: discard_body_id_varid !! 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. contains - procedure :: close => netcdf_io_close !! Closes an open NetCDF file - procedure :: find_tslot => netcdf_io_find_tslot !! Finds the time dimension index for a given value of t - procedure :: get_idvals => netcdf_io_get_idvals !! Gets the valid id numbers currently stored in this dataset - procedure :: sync => netcdf_io_sync !! Syncrhonize the disk and memory buffer of the NetCDF file (e.g. commit the frame files stored in memory to disk) + procedure :: close => netcdf_io_close !! Closes an open NetCDF file + procedure :: find_tslot => netcdf_io_find_tslot !! Finds the time dimension index for a given value of t + procedure :: find_idslot => netcdf_io_find_idslot !! Finds the id dimension index for a given value of id + procedure :: get_idvals => netcdf_io_get_idvals !! Gets the valid id numbers currently stored in this dataset + procedure :: sync => netcdf_io_sync !! Syncrhonize the disk and memory buffer of the NetCDF file (e.g. commit the frame files stored in memory to disk) end type netcdf_parameters interface @@ -165,11 +167,19 @@ module subroutine netcdf_io_get_idvals(self) class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset end subroutine netcdf_io_get_idvals - module subroutine netcdf_io_find_tslot(self, t) + module subroutine netcdf_io_find_tslot(self, t, tslot) implicit none class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset real(DP), intent(in) :: t !! The value of time to search for + integer(I4B), intent(out) :: tslot !! The index of the time slot where this data belongs end subroutine netcdf_io_find_tslot + + module subroutine netcdf_io_find_idslot(self, id, idslot) + implicit none + class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + integer(I4B), intent(in) :: id !! The value of id to search for + integer(I4B), intent(out) :: idslot !! The index of the id slot where this data belongs + end subroutine netcdf_io_find_idslot module subroutine netcdf_io_sync(self) implicit none diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index cfc60ca3c..12bc4f9d7 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -580,8 +580,7 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, param) associate (nc => self%system_history%nc, cb => self%cb) call nc%open(param, readonly=.true.) - call nc%find_tslot(param%t0) - tslot = nc%tslot + call nc%find_tslot(param%t0, tslot) call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%time_dimid, len=itmax), "netcdf_io_get_t0_values_system time_dimid" ) call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%name_dimid, len=idmax), "netcdf_io_get_t0_values_system name_dimid" ) allocate(vals(idmax)) @@ -627,8 +626,7 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, param) end if ! Retrieve the current bookkeeping variables - call nc%find_tslot(self%t) - tslot = nc%tslot + call nc%find_tslot(self%t, tslot) call netcdf_io_check( nf90_get_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_get_t0_values_system L_escape_varid" ) call netcdf_io_check( nf90_get_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_io_get_t0_values_system GMescape_varid" ) call netcdf_io_check( nf90_get_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), "netcdf_io_get_t0_values_system E_collisions_varid" ) @@ -962,7 +960,7 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier ! Return integer(I4B) :: ierr !! Error code: returns 0 if the read is successful ! Internals - integer(I4B) :: i, idmax, npl_check, ntp_check, str_max, status, npl, ntp + integer(I4B) :: i, idmax, npl_check, ntp_check, str_max, status, npl, ntp, tslot real(DP), dimension(:), allocatable :: rtemp real(DP), dimension(:,:), allocatable :: vectemp integer(I4B), dimension(:), allocatable :: itemp @@ -970,10 +968,10 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier call nc%open(param, readonly=.true.) - call nc%find_tslot(self%t) + call nc%find_tslot(self%t, tslot) call self%read_hdr(nc, param) - associate(cb => self%cb, pl => self%pl, tp => self%tp,tslot => nc%tslot) + associate(cb => self%cb, pl => self%pl, tp => self%tp) ! Save these values as variables as they get reset by the setup method npl = pl%nbody ntp = tp%nbody @@ -1513,7 +1511,7 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, j,idslot, old_mode + integer(I4B) :: i, j, idslot, old_mode integer(I4B), dimension(:), allocatable :: ind real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting from pseudovelocity in GR-enabled runs real(DP) :: a, e, inc, omega, capom, capm, varpi, lam, f, cape, capf @@ -1533,8 +1531,7 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) do i = 1, n j = ind(i) - idslot = self%id(j) + 1 - + call nc%find_idslot(self%id(j), idslot) !! Convert from pseudovelocity to heliocentric without replacing the current value of pseudovelocity if (param%lgr) call swiftest_gr_pseudovel2vel(param, self%mu(j), self%rh(:, j), self%vh(:, j), vh(:)) @@ -1620,7 +1617,7 @@ module subroutine swiftest_io_netcdf_write_frame_cb(self, nc, param) call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), "netcdf_io_write_frame_cb nf90_set_fill" ) - idslot = self%id + 1 + call nc%find_idslot(self%id, idslot) call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id, start=[idslot]), "netcdf_io_write_frame_cb nf90_put_var cb id_varid" ) call netcdf_io_check( nf90_put_var(nc%id, nc%status_varid, ACTIVE, start=[idslot, tslot]), "netcdf_io_write_frame_cb nf90_put_var cb id_varid" ) @@ -1650,7 +1647,6 @@ module subroutine swiftest_io_netcdf_write_frame_system(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - call nc%find_tslot(self%t) call self%write_hdr(nc, param) call self%cb%write_frame(nc, param) call self%pl%write_frame(nc, param) @@ -1671,29 +1667,29 @@ module subroutine swiftest_io_netcdf_write_hdr_system(self, nc, param) class(swiftest_nbody_system), intent(in) :: self !! Swiftest nbody system object class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + ! Internals + integer(I4B) :: tslot + + call nc%find_tslot(self%t, tslot) + call netcdf_io_check( nf90_put_var(nc%id, nc%time_varid, self%t, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var time_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var npl_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var ntp_varid" ) + if (param%lmtiny_pl) call netcdf_io_check( nf90_put_var(nc%id, nc%nplm_varid, self%pl%nplm, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var nplm_varid" ) + + if (param%lenergy) then + call netcdf_io_check( nf90_put_var(nc%id, nc%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var KE_orb_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var KE_spin_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%PE_varid, self%pe, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var PE_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%BE_varid, self%be, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var BE_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%TE_varid, self%te, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var TE_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%L_orbit_varid, self%L_orbit(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_orbit_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%L_spin_varid, self%L_spin(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_spin_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_escape_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var E_collisions_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%E_untracked_varid, self%E_untracked, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var E_untracked_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var GMescape_varid" ) + end if - associate(tslot => nc%tslot) - - call netcdf_io_check( nf90_put_var(nc%id, nc%time_varid, self%t, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var time_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var npl_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var ntp_varid" ) - if (param%lmtiny_pl) call netcdf_io_check( nf90_put_var(nc%id, nc%nplm_varid, self%pl%nplm, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var nplm_varid" ) - - if (param%lenergy) then - call netcdf_io_check( nf90_put_var(nc%id, nc%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var KE_orb_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var KE_spin_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%PE_varid, self%pe, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var PE_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%BE_varid, self%be, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var BE_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%TE_varid, self%te, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var TE_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%L_orbit_varid, self%L_orbit(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_orbit_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%L_spin_varid, self%L_spin(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_spin_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_escape_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var E_collisions_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%E_untracked_varid, self%E_untracked, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var E_untracked_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var GMescape_varid" ) - end if - - end associate return end subroutine swiftest_io_netcdf_write_hdr_system @@ -1725,11 +1721,7 @@ module subroutine swiftest_io_netcdf_write_info_body(self, nc, param) do i = 1, n j = ind(i) - idslot = findloc(nc%idvals, self%id(j), dim=1) - if (idslot == 0) then - nc%max_idslot = nc%max_idslot + 1 - idslot = nc%max_idslot - end if + call nc%find_idslot(self%id(j), idslot) call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id(j), start=[idslot]), "netcdf_io_write_info_body nf90_put_var id_varid" ) call netcdf_io_check( nf90_put_var(nc%id, nc%status_varid, self%status(j), start=[idslot,tslot]), "netcdf_io_write_info_body nf90_put_var status_varid" ) @@ -1776,7 +1768,8 @@ module subroutine swiftest_io_netcdf_write_info_cb(self, nc, param) ! This string of spaces of length NAMELEN is used to clear out any old data left behind inside the string variables call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), "netcdf_io_write_info_cb nf90_set_fill NF90_NOFILL" ) - idslot = self%id + 1 + call nc%find_idslot(self%id, idslot) + call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id, start=[idslot]), "netcdf_io_write_info_cb nf90_put_var id_varid" ) charstring = trim(adjustl(self%info%name))