aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2022-10-11 17:56:55 +0200
committerGravatar Tim Segers <tsegers@pm.me>2022-10-11 17:56:55 +0200
commit70ea0d58f937c4493bdcbacd59d4f7bf18792352 (patch)
treee1aa47ac7c9d62338e50e747d9e2dcee5f9444d0 /src
parent07cac4282bf721e75d70f1811f55152989a6a7c5 (diff)
downloadopendeco-70ea0d58f937c4493bdcbacd59d4f7bf18792352.tar.gz
Make various constants configurable
- SURFACE_PRESSURE* - SWITCH_INTERMEDIATE* - P_WV - PO2_MAX - END_MAX - ALGO_VER * can now also be set from the CLI
Diffstat (limited to 'src')
-rw-r--r--src/deco.c9
-rw-r--r--src/deco.h12
-rw-r--r--src/opendeco.c53
-rw-r--r--src/output.c2
-rw-r--r--src/output.h1
-rw-r--r--src/schedule.c4
-rw-r--r--src/schedule.h5
7 files changed, 62 insertions, 24 deletions
diff --git a/src/deco.c b/src/deco.c
index 5ef6537..5d03e75 100644
--- a/src/deco.c
+++ b/src/deco.c
@@ -6,11 +6,14 @@
#include "deco.h"
+#define RND(x) (round((x) *10000) / 10000)
+
enum ALGO ALGO_VER = ZHL_16C;
+double SURFACE_PRESSURE = 1.01325;
+double P_WV = P_WV_BUHL;
-#define PO2_MAX (1.6)
-#define END_MAX (abs_depth(msw_to_bar(30)))
-#define RND(x) (round((x) *10000) / 10000)
+double PO2_MAX = 1.6;
+double END_MAX = 4.01325;
typedef struct zhl_n2_t {
double t;
diff --git a/src/deco.h b/src/deco.h
index 439626f..68c65ed 100644
--- a/src/deco.h
+++ b/src/deco.h
@@ -12,11 +12,10 @@
#define P_WV_BUHL 0.0627 /* Buhlmann value, Rq = 1.0, least conservative */
#define P_WV_NAVY 0.0567 /* US. Navy value, Rq = 0.9 */
#define P_WV_SCHR 0.0493 /* Schreiner value, Rq = 0.8, most conservative */
-#define P_WV P_WV_BUHL
-#define SURFACE_PRESSURE 1.01325
#define MOD_AUTO 0
+/* types */
enum ALGO {
ZHL_16A = 0,
ZHL_16B = 1,
@@ -40,6 +39,15 @@ typedef struct gas_t {
double mod;
} gas_t;
+/* global variables */
+extern enum ALGO ALGO_VER;
+extern double SURFACE_PRESSURE;
+extern double P_WV;
+
+extern double PO2_MAX;
+extern double END_MAX;
+
+/* functions */
double bar_to_msw(const double bar);
double msw_to_bar(const double msw);
double abs_depth(const double gd);
diff --git a/src/opendeco.c b/src/opendeco.c
index 9231ab3..8a1287b 100644
--- a/src/opendeco.c
+++ b/src/opendeco.c
@@ -28,13 +28,15 @@ const char *argp_program_bug_address = "<~tsegers/opendeco@lists.sr.ht> or https
const char *argp_program_version = "opendeco " VERSION;
static struct argp_option options[] = {
- {"depth", 'd', "NUMBER", 0, "Set the depth of the dive in meters", 0},
- {"time", 't', "NUMBER", 0, "Set the time of the dive in minutes", 1},
- {"gas", 'g', "STRING", 0, "Set the bottom gas used during the dive, defaults to Air", 2},
- {"gflow", 'l', "NUMBER", 0, "Set the gradient factor at the first stop, defaults to 30", 3},
- {"gfhigh", 'h', "NUMBER", 0, "Set the gradient factor at the surface, defaults to 75", 4},
- {"decogasses", 'G', "LIST", 0, "Set the gasses available for deco", 5},
- {0, 0, 0, 0, 0, 0}
+ {"depth", 'd', "NUMBER", 0, "Set the depth of the dive in meters", 0},
+ {"time", 't', "NUMBER", 0, "Set the time of the dive in minutes", 1},
+ {"gas", 'g', "STRING", 0, "Set the bottom gas used during the dive, defaults to Air", 2},
+ {"pressure", 'p', "STRING", 0, "Set the surface air pressure, defaults to 1.01325bar or 1atm", 3},
+ {0, 's', 0, OPTION_ARG_OPTIONAL, "Only switch gas at deco stops", 4},
+ {"gflow", 'l', "NUMBER", 0, "Set the gradient factor at the first stop, defaults to 30", 5},
+ {"gfhigh", 'h', "NUMBER", 0, "Set the gradient factor at the surface, defaults to 75", 6},
+ {"decogasses", 'G', "LIST", 0, "Set the gasses available for deco", 7},
+ {0, 0, 0, 0, 0, 0}
};
struct arguments {
@@ -44,6 +46,8 @@ struct arguments {
int gflow;
int gfhigh;
char *decogasses;
+ double SURFACE_PRESSURE;
+ int SWITCH_INTERMEDIATE;
};
static error_t parse_opt(int key, char *arg, struct argp_state *state)
@@ -60,6 +64,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'g':
arguments->gas = arg;
break;
+ case 'p':
+ arguments->SURFACE_PRESSURE = arg ? atof(arg) : -1;
+ break;
+ case 's':
+ arguments->SWITCH_INTERMEDIATE = 0;
+ break;
case 'G':
arguments->decogasses = arg;
break;
@@ -75,6 +85,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
argp_failure(state, 1, 0, "Options -d and -t are required. See --help for more information");
exit(ARGP_ERR_UNKNOWN);
}
+ if (arguments->SURFACE_PRESSURE < 0) {
+ argp_state_help(state, stderr, ARGP_HELP_USAGE);
+ argp_failure(state, 1, 0, "Surface air pressure must be positive. See --help for more information");
+ exit(ARGP_ERR_UNKNOWN);
+ }
default:
return ARGP_ERR_UNKNOWN;
}
@@ -149,17 +164,25 @@ int main(int argc, char *argv[])
setlocale(LC_ALL, "en_US.utf8");
/* argp */
- struct arguments arguments;
-
- arguments.depth = -1;
- arguments.time = -1;
- arguments.gas = "Air";
- arguments.gflow = 30;
- arguments.gfhigh = 75;
- arguments.decogasses = "";
+ struct arguments arguments = {
+ .depth = -1,
+ .time = -1,
+ .gas = "Air",
+ .gflow = 30,
+ .gfhigh = 75,
+ .decogasses = "",
+ .SURFACE_PRESSURE = 0,
+ .SWITCH_INTERMEDIATE = 1,
+ };
argp_parse(&argp, argc, argv, 0, 0, &arguments);
+ /* apply global options */
+ if (arguments.SURFACE_PRESSURE > 0)
+ SURFACE_PRESSURE = arguments.SURFACE_PRESSURE;
+
+ SWITCH_INTERMEDIATE = arguments.SWITCH_INTERMEDIATE;
+
/* setup */
decostate_t ds;
init_decostate(&ds, arguments.gflow, arguments.gfhigh, msw_to_bar(3));
diff --git a/src/output.c b/src/output.c
index 589c811..bf9a4d7 100644
--- a/src/output.c
+++ b/src/output.c
@@ -6,8 +6,6 @@
#include "output.h"
-extern enum ALGO ALGO_VER;
-
void format_mm_ss(char *buf, const size_t buflen, const double time)
{
double mm;
diff --git a/src/output.h b/src/output.h
index 640b457..5cc3adc 100644
--- a/src/output.h
+++ b/src/output.h
@@ -12,6 +12,7 @@
#define DEC 0x2198 /* Unicode South East Arrow */
#define SWI 0x21BB /* Clockwise Open Circle Arrow */
+/* functions */
void print_planhead();
void print_planline(const wchar_t sign, const double depth, const double time, const double runtime, const gas_t *gas);
void print_planfoot(const decostate_t *ds);
diff --git a/src/schedule.c b/src/schedule.c
index d13a9c9..d444d5e 100644
--- a/src/schedule.c
+++ b/src/schedule.c
@@ -5,11 +5,11 @@
#include "schedule.h"
-#define SWITCH_INTERMEDIATE 1
-
#define STOPLEN_ROUGH 10
#define STOPLEN_FINE 1
+int SWITCH_INTERMEDIATE = 1;
+
const gas_t *best_gas(const double depth, const gas_t *gasses, const int nof_gasses)
{
const gas_t *best = NULL;
diff --git a/src/schedule.h b/src/schedule.h
index f2e6363..57f1e9d 100644
--- a/src/schedule.h
+++ b/src/schedule.h
@@ -5,6 +5,7 @@
#include "deco.h"
+/* types */
typedef struct waypoint_t {
double depth;
double time;
@@ -26,6 +27,10 @@ typedef enum segtype_t {
SEG_TRAVEL,
} segtype_t;
+/* global variables */
+extern int SWITCH_INTERMEDIATE;
+
+/* functions */
typedef void (*waypoint_callback_t)(const decostate_t *ds, const waypoint_t, const segtype_t);
const gas_t *best_gas(const double depth, const gas_t *gasses, const int nof_gasses);