]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Merge branch 'mac' of git://git.hohndel.org/subsurface
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 1 Jan 2012 22:37:38 +0000 (14:37 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 1 Jan 2012 22:37:38 +0000 (14:37 -0800)
* 'mac' of git://git.hohndel.org/subsurface:
  Turn subsurface into a real Mac application

dive.c
dive.h
divelist.c
equipment.c
libdivecomputer.c
parse-xml.c
statistics.c

diff --git a/dive.c b/dive.c
index 3fa09bd10c05982a9972c0db8a58a76314543f59..3774ba80d037d77b9077a48e42fea16077cf50bc 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -234,6 +234,122 @@ static int same_rounded_pressure(pressure_t a, pressure_t b)
        return abs(a.mbar - b.mbar) <= 500;
 }
 
+static void sanitize_gasmix(struct gasmix *mix)
+{
+       unsigned int o2, he;
+
+       o2 = mix->o2.permille;
+       he = mix->he.permille;
+
+       /* Regular air: leave empty */
+       if (!he) {
+               if (!o2)
+                       return;
+               /* 20.9% or 21% O2 is just air */
+               if (o2 >= 209 && o2 <= 210) {
+                       mix->o2.permille = 0;
+                       return;
+               }
+       }
+
+       /* Sane mix? */
+       if (o2 <= 1000 && he <= 1000 && o2+he <= 1000)
+               return;
+       fprintf(stderr, "Odd gasmix: %d O2 %d He\n", o2, he);
+       memset(mix, 0, sizeof(*mix));
+}
+
+/*
+ * See if the size/workingpressure looks like some standard cylinder
+ * size, eg "AL80".
+ */
+static void match_standard_cylinder(cylinder_type_t *type)
+{
+       double cuft;
+       int psi, len;
+       const char *fmt;
+       char buffer[20], *p;
+
+       /* Do we already have a cylinder description? */
+       if (type->description)
+               return;
+
+       cuft = ml_to_cuft(type->size.mliter);
+       cuft *= to_ATM(type->workingpressure);
+       psi = to_PSI(type->workingpressure);
+
+       switch (psi) {
+       case 2300 ... 2500:     /* 2400 psi: LP tank */
+               fmt = "LP%d";
+               break;
+       case 2600 ... 2700:     /* 2640 psi: LP+10% */
+               fmt = "LP%d";
+               break;
+       case 2900 ... 3100:     /* 3000 psi: ALx tank */
+               fmt = "AL%d";
+               break;
+       case 3400 ... 3500:     /* 3442 psi: HP tank */
+               fmt = "HP%d";
+               break;
+       case 3700 ... 3850:     /* HP+10% */
+               fmt = "HP%d+";
+               break;
+       default:
+               return;
+       }
+       len = snprintf(buffer, sizeof(buffer), fmt, (int) (cuft+0.5));
+       p = malloc(len+1);
+       if (!p)
+               return;
+       memcpy(p, buffer, len+1);
+       type->description = p;
+}
+
+
+/*
+ * There are two ways to give cylinder size information:
+ *  - total amount of gas in cuft (depends on working pressure and physical size)
+ *  - physical size
+ *
+ * where "physical size" is the one that actually matters and is sane.
+ *
+ * We internally use physical size only. But we save the workingpressure
+ * so that we can do the conversion if required.
+ */
+static void sanitize_cylinder_type(cylinder_type_t *type)
+{
+       double volume_of_air, atm, volume;
+
+       /* If we have no working pressure, it had *better* be just a physical size! */
+       if (!type->workingpressure.mbar)
+               return;
+
+       /* No size either? Nothing to go on */
+       if (!type->size.mliter)
+               return;
+
+       if (input_units.volume == CUFT) {
+               /* confusing - we don't really start from ml but millicuft !*/
+               volume_of_air = cuft_to_l(type->size.mliter);
+               atm = to_ATM(type->workingpressure);            /* working pressure in atm */
+               volume = volume_of_air / atm;                   /* milliliters at 1 atm: "true size" */
+               type->size.mliter = volume + 0.5;
+       }
+
+       /* Ok, we have both size and pressure: try to match a description */
+       match_standard_cylinder(type);
+}
+
+static void sanitize_cylinder_info(struct dive *dive)
+{
+       int i;
+
+       for (i = 0; i < MAX_CYLINDERS; i++) {
+               sanitize_gasmix(&dive->cylinder[i].gasmix);
+               sanitize_cylinder_type(&dive->cylinder[i].type);
+       }
+}
+
 struct dive *fixup_dive(struct dive *dive)
 {
        int i,j;
@@ -246,6 +362,7 @@ struct dive *fixup_dive(struct dive *dive)
        int lasttemp = 0, lastpressure = 0;
        int pressure_delta[MAX_CYLINDERS] = {INT_MAX, };
 
+       sanitize_cylinder_info(dive);
        for (i = 0; i < dive->samples; i++) {
                struct sample *sample = dive->sample + i;
                int time = sample->time.seconds;
diff --git a/dive.h b/dive.h
index 0549843ab5374cdca86d5be614c40a9017d0a6d8..bdf3aa6e1f52fc8c553377592537741dc95381e9 100644 (file)
--- a/dive.h
+++ b/dive.h
@@ -326,4 +326,6 @@ const char *monthname(int mon);
 #define FIVE_STARS     UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
 extern const char *star_strings[];
 
+#define AIR_PERMILLE 209
+
 #endif /* DIVE_H */
index 86e7daf571052104710ce8060ace9af34c11a17f..4ab61997cfc4e71c374b0f6606708e760377e14d 100644 (file)
@@ -244,7 +244,7 @@ static void get_dive_gas(struct dive *dive, int *o2, int *he, int *o2low)
                if (cylinder_none(cyl))
                        continue;
                if (!o2)
-                       o2 = 209;
+                       o2 = AIR_PERMILLE;
                if (o2 < mino2)
                        mino2 = o2;
                if (he > maxhe)
@@ -258,7 +258,7 @@ newmax:
                maxo2 = o2;
        }
        /* All air? Show/sort as "air"/zero */
-       if (!maxhe && maxo2 == 209 && mino2 == maxo2)
+       if (!maxhe && maxo2 == AIR_PERMILLE && mino2 == maxo2)
                maxo2 = mino2 = 0;
        *o2 = maxo2;
        *he = maxhe;
@@ -392,8 +392,10 @@ static int calculate_otu(struct dive *dive)
                struct sample *sample = dive->sample + i;
                struct sample *psample = sample - 1;
                t = sample->time.seconds - psample->time.seconds;
-               po2 = dive->cylinder[sample->cylinderindex].gasmix.o2.permille / 1000.0 *
-                       (sample->depth.mm + 10000) / 10000.0;
+               int o2 = dive->cylinder[sample->cylinderindex].gasmix.o2.permille;
+               if (!o2)
+                       o2 = AIR_PERMILLE;
+               po2 = o2 / 1000.0 * (sample->depth.mm + 10000) / 10000.0;
                if (po2 >= 0.5)
                        otu += pow(po2 - 0.5, 0.83) * t / 30.0;
        }
