8 * Some silly typedefs to make our units very explicit.
10 * Also, the units are chosen so that values can be expressible as
11 * integers, so that we never have FP rounding issues. And they
12 * are small enough that converting to/from imperial units doesn't
15 * We also strive to make '0' a meaningless number saying "not
16 * initialized", since many values are things that may not have
17 * been reported (eg tank pressure or temperature from dive
18 * computers that don't support them). But sometimes -1 is an even
19 * more explicit way of saying "not there".
21 * Thus "millibar" for pressure, for example, or "millikelvin" for
22 * temperatures. Doing temperatures in celsius or fahrenheit would
23 * make for loss of precision when converting from one to the other,
24 * and using millikelvin is SI-like but also means that a temperature
25 * of '0' is clearly just a missing temperature or tank pressure.
27 * Also strive to use units that can not possibly be mistaken for a
28 * valid value in a "normal" system without conversion. If the max
29 * depth of a dive is '20000', you probably didn't convert from mm on
30 * output, or if the max depth gets reported as "0.2ft" it was either
31 * a really boring dive, or there was some missing input conversion,
32 * and a 60-ft dive got recorded as 60mm.
34 * Doing these as "structs containing value" means that we always
35 * have to explicitly write out those units in order to get at the
36 * actual value. So there is hopefully little fear of using a value
37 * in millikelvin as Fahrenheit by mistake.
39 * We don't actually use these all yet, so maybe they'll change, but
40 * I made a number of types as guidelines.
80 static inline int to_feet(depth_t depth)
82 return depth.mm * 0.00328084 + 0.5;
85 static inline int to_C(temperature_t temp)
89 return (temp.mkelvin - 273150) / 1000;
92 static inline int to_PSI(pressure_t pressure)
94 return pressure.mbar * 0.0145037738 + 0.5;
100 temperature_t temperature;
101 pressure_t tankpressure;
105 #define MAX_MIXES (4)
112 depth_t maxdepth, meandepth;
113 duration_t duration, surfacetime;
115 temperature_t airtemp, watertemp;
116 pressure_t beginning_pressure, end_pressure;
117 gasmix_t gasmix[MAX_MIXES];
119 struct sample sample[];
129 extern struct dive_table dive_table;
131 static inline struct dive *get_dive(unsigned int nr)
133 if (nr >= dive_table.nr)
135 return dive_table.dives[nr];
138 extern void parse_xml_init(void);
139 extern void parse_xml_file(const char *filename);
141 extern void flush_dive_info_changes(void);
142 extern void save_dives(const char *filename);
144 static inline unsigned int dive_size(int samples)
146 return sizeof(struct dive) + samples*sizeof(struct sample);
149 extern struct dive *fixup_dive(struct dive *dive);
150 extern struct dive *try_to_merge(struct dive *a, struct dive *b);