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
12
divelist.c
12
divelist.c
|
|
@ -655,7 +655,7 @@ static int calculate_otu(struct dive *dive)
|
|||
po2 = sample->po2;
|
||||
} else {
|
||||
int o2 = active_o2(dive, dc, sample->time);
|
||||
po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);
|
||||
po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive, &dive->dc);
|
||||
}
|
||||
if (po2 >= 500)
|
||||
otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0;
|
||||
|
|
@ -720,7 +720,7 @@ static int calculate_sac(struct dive *dive)
|
|||
}
|
||||
}
|
||||
/* Mean pressure in bar (SAC calculations are in bar*l/min) */
|
||||
pressure = depth_to_mbar(dive->dc.meandepth.mm, dive) / 1000.0;
|
||||
pressure = depth_to_mbar(dive->dc.meandepth.mm, dive, &dive->dc) / 1000.0;
|
||||
sac = airuse / pressure * 60 / duration;
|
||||
|
||||
/* milliliters per minute.. */
|
||||
|
|
@ -744,7 +744,7 @@ static void add_dive_to_deco(struct dive *dive)
|
|||
|
||||
for (j = t0; j < t1; j++) {
|
||||
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
|
||||
(void) add_segment(depth_to_mbar(depth, dive) / 1000.0,
|
||||
(void) add_segment(depth_to_mbar(depth, dive, &dive->dc) / 1000.0,
|
||||
&dive->cylinder[sample->sensor].gasmix, 1, sample->po2, dive);
|
||||
}
|
||||
}
|
||||
|
|
@ -790,7 +790,7 @@ double init_decompression(struct dive *dive)
|
|||
/* again skip dives from different trips */
|
||||
if (dive->divetrip && dive->divetrip != pdive->divetrip)
|
||||
continue;
|
||||
surface_pressure = (pdive->dc.surface_pressure.mbar ? pdive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000;
|
||||
surface_pressure = get_surface_pressure_in_mbar(pdive, TRUE) / 1000.0;
|
||||
if (!deco_init) {
|
||||
clear_deco(surface_pressure);
|
||||
deco_init = TRUE;
|
||||
|
|
@ -816,7 +816,7 @@ double init_decompression(struct dive *dive)
|
|||
/* add the final surface time */
|
||||
if (lasttime && dive->when > lasttime) {
|
||||
surface_time = dive->when - lasttime;
|
||||
surface_pressure = (dive->dc.surface_pressure.mbar ? dive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000;
|
||||
surface_pressure = get_surface_pressure_in_mbar(dive, TRUE) / 1000.0;
|
||||
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive);
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
|
||||
|
|
@ -824,7 +824,7 @@ double init_decompression(struct dive *dive)
|
|||
#endif
|
||||
}
|
||||
if (!deco_init) {
|
||||
double surface_pressure = (dive->dc.surface_pressure.mbar ? dive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000;
|
||||
double surface_pressure = get_surface_pressure_in_mbar(dive, TRUE) / 1000.0;
|
||||
clear_deco(surface_pressure);
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
printf("no previous dive\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue