[PATCH] Use get_cylinder_index in per_cylinder_mean_depth

Anton Lundin glance at acc.umu.se
Wed Nov 20 10:52:17 UTC 2013


Use get_cylinder_index that handles SAMPLE_EVENT_GASCHANGE and
SAMPLE_EVENT_GASCHANGE2.

This also removes the need for a special case where get_gasidx returns
-1, because get_cylinder_index always returns the "closest" gas that it
finds.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 dive.c    | 6 +-----
 dive.h    | 1 +
 profile.c | 2 +-
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/dive.c b/dive.c
index 269aeb6..8ce1c95 100644
--- a/dive.c
+++ b/dive.c
@@ -361,11 +361,7 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
 		int time = sample->time.seconds;
 		int depth = sample->depth.mm;
 		if (ev && time >= ev->time.seconds) {
-			int o2 = (ev->value & 0xFFFF) * 10;
-			int he = (ev->value >> 16) * 10;
-			int tank = get_gasidx(dive, o2, he);
-			if (tank >= 0)
-				idx = tank; // should never happen unless the input file is inconsistent
+			idx = get_cylinder_index(dive, ev);
 			ev = get_next_event(ev->next, "gaschange");
 		}
 		/* We ignore segments at the surface */
diff --git a/dive.h b/dive.h
index 9523a47..fed932c 100644
--- a/dive.h
+++ b/dive.h
@@ -662,6 +662,7 @@ extern void fill_default_cylinder(cylinder_t *cyl);
 extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
 extern void add_event(struct divecomputer *dc, int time, int type, int flags, int value, const char *name);
 extern void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *mean, int *duration);
+extern int get_cylinder_index(struct dive *dive, struct event *ev);
 
 /* UI related protopypes */
 
diff --git a/profile.c b/profile.c
index c0520bc..0f90370 100644
--- a/profile.c
+++ b/profile.c
@@ -553,7 +553,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
 	}
 }
 
-static int get_cylinder_index(struct dive *dive, struct event *ev)
+int get_cylinder_index(struct dive *dive, struct event *ev)
 {
 	int i;
 	int best = 0, score = INT_MAX;
-- 
1.8.3.2



More information about the subsurface mailing list