summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-15 17:24:17 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-15 17:35:14 -0800
commitdb8de4233d90f4cd111163c012a0d89e1cdbc45c (patch)
tree6f72600db064d99214086c47020d76dd52c13d6b /planner.c
parentc3a08ff056e361257c1c2972d928235f82a37da8 (diff)
downloadsubsurface-db8de4233d90f4cd111163c012a0d89e1cdbc45c.tar.gz
Calculate the gas used during the planned dive
This works on the assumption that the diver uses the deco SAC rate while on a calculated deco stop and the bottom SAC rate during the rest of the dive (including the time they move from deco stop to deco stop). This is making the planning function mostly useful for open circuit diving. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/planner.c b/planner.c
index 8ad771064..65d86f7e3 100644
--- a/planner.c
+++ b/planner.c
@@ -431,7 +431,8 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
{
char buffer[2000];
- int len, lastdepth = 0, lasttime = 0;
+ int consumption[MAX_CYLINDERS] = { 0, };
+ int len, gasidx, lastdepth = 0, lasttime = 0;
struct divedatapoint *dp = diveplan->dp;
int o2, he;
@@ -448,6 +449,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
char gas[12];
double depthvalue;
int decimals;
+ double used;
int newo2 = o2, newhe = he;
struct divedatapoint *nextdp;
@@ -473,20 +475,27 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
if (!dp->entered && o2 == newo2 && he == newhe && nextdp && dp->depth != lastdepth && nextdp->depth != dp->depth)
continue;
get_gas_string(o2, he, gas, 12);
+ gasidx = get_gasidx(dive, o2, he);
len = strlen(buffer);
if (dp->depth != lastdepth) {
+ used = diveplan->bottomsac / 1000.0 * depth_to_mbar((dp->depth + lastdepth) / 2, dive) *
+ (dp->time - lasttime) / 60;
snprintf(buffer + len, sizeof(buffer) - len, "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s\n",
decimals, depthvalue, depth_unit,
FRACTION(dp->time - lasttime, 60),
FRACTION(dp->time, 60),
gas);
} else {
+ /* we use deco SAC rate during the calculated deco stops, bottom SAC rate everywhere else */
+ int sac = dp->entered ? diveplan->bottomsac : diveplan->decosac;
+ used = sac / 1000.0 * depth_to_mbar(dp->depth, dive) * (dp->time - lasttime) / 60;
snprintf(buffer + len, sizeof(buffer) - len, "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s\n",
decimals, depthvalue, depth_unit,
FRACTION(dp->time - lasttime, 60),
FRACTION(dp->time, 60),
gas);
}
+ consumption[gasidx] += used;
get_gas_string(newo2, newhe, gas, 12);
if (o2 != newo2 || he != newhe) {
len = strlen(buffer);
@@ -497,6 +506,20 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
lasttime = dp->time;
lastdepth = dp->depth;
} while((dp = dp->next) != NULL);
+ len = strlen(buffer);
+ snprintf(buffer + len, sizeof(buffer) - len, "Gas consumption:\n");
+ for (gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) {
+ double volume;
+ const char *unit;
+ char gas[12];
+ if (consumption[gasidx] == 0)
+ continue;
+ len = strlen(buffer);
+ volume = get_volume_units(consumption[gasidx], NULL, &unit);
+ get_gas_string(dive->cylinder[gasidx].gasmix.o2.permille,
+ dive->cylinder[gasidx].gasmix.he.permille, gas, 12);
+ snprintf(buffer + len, sizeof(buffer) - len, "%.0f%s of %s\n", volume, unit, gas);
+ }
dive->notes = strdup(buffer);
}