mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
general: simplify a few unit manipulations
Now that we have defined addition and subtraction on unit classes, let's use them in a few examples. Yes, some of these are a bit pointless, because they are of the kind a.mbar - b.mbar => (a-b).mbar However, these probably should be further simplified by storing the result in a unit type. This commit is mostly a proof-of-concept. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
729cc16fc5
commit
110e64bc66
14 changed files with 59 additions and 68 deletions
|
@ -93,16 +93,17 @@ static weight_t get_weight(const char *line)
|
|||
|
||||
static pressure_t get_airpressure(const char *line)
|
||||
{
|
||||
pressure_t p;
|
||||
p.mbar = lrint(ascii_strtod(line, NULL));
|
||||
return p;
|
||||
return pressure_t { .mbar = static_cast<int32_t>(lrint(ascii_strtod(line, NULL))) };
|
||||
}
|
||||
|
||||
static pressure_t get_pressure(const char *line)
|
||||
{
|
||||
pressure_t p;
|
||||
p.mbar = lrint(1000 * ascii_strtod(line, NULL));
|
||||
return p;
|
||||
return pressure_t { .mbar = static_cast<int32_t>(lrint(1000 * ascii_strtod(line, NULL))) };
|
||||
}
|
||||
|
||||
static o2pressure_t get_o2pressure(const char *line)
|
||||
{
|
||||
return o2pressure_t { .mbar = static_cast<uint16_t>(lrint(1000 * ascii_strtod(line, NULL))) };
|
||||
}
|
||||
|
||||
static int get_salinity(const char *line)
|
||||
|
@ -557,43 +558,35 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const std::str
|
|||
}
|
||||
|
||||
if (!strcmp(key, "po2")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->setpoint.mbar = p.mbar;
|
||||
sample->setpoint = get_o2pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "sensor1")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->o2sensor[0].mbar = p.mbar;
|
||||
sample->o2sensor[0] = get_o2pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "sensor2")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->o2sensor[1].mbar = p.mbar;
|
||||
sample->o2sensor[1] = get_o2pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "sensor3")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->o2sensor[2].mbar = p.mbar;
|
||||
sample->o2sensor[2] = get_o2pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "sensor4")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->o2sensor[3].mbar = p.mbar;
|
||||
sample->o2sensor[3] = get_o2pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "sensor5")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->o2sensor[4].mbar = p.mbar;
|
||||
sample->o2sensor[4] = get_o2pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "sensor6")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->o2sensor[5].mbar = p.mbar;
|
||||
sample->o2sensor[5] = get_o2pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "o2pressure")) {
|
||||
pressure_t p = get_pressure(value.c_str());
|
||||
sample->pressure[1].mbar = p.mbar;
|
||||
sample->pressure[1] = get_pressure(value.c_str());
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "heartbeat")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue