summaryrefslogtreecommitdiffstats
path: root/core/equipment.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-06-04 13:52:48 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-06-19 13:11:10 -0700
commit619d3fb1fd4b7ab532537b7eca78f668d2ce381b (patch)
tree7a4575845be7b5a196a1450c370b660a18ef9e13 /core/equipment.c
parent83522747581500ef39005bc76b1048db1cd3bd29 (diff)
downloadsubsurface-619d3fb1fd4b7ab532537b7eca78f668d2ce381b.tar.gz
Cleanup: move gas-functions to own translation unit
But only functions that operate only on gases. Functions concerning cylinders or dives remain in dive.c or are moved to equipment.c Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/equipment.c')
-rw-r--r--core/equipment.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/equipment.c b/core/equipment.c
index 325c57cb7..81033ace6 100644
--- a/core/equipment.c
+++ b/core/equipment.c
@@ -10,6 +10,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
+#include <limits.h>
#include "equipment.h"
#include "gettext.h"
#include "dive.h"
@@ -101,6 +102,36 @@ const char *gasname(struct gasmix gasmix)
return gas;
}
+int gas_volume(const cylinder_t *cyl, pressure_t p)
+{
+ double bar = p.mbar / 1000.0;
+ double z_factor = gas_compressibility_factor(cyl->gasmix, bar);
+ return lrint(cyl->type.size.mliter * bar_to_atm(bar) / z_factor);
+}
+
+int find_best_gasmix_match(struct gasmix mix, const cylinder_t array[], unsigned int used)
+{
+ int i;
+ int best = -1, score = INT_MAX;
+
+ for (i = 0; i < MAX_CYLINDERS; i++) {
+ const cylinder_t *match;
+ int distance;
+
+ if (used & (1 << i))
+ continue;
+ match = array + i;
+ if (cylinder_nodata(match))
+ continue;
+ distance = gasmix_distance(mix, match->gasmix);
+ if (distance >= score)
+ continue;
+ best = i;
+ score = distance;
+ }
+ return best;
+}
+
bool weightsystem_none(const weightsystem_t *ws)
{
return !ws->weight.grams && !ws->description;