aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/deco.c54
-rw-r--r--src/deco.h19
-rw-r--r--src/opendeco-conf.h1
-rw-r--r--src/opendeco.c1
-rw-r--r--src/output.c1
-rw-r--r--src/schedule.c1
-rw-r--r--src/units.c59
-rw-r--r--src/units.h30
8 files changed, 94 insertions, 72 deletions
diff --git a/src/deco.c b/src/deco.c
index 08a3957..f39c61e 100644
--- a/src/deco.c
+++ b/src/deco.c
@@ -5,12 +5,11 @@
#include <stdbool.h>
#include "deco.h"
+#include "units.h"
#define RND(x) (round((x) *10000) / 10000)
enum ALGO ALGO_VER = ALGO_VER_DEFAULT;
-enum UNITS UNITS = UNITS_DEFAULT;
-double SURFACE_PRESSURE = SURFACE_PRESSURE_DEFAULT;
double P_WV = P_WV_DEFAULT;
double END_MAX = END_MAX_DEFAULT;
@@ -65,57 +64,6 @@ const zhl_he_t ZHL16He[] = {
{.t = 240.03, .a = 0.5119, .b = 0.9267},
};
-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;
-}
-
void add_segment_ascdec(decostate_t *ds, double dstart, double dend, double time, const gas_t *gas)
{
assert(time > 0);
diff --git a/src/deco.h b/src/deco.h
index 1ec5645..3d87b15 100644
--- a/src/deco.h
+++ b/src/deco.h
@@ -16,16 +16,9 @@
#define P_WV_SCHR 0.0493 /* Schreiner value, Rq = 0.8, most conservative */
#define ALGO_VER_DEFAULT ZHL_16C
-#define UNITS_DEFAULT METRIC
-#define SURFACE_PRESSURE_DEFAULT 1.01325
#define P_WV_DEFAULT P_WV_BUHL
/* types */
-enum UNITS {
- METRIC,
- IMPERIAL,
-};
-
enum ALGO {
ZHL_16A = 0,
ZHL_16B = 1,
@@ -47,24 +40,12 @@ typedef struct decostate_t {
/* global variables */
extern enum ALGO ALGO_VER;
-extern enum UNITS UNITS;
-extern double SURFACE_PRESSURE;
extern double P_WV;
extern double PO2_MAX;
extern double END_MAX;
/* functions */
-double bar_to_msw(double bar);
-double msw_to_bar(double msw);
-double bar_to_fsw(double bar);
-double fsw_to_bar(double msw);
-double msw_or_fsw(double msw, double fsw);
-double xsw_to_bar(double xsw);
-double bar_to_xsw(double bar);
-double abs_depth(double gd);
-double gauge_depth(double ad);
-
void add_segment_ascdec(decostate_t *ds, double dstart, double dend, double time, const gas_t *gas);
void add_segment_const(decostate_t *ds, double depth, double time, const gas_t *gas);
double get_gf(const decostate_t *ds, double depth);
diff --git a/src/opendeco-conf.h b/src/opendeco-conf.h
index 359889a..2f49d0f 100644
--- a/src/opendeco-conf.h
+++ b/src/opendeco-conf.h
@@ -4,6 +4,7 @@
#define OPENDECOCONF_H
#include "deco.h"
+#include "units.h"
#ifndef VERSION
#define VERSION "unknown version"
diff --git a/src/opendeco.c b/src/opendeco.c
index 926ff50..b57004b 100644
--- a/src/opendeco.c
+++ b/src/opendeco.c
@@ -13,6 +13,7 @@
#include "opendeco-conf.h"
#include "output.h"
#include "schedule.h"
+#include "units.h"
#define MOD_OXY (abs_depth(xsw_to_bar(msw_or_fsw(6, 20))))
diff --git a/src/output.c b/src/output.c
index 43ee82a..07eacbe 100644
--- a/src/output.c
+++ b/src/output.c
@@ -6,6 +6,7 @@
#include <errno.h>
#include "output.h"
+#include "units.h"
#define DEPTHUNIT ((UNITS == METRIC) ? "m " : "ft")
diff --git a/src/schedule.c b/src/schedule.c
index 5786159..fdd81a2 100644
--- a/src/schedule.c
+++ b/src/schedule.c
@@ -5,6 +5,7 @@
#include <stdbool.h>
#include "schedule.h"
+#include "units.h"
#define STOPLEN_ROUGH 10
#define STOPLEN_FINE 1
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;
+}
diff --git a/src/units.h b/src/units.h
new file mode 100644
index 0000000..1557bc0
--- /dev/null
+++ b/src/units.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: MIT-0 */
+
+#ifndef UNITS_H
+#define UNITS_H
+
+#define UNITS_DEFAULT METRIC
+#define SURFACE_PRESSURE_DEFAULT 1.01325
+
+/* types */
+enum UNITS {
+ METRIC,
+ IMPERIAL,
+};
+
+/* global variables */
+extern enum UNITS UNITS;
+extern double SURFACE_PRESSURE;
+
+/* functions */
+double bar_to_msw(double bar);
+double msw_to_bar(double msw);
+double bar_to_fsw(double bar);
+double fsw_to_bar(double msw);
+double msw_or_fsw(double msw, double fsw);
+double xsw_to_bar(double xsw);
+double bar_to_xsw(double bar);
+double abs_depth(double gd);
+double gauge_depth(double ad);
+
+#endif /* end of include guard: UNITS_H */