]> git.tdb.fi Git - ext/subsurface.git/blobdiff - profile.c
Correctly plot dives ending below the surface
[ext/subsurface.git] / profile.c
index 173032a130a85088c10dfd26e0a0bae2dbd64bd2..60e0f4215e2b69e481dd11501d188f36c8d64a15 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -1098,7 +1098,7 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
                entry->temperature = sample->temperature.mkelvin;
 
                if (depth || lastdepth)
-                       lastindex = i+pi_idx;
+                       lastindex = i + pi_idx;
 
                lastdepth = depth;
                if (depth > pi->maxdepth)
@@ -1162,9 +1162,12 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
        i = nr + 2;
        pi->entry[i].sec = sec + 20;
        pi->entry[i+1].sec = sec + 40;
-       /* the number of actual entries - we may have allocated more if there
-        * were gas change events, but this is how many were filled */
+       /* the number of actual entries - some computers have lots of
+        * depth 0 samples at the end of a dive, we want to make sure
+        * we have exactly one of them at the end */
        pi->nr = lastindex+1;
+       while (pi->nr <= i+2 && pi->entry[pi->nr-1].depth > 0)
+               pi->nr++;
        pi->maxtime = pi->entry[lastindex].sec;
 
        pi->endpressure = pi->minpressure = dive->cylinder[0].end.mbar;