aboutsummaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-12-11 21:28:18 -0800
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-12-11 21:28:18 -0800
commit51176cb0897c04340d831a6a9f967933c5f7f059 (patch)
tree6bd4887f5bc725a61c7c20be29ff90cfdde5f9c4 /divelist.c
parentbb09b67182187be284ae1f80fc7174da0dcd9ee3 (diff)
downloadsubsurface-51176cb0897c04340d831a6a9f967933c5f7f059.tar.gz
Make the dive gas record the single highest mix
.. using the regular sorting rules: sort by Helium content first, Oxygen content second. Air always sorts last (even behind the theoretical hypoxic Nitrox that nobody sane would use). This is what Don Kinney implies would be the natural thing for a trimix diver. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/divelist.c b/divelist.c
index 546d54bd0..5b6c7e3e1 100644
--- a/divelist.c
+++ b/divelist.c
@@ -223,7 +223,13 @@ static void temperature_data_func(GtkTreeViewColumn *col,
g_object_set(renderer, "text", buffer, NULL);
}
-/* Get max O2/He permille levels for a dive for the dive summary */
+/*
+ * Get "maximal" dive gas for a dive.
+ * Rules:
+ * - Trimix trumps nitrox (highest He wins, O2 breaks ties)
+ * - Nitrox trumps air (even if hypoxic)
+ * These are the same rules as the inter-dive sorting rules.
+ */
static void get_dive_gas(struct dive *dive, int *o2, int *he)
{
int i;
@@ -231,10 +237,18 @@ static void get_dive_gas(struct dive *dive, int *o2, int *he)
for (i = 0; i < MAX_CYLINDERS; i++) {
struct gasmix *mix = &dive->cylinder[i].gasmix;
- if (mix->o2.permille > maxo2)
- maxo2 = mix->o2.permille;
- if (mix->he.permille > maxhe)
- maxhe = mix->he.permille;
+ int o2 = mix->o2.permille;
+ int he = mix->he.permille;
+
+ if (he > maxhe)
+ goto newmax;
+ if (he < maxhe)
+ continue;
+ if (o2 <= maxo2)
+ continue;
+newmax:
+ maxhe = he;
+ maxo2 = o2;
}
*o2 = maxo2;
*he = maxhe;