diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-25 19:10:03 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-25 22:05:32 -0700 |
commit | efc5f4d9ababda3078a696bec8840a5eb173ee3d (patch) | |
tree | eb6586d59ff6cb4b7a6e77f68bfede0ca7a0f74a /core/load-git.c | |
parent | c5167f00398ce16daaeb26ceb00ca058b6d1606c (diff) | |
download | subsurface-efc5f4d9ababda3078a696bec8840a5eb173ee3d.tar.gz |
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/load-git.c')
-rw-r--r-- | core/load-git.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/load-git.c b/core/load-git.c index 6a3cc75ce..e7732a69f 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -560,6 +560,7 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va static char *parse_sample_unit(struct sample *sample, double val, char *unit) { + unsigned int sensor; char *end = unit, c; /* Skip over the unit */ @@ -572,12 +573,16 @@ static char *parse_sample_unit(struct sample *sample, double val, char *unit) } /* The units are "°C", "m" or "bar", so let's just look at the first character */ + /* The cylinder pressure may also be of the form '123.0bar:4' to indicate sensor */ switch (*unit) { case 'm': sample->depth.mm = lrint(1000*val); break; case 'b': - sample->pressure[0].mbar = lrint(1000*val); + sensor = sample->sensor[0]; + if (end > unit+4 && unit[3] == ':') + sensor = atoi(unit+4); + add_sample_pressure(sample, sensor, lrint(1000*val)); break; default: sample->temperature.mkelvin = C_to_mkelvin(val); |