aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-13 19:37:41 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-13 19:37:41 -0800
commitb94a93d06154a7b245e374512592fc25d8e58370 (patch)
tree6c2d379838a6d584c46f8f7e4d5f00fde1300c57
parent23ce727e62c5670ca30c487fc9fd52eb25883de5 (diff)
downloadsubsurface-b94a93d06154a7b245e374512592fc25d8e58370.tar.gz
During multi-dive deco calculations don't look at dives from other trips
Previously the code in init_decompression() would mindlessly walk back the dive_table until it found a gap of at least 48h and take all those dives into consideration when calculating tissue saturation. This goes horribly wrong if you load dives from two divers into the same data file. With this commit things will still turn out correctly, as long as the dives are in separate trips in for each of the divers. So with this I can load both Linus' and my divelog and things stay sane even on our shared dive trips. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/divelist.c b/divelist.c
index e7eb5562d..0cf4d7be0 100644
--- a/divelist.c
+++ b/divelist.c
@@ -847,9 +847,10 @@ static struct gasmix air = { .o2.permille = 209 };
double init_decompression(struct dive *dive)
{
int i, divenr = -1;
- timestamp_t when;
+ unsigned int surface_time;
+ timestamp_t when, lasttime = 0;
gboolean deco_init = FALSE;
- double tissue_tolerance;
+ double tissue_tolerance, surface_pressure;
if (!dive)
return 0.0;
@@ -859,16 +860,21 @@ double init_decompression(struct dive *dive)
i = divenr;
while (--i) {
struct dive* pdive = get_dive(i);
+ /* we don't want to mix dives from different trips as we keep looking
+ * for how far back we need to go */
+ if (dive->divetrip && pdive->divetrip != dive->divetrip)
+ continue;
if (!pdive || pdive->when > when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
break;
when = pdive->when;
+ lasttime = when + pdive->duration.seconds;
}
-
while (++i < divenr) {
struct dive* pdive = get_dive(i);
- double surface_pressure = pdive->surface_pressure.mbar ? pdive->surface_pressure.mbar / 1000.0 : 1.013;
- unsigned int surface_time = get_dive(i+1)->when - pdive->when - pdive->duration.seconds;
-
+ /* again skip dives from different trips */
+ if (dive->divetrip && dive->divetrip != pdive->divetrip)
+ continue;
+ surface_pressure = pdive->surface_pressure.mbar ? pdive->surface_pressure.mbar / 1000.0 : 1.013;
if (!deco_init) {
clear_deco(surface_pressure);
deco_init = TRUE;
@@ -881,6 +887,20 @@ double init_decompression(struct dive *dive)
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;
+ tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive);
+#if DECO_CALC_DEBUG & 2
+ printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
+ dump_tissues();
+#endif
+ }
+ }
+ /* add the final surface time */
+ if (lasttime && dive->when > lasttime) {
+ surface_time = dive->when - lasttime;
+ surface_pressure = dive->surface_pressure.mbar ? dive->surface_pressure.mbar / 1000.0 : 1.013;
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive);
#if DECO_CALC_DEBUG & 2
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));