aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/units.c
blob: 519f4c2c7a4a005725ec1b800c6fc0bdc4c43d8e (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
/* SPDX-License-Identifier: MIT-0 */

#include <assert.h>

#include "units.h"

enum UNITS UNITS = UNITS_DEFAULT;
double SURFACE_PRESSURE = SURFACE_PRESSURE_DEFAULT;

double bar_to_msw(double bar)
{
    return bar * 10;
}

double msw_to_bar(double msw)
{
    return msw / 10;
}

double bar_to_fsw(double bar)
{
    return (bar / 1.01325) * 33.0;
}

double fsw_to_bar(double fsw)
{
    return (fsw * 1.01325) / 33.0;
}

double msw_or_fsw(double msw, double fsw)
{
    assert(UNITS == METRIC || UNITS == IMPERIAL);

    return (UNITS == METRIC) ? msw : fsw;
}

double xsw_to_bar(double xsw)
{
    assert(UNITS == METRIC || UNITS == IMPERIAL);

    return (UNITS == METRIC) ? msw_to_bar(xsw) : fsw_to_bar(xsw);
}

double bar_to_xsw(double bar)
{
    assert(UNITS == METRIC || UNITS == IMPERIAL);

    return (UNITS == METRIC) ? bar_to_msw(bar) : bar_to_fsw(bar);
}

double abs_depth(double gd)
{
    return gd + SURFACE_PRESSURE;
}

double gauge_depth(double ad)
{
    return ad - SURFACE_PRESSURE;
}