[PATCH] Only calculate with he when he is present in event

Anton Lundin glance at acc.umu.se
Mon Sep 16 23:25:47 UTC 2013


Old gasswitch events only contains O2, so don't look at he part when
there is no he in the event.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 profile.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/profile.c b/profile.c
index eb6be2c..e0e9bad 100644
--- a/profile.c
+++ b/profile.c
@@ -646,7 +646,14 @@ static int get_cylinder_index(struct dive *dive, struct event *ev)
 
 		delta_o2 = get_o2(&cyl->gasmix) - target_o2;
 		delta_he = get_he(&cyl->gasmix) - target_he;
-		distance = delta_o2 * delta_o2 + delta_he * delta_he;
+		distance = delta_o2 * delta_o2;
+
+		/* If we don't have he in the gas-change event,
+		 * its probably a old gas-change event that only contains o2,
+		 * so don't compare the he-part when looking for the right gas.
+		 */
+		if (target_he != 0)
+			distance += delta_he * delta_he;
 		if (distance >= score)
 			continue;
 		score = distance;
-- 
1.8.1.2



More information about the subsurface mailing list