summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-08 21:00:30 +0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-08 21:05:16 +0800
commitfef4d15965f4efefe9ed554df5a78d279289630a (patch)
tree789405b2ea78c71b80e2d27518071aed3a3c6359
parenteec5dba1c23a6aef8c73ff744973cf8ad821eef2 (diff)
downloadsubsurface-fef4d15965f4efefe9ed554df5a78d279289630a.tar.gz
When interpolating tank pressures, don't devide by zero
When an interpolated segment is on the surface we get no pressure time - and try to divide by zero. (plus a small whitespace issue that slipped throught the cracks earlier) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--profile.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/profile.c b/profile.c
index 0b90a288d..81c002966 100644
--- a/profile.c
+++ b/profile.c
@@ -428,8 +428,8 @@ struct pr_interpolate_struct {
#ifdef DEBUG_PR_INTERPOLATE
static void dump_pr_interpolate(int i, pr_interpolate_t interpolate_pr)
{
- printf("Interpolate for entry %d: start %d - end %d - pt %d - acc_pt %d\n", i,
- interpolate_pr.start, interpolate_pr.end, interpolate_pr.pressure_time, interpolate_pr.acc_pressure_time);
+ printf("Interpolate for entry %d: start %d - end %d - pt %d - acc_pt %d\n", i,
+ interpolate_pr.start, interpolate_pr.end, interpolate_pr.pressure_time, interpolate_pr.acc_pressure_time);
}
#endif
@@ -620,12 +620,15 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
#ifdef DEBUG_PR_INTERPOLATE
dump_pr_interpolate(i, interpolate);
#endif
- /* Overall pressure change over total pressure-time for this segment*/
- magic = (interpolate.end - interpolate.start) / (double) interpolate.pressure_time;
-
- /* Use that overall pressure change to update the current pressure */
- cur_pr[cyl] = interpolate.start + magic * interpolate.acc_pressure_time + 0.5;
- INTERPOLATED_PRESSURE(entry) = cur_pr[cyl];
+ /* if this segment had pressure time, set the interpolated pressure */
+ if (interpolate.pressure_time) {
+ /* Overall pressure change over total pressure-time for this segment*/
+ magic = (interpolate.end - interpolate.start) / (double) interpolate.pressure_time;
+
+ /* Use that overall pressure change to update the current pressure */
+ cur_pr[cyl] = interpolate.start + magic * interpolate.acc_pressure_time + 0.5;
+ INTERPOLATED_PRESSURE(entry) = cur_pr[cyl];
+ }
}
}