diff options
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -280,6 +280,50 @@ static void plot_cylinder_pressure(struct dive *dive, cairo_t *cr, cairo_stroke(cr); } +/* + * 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, &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) @@ -318,6 +362,9 @@ static void plot(cairo_t *cr, int w, int h, struct dive *dive) 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); |