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 get_pressure_units(unsigned int mb, const char **units);
91 extern double get_depth_units(unsigned int mm, int *frac, const char **units);
92 extern double get_volume_units(unsigned int mm, int *frac, const char **units);
93 extern double get_temp_units(unsigned int mm, const char **units);
95 static inline double ml_to_cuft(int ml)
97 return ml / 28316.8466;
100 static inline double cuft_to_l(double cuft)
102 return cuft * 28.3168466;
105 static inline double mm_to_feet(int mm)
107 return mm * 0.00328084;
110 static inline int to_feet(depth_t depth)
112 return mm_to_feet(depth.mm) + 0.5;
115 static double mkelvin_to_C(int mkelvin)
117 return (mkelvin - 273150) / 1000.0;
120 static double mkelvin_to_F(int mkelvin)
122 return mkelvin * 9 / 5000.0 - 459.670;
125 static inline int to_C(temperature_t temp)
129 return mkelvin_to_C(temp.mkelvin) + 0.5;
132 static inline int to_F(temperature_t temp)
136 return mkelvin_to_F(temp.mkelvin) + 0.5;
139 static inline int to_K(temperature_t temp)
143 return (temp.mkelvin + 499)/1000;
146 static inline double psi_to_bar(double psi)
148 return psi / 14.5037738;
150 static inline int to_PSI(pressure_t pressure)
152 return pressure.mbar * 0.0145037738 + 0.5;
155 static inline double bar_to_atm(double bar)
157 return bar / 1.01325;
160 static inline double to_ATM(pressure_t pressure)
162 return pressure.mbar / 1013.25;
165 static inline int mbar_to_PSI(int mbar)
167 pressure_t p = {mbar};
174 temperature_t temperature;
175 pressure_t cylinderpressure;
180 * Events are currently pretty meaningless. This is
181 * just based on the random data that libdivecomputer
182 * gives us. I'm not sure what a real "architected"
183 * event model would actually look like, but right
184 * now you can associate a list of events with a dive,
185 * and we'll do something about it.
190 int type, flags, value;
194 #define MAX_CYLINDERS (8)
201 char *divemaster, *buddy;
202 double latitude, longitude;
203 depth_t maxdepth, meandepth;
204 duration_t duration, surfacetime;
206 temperature_t airtemp, watertemp;
207 cylinder_t cylinder[MAX_CYLINDERS];
209 struct event *events;
210 int samples, alloc_samples;
211 struct sample sample[];
215 * We keep our internal data in well-specified units, but
216 * the input and output may come in some random format. This
217 * keeps track of those units.
219 /* turns out in Win32 PASCAL is defined as a calling convention */
224 enum { METERS, FEET } length;
225 enum { LITER, CUFT } volume;
226 enum { BAR, PSI, PASCAL } pressure;
227 enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
228 enum { KG, LBS } weight;
231 extern const struct units SI_units, IMPERIAL_units;
232 extern struct units input_units, output_units;
237 int nr, allocated, preexisting;
241 extern struct dive_table dive_table;
243 extern int selected_dive;
244 #define current_dive (get_dive(selected_dive))
246 static inline struct dive *get_dive(unsigned int nr)
248 if (nr >= dive_table.nr)
250 return dive_table.dives[nr];
253 extern void parse_xml_init(void);
254 extern void parse_xml_file(const char *filename, GError **error);
255 extern void set_filename(const char *filename);
258 extern xmlDoc *test_xslt_transforms(xmlDoc *doc);
261 extern void show_dive_info(struct dive *);
263 extern void show_dive_equipment(struct dive *);
265 extern void show_dive_stats(struct dive *);
267 extern void update_dive(struct dive *new_dive);
268 extern void save_dives(const char *filename);
270 static inline unsigned int dive_size(int samples)
272 return sizeof(struct dive) + samples*sizeof(struct sample);
275 extern time_t utc_mktime(struct tm *tm);
277 extern struct dive *alloc_dive(void);
278 extern void record_dive(struct dive *dive);
280 extern struct sample *prepare_sample(struct dive **divep);
281 extern void finish_sample(struct dive *dive, struct sample *sample);
283 extern void report_dives(gboolean imported);
284 extern struct dive *fixup_dive(struct dive *dive);
285 extern struct dive *try_to_merge(struct dive *a, struct dive *b);
287 extern void renumber_dives(int nr);
289 extern void add_event(struct dive *dive, int time, int type, int flags, int value, const char *name);
291 /* UI related protopypes */
293 extern void init_ui(int *argcp, char ***argvp);
295 extern void run_ui(void);
297 extern void report_error(GError* error);
299 extern void add_cylinder_description(cylinder_type_t *);
300 extern void add_people(const char *string);
301 extern void add_location(const char *string);
302 extern void remember_event(const char *eventname);
303 extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
305 extern int edit_dive_info(struct dive *dive);
306 extern void dive_list_update_dives(void);
307 extern void flush_divelist(struct dive *dive);
309 #define DIVE_ERROR_PARSE 1
311 const char *weekday(int wday);
312 const char *monthname(int mon);
314 #define UTF8_DEGREE "\xc2\xb0"
315 #define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"