diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-02-09 07:49:12 +1100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-02-09 08:01:59 +1100 |
commit | 61861d2611779449b3a4ab6dd2096f50e50399b0 (patch) | |
tree | 898a7718d21b968a3cb97e85ca1da54f8ee4b374 /profile.c | |
parent | 54ff04c61b8e781ab3333ddd82178dc669286cae (diff) | |
download | subsurface-61861d2611779449b3a4ab6dd2096f50e50399b0.tar.gz |
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>
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1011,16 +1011,16 @@ static void set_sac_color(struct graphics_context *gc, int sac, int avg_sac) } /* calculate the current SAC in ml/min and convert to int */ -#define GET_LOCAL_SAC(_entry1, _entry2, _dive) (int) \ +#define GET_LOCAL_SAC(_entry1, _entry2, _dive, _dc) (int) \ ((GET_PRESSURE((_entry1)) - GET_PRESSURE((_entry2))) * \ (_dive)->cylinder[(_entry1)->cylinderindex].type.size.mliter / \ (((_entry2)->sec - (_entry1)->sec) / 60.0) / \ - depth_to_mbar(((_entry1)->depth + (_entry2)->depth) / 2.0, (_dive))) + depth_to_mbar(((_entry1)->depth + (_entry2)->depth) / 2.0, (_dive), (_dc))) #define SAC_WINDOW 45 /* sliding window in seconds for current SAC calculation */ static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info *pi, - struct dive *dive) + struct dive *dive, struct divecomputer *dc) { int i; int last = -1, last_index = -1; @@ -1050,12 +1050,12 @@ static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info if (!last_entry) { last = i; last_entry = entry; - sac = GET_LOCAL_SAC(entry, pi->entry + i + 1, dive); + sac = GET_LOCAL_SAC(entry, pi->entry + i + 1, dive, dc); } else { int j; sac = 0; for (j = last; j < i; j++) - sac += GET_LOCAL_SAC(pi->entry + j, pi->entry + j + 1, dive); + sac += GET_LOCAL_SAC(pi->entry + j, pi->entry + j + 1, dive, dc); sac /= (i - last); if (entry->sec - last_entry->sec >= SAC_WINDOW) { last++; @@ -1400,12 +1400,12 @@ static void fill_missing_segment_pressures(pr_track_t *list) * scale pressures, so it ends up being a unitless scaling * factor. */ -static inline int pressure_time(struct dive *dive, struct plot_data *a, struct plot_data *b) +static inline int pressure_time(struct dive *dive, struct divecomputer *dc, struct plot_data *a, struct plot_data *b) { int time = b->sec - a->sec; int depth = (a->depth + b->depth)/2; - return depth_to_mbar(depth, dive) * time; + return depth_to_mbar(depth, dive, dc) * time; } static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, pr_track_t **track_pr) @@ -1453,7 +1453,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, magic = (segment->end - segment->start) / (double) segment->pressure_time; /* Use that overall pressure change to update the current pressure */ - cur_pt = pressure_time(dive, entry-1, entry); + cur_pt = pressure_time(dive, &dive->dc, entry-1, entry); pressure = cur_pr[cyl] + cur_pt * magic + 0.5; INTERPOLATED_PRESSURE(entry) = pressure; cur_pr[cyl] = pressure; @@ -1768,7 +1768,7 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer struct plot_data *entry = pi->entry + i; /* discrete integration of pressure over time to get the SAC rate equivalent */ - current->pressure_time += pressure_time(dive, entry-1, entry); + current->pressure_time += pressure_time(dive, dc, entry-1, entry); /* track the segments per cylinder and their pressure/time integral */ if (entry->cylinderindex != cylinderindex) { @@ -1814,7 +1814,7 @@ static void calculate_deco_information(struct dive *dive, struct divecomputer *d { int i; double amb_pressure; - double surface_pressure = (dive->dc.surface_pressure.mbar ? dive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000.0; + double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, TRUE)) / 1000.0; for (i = 1; i < pi->nr; i++) { int fo2, fhe, j, t0, t1; @@ -1822,7 +1822,7 @@ static void calculate_deco_information(struct dive *dive, struct divecomputer *d struct plot_data *entry = pi->entry + i; int cylinderindex = entry->cylinderindex; - amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0; + amb_pressure = depth_to_mbar(entry->depth, dive, dc) / 1000.0; fo2 = dive->cylinder[cylinderindex].gasmix.o2.permille ? : O2_IN_AIR; fhe = dive->cylinder[cylinderindex].gasmix.he.permille; double ratio = (double)fhe / (1000.0 - fo2); @@ -1876,7 +1876,7 @@ static void calculate_deco_information(struct dive *dive, struct divecomputer *d tissue_tolerance = 0; for (j = t0+1; j <= t1; j++) { int depth = interpolate(entry[-1].depth, entry[0].depth, j - t0, t1 - t0); - double min_pressure = add_segment(depth_to_mbar(depth, dive) / 1000.0, + double min_pressure = add_segment(depth_to_mbar(depth, dive, dc) / 1000.0, &dive->cylinder[cylinderindex].gasmix, 1, entry->po2 * 1000, dive); tissue_tolerance = min_pressure; } @@ -2039,7 +2039,7 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) plot_temperature_profile(gc, pi); /* Cylinder pressure plot */ - plot_cylinder_pressure(gc, pi, dive); + plot_cylinder_pressure(gc, pi, dive, dc); /* Text on top of all graphs.. */ plot_temperature_text(gc, pi); |