diff options
author | Robert C. Helling <helling@atdotde.de> | 2014-08-05 12:58:23 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-08-05 06:58:35 -0700 |
commit | 63d98138b41fe373960b58ecb45c239392d43c57 (patch) | |
tree | 1d018b57272409320e59bb91e5790d79eaec6658 /planner.c | |
parent | c477f56029096b207e5da811989aefb885dae799 (diff) | |
download | subsurface-63d98138b41fe373960b58ecb45c239392d43c57.tar.gz |
Bail out of deco calculation after 48h or dive time
With very low values of GFhigh and setting the last stop depth to 6m it
is possible to create dives that need infintie decompression time.
This ends deco after 48h and replaces the dive plan with an error message.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r-- | planner.c | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -517,7 +517,7 @@ static unsigned int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, return stoplevels; } -static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer) +static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error) { char buffer[20000], temp[1000]; int len, lastdepth = 0, lasttime = 0; @@ -533,6 +533,15 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool if (!dp) return; + if (error) { + snprintf(temp, sizeof(temp), + translate("gettextFromC", "Decompression calculation aborted due to excessive time")); + snprintf(buffer, sizeof(buffer), "<span style='color: red;'>%s </span> %s<br>", + translate("gettextFromC", "Warning:"), temp); + dive->notes = strdup(buffer); + return; + } + len = show_disclaimer ? snprintf(buffer, sizeof(buffer), "<div><b>%s<b></div><br>", disclaimer) : 0; snprintf(temp, sizeof(temp), translate("gettextFromC", "based on GFlow = %d and GFhigh = %d"), diveplan->gflow, diveplan->gfhigh); @@ -724,7 +733,7 @@ int ascend_velocity(int depth, int avg_depth, int bottom_time) } } -void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool show_disclaimer) +int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool show_disclaimer) { struct sample *sample; int po2; @@ -747,6 +756,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool int o2time = 0; int breaktime = -1; int breakcylinder; + int error = 0; set_gf(diveplan->gflow, diveplan->gfhigh, prefs.gf_low_at_maxdepth); if (!diveplan->surface_pressure) @@ -772,9 +782,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool transitiontime = depth / 75; /* this still needs to be made configurable */ plan_add_segment(diveplan, transitiontime, 0, gas, po2, false); create_dive_from_plan(diveplan, is_planner); - return; + return(error); } - tissue_tolerance = tissue_at_end(&displayed_dive, cached_datap); #if DEBUG_PLAN & 4 @@ -889,6 +898,11 @@ void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool DECOTIMESTEP, po2, &displayed_dive); cache_deco_state(tissue_tolerance, &trial_cache); clock += DECOTIMESTEP; + /* Finish infinite deco */ + if(clock >= 48 * 3600 && depth >= 6000) { + error = LONGDECO; + break; + } if (prefs.doo2breaks) { if (get_o2(&displayed_dive.cylinder[current_cylinder].gasmix) == 1000) { o2time += DECOTIMESTEP; @@ -929,7 +943,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool * data that we need to be there when plotting the dive */ plan_add_segment(diveplan, clock - previous_point_time, 0, gas, po2, false); create_dive_from_plan(diveplan, is_planner); - add_plan_to_notes(diveplan, &displayed_dive, show_disclaimer); + add_plan_to_notes(diveplan, &displayed_dive, show_disclaimer, error); fixup_dc_duration(&displayed_dive.dc); free(stoplevels); |