summaryrefslogtreecommitdiffstats
path: root/core/equipment.c
diff options
context:
space:
mode:
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;