mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Clean up the handling of surface pressure
There are two ways to look at surface pressure. One is to say "what was the surface pressure during that dive?" - in that case we now return an average over the pressure reported by the different divecomputers (or the standard 1013mbar if none reported any). Or you want to do specific calculations for a specific divecomputer - in which case we access only the pressure reported by THAT divecomputer, if present (and fall back to the previous case, otherwise). We still have lots of places in Subsurface that only act on the first divecomputer. As a side effect of this change we now make this more obvious as we in those cases pass a pointer to the first divecomputer explicitly to the calculations. Either way, this commit should prevent us from ever mistakenly basing our calculations on a surface pressure of 0 (which is the initial bug in deco.c that triggered all this). Similar changes need to be made for other elements that we currently only use from the first divecomputer, i.e., salinity. Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
54ff04c61b
commit
61861d2611
7 changed files with 51 additions and 31 deletions
16
dive.c
16
dive.c
|
|
@ -230,6 +230,22 @@ int get_duration_in_sec(struct dive *dive)
|
|||
return duration;
|
||||
}
|
||||
|
||||
int get_surface_pressure_in_mbar(const struct dive *dive, gboolean non_null)
|
||||
{
|
||||
int count = 0, pressure = 0;
|
||||
const struct divecomputer *dc = &dive->dc;
|
||||
do {
|
||||
if (dc->surface_pressure.mbar) {
|
||||
pressure = (double)(count * pressure + dc->surface_pressure.mbar) / (count + 1) + 0.5;
|
||||
count++;
|
||||
}
|
||||
dc = dc->next;
|
||||
} while (dc);
|
||||
if (!pressure && non_null)
|
||||
pressure = SURFACE_PRESSURE;
|
||||
return pressure;
|
||||
}
|
||||
|
||||
static void update_temperature(temperature_t *temperature, int new)
|
||||
{
|
||||
if (new) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue