]> git.tdb.fi Git - ext/subsurface.git/blobdiff - dive.c
Fix crash when editing weight system info
[ext/subsurface.git] / dive.c
diff --git a/dive.c b/dive.c
index 57a735c8e72d2969cf7469c5969373cc94d4b0fc..f4bf497a7da0edeafb91b5a26b1de067f87d64b7 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -120,6 +120,28 @@ double get_depth_units(unsigned int mm, int *frac, const char **units)
        return d;
 }
 
+double get_weight_units(unsigned int grams, int *frac, const char **units)
+{
+       int decimals;
+       double value;
+       const char* unit;
+
+       if (output_units.weight == LBS) {
+               value = grams_to_lbs(grams);
+               unit = "lbs";
+               decimals = 0;
+       } else {
+               value = grams / 1000.0;
+               unit = "kg";
+               decimals = 1;
+       }
+       if (frac)
+               *frac = decimals;
+       if (units)
+               *units = unit;
+       return value;
+}
+
 struct dive *alloc_dive(void)
 {
        const int initial_samples = 5;
@@ -451,7 +473,12 @@ struct dive *fixup_dive(struct dive *dive)
                }
        }
        if (end < 0)
+       {
+               /* Assume an ascent/descent rate of 9 m/min */
+               int asc_desc_time = dive->maxdepth.mm*60/9000;
+               dive->meandepth.mm = dive->maxdepth.mm*(dive->duration.seconds-asc_desc_time)/dive->duration.seconds;
                return dive;
+       }
 
        update_duration(&dive->duration, end - start);
        if (start != end)
@@ -464,6 +491,7 @@ struct dive *fixup_dive(struct dive *dive)
        add_people(dive->buddy);
        add_people(dive->divemaster);
        add_location(dive->location);
+       add_suit(dive->suit);
        for (i = 0; i < MAX_CYLINDERS; i++) {
                cylinder_t *cyl = dive->cylinder + i;
                add_cylinder_description(&cyl->type);
@@ -681,6 +709,7 @@ struct dive *try_to_merge(struct dive *a, struct dive *b)
        MERGE_TXT(res, a, b, buddy);
        MERGE_TXT(res, a, b, divemaster);
        MERGE_MAX(res, a, b, rating);
+       MERGE_TXT(res, a, b, suit);
        MERGE_MAX(res, a, b, number);
        MERGE_MAX(res, a, b, maxdepth.mm);
        res->meandepth.mm = 0;