summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar willemferguson <willemferguson@zoology.up.ac.za>2019-04-30 12:42:33 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-05-15 07:37:14 -0700
commit1bdf00b2b472078a0b24f1c269782d822cb96e02 (patch)
tree13a5e784118d9abb0a1bc1dfa9cbe4a9f457de80 /core
parentca6aa3813956b5e8be68b86ed36a5786b3ee746f (diff)
downloadsubsurface-1bdf00b2b472078a0b24f1c269782d822cb96e02.tar.gz
Convert the atmospheric pressure in the Information Tab to an editable field
The Information tab shows the atmospheric pressure. Make this value editable and also ensure that changes to it are undo-able. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Diffstat (limited to 'core')
-rw-r--r--core/dive.c28
-rw-r--r--core/dive.h2
-rw-r--r--core/load-git.c12
-rw-r--r--core/parse-xml.c2
-rw-r--r--core/save-git.c3
-rw-r--r--core/save-xml.c3
-rw-r--r--core/subsurface-qt/DiveListNotifier.h1
-rw-r--r--core/units.h11
8 files changed, 56 insertions, 6 deletions
diff --git a/core/dive.c b/core/dive.c
index 0f67ebe61..d20350a80 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -1317,9 +1317,10 @@ static struct event *find_previous_event(struct divecomputer *dc, struct event *
return previous;
}
-static void fixup_surface_pressure(struct dive *dive)
+pressure_t calculate_surface_pressure(const struct dive *dive)
{
- struct divecomputer *dc;
+ const struct divecomputer *dc;
+ pressure_t res;
int sum = 0, nr = 0;
for_each_dc (dive, dc) {
@@ -1328,8 +1329,24 @@ static void fixup_surface_pressure(struct dive *dive)
nr++;
}
}
- if (nr)
- dive->surface_pressure.mbar = (sum + nr / 2) / nr;
+ res.mbar = nr ? (sum + nr / 2) / nr : 0;
+ return res;
+}
+
+static void fixup_surface_pressure(struct dive *dive)
+{
+ dive->surface_pressure = calculate_surface_pressure(dive);
+}
+
+/* if the surface pressure in the dive data is redundant to the calculated
+ * value (i.e., it was added by running fixup on the dive) return 0,
+ * otherwise return the air temperature given in the dive */
+pressure_t un_fixup_surface_pressure(const struct dive *d)
+{
+ pressure_t res = d->surface_pressure;
+ if (res.mbar && res.mbar == calculate_surface_pressure(d).mbar)
+ res.mbar = 0;
+ return res;
}
static void fixup_water_salinity(struct dive *dive)
@@ -1823,7 +1840,8 @@ struct dive *fixup_dive(struct dive *dive)
fixup_dive_dc(dive, dc);
fixup_water_salinity(dive);
- fixup_surface_pressure(dive);
+ if (!dive->surface_pressure.mbar)
+ fixup_surface_pressure(dive);
fixup_meandepth(dive);
fixup_duration(dive);
fixup_watertemp(dive);
diff --git a/core/dive.h b/core/dive.h
index 6f75aff43..7aea050b6 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -533,6 +533,8 @@ extern bool dive_or_trip_less_than(struct dive_or_trip a, struct dive_or_trip b)
extern void sort_dive_table(struct dive_table *table);
extern void sort_trip_table(struct trip_table *table);
extern struct dive *fixup_dive(struct dive *dive);
+extern pressure_t calculate_surface_pressure(const struct dive *dive);
+extern pressure_t un_fixup_surface_pressure(const struct dive *d);
extern void fixup_dc_duration(struct divecomputer *dc);
extern int dive_getUniqID();
extern unsigned int dc_airtemp(const struct divecomputer *dc);
diff --git a/core/load-git.c b/core/load-git.c
index c6b3400a8..a0baedecd 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -76,6 +76,13 @@ static weight_t get_weight(const char *line)
return w;
}
+static pressure_t get_airpressure(const char *line)
+{
+ pressure_t p;
+ p.mbar = lrint(ascii_strtod(line, NULL));
+ return p;
+}
+
static pressure_t get_pressure(const char *line)
{
pressure_t p;
@@ -245,6 +252,9 @@ static void parse_dive_airtemp(char *line, struct membuffer *str, void *_dive)
static void parse_dive_watertemp(char *line, struct membuffer *str, void *_dive)
{ UNUSED(str); struct dive *dive = _dive; dive->watertemp = get_temperature(line); }
+static void parse_dive_airpressure(char *line, struct membuffer *str, void *_dive)
+{ UNUSED(str); struct dive *dive = _dive; dive->surface_pressure = get_airpressure(line); }
+
static void parse_dive_duration(char *line, struct membuffer *str, void *_dive)
{ UNUSED(str); struct dive *dive = _dive; dive->duration = get_duration(line); }
@@ -980,7 +990,7 @@ static void divecomputer_parser(char *line, struct membuffer *str, void *_dc)
struct keyword_action dive_action[] = {
#undef D
#define D(x) { #x, parse_dive_ ## x }
- D(airtemp), D(buddy), D(cylinder), D(divemaster), D(divesiteid), D(duration),
+ D(airpressure), D(airtemp), D(buddy), D(cylinder), D(divemaster), D(divesiteid), D(duration),
D(gps), D(location), D(notes), D(notrip), D(rating), D(suit),
D(tags), D(visibility), D(watertemp), D(weightsystem)
};
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 483614c6e..43d0049a7 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1306,6 +1306,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str
return;
if (MATCH("visibility.dive", get_rating, &dive->visibility))
return;
+ if (MATCH_STATE("airpressure.dive", pressure, &dive->surface_pressure))
+ return;
if (state->cur_ws_index < MAX_WEIGHTSYSTEMS) {
if (MATCH("description.weightsystem", utf8_string, &dive->weightsystem[state->cur_ws_index].description))
return;
diff --git a/core/save-git.c b/core/save-git.c
index b13921c60..a5f6f0dde 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -425,10 +425,13 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
*/
static void create_dive_buffer(struct dive *dive, struct membuffer *b)
{
+ pressure_t surface_pressure = un_fixup_surface_pressure(dive);
if (dive->dc.duration.seconds > 0)
put_format(b, "duration %u:%02u min\n", FRACTION(dive->dc.duration.seconds, 60));
SAVE("rating", rating);
SAVE("visibility", visibility);
+ if (surface_pressure.mbar)
+ SAVE("airpressure", surface_pressure.mbar);
cond_put_format(dive->notrip, b, "notrip\n");
save_tags(b, dive->tag_list);
if (dive->dive_site)
diff --git a/core/save-xml.c b/core/save-xml.c
index 02cb2bf87..f043ab6d8 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -473,6 +473,7 @@ static void save_picture(struct membuffer *b, struct picture *pic)
void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize)
{
struct divecomputer *dc;
+ pressure_t surface_pressure = un_fixup_surface_pressure(dive);
put_string(b, "<dive");
if (dive->number)
@@ -488,6 +489,8 @@ void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize)
put_format(b, " divesiteid='%8x'", dive->dive_site->uuid);
}
show_date(b, dive->when);
+ if (surface_pressure.mbar)
+ put_pressure(b, surface_pressure, " airpressure='", " bar'");
if (dive->dc.duration.seconds > 0)
put_format(b, " duration='%u:%02u min'>\n",
FRACTION(dive->dc.duration.seconds, 60));
diff --git a/core/subsurface-qt/DiveListNotifier.h b/core/subsurface-qt/DiveListNotifier.h
index b57595aa6..95a67a1e8 100644
--- a/core/subsurface-qt/DiveListNotifier.h
+++ b/core/subsurface-qt/DiveListNotifier.h
@@ -19,6 +19,7 @@ enum class DiveField {
DURATION,
AIR_TEMP,
WATER_TEMP,
+ ATM_PRESS,
DIVESITE,
DIVEMASTER,
BUDDY,
diff --git a/core/units.h b/core/units.h
index c9920ac14..2307622e9 100644
--- a/core/units.h
+++ b/core/units.h
@@ -254,6 +254,17 @@ static inline int mbar_to_PSI(int mbar)
return to_PSI(p);
}
+static inline int32_t altitude_to_pressure(int32_t altitude) // altitude in mm above sea level
+{ // returns atmospheric pressure in mbar
+ return (int32_t) (1013.0 * exp(- altitude / 7800000.0));
+}
+
+
+static inline int32_t pressure_to_altitude(int32_t pressure) // pressure in mbar
+{ // returns altitude in mm above sea level
+ return (int32_t) (log(1013.0 / pressure) * 7800000);
+}
+
/*
* We keep our internal data in well-specified units, but
* the input and output may come in some random format. This