summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-02-24 11:39:51 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-24 11:48:29 -0800
commit7b20fb826c9f7ff2ad9d26526e6457a5b5d9b9d5 (patch)
treee0e47fa44346d54720133bc79ed112a002972070 /divelist.c
parentb62e63650a3794a90f7af1aaee62b7fa7780b455 (diff)
downloadsubsurface-7b20fb826c9f7ff2ad9d26526e6457a5b5d9b9d5.tar.gz
Use the improved duration and average depth for everything
The code was written to get the SAC rate correct, but we probably do want to have the duration and mean depth of the dive always be shown for the non-surface-time. So move the code from the sac-rate calculation to the generic dive fixup part. This makes the dive list and statistics all show the duration as the under-water duration, which is not necessarily the same as "difference between beginning and end of dive". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c48
1 files changed, 5 insertions, 43 deletions
diff --git a/divelist.c b/divelist.c
index 501cf0487..952b03bb2 100644
--- a/divelist.c
+++ b/divelist.c
@@ -719,46 +719,6 @@ static double calculate_airuse(struct dive *dive)
return airuse;
}
-/*
- * Calculate how long we were actually under water, and the average
- * depth while under water.
- *
- * This ignores any surface time in the middle of the dive.
- */
-static int calculate_duration(struct dive *dive, struct divecomputer *dc, int *meandepth)
-{
- int duration, i;
- int lasttime, lastdepth, depthtime;
-
- duration = 0;
- lasttime = 0;
- lastdepth = 0;
- depthtime = 0;
- for (i = 0; i < dc->samples; i++) {
- struct sample *sample = dc->sample + i;
- int time = sample->time.seconds;
- int depth = sample->depth.mm;
-
- /* We ignore segments at the surface */
- if (depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) {
- duration += time - lasttime;
- depthtime += (time - lasttime)*(depth+lastdepth)/2;
- }
- lastdepth = depth;
- lasttime = time;
- }
- if (duration) {
- if (meandepth)
- *meandepth = depthtime / duration;
- return duration;
- }
-
- /* No samples? */
- if (meandepth)
- *meandepth = dive->meandepth.mm;
- return dive->duration.seconds;
-}
-
/* this only uses the first divecomputer to calculate the SAC rate */
static int calculate_sac(struct dive *dive)
{
@@ -770,12 +730,14 @@ static int calculate_sac(struct dive *dive)
if (!airuse)
return 0;
- duration = calculate_duration(dive, dc, &meandepth);
-
- /* find and eliminate long surface intervals */
+ duration = dc->duration.seconds;
if (!duration)
return 0;
+ meandepth = dc->meandepth.mm;
+ if (!meandepth)
+ return 0;
+
/* Mean pressure in ATM (SAC calculations are in atm*l/min) */
pressure = (double) depth_to_mbar(meandepth, dive) / SURFACE_PRESSURE;
sac = airuse / pressure * 60 / duration;