[PATCH] Consider the first temperature sample as air temp

Alexandre Belloni alexandre.belloni at piout.net
Tue Nov 8 23:31:03 PST 2011


The first temperature reading is considered as the air temperature
before the dive.

It doesn't handle the case where only one reading is made and it is
actually the water temperature. Is that the case on any supported
divecomputer ?

Signed-off-by: Alexandre Belloni <alexandre.belloni at piout.net>
---
 dive.c |   39 +++++++++++++++++++++++++++------------
 1 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/dive.c b/dive.c
index cb94e79..8c6a0a5 100644
--- a/dive.c
+++ b/dive.c
@@ -255,7 +255,7 @@ struct dive *fixup_dive(struct dive *dive)
 	double depthtime = 0;
 	int lasttime = 0;
 	int start = -1, end = -1;
-	int maxdepth = 0, mintemp = 0;
+	int maxdepth = 0, mintemp = 0, airtemp = 0;
 	int lastdepth = 0;
 	int lasttemp = 0;
 	unsigned long flags = 0;
@@ -279,18 +279,26 @@ struct dive *fixup_dive(struct dive *dive)
 		flags = fixup_pressure(dive, sample, flags);
 
 		if (temp) {
-			/*
-			 * If we have consecutive identical
-			 * temperature readings, throw away
-			 * the redundant ones.
+			/* Consider the first temperature as
+			 * the air temperature
 			 */
-			if (lasttemp == temp)
-				sample->temperature.mkelvin = 0;
-			else
-				lasttemp = temp;
-
-			if (!mintemp || temp < mintemp)
-				mintemp = temp;
+			if (!airtemp)
+			{
+				airtemp = temp;
+			} else {
+				/*
+				 * If we have consecutive identical
+				 * temperature readings, throw away
+				 * the redundant ones.
+				 */
+				if (lasttemp == temp)
+					sample->temperature.mkelvin = 0;
+				else
+					lasttemp = temp;
+
+				if (!mintemp || temp < mintemp)
+					mintemp = temp;
+			}
 		}
 		depthtime += (time - lasttime) * (lastdepth + depth) / 2;
 		lastdepth = depth;
@@ -299,12 +307,19 @@ struct dive *fixup_dive(struct dive *dive)
 	if (end < 0)
 		return dive;
 
+	/* It could happen that we had only one temperature reading
+	 * Redundants ones may have been thrown away before
+	 */
+	if (!mintemp && airtemp)
+		mintemp = airtemp;
+
 	update_duration(&dive->duration, end - start);
 	if (start != end)
 		depthtime /= (end - start);
 
 	update_depth(&dive->meandepth, depthtime);
 	update_temperature(&dive->watertemp, mintemp);
+	update_temperature(&dive->airtemp, airtemp);
 	update_depth(&dive->maxdepth, maxdepth);
 
 	add_people(dive->buddy);
-- 
1.7.4.1



More information about the subsurface mailing list