mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
core: return pressures structure from fill_pressures()
Instead of taking an out-parameter. That's more idiomatic C++. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ead58cd039
commit
411188728d
6 changed files with 22 additions and 24 deletions
|
@ -445,9 +445,8 @@ void calc_crushing_pressure(struct deco_state *ds, double pressure)
|
|||
void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int ccpo2, enum divemode_t divemode, int, bool in_planner)
|
||||
{
|
||||
int ci;
|
||||
struct gas_pressures pressures;
|
||||
bool icd = false;
|
||||
fill_pressures(&pressures, pressure - ((in_planner && (decoMode(true) == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE),
|
||||
gas_pressures pressures = fill_pressures(pressure - ((in_planner && (decoMode(true) == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE),
|
||||
gasmix, (double) ccpo2 / 1000.0, divemode);
|
||||
|
||||
for (ci = 0; ci < 16; ci++) {
|
||||
|
|
|
@ -637,13 +637,12 @@ void update_setpoint_events(const struct dive *dive, struct divecomputer *dc)
|
|||
const struct event *next = get_next_event(ev, "gaschange");
|
||||
|
||||
for (int i = 0; i < dc->samples; i++) {
|
||||
struct gas_pressures pressures;
|
||||
if (next && dc->sample[i].time.seconds >= next->time.seconds) {
|
||||
ev = next;
|
||||
gasmix = get_gasmix_from_event(dive, ev);
|
||||
next = get_next_event(ev, "gaschange");
|
||||
}
|
||||
fill_pressures(&pressures, lrint(calculate_depth_to_mbarf(dc->sample[i].depth.mm, dc->surface_pressure, 0)), gasmix ,0, dc->divemode);
|
||||
gas_pressures pressures = fill_pressures(lrint(calculate_depth_to_mbarf(dc->sample[i].depth.mm, dc->surface_pressure, 0)), gasmix ,0, dc->divemode);
|
||||
if (abs(dc->sample[i].setpoint.mbar - (int)(1000 * pressures.o2)) <= 50)
|
||||
dc->sample[i].setpoint.mbar = 0;
|
||||
}
|
||||
|
|
33
core/gas.cpp
33
core/gas.cpp
|
@ -116,42 +116,43 @@ int pscr_o2(const double amb_pressure, struct gasmix mix)
|
|||
* 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.cpp; add_segment() in deco.cpp.
|
||||
*/
|
||||
void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, struct gasmix mix, double po2, enum divemode_t divemode)
|
||||
gas_pressures fill_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
|
||||
struct gas_pressures pressures;
|
||||
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;
|
||||
pressures.o2 = amb_pressure;
|
||||
pressures.n2 = pressures.he = 0.0;
|
||||
} else {
|
||||
pressures->o2 = po2;
|
||||
pressures.o2 = po2;
|
||||
if (get_o2(mix) == 1000) {
|
||||
pressures->he = pressures->n2 = 0;
|
||||
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;
|
||||
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 = pscr_o2(amb_pressure, mix) / 1000.0;
|
||||
pressures.o2 = pscr_o2(amb_pressure, mix) / 1000.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));
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
return pressures;
|
||||
}
|
||||
|
||||
enum gastype gasmix_to_type(struct gasmix mix)
|
||||
|
|
|
@ -61,7 +61,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 gas_pressures fill_pressures(double amb_pressure, struct gasmix mix, double po2, enum divemode_t dctype);
|
||||
|
||||
extern bool gasmix_is_air(struct gasmix gasmix);
|
||||
extern bool gasmix_is_invalid(struct gasmix mix);
|
||||
|
|
|
@ -579,12 +579,11 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
while (dp) {
|
||||
if (dp->time != 0) {
|
||||
std::string temp;
|
||||
struct gas_pressures pressures;
|
||||
struct gasmix gasmix = get_cylinder(dive, dp->cylinderid)->gasmix;
|
||||
|
||||
current_divemode = get_current_divemode(&dive->dc, dp->time, &evd, ¤t_divemode);
|
||||
amb = depth_to_atm(dp->depth.mm, dive);
|
||||
fill_pressures(&pressures, amb, gasmix, (current_divemode == OC) ? 0.0 : amb * gasmix.o2.permille / 1000.0, current_divemode);
|
||||
gas_pressures pressures = fill_pressures(amb, gasmix, (current_divemode == OC) ? 0.0 : amb * gasmix.o2.permille / 1000.0, current_divemode);
|
||||
|
||||
if (pressures.o2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) {
|
||||
const char *depth_unit;
|
||||
|
|
|
@ -1195,7 +1195,7 @@ static void calculate_gas_information_new(const struct dive *dive, const struct
|
|||
gasmix = get_gasmix(dive, dc, entry.sec, &evg, gasmix);
|
||||
amb_pressure = depth_to_bar(entry.depth, dive);
|
||||
current_divemode = get_current_divemode(dc, entry.sec, &evd, ¤t_divemode);
|
||||
fill_pressures(&entry.pressures, amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry.o2pressure.mbar / 1000.0, current_divemode);
|
||||
entry.pressures = fill_pressures(amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry.o2pressure.mbar / 1000.0, current_divemode);
|
||||
fn2 = 1000.0 * entry.pressures.n2 / amb_pressure;
|
||||
fhe = 1000.0 * entry.pressures.he / amb_pressure;
|
||||
if (dc->divemode == PSCR) { // OC pO2 is calulated for PSCR with or without external PO2 monitoring.
|
||||
|
|
Loading…
Reference in a new issue