8 #include <libxml/tree.h>
11 * Some silly typedefs to make our units very explicit.
13 * Also, the units are chosen so that values can be expressible as
14 * integers, so that we never have FP rounding issues. And they
15 * are small enough that converting to/from imperial units doesn't
18 * We also strive to make '0' a meaningless number saying "not
19 * initialized", since many values are things that may not have
20 * been reported (eg cylinder pressure or temperature from dive
21 * computers that don't support them). But sometimes -1 is an even
22 * more explicit way of saying "not there".
24 * Thus "millibar" for pressure, for example, or "millikelvin" for
25 * temperatures. Doing temperatures in celsius or fahrenheit would
26 * make for loss of precision when converting from one to the other,
27 * and using millikelvin is SI-like but also means that a temperature
28 * of '0' is clearly just a missing temperature or cylinder pressure.
30 * Also strive to use units that can not possibly be mistaken for a
31 * valid value in a "normal" system without conversion. If the max
32 * depth of a dive is '20000', you probably didn't convert from mm on
33 * output, or if the max depth gets reported as "0.2ft" it was either
34 * a really boring dive, or there was some missing input conversion,
35 * and a 60-ft dive got recorded as 60mm.
37 * Doing these as "structs containing value" means that we always
38 * have to explicitly write out those units in order to get at the
39 * actual value. So there is hopefully little fear of using a value
40 * in millikelvin as Fahrenheit by mistake.
42 * We don't actually use these all yet, so maybe they'll change, but
43 * I made a number of types as guidelines.
80 pressure_t workingpressure;
81 const char *description; /* "LP85", "AL72", "AL80", "HP100+" or whatever */
87 pressure_t start, end, sample_start, sample_end;
92 const char *description; /* "integrated", "belt", "ankle" */
95 extern int cylinder_none(void *_data);
96 extern int weightsystem_none(void *_data);
98 extern int get_pressure_units(unsigned int mb, const char **units);
99 extern double get_depth_units(unsigned int mm, int *frac, const char **units);
100 extern double get_volume_units(unsigned int ml, int *frac, const char **units);
101 extern double get_temp_units(unsigned int mk, const char **units);
102 extern double get_weight_units(unsigned int grams, int *frac, const char **units);
104 static inline double grams_to_lbs(int grams)
106 return grams / 453.6;
109 static inline int lbs_to_grams(double lbs)
111 return lbs * 453.6 + 0.5;
114 static inline double ml_to_cuft(int ml)
116 return ml / 28316.8466;
119 static inline double cuft_to_l(double cuft)
121 return cuft * 28.3168466;
124 static inline double mm_to_feet(int mm)
126 return mm * 0.00328084;
129 static inline unsigned long feet_to_mm(double feet)
131 return feet * 304.8 + 0.5;
134 static inline int to_feet(depth_t depth)
136 return mm_to_feet(depth.mm) + 0.5;
139 static inline double mkelvin_to_C(int mkelvin)
141 return (mkelvin - 273150) / 1000.0;
144 static inline double mkelvin_to_F(int mkelvin)
146 return mkelvin * 9 / 5000.0 - 459.670;
149 static inline unsigned long F_to_mkelvin(double f)
151 return (f-32) * 1000 / 1.8 + 273150.5;
154 static inline int to_C(temperature_t temp)
158 return mkelvin_to_C(temp.mkelvin) + 0.5;
161 static inline int to_F(temperature_t temp)
165 return mkelvin_to_F(temp.mkelvin) + 0.5;
168 static inline int to_K(temperature_t temp)
172 return (temp.mkelvin + 499)/1000;
175 static inline double psi_to_bar(double psi)
177 return psi / 14.5037738;
180 static inline unsigned long psi_to_mbar(double psi)
182 return psi_to_bar(psi)*1000 + 0.5;
185 static inline int to_PSI(pressure_t pressure)
187 return pressure.mbar * 0.0145037738 + 0.5;
190 static inline double bar_to_atm(double bar)
192 return bar / 1.01325;
195 static inline double to_ATM(pressure_t pressure)
197 return pressure.mbar / 1013.25;
200 static inline int mbar_to_PSI(int mbar)
202 pressure_t p = {mbar};
209 temperature_t temperature;
210 pressure_t cylinderpressure;
215 * Events are currently pretty meaningless. This is
216 * just based on the random data that libdivecomputer
217 * gives us. I'm not sure what a real "architected"
218 * event model would actually look like, but right
219 * now you can associate a list of events with a dive,
220 * and we'll do something about it.
225 int type, flags, value;
229 #define MAX_CYLINDERS (8)
230 #define MAX_WEIGHTSYSTEMS (4)
231 #define W_IDX_PRIMARY 0
232 #define W_IDX_SECONDARY 1
239 char *divemaster, *buddy;
241 double latitude, longitude;
242 depth_t maxdepth, meandepth;
243 duration_t duration, surfacetime;
245 temperature_t airtemp, watertemp;
246 cylinder_t cylinder[MAX_CYLINDERS];
247 weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
250 struct event *events;
251 int samples, alloc_samples;
252 struct sample sample[];
256 * We keep our internal data in well-specified units, but
257 * the input and output may come in some random format. This
258 * keeps track of those units.
260 /* turns out in Win32 PASCAL is defined as a calling convention */
265 enum { METERS, FEET } length;
266 enum { LITER, CUFT } volume;
267 enum { BAR, PSI, PASCAL } pressure;
268 enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
269 enum { KG, LBS } weight;
272 extern const struct units SI_units, IMPERIAL_units;
273 extern struct units input_units, output_units;
278 int nr, allocated, preexisting;
282 extern struct dive_table dive_table;
284 extern int *selectiontracker;
285 extern int selected_dive;
286 #define current_dive (get_dive(selected_dive))
288 static inline struct dive *get_dive(unsigned int nr)
290 if (nr >= dive_table.nr || nr < 0)
292 return dive_table.dives[nr];
295 extern void parse_xml_init(void);
296 extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error);
297 extern void set_filename(const char *filename);
299 extern void parse_file(const char *filename, GError **error);
302 extern xmlDoc *test_xslt_transforms(xmlDoc *doc);
305 extern void show_dive_info(struct dive *);
307 extern void show_dive_equipment(struct dive *, int w_idx);
309 extern void show_dive_stats(struct dive *);
311 extern void update_dive(struct dive *new_dive);
312 extern void save_dives(const char *filename);
314 static inline unsigned int dive_size(int samples)
316 return sizeof(struct dive) + samples*sizeof(struct sample);
319 extern time_t utc_mktime(struct tm *tm);
321 extern struct dive *alloc_dive(void);
322 extern void record_dive(struct dive *dive);
323 extern void delete_dive(struct dive *dive);
325 extern struct sample *prepare_sample(struct dive **divep);
326 extern void finish_sample(struct dive *dive);
328 extern void report_dives(gboolean imported);
329 extern struct dive *fixup_dive(struct dive *dive);
330 extern struct dive *try_to_merge(struct dive *a, struct dive *b);
332 extern void renumber_dives(int nr);
334 extern void add_event(struct dive *dive, int time, int type, int flags, int value, const char *name);
336 /* UI related protopypes */
338 extern void init_ui(int *argcp, char ***argvp);
340 extern void run_ui(void);
341 extern void exit_ui(void);
343 extern void report_error(GError* error);
345 extern void add_cylinder_description(cylinder_type_t *);
346 extern void add_weightsystem_description(weightsystem_t *);
347 extern void add_people(const char *string);
348 extern void add_location(const char *string);
349 extern void add_suit(const char *string);
350 extern void remember_event(const char *eventname);
351 extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
353 extern int add_new_dive(struct dive *dive);
354 extern int edit_dive_info(struct dive *dive);
355 extern int edit_multi_dive_info(int nr, int *indices);
356 extern void dive_list_update_dives(void);
357 extern void flush_divelist(struct dive *dive);
359 #define DIVE_ERROR_PARSE 1
361 const char *weekday(int wday);
362 const char *monthname(int mon);
364 #define UTF8_DEGREE "\xc2\xb0"
365 #define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
366 #define UTF8_WHITESTAR "\xe2\x98\x86"
367 #define UTF8_BLACKSTAR "\xe2\x98\x85"
368 #define ZERO_STARS UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
369 #define ONE_STARS UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
370 #define TWO_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
371 #define THREE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR
372 #define FOUR_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR
373 #define FIVE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
374 extern const char *star_strings[];
376 #define AIR_PERMILLE 209