From: Linus Torvalds Date: Tue, 6 Sep 2011 22:17:24 +0000 (-0700) Subject: Merge branch 'dirk' X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=dbfce3035ef1499e47607a84b3ed07ccc95abd70;p=ext%2Fsubsurface.git Merge branch 'dirk' * dirk: Print starting and ending pressures Fix up conflicts in profile.c due to different ways to set the text formatting. Dirk's 'text_format_options' thing is prettier than mine. Use it. --- dbfce3035ef1499e47607a84b3ed07ccc95abd70 diff --cc profile.c index febea80,f0a4c70..af1976e --- a/profile.c +++ b/profile.c @@@ -281,47 -280,21 +280,65 @@@ static void plot_cylinder_pressure(stru 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, 1, 0, maxx*0.95, maxy*0.9, "cuft: %4.2f", airuse); ++ 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, 1, 0, maxx*0.95, maxy*0.95, "SAC: %4.2f", sac); ++ 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); } } @@@ -343,10 -316,8 +360,11 @@@ static void plot(cairo_t *cr, int w, in /* 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);