[PATCH 2/3] ToolTipItem: show gf line based on correct gradient factor preferences

Rick Walsh rickmwalsh at gmail.com
Tue Oct 25 22:21:47 PDT 2016


Calculate gfline using the gradient factor that is set by the planner
preferences when in the planner, and by the general prefs when not in the
planner. This is achieved by doing the gradient factor calculation in dive.c,
where buehlmann_config is defined.

Previously, the gfline was calculated using the general preferences gfhigh and
gflow, even when in the planner.

Signed-off-by: Rick Walsh <rickmwalsh at gmail.com>
---
 core/deco.c    | 14 ++++++++++++++
 core/deco.h    |  2 ++
 core/profile.c |  5 +----
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/core/deco.c b/core/deco.c
index 09426bd..b138a9f 100644
--- a/core/deco.c
+++ b/core/deco.c
@@ -618,3 +618,17 @@ void set_vpmb_conservatism(short conservatism)
 	else
 		vpmb_config.conservatism = conservatism;
 }
+
+double get_gf(double ambpressure_bar, const struct dive *dive)
+{
+	double surface_pressure_bar = get_surface_pressure_in_mbar(dive, true) / 1000.0;
+	double gf_low = buehlmann_config.gf_low;
+	double gf_high = buehlmann_config.gf_high;
+	double gf;
+	if (gf_low_pressure_this_dive > surface_pressure_bar)
+		gf = MAX((double)gf_low, (ambpressure_bar - surface_pressure_bar) /
+			(gf_low_pressure_this_dive - surface_pressure_bar) * (gf_low - gf_high) + gf_high);
+	else
+		gf = gf_low;
+	return gf;
+}
diff --git a/core/deco.h b/core/deco.h
index fd3b94a..bfedd60 100644
--- a/core/deco.h
+++ b/core/deco.h
@@ -13,6 +13,8 @@ extern double gf_low_pressure_this_dive;
 
 extern int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct dive *dive, bool smooth);
 
+double get_gf(double ambpressure_bar, const struct dive *dive);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/core/profile.c b/core/profile.c
index 935f95e..abe1757 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -962,10 +962,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
 			int time_stepsize = 20;
 
 			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) *
-						(100.0 - AMB_PERCENTAGE) / 100.0 + AMB_PERCENTAGE;
+			entry->gfline = get_gf(entry->ambpressure, dive) * (100.0 - AMB_PERCENTAGE) + AMB_PERCENTAGE;
 			if (t0 > t1) {
 				fprintf(stderr, "non-monotonous dive stamps %d %d\n", t0, t1);
 				int xchg = t1;
-- 
2.7.4



More information about the subsurface mailing list