aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/deco.h
blob: 3d87b154c88aca47d8f96c4bcb57019df21d8738 (plain) (blame)
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
/* SPDX-License-Identifier: MIT-0 */

#ifndef DECO_H
#define DECO_H

#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]))

#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 ALGO_VER_DEFAULT ZHL_16C
#define P_WV_DEFAULT P_WV_BUHL

/* types */
enum ALGO {
    ZHL_16A = 0,
    ZHL_16B = 1,
    ZHL_16C = 2,
};

typedef struct decostate_t {
    double pn2[16];
    double phe[16];
    unsigned char gflo;
    unsigned char gfhi;
    double firststop;
    double max_depth;
    double ceil_multiple;
    const gas_t *gas;
    double depth;
    double runtime;
} decostate_t;

/* global variables */
extern enum ALGO ALGO_VER;
extern double P_WV;

extern double PO2_MAX;
extern double END_MAX;

/* functions */
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);
double ceiling(const decostate_t *ds, double gf);
double gf99(const decostate_t *ds, double depth);

void init_decostate(decostate_t *ds, unsigned char gflo, unsigned char gfhi, double ceil_multiple);

double ppO2(double depth, const gas_t *gas);
double end(double depth, const gas_t *gas);
double ead(double depth, const gas_t *gas);

#endif /* end of include guard: DECO_H */