mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Round MOD of gas rather than truncate
For the proper calculation, we need to take salinity and surface pressure into account (rather than depth = bar * 10 - 10) Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
9c6a3a7ff3
commit
a7d18a9fa6
6 changed files with 24 additions and 12 deletions
26
dive.h
26
dive.h
|
@ -167,13 +167,6 @@ static inline int interpolate(int a, int b, int part, int whole)
|
|||
return rint(x / whole);
|
||||
}
|
||||
|
||||
/* MOD rounded to multiples of roundto mm */
|
||||
static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, int roundto) {
|
||||
depth_t depth;
|
||||
depth.mm = ((po2_limit.mbar * 1000 / get_o2(mix) * 10 - 10000) / roundto) * roundto;
|
||||
return depth;
|
||||
}
|
||||
|
||||
void get_gas_string(const struct gasmix *gasmix, char *text, int len);
|
||||
const char *gasname(const struct gasmix *gasmix);
|
||||
|
||||
|
@ -445,6 +438,25 @@ static inline int rel_mbar_to_depth(int mbar, struct dive *dive)
|
|||
return cm * 10;
|
||||
}
|
||||
|
||||
static inline int mbar_to_depth(int mbar, struct dive *dive)
|
||||
{
|
||||
pressure_t surface_pressure;
|
||||
if (dive->surface_pressure.mbar)
|
||||
surface_pressure = dive->surface_pressure;
|
||||
else
|
||||
surface_pressure.mbar = SURFACE_PRESSURE;
|
||||
return rel_mbar_to_depth(mbar - surface_pressure.mbar, dive);
|
||||
}
|
||||
|
||||
/* MOD rounded to multiples of roundto mm */
|
||||
static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, struct dive *dive, int roundto) {
|
||||
depth_t rounded_depth;
|
||||
|
||||
double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix), dive);
|
||||
rounded_depth.mm = rint(depth / roundto) * roundto;
|
||||
return rounded_depth;
|
||||
}
|
||||
|
||||
#define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */
|
||||
|
||||
/* this is a global spot for a temporary dive structure that we use to
|
||||
|
|
|
@ -226,7 +226,7 @@ void reset_cylinders(struct dive *dive, bool track_gas)
|
|||
if (cylinder_none(cyl))
|
||||
continue;
|
||||
if (cyl->depth.mm == 0) /* if the gas doesn't give a mod, calculate based on prefs */
|
||||
cyl->depth = gas_mod(&cyl->gasmix, decopo2, M_OR_FT(3,10));
|
||||
cyl->depth = gas_mod(&cyl->gasmix, decopo2, dive, M_OR_FT(3,10));
|
||||
if (track_gas)
|
||||
cyl->start.mbar = cyl->end.mbar = cyl->type.workingpressure.mbar;
|
||||
cyl->gas_used.mliter = 0;
|
||||
|
|
|
@ -176,7 +176,7 @@ void fill_default_cylinder(cylinder_t *cyl)
|
|||
cyl->type.size.mliter = cuft_to_l(ti->cuft) * 1000 / bar_to_atm(psi_to_bar(ti->psi));
|
||||
}
|
||||
// MOD of air
|
||||
cyl->depth = gas_mod(&cyl->gasmix, pO2, 1);
|
||||
cyl->depth = gas_mod(&cyl->gasmix, pO2, &displayed_dive, 1);
|
||||
}
|
||||
|
||||
/* make sure that the gas we are switching to is represented in our
|
||||
|
|
|
@ -963,7 +963,7 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
|
|||
* END takes O₂ + N₂ (air) into account ("Narcotic" for trimix dives)
|
||||
* EAD just uses N₂ ("Air" for nitrox dives) */
|
||||
pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) };
|
||||
entry->mod = (double)gas_mod(&dive->cylinder[cylinderindex].gasmix, modpO2, 1).mm;
|
||||
entry->mod = (double)gas_mod(&dive->cylinder[cylinderindex].gasmix, modpO2, dive, 1).mm;
|
||||
entry->end = (entry->depth + 10000) * (1000 - fhe) / 1000.0 - 10000;
|
||||
entry->ead = (entry->depth + 10000) * fn2 / (double)N2_IN_AIR - 10000;
|
||||
entry->eadd = (entry->depth + 10000) *
|
||||
|
|
|
@ -218,7 +218,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||
prefs.o2consumption / prefs.decosac / prefs.pscr_ratio;
|
||||
else
|
||||
modpO2.mbar = prefs.decopo2;
|
||||
cyl->depth = gas_mod(&cyl->gasmix, modpO2, M_OR_FT(3, 10));
|
||||
cyl->depth = gas_mod(&cyl->gasmix, modpO2, &displayed_dive, M_OR_FT(3, 10));
|
||||
changed = true;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -536,7 +536,7 @@ bool DivePlannerPointsModel::addGas(struct gasmix mix)
|
|||
prefs.o2consumption / prefs.decosac / prefs.pscr_ratio;
|
||||
else
|
||||
modpO2.mbar = prefs.decopo2;
|
||||
cyl->depth = gas_mod(&mix, modpO2, M_OR_FT(3,10));
|
||||
cyl->depth = gas_mod(&mix, modpO2, &displayed_dive, M_OR_FT(3,10));
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue