]> git.tdb.fi Git - ext/subsurface.git/blobdiff - dive.c
Fix profile and average depth for freedives
[ext/subsurface.git] / dive.c
diff --git a/dive.c b/dive.c
index f5d0828015e2b64990a390d877839e43335ffd48..54784cdbabfb01fbb5c5a8db539cdc481f20c613 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -472,8 +472,21 @@ struct dive *fixup_dive(struct dive *dive)
                        cyl->sample_end.mbar = 0;
                }
        }
-       if (end < 0)
+       if (end < 0) {
+               /* Assume an ascent/descent rate of 9 m/min */
+               int depth = dive->maxdepth.mm;
+               int asc_desc_time = depth*60/9000;
+               int duration = dive->duration.seconds;
+
+               /* Some sanity checks against insane dives */
+               if (duration < 2)
+                       duration = 2;
+               if (asc_desc_time * 2 >= duration)
+                       asc_desc_time = duration/2;
+
+               dive->meandepth.mm = depth*(duration-asc_desc_time)/duration;
                return dive;
+       }
 
        update_duration(&dive->duration, end - start);
        if (start != end)