[PATCH 3/2] Remove linear pressure interpolation detection code

Linus Torvalds torvalds at linux-foundation.org
Sat Apr 2 05:39:21 PDT 2016


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sat, 2 Apr 2016 07:28:03 -0500
Subject: [PATCH 3/2] Remove linear pressure interpolation detection code

Dirk says that divinglog hasn't been doing the linear pressure
interpolation for a long while, so we're doing extra dive fixups that
really aren't needed any more.

Also, the code is actually buggy: it only ever worked on the first
cylinder anyway (because only the first cylinder pressure_delta[] would
be initialized).  That was probably perfectly fine in practice, since
it's unlikely that many tech divers used old versions of divinglog
anyway, so the bug per se isn't a reason to remove it - but it is a sign
that the code was a bit hard to read, so let's get rid of it if there is
no reason to maintain it or fix it.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This cleanup came from talking about the dive fixup patches with Dirk and 
then looking at the code and going "oh, that doesn't even work for 
anything but the first cylinder".

The initialization

-       int pressure_delta[MAX_CYLINDERS] = { INT_MAX, };

only sets the first entry to INT_MAX, the rest will be initialized to 
zero, which will mean that the whole "this might be a linear 
interpolation" only triggers for the first cylinder, despite the code 
obviously trying to do it for all of them.

 subsurface-core/dive.c | 52 ++------------------------------------------------
 1 file changed, 2 insertions(+), 50 deletions(-)

diff --git a/subsurface-core/dive.c b/subsurface-core/dive.c
index 12154704f5d8..f870d90e2a4e 100644
--- a/subsurface-core/dive.c
+++ b/subsurface-core/dive.c
@@ -1305,17 +1305,12 @@ static void fixup_dc_cylinder_index(struct dive *dive, struct divecomputer *dc)
 	}
 }
 
-/*
- * Simplify dc pressure information:
- *  (a) Remove redundant pressure information
- *  (b) Remove linearly interpolated pressure data
- */
+/* Remove redundant pressure information */
 static void simplify_dc_pressures(struct dive *dive, struct divecomputer *dc)
 {
-	int i, j;
+	int i;
 	int lastindex = -1;
 	int lastpressure = 0, lasto2pressure = 0;
-	int pressure_delta[MAX_CYLINDERS] = { INT_MAX, };
 
 	for (i = 0; i < dc->samples; i++) {
 		struct sample *sample = dc->sample + i;
@@ -1324,60 +1319,17 @@ static void simplify_dc_pressures(struct dive *dive, struct divecomputer *dc)
 		int index;
 
 		index = sample->sensor;
-
 		if (index == lastindex) {
 			/* Remove duplicate redundant pressure information */
 			if (pressure == lastpressure)
 				sample->cylinderpressure.mbar = 0;
 			if (o2_pressure == lasto2pressure)
 				sample->o2cylinderpressure.mbar = 0;
-			/* check for simply linear data in the samples
-			   +INT_MAX means uninitialized, -INT_MAX means not linear */
-			if (pressure_delta[index] != -INT_MAX && lastpressure) {
-				if (pressure_delta[index] == INT_MAX) {
-					pressure_delta[index] = abs(pressure - lastpressure);
-				} else {
-					int cur_delta = abs(pressure - lastpressure);
-					if (cur_delta && abs(cur_delta - pressure_delta[index]) > 150) {
-						/* ok the samples aren't just a linearisation
-						 * between start and end */
-						pressure_delta[index] = -INT_MAX;
-					}
-				}
-			}
 		}
 		lastindex = index;
 		lastpressure = pressure;
 		lasto2pressure = o2_pressure;
 	}
-
-	/* if all the samples for a cylinder have pressure data that
-	 * is basically equidistant throw out the sample cylinder pressure
-	 * information but make sure we still have a valid start and end
-	 * pressure
-	 * this happens when DivingLog decides to linearalize the
-	 * pressure between beginning and end and for strange reasons
-	 * decides to put that in the sample data as if it came from
-	 * the dive computer; we don't want that (we'll visualize with
-	 * constant SAC rate instead)
-	 * WARNING WARNING - I have only seen this in single tank dives
-	 * --- maybe I should try to create a multi tank dive and see what
-	 * --- divinglog does there - but the code right now is only tested
-	 * --- for the single tank case */
-	for (j = 0; j < MAX_CYLINDERS; j++) {
-		if (abs(pressure_delta[j]) != INT_MAX) {
-			cylinder_t *cyl = dive->cylinder + j;
-			for (i = 0; i < dc->samples; i++)
-				if (dc->sample[i].sensor == j)
-					dc->sample[i].cylinderpressure.mbar = 0;
-			if (!cyl->start.mbar)
-				cyl->start.mbar = cyl->sample_start.mbar;
-			if (!cyl->end.mbar)
-				cyl->end.mbar = cyl->sample_end.mbar;
-			cyl->sample_start.mbar = 0;
-			cyl->sample_end.mbar = 0;
-		}
-	}
 }
 
 /* FIXME! sensor -> cylinder mapping? */
-- 
2.8.0.rc4.303.g3931579



More information about the subsurface mailing list