]> git.tdb.fi Git - ext/subsurface.git/blob - dive.h
Split up profile frame generation into its own file.
[ext/subsurface.git] / dive.h
1 #ifndef DIVE_H
2 #define DIVE_H
3
4 /*
5  * Some silly typedefs to make our units very explicit.
6  *
7  * Also, the units are chosen so that values can be expressible as
8  * integers, so that we never have FP rounding issues. And they
9  * are small enough that converting to/from imperial units doesn't
10  * really matter.
11  *
12  * We also strive to make '0' a meaningless number saying "not
13  * initialized", since many values are things that may not have
14  * been reported (eg tank pressure or temperature from dive
15  * computers that don't support them). But sometimes -1 is an even
16  * more explicit way of saying "not there".
17  *
18  * Thus "millibar" for pressure, for example, or "millikelvin" for
19  * temperatures. Doing temperatures in celsius or fahrenheit would
20  * make for loss of precision when converting from one to the other,
21  * and using millikelvin is SI-like but also means that a temperature
22  * of '0' is clearly just a missing temperature or tank pressure.
23  *
24  * Also strive to use units that can not possibly be mistaken for a
25  * valid value in a "normal" system without conversion. If the max
26  * depth of a dive is '20000', you probably didn't convert from mm on
27  * output, or if the max depth gets reported as "0.2ft" it was either
28  * a really boring dive, or there was some missing input conversion,
29  * and a 60-ft dive got recorded as 60mm.
30  *
31  * Doing these as "structs containing value" means that we always
32  * have to explicitly write out those units in order to get at the
33  * actual value. So there is hopefully little fear of using a value
34  * in millikelvin as Fahrenheit by mistake.
35  *
36  * We don't actually use these all yet, so maybe they'll change, but
37  * I made a number of types as guidelines.
38  */
39 typedef struct {
40         int seconds;
41 } duration_t;
42
43 typedef struct {
44         int mm;
45 } depth_t;
46
47 typedef struct {
48         int mbar;
49 } pressure_t;
50
51 typedef struct {
52         int mkelvin;
53 } temperature_t;
54
55 typedef struct {
56         int mliter;
57 } volume_t;
58
59 typedef struct {
60         int permille;
61 } fraction_t;
62
63 typedef struct {
64         int grams;
65 } weight_t;
66
67 typedef struct {
68         fraction_t o2;
69         fraction_t n2;
70         fraction_t he2;
71 } gasmix_t;
72
73 typedef struct {
74         volume_t size;
75         pressure_t pressure;
76 } tank_type_t;
77
78 static inline int to_feet(depth_t depth)
79 {
80         return depth.mm * 0.00328084 + 0.5;
81 }
82
83 static inline int to_C(temperature_t temp)
84 {
85         if (!temp.mkelvin)
86                 return 0;
87         return (temp.mkelvin - 273150) / 1000;
88 }
89
90 static inline int to_PSI(pressure_t pressure)
91 {
92         return pressure.mbar * 0.0145037738 + 0.5;
93 }
94
95 struct sample {
96         duration_t time;
97         depth_t depth;
98         temperature_t temperature;
99         pressure_t tankpressure;
100         int tankindex;
101 };
102
103 struct dive {
104         const char *name;
105         time_t when;
106         depth_t maxdepth, meandepth;
107         duration_t duration, surfacetime;
108         depth_t visibility;
109         temperature_t airtemp, watertemp;
110         pressure_t beginning_pressure, end_pressure;
111         int samples;
112         struct sample sample[];
113 };
114
115 extern int verbose;
116
117 struct dive_table {
118         int nr, allocated;
119         struct dive **dives;
120 };
121
122 extern struct dive_table dive_table;
123
124 extern void parse_xml_init(void);
125 extern void parse_xml_file(const char *filename);
126
127 #endif /* DIVE_H */