summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-04-26 17:29:40 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-08 12:28:09 -0700
commitc3a3c1a1e7d7eedc7aa09ba9842069e9933cb7b2 (patch)
tree0375e31c2e39e47944a2cf275f98e9a08493b611 /dive.c
parent00e7ef2cf88e1a96bf14317af79ab2c9b3468ed2 (diff)
downloadsubsurface-c3a3c1a1e7d7eedc7aa09ba9842069e9933cb7b2.tar.gz
Planner: Implement ascend rate according to GUE standard procedures
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index 4bae24526..019b1d0a4 100644
--- a/dive.c
+++ b/dive.c
@@ -2218,3 +2218,23 @@ void set_userid(char *rUserId)
strcpy(prefs.userid, rUserId);
}
#undef MAX_USERID_SIZE
+
+int average_depth(struct diveplan *dive)
+{
+ int integral = 0;
+ int last_time = 0;
+ int last_depth = 0;
+ struct divedatapoint *dp = dive->dp;
+
+ while (dp) {
+ if (dp->time) {
+ /* Ignore gas indication samples */
+ integral += (dp->depth + last_depth) * (dp->time - last_time) / 2;
+ last_time = dp->time;
+ last_depth = dp->depth;
+ }
+ dp = dp->next;
+ }
+
+ return integral / last_time;
+}