summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-08 20:10:47 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-08 20:14:13 -0800
commitb8c7992bbfe03dce665cbd5ba6144b0c8b59b6fd (patch)
tree525fe8b4d2d2275ffb0c6144549dcad6c530f6b0
parent51f97a97cebbedaed102e9a3e7e694401c880526 (diff)
downloadsubsurface-b8c7992bbfe03dce665cbd5ba6144b0c8b59b6fd.tar.gz
Improve calculation of maxtemp and mintemp of dive
The existing code only populated the maxtemp based on the samples of a dive and then in statistics.c checked if there was no such temperature and replaced it with the water temperature of the first divecomputer. It makes much more sense to add the water temperature information in every divecomputer to the min / max calculation during the dive fixup phase. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c15
-rw-r--r--statistics.c12
2 files changed, 10 insertions, 17 deletions
diff --git a/dive.c b/dive.c
index 95d946025..bccf753df 100644
--- a/dive.c
+++ b/dive.c
@@ -259,13 +259,13 @@ static void fixup_pressure(struct dive *dive, struct sample *sample)
cyl->sample_end.mbar = pressure;
}
-static void update_min_max_temperatures(struct dive *dive, struct sample *sample)
+static void update_min_max_temperatures(struct dive *dive, temperature_t temperature)
{
- if (sample->temperature.mkelvin) {
- if (!dive->maxtemp.mkelvin || sample->temperature.mkelvin > dive->maxtemp.mkelvin)
- dive->maxtemp = sample->temperature;
- if (!dive->mintemp.mkelvin || sample->temperature.mkelvin < dive->mintemp.mkelvin)
- dive->mintemp = sample->temperature;
+ if (temperature.mkelvin) {
+ if (!dive->maxtemp.mkelvin || temperature.mkelvin > dive->maxtemp.mkelvin)
+ dive->maxtemp = temperature;
+ if (!dive->mintemp.mkelvin || temperature.mkelvin < dive->mintemp.mkelvin)
+ dive->mintemp = temperature;
}
}
@@ -510,6 +510,7 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
int lasttemp = 0, lastpressure = 0;
int pressure_delta[MAX_CYLINDERS] = {INT_MAX, };
+ update_min_max_temperatures(dive, dc->watertemp);
for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i;
int time = sample->time.seconds;
@@ -566,7 +567,7 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
if (!mintemp || temp < mintemp)
mintemp = temp;
}
- update_min_max_temperatures(dive, sample);
+ update_min_max_temperatures(dive, sample->temperature);
depthtime += (time - lasttime) * (lastdepth + depth) / 2;
lastdepth = depth;
diff --git a/statistics.c b/statistics.c
index d7abbc592..c08324d54 100644
--- a/statistics.c
+++ b/statistics.c
@@ -105,19 +105,11 @@ static void process_temperatures(struct dive *dp, stats_t *stats)
{
int min_temp, mean_temp, max_temp = 0;
- if (dp->maxtemp.mkelvin)
- max_temp = dp->maxtemp.mkelvin;
- else
- max_temp = dp->dc.watertemp.mkelvin;
-
+ max_temp = dp->maxtemp.mkelvin;
if (max_temp && (!stats->max_temp || max_temp > stats->max_temp))
stats->max_temp = max_temp;
- if (dp->mintemp.mkelvin)
- min_temp = dp->mintemp.mkelvin;
- else
- min_temp = dp->dc.watertemp.mkelvin;
-
+ min_temp = dp->mintemp.mkelvin;
if (min_temp && (!stats->min_temp || min_temp < stats->min_temp))
stats->min_temp = min_temp;