From 966dc068ef214a42bf0d2279c02035105358ee6e Mon Sep 17 00:00:00 2001 From: David A Minton Date: Mon, 15 Nov 2021 16:33:09 -0500 Subject: [PATCH] Improved handling of mass conservation error halting. Failed output info is now saved in a time slot after the present one in order to prevent overwriting of the bin.nc with bad data --- src/io/io.f90 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index b84569cca..7ec71d9ae 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -72,11 +72,20 @@ module subroutine io_conservation_report(self, param, lterminal) if (lterminal) write(*, EGYTERMFMT) Lerror, Ecoll_error, Etotal_error, Merror if (abs(Merror) > 100 * epsilon(Merror)) then write(*,*) "Severe error! Mass not conserved! Halting!" - call pl%xv2el(cb) - call self%write_hdr(param%nciu, param) - call cb%write_frame(param%nciu, param) - call pl%write_frame(param%nciu, param) - call param%nciu%close() + if ((param%out_type == REAL4_TYPE) .or. (param%out_type == REAL8_TYPE)) then + write(*,*) "Merror = ", Merror + write(*,*) "GMtot_now : ",GMtot_now + write(*,*) "GMtot_orig: ",system%GMtot_orig + write(*,*) "Difference: ",GMtot_now - system%GMtot_orig + else if ((param%out_type == NETCDF_FLOAT_TYPE) .or. (param%out_type == NETCDF_DOUBLE_TYPE)) then + ! Save the frame of data to the bin file in the slot just after the present one for diagnostics + param%ioutput = param%ioutput + 1_I8B + call pl%xv2el(cb) + call self%write_hdr(param%nciu, param) + call cb%write_frame(param%nciu, param) + call pl%write_frame(param%nciu, param) + call param%nciu%close() + end if call util_exit(FAILURE) end if end if