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 gboolean cylinder_none(void *_data);
96 extern gboolean no_cylinders(cylinder_t *cyl);
97 extern gboolean cylinders_equal(cylinder_t *cyl1, cylinder_t *cyl2);
98 extern void copy_cylinders(cylinder_t *cyl1, cylinder_t *cyl2);
99 extern gboolean no_weightsystems(weightsystem_t *ws);
100 extern gboolean weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2);
102 extern int get_pressure_units(unsigned int mb, const char **units);
103 extern double get_depth_units(unsigned int mm, int *frac, const char **units);
104 extern double get_volume_units(unsigned int ml, int *frac, const char **units);
105 extern double get_temp_units(unsigned int mk, const char **units);
106 extern double get_weight_units(unsigned int grams, int *frac, const char **units);
108 static inline double grams_to_lbs(int grams)
110 return grams / 453.6;
113 static inline int lbs_to_grams(double lbs)
115 return lbs * 453.6 + 0.5;
118 static inline double ml_to_cuft(int ml)
120 return ml / 28316.8466;
123 static inline double cuft_to_l(double cuft)
125 return cuft * 28.3168466;
128 static inline double mm_to_feet(int mm)
130 return mm * 0.00328084;
133 static inline unsigned long feet_to_mm(double feet)
135 return feet * 304.8 + 0.5;
138 static inline int to_feet(depth_t depth)
140 return mm_to_feet(depth.mm) + 0.5;
143 static inline double mkelvin_to_C(int mkelvin)
145 return (mkelvin - 273150) / 1000.0;
148 static inline double mkelvin_to_F(int mkelvin)
150 return mkelvin * 9 / 5000.0 - 459.670;
153 static inline unsigned long F_to_mkelvin(double f)
155 return (f-32) * 1000 / 1.8 + 273150.5;
158 static inline int to_C(temperature_t temp)
162 return mkelvin_to_C(temp.mkelvin) + 0.5;
165 static inline int to_F(temperature_t temp)
169 return mkelvin_to_F(temp.mkelvin) + 0.5;
172 static inline int to_K(temperature_t temp)
176 return (temp.mkelvin + 499)/1000;
179 static inline double psi_to_bar(double psi)
181 return psi / 14.5037738;
184 static inline unsigned long psi_to_mbar(double psi)
186 return psi_to_bar(psi)*1000 + 0.5;
189 static inline int to_PSI(pressure_t pressure)
191 return pressure.mbar * 0.0145037738 + 0.5;
194 static inline double bar_to_atm(double bar)
196 return bar / 1.01325;
199 static inline double to_ATM(pressure_t pressure)
201 return pressure.mbar / 1013.25;
204 static inline int mbar_to_PSI(int mbar)
206 pressure_t p = {mbar};
213 temperature_t temperature;
214 pressure_t cylinderpressure;
219 * Events are currently pretty meaningless. This is
220 * just based on the random data that libdivecomputer
221 * gives us. I'm not sure what a real "architected"
222 * event model would actually look like, but right
223 * now you can associate a list of events with a dive,
224 * and we'll do something about it.
229 int type, flags, value;
233 #define MAX_CYLINDERS (8)
234 #define MAX_WEIGHTSYSTEMS (4)
235 #define W_IDX_PRIMARY 0
236 #define W_IDX_SECONDARY 1
244 char *divemaster, *buddy;
246 double latitude, longitude;
247 depth_t maxdepth, meandepth;
248 duration_t duration, surfacetime;
250 temperature_t airtemp, watertemp;
251 cylinder_t cylinder[MAX_CYLINDERS];
252 weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
255 struct event *events;
256 int samples, alloc_samples;
257 struct sample sample[];
261 * We keep our internal data in well-specified units, but
262 * the input and output may come in some random format. This
263 * keeps track of those units.
265 /* turns out in Win32 PASCAL is defined as a calling convention */
270 enum { METERS, FEET } length;
271 enum { LITER, CUFT } volume;
272 enum { BAR, PSI, PASCAL } pressure;
273 enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
274 enum { KG, LBS } weight;
277 extern const struct units SI_units, IMPERIAL_units;
278 extern struct units input_units, output_units;
283 int nr, allocated, preexisting;
287 extern struct dive_table dive_table;
289 extern int selected_dive;
290 #define current_dive (get_dive(selected_dive))
292 static inline struct dive *get_dive(unsigned int nr)
294 if (nr >= dive_table.nr || nr < 0)
296 return dive_table.dives[nr];
300 * Iterate over each dive, with the first parameter being the index
301 * iterator variable, and the second one being the dive one.
303 * I don't think anybody really wants the index, and we could make
304 * it local to the for-loop, but that would make us requires C99.
306 #define for_each_dive(_i,_x) \
307 for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
309 extern void parse_xml_init(void);
310 extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error);
311 extern void set_filename(const char *filename);
313 extern void parse_file(const char *filename, GError **error);
316 extern xmlDoc *test_xslt_transforms(xmlDoc *doc);
319 extern void show_dive_info(struct dive *);
321 extern void show_dive_equipment(struct dive *, int w_idx);
323 extern void show_dive_stats(struct dive *);
325 extern void update_dive(struct dive *new_dive);
326 extern void save_dives(const char *filename);
328 static inline unsigned int dive_size(int samples)
330 return sizeof(struct dive) + samples*sizeof(struct sample);
333 extern time_t utc_mktime(struct tm *tm);
335 extern struct dive *alloc_dive(void);
336 extern void record_dive(struct dive *dive);
337 extern void delete_dive(struct dive *dive);
339 extern struct sample *prepare_sample(struct dive **divep);
340 extern void finish_sample(struct dive *dive);
342 extern void report_dives(gboolean imported);
343 extern struct dive *fixup_dive(struct dive *dive);
344 extern struct dive *try_to_merge(struct dive *a, struct dive *b);
346 extern void renumber_dives(int nr);
348 extern void add_event(struct dive *dive, int time, int type, int flags, int value, const char *name);
350 /* UI related protopypes */
352 extern void init_ui(int *argcp, char ***argvp);
354 extern void run_ui(void);
355 extern void exit_ui(void);
357 extern void report_error(GError* error);
359 extern void add_cylinder_description(cylinder_type_t *);
360 extern void add_weightsystem_description(weightsystem_t *);
361 extern void add_people(const char *string);
362 extern void add_location(const char *string);
363 extern void add_suit(const char *string);
364 extern void remember_event(const char *eventname);
365 extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
367 extern int add_new_dive(struct dive *dive);
368 extern int edit_dive_info(struct dive *dive);
369 extern int edit_multi_dive_info(struct dive *single_dive);
370 extern void dive_list_update_dives(void);
371 extern void flush_divelist(struct dive *dive);
373 #define DIVE_ERROR_PARSE 1
375 const char *weekday(int wday);
376 const char *monthname(int mon);
378 #define UTF8_DEGREE "\xc2\xb0"
379 #define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
380 #define UTF8_WHITESTAR "\xe2\x98\x86"
381 #define UTF8_BLACKSTAR "\xe2\x98\x85"
382 #define ZERO_STARS UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
383 #define ONE_STARS UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
384 #define TWO_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
385 #define THREE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR
386 #define FOUR_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR
387 #define FIVE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
388 extern const char *star_strings[];
390 #define AIR_PERMILLE 209