summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.c26
-rw-r--r--dive.h1
-rw-r--r--parse-xml.c2
-rw-r--r--save-xml.c17
-rw-r--r--statistics.c7
5 files changed, 50 insertions, 3 deletions
diff --git a/dive.c b/dive.c
index e337ca319..35f1c3f46 100644
--- a/dive.c
+++ b/dive.c
@@ -484,11 +484,13 @@ static void fixup_watertemp(struct dive *dive)
dive->watertemp.mkelvin = (sum + nr / 2) / nr;
}
-static void fixup_airtemp(struct dive *dive)
+void fixup_airtemp(struct dive *dive)
{
struct divecomputer *dc;
int sum = 0, nr = 0;
+ if (dive->airtemp.mkelvin)
+ return;
for_each_dc(dive, dc) {
if (dc->airtemp.mkelvin) {
sum += dc->airtemp.mkelvin;
@@ -499,6 +501,20 @@ static void fixup_airtemp(struct dive *dive)
dive->airtemp.mkelvin = (sum + nr / 2) / nr;
}
+/* zero out the airtemp in the dive structure if it was just created by
+ * running fixup on the dive. keep it if it had been edited by hand */
+static void un_fixup_airtemp(struct dive *a)
+{
+ temperature_t temp;
+ temp.mkelvin = a->airtemp.mkelvin;
+ a->airtemp.mkelvin = 0;
+ fixup_airtemp(a);
+ if (a->airtemp.mkelvin && a->airtemp.mkelvin != temp.mkelvin)
+ a->airtemp.mkelvin = temp.mkelvin;
+ else
+ a->airtemp.mkelvin = 0;
+}
+
/*
* events are stored as a linked list, so the concept of
* "consecutive, identical events" is somewhat hard to
@@ -983,6 +999,13 @@ static void merge_equipment(struct dive *res, struct dive *a, struct dive *b)
merge_weightsystem_info(res->weightsystem+i, a->weightsystem + i, b->weightsystem + i);
}
+static void merge_airtemps(struct dive *res, struct dive *a, struct dive *b)
+{
+ un_fixup_airtemp(a);
+ un_fixup_airtemp(b);
+ MERGE_NONZERO(res, a, b, airtemp.mkelvin);
+}
+
/*
* When merging two dives, this picks the trip from one, and removes it
* from the other.
@@ -1616,6 +1639,7 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
MERGE_NONZERO(res, a, b, cns);
MERGE_NONZERO(res, a, b, visibility);
merge_equipment(res, a, b);
+ merge_airtemps(res, a, b);
if (dl) {
/* If we prefer downloaded, do those first, and get rid of "might be same" computers */
join_dive_computers(&res->dc, &dl->dc, &a->dc, 1);
diff --git a/dive.h b/dive.h
index 35becba07..fdeac977a 100644
--- a/dive.h
+++ b/dive.h
@@ -561,6 +561,7 @@ extern void finish_sample(struct divecomputer *dc);
extern void sort_table(struct dive_table *table);
extern void report_dives(gboolean imported, gboolean prefer_imported);
extern struct dive *fixup_dive(struct dive *dive);
+extern void fixup_airtemp(struct dive *dive);
extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean prefer_downloaded);
extern struct dive *try_to_merge(struct dive *a, struct dive *b, gboolean prefer_downloaded);
extern void renumber_dives(int nr);
diff --git a/parse-xml.c b/parse-xml.c
index 9c9e2abbc..5ae27c811 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1011,6 +1011,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
return;
if (MATCH(".he", gasmix, &dive->cylinder[cur_cylinder_index].gasmix.he))
return;
+ if (MATCH(".divetemperature.air", temperature, &dive->airtemp))
+ return;
nonmatch("dive", name, buf);
}
diff --git a/save-xml.c b/save-xml.c
index 22059a178..c0af41c4c 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -150,6 +150,21 @@ static void save_depths(FILE *f, struct divecomputer *dc)
fputs(" />\n", f);
}
+static void save_dive_temperature(FILE *f, struct dive *dive)
+{
+ temperature_t temp;
+ temp.mkelvin = dive->airtemp.mkelvin;
+ dive->airtemp.mkelvin = 0;
+ fixup_airtemp(dive);
+ if (dive->airtemp.mkelvin && temp.mkelvin != dive->airtemp.mkelvin) {
+ fputs(" <divetemperature", f);
+ show_temperature(f, temp, " air='", "'");
+ fputs(" />\n", f);
+ }
+ dive->airtemp.mkelvin = temp.mkelvin;
+
+}
+
static void save_temperatures(FILE *f, struct divecomputer *dc)
{
if (!dc->airtemp.mkelvin && !dc->watertemp.mkelvin)
@@ -448,7 +463,7 @@ void save_dive(FILE *f, struct dive *dive)
save_overview(f, dive);
save_cylinder_info(f, dive);
save_weightsystem_info(f, dive);
-
+ save_dive_temperature(f, dive);
/* Save the dive computer data */
dc = &dive->dc;
do {
diff --git a/statistics.c b/statistics.c
index d87353b7f..fdea8bdba 100644
--- a/statistics.c
+++ b/statistics.c
@@ -574,7 +574,12 @@ static void show_single_dive_stats(struct dive *dive)
value = get_temp_units(dc->airtemp.mkelvin, &unit);
set_label(single_w.air_temp, "%.1f %s", value, unit);
} else {
- set_label(single_w.air_temp, "");
+ if (dive->airtemp.mkelvin) {
+ value = get_temp_units(dive->airtemp.mkelvin, &unit);
+ set_label(single_w.air_temp, "%.1f %s", value, unit);
+ } else {
+ set_label(single_w.air_temp, "");
+ }
}
mbar = dc->surface_pressure.mbar;
/* it would be easy to get dive data here: