summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-19 14:28:07 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-19 14:28:07 -0800
commit852772079472de6afa9e5d1fc88dfe81857798c4 (patch)
tree3f567a8376ea79662fc9649851a18a496a8de727 /planner.c
parent0fd6907965b94c03e476b3f6333423cfdac00996 (diff)
downloadsubsurface-852772079472de6afa9e5d1fc88dfe81857798c4.tar.gz
Planner: Start calculations with gas 0 instead of air
The planner had a fatal flaw in that it ALWAYS started with AIR, even when clearly claiming to use the correct gas. We only picked up correct gases from events, but not at the beginning of the dive (where there is no event). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/planner.c b/planner.c
index 245cb1bbb..1057bea13 100644
--- a/planner.c
+++ b/planner.c
@@ -137,6 +137,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
struct divecomputer *dc;
struct sample *sample, *psample;
int i, j, t0, t1, gasidx, lastdepth;
+ int o2, he;
double tissue_tolerance;
if (!dive)
@@ -152,8 +153,10 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
return tissue_tolerance;
psample = sample = dc->sample;
lastdepth = t0 = 0;
+ /* we always start with gas 0 (unless an event tells us otherwise) */
+ o2 = dive->cylinder[0].gasmix.o2.permille;
+ he = dive->cylinder[0].gasmix.he.permille;
for (i = 0; i < dc->samples; i++, sample++) {
- int o2 = 0, he = 0;
t1 = sample->time.seconds;
get_gas_from_events(&dive->dc, t0, &o2, &he);
if ((gasidx = get_gasidx(dive, o2, he)) == -1) {
@@ -176,7 +179,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
/* how many seconds until we can ascend to the next stop? */
int time_at_last_depth(struct dive *dive, int next_stop, char **cached_data_p)
{
- int depth, gasidx, o2 = 0, he = 0;
+ int depth, gasidx, o2, he;
double surface_pressure, tissue_tolerance;
int wait = 0;
struct sample *sample;
@@ -187,6 +190,9 @@ int time_at_last_depth(struct dive *dive, int next_stop, char **cached_data_p)
tissue_tolerance = tissue_at_end(dive, cached_data_p);
sample = &dive->dc.sample[dive->dc.samples - 1];
depth = sample->depth.mm;
+ /* we always start with gas 0 (unless an event tells us otherwise) */
+ o2 = dive->cylinder[0].gasmix.o2.permille;
+ he = dive->cylinder[0].gasmix.he.permille;
get_gas_from_events(&dive->dc, sample->time.seconds, &o2, &he);
gasidx = get_gasidx(dive, o2, he);
while (deco_allowed_depth(tissue_tolerance, surface_pressure, dive, 1) > next_stop) {
@@ -652,7 +658,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep)
break;
stopidx--;
- /* so now we now the first decostop level above us
+ /* so now we know the first decostop level above us
* NOTE, this could be the surface or a long list of potential stops
* we do NOT start only at the ceiling, as the ceiling may come down
* further during the ascent.
@@ -689,7 +695,10 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep)
* make this configurable at some point */
wait_time = ((wait_time + 59) / 60) * 60;
#if DEBUG_PLAN & 2
- printf("waittime %d:%02d at depth %5.2lfm\n", FRACTION(wait_time, 60), stoplevels[stopidx] / 1000.0);
+ tissue_tolerance = tissue_at_end(dive, cached_datap);
+ ceiling = deco_allowed_depth(tissue_tolerance, diveplan->surface_pressure / 1000.0, dive, 1);
+ printf("waittime %d:%02d at depth %5.2lfm; ceiling %5.2lfm\n", FRACTION(wait_time, 60),
+ stoplevels[stopidx] / 1000.0, ceiling / 1000.0);
#endif
if (wait_time)
plan_add_segment(diveplan, wait_time, stoplevels[stopidx], o2, he, po2);