aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/units.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/units.c')
-rw-r--r--src/units.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/units.c b/src/units.c
new file mode 100644
index 0000000..519f4c2
--- /dev/null
+++ b/src/units.c
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: MIT-0 */
+
+#include <assert.h>
+
+#include "units.h"
+
+enum UNITS UNITS = UNITS_DEFAULT;
+double SURFACE_PRESSURE = SURFACE_PRESSURE_DEFAULT;
+
+double bar_to_msw(double bar)
+{
+ return bar * 10;
+}
+
+double msw_to_bar(double msw)
+{
+ return msw / 10;
+}
+
+double bar_to_fsw(double bar)
+{
+ return (bar / 1.01325) * 33.0;
+}
+
+double fsw_to_bar(double fsw)
+{
+ return (fsw * 1.01325) / 33.0;
+}
+
+double msw_or_fsw(double msw, double fsw)
+{
+ assert(UNITS == METRIC || UNITS == IMPERIAL);
+
+ return (UNITS == METRIC) ? msw : fsw;
+}
+
+double xsw_to_bar(double xsw)
+{
+ assert(UNITS == METRIC || UNITS == IMPERIAL);
+
+ return (UNITS == METRIC) ? msw_to_bar(xsw) : fsw_to_bar(xsw);
+}
+
+double bar_to_xsw(double bar)
+{
+ assert(UNITS == METRIC || UNITS == IMPERIAL);
+
+ return (UNITS == METRIC) ? bar_to_msw(bar) : bar_to_fsw(bar);
+}
+
+double abs_depth(double gd)
+{
+ return gd + SURFACE_PRESSURE;
+}
+
+double gauge_depth(double ad)
+{
+ return ad - SURFACE_PRESSURE;
+}