[PATCH] Fix pressure_time calculation for SAC-rate
Linus Torvalds
torvalds at linux-foundation.org
Sun Jan 6 17:03:48 PST 2013
From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sun, 6 Jan 2013 16:55:25 -0800
Subject: [PATCH] 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 at linux-foundation.org>
---
This fixes the problem I mentioned in the previous commit:
"That does make the rounding errors more obvious in the graph, but we
can fix that separately."
and they were apparently just due to the pressure-time being done in bar,
rather than atm. So with this, together with the previous cleanup, I now
get the exact beginning/ending pressures I entered manually on the plot,
*and* the pressure graph doesn't have any kinks.
profile.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/profile.c b/profile.c
index 7540ff764d45..6643e34cf185 100644
--- a/profile.c
+++ b/profile.c
@@ -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;
--
1.8.1.rc2.6.g18499ba
More information about the subsurface
mailing list