+/*
+ * Return air usage (in liters).
+ */
+static double calculate_airuse(struct dive *dive)
+{
+ double airuse = 0;
+ int i;
+
+ for (i = 0; i < MAX_CYLINDERS; i++) {
+ cylinder_t *cyl = dive->cylinder + i;
+ int size = cyl->type.size.mliter;
+ double kilo_atm;
+
+ if (!size)
+ continue;
+
+ kilo_atm = (cyl->start.mbar - cyl->end.mbar) / 1013250.0;
+
+ /* Liters of air at 1 atm == milliliters at 1k atm*/
+ airuse += kilo_atm * size;
+ }
+ return airuse;
+}
+
+static void plot_info(struct dive *dive, cairo_t *cr,
+ double topx, double topy, double maxx, double maxy)
+{
+ const double liters_per_cuft = 28.317;
+ double airuse;
+
+ airuse = calculate_airuse(dive);
+ if (!airuse)
+ return;
+
+ /* I really need to start addign some unit setting thing */
+ airuse /= liters_per_cuft;
+ plot_text(cr, 1, 0, maxx*0.95, maxy*0.9, "cuft: %4.2f", airuse);
+ if (dive->duration.seconds) {
+ double pressure = 1 + (dive->meandepth.mm / 10000.0);
+ double sac = airuse / pressure * 60 / dive->duration.seconds;
+ plot_text(cr, 1, 0, maxx*0.95, maxy*0.95, "SAC: %4.2f", sac);
+ }
+}
+