mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: move depth_to_* functions into struct dive
Seems logical in a C++ code base. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3660241993
commit
bf84d66df2
9 changed files with 83 additions and 85 deletions
|
@ -630,12 +630,12 @@ void update_regression(struct deco_state *ds, const struct dive *dive)
|
|||
ds->sumx += ds->plot_depth;
|
||||
ds->sumxx += (long)ds->plot_depth * ds->plot_depth;
|
||||
double n2_gradient, he_gradient, total_gradient;
|
||||
n2_gradient = update_gradient(ds, depth_to_bar(ds->plot_depth, dive), ds->bottom_n2_gradient[ds->ci_pointing_to_guiding_tissue]);
|
||||
he_gradient = update_gradient(ds, depth_to_bar(ds->plot_depth, dive), ds->bottom_he_gradient[ds->ci_pointing_to_guiding_tissue]);
|
||||
n2_gradient = update_gradient(ds, dive->depth_to_bar(ds->plot_depth), ds->bottom_n2_gradient[ds->ci_pointing_to_guiding_tissue]);
|
||||
he_gradient = update_gradient(ds, dive->depth_to_bar(ds->plot_depth), ds->bottom_he_gradient[ds->ci_pointing_to_guiding_tissue]);
|
||||
total_gradient = ((n2_gradient * ds->tissue_n2_sat[ds->ci_pointing_to_guiding_tissue]) + (he_gradient * ds->tissue_he_sat[ds->ci_pointing_to_guiding_tissue]))
|
||||
/ (ds->tissue_n2_sat[ds->ci_pointing_to_guiding_tissue] + ds->tissue_he_sat[ds->ci_pointing_to_guiding_tissue]);
|
||||
|
||||
double buehlmann_gradient = (1.0 / ds->buehlmann_inertgas_b[ds->ci_pointing_to_guiding_tissue] - 1.0) * depth_to_bar(ds->plot_depth, dive) + ds->buehlmann_inertgas_a[ds->ci_pointing_to_guiding_tissue];
|
||||
double buehlmann_gradient = (1.0 / ds->buehlmann_inertgas_b[ds->ci_pointing_to_guiding_tissue] - 1.0) * dive->depth_to_bar(ds->plot_depth) + ds->buehlmann_inertgas_a[ds->ci_pointing_to_guiding_tissue];
|
||||
double gf = (total_gradient - vpmb_config.other_gases_pressure) / buehlmann_gradient;
|
||||
ds->sumxy += gf * ds->plot_depth;
|
||||
ds->sumy += gf;
|
||||
|
|
|
@ -39,8 +39,6 @@ const char *divemode_text_ui[] = {
|
|||
// For writing/reading files.
|
||||
const char *divemode_text[] = {"OC", "CCR", "PSCR", "Freedive"};
|
||||
|
||||
static double calculate_depth_to_mbarf(int depth, pressure_t surface_pressure, int salinity);
|
||||
|
||||
// It's the "manually added" divecomputer.
|
||||
// Even for dives without divecomputer, we allocate a divecomputer structure.
|
||||
dive::dive() : dcs(1)
|
||||
|
@ -481,6 +479,8 @@ int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *
|
|||
return static_cast<size_t>(res) < dive->cylinders.size() ? res : 0;
|
||||
}
|
||||
|
||||
static double calculate_depth_to_mbarf(int depth, pressure_t surface_pressure, int salinity);
|
||||
|
||||
/* this gets called when the dive mode has changed (so OC vs. CC)
|
||||
* there are two places we might have setpoints... events or in the samples
|
||||
*/
|
||||
|
@ -2721,7 +2721,7 @@ fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner)
|
|||
fraction_t fo2;
|
||||
int po2 = in_planner ? prefs.bottompo2 : (int)(prefs.modpO2 * 1000.0);
|
||||
|
||||
fo2.permille = (po2 * 100 / depth_to_mbar(depth.mm, dive)) * 10; //use integer arithmetic to round down to nearest percent
|
||||
fo2.permille = (po2 * 100 / dive->depth_to_mbar(depth.mm)) * 10; //use integer arithmetic to round down to nearest percent
|
||||
// Don't permit >100% O2
|
||||
if (fo2.permille > 1000)
|
||||
fo2.permille = 1000;
|
||||
|
@ -2733,8 +2733,8 @@ fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, frac
|
|||
{
|
||||
fraction_t fhe;
|
||||
int pnarcotic, ambient;
|
||||
pnarcotic = depth_to_mbar(prefs.bestmixend.mm, dive);
|
||||
ambient = depth_to_mbar(depth.mm, dive);
|
||||
pnarcotic = dive->depth_to_mbar(prefs.bestmixend.mm);
|
||||
ambient = dive->depth_to_mbar(depth.mm);
|
||||
if (o2narcotic) {
|
||||
fhe.permille = (100 - 100 * pnarcotic / ambient) * 10; //use integer arithmetic to round up to nearest percent
|
||||
} else {
|
||||
|
@ -2792,32 +2792,32 @@ static double calculate_depth_to_mbarf(int depth, pressure_t surface_pressure, i
|
|||
return mbar + depth * specific_weight;
|
||||
}
|
||||
|
||||
int depth_to_mbar(int depth, const struct dive *dive)
|
||||
int dive::depth_to_mbar(int depth) const
|
||||
{
|
||||
return lrint(depth_to_mbarf(depth, dive));
|
||||
return lrint(depth_to_mbarf(depth));
|
||||
}
|
||||
|
||||
double depth_to_mbarf(int depth, const struct dive *dive)
|
||||
double dive::depth_to_mbarf(int depth) const
|
||||
{
|
||||
// For downloaded and planned dives, use DC's values
|
||||
int salinity = dive->dcs[0].salinity;
|
||||
pressure_t surface_pressure = dive->dcs[0].surface_pressure;
|
||||
int salinity = dcs[0].salinity;
|
||||
pressure_t surface_pressure = dcs[0].surface_pressure;
|
||||
|
||||
if (is_dc_manually_added_dive(&dive->dcs[0])) { // For manual dives, salinity and pressure in another place...
|
||||
surface_pressure = dive->surface_pressure;
|
||||
salinity = dive->user_salinity;
|
||||
if (is_dc_manually_added_dive(&dcs[0])) { // For manual dives, salinity and pressure in another place...
|
||||
surface_pressure = this->surface_pressure;
|
||||
salinity = user_salinity;
|
||||
}
|
||||
return calculate_depth_to_mbarf(depth, surface_pressure, salinity);
|
||||
}
|
||||
|
||||
double depth_to_bar(int depth, const struct dive *dive)
|
||||
double dive::depth_to_bar(int depth) const
|
||||
{
|
||||
return depth_to_mbar(depth, dive) / 1000.0;
|
||||
return depth_to_mbar(depth) / 1000.0;
|
||||
}
|
||||
|
||||
double depth_to_atm(int depth, const struct dive *dive)
|
||||
double dive::depth_to_atm(int depth) const
|
||||
{
|
||||
return mbar_to_atm(depth_to_mbar(depth, dive));
|
||||
return mbar_to_atm(depth_to_mbar(depth));
|
||||
}
|
||||
|
||||
/* for the inverse calculation we use just the relative pressure
|
||||
|
@ -2864,7 +2864,7 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou
|
|||
{
|
||||
depth_t rounded_depth;
|
||||
pressure_t ppo2n2;
|
||||
ppo2n2.mbar = depth_to_mbar(end.mm, dive);
|
||||
ppo2n2.mbar = dive->depth_to_mbar(end.mm);
|
||||
|
||||
int maxambient = prefs.o2narcotic ?
|
||||
(int)lrint(ppo2n2.mbar / (1 - get_he(mix) / 1000.0))
|
||||
|
|
|
@ -87,6 +87,10 @@ struct dive {
|
|||
bool is_planned() const;
|
||||
bool is_logged() const;
|
||||
|
||||
int depth_to_mbar(int depth) const;
|
||||
double depth_to_mbarf(int depth) const;
|
||||
double depth_to_bar(int depth) const;
|
||||
double depth_to_atm(int depth) const;
|
||||
};
|
||||
|
||||
/* For the top-level list: an entry is either a dive or a trip */
|
||||
|
@ -129,10 +133,6 @@ extern fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planne
|
|||
extern fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2);
|
||||
|
||||
extern int get_surface_pressure_in_mbar(const struct dive *dive, bool non_null);
|
||||
extern int depth_to_mbar(int depth, const struct dive *dive);
|
||||
extern double depth_to_mbarf(int depth, const struct dive *dive);
|
||||
extern double depth_to_bar(int depth, const struct dive *dive);
|
||||
extern double depth_to_atm(int depth, const struct dive *dive);
|
||||
extern int rel_mbar_to_depth(int mbar, const struct dive *dive);
|
||||
extern int mbar_to_depth(int mbar, const struct dive *dive);
|
||||
extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto);
|
||||
|
|
|
@ -95,10 +95,10 @@ static int get_sample_o2(const struct dive *dive, const struct divecomputer *dc,
|
|||
po2 = (po2f + po2i) / 2;
|
||||
} else if (sample.setpoint.mbar > 0) {
|
||||
po2 = std::min((int) sample.setpoint.mbar,
|
||||
depth_to_mbar(sample.depth.mm, dive));
|
||||
dive->depth_to_mbar(sample.depth.mm));
|
||||
} else {
|
||||
double amb_presure = depth_to_bar(sample.depth.mm, dive);
|
||||
double pamb_pressure = depth_to_bar(psample.depth.mm , dive);
|
||||
double amb_presure = dive->depth_to_bar(sample.depth.mm);
|
||||
double pamb_pressure = dive->depth_to_bar(psample.depth.mm );
|
||||
if (dc->divemode == PSCR) {
|
||||
po2i = pscr_o2(pamb_pressure, get_gasmix_at_time(*dive, *dc, psample.time));
|
||||
po2f = pscr_o2(amb_presure, get_gasmix_at_time(*dive, *dc, sample.time));
|
||||
|
@ -135,15 +135,15 @@ static int calculate_otu(const struct dive *dive)
|
|||
} else {
|
||||
if (sample.setpoint.mbar > 0) {
|
||||
po2f = std::min((int) sample.setpoint.mbar,
|
||||
depth_to_mbar(sample.depth.mm, dive));
|
||||
dive->depth_to_mbar(sample.depth.mm));
|
||||
if (psample.setpoint.mbar > 0)
|
||||
po2i = std::min((int) psample.setpoint.mbar,
|
||||
depth_to_mbar(psample.depth.mm, dive));
|
||||
dive->depth_to_mbar(psample.depth.mm));
|
||||
else
|
||||
po2i = po2f;
|
||||
} else { // For OC and rebreather without o2 sensor/setpoint
|
||||
double amb_presure = depth_to_bar(sample.depth.mm, dive);
|
||||
double pamb_pressure = depth_to_bar(psample.depth.mm , dive);
|
||||
double amb_presure = dive->depth_to_bar(sample.depth.mm);
|
||||
double pamb_pressure = dive->depth_to_bar(psample.depth.mm);
|
||||
if (dc->divemode == PSCR) {
|
||||
po2i = pscr_o2(pamb_pressure, get_gasmix_at_time(*dive, *dc, psample.time));
|
||||
po2f = pscr_o2(amb_presure, get_gasmix_at_time(*dive, *dc, sample.time));
|
||||
|
@ -381,7 +381,7 @@ static int calculate_sac(const struct dive *dive)
|
|||
return 0;
|
||||
|
||||
/* Mean pressure in ATM (SAC calculations are in atm*l/min) */
|
||||
pressure = depth_to_atm(meandepth, dive);
|
||||
pressure = dive->depth_to_atm(meandepth);
|
||||
sac = airuse / pressure * 60 / duration;
|
||||
|
||||
/* milliliters per minute.. */
|
||||
|
@ -403,7 +403,7 @@ static void add_dive_to_deco(struct deco_state *ds, const struct dive *dive, boo
|
|||
for (j = t0; j < t1; j++) {
|
||||
int depth = interpolate(psample.depth.mm, sample.depth.mm, j - t0, t1 - t0);
|
||||
auto gasmix = loop.next(j);
|
||||
add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, sample.setpoint.mbar,
|
||||
add_segment(ds, dive->depth_to_bar(depth), gasmix, 1, sample.setpoint.mbar,
|
||||
loop_d.next(j), dive->sac,
|
||||
in_planner);
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ static inline int calc_pressure_time(const struct dive *dive, const struct plot_
|
|||
if (depth <= SURFACE_THRESHOLD)
|
||||
return 0;
|
||||
|
||||
return depth_to_mbar(depth, dive) * time;
|
||||
return dive->depth_to_mbar(depth) * time;
|
||||
}
|
||||
|
||||
#ifdef PRINT_PRESSURES_DEBUG
|
||||
|
|
|
@ -105,10 +105,10 @@ static void interpolate_transition(struct deco_state *ds, struct dive *dive, dur
|
|||
|
||||
for (j = t0.seconds; j < t1.seconds; j++) {
|
||||
int depth = interpolate(d0.mm, d1.mm, j - t0.seconds, t1.seconds - t0.seconds);
|
||||
add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, po2.mbar, divemode, prefs.bottomsac, true);
|
||||
add_segment(ds, dive->depth_to_bar(depth), gasmix, 1, po2.mbar, divemode, prefs.bottomsac, true);
|
||||
}
|
||||
if (d1.mm > d0.mm)
|
||||
calc_crushing_pressure(ds, depth_to_bar(d1.mm, dive));
|
||||
calc_crushing_pressure(ds, dive->depth_to_bar(d1.mm));
|
||||
}
|
||||
|
||||
/* returns the tissue tolerance at the end of this (partial) dive */
|
||||
|
@ -153,12 +153,11 @@ static int tissue_at_end(struct deco_state *ds, struct dive *dive, const struct
|
|||
pressure_t ceiling_pressure;
|
||||
nuclear_regeneration(ds, t0.seconds);
|
||||
vpmb_start_gradient(ds);
|
||||
ceiling_pressure.mbar = depth_to_mbar(deco_allowed_depth(tissue_tolerance_calc(ds, dive,
|
||||
depth_to_bar(lastdepth.mm, dive), true),
|
||||
ceiling_pressure.mbar = dive->depth_to_mbar(deco_allowed_depth(tissue_tolerance_calc(ds, dive,
|
||||
dive->depth_to_bar(lastdepth.mm), true),
|
||||
dive->surface_pressure.mbar / 1000.0,
|
||||
dive,
|
||||
1),
|
||||
dive);
|
||||
1));
|
||||
if (ceiling_pressure.mbar > ds->max_bottom_ceiling_pressure.mbar)
|
||||
ds->max_bottom_ceiling_pressure.mbar = ceiling_pressure.mbar;
|
||||
}
|
||||
|
@ -186,7 +185,7 @@ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_dept
|
|||
if (!cyl)
|
||||
return;
|
||||
mean_depth.mm = (old_depth + new_depth) / 2;
|
||||
gas_used.mliter = lrint(depth_to_atm(mean_depth.mm, d) * sac / 60 * duration * factor / 1000);
|
||||
gas_used.mliter = lrint(d->depth_to_atm(mean_depth.mm) * sac / 60 * duration * factor / 1000);
|
||||
cyl->gas_used.mliter += gas_used.mliter;
|
||||
if (in_deco)
|
||||
cyl->deco_gas_used.mliter += gas_used.mliter;
|
||||
|
@ -534,11 +533,11 @@ static bool trial_ascent(struct deco_state *ds, int wait_time, int trial_depth,
|
|||
// However, we still need to make sure we don't break the ceiling due to on-gassing during ascent.
|
||||
trial_cache.cache(ds);
|
||||
if (wait_time)
|
||||
add_segment(ds, depth_to_bar(trial_depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(trial_depth),
|
||||
gasmix,
|
||||
wait_time, po2, divemode, prefs.decosac, true);
|
||||
if (decoMode(true) == VPMB) {
|
||||
double tolerance_limit = tissue_tolerance_calc(ds, dive, depth_to_bar(stoplevel, dive), true);
|
||||
double tolerance_limit = tissue_tolerance_calc(ds, dive, dive->depth_to_bar(stoplevel), true);
|
||||
update_regression(ds, dive);
|
||||
if (deco_allowed_depth(tolerance_limit, surface_pressure, dive, 1) > stoplevel) {
|
||||
trial_cache.restore(ds, false);
|
||||
|
@ -551,10 +550,10 @@ static bool trial_ascent(struct deco_state *ds, int wait_time, int trial_depth,
|
|||
int deltad = ascent_velocity(trial_depth, avg_depth, bottom_time) * base_timestep;
|
||||
if (deltad > trial_depth) /* don't test against depth above surface */
|
||||
deltad = trial_depth;
|
||||
add_segment(ds, depth_to_bar(trial_depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(trial_depth),
|
||||
gasmix,
|
||||
base_timestep, po2, divemode, prefs.decosac, true);
|
||||
tolerance_limit = tissue_tolerance_calc(ds, dive, depth_to_bar(trial_depth, dive), true);
|
||||
tolerance_limit = tissue_tolerance_calc(ds, dive, dive->depth_to_bar(trial_depth), true);
|
||||
if (decoMode(true) == VPMB)
|
||||
update_regression(ds, dive);
|
||||
if (deco_allowed_depth(tolerance_limit, surface_pressure, dive, 1) > trial_depth - deltad) {
|
||||
|
@ -768,7 +767,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
track_ascent_gas(depth, dive, current_cylinder, avg_depth, bottom_time, safety_stop, divemode);
|
||||
// How long can we stay at the current depth and still directly ascent to the surface?
|
||||
do {
|
||||
add_segment(ds, depth_to_bar(depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(depth),
|
||||
get_cylinder(dive, current_cylinder)->gasmix,
|
||||
timestep, po2, divemode, prefs.bottomsac, true);
|
||||
update_cylinder_pressure(dive, depth, depth, timestep, prefs.bottomsac, get_cylinder(dive, current_cylinder), false, divemode);
|
||||
|
@ -831,7 +830,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
divemode = OC;
|
||||
po2 = 0;
|
||||
int bailoutsegment = std::max(prefs.min_switch_duration, 60 * prefs.problemsolvingtime);
|
||||
add_segment(ds, depth_to_bar(depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(depth),
|
||||
get_cylinder(dive, current_cylinder)->gasmix,
|
||||
bailoutsegment, po2, divemode, prefs.bottomsac, true);
|
||||
plan_add_segment(diveplan, bailoutsegment, depth, current_cylinder, po2, false, divemode);
|
||||
|
@ -863,10 +862,9 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
decodive = false;
|
||||
first_stop_depth = 0;
|
||||
stopidx = bottom_stopidx;
|
||||
ds->first_ceiling_pressure.mbar = depth_to_mbar(
|
||||
deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(depth, dive), true),
|
||||
diveplan->surface_pressure / 1000.0, dive, 1),
|
||||
dive);
|
||||
ds->first_ceiling_pressure.mbar = dive->depth_to_mbar(
|
||||
deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(depth), true),
|
||||
diveplan->surface_pressure / 1000.0, dive, 1));
|
||||
if (ds->max_bottom_ceiling_pressure.mbar > ds->first_ceiling_pressure.mbar)
|
||||
ds->first_ceiling_pressure.mbar = ds->max_bottom_ceiling_pressure.mbar;
|
||||
|
||||
|
@ -897,7 +895,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
if (depth - deltad < stoplevels[stopidx])
|
||||
deltad = depth - stoplevels[stopidx];
|
||||
|
||||
add_segment(ds, depth_to_bar(depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(depth),
|
||||
get_cylinder(dive, current_cylinder)->gasmix,
|
||||
base_timestep, po2, divemode, prefs.decosac, true);
|
||||
last_segment_min_switch = false;
|
||||
|
@ -938,7 +936,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
#endif
|
||||
/* Stop for the minimum duration to switch gas unless we switch to o2 */
|
||||
if (!last_segment_min_switch && get_o2(get_cylinder(dive, current_cylinder)->gasmix) != 1000) {
|
||||
add_segment(ds, depth_to_bar(depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(depth),
|
||||
get_cylinder(dive, current_cylinder)->gasmix,
|
||||
prefs.min_switch_duration, po2, divemode, prefs.decosac, true);
|
||||
clock += prefs.min_switch_duration;
|
||||
|
@ -994,7 +992,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
#endif
|
||||
/* Stop for the minimum duration to switch gas unless we switch to o2 */
|
||||
if (!last_segment_min_switch && get_o2(get_cylinder(dive, current_cylinder)->gasmix) != 1000) {
|
||||
add_segment(ds, depth_to_bar(depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(depth),
|
||||
get_cylinder(dive, current_cylinder)->gasmix,
|
||||
prefs.min_switch_duration, po2, divemode, prefs.decosac, true);
|
||||
clock += prefs.min_switch_duration;
|
||||
|
@ -1048,7 +1046,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
}
|
||||
}
|
||||
}
|
||||
add_segment(ds, depth_to_bar(depth, dive), get_cylinder(dive, stop_cylinder)->gasmix,
|
||||
add_segment(ds, dive->depth_to_bar(depth), get_cylinder(dive, stop_cylinder)->gasmix,
|
||||
laststoptime, po2, divemode, prefs.decosac, true);
|
||||
last_segment_min_switch = false;
|
||||
decostoptable[decostopcounter].depth = depth;
|
||||
|
|
|
@ -335,7 +335,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
if (isobaric_counterdiffusion(lastprintgasmix, newgasmix, &icdvalues)) // Do icd calulations
|
||||
icdwarning = true;
|
||||
if (icdvalues.dN2 > 0) { // If the gas change involved helium as well as an increase in nitrogen..
|
||||
icdbuf += icd_entry(&icdvalues, icdtableheader, dp->time, depth_to_mbar(dp->depth.mm, dive), lastprintgasmix, newgasmix); // .. then print calculations to buffer.
|
||||
icdbuf += icd_entry(&icdvalues, icdtableheader, dp->time, dive->depth_to_mbar(dp->depth.mm), lastprintgasmix, newgasmix); // .. then print calculations to buffer.
|
||||
icdtableheader = false;
|
||||
}
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
if (isobaric_counterdiffusion(lastprintgasmix, gasmix, &icdvalues)) // Do icd calculations
|
||||
icdwarning = true;
|
||||
if (icdvalues.dN2 > 0) { // If the gas change involved helium as well as an increase in nitrogen..
|
||||
icdbuf += icd_entry(&icdvalues, icdtableheader, lasttime, depth_to_mbar(dp->depth.mm, dive), lastprintgasmix, gasmix); // .. then print data to buffer.
|
||||
icdbuf += icd_entry(&icdvalues, icdtableheader, lasttime, dive->depth_to_mbar(dp->depth.mm), lastprintgasmix, gasmix); // .. then print data to buffer.
|
||||
icdtableheader = false;
|
||||
}
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
if (isobaric_counterdiffusion(lastprintgasmix, newgasmix, &icdvalues)) // Do icd calculations
|
||||
icdwarning = true;
|
||||
if (icdvalues.dN2 > 0) { // If the gas change involved helium as well as an increase in nitrogen..
|
||||
icdbuf += icd_entry(&icdvalues, icdtableheader, dp->time, depth_to_mbar(dp->depth.mm, dive), lastprintgasmix, newgasmix); // ... then print data to buffer.
|
||||
icdbuf += icd_entry(&icdvalues, icdtableheader, dp->time, dive->depth_to_mbar(dp->depth.mm), lastprintgasmix, newgasmix); // ... then print data to buffer.
|
||||
icdtableheader = false;
|
||||
}
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
/* Calculate minimum gas volume. */
|
||||
volume_t mingasv;
|
||||
mingasv.mliter = lrint(prefs.sacfactor / 100.0 * prefs.problemsolvingtime * prefs.bottomsac
|
||||
* depth_to_bar(lastbottomdp->depth.mm, dive)
|
||||
* dive->depth_to_bar(lastbottomdp->depth.mm)
|
||||
+ prefs.sacfactor / 100.0 * cyl.deco_gas_used.mliter);
|
||||
/* Calculate minimum gas pressure for cyclinder. */
|
||||
lastbottomdp->minimum_gas.mbar = lrint(isothermal_pressure(cyl.gasmix, 1.0,
|
||||
|
@ -580,7 +580,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
struct gasmix gasmix = get_cylinder(dive, dp->cylinderid)->gasmix;
|
||||
|
||||
divemode_t current_divemode = loop.next(dp->time);
|
||||
amb = depth_to_atm(dp->depth.mm, dive);
|
||||
amb = dive->depth_to_atm(dp->depth.mm);
|
||||
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) {
|
||||
|
|
|
@ -124,7 +124,7 @@ static int get_local_sac(struct plot_info &pi, int idx1, int idx2, struct dive *
|
|||
|
||||
/* Mean pressure in ATM */
|
||||
depth = (entry1.depth + entry2.depth) / 2;
|
||||
atm = depth_to_atm(depth, dive);
|
||||
atm = dive->depth_to_atm(depth);
|
||||
|
||||
cyl = get_cylinder(dive, index);
|
||||
|
||||
|
@ -523,7 +523,7 @@ static int sac_between(const struct dive *dive, const struct plot_info &pi, int
|
|||
const struct plot_data &next = pi.entry[first + 1];
|
||||
int depth = (entry.depth + next.depth) / 2;
|
||||
int time = next.sec - entry.sec;
|
||||
double atm = depth_to_atm(depth, dive);
|
||||
double atm = dive->depth_to_atm(depth);
|
||||
|
||||
pressuretime += atm * time;
|
||||
} while (++first < last);
|
||||
|
@ -797,7 +797,7 @@ static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, st
|
|||
const int deco_stepsize = M_OR_FT(3, 10);
|
||||
/* at what depth is the current deco-step? */
|
||||
int next_stop = round_up(deco_allowed_depth(
|
||||
tissue_tolerance_calc(ds, dive, depth_to_bar(entry.depth, dive), in_planner),
|
||||
tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner),
|
||||
surface_pressure, dive, 1), deco_stepsize);
|
||||
int ascent_depth = entry.depth;
|
||||
/* at what time should we give up and say that we got enuff NDL? */
|
||||
|
@ -813,11 +813,11 @@ static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, st
|
|||
}
|
||||
/* stop if the ndl is above max_ndl seconds, and call it plenty of time */
|
||||
while (entry.ndl_calc < MAX_PROFILE_DECO &&
|
||||
deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(entry.depth, dive), in_planner),
|
||||
deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner),
|
||||
surface_pressure, dive, 1) <= 0
|
||||
) {
|
||||
entry.ndl_calc += time_stepsize;
|
||||
add_segment(ds, depth_to_bar(entry.depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(entry.depth),
|
||||
gasmix, time_stepsize, entry.o2pressure.mbar, divemode, prefs.bottomsac, in_planner);
|
||||
}
|
||||
/* we don't need to calculate anything else */
|
||||
|
@ -829,9 +829,9 @@ static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, st
|
|||
|
||||
/* Add segments for movement to stopdepth */
|
||||
for (; ascent_depth > next_stop; ascent_depth -= ascent_s_per_step * ascent_velocity(ascent_depth, entry.running_sum / entry.sec, 0), entry.tts_calc += ascent_s_per_step) {
|
||||
add_segment(ds, depth_to_bar(ascent_depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(ascent_depth),
|
||||
gasmix, ascent_s_per_step, entry.o2pressure.mbar, divemode, prefs.decosac, in_planner);
|
||||
next_stop = round_up(deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(ascent_depth, dive), in_planner),
|
||||
next_stop = round_up(deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(ascent_depth), in_planner),
|
||||
surface_pressure, dive, 1), deco_stepsize);
|
||||
}
|
||||
ascent_depth = next_stop;
|
||||
|
@ -850,13 +850,13 @@ static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, st
|
|||
entry.tts_calc += time_stepsize;
|
||||
if (entry.tts_calc > MAX_PROFILE_DECO)
|
||||
break;
|
||||
add_segment(ds, depth_to_bar(ascent_depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(ascent_depth),
|
||||
gasmix, time_stepsize, entry.o2pressure.mbar, divemode, prefs.decosac, in_planner);
|
||||
|
||||
if (deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(ascent_depth,dive), in_planner), surface_pressure, dive, 1) <= next_stop) {
|
||||
if (deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(ascent_depth), in_planner), surface_pressure, dive, 1) <= next_stop) {
|
||||
/* move to the next stop and add the travel between stops */
|
||||
for (; ascent_depth > next_stop; ascent_depth -= ascent_s_per_deco_step * ascent_velocity(ascent_depth, entry.running_sum / entry.sec, 0), entry.tts_calc += ascent_s_per_deco_step)
|
||||
add_segment(ds, depth_to_bar(ascent_depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(ascent_depth),
|
||||
gasmix, ascent_s_per_deco_step, entry.o2pressure.mbar, divemode, prefs.decosac, in_planner);
|
||||
ascent_depth = next_stop;
|
||||
next_stop -= deco_stepsize;
|
||||
|
@ -894,7 +894,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
|
|||
while ((abs(prev_deco_time - ds->deco_time) >= 30) && (count_iteration < 10)) {
|
||||
int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling = 0, final_tts = 0 , time_clear_ceiling = 0;
|
||||
if (decoMode(in_planner) == VPMB)
|
||||
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
||||
ds->first_ceiling_pressure.mbar = dive->depth_to_mbar(first_ceiling);
|
||||
|
||||
gasmix_loop loop(*dive, *dc);
|
||||
divemode_loop loop_d(*dc);
|
||||
|
@ -906,7 +906,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
|
|||
|
||||
divemode_t current_divemode = loop_d.next(entry.sec);
|
||||
struct gasmix gasmix = loop.next(t1);
|
||||
entry.ambpressure = depth_to_bar(entry.depth, dive);
|
||||
entry.ambpressure = dive->depth_to_bar(entry.depth);
|
||||
entry.gfline = get_gf(ds, entry.ambpressure, dive) * (100.0 - AMB_PERCENTAGE) + AMB_PERCENTAGE;
|
||||
if (t0 > t1) {
|
||||
report_info("non-monotonous dive stamps %d %d", t0, t1);
|
||||
|
@ -918,7 +918,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
|
|||
time_stepsize = t1 - t0;
|
||||
for (j = t0 + time_stepsize; j <= t1; j += time_stepsize) {
|
||||
int depth = interpolate(prev.depth, entry.depth, j - t0, t1 - t0);
|
||||
add_segment(ds, depth_to_bar(depth, dive),
|
||||
add_segment(ds, dive->depth_to_bar(depth),
|
||||
gasmix, time_stepsize, entry.o2pressure.mbar, current_divemode, entry.sac, in_planner);
|
||||
entry.icd_warning = ds->icd_warning;
|
||||
if ((t1 - j < time_stepsize) && (j < t1))
|
||||
|
@ -935,9 +935,9 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
|
|||
if (!first_iteration || in_planner)
|
||||
vpmb_next_gradient(ds, ds->deco_time, surface_pressure / 1000.0, in_planner);
|
||||
}
|
||||
entry.ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(entry.depth, dive), in_planner), surface_pressure, dive, !prefs.calcceiling3m);
|
||||
entry.ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner), surface_pressure, dive, !prefs.calcceiling3m);
|
||||
if (prefs.calcceiling3m)
|
||||
current_ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(entry.depth, dive), in_planner), surface_pressure, dive, true);
|
||||
current_ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner), surface_pressure, dive, true);
|
||||
else
|
||||
current_ceiling = entry.ceiling;
|
||||
last_ceiling = current_ceiling;
|
||||
|
@ -947,7 +947,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
|
|||
(time_deep_ceiling == t0 && entry.depth == prev.depth)) {
|
||||
time_deep_ceiling = t1;
|
||||
first_ceiling = current_ceiling;
|
||||
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
||||
ds->first_ceiling_pressure.mbar = dive->depth_to_mbar(first_ceiling);
|
||||
if (first_iteration) {
|
||||
nuclear_regeneration(ds, t1);
|
||||
vpmb_start_gradient(ds);
|
||||
|
@ -1143,14 +1143,14 @@ static void calculate_gas_information_new(const struct dive *dive, const struct
|
|||
struct plot_data &entry = pi.entry[i];
|
||||
|
||||
auto gasmix = loop.next(entry.sec);
|
||||
amb_pressure = depth_to_bar(entry.depth, dive);
|
||||
amb_pressure = dive->depth_to_bar(entry.depth);
|
||||
divemode_t current_divemode = loop_d.next(entry.sec);
|
||||
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.
|
||||
struct gasmix gasmix2 = loop.next(entry.sec);
|
||||
entry.scr_OC_pO2.mbar = (int) depth_to_mbar(entry.depth, dive) * get_o2(gasmix2) / 1000;
|
||||
entry.scr_OC_pO2.mbar = (int) dive->depth_to_mbar(entry.depth) * get_o2(gasmix2) / 1000;
|
||||
}
|
||||
|
||||
/* Calculate MOD, EAD, END and EADD based on partial pressures calculated before
|
||||
|
@ -1159,9 +1159,9 @@ static void calculate_gas_information_new(const struct dive *dive, const struct
|
|||
* EAD just uses N₂ ("Air" for nitrox dives) */
|
||||
pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) };
|
||||
entry.mod = gas_mod(gasmix, modpO2, dive, 1).mm;
|
||||
entry.end = mbar_to_depth(lrint(depth_to_mbarf(entry.depth, dive) * (1000 - fhe) / 1000.0), dive);
|
||||
entry.ead = mbar_to_depth(lrint(depth_to_mbarf(entry.depth, dive) * fn2 / (double)N2_IN_AIR), dive);
|
||||
entry.eadd = mbar_to_depth(lrint(depth_to_mbarf(entry.depth, dive) *
|
||||
entry.end = mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * (1000 - fhe) / 1000.0), dive);
|
||||
entry.ead = mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * fn2 / (double)N2_IN_AIR), dive);
|
||||
entry.eadd = mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) *
|
||||
(entry.pressures.o2 / amb_pressure * O2_DENSITY +
|
||||
entry.pressures.n2 / amb_pressure * N2_DENSITY +
|
||||
entry.pressures.he / amb_pressure * HE_DENSITY) /
|
||||
|
@ -1206,7 +1206,7 @@ static void fill_o2_values(const struct dive *dive, const struct divecomputer *d
|
|||
else
|
||||
entry.o2sensor[j].mbar = last_sensor[j].mbar;
|
||||
} // having initialised the empty o2 sensor values for this point on the profile,
|
||||
amb_pressure.mbar = depth_to_mbar(entry.depth, dive);
|
||||
amb_pressure.mbar = dive->depth_to_mbar(entry.depth);
|
||||
o2pressure.mbar = calculate_ccr_po2(entry, dc); // ...calculate the po2 based on the sensor data
|
||||
entry.o2pressure.mbar = std::min(o2pressure.mbar, amb_pressure.mbar);
|
||||
} else {
|
||||
|
@ -1610,7 +1610,7 @@ std::vector<std::string> compare_samples(const struct dive *d, const struct plot
|
|||
const char *volume_unit;
|
||||
|
||||
/* Mean pressure in ATM */
|
||||
double atm = depth_to_atm(avg_depth, d);
|
||||
double atm = d->depth_to_atm(avg_depth);
|
||||
|
||||
/* milliliters per minute */
|
||||
int sac = lrint(total_volume_used / atm * 60 / delta_time);
|
||||
|
|
|
@ -144,7 +144,7 @@ void TabDiveInformation::updateProfile()
|
|||
continue;
|
||||
volumes.append(get_volume_string(gases[i], true));
|
||||
if (duration[i]) {
|
||||
sac.mliter = lrint(gases[i].mliter / (depth_to_atm(mean[i], currentDive) * duration[i] / 60));
|
||||
sac.mliter = lrint(gases[i].mliter / (currentDive->depth_to_atm(mean[i]) * duration[i] / 60));
|
||||
SACs.append(get_volume_string(sac, true).append(tr("/min")));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue