mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Core: Fix bug salinity and pressure values in mbar <-> depth conversion
The conversion between mbar and depth sometimes uses DC's salinity, sometimes user's salinity. By other hand, it uses surface pressure given by user in calculation. This fix try to standartize this values, using them from same source. Signed-off-by: Rafael M. Salvioni <rafael.salvioni@gmail.com>
This commit is contained in:
parent
1e082affdd
commit
695c37499a
5 changed files with 9878 additions and 9852 deletions
|
@ -1,5 +1,6 @@
|
|||
desktop: added button to hide the infobox in the dive profile
|
||||
desktop: use persisted device information for the dive computer configuration
|
||||
core: fix bug using salinity and pressure values in mbar <-> depth conversion
|
||||
export: fix bug resulting in invalid CSV for '""' in 'CSV summary dive details'
|
||||
desktop: add support for multiple tanks to the profile ruler
|
||||
export: change format produced by 'CSV summary dive details' from TSV (tab separated) to CSV
|
||||
|
|
32
core/dive.c
32
core/dive.c
|
@ -3254,12 +3254,20 @@ static double calculate_depth_to_mbarf(int depth, pressure_t surface_pressure, i
|
|||
|
||||
int depth_to_mbar(int depth, const struct dive *dive)
|
||||
{
|
||||
return lrint(calculate_depth_to_mbarf(depth, dive->surface_pressure, dive->salinity));
|
||||
return lrint(depth_to_mbarf(depth, dive));
|
||||
}
|
||||
|
||||
double depth_to_mbarf(int depth, const struct dive *dive)
|
||||
{
|
||||
return calculate_depth_to_mbarf(depth, dive->surface_pressure, dive->salinity);
|
||||
// To downloaded and planned dives, use DC's values
|
||||
int salinity = dive->dc.salinity;
|
||||
pressure_t surface_pressure = dive->dc.surface_pressure;
|
||||
|
||||
if (is_manually_added_dc(&dive->dc)) { // To manual dives, salinity and pressure in another place...
|
||||
surface_pressure = dive->surface_pressure;
|
||||
salinity = dive->user_salinity;
|
||||
}
|
||||
return calculate_depth_to_mbarf(depth, surface_pressure, salinity);
|
||||
}
|
||||
|
||||
double depth_to_bar(int depth, const struct dive *dive)
|
||||
|
@ -3278,20 +3286,26 @@ double depth_to_atm(int depth, const struct dive *dive)
|
|||
* take care of this, but the Uemis we support natively */
|
||||
int rel_mbar_to_depth(int mbar, const struct dive *dive)
|
||||
{
|
||||
double specific_weight = salinity_to_specific_weight(SEAWATER_SALINITY);
|
||||
if (dive->dc.salinity)
|
||||
specific_weight = salinity_to_specific_weight(dive->dc.salinity);
|
||||
// To downloaded and planned dives, use DC's salinity. Manual dives, use user's salinity
|
||||
int salinity = is_manually_added_dc(&dive->dc) ? dive->user_salinity : dive->dc.salinity;
|
||||
if (!salinity)
|
||||
salinity = SEAWATER_SALINITY;
|
||||
|
||||
/* whole mbar gives us cm precision */
|
||||
double specific_weight = salinity_to_specific_weight(salinity);
|
||||
return (int)lrint(mbar / specific_weight);
|
||||
}
|
||||
|
||||
int mbar_to_depth(int mbar, const struct dive *dive)
|
||||
{
|
||||
pressure_t surface_pressure;
|
||||
if (dive->surface_pressure.mbar)
|
||||
surface_pressure = dive->surface_pressure;
|
||||
else
|
||||
// To downloaded and planned dives, use DC's pressure. Manual dives, use user's pressure
|
||||
pressure_t surface_pressure = is_manually_added_dc(&dive->dc)
|
||||
? dive->surface_pressure
|
||||
: dive->dc.surface_pressure;
|
||||
|
||||
if (!surface_pressure.mbar)
|
||||
surface_pressure.mbar = SURFACE_PRESSURE;
|
||||
|
||||
return rel_mbar_to_depth(mbar - surface_pressure.mbar, dive);
|
||||
}
|
||||
|
||||
|
|
|
@ -695,9 +695,20 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
|
||||
set_gf(diveplan->gflow, diveplan->gfhigh);
|
||||
set_vpmb_conservatism(diveplan->vpmb_conservatism);
|
||||
if (!diveplan->surface_pressure)
|
||||
diveplan->surface_pressure = SURFACE_PRESSURE;
|
||||
dive->surface_pressure.mbar = diveplan->surface_pressure;
|
||||
|
||||
if (!diveplan->surface_pressure) {
|
||||
// Lets use dive's surface pressure in planner, if have one...
|
||||
if (dive->dc.surface_pressure.mbar) { // First from DC...
|
||||
diveplan->surface_pressure = dive->dc.surface_pressure.mbar;
|
||||
}
|
||||
else if (dive->surface_pressure.mbar) { // After from user...
|
||||
diveplan->surface_pressure = dive->surface_pressure.mbar;
|
||||
}
|
||||
else {
|
||||
diveplan->surface_pressure = SURFACE_PRESSURE;
|
||||
}
|
||||
}
|
||||
|
||||
clear_deco(ds, dive->surface_pressure.mbar / 1000.0, true);
|
||||
ds->max_bottom_ceiling_pressure.mbar = ds->first_ceiling_pressure.mbar = 0;
|
||||
create_dive_from_plan(diveplan, dive, is_planner);
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue