aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-09-15 14:55:20 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-09-18 06:20:25 -0700
commitd6abb739d927285b55964f0644ee059be5f7db0b (patch)
treea9f68411ee735e2f03d8227eeb768e7cafdacbab /dive.c
parentae6b0468b16200dcc01f8e1cfd43260b63e830dc (diff)
downloadsubsurface-d6abb739d927285b55964f0644ee059be5f7db0b.tar.gz
Helper function for partial pressure calculation
This patch introduces a new structure holding partial pressures (doubles in bar) for all three gases and a helper function to compute them from gasmix (which holds fractions) and ambient pressure. Currentlty this works for OC and CCR, to be extended later to PSCR. Currently the dive_comp_type argument is unused. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index 22cf3ad46..85f70e3b1 100644
--- a/dive.c
+++ b/dive.c
@@ -1454,6 +1454,29 @@ int gasmix_distance(const struct gasmix *a, const struct gasmix *b)
return delta_he + delta_o2;
}
+/* Compute partial gas pressures in bar from gasmix and ambient pressures, possibly for OC or CCR, to be extended to PSCT */
+extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, const enum dive_comp_type type)
+{
+ if (po2) {
+ /* we have an O₂ partial pressure in the sample - so this
+ * is likely a CC dive... use that instead of the value
+ * from the cylinder info */
+ if (po2 >= amb_pressure || get_o2(mix) == 1000) {
+ pressures->o2 = amb_pressure;
+ pressures->he = 0;
+ 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 {
+ pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure;
+ pressures->he = get_he(mix) / 1000.0 * amb_pressure;
+ pressures->n2 = (1000 - get_o2(mix) - get_he(mix)) / 1000.0 * amb_pressure;
+ }
+
+}
+
static int find_cylinder_match(cylinder_t *cyl, cylinder_t array[], unsigned int used)
{
int i;