index 482fb4e1c3ee7595e1824d1e1ee595d0743fd21a..d2c7891aef4569c334d2a3c210be73aaf51d25cc 100644 (file)
@@ -285,7 +285,7 @@ static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
        o2 = cyl->gasmix.o2.permille / 10.0;
        he = cyl->gasmix.he.permille / 10.0;
        if (!o2)
-               o2 = 21.0;
+               o2 = AIR_PERMILLE / 10.0;
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->he), he);
 }
index 9d4c1065a3817ce046798448b7c7a39a2a10be2a..daf724190d44d7868ff1a753c29a6a9954c06e09 100644 (file)
@@ -109,7 +109,7 @@ static int parse_gasmixes(struct dive *dive, parser_t *parser, int ngases)
                he = gasmix.helium * 1000 + 0.5;
 
                /* Ignore bogus data - libdivecomputer does some crazy stuff */
-               if (o2 < 210 || o2 >= 1000)
+               if (o2 <= AIR_PERMILLE || o2 >= 1000)
                        o2 = 0;
                if (he < 0 || he >= 800 || o2+he >= 1000)
                        he = 0;
index 4d8568997d835205e8624dd9becef1f6c8f04362..6840610728e0e0f6da0f89d1218e11d7c9a101c5 100644 (file)
@@ -1063,127 +1063,10 @@ static void dive_start(void)
        memset(&tm, 0, sizeof(tm));
 }
 
