summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.c117
-rw-r--r--dive.h2
-rw-r--r--divelist.c10
-rw-r--r--equipment.c2
-rw-r--r--libdivecomputer.c2
-rw-r--r--parse-xml.c117
-rw-r--r--statistics.c2
7 files changed, 128 insertions, 124 deletions
diff --git a/dive.c b/dive.c
index 3fa09bd10..3774ba80d 100644
--- 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 0549843ab..bdf3aa6e1 100644
--- 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 */
diff --git a/divelist.c b/divelist.c
index 86e7daf57..4ab61997c 100644
--- a/divelist.c
+++ b/divelist.c
@@ -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;
}
diff --git a/equipment.c b/equipment.c
index 482fb4e1c..d2c7891ae 100644
--- a/equipment.c
+++ b/equipment.c
@@ -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);
}
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 9d4c1065a..daf724190 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -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;
diff --git a/parse-xml.c b/parse-xml.c
index 4d8568997..684061072 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -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;
diff --git a/statistics.c b/statistics.c
index f8f9d0e24..9510030d7 100644
--- a/statistics.c
+++ b/statistics.c
@@ -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;