summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.c33
-rw-r--r--dive.h2
-rw-r--r--divelist.c16
-rw-r--r--file.c8
-rw-r--r--info.c8
-rw-r--r--main.c4
6 files changed, 52 insertions, 19 deletions
diff --git a/dive.c b/dive.c
index d66c30826..7db239584 100644
--- a/dive.c
+++ b/dive.c
@@ -469,6 +469,36 @@ static void fixup_duration(struct dive *dive)
dive->duration.seconds = duration;
}
+static void fixup_watertemp(struct dive *dive)
+{
+ struct divecomputer *dc;
+ int sum = 0, nr = 0;
+
+ for_each_dc(dive, dc) {
+ if (dc->watertemp.mkelvin) {
+ sum += dc->watertemp.mkelvin;
+ nr++;
+ }
+ }
+ if (nr)
+ dive->watertemp.mkelvin = (sum + nr / 2) / nr;
+}
+
+static void fixup_airtemp(struct dive *dive)
+{
+ struct divecomputer *dc;
+ int sum = 0, nr = 0;
+
+ for_each_dc(dive, dc) {
+ if (dc->airtemp.mkelvin) {
+ sum += dc->airtemp.mkelvin;
+ nr++;
+ }
+ }
+ if (nr)
+ dive->airtemp.mkelvin = (sum + nr / 2) / nr;
+}
+
/*
* events are stored as a linked list, so the concept of
* "consecutive, identical events" is somewhat hard to
@@ -662,6 +692,8 @@ struct dive *fixup_dive(struct dive *dive)
fixup_surface_pressure(dive);
fixup_meandepth(dive);
fixup_duration(dive);
+ fixup_watertemp(dive);
+ fixup_airtemp(dive);
for_each_dc(dive, dc)
fixup_dive_dc(dive, dc);
@@ -1580,7 +1612,6 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
MERGE_MAX(res, a, b, rating);
MERGE_TXT(res, a, b, suit);
MERGE_MAX(res, a, b, number);
- res->dc.meandepth.mm = 0;
MERGE_NONZERO(res, a, b, cns);
MERGE_NONZERO(res, a, b, visibility);
merge_equipment(res, a, b);
diff --git a/dive.h b/dive.h
index ace1c9fc2..84133a424 100644
--- a/dive.h
+++ b/dive.h
@@ -320,7 +320,7 @@ struct dive {
int sac, otu, cns, maxcns;
/* Calculated based on dive computer data */
- temperature_t mintemp, maxtemp;
+ temperature_t mintemp, maxtemp, watertemp, airtemp;
depth_t maxdepth, meandepth;
pressure_t surface_pressure;
duration_t duration;
diff --git a/divelist.c b/divelist.c
index 70a99f9c6..03e0287d3 100644
--- a/divelist.c
+++ b/divelist.c
@@ -720,7 +720,7 @@ static int calculate_sac(struct dive *dive)
}
}
/* Mean pressure in bar (SAC calculations are in bar*l/min) */
- pressure = depth_to_mbar(dive->dc.meandepth.mm, dive) / 1000.0;
+ pressure = depth_to_mbar(dc->meandepth.mm, dive) / 1000.0;
sac = airuse / pressure * 60 / duration;
/* milliliters per minute.. */
@@ -735,7 +735,7 @@ static void add_dive_to_deco(struct dive *dive)
if (!dc)
return;
- for (i = 1; i < dive->dc.samples; i++) {
+ for (i = 1; i < dc->samples; i++) {
struct sample *psample = dc->sample + i - 1;
struct sample *sample = dc->sample + i;
int t0 = psample->time.seconds;
@@ -1322,7 +1322,7 @@ static void fill_dive_list(void)
DIVE_LOCATION, dive->location,
DIVE_LOC_ICON, icon,
DIVE_RATING, dive->rating,
- DIVE_TEMPERATURE, dive->dc.watertemp.mkelvin,
+ DIVE_TEMPERATURE, dive->watertemp.mkelvin,
DIVE_SAC, 0,
-1);
gtk_tree_store_append(liststore, &iter, NULL);
@@ -1335,7 +1335,7 @@ static void fill_dive_list(void)
DIVE_LOCATION, dive->location,
DIVE_LOC_ICON, icon,
DIVE_RATING, dive->rating,
- DIVE_TEMPERATURE, dive->dc.watertemp.mkelvin,
+ DIVE_TEMPERATURE, dive->watertemp.mkelvin,
DIVE_TOTALWEIGHT, 0,
DIVE_SUIT, dive->suit,
DIVE_SAC, 0,
@@ -1674,8 +1674,8 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
DIVE_DATE, &store_dive.when,
DIVE_RATING, &store_dive.rating,
DIVE_DEPTH, &store_dive.maxdepth,
- DIVE_DURATION, &store_dive.dc.duration,
- DIVE_TEMPERATURE, &store_dive.dc.watertemp.mkelvin,
+ DIVE_DURATION, &store_dive.duration,
+ DIVE_TEMPERATURE, &store_dive.watertemp.mkelvin,
DIVE_TOTALWEIGHT, &totalweight,
DIVE_SUIT, &store_dive.suit,
DIVE_CYLINDER, &cylinder_text,
@@ -1691,8 +1691,8 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
DIVE_DATE, store_dive.when,
DIVE_RATING, store_dive.rating,
DIVE_DEPTH, store_dive.maxdepth,
- DIVE_DURATION, store_dive.dc.duration,
- DIVE_TEMPERATURE, store_dive.dc.watertemp.mkelvin,
+ DIVE_DURATION, store_dive.duration,
+ DIVE_TEMPERATURE, store_dive.watertemp.mkelvin,
DIVE_TOTALWEIGHT, totalweight,
DIVE_SUIT, store_dive.suit,
DIVE_CYLINDER, cylinder_text,
diff --git a/file.c b/file.c
index 3ca5f93cb..cdad961e5 100644
--- a/file.c
+++ b/file.c
@@ -174,6 +174,7 @@ static int try_to_open_csv(const char *filename, struct memblock *mem, enum csv_
int i, time;
timestamp_t date;
struct dive *dive;
+ struct divecomputer *dc;
for (i = 0; i < 8; i++) {
header[i] = p;
@@ -190,6 +191,7 @@ static int try_to_open_csv(const char *filename, struct memblock *mem, enum csv_
dive = alloc_dive();
dive->when = date;
dive->number = atoi(header[1]);
+ dc = &dive->dc;
time = 0;
for (;;) {
@@ -204,13 +206,13 @@ static int try_to_open_csv(const char *filename, struct memblock *mem, enum csv_
if (errno)
break;
- sample = prepare_sample(&dive->dc);
+ sample = prepare_sample(dc);
sample->time.seconds = time;
add_sample_data(sample, type, val);
- finish_sample(&dive->dc);
+ finish_sample(dc);
time++;
- dive->dc.duration.seconds = time;
+ dc->duration.seconds = time;
if (*end != ',')
break;
p = end+1;
diff --git a/info.c b/info.c
index 47cca5621..b411ed56d 100644
--- a/info.c
+++ b/info.c
@@ -593,8 +593,8 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc
default:
mkelvin = 0;
}
- if (mkelvin != dive->dc.airtemp.mkelvin && dive->dc.airtemp.mkelvin == master->dc.airtemp.mkelvin) {
- dive->dc.airtemp.mkelvin = mkelvin;
+ if (mkelvin != dive->airtemp.mkelvin && dive->airtemp.mkelvin == master->airtemp.mkelvin) {
+ dive->airtemp.mkelvin = mkelvin;
changed = 1;
}
}
@@ -808,9 +808,9 @@ static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info
info->viz = text_entry(hbox, _("Visibility"), star_list, star_strings[dive->visibility]);
- value = get_temp_units(dive->dc.airtemp.mkelvin, &unit);
+ value = get_temp_units(dive->airtemp.mkelvin, &unit);
snprintf(buffer, sizeof(buffer), _("Air Temp in %s"), unit);
- if (dive->dc.airtemp.mkelvin)
+ if (dive->airtemp.mkelvin)
snprintf(airtemp, sizeof(airtemp), "%.1f", value);
else
airtemp[0] = '\0';
diff --git a/main.c b/main.c
index 170481035..a22524f29 100644
--- a/main.c
+++ b/main.c
@@ -172,8 +172,8 @@ void report_dives(gboolean is_imported, gboolean prefer_imported)
/* only try to merge overlapping dives - or if one of the dives has
* zero duration (that might be a gps marker from the webservice) */
- if (prev->dc.duration.seconds && dive->dc.duration.seconds &&
- prev->when + prev->dc.duration.seconds < dive->when)
+ if (prev->duration.seconds && dive->duration.seconds &&
+ prev->when + prev->duration.seconds < dive->when)
continue;
merged = try_to_merge(prev, dive, prefer_imported);