profile: turn plotdata::mod, ead, eadd, end into depth_t

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-12-14 20:46:15 +01:00 committed by Michael Keller
parent 58d096adfc
commit 4237cb9999
3 changed files with 39 additions and 38 deletions

View file

@ -1126,23 +1126,23 @@ static void calculate_gas_information_new(const struct dive *dive, const struct
* END takes O + N (air) into account ("Narcotic" for trimix dives) * END takes O + N (air) into account ("Narcotic" for trimix dives)
* EAD just uses N ("Air" for nitrox dives) */ * EAD just uses N ("Air" for nitrox dives) */
pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) }; pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) };
entry.mod = dive->gas_mod(gasmix, modpO2, 1_mm).mm; entry.mod = dive->gas_mod(gasmix, modpO2, 1_mm);
entry.end = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * (1000 - fhe) / 1000.0)).mm; entry.end = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * (1000 - fhe) / 1000.0));
entry.ead = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * fn2 / (double)N2_IN_AIR)).mm; entry.ead = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * fn2 / (double)N2_IN_AIR));
entry.eadd = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * entry.eadd = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) *
(entry.pressures.o2 / amb_pressure * O2_DENSITY + (entry.pressures.o2 / amb_pressure * O2_DENSITY +
entry.pressures.n2 / amb_pressure * N2_DENSITY + entry.pressures.n2 / amb_pressure * N2_DENSITY +
entry.pressures.he / amb_pressure * HE_DENSITY) / entry.pressures.he / amb_pressure * HE_DENSITY) /
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000)).mm; (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000));
entry.density = gas_density(entry.pressures); entry.density = gas_density(entry.pressures);
if (entry.mod < 0) if (entry.mod.mm < 0)
entry.mod = 0; entry.mod = 0_m;
if (entry.ead < 0) if (entry.ead.mm < 0)
entry.ead = 0; entry.ead = 0_m;
if (entry.end < 0) if (entry.end.mm < 0)
entry.end = 0; entry.end = 0_m;
if (entry.eadd < 0) if (entry.eadd.mm < 0)
entry.eadd = 0; entry.eadd = 0_m;
} }
} }
@ -1259,7 +1259,8 @@ struct plot_info create_plot_info_new(const struct dive *dive, const struct dive
static std::vector<std::string> plot_string(const struct dive *d, const struct plot_info &pi, int idx) static std::vector<std::string> plot_string(const struct dive *d, const struct plot_info &pi, int idx)
{ {
int pressurevalue, mod, ead, end, eadd; int pressurevalue;
depth_t mod, ead, end, eadd;
const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit; const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
double depthvalue, tempvalue, speedvalue, sacvalue; double depthvalue, tempvalue, speedvalue, sacvalue;
int decimals, cyl; int decimals, cyl;
@ -1301,26 +1302,26 @@ static std::vector<std::string> plot_string(const struct dive *d, const struct p
res.push_back(casprintf_loc(translate("gettextFromC", "pN₂: %.2fbar"), entry.pressures.n2)); res.push_back(casprintf_loc(translate("gettextFromC", "pN₂: %.2fbar"), entry.pressures.n2));
if (prefs.pp_graphs.phe && entry.pressures.he > 0) if (prefs.pp_graphs.phe && entry.pressures.he > 0)
res.push_back(casprintf_loc(translate("gettextFromC", "pHe: %.2fbar"), entry.pressures.he)); res.push_back(casprintf_loc(translate("gettextFromC", "pHe: %.2fbar"), entry.pressures.he));
if (prefs.mod && entry.mod > 0) { if (prefs.mod && entry.mod.mm > 0) {
mod = lrint(get_depth_units(entry.mod, NULL, &depth_unit)); mod.mm = lrint(get_depth_units(entry.mod.mm, NULL, &depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "MOD: %d%s"), mod, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "MOD: %d%s"), mod.mm, depth_unit));
} }
eadd = lrint(get_depth_units(entry.eadd, NULL, &depth_unit)); eadd.mm = lrint(get_depth_units(entry.eadd.mm, NULL, &depth_unit));
if (prefs.ead) { if (prefs.ead) {
switch (pi.dive_type) { switch (pi.dive_type) {
case plot_info::NITROX: case plot_info::NITROX:
if (entry.ead > 0) { if (entry.ead.mm > 0) {
ead = lrint(get_depth_units(entry.ead, NULL, &depth_unit)); ead.mm = lrint(get_depth_units(entry.ead.mm, NULL, &depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "EAD: %d%s"), ead, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "EAD: %d%s"), ead.mm, depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd, depth_unit, entry.density)); res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd.mm, depth_unit, entry.density));
break; break;
} }
case plot_info::TRIMIX: case plot_info::TRIMIX:
if (entry.end > 0) { if (entry.end.mm > 0) {
end = lrint(get_depth_units(entry.end, NULL, &depth_unit)); end.mm = lrint(get_depth_units(entry.end.mm, NULL, &depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "END: %d%s"), end, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "END: %d%s"), end.mm, depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd, depth_unit, entry.density)); res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd.mm, depth_unit, entry.density));
break; break;
} }
case plot_info::AIR: case plot_info::AIR:

View file

@ -60,7 +60,7 @@ struct plot_data {
std::array<pressure_t, MAX_O2_SENSORS> o2sensor; //for rebreathers with several sensors std::array<pressure_t, MAX_O2_SENSORS> o2sensor; //for rebreathers with several sensors
pressure_t o2setpoint; pressure_t o2setpoint;
pressure_t scr_OC_pO2; pressure_t scr_OC_pO2;
int mod = 0, ead = 0, end = 0, eadd = 0; depth_t mod, ead, end, eadd;
velocity_t velocity = STABLE; velocity_t velocity = STABLE;
int speed = 0; int speed = 0;
/* values calculated by us */ /* values calculated by us */

View file

@ -92,10 +92,10 @@ static void put_pd(struct membuffer *b, const struct plot_info &pi, int idx)
put_int(b, entry.o2sensor[i].mbar); put_int(b, entry.o2sensor[i].mbar);
put_int(b, entry.o2setpoint.mbar); put_int(b, entry.o2setpoint.mbar);
put_int(b, entry.scr_OC_pO2.mbar); put_int(b, entry.scr_OC_pO2.mbar);
put_int(b, entry.mod); put_int(b, entry.mod.mm);
put_int(b, entry.ead); put_int(b, entry.ead.mm);
put_int(b, entry.end); put_int(b, entry.end.mm);
put_int(b, entry.eadd); put_int(b, entry.eadd.mm);
switch (entry.velocity) { switch (entry.velocity) {
case STABLE: case STABLE:
put_csv_string(b, "STABLE"); put_csv_string(b, "STABLE");
@ -296,29 +296,29 @@ static std::string format_st_event(const plot_data &entry, const plot_data &next
replace_all(format_string, "[scr_oc_po2]", ""); replace_all(format_string, "[scr_oc_po2]", "");
} }
if (entry.mod > 0) { if (entry.mod.mm > 0) {
value = get_depth_units(entry.mod, &decimals, &unit); value = get_depth_units(entry.mod.mm, &decimals, &unit);
replace_all(format_string, "[mod]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[mod]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[mod]", ""); replace_all(format_string, "[mod]", "");
} }
if (entry.ead > 0) { if (entry.ead.mm > 0) {
value = get_depth_units(entry.ead, &decimals, &unit); value = get_depth_units(entry.ead.mm, &decimals, &unit);
replace_all(format_string, "[ead]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[ead]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[ead]", ""); replace_all(format_string, "[ead]", "");
} }
if (entry.end > 0) { if (entry.end.mm > 0) {
value = get_depth_units(entry.end, &decimals, &unit); value = get_depth_units(entry.end.mm, &decimals, &unit);
replace_all(format_string, "[end]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[end]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[end]", ""); replace_all(format_string, "[end]", "");
} }
if (entry.eadd > 0) { if (entry.eadd.mm > 0) {
value = get_depth_units(entry.eadd, &decimals, &unit); value = get_depth_units(entry.eadd.mm, &decimals, &unit);
replace_all(format_string, "[eadd]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[eadd]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[eadd]", ""); replace_all(format_string, "[eadd]", "");