aboutsummaryrefslogtreecommitdiffstats
path: root/core/profile.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/profile.c')
-rw-r--r--core/profile.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/core/profile.c b/core/profile.c
index 53eff57e6..e96febffb 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -31,6 +31,7 @@ static struct plot_data *last_pi_entry_new = NULL;
void populate_pressure_information(struct dive *, struct divecomputer *, struct plot_info *, int);
extern bool in_planner();
+extern int bottom_time;
#ifdef DEBUG_PI
/* debugging tool - not normally used */
@@ -954,19 +955,25 @@ static void calculate_ndl_tts(struct dive *dive, struct plot_data *entry, struct
*/
void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode)
{
- int i, count_iteration = 0;
+ int i, count_iteration = 0, deco_time;
double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 1000.0;
bool first_iteration = true;
- int deco_time = 0, prev_deco_time = 10000000;
+ int prev_deco_time = 10000000, time_deep_ceiling = 0;
+ if (in_planner())
+ deco_time = pi->maxtime - bottom_time;
+ else
+ deco_time = 0;
struct deco_state *cache_data_initial = NULL;
/* For VPM-B outside the planner, cache the initial deco state for CVA iterations */
- if (decoMode() == VPMB && !in_planner())
+ if (decoMode() == VPMB) {
cache_deco_state(&cache_data_initial);
+ }
/* For VPM-B outside the planner, iterate until deco time converges (usually one or two iterations after the initial)
* Set maximum number of iterations to 10 just in case */
while ((abs(prev_deco_time - deco_time) >= 30) && (count_iteration < 10)) {
- int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling, final_tts = 0 , time_clear_ceiling = 0, time_deep_ceiling = 0;
- deco_state->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
+ int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling, final_tts = 0 , time_clear_ceiling = 0;
+ if (decoMode() == VPMB)
+ deco_state->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
struct gasmix *gasmix = NULL;
struct event *ev = NULL;
@@ -1001,9 +1008,9 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
if (decoMode() == VPMB && last_ceiling >= first_ceiling && first_iteration == true) {
nuclear_regeneration(t1);
vpmb_start_gradient();
- /* For CVA calculations, start by guessing deco time = dive time remaining */
- deco_time = pi->maxtime - t1;
- vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
+ /* For CVA iterations, calculate next gradient */
+ if (!first_iteration || in_planner())
+ vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
}
entry->ceiling = deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, !prefs.calcceiling3m);
if (prefs.calcceiling3m)
@@ -1011,9 +1018,10 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
else
current_ceiling = entry->ceiling;
last_ceiling = current_ceiling;
- /* If using VPM-B outside the planner, take first_ceiling_pressure as the deepest ceiling */
+ /* If using VPM-B, take first_ceiling_pressure as the deepest ceiling */
if (decoMode() == VPMB) {
- if (current_ceiling > first_ceiling) {
+ if (current_ceiling >= first_ceiling ||
+ time_deep_ceiling == t0 && entry->depth == (entry - 1)->depth) {
time_deep_ceiling = t1;
first_ceiling = current_ceiling;
deco_state->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
@@ -1021,7 +1029,8 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
nuclear_regeneration(t1);
vpmb_start_gradient();
/* For CVA calculations, start by guessing deco time = dive time remaining */
- deco_time = pi->maxtime - t1;
+ if (!in_planner())
+ deco_time = pi->maxtime - t1;
vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
}
}
@@ -1083,7 +1092,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
count_iteration ++;
restore_deco_state(cache_data_initial, true);
} else {
- // With Buhlmann, or not in planner, iterating isn't needed. This makes the while condition false.
+ // With Buhlmann iterating isn't needed. This makes the while condition false.
prev_deco_time = deco_time = 0;
}
}