summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2015-08-31 23:39:43 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-08-31 15:18:40 -0700
commite32896c2bc85a11c2eacc35c0267c2fa90d73b59 (patch)
treeca2fe52426f10e38311c9f083a1458d8fd3b213a
parentbd8126a709f81631f949c374f4236861b519ea48 (diff)
downloadsubsurface-e32896c2bc85a11c2eacc35c0267c2fa90d73b59.tar.gz
Introduce double depth_to_bar()
as it leads to significant cleanup. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h5
-rw-r--r--divelist.c2
-rw-r--r--planner.c24
-rw-r--r--profile.c24
4 files changed, 30 insertions, 25 deletions
diff --git a/dive.h b/dive.h
index 108e5d1ca..eac6e724d 100644
--- a/dive.h
+++ b/dive.h
@@ -419,6 +419,11 @@ static inline int depth_to_mbar(int depth, struct dive *dive)
return calculate_depth_to_mbar(depth, dive->surface_pressure, dive->salinity);
}
+static inline double depth_to_bar(int depth, struct dive *dive)
+{
+ return depth_to_mbar(depth, dive) / 1000.0;
+}
+
static inline double depth_to_atm(int depth, struct dive *dive)
{
return mbar_to_atm(depth_to_mbar(depth, dive));
diff --git a/divelist.c b/divelist.c
index d9a3e2a7b..3cbff84ef 100644
--- a/divelist.c
+++ b/divelist.c
@@ -323,7 +323,7 @@ static void add_dive_to_deco(struct dive *dive)
for (j = t0; j < t1; j++) {
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
- (void)add_segment(depth_to_mbar(depth, dive) / 1000.0,
+ add_segment(depth_to_bar(depth, dive),
&dive->cylinder[sample->sensor].gasmix, 1, sample->setpoint.mbar, dive, dive->sac);
}
}
diff --git a/planner.c b/planner.c
index 6abe8ec4a..e0f889ec4 100644
--- a/planner.c
+++ b/planner.c
@@ -107,10 +107,10 @@ void interpolate_transition(struct dive *dive, duration_t t0, duration_t t1, dep
for (j = t0.seconds; j < t1.seconds; j++) {
int depth = interpolate(d0.mm, d1.mm, j - t0.seconds, t1.seconds - t0.seconds);
- add_segment(depth_to_mbar(depth, dive) / 1000.0, gasmix, 1, po2.mbar, dive, prefs.bottomsac);
+ add_segment(depth_to_bar(depth, dive), gasmix, 1, po2.mbar, dive, prefs.bottomsac);
}
if (d1.mm > d0.mm)
- calc_crushing_pressure(depth_to_mbar(d1.mm, &displayed_dive) / 1000.0);
+ calc_crushing_pressure(depth_to_bar(d1.mm, &displayed_dive));
}
/* returns the tissue tolerance at the end of this (partial) dive */
@@ -875,7 +875,7 @@ bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time
// deeper than the next stop (thus the offgasing during the ascent is ignored).
// However, we still need to make sure we don't break the ceiling due to on-gassing during ascent.
if (prefs.deco_mode == VPMB && (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive,
- depth_to_mbar(stoplevel, &displayed_dive)),
+ depth_to_bar(stoplevel, &displayed_dive)),
surface_pressure, &displayed_dive, 1) > stoplevel))
return false;
@@ -884,10 +884,10 @@ bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time
int deltad = ascent_velocity(trial_depth, avg_depth, bottom_time) * TIMESTEP;
if (deltad > trial_depth) /* don't test against depth above surface */
deltad = trial_depth;
- add_segment(depth_to_mbar(trial_depth, &displayed_dive) / 1000.0,
+ add_segment(depth_to_bar(trial_depth, &displayed_dive),
gasmix,
TIMESTEP, po2, &displayed_dive, prefs.decosac);
- if (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive, depth_to_mbar(trial_depth, &displayed_dive) / 1000.0),
+ if (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive, depth_to_bar(trial_depth, &displayed_dive)),
surface_pressure, &displayed_dive, 1) > trial_depth - deltad) {
/* We should have stopped */
clear_to_ascend = false;
@@ -1039,7 +1039,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
while (trial_ascent(depth, 0, avg_depth, bottom_time, &displayed_dive.cylinder[current_cylinder].gasmix,
po2, diveplan->surface_pressure / 1000.0) &&
enough_gas(current_cylinder)) {
- add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
+ add_segment(depth_to_bar(depth, &displayed_dive),
&displayed_dive.cylinder[current_cylinder].gasmix,
DECOTIMESTEP, po2, &displayed_dive, prefs.bottomsac);
update_cylinder_pressure(&displayed_dive, depth, depth, DECOTIMESTEP, prefs.bottomsac, &displayed_dive.cylinder[current_cylinder], false);
@@ -1059,7 +1059,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
if (depth - deltad < 0)
deltad = depth;
- add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
+ add_segment(depth_to_bar(depth, &displayed_dive),
&displayed_dive.cylinder[current_cylinder].gasmix,
TIMESTEP, po2, &displayed_dive, prefs.decosac);
clock += TIMESTEP;
@@ -1125,7 +1125,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
breakcylinder = 0;
o2time = 0;
first_ceiling_pressure.mbar = depth_to_mbar(deco_allowed_depth(tissue_tolerance_calc(&displayed_dive,
- depth_to_mbar(depth, &displayed_dive) / 1000.0),
+ depth_to_bar(depth, &displayed_dive)),
diveplan->surface_pressure / 1000.0,
&displayed_dive,
1),
@@ -1152,7 +1152,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
if (depth - deltad < stoplevels[stopidx])
deltad = depth - stoplevels[stopidx];
- add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
+ add_segment(depth_to_bar(depth, &displayed_dive),
&displayed_dive.cylinder[current_cylinder].gasmix,
TIMESTEP, po2, &displayed_dive, prefs.decosac);
clock += TIMESTEP;
@@ -1186,7 +1186,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi].depth / 1000.0);
#endif
/* Stop for the minimum duration to switch gas */
- add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
+ add_segment(depth_to_bar(depth, &displayed_dive),
&displayed_dive.cylinder[current_cylinder].gasmix,
prefs.min_switch_duration, po2, &displayed_dive, prefs.decosac);
clock += prefs.min_switch_duration;
@@ -1232,7 +1232,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi + 1].depth / 1000.0);
#endif
/* Stop for the minimum duration to switch gas */
- add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
+ add_segment(depth_to_bar(depth, &displayed_dive),
&displayed_dive.cylinder[current_cylinder].gasmix,
prefs.min_switch_duration, po2, &displayed_dive, prefs.decosac);
clock += prefs.min_switch_duration;
@@ -1245,7 +1245,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
int this_decotimestep;
this_decotimestep = DECOTIMESTEP - clock % DECOTIMESTEP;
- add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
+ add_segment(depth_to_bar(depth, &displayed_dive),
&displayed_dive.cylinder[current_cylinder].gasmix,
this_decotimestep, po2, &displayed_dive, prefs.decosac);
clock += this_decotimestep;
diff --git a/profile.c b/profile.c
index 04ec35c4b..158517e2d 100644
--- a/profile.c
+++ b/profile.c
@@ -771,7 +771,7 @@ static void calculate_ndl_tts(struct plot_data *entry, struct dive *dive, double
const int time_stepsize = 60;
const int deco_stepsize = 3000;
/* at what depth is the current deco-step? */
- int next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_mbar(entry->depth, dive) / 1000.0),
+ int next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)),
surface_pressure, dive, 1), deco_stepsize);
int ascent_depth = entry->depth;
/* at what time should we give up and say that we got enuff NDL? */
@@ -786,9 +786,9 @@ static void calculate_ndl_tts(struct plot_data *entry, struct dive *dive, double
return;
}
/* stop if the ndl is above max_ndl seconds, and call it plenty of time */
- while (entry->ndl_calc < max_ndl && deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_mbar(entry->depth, dive) / 1000.0), surface_pressure, dive, 1) <= 0) {
+ while (entry->ndl_calc < max_ndl && deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, 1) <= 0) {
entry->ndl_calc += time_stepsize;
- add_segment(depth_to_mbar(entry->depth, dive) / 1000.0,
+ add_segment(depth_to_bar(entry->depth, dive),
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->o2pressure.mbar, dive, prefs.bottomsac);
}
/* we don't need to calculate anything else */
@@ -800,9 +800,9 @@ static void calculate_ndl_tts(struct plot_data *entry, struct dive *dive, double
/* Add segments for movement to stopdepth */
for (; ascent_depth > next_stop; ascent_depth -= ascent_mm_per_step, entry->tts_calc += ascent_s_per_step) {
- add_segment(depth_to_mbar(ascent_depth, dive) / 1000.0,
+ add_segment(depth_to_bar(ascent_depth, dive),
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_step, entry->o2pressure.mbar, dive, prefs.decosac);
- next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_mbar(ascent_depth, dive) / 1000.0), surface_pressure, dive, 1), deco_stepsize);
+ next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(ascent_depth, dive)), surface_pressure, dive, 1), deco_stepsize);
}
ascent_depth = next_stop;
@@ -818,13 +818,13 @@ static void calculate_ndl_tts(struct plot_data *entry, struct dive *dive, double
entry->stoptime_calc += time_stepsize;
entry->tts_calc += time_stepsize;
- add_segment(depth_to_mbar(ascent_depth, dive) / 1000.0,
+ add_segment(depth_to_bar(ascent_depth, dive),
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->o2pressure.mbar, dive, prefs.decosac);
- if (deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_mbar(ascent_depth,dive) / 1000.0), surface_pressure, dive, 1) <= next_stop) {
+ if (deco_allowed_depth(tissue_tolerance_calc(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_mm_per_deco_step, entry->tts_calc += ascent_s_per_deco_step)
- add_segment(depth_to_mbar(ascent_depth, dive) / 1000.0,
+ add_segment(depth_to_bar(ascent_depth, dive),
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_deco_step, entry->o2pressure.mbar, dive, prefs.decosac);
ascent_depth = next_stop;
next_stop -= deco_stepsize;
@@ -844,7 +844,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
int j, t0 = (entry - 1)->sec, t1 = entry->sec;
int time_stepsize = 20;
- entry->ambpressure = (double)depth_to_mbar(entry->depth, dive) / 1000.0;
+ entry->ambpressure = depth_to_bar(entry->depth, dive);
entry->gfline = MAX((double)prefs.gflow, (entry->ambpressure - surface_pressure) / (gf_low_pressure_this_dive - surface_pressure) *
(prefs.gflow - prefs.gfhigh) +
prefs.gfhigh) *
@@ -853,7 +853,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
time_stepsize = t1 - t0;
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(depth_to_mbar(depth, dive) / 1000.0,
+ add_segment(depth_to_bar(depth, dive),
&dive->cylinder[entry->cylinderindex].gasmix, time_stepsize, entry->o2pressure.mbar, dive, entry->sac);
if ((t1 - j < time_stepsize) && (j < t1))
time_stepsize = t1 - j;
@@ -861,7 +861,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
if (t0 == t1)
entry->ceiling = (entry - 1)->ceiling;
else
- entry->ceiling = deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_mbar(entry->depth, dive) / 1000.0), surface_pressure, dive, !prefs.calcceiling3m);
+ entry->ceiling = deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, !prefs.calcceiling3m);
for (j = 0; j < 16; j++) {
double m_value = buehlmann_inertgas_a[j] + entry->ambpressure / buehlmann_inertgas_b[j];
entry->ceilings[j] = deco_allowed_depth(tolerated_by_tissue[j], surface_pressure, dive, 1);
@@ -952,7 +952,7 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
struct plot_data *entry = pi->entry + i;
int cylinderindex = entry->cylinderindex;
- amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0;
+ amb_pressure = depth_to_bar(entry->depth, dive);
fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->o2pressure.mbar / 1000.0, dive->dc.divemode);
fn2 = (int)(1000.0 * entry->pressures.n2 / amb_pressure);