From 879de8903e617d9e172a36045dc1b7b7ca4250c1 Mon Sep 17 00:00:00 2001 From: Tim Segers Date: Wed, 12 Oct 2022 16:04:51 +0200 Subject: Add option to perform last deco stop at 6m instead of 3m --- src/deco.c | 9 ++++++++- src/deco.h | 4 ++++ src/opendeco.c | 15 ++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/deco.c b/src/deco.c index a03ed34..204a2a7 100644 --- a/src/deco.c +++ b/src/deco.c @@ -15,6 +15,8 @@ double P_WV = P_WV_DEFAULT; double PO2_MAX = PO2_MAX_DEFAULT; double END_MAX = END_MAX_DEFAULT; +int LAST_STOP_AT_SIX = LAST_STOP_AT_SIX_DEFAULT; + typedef struct zhl_n2_t { double t; double a[3]; @@ -213,7 +215,12 @@ double round_ceiling(const decostate_t *ds, const double c) { assert(ds->ceil_multiple != 0); - return abs_depth(ds->ceil_multiple * ceil(RND(gauge_depth(c) / ds->ceil_multiple))); + int numbered_stop = ceil(RND(gauge_depth(c) / ds->ceil_multiple)); + + if (numbered_stop == 1 && LAST_STOP_AT_SIX) + numbered_stop = 2; + + return abs_depth(ds->ceil_multiple * numbered_stop); } double ceiling(const decostate_t *ds, double gf) diff --git a/src/deco.h b/src/deco.h index 16072a1..11f6bc9 100644 --- a/src/deco.h +++ b/src/deco.h @@ -20,6 +20,8 @@ #define PO2_MAX_DEFAULT 1.6 #define END_MAX_DEFAULT 4.01325 +#define LAST_STOP_AT_SIX_DEFAULT 0 + #define MOD_AUTO 0 /* types */ @@ -54,6 +56,8 @@ extern double P_WV; extern double PO2_MAX; extern double END_MAX; +extern int LAST_STOP_AT_SIX; + /* functions */ double bar_to_msw(const double bar); double msw_to_bar(const double msw); diff --git a/src/opendeco.c b/src/opendeco.c index 9329383..ae95f58 100644 --- a/src/opendeco.c +++ b/src/opendeco.c @@ -38,6 +38,7 @@ static struct argp_option options[] = { {"gfhigh", 'h', "NUMBER", 0, "Set the gradient factor at the surface, defaults to 75", 5}, {"decogasses", 'G', "LIST", 0, "Set the gasses available for deco", 6}, {0, 's', 0, OPTION_ARG_OPTIONAL, "Only switch gas at deco stops", 7}, + {0, '6', 0, OPTION_ARG_OPTIONAL, "Perform last deco stop at 6m", 8}, {0, 0, 0, 0, "Informational options:", 0}, {0, 0, 0, 0, 0, 0} }; @@ -51,6 +52,7 @@ struct arguments { char *decogasses; double SURFACE_PRESSURE; int SWITCH_INTERMEDIATE; + int LAST_STOP_AT_SIX; }; static error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -73,6 +75,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) case 's': arguments->SWITCH_INTERMEDIATE = 0; break; + case '6': + arguments->LAST_STOP_AT_SIX = 1; + break; case 'G': arguments->decogasses = arg; break; @@ -174,17 +179,17 @@ int main(int argc, char *argv[]) .gflow = 30, .gfhigh = 75, .decogasses = "", - .SURFACE_PRESSURE = 0, - .SWITCH_INTERMEDIATE = 1, + .SURFACE_PRESSURE = SURFACE_PRESSURE_DEFAULT, + .SWITCH_INTERMEDIATE = SWITCH_INTERMEDIATE_DEFAULT, + .LAST_STOP_AT_SIX = LAST_STOP_AT_SIX_DEFAULT, }; argp_parse(&argp, argc, argv, 0, 0, &arguments); /* apply global options */ - if (arguments.SURFACE_PRESSURE > 0) - SURFACE_PRESSURE = arguments.SURFACE_PRESSURE; - + SURFACE_PRESSURE = arguments.SURFACE_PRESSURE; SWITCH_INTERMEDIATE = arguments.SWITCH_INTERMEDIATE; + LAST_STOP_AT_SIX = arguments.LAST_STOP_AT_SIX; /* setup */ decostate_t ds; -- cgit v1.2.3-70-g09d2