summaryrefslogtreecommitdiffstats
path: root/core/planner.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-05 20:43:06 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-08-08 16:26:31 -0700
commit52e5d9c605469b338075e22533a8f97a6f984b57 (patch)
treec8fd18dc85ee5afba09c6714353316efc8a8db68 /core/planner.c
parent594d1d3514f91221884bdc31f29a09e8f325f1e8 (diff)
downloadsubsurface-52e5d9c605469b338075e22533a8f97a6f984b57.tar.gz
Cleanup: move planner/deco related declarations planner/deco.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/planner.c')
-rw-r--r--core/planner.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/core/planner.c b/core/planner.c
index fb53fb59d..b4400b91f 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -5,12 +5,11 @@
*
* (c) Dirk Hohndel 2013
*/
-#include "ssrf.h"
#include <assert.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
-#include "dive.h"
+#include "ssrf.h"
#include "divelist.h"
#include "subsurface-string.h"
#include "deco.h"
@@ -638,6 +637,32 @@ void printdecotable(struct decostop *table)
}
}
+static void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth)
+{
+ int integral = 0;
+ int last_time = 0;
+ int last_depth = 0;
+ struct divedatapoint *dp = dive->dp;
+
+ *max_depth = 0;
+
+ while (dp) {
+ if (dp->time) {
+ /* Ignore gas indication samples */
+ integral += (dp->depth.mm + last_depth) * (dp->time - last_time) / 2;
+ last_time = dp->time;
+ last_depth = dp->depth.mm;
+ if (dp->depth.mm > *max_depth)
+ *max_depth = dp->depth.mm;
+ }
+ dp = dp->next;
+ }
+ if (last_time)
+ *avg_depth = integral / last_time;
+ else
+ *avg_depth = *max_depth = 0;
+}
+
bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer)
{