As pointed out in the user forum, we did not properly take into account tissue 
saturation from previous dives. Turns out, there were two problems:

When determining which dives to consider, we went back in the dive list to the 
first dive in the past of the presently considered dive and then further back 
in time until there was a 48h break. Then we added the saturation from there 
on. In the case of a planned dive (which at the planning stage has number -1), 
this added also dives in the future of the to be planned dive. Plus a very long 
desaturation.

Second, when adding the dive, it then added the surface interval from before 
that dive (rather than the other way around).

Please people (Rick?), could you have a look at the code and check if this 
makes sense. It does so at least in my test case.

Best
Robert

From d4fb5e363c43671da596c0fb59c71367d7cb7c52 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Wed, 8 Jun 2016 21:51:02 +0200
Subject: [PATCH] Fix logic for presaturation
To: [email protected]

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 <[email protected]>
---
 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)

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to