mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
98ed131bda
commit
25209bfbb4
1 changed files with 17 additions and 2 deletions
19
profile.c
19
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue