]> git.tdb.fi Git - ext/subsurface.git/blobdiff - dive.c
Merge branch 'quit-handling' of git://github.com/dirkhh/subsurface
[ext/subsurface.git] / dive.c
diff --git a/dive.c b/dive.c
index 32ea2ffe19a72f240df0638eafb1a9be3770a7d8..41bbabd698868bf43c90555acc38d13a83b41a9c 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -1,8 +1,35 @@
+/* dive.c */
+/* maintains the internal dive list structure */
 #include <string.h>
 #include <stdio.h>
 
 #include "dive.h"
 
+double get_depth_units(unsigned int mm, int *frac, const char **units)
+{
+       int decimals;
+       double d;
+       const char *unit;
+
+       switch (output_units.length) {
+       case METERS:
+               d = mm / 1000.0;
+               unit = "m";
+               decimals = d < 20;
+               break;
+       case FEET:
+               d = mm_to_feet(mm);
+               unit = "ft";
+               decimals = 0;
+               break;
+       }
+       if (frac)
+               *frac = decimals;
+       if (units)
+               *units = unit;
+       return d;
+}
+
 struct dive *alloc_dive(void)
 {
        const int initial_samples = 5;
@@ -117,7 +144,6 @@ struct dive *fixup_dive(struct dive *dive)
        int maxdepth = 0, mintemp = 0;
        int lastdepth = 0;
        int lasttemp = 0;
-       temperature_t *redundant_temp = NULL;
 
        for (i = 0; i < dive->samples; i++) {
                struct sample *sample = dive->sample + i;
@@ -141,17 +167,12 @@ struct dive *fixup_dive(struct dive *dive)
                        /*
                         * If we have consecutive identical
                         * temperature readings, throw away
-                        * the redundant ones. We care about
-                        * the "edges" only.
+                        * the redundant ones.
                         */
-                       if (lasttemp == temp) {
-                               if (redundant_temp)
-                                       redundant_temp->mkelvin = 0;
-                               redundant_temp = &sample->temperature;
-                       } else {
-                               redundant_temp = NULL;
+                       if (lasttemp == temp)
+                               sample->temperature.mkelvin = 0;
+                       else
                                lasttemp = temp;
-                       }
 
                        if (!mintemp || temp < mintemp)
                                mintemp = temp;