summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/dive.c6
-rw-r--r--core/gas.c17
-rw-r--r--core/gas.h6
3 files changed, 26 insertions, 3 deletions
diff --git a/core/dive.c b/core/dive.c
index f79af7ed2..c3fd95bf1 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -2065,7 +2065,7 @@ void fill_pressures(struct gas_pressures *pressures, const double amb_pressure,
pressures->o2 = 0;
if (get_o2(mix) != 1000) {
pressures->he = (amb_pressure - pressures->o2) * get_he(mix) / (1000.0 - get_o2(mix));
- pressures->n2 = (amb_pressure - pressures->o2) * (1000 - get_o2(mix) - get_he(mix)) / (1000.0 - get_o2(mix));
+ pressures->n2 = (amb_pressure - pressures->o2) * get_n2(mix) / (1000.0 - get_o2(mix));
} else {
pressures->he = pressures->n2 = 0;
}
@@ -2073,7 +2073,7 @@ void fill_pressures(struct gas_pressures *pressures, const double amb_pressure,
// Open circuit dives: no gas pressure values available, they need to be calculated
pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure; // These calculations are also used if the CCR calculation above..
pressures->he = get_he(mix) / 1000.0 * amb_pressure; // ..returned a po2 of zero (i.e. o2 sensor data not resolvable)
- pressures->n2 = (1000 - get_o2(mix) - get_he(mix)) / 1000.0 * amb_pressure;
+ pressures->n2 = get_n2(mix) / 1000.0 * amb_pressure;
}
}
}
@@ -3760,7 +3760,7 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou
int maxambient = prefs.o2narcotic ?
(int)lrint(ppo2n2.mbar / (1 - get_he(mix) / 1000.0))
:
- (int)lrint(ppo2n2.mbar * N2_IN_AIR / (1000 - get_he(mix) - get_o2(mix)));
+ (int)lrint(ppo2n2.mbar * N2_IN_AIR / get_n2(mix));
rounded_depth.mm = (int)lrint(((double)mbar_to_depth(maxambient, dive)) / roundto) * roundto;
return rounded_depth;
}
diff --git a/core/gas.c b/core/gas.c
index 9f67d0b92..040f938f6 100644
--- a/core/gas.c
+++ b/core/gas.c
@@ -77,3 +77,20 @@ bool gasmix_is_air(struct gasmix gasmix)
int he = gasmix.he.permille;
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
}
+
+static fraction_t make_fraction(int i)
+{
+ fraction_t res;
+ res.permille = i;
+ return res;
+}
+
+fraction_t get_gas_component_fraction(struct gasmix mix, enum gas_component component)
+{
+ switch (component) {
+ case O2: return make_fraction(get_o2(mix));
+ case N2: return make_fraction(get_n2(mix));
+ case HE: return make_fraction(get_he(mix));
+ default: return make_fraction(0);
+ }
+}
diff --git a/core/gas.h b/core/gas.h
index 316f4d3de..c5db7eeff 100644
--- a/core/gas.h
+++ b/core/gas.h
@@ -43,12 +43,18 @@ static inline int get_he(struct gasmix mix)
return mix.he.permille;
}
+static inline int get_n2(struct gasmix mix)
+{
+ return 1000 - get_o2(mix) - get_he(mix);
+}
+
struct gas_pressures {
double o2, n2, he;
};
extern void sanitize_gasmix(struct gasmix *mix);
extern int gasmix_distance(struct gasmix a, struct gasmix b);
+extern fraction_t get_gas_component_fraction(struct gasmix mix, enum gas_component component);
extern bool gasmix_is_air(struct gasmix gasmix);