10 * Some silly typedefs to make our units very explicit.
12 * Also, the units are chosen so that values can be expressible as
13 * integers, so that we never have FP rounding issues. And they
14 * are small enough that converting to/from imperial units doesn't
17 * We also strive to make '0' a meaningless number saying "not
18 * initialized", since many values are things that may not have
19 * been reported (eg cylinder pressure or temperature from dive
20 * computers that don't support them). But sometimes -1 is an even
21 * more explicit way of saying "not there".
23 * Thus "millibar" for pressure, for example, or "millikelvin" for
24 * temperatures. Doing temperatures in celsius or fahrenheit would
25 * make for loss of precision when converting from one to the other,
26 * and using millikelvin is SI-like but also means that a temperature
27 * of '0' is clearly just a missing temperature or cylinder pressure.
29 * Also strive to use units that can not possibly be mistaken for a
30 * valid value in a "normal" system without conversion. If the max
31 * depth of a dive is '20000', you probably didn't convert from mm on
32 * output, or if the max depth gets reported as "0.2ft" it was either
33 * a really boring dive, or there was some missing input conversion,
34 * and a 60-ft dive got recorded as 60mm.
36 * Doing these as "structs containing value" means that we always
37 * have to explicitly write out those units in order to get at the
38 * actual value. So there is hopefully little fear of using a value
39 * in millikelvin as Fahrenheit by mistake.
41 * We don't actually use these all yet, so maybe they'll change, but
42 * I made a number of types as guidelines.
79 pressure_t workingpressure;
80 const char *description; /* "LP85", "AL72", "AL80", "HP100+" or whatever */
86 pressure_t start, end;
89 static inline int to_feet(depth_t depth)
91 return depth.mm * 0.00328084 + 0.5;
94 static inline int to_C(temperature_t temp)
98 return (temp.mkelvin - 273150 + 499) / 1000;
101 static inline int to_F(temperature_t temp)
105 return temp.mkelvin * 9 / 5000.0 - 459.670 + 0.5;
108 static inline int to_K(temperature_t temp)
112 return (temp.mkelvin + 499)/1000;
115 static inline int to_PSI(pressure_t pressure)
117 return pressure.mbar * 0.0145037738 + 0.5;
123 temperature_t temperature;
124 pressure_t cylinderpressure;
128 #define MAX_CYLINDERS (8)
134 depth_t maxdepth, meandepth;
135 duration_t duration, surfacetime;
137 temperature_t airtemp, watertemp;
138 cylinder_t cylinder[MAX_CYLINDERS];
140 struct sample sample[];
144 * We keep our internal data in well-specified units, but
145 * the input and output may come in some random format. This
146 * keeps track of those units.
149 enum { METERS, FEET } length;
150 enum { LITER, CUFT } volume;
151 enum { BAR, PSI, PASCAL } pressure;
152 enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
153 enum { KG, LBS } weight;
156 extern const struct units SI_units, IMPERIAL_units;
157 extern struct units input_units, output_units;
166 extern struct dive_table dive_table;
168 static inline struct dive *get_dive(unsigned int nr)
170 if (nr >= dive_table.nr)
172 return dive_table.dives[nr];
175 extern void parse_xml_init(void);
176 extern void parse_xml_file(const char *filename, GError **error);
178 extern void flush_dive_info_changes(void);
179 extern void save_dives(const char *filename);
181 static inline unsigned int dive_size(int samples)
183 return sizeof(struct dive) + samples*sizeof(struct sample);
186 extern struct dive *fixup_dive(struct dive *dive);
187 extern struct dive *try_to_merge(struct dive *a, struct dive *b);
189 #define DIVE_ERROR_PARSE 1