From 385b2157148c31f860fec5483521b1b863bc11e4 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 14 Oct 2021 11:33:37 -0400 Subject: [PATCH] Fixed netcdf_get_old_t_final_system to read NetCDF formatted files properly in order to determine the last time value --- src/io/io.f90 | 2 +- src/netcdf/netcdf.f90 | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index e00310a1b..e6f84910f 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -1215,8 +1215,8 @@ module subroutine io_read_in_base(self,param) case(NETCDF_DOUBLE_TYPE, NETCDF_FLOAT_TYPE) select type(self) class is (swiftest_body) - if (self%nbody == 0) return call self%setup(self%nbody, param) + if (self%nbody == 0) return end select ierr = self%read_frame(param%nciu, param) diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 339a652e6..5e05c68e5 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -63,23 +63,26 @@ module function netcdf_get_old_t_final_system(self, param) result(old_t_final) ! Result real(DP) :: old_t_final ! Internals - class(swiftest_nbody_system), allocatable :: tmpsys - class(swiftest_parameters), allocatable :: tmpparam - Integer(I4B) :: ierr + !class(swiftest_nbody_system), allocatable :: tmpsys + !class(swiftest_parameters), allocatable :: tmpparam + !integer(I4B) :: ierr + integer(I4B) :: itmax + real(DP), dimension(:), allocatable :: tvals - old_t_final = 0.0_DP - allocate(tmpsys, source=self) - allocate(tmpparam, source=param) - ierr = 0 - do - ierr = tmpsys%read_frame(param%nciu, tmpparam) - end do - if (is_iostat_end(ierr)) then - old_t_final = tmpparam%t - return - end if + call check( nf90_open(param%outfile, NF90_NOWRITE, param%nciu%ncid) ) + call check( nf90_inquire_dimension(param%nciu%ncid, param%nciu%time_dimid, len=itmax) ) + allocate(tvals(itmax)) + call check( nf90_inq_varid(param%nciu%ncid, TIME_DIMNAME, param%nciu%time_varid) ) + call check( nf90_get_var(param%nciu%ncid, param%nciu%time_varid, tvals(:)) ) + call check( nf90_close(param%nciu%ncid) ) + + old_t_final = tvals(itmax) + + deallocate(tvals) + + return end function netcdf_get_old_t_final_system @@ -303,7 +306,7 @@ module subroutine netcdf_open(self, param) class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters - call check( nf90_open(param%outfile, nf90_write, self%ncid) ) + call check( nf90_open(param%outfile, NF90_WRITE, self%ncid) ) call check( nf90_inq_varid(self%ncid, TIME_DIMNAME, self%time_varid)) call check( nf90_inq_varid(self%ncid, ID_DIMNAME, self%id_varid))