summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/deco.c4
-rw-r--r--core/deco.h2
-rw-r--r--core/divelist.c13
-rw-r--r--core/divelist.h2
-rw-r--r--core/planner.c20
-rw-r--r--core/profile.c22
6 files changed, 33 insertions, 30 deletions
diff --git a/core/deco.c b/core/deco.c
index 650376c60..5ca8e1a75 100644
--- a/core/deco.c
+++ b/core/deco.c
@@ -444,13 +444,13 @@ void calc_crushing_pressure(struct deco_state *ds, double pressure)
}
/* add period_in_seconds at the given pressure and gas to the deco calculation */
-void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int ccpo2, enum divemode_t divemode, int sac)
+void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int ccpo2, enum divemode_t divemode, int sac, bool in_planner)
{
UNUSED(sac);
int ci;
struct gas_pressures pressures;
bool icd = false;
- fill_pressures(&pressures, pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE),
+ fill_pressures(&pressures, pressure - ((in_planner && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE),
gasmix, (double) ccpo2 / 1000.0, divemode);
for (ci = 0; ci < 16; ci++) {
diff --git a/core/deco.h b/core/deco.h
index 29a492c93..f8aa73abd 100644
--- a/core/deco.h
+++ b/core/deco.h
@@ -65,7 +65,7 @@ extern double tissue_tolerance_calc(struct deco_state *ds, const struct dive *di
extern void calc_crushing_pressure(struct deco_state *ds, double pressure);
extern void vpmb_start_gradient(struct deco_state *ds);
extern void clear_vpmb_state(struct deco_state *ds);
-extern void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int setpoint, enum divemode_t divemode, int sac);
+extern void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int setpoint, enum divemode_t divemode, int sac, bool in_planner);
extern double regressiona(const struct deco_state *ds);
extern double regressionb(const struct deco_state *ds);
diff --git a/core/divelist.c b/core/divelist.c
index fc02dac45..583451e8f 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -372,7 +372,7 @@ static int calculate_sac(const struct dive *dive)
}
/* for now we do this based on the first divecomputer */
-static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
+static void add_dive_to_deco(struct deco_state *ds, struct dive *dive, bool in_planner)
{
struct divecomputer *dc = &dive->dc;
struct gasmix gasmix = gasmix_air;
@@ -394,7 +394,8 @@ static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
gasmix = get_gasmix(dive, dc, j, &ev, gasmix);
add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, sample->setpoint.mbar,
- get_current_divemode(&dive->dc, j, &evd, &current_divemode), dive->sac);
+ get_current_divemode(&dive->dc, j, &evd, &current_divemode), dive->sac,
+ in_planner);
}
}
}
@@ -419,7 +420,7 @@ static struct gasmix air = { .o2.permille = O2_IN_AIR, .he.permille = 0 };
/* return negative surface time if dives are overlapping */
/* The place you call this function is likely the place where you want
* to create the deco_state */
-int init_decompression(struct deco_state *ds, const struct dive *dive)
+int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_planner)
{
int i, divenr = -1;
int surface_time = 48 * 60 * 60;
@@ -534,14 +535,14 @@ int init_decompression(struct deco_state *ds, const struct dive *dive)
#endif
return surface_time;
}
- add_segment(ds, surface_pressure, air, surface_time, 0, dive->dc.divemode, prefs.decosac);
+ add_segment(ds, surface_pressure, air, surface_time, 0, dive->dc.divemode, prefs.decosac, in_planner);
#if DECO_CALC_DEBUG & 2
printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60));
dump_tissues(ds);
#endif
}
- add_dive_to_deco(ds, pdive);
+ add_dive_to_deco(ds, pdive, in_planner);
last_starttime = pdive->when;
last_endtime = dive_endtime(pdive);
@@ -571,7 +572,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive)
#endif
return surface_time;
}
- add_segment(ds, surface_pressure, air, surface_time, 0, dive->dc.divemode, prefs.decosac);
+ add_segment(ds, surface_pressure, air, surface_time, 0, dive->dc.divemode, prefs.decosac, in_planner);
#if DECO_CALC_DEBUG & 2
printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60));
dump_tissues(ds);
diff --git a/core/divelist.h b/core/divelist.h
index 12c897f8c..41b6b9492 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -26,7 +26,7 @@ extern struct dive_table dive_table;
extern void sort_dive_table(struct dive_table *table);
extern void update_cylinder_related_info(struct dive *);
-extern int init_decompression(struct deco_state *ds, const struct dive *dive);
+extern int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_planner);
/* divelist core logic functions */
extern void process_loaded_dives();
diff --git a/core/planner.c b/core/planner.c
index 341fa6dad..f78031644 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -103,7 +103,7 @@ static void interpolate_transition(struct deco_state *ds, struct dive *dive, dur
for (j = t0.seconds; j < t1.seconds; j++) {
int depth = interpolate(d0.mm, d1.mm, j - t0.seconds, t1.seconds - t0.seconds);
- add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, po2.mbar, divemode, prefs.bottomsac);
+ add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, po2.mbar, divemode, prefs.bottomsac, true);
}
if (d1.mm > d0.mm)
calc_crushing_pressure(ds, depth_to_bar(d1.mm, dive));
@@ -125,7 +125,7 @@ static int tissue_at_end(struct deco_state *ds, struct dive *dive, struct deco_s
if (*cached_datap) {
restore_deco_state(*cached_datap, ds, true);
} else {
- surface_interval = init_decompression(ds, dive);
+ surface_interval = init_decompression(ds, dive, true);
cache_deco_state(ds, cached_datap);
}
dc = &dive->dc;
@@ -533,7 +533,7 @@ static bool trial_ascent(struct deco_state *ds, int wait_time, int trial_depth,
if (wait_time)
add_segment(ds, depth_to_bar(trial_depth, dive),
gasmix,
- wait_time, po2, divemode, prefs.decosac);
+ wait_time, po2, divemode, prefs.decosac, true);
if (decoMode() == VPMB) {
double tolerance_limit = tissue_tolerance_calc(ds, dive, depth_to_bar(stoplevel, dive));
update_regression(ds, dive);
@@ -551,7 +551,7 @@ static bool trial_ascent(struct deco_state *ds, int wait_time, int trial_depth,
deltad = trial_depth;
add_segment(ds, depth_to_bar(trial_depth, dive),
gasmix,
- TIMESTEP, po2, divemode, prefs.decosac);
+ TIMESTEP, po2, divemode, prefs.decosac, true);
tolerance_limit = tissue_tolerance_calc(ds, dive, depth_to_bar(trial_depth, dive));
if (decoMode() == VPMB)
update_regression(ds, dive);
@@ -766,7 +766,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
do {
add_segment(ds, depth_to_bar(depth, dive),
get_cylinder(dive, current_cylinder)->gasmix,
- timestep, po2, divemode, prefs.bottomsac);
+ timestep, po2, divemode, prefs.bottomsac, true);
update_cylinder_pressure(dive, depth, depth, timestep, prefs.bottomsac, get_cylinder(dive, current_cylinder), false, divemode);
clock += timestep;
} while (trial_ascent(ds, 0, depth, 0, avg_depth, bottom_time, get_cylinder(dive, current_cylinder)->gasmix,
@@ -831,7 +831,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
int bailoutsegment = MAX(prefs.min_switch_duration, 60 * prefs.problemsolvingtime);
add_segment(ds, depth_to_bar(depth, dive),
get_cylinder(dive, current_cylinder)->gasmix,
- bailoutsegment, po2, divemode, prefs.bottomsac);
+ bailoutsegment, po2, divemode, prefs.bottomsac, true);
plan_add_segment(diveplan, bailoutsegment, depth, current_cylinder, po2, false, divemode);
bottom_time += bailoutsegment;
last_segment_min_switch = true;
@@ -898,7 +898,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
add_segment(ds, depth_to_bar(depth, dive),
get_cylinder(dive, current_cylinder)->gasmix,
- TIMESTEP, po2, divemode, prefs.decosac);
+ TIMESTEP, po2, divemode, prefs.decosac, true);
last_segment_min_switch = false;
clock += TIMESTEP;
depth -= deltad;
@@ -937,7 +937,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
if (!last_segment_min_switch && get_o2(get_cylinder(dive, current_cylinder)->gasmix) != 1000) {
add_segment(ds, depth_to_bar(depth, dive),
get_cylinder(dive, current_cylinder)->gasmix,
- prefs.min_switch_duration, po2, divemode, prefs.decosac);
+ prefs.min_switch_duration, po2, divemode, prefs.decosac, true);
clock += prefs.min_switch_duration;
last_segment_min_switch = true;
}
@@ -991,7 +991,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
if (!last_segment_min_switch && get_o2(get_cylinder(dive, current_cylinder)->gasmix) != 1000) {
add_segment(ds, depth_to_bar(depth, dive),
get_cylinder(dive, current_cylinder)->gasmix,
- prefs.min_switch_duration, po2, divemode, prefs.decosac);
+ prefs.min_switch_duration, po2, divemode, prefs.decosac, true);
clock += prefs.min_switch_duration;
last_segment_min_switch = true;
}
@@ -1047,7 +1047,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
}
}
add_segment(ds, depth_to_bar(depth, dive), get_cylinder(dive, stop_cylinder)->gasmix,
- laststoptime, po2, divemode, prefs.decosac);
+ laststoptime, po2, divemode, prefs.decosac, true);
last_segment_min_switch = false;
decostoptable[decostopcounter].depth = depth;
decostoptable[decostopcounter].time = laststoptime;
diff --git a/core/profile.c b/core/profile.c
index d46db834e..19c38a4c1 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -350,7 +350,6 @@ static void check_setpoint_events(const struct dive *dive, const struct divecomp
set_setpoint(pi, i, setpoint.mbar, INT_MAX);
}
-
static void calculate_max_limits_new(const struct dive *dive, const struct divecomputer *given_dc, struct plot_info *pi, bool in_planner)
{
const struct divecomputer *dc = &(dive->dc);
@@ -908,7 +907,8 @@ static void setup_gas_sensor_pressure(const struct dive *dive, const struct dive
}
/* calculate DECO STOP / TTS / NDL */
-static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, struct plot_data *entry, struct gasmix gasmix, double surface_pressure,enum divemode_t divemode)
+static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, struct plot_data *entry, struct gasmix gasmix,
+ double surface_pressure, enum divemode_t divemode, bool in_planner)
{
/* should this be configurable? */
/* ascent speed up to first deco stop */
@@ -940,7 +940,7 @@ static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, st
) {
entry->ndl_calc += time_stepsize;
add_segment(ds, depth_to_bar(entry->depth, dive),
- gasmix, time_stepsize, entry->o2pressure.mbar, divemode, prefs.bottomsac);
+ gasmix, time_stepsize, entry->o2pressure.mbar, divemode, prefs.bottomsac, in_planner);
}
/* we don't need to calculate anything else */
return;
@@ -952,7 +952,7 @@ static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, st
/* Add segments for movement to stopdepth */
for (; ascent_depth > next_stop; ascent_depth -= ascent_s_per_step * ascent_velocity(ascent_depth, entry->running_sum / entry->sec, 0), entry->tts_calc += ascent_s_per_step) {
add_segment(ds, depth_to_bar(ascent_depth, dive),
- gasmix, ascent_s_per_step, entry->o2pressure.mbar, divemode, prefs.decosac);
+ gasmix, ascent_s_per_step, entry->o2pressure.mbar, divemode, prefs.decosac, in_planner);
next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(ascent_depth, dive)),
surface_pressure, dive, 1), deco_stepsize);
}
@@ -973,13 +973,13 @@ static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, st
if (entry->tts_calc > MAX_PROFILE_DECO)
break;
add_segment(ds, depth_to_bar(ascent_depth, dive),
- gasmix, time_stepsize, entry->o2pressure.mbar, divemode, prefs.decosac);
+ gasmix, time_stepsize, entry->o2pressure.mbar, divemode, prefs.decosac, in_planner);
if (deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(ascent_depth,dive)), surface_pressure, dive, 1) <= next_stop) {
/* move to the next stop and add the travel between stops */
for (; ascent_depth > next_stop; ascent_depth -= ascent_s_per_deco_step * ascent_velocity(ascent_depth, entry->running_sum / entry->sec, 0), entry->tts_calc += ascent_s_per_deco_step)
add_segment(ds, depth_to_bar(ascent_depth, dive),
- gasmix, ascent_s_per_deco_step, entry->o2pressure.mbar, divemode, prefs.decosac);
+ gasmix, ascent_s_per_deco_step, entry->o2pressure.mbar, divemode, prefs.decosac, in_planner);
ascent_depth = next_stop;
next_stop -= deco_stepsize;
}
@@ -995,6 +995,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
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 prev_deco_time = 10000000, time_deep_ceiling = 0;
+ bool in_planner = planner_ds != NULL;
if (!planner_ds) {
ds->deco_time = 0;
@@ -1040,7 +1041,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
for (j = t0 + time_stepsize; j <= t1; j += time_stepsize) {
int depth = interpolate(entry[-1].depth, entry[0].depth, j - t0, t1 - t0);
add_segment(ds, depth_to_bar(depth, dive),
- gasmix, time_stepsize, entry->o2pressure.mbar, current_divemode, entry->sac);
+ gasmix, time_stepsize, entry->o2pressure.mbar, current_divemode, entry->sac, in_planner);
entry->icd_warning = ds->icd_warning;
if ((t1 - j < time_stepsize) && (j < t1))
time_stepsize = t1 - j;
@@ -1140,7 +1141,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
/* We are going to mess up deco state, so store it for later restore */
struct deco_state *cache_data = NULL;
cache_deco_state(ds, &cache_data);
- calculate_ndl_tts(ds, dive, entry, gasmix, surface_pressure, current_divemode);
+ calculate_ndl_tts(ds, dive, entry, gasmix, surface_pressure, current_divemode, in_planner);
if (decoMode() == VPMB && !planner_ds && i == pi->nr - 1)
final_tts = entry->tts_calc;
/* Restore "real" deco state for next real time step */
@@ -1357,9 +1358,10 @@ void create_plot_info_new(const struct dive *dive, const struct divecomputer *dc
{
int o2, he, o2max;
struct deco_state plot_deco_state;
- init_decompression(&plot_deco_state, dive);
+ bool in_planner = planner_ds != NULL;
+ init_decompression(&plot_deco_state, dive, in_planner);
free_plot_info_data(pi);
- calculate_max_limits_new(dive, dc, pi, planner_ds != NULL);
+ calculate_max_limits_new(dive, dc, pi, in_planner);
get_dive_gas(dive, &o2, &he, &o2max);
if (dc->divemode == FREEDIVE){
pi->dive_type = FREEDIVE;