aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2023-01-05 09:29:45 +0100
committerGravatar Tim Segers <tsegers@pm.me>2023-01-07 15:24:51 +0100
commit5b8235cb3cbf04e903ca0ab337ad57a52e450dd2 (patch)
tree7128e03325db374389ba40d28f2d59e9e46314a4
parent9abb518efdbe45dee564add30b2b5c597cd6e73a (diff)
downloadopendeco-5b8235cb3cbf04e903ca0ab337ad57a52e450dd2.tar.gz
Restructure main()
-rw-r--r--src/opendeco.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/opendeco.c b/src/opendeco.c
index 6f8711e..79b1f98 100644
--- a/src/opendeco.c
+++ b/src/opendeco.c
@@ -139,11 +139,22 @@ int parse_gasses(gas_t **gasses, char *str)
return nof_gasses;
}
+void apply_arguments(struct arguments *arguments)
+{
+ SURFACE_PRESSURE = arguments->SURFACE_PRESSURE;
+ SWITCH_INTERMEDIATE = arguments->SWITCH_INTERMEDIATE;
+ LAST_STOP_AT_SIX = arguments->LAST_STOP_AT_SIX;
+ RMV_DIVE = arguments->RMV_DIVE;
+ RMV_DECO = arguments->RMV_DECO;
+ SHOW_TRAVEL = arguments->SHOW_TRAVEL;
+ UNITS = arguments->UNITS;
+}
+
int main(int argc, char *argv[])
{
setlocale(LC_ALL, "en_US.utf8");
- /* argp */
+ /* get conf and cli options */
char *gas_default = strdup("Air");
char *decogasses_default = strdup("");
@@ -167,29 +178,27 @@ int main(int argc, char *argv[])
opendeco_argp_parse(argc, argv, &arguments);
/* apply global options */
- SURFACE_PRESSURE = arguments.SURFACE_PRESSURE;
- SWITCH_INTERMEDIATE = arguments.SWITCH_INTERMEDIATE;
- LAST_STOP_AT_SIX = arguments.LAST_STOP_AT_SIX;
- RMV_DIVE = arguments.RMV_DIVE;
- RMV_DECO = arguments.RMV_DECO;
- SHOW_TRAVEL = arguments.SHOW_TRAVEL;
- UNITS = arguments.UNITS;
+ apply_arguments(&arguments);
/* setup */
decostate_t ds;
- init_decostate(&ds, arguments.gflow, arguments.gfhigh, xsw_to_bar(msw_or_fsw(3, 10)));
+ decostate_t ds_p5;
+ gas_t bottom_gas;
+ gas_t *deco_gasses;
+
+ double depth;
+ const gas_t *gas;
+
double dec_per_min = xsw_to_bar(msw_or_fsw(9, 30));
+ int nof_gasses = parse_gasses(&deco_gasses, arguments.decogasses);
- gas_t bottom_gas;
+ init_decostate(&ds, arguments.gflow, arguments.gfhigh, xsw_to_bar(msw_or_fsw(3, 10)));
if (scan_gas(&bottom_gas, arguments.gas)) {
wprintf(L"Invalid gas (%s). Aborting!\n", arguments.gas);
exit(-1);
}
- gas_t *deco_gasses;
- int nof_gasses = parse_gasses(&deco_gasses, arguments.decogasses);
-
/* override oxygen mod */
for (int i = 0; i < nof_gasses; i++)
if (gas_o2(&deco_gasses[i]) == 100)
@@ -210,23 +219,23 @@ int main(int argc, char *argv[])
};
print_planhead();
- simulate_dive(&ds, waypoints, len(waypoints), &print_segment_callback);
- /* generate deco schedule */
- double depth = waypoints[len(waypoints) - 1].depth;
- const gas_t *gas = waypoints[len(waypoints) - 1].gas;
+ simulate_dive(&ds, waypoints, len(waypoints), &print_segment_callback);
- /* determine @+5 TTS */
- decostate_t ds_ = ds;
- add_segment_const(&ds_, depth, 5, gas);
- decoinfo_t di_plus5 = calc_deco(&ds_, depth, gas, deco_gasses, nof_gasses, NULL);
+ depth = waypoints[len(waypoints) - 1].depth;
+ gas = waypoints[len(waypoints) - 1].gas;
+ ds_p5 = ds;
- /* print actual deco schedule */
+ /* calculate deco */
decoinfo_t di = calc_deco(&ds, depth, gas, deco_gasses, nof_gasses, &print_segment_callback);
+ /* calculate @+5 TTS */
+ add_segment_const(&ds_p5, depth, 5, gas);
+ decoinfo_t di_p5 = calc_deco(&ds_p5, depth, gas, deco_gasses, nof_gasses, NULL);
+
/* output deco info and disclaimer */
wprintf(L"\nNDL: %imin TTS: %imin TTS @+5: %imin\n", (int) floor(di.ndl), (int) ceil(di.tts),
- (int) ceil(di_plus5.tts));
+ (int) ceil(di_p5.tts));
print_planfoot(&ds);
print_gas_use();
print_disclaimer();