From d58f67273b740404ca36369cac4acb0428018b64 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 6 Jan 2023 20:07:35 -0500 Subject: [PATCH] Lots of fiddly maintenence to get restarts cleaned up and repeatable. Dealing with a tricky case where all mass values are the same. The WHM sort on ih3 messed up the order on the restart. Also removed NUL character from strings saved by NetCDF --- src/helio/helio_util.f90 | 13 ++++++++++++- src/swiftest/swiftest_io.f90 | 19 +++++++++++++++++++ src/swiftest/swiftest_module.f90 | 13 +++++++++---- src/swiftest/swiftest_util.f90 | 12 ++++++++---- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/helio/helio_util.f90 b/src/helio/helio_util.f90 index 5de0564a0..7d887a6b2 100644 --- a/src/helio/helio_util.f90 +++ b/src/helio/helio_util.f90 @@ -21,10 +21,21 @@ module subroutine helio_util_setup_initialize_system(self, param) class(helio_nbody_system), intent(inout) :: self !! Helio nbody system object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - call whm_util_setup_initialize_system(self, param) + call swiftest_util_setup_initialize_system(self, param) call self%pl%h2b(self%cb) call self%tp%h2b(self%cb) call self%pl%sort("mass", ascending=.false.) + + ! Make sure that the discard list gets allocated initially + call self%tp_discards%setup(0, param) + call self%pl%set_mu(self%cb) + call self%tp%set_mu(self%cb) + + if (param%lgr .and. param%in_type == "ASCII") then !! pseudovelocity conversion for NetCDF input files is handled by NetCDF routines + call self%pl%v2pv(param) + call self%tp%v2pv(param) + end if + call self%pl%flatten(param) return diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index e49bdd3f0..ea6ab2c6d 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -1792,6 +1792,25 @@ module subroutine swiftest_io_netcdf_write_info_cb(self, nc, param) return end subroutine swiftest_io_netcdf_write_info_cb + module subroutine swiftest_io_remove_nul_char(string) + !! author: David A. Minton + !! + !! Remove spaces and trailing NUL characters that are introduced by NetCDF strings + implicit none + ! Arguments + character(len=*), intent(inout) :: string !! String to make upper case + ! Internals + integer(I4B) :: pos + + pos = index(string, achar(0)) - 1 + if (pos > 0) then + string = trim(adjustl(string(1:pos))) + else + string = trim(adjustl(string)) + end if + + return + end subroutine swiftest_io_remove_nul_char module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, iomsg) !! author: The Purdue Swiftest Team - David A. Minton, Carlisle A. Wishard, Jennifer L.L. Pouplin, and Jacob R. Elliott diff --git a/src/swiftest/swiftest_module.f90 b/src/swiftest/swiftest_module.f90 index ce74907b5..b965e57d3 100644 --- a/src/swiftest/swiftest_module.f90 +++ b/src/swiftest/swiftest_module.f90 @@ -721,11 +721,10 @@ module subroutine swiftest_io_netcdf_write_info_cb(self, nc, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine swiftest_io_netcdf_write_info_cb - module subroutine swiftest_io_write_discard(self, param) + module subroutine swiftest_io_remove_nul_char(string) implicit none - class(swiftest_nbody_system), intent(inout) :: self !! SyMBA nbody system object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - end subroutine swiftest_io_write_discard + character(len=*), intent(inout) :: string !! String to remove nul characters from + end subroutine swiftest_io_remove_nul_char module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, iomsg) implicit none @@ -861,6 +860,12 @@ module subroutine swiftest_io_toupper(string) character(*), intent(inout) :: string !! String to make upper case end subroutine swiftest_io_toupper + module subroutine swiftest_io_write_discard(self, param) + implicit none + class(swiftest_nbody_system), intent(inout) :: self !! SyMBA nbody system object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + end subroutine swiftest_io_write_discard + module subroutine swiftest_io_write_frame_system(self, param) implicit none class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody_system object diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index ebe9e8c87..aa3f4c4d0 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -2411,16 +2411,20 @@ module subroutine swiftest_util_set_particle_info(self, name, particle_type, sta fmtlabel = "(A" // trim(adjustl(lenstr)) // ")" if (present(name)) then - write(self%name, fmtlabel) trim(adjustl(name)) + write(self%name, fmtlabel) name + call swiftest_io_remove_nul_char(self%name) end if if (present(particle_type)) then - write(self%particle_type, fmtlabel) trim(adjustl(particle_type)) + write(self%particle_type, fmtlabel) particle_type + call swiftest_io_remove_nul_char(self%particle_type) end if if (present(status)) then - write(self%status, fmtlabel) trim(adjustl(status)) + write(self%status, fmtlabel) status + call swiftest_io_remove_nul_char(self%status) end if if (present(origin_type)) then - write(self%origin_type, fmtlabel) trim(adjustl(origin_type)) + write(self%origin_type, fmtlabel) origin_type + call swiftest_io_remove_nul_char(self%origin_type) end if if (present(origin_time)) then self%origin_time = origin_time