-static void sanitize_gasmix(struct gasmix *mix)
-{
-       unsigned int o2, he;
-
-       o2 = mix->o2.permille;
-       he = mix->he.permille;
-
-       /* Regular air: leave empty */
-       if (!he) {
-               if (!o2)
-                       return;
-               /* 20.9% or 21% O2 is just air */
-               if (o2 >= 209 && o2 <= 210) {
-                       mix->o2.permille = 0;
-                       return;
-               }
-       }
-
-       /* Sane mix? */
-       if (o2 <= 1000 && he <= 1000 && o2+he <= 1000)
-               return;
-       fprintf(stderr, "Odd gasmix: %d O2 %d He\n", o2, he);
-       memset(mix, 0, sizeof(*mix));
-}
-
-/*
- * See if the size/workingpressure looks like some standard cylinder
- * size, eg "AL80".
- */
-static void match_standard_cylinder(cylinder_type_t *type)
-{
-       double cuft;
-       int psi, len;
-       const char *fmt;
-       char buffer[20], *p;
-
-       /* Do we already have a cylinder description? */
-       if (type->description)
-               return;
-
-       cuft = ml_to_cuft(type->size.mliter);
-       cuft *= to_ATM(type->workingpressure);
-       psi = to_PSI(type->workingpressure);
-
-       switch (psi) {
-       case 2300 ... 2500:     /* 2400 psi: LP tank */
-               fmt = "LP%d";
-               break;
-       case 2600 ... 2700:     /* 2640 psi: LP+10% */
-               fmt = "LP%d";
-               break;
-       case 2900 ... 3100:     /* 3000 psi: ALx tank */
-               fmt = "AL%d";
-               break;
-       case 3400 ... 3500:     /* 3442 psi: HP tank */
-               fmt = "HP%d";
-               break;
-       case 3700 ... 3850:     /* HP+10% */
-               fmt = "HP%d+";
-               break;
-       default:
-               return;
-       }
-       len = snprintf(buffer, sizeof(buffer), fmt, (int) (cuft+0.5));
-       p = malloc(len+1);
-       if (!p)
-               return;
-       memcpy(p, buffer, len+1);
-       type->description = p;
-}
-
-
-/*
- * There are two ways to give cylinder size information:
- *  - total amount of gas in cuft (depends on working pressure and physical size)
- *  - physical size
- *
- * where "physical size" is the one that actually matters and is sane.
- *
- * We internally use physical size only. But we save the workingpressure
- * so that we can do the conversion if required.
- */
-static void sanitize_cylinder_type(cylinder_type_t *type)
-{
-       double volume_of_air, atm, volume;
-
-       /* If we have no working pressure, it had *better* be just a physical size! */
-       if (!type->workingpressure.mbar)
-               return;
-
-       /* No size either? Nothing to go on */
-       if (!type->size.mliter)
-               return;
-
-       if (input_units.volume == CUFT) {
-               /* confusing - we don't really start from ml but millicuft !*/
-               volume_of_air = cuft_to_l(type->size.mliter);
-               atm = to_ATM(type->workingpressure);            /* working pressure in atm */
-               volume = volume_of_air / atm;                   /* milliliters at 1 atm: "true size" */
-               type->size.mliter = volume + 0.5;
-       }
-
-       /* Ok, we have both size and pressure: try to match a description */
-       match_standard_cylinder(type);
-}
-
-static void sanitize_cylinder_info(struct dive *dive)
-{
-       int i;
-
-       for (i = 0; i < MAX_CYLINDERS; i++) {
-               sanitize_gasmix(&dive->cylinder[i].gasmix);
-               sanitize_cylinder_type(&dive->cylinder[i].type);
-       }
-}
-
 static void dive_end(void)
 {
        if (!dive)
                return;
-       sanitize_cylinder_info(dive);
        record_dive(dive);
        dive = NULL;
        cylinder_index = 0;
index f8f9d0e24549ca10c568eb85fcc2b957ea14a814..9510030d717655e06b1104474814429e2af3ef07 100644 (file)
@@ -171,7 +171,7 @@ void show_dive_stats(struct dive *dive)
                end = cyl->end.mbar ? : cyl->sample_end.mbar;
                if (!cylinder_none(cyl)) {
                        /* 0% O2 strangely means air, so 21% - I don't like that at all */
-                       int o2 = cyl->gasmix.o2.permille ? : 209;
+                       int o2 = cyl->gasmix.o2.permille ? : AIR_PERMILLE;
                        if (offset > 0) {
                                snprintf(buf+offset, 80-offset, ", ");
                                offset += 2;