From d4fb5e363c43671da596c0fb59c71367d7cb7c52 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Wed, 8 Jun 2016 21:51:02 +0200 Subject: [PATCH] Fix logic for presaturation To: subsurface@subsurface-divelog.org There were two problems in the calculation of tissue pre- saturation from previous dives: We added the surface interval after the dive rather than before and when also took dives into accout that were in the future of the dive considerd. Reported-by: Timothy Massey Signed-off-by: Robert C. Helling --- core/divelist.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/divelist.c b/core/divelist.c index 1ac19bd..fa100c2 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -400,6 +400,9 @@ double init_decompression(struct dive *dive) /* again skip dives from different trips */ if (dive->divetrip && dive->divetrip != pdive->divetrip) continue; + /* Don't add future dives */ + if (pdive->when > dive->when) + continue; /* This could be break if the divelist is always sorted */ surface_pressure = get_surface_pressure_in_mbar(pdive, true) / 1000.0; if (!deco_init) { clear_deco(surface_pressure); @@ -408,12 +411,6 @@ double init_decompression(struct dive *dive) dump_tissues(); #endif } - add_dive_to_deco(pdive); - laststart = pdive->when; -#if DECO_CALC_DEBUG & 2 - printf("added dive #%d\n", pdive->number); - dump_tissues(); -#endif if (pdive->when > lasttime) { surface_time = pdive->when - lasttime; lasttime = pdive->when + pdive->duration.seconds; @@ -423,6 +420,12 @@ double init_decompression(struct dive *dive) dump_tissues(); #endif } + add_dive_to_deco(pdive); + laststart = pdive->when; +#if DECO_CALC_DEBUG & 2 + printf("added dive #%d\n", pdive->number); + dump_tissues(); +#endif } /* add the final surface time */ if (lasttime && dive->when > lasttime) { -- 2.7.4 (Apple Git-66)