aboutsummaryrefslogtreecommitdiffstats
path: root/core/gas.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-25 11:36:44 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-25 13:59:52 -0700
commit464dd93fe8266e3d0af706a6809f09611bd9f83c (patch)
tree16114568db6e58ad25e14dd76f5a724a7f33d6e8 /core/gas.c
parent8212acc9925b28ecd546b01047c6a8fc574326ef (diff)
downloadsubsurface-464dd93fe8266e3d0af706a6809f09611bd9f83c.tar.gz
cleanup: move fill_pressures from dive.c to gas.c
This function does not access a dive structure. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/gas.c')
-rw-r--r--core/gas.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/gas.c b/core/gas.c
index 757f912b0..128305e12 100644
--- a/core/gas.c
+++ b/core/gas.c
@@ -94,3 +94,48 @@ fraction_t get_gas_component_fraction(struct gasmix mix, enum gas_component comp
default: return make_fraction(0);
}
}
+
+/* fill_pressures(): Compute partial gas pressures in bar from gasmix and ambient pressures, possibly for OC or CCR, to be
+ * extended to PSCT. This function does the calculations of gas pressures applicable to a single point on the dive profile.
+ * The structure "pressures" is used to return calculated gas pressures to the calling software.
+ * Call parameters: po2 = po2 value applicable to the record in calling function
+ * amb_pressure = ambient pressure applicable to the record in calling function
+ * *pressures = structure for communicating o2 sensor values from and gas pressures to the calling function.
+ * *mix = structure containing cylinder gas mixture information.
+ * divemode = the dive mode pertaining to this point in the dive profile.
+ * This function called by: calculate_gas_information_new() in profile.c; add_segment() in deco.c.
+ */
+void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, struct gasmix mix, double po2, enum divemode_t divemode)
+{
+ if ((divemode != OC) && po2) { // This is a rebreather dive where pressures->o2 is defined
+ if (po2 >= amb_pressure) {
+ pressures->o2 = amb_pressure;
+ pressures->n2 = pressures->he = 0.0;
+ } else {
+ pressures->o2 = po2;
+ if (get_o2(mix) == 1000) {
+ pressures->he = pressures->n2 = 0;
+ } else {
+ pressures->he = (amb_pressure - pressures->o2) * (double)get_he(mix) / (1000 - get_o2(mix));
+ pressures->n2 = amb_pressure - pressures->o2 - pressures->he;
+ }
+ }
+ } else {
+ if (divemode == PSCR) { /* The steady state approximation should be good enough */
+ pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure - (1.0 - get_o2(mix) / 1000.0) * prefs.o2consumption / (prefs.bottomsac * prefs.pscr_ratio / 1000.0);
+ if (pressures->o2 < 0) // He's dead, Jim.
+ 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) * get_n2(mix) / (1000.0 - get_o2(mix));
+ } else {
+ pressures->he = pressures->n2 = 0;
+ }
+ } else {
+ // 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 = get_n2(mix) / 1000.0 * amb_pressure;
+ }
+ }
+}