summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-12 20:57:49 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-12 20:57:49 +0100
commit56f62cc4ab46f811b4340aa36ad1df42bb08832c (patch)
tree1dc0319ac498e2d10d4097244f82c2a435dbe642
parentfbbdb834f9f3900d56347dc250f5995f173129b0 (diff)
downloadsubsurface-56f62cc4ab46f811b4340aa36ad1df42bb08832c.tar.gz
Store and parse salinity and surface pressure
In my excitement about extracting these from libdivecomputer I forgot to actually store them and then parse them again. Oops. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--parse-xml.c18
-rw-r--r--save-xml.c26
2 files changed, 44 insertions, 0 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 36a91f4f6..f62ce9891 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -308,6 +308,20 @@ static void pressure(char *buffer, void *_press)
free(buffer);
}
+static void salinity(char *buffer, void *_salinity)
+{
+ int *salinity = _salinity;
+ union int_or_float val;
+ switch (integer_or_float(buffer, &val)) {
+ case FLOAT:
+ *salinity = val.fp * 10.0 + 0.5;
+ break;
+ default:
+ printf("Strange salinity reading %s\n", buffer);
+ }
+ free(buffer);
+}
+
static void depth(char *buffer, void *_depth)
{
depth_t *depth = _depth;
@@ -1106,6 +1120,10 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf)
return;
if (MATCH(".temperature.water", temperature, &dive->watertemp))
return;
+ if (MATCH(".surface.pressure", pressure, &dive->surface_pressure))
+ return;
+ if (MATCH(".water.salinity", salinity, &dive->salinity))
+ return;
if (MATCH(".cylinderstartpressure", pressure, &dive->cylinder[0].start))
return;
if (MATCH(".cylinderendpressure", pressure, &dive->cylinder[0].end))
diff --git a/save-xml.c b/save-xml.c
index fb62651d6..824763c44 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -57,6 +57,11 @@ static void show_pressure(FILE *f, pressure_t pressure, const char *pre, const c
show_milli(f, pre, pressure.mbar, " bar", post);
}
+static void show_salinity(FILE *f, int salinity, const char *pre, const char *post)
+{
+ if (salinity)
+ fprintf(f, "%s%.1f kg/l%s", pre, salinity / 10.0, post);
+}
/*
* We're outputting utf8 in xml.
* We need to quote the characters <, >, &.
@@ -154,6 +159,25 @@ static void save_temperatures(FILE *f, struct dive *dive)
fputs(" />\n", f);
}
+static void save_airpressure(FILE *f, struct dive *dive)
+{
+ if (!dive->surface_pressure.mbar)
+ return;
+ fputs(" <surface", f);
+ show_pressure(f, dive->surface_pressure, " pressure='", "'");
+ fputs(" />\n", f);
+}
+
+static void save_salinity(FILE *f, struct dive *dive)
+{
+ if (!dive->salinity)
+ return;
+ fputs(" <water ", f);
+ show_salinity(f, dive->salinity, " salinity='", "'");
+ fputs(" />\n", f);
+}
+
+
static void show_location(FILE *f, struct dive *dive)
{
char buffer[80];
@@ -185,6 +209,8 @@ static void save_overview(FILE *f, struct dive *dive)
{
save_depths(f, dive);
save_temperatures(f, dive);
+ save_airpressure(f, dive);
+ save_salinity(f, dive);
show_duration(f, dive->surfacetime, " <surfacetime>", "</surfacetime>\n");
show_location(f, dive);
show_utf8(f, dive->divemaster, " <divemaster>","</divemaster>\n", 0);