diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-01-06 16:55:25 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-06 22:16:59 -0800 |
commit | 25209bfbb4c653c34ddd43f7067e6d0604779b07 (patch) | |
tree | 1e9d143261f3bf344f2126cfe46bc80f3b1d8fbc | |
parent | 98ed131bdaee6074a2f65d0643e7137e7e5692df (diff) | |
download | subsurface-25209bfbb4c653c34ddd43f7067e6d0604779b07.tar.gz |
Fix pressure_time calculation for SAC-rate
The code was using bar, not atm to calculate the pressure_time
multiplier. But SAC-rate is relative to atm.
We could do the correction at the end (and keep the pressure_time in
"bar-seconds"), but let's just use the expected units during the
integration. Especially since this also makes a helper function to do
the calculations (with variables to keep the units obvious) instead of
having multi-line expressions that have the wrong units.
This fixes what I thought were rounding errors for the pressure graphs.
They were just unit confusion.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | profile.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -1685,6 +1685,20 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc } while ((secondary = secondary->next) != NULL); } +/* + * What's the pressure-time between two plot data entries? + * We're calculating the integral of pressure over time by + * adding these up. + */ +static inline double pressure_time(struct dive *dive, struct plot_data *a, struct plot_data *b) +{ + int time = b->sec - a->sec; + int depth = (a->depth + b->depth)/2; + int mbar = depth_to_mbar(depth, dive); + + return bar_to_atm(mbar / 1000.0) * time; +} + static void populate_pressure_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi) { int i, cylinderindex; @@ -1709,6 +1723,9 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer entry->same_cylinder = entry->cylinderindex == cylinderindex; cylinderindex = entry->cylinderindex; + /* discrete integration of pressure over time to get the SAC rate equivalent */ + current->pressure_time += pressure_time(dive, entry-1, entry); + /* track the segments per cylinder and their pressure/time integral */ if (!entry->same_cylinder) { current = pr_track_alloc(SENSOR_PRESSURE(entry), entry->sec); @@ -1724,8 +1741,6 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer } } /* finally, do the discrete integration to get the SAC rate equivalent */ - current->pressure_time += (entry->sec - (entry-1)->sec) * - depth_to_mbar((entry->depth + (entry-1)->depth) / 2, dive) / 1000.0; if (SENSOR_PRESSURE(entry)) { current->end = SENSOR_PRESSURE(entry); current->t_end = entry->sec; |