1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* SPDX-License-Identifier: MIT-0 */
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "output.h"
#include "units.h"
#define DEPTHUNIT ((UNITS == METRIC) ? "m " : "ft")
void format_mm_ss(char *buf, size_t buflen, double time)
{
double mm;
double ss = round(modf(time, &mm) * 60);
/* prevents 0.99999 minutes showing as 00:60 */
mm += ss / 60;
ss = (int) ss % 60;
snprintf(buf, buflen, "%3i:%02i", (int) mm, (int) ss);
}
void format_gas(char *buf, size_t buflen, const gas_t *gas)
{
if (gas_o2(gas) == 21 && gas_he(gas) == 0)
snprintf(buf, buflen, "Air");
else if (gas_o2(gas) == 100)
snprintf(buf, buflen, "Oxygen");
else if (gas_he(gas) == 0)
snprintf(buf, buflen, "Nitrox %i", gas_o2(gas));
else
snprintf(buf, buflen, "%i/%i", gas_o2(gas), gas_he(gas));
}
int scan_gas(gas_t *gas, char *str)
{
int o2 = 0;
int he = 0;
if (!strcmp(str, "Air")) {
o2 = 21;
goto match;
}
if (!strcmp(str, "Oxygen")) {
o2 = 100;
goto match;
}
if (sscanf(str, "%i/%i", &o2, &he) == 2)
goto match;
if (sscanf(str, "EAN %i", &o2) == 1)
goto match;
if (sscanf(str, "Nitrox %i", &o2) == 1)
goto match;
if (sscanf(str, "%i", &o2) == 1)
goto match;
return -EINVAL;
match:
if (o2 < 0 || he < 0)
return -EINVAL;
if (o2 + he > 100)
return -EINVAL;
*gas = gas_new(o2, he, MOD_AUTO);
return 0;
}
void print_planhead(void)
{
wprintf(L"DIVE PLAN\n\n");
wprintf(L" %-1s %6s %8s %-7s %1s %-9s %4s %5s\n", "", "Depth", "Duration", "Runtime", "", "Gas", "pO2",
"EAD");
}
void print_planline(wchar_t sign, double depth, double time, double runtime, const gas_t *gas)
{
static char gasbuf[11];
static char runbuf[8];
static char pO2buf[5];
static char eadbuf[6];
static char timbuf[16];
static gas_t last_gas;
const int depth_x = round(bar_to_xsw(gauge_depth(depth)));
const int ead_x = round(bar_to_xsw(max(0, gauge_depth(ead(depth, gas)))));
wchar_t swi = L' ';
snprintf(runbuf, len(runbuf), "(%i)", (int) ceil(runtime));
format_gas(gasbuf, len(gasbuf), gas);
format_mm_ss(timbuf, len(timbuf), time);
/* print gas swich symbol if gas changed */
if (!gas_equal(gas, &last_gas)) {
last_gas = *gas;
swi = SWI;
}
/* only print ead and pO2 on stops */
if (sign == LVL) {
snprintf(eadbuf, 6, "%3i%s", ead_x, DEPTHUNIT);
snprintf(pO2buf, 5, "%4.2f", ppO2(depth, gas));
} else {
snprintf(eadbuf, 6, "%5s", "-");
snprintf(pO2buf, 5, "%4s", "-");
}
wprintf(L" %lc %4i%2s %8s %-7s %lc %-9s %s %s\n", sign, depth_x, DEPTHUNIT, timbuf, runbuf, swi, gasbuf,
pO2buf, eadbuf);
}
void print_planfoot(const decostate_t *ds)
{
char *model;
char *rq;
if (ALGO_VER == ZHL_16A)
model = "ZHL-16A";
else if (ALGO_VER == ZHL_16B)
model = "ZHL-16B";
else if (ALGO_VER == ZHL_16C)
model = "ZHL-16C";
else
model = "???";
if (P_WV == P_WV_BUHL)
rq = "1.0";
else if (P_WV == P_WV_NAVY)
rq = "0.9";
else if (P_WV == P_WV_SCHR)
rq = "0.8";
else
rq = "???";
wprintf(L"\nDeco model: Buhlmann %s\n", model);
wprintf(L"Conservatism: GF %i/%i, Rq = %s\n", ds->gflo, ds->gfhi, rq);
wprintf(L"Surface pressure: %4.3fbar\n", SURFACE_PRESSURE);
}
void print_disclaimer(void)
{
wprintf(L"\nWARNING: DIVE PLAN MAY BE INACCURATE AND MAY CONTAIN\nERRORS THAT COULD LEAD TO INJURY OR DEATH.\n");
}
|