diff options
author | Tim Segers <tsegers@pm.me> | 2023-08-07 21:53:38 +0200 |
---|---|---|
committer | Tim Segers <tsegers@pm.me> | 2023-08-21 20:54:39 +0200 |
commit | c46ebe4b35e3a0ffebf00b0eaa31b842279396b6 (patch) | |
tree | 9f1d0a6d598dcd00ec6343d3a7dce14afd796432 /src | |
parent | 8bc512bf10a424289e6974627540770f3bcec074 (diff) | |
download | opendeco-c46ebe4b35e3a0ffebf00b0eaa31b842279396b6.tar.gz |
Split gas functions out from deco.c
Diffstat (limited to 'src')
-rw-r--r-- | src/deco.c | 36 | ||||
-rw-r--r-- | src/deco.h | 21 | ||||
-rw-r--r-- | src/gas.c | 42 | ||||
-rw-r--r-- | src/gas.h | 30 |
4 files changed, 74 insertions, 55 deletions
@@ -13,7 +13,6 @@ enum UNITS UNITS = UNITS_DEFAULT; double SURFACE_PRESSURE = SURFACE_PRESSURE_DEFAULT; double P_WV = P_WV_DEFAULT; -double PO2_MAX = PO2_MAX_DEFAULT; double END_MAX = END_MAX_DEFAULT; typedef struct zhl_n2_t { @@ -117,41 +116,6 @@ double gauge_depth(double ad) return ad - SURFACE_PRESSURE; } -gas_t gas_new(unsigned char o2, unsigned char he, double mod) -{ - assert(o2 + he <= 100); - - if (mod == MOD_AUTO) - mod = PO2_MAX / (o2 / 100.0); - - return (gas_t){.o2 = o2, .he = he, .n2 = 100 - o2 - he, .mod = mod}; -} - -int gas_equal(const gas_t *g1, const gas_t *g2) -{ - return g1->o2 == g2->o2 && g1->he == g2->he && g1->mod == g2->mod; -} - -unsigned char gas_o2(const gas_t *gas) -{ - return gas->o2; -} - -unsigned char gas_he(const gas_t *gas) -{ - return gas->he; -} - -unsigned char gas_n2(const gas_t *gas) -{ - return gas->n2; -} - -double gas_mod(const gas_t *gas) -{ - return gas->mod; -} - void add_segment_ascdec(decostate_t *ds, double dstart, double dend, double time, const gas_t *gas) { assert(time > 0); @@ -5,6 +5,8 @@ #include <stddef.h> +#include "gas.h" + #define max(X, Y) (((X) > (Y)) ? (X) : (Y)) #define min(X, Y) (((X) < (Y)) ? (X) : (Y)) #define len(X) (sizeof(X) / sizeof((X)[0])) @@ -18,11 +20,6 @@ #define SURFACE_PRESSURE_DEFAULT 1.01325 #define P_WV_DEFAULT P_WV_BUHL -#define PO2_MAX_DEFAULT 1.6 -#define END_MAX_DEFAULT 4.01325 - -#define MOD_AUTO 0 - /* types */ enum UNITS { METRIC, @@ -35,13 +32,6 @@ enum ALGO { ZHL_16C = 2, }; -typedef struct gas_t { - unsigned char o2; - unsigned char he; - unsigned char n2; - double mod; -} gas_t; - typedef struct decostate_t { double pn2[16]; double phe[16]; @@ -75,13 +65,6 @@ double bar_to_xsw(double bar); double abs_depth(double gd); double gauge_depth(double ad); -gas_t gas_new(unsigned char o2, unsigned char he, double mod); -int gas_equal(const gas_t *g1, const gas_t *g2); -unsigned char gas_o2(const gas_t *gas); -unsigned char gas_he(const gas_t *gas); -unsigned char gas_n2(const gas_t *gas); -double gas_mod(const gas_t *gas); - 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/gas.c b/src/gas.c new file mode 100644 index 0000000..c59db2c --- /dev/null +++ b/src/gas.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: MIT-0 */ + +#include <assert.h> + +#include "gas.h" + +double PO2_MAX = PO2_MAX_DEFAULT; + +gas_t gas_new(unsigned char o2, unsigned char he, double mod) +{ + assert(o2 + he <= 100); + + if (mod == MOD_AUTO) + mod = PO2_MAX / (o2 / 100.0); + + return (gas_t){.o2 = o2, .he = he, .n2 = 100 - o2 - he, .mod = mod}; +} + +int gas_equal(const gas_t *g1, const gas_t *g2) +{ + return g1->o2 == g2->o2 && g1->he == g2->he && g1->mod == g2->mod; +} + +unsigned char gas_o2(const gas_t *gas) +{ + return gas->o2; +} + +unsigned char gas_he(const gas_t *gas) +{ + return gas->he; +} + +unsigned char gas_n2(const gas_t *gas) +{ + return gas->n2; +} + +double gas_mod(const gas_t *gas) +{ + return gas->mod; +} diff --git a/src/gas.h b/src/gas.h new file mode 100644 index 0000000..ca38a8d --- /dev/null +++ b/src/gas.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: MIT-0 */ + +#ifndef GAS_H +#define GAS_H + +#define PO2_MAX_DEFAULT 1.6 +#define END_MAX_DEFAULT 4.01325 + +extern double PO2_MAX; +extern double END_MAX; + +#define MOD_AUTO 0 + +/* types */ +typedef struct gas_t { + unsigned char o2; + unsigned char he; + unsigned char n2; + double mod; +} gas_t; + +/* functions */ +gas_t gas_new(unsigned char o2, unsigned char he, double mod); +int gas_equal(const gas_t *g1, const gas_t *g2); +unsigned char gas_o2(const gas_t *gas); +unsigned char gas_he(const gas_t *gas); +unsigned char gas_n2(const gas_t *gas); +double gas_mod(const gas_t *gas); + +#endif /* end of include guard: GAS_H */ |