mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 21:06:17 +00:00
Merge branch 'airtemp-fix'
This commit is contained in:
commit
869edfbe39
5 changed files with 50 additions and 3 deletions
26
dive.c
26
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);
|
||||
|
|
1
dive.h
1
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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
17
save-xml.c
17
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 {
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue