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;
90 extern int cylinder_none(cylinder_t *cyl);
92 extern int get_pressure_units(unsigned int mb, const char **units);
93 extern double get_depth_units(unsigned int mm, int *frac, const char **units);
94 extern double get_volume_units(unsigned int mm, int *frac, const char **units);
95 extern double get_temp_units(unsigned int mm, const char **units);
97 static inline double ml_to_cuft(int ml)
99 return ml / 28316.8466;
102 static inline double cuft_to_l(double cuft)
104 return cuft * 28.3168466;
107 static inline double mm_to_feet(int mm)
109 return mm * 0.00328084;
112 static inline int to_feet(depth_t depth)
114 return mm_to_feet(depth.mm) + 0.5;
117 static double mkelvin_to_C(int mkelvin)
119 return (mkelvin - 273150) / 1000.0;
122 static double mkelvin_to_F(int mkelvin)
124 return mkelvin * 9 / 5000.0 - 459.670;
127 static inline int to_C(temperature_t temp)
131 return mkelvin_to_C(temp.mkelvin) + 0.5;
134 static inline int to_F(temperature_t temp)
138 return mkelvin_to_F(temp.mkelvin) + 0.5;
141 static inline int to_K(temperature_t temp)
145 return (temp.mkelvin + 499)/1000;
148 static inline double psi_to_bar(double psi)
150 return psi / 14.5037738;
152 static inline int to_PSI(pressure_t pressure)
154 return pressure.mbar * 0.0145037738 + 0.5;
157 static inline double bar_to_atm(double bar)
159 return bar / 1.01325;
162 static inline double to_ATM(pressure_t pressure)
164 return pressure.mbar / 1013.25;
167 static inline int mbar_to_PSI(int mbar)
169 pressure_t p = {mbar};
176 temperature_t temperature;
177 pressure_t cylinderpressure;
182 * Events are currently pretty meaningless. This is
183 * just based on the random data that libdivecomputer
184 * gives us. I'm not sure what a real "architected"
185 * event model would actually look like, but right
186 * now you can associate a list of events with a dive,
187 * and we'll do something about it.
192 int type, flags, value;
196 #define MAX_CYLINDERS (8)
203 char *divemaster, *buddy;
205 double latitude, longitude;
206 depth_t maxdepth, meandepth;
207 duration_t duration, surfacetime;
209 temperature_t airtemp, watertemp;
210 cylinder_t cylinder[MAX_CYLINDERS];
212 struct event *events;
213 int samples, alloc_samples;
214 struct sample sample[];
218 * We keep our internal data in well-specified units, but
219 * the input and output may come in some random format. This
220 * keeps track of those units.
222 /* turns out in Win32 PASCAL is defined as a calling convention */
227 enum { METERS, FEET } length;
228 enum { LITER, CUFT } volume;
229 enum { BAR, PSI, PASCAL } pressure;
230 enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
231 enum { KG, LBS } weight;
234 extern const struct units SI_units, IMPERIAL_units;
235 extern struct units input_units, output_units;
240 int nr, allocated, preexisting;
244 extern struct dive_table dive_table;
246 extern int selected_dive;
247 #define current_dive (get_dive(selected_dive))
249 static inline struct dive *get_dive(unsigned int nr)
251 if (nr >= dive_table.nr)
253 return dive_table.dives[nr];
256 extern void parse_xml_init(void);
257 extern void parse_xml_file(const char *filename, GError **error);
258 extern void set_filename(const char *filename);
261 extern xmlDoc *test_xslt_transforms(xmlDoc *doc);
264 extern void show_dive_info(struct dive *);
266 extern void show_dive_equipment(struct dive *);
268 extern void show_dive_stats(struct dive *);
270 extern void update_dive(struct dive *new_dive);
271 extern void save_dives(const char *filename);
273 static inline unsigned int dive_size(int samples)
275 return sizeof(struct dive) + samples*sizeof(struct sample);
278 extern time_t utc_mktime(struct tm *tm);
280 extern struct dive *alloc_dive(void);
281 extern void record_dive(struct dive *dive);
283 extern struct sample *prepare_sample(struct dive **divep);
284 extern void finish_sample(struct dive *dive, struct sample *sample);
286 extern void report_dives(gboolean imported);
287 extern struct dive *fixup_dive(struct dive *dive);
288 extern struct dive *try_to_merge(struct dive *a, struct dive *b);
290 extern void renumber_dives(int nr);
292 extern void add_event(struct dive *dive, int time, int type, int flags, int value, const char *name);
294 /* UI related protopypes */
296 extern void init_ui(int *argcp, char ***argvp);
298 extern void run_ui(void);
300 extern void report_error(GError* error);
302 extern void add_cylinder_description(cylinder_type_t *);
303 extern void add_people(const char *string);
304 extern void add_location(const char *string);
305 extern void remember_event(const char *eventname);
306 extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
308 extern int edit_dive_info(struct dive *dive);
309 extern void dive_list_update_dives(void);
310 extern void flush_divelist(struct dive *dive);
312 #define DIVE_ERROR_PARSE 1
314 const char *weekday(int wday);
315 const char *monthname(int mon);
317 #define UTF8_DEGREE "\xc2\xb0"
318 #define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
319 #define UTF8_WHITESTAR "\xe2\x98\x86"
320 #define UTF8_BLACKSTAR "\xe2\x98\x85"
321 #define ZERO_STARS UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
322 #define ONE_STARS UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
323 #define TWO_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
324 #define THREE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR
325 #define FOUR_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR
326 #define FIVE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
327 extern const char *star_strings[];