summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-09 06:50:53 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-09 07:02:43 -0800
commitc7efcb23a9a838f88c6691cb7b278126ae639c4b (patch)
tree13574139ec6d4b8e7db05ed7efb56f3a65cacd92 /dive.c
parent0755cc522b9d68580f79e567808770df5814f150 (diff)
downloadsubsurface-c7efcb23a9a838f88c6691cb7b278126ae639c4b.tar.gz
Add a meandepth to the dive structure
This is currently only used in one place (in statistics.c), but it certainly is consistent with the other recent changes to avoid using only the first divecomputer when trying to make statements about a dive. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index fb9d1e84e..ef05c51fe 100644
--- a/dive.c
+++ b/dive.c
@@ -454,6 +454,21 @@ static void fixup_water_salinity(struct dive *dive)
dive->salinity = (sum + nr/2)/nr;
}
+static void fixup_meandepth(struct dive *dive)
+{
+ struct divecomputer *dc;
+ int sum = 0, nr = 0;
+
+ for_each_dc(dive, dc) {
+ if (dc->meandepth.mm) {
+ sum += dc->meandepth.mm;
+ nr++;
+ }
+ }
+ if (nr)
+ dive->meandepth.mm = (sum + nr / 2) / nr;
+}
+
/*
* events are stored as a linked list, so the concept of
* "consecutive, identical events" is somewhat hard to
@@ -645,6 +660,7 @@ struct dive *fixup_dive(struct dive *dive)
fixup_water_salinity(dive);
fixup_surface_pressure(dive);
+ fixup_meandepth(dive);
for_each_dc(dive, dc)
fixup_dive_dc(dive, dc);