summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--core/dive.c45
-rw-r--r--core/dive.h2
-rw-r--r--core/gas.c45
-rw-r--r--core/gas.h2
4 files changed, 47 insertions, 47 deletions
diff --git a/core/dive.c b/core/dive.c
index a9c69a3b0..5bb406f08 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -1943,51 +1943,6 @@ extern int get_cylinder_idx_by_use(const struct dive *dive, enum cylinderuse cyl
return -1; // negative number means cylinder_use_type not found in list of cylinders
}
-/* 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;
- }
- }
-}
-
/* Force an initial gaschange event to the (old) gas #0 */
static void add_initial_gaschange(struct dive *dive, struct divecomputer *dc, int offset, int idx)
{
diff --git a/core/dive.h b/core/dive.h
index 27e73375f..523d648bb 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -28,8 +28,6 @@ extern const char *cylinderuse_text[NUM_GAS_USE];
extern const char *divemode_text_ui[];
extern const char *divemode_text[];
-extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, struct gasmix mix, double po2, enum divemode_t dctype);
-
/* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */
static inline int interpolate(int a, int b, int part, int whole)
{
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;
+ }
+ }
+}
diff --git a/core/gas.h b/core/gas.h
index c5db7eeff..014eaca4b 100644
--- a/core/gas.h
+++ b/core/gas.h
@@ -2,6 +2,7 @@
#ifndef GAS_H
#define GAS_H
+#include "divemode.h"
#include "units.h"
#ifdef __cplusplus
@@ -55,6 +56,7 @@ struct gas_pressures {
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 void fill_pressures(struct gas_pressures *pressures, double amb_pressure, struct gasmix mix, double po2, enum divemode_t dctype);
extern bool gasmix_is_air(struct gasmix gasmix);