mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
8212acc992
commit
464dd93fe8
4 changed files with 47 additions and 47 deletions
45
core/dive.c
45
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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
45
core/gas.c
45
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue