summaryrefslogtreecommitdiffstats
path: root/core/profile.c
diff options
context:
space:
mode:
authorGravatar Willem Ferguson <willemferguson@zoology.up.ac.za>2018-04-07 17:52:16 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-05-14 23:47:00 +0300
commitcad4eb39c4ac0a46dbaab6932e9319704eb90e6d (patch)
treec9b1ff2298a5b4ec9684ee5b338f1e7110a66b12 /core/profile.c
parentb9174332d562b8b9c436a94880c51acf2c5ab761 (diff)
downloadsubsurface-cad4eb39c4ac0a46dbaab6932e9319704eb90e6d.tar.gz
Implement get_divemode() to find the divemode at a particular time
Replaced a rather cumbersome function that that did the above. Upon the suggestion of Robert Helling who proposed a much shorter way, this new function replaced the previous ones. This necessitated changes to divelist.c, profile.c and plannernotes.c, as well as dive.c/h. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Diffstat (limited to 'core/profile.c')
-rw-r--r--core/profile.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/core/profile.c b/core/profile.c
index 789727635..be20c7ac7 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -996,7 +996,6 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne
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;
- enum dive_comp_type current_divemode;
if (!in_planner()) {
ds->deco_time = 0;
@@ -1018,16 +1017,16 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne
if (decoMode() == VPMB)
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
struct gasmix *gasmix = NULL;
- struct event *ev = NULL, *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc, TRUE);
+ struct event *ev = NULL, *evd = NULL;
+ enum dive_comp_type current_divemode = UNDEF_COMP_TYPE;
for (i = 1; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
int j, t0 = (entry - 1)->sec, t1 = entry->sec;
int time_stepsize = 20;
- current_divemode = get_divemode_at_time(dc, entry->sec, &ev_dmt);
+ current_divemode = get_current_divemode(dc, entry->sec, &evd, &current_divemode);
gasmix = get_gasmix(dive, dc, t1, &ev, gasmix);
-
entry->ambpressure = depth_to_bar(entry->depth, dive);
entry->gfline = get_gf(ds, entry->ambpressure, dive) * (100.0 - AMB_PERCENTAGE) + AMB_PERCENTAGE;
if (t0 > t1) {
@@ -1205,24 +1204,18 @@ static int calculate_ccr_po2(struct plot_data *entry, struct divecomputer *dc)
static void calculate_gas_information_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
int i;
- enum dive_comp_type current_divemode;
double amb_pressure;
struct gasmix *gasmix = NULL;
- struct event *nextev, *evg = NULL, *evd = dc->events;
-
- current_divemode = dc->divemode;
- nextev = get_next_divemodechange(&evd, TRUE);
+ struct event *evg = NULL, *evd = NULL;
+ enum dive_comp_type current_divemode = UNDEF_COMP_TYPE;
for (i = 1; i < pi->nr; i++) {
int fn2, fhe;
struct plot_data *entry = pi->entry + i;
gasmix = get_gasmix(dive, dc, entry->sec, &evg, gasmix);
- if (nextev && (entry->sec > nextev->time.seconds)) { // If there are divemode changes and sample time
- current_divemode = nextev->divemode; // has reached that of the current divemode event, then set the
- nextev = get_next_divemodechange(&evd, TRUE); // current divemode and find the next divemode event
- }
amb_pressure = depth_to_bar(entry->depth, dive);
+ current_divemode = get_current_divemode(dc, entry->sec, &evd, &current_divemode);
fill_pressures(&entry->pressures, amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry->o2pressure.mbar / 1000.0, current_divemode);
fn2 = (int)(1000.0 * entry->pressures.n2 / amb_pressure);
fhe = (int)(1000.0 * entry->pressures.he / amb_pressure);