cairo_stroke(cr);
}
- plot_text(cr, 1, 0, maxx*0.95, maxy*0.9, "cuft: %4.2f", airuse);
+/*
+ * 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)
+{
++ text_render_options_t tro = {0.2, 1.0, 0.2, LEFT};
+ 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.95, "SAC: %4.2f", sac);
++ plot_text(cr, &tro, 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, &tro, maxx*0.95, maxy*0.95, "SAC: %4.2f", sac);
++ }
++}
+
+ static void plot_cylinder_pressure_text(struct dive *dive, cairo_t *cr,
+ double topx, double topy, double maxx, double maxy)
+ {
+ double scalex, scaley;
+ double startp,endp;
+
+ cairo_set_font_size(cr, 10);
+
+ if (get_cylinder_pressure_range(dive, &scalex, &scaley,
+ &startp, &endp)) {
+ text_render_options_t tro = {0.2, 1.0, 0.2, LEFT};
+ plot_text(cr, &tro, SCALE(0, startp), "%3.0f bar", startp/1000.0);
+ plot_text(cr, &tro, SCALE(dive->duration.seconds, endp),
+ "%3.0f bar", endp/1000.0);
}
}
/* Text on top of all graphs.. */
plot_depth_text(dive, cr, topx, topy, maxx, maxy);
+ plot_cylinder_pressure_text(dive, cr, topx, topy, maxx, maxy);
+ /* And info box in the lower right corner.. */
+ plot_info(dive, cr, topx, topy, maxx, maxy);
+
/* Bounding box last */
scalex = scaley = 1.0;
cairo_set_source_rgb(cr, 1, 1, 1);