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 extern int get_pressure_units(unsigned int mb, const char **units);
90 extern double get_depth_units(unsigned int mm, int *frac, const char **units);
91 extern double get_volume_units(unsigned int mm, int *frac, const char **units);
92 extern double get_temp_units(unsigned int mm, const char **units);
94 static inline double ml_to_cuft(int ml)
96 return ml / 28316.8466;
99 static inline double cuft_to_l(double cuft)
101 return cuft * 28.3168466;
104 static inline double mm_to_feet(int mm)
106 return mm * 0.00328084;
109 static inline int to_feet(depth_t depth)
111 return mm_to_feet(depth.mm) + 0.5;
114 static double mkelvin_to_C(int mkelvin)
116 return (mkelvin - 273150) / 1000.0;
119 static double mkelvin_to_F(int mkelvin)
121 return mkelvin * 9 / 5000.0 - 459.670;
124 static inline int to_C(temperature_t temp)
128 return mkelvin_to_C(temp.mkelvin) + 0.5;
131 static inline int to_F(temperature_t temp)
135 return mkelvin_to_F(temp.mkelvin) + 0.5;
138 static inline int to_K(temperature_t temp)
142 return (temp.mkelvin + 499)/1000;
145 static inline double psi_to_bar(double psi)
147 return psi / 14.5037738;
149 static inline int to_PSI(pressure_t pressure)
151 return pressure.mbar * 0.0145037738 + 0.5;
154 static inline double bar_to_atm(double bar)
156 return bar / 1.01325;
159 static inline double to_ATM(pressure_t pressure)
161 return pressure.mbar / 1013.25;
164 static inline int mbar_to_PSI(int mbar)
166 pressure_t p = {mbar};
173 temperature_t temperature;
174 pressure_t cylinderpressure;
179 * Events are currently pretty meaningless. This is
180 * just based on the random data that libdivecomputer
181 * gives us. I'm not sure what a real "architected"
182 * event model would actually look like, but right
183 * now you can associate a list of events with a dive,
184 * and we'll do something about it.
189 int type, flags, value;
193 #define MAX_CYLINDERS (8)
200 char *divemaster, *buddy;
201 double latitude, longitude;
202 depth_t maxdepth, meandepth;
203 duration_t duration, surfacetime;
205 temperature_t airtemp, watertemp;
206 cylinder_t cylinder[MAX_CYLINDERS];
208 struct event *events;
209 int samples, alloc_samples;
210 struct sample sample[];
214 * We keep our internal data in well-specified units, but
215 * the input and output may come in some random format. This
216 * keeps track of those units.
218 /* turns out in Win32 PASCAL is defined as a calling convention */
223 enum { METERS, FEET } length;
224 enum { LITER, CUFT } volume;
225 enum { BAR, PSI, PASCAL } pressure;
226 enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
227 enum { KG, LBS } weight;
230 extern const struct units SI_units, IMPERIAL_units;
231 extern struct units input_units, output_units;
236 int nr, allocated, preexisting;
240 extern struct dive_table dive_table;
242 extern int selected_dive;
243 #define current_dive (get_dive(selected_dive))
245 static inline struct dive *get_dive(unsigned int nr)
247 if (nr >= dive_table.nr)
249 return dive_table.dives[nr];
252 extern void parse_xml_init(void);
253 extern void parse_xml_file(const char *filename, GError **error);
254 extern void set_filename(const char *filename);
256 extern void show_dive_info(struct dive *);
257 extern void flush_dive_info_changes(struct dive *);
259 extern void show_dive_equipment(struct dive *);
260 extern void flush_dive_equipment_changes(struct dive *);
262 extern void show_dive_stats(struct dive *);
264 extern void update_dive(struct dive *new_dive);
265 extern void save_dives(const char *filename);
267 static inline unsigned int dive_size(int samples)
269 return sizeof(struct dive) + samples*sizeof(struct sample);
272 extern time_t utc_mktime(struct tm *tm);
274 extern struct dive *alloc_dive(void);
275 extern void record_dive(struct dive *dive);
277 extern struct sample *prepare_sample(struct dive **divep);
278 extern void finish_sample(struct dive *dive, struct sample *sample);
280 extern void report_dives(gboolean imported);
281 extern struct dive *fixup_dive(struct dive *dive);
282 extern struct dive *try_to_merge(struct dive *a, struct dive *b);
284 extern void renumber_dives(int nr);
286 extern void add_event(struct dive *dive, int time, int type, int flags, int value, const char *name);
288 /* UI related protopypes */
290 extern void init_ui(int argc, char **argv);
292 extern void run_ui(void);
294 extern void report_error(GError* error);
296 extern void add_cylinder_description(cylinder_type_t *);
297 extern void add_people(const char *string);
298 extern void add_location(const char *string);
299 extern void remember_event(const char *eventname);
300 extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
302 extern void dive_list_update_dives(void);
303 extern void flush_divelist(struct dive *dive);
305 #define DIVE_ERROR_PARSE 1
307 const char *weekday(int wday);
308 const char *monthname(int mon);
310 #define UTF8_DEGREE "\xc2\xb0"
311 #define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"