summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-01 10:04:12 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-01 10:04:12 -0700
commit1b606ae2260395471890616f8b9dcb16e997fa3d (patch)
tree1a674959df73ed1ed5d274e04cd61d4722fdc8a3 /profile.c
parent072b4f743c19566ad55bb4b30e0844082cccfbd1 (diff)
downloadsubsurface-1b606ae2260395471890616f8b9dcb16e997fa3d.tar.gz
First stab at plotting a pO2 graph
So far this is done unconditionally. This already starts some of the infrastructure for other gases, but so far only O2 is handled. We also need a pressure scale on the right to make this useful - or we need to do peek / trough pressure prints like we do for temperature and depth. Finally, I think I want to move the plot further down, maybe make the whole plot area taller if we are plotting partial gas pressures as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/profile.c b/profile.c
index db2b1819b..7d3a4d5ee 100644
--- a/profile.c
+++ b/profile.c
@@ -43,6 +43,7 @@ struct plot_info {
/* Depth info */
int depth;
int smoothed;
+ double po2;
velocity_t velocity;
struct plot_data *min[3];
struct plot_data *max[3];
@@ -68,6 +69,9 @@ typedef enum {
/* Velocity colors. Order is still important, ref VELOCITY_COLORS_START_IDX. */
VELO_STABLE, VELO_SLOW, VELO_MODERATE, VELO_FAST, VELO_CRAZY,
+ /* gas colors */
+ PO2, PN2, PHE,
+
/* Other colors */
TEXT_BACKGROUND, ALERT_BG, ALERT_FG, EVENTS, SAMPLE_DEEP, SAMPLE_SHALLOW,
SMOOTHED, MINUTE, TIME_GRID, TIME_TEXT, DEPTH_GRID, MEAN_DEPTH, DEPTH_TOP,
@@ -99,6 +103,10 @@ static const color_t profile_color[] = {
[VELO_FAST] = {{PIRATEGOLD1, BLACK1_LOW_TRANS}},
[VELO_CRAZY] = {{RED1, BLACK1_LOW_TRANS}},
+ [PO2] = {{APPLE1, APPLE1_MED_TRANS}},
+ [PN2] = {{ROYALBLUE2, ROYALBLUE2_LOW_TRANS}},
+ [PHE] = {{PEANUT, PEANUT_MED_TRANS}},
+
[TEXT_BACKGROUND] = {{CONCRETE1_LOWER_TRANS, WHITE1}},
[ALERT_BG] = {{BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS}},
[ALERT_FG] = {{BLACK1_LOW_TRANS, BLACK1_LOW_TRANS}},
@@ -482,6 +490,27 @@ static void plot_depth_scale(struct graphics_context *gc, struct plot_info *pi)
}
}
+static void plot_po2_profile(struct graphics_context *gc, struct plot_info *pi)
+{
+ int i;
+ struct plot_data *entry;
+
+ gc->leftx = 0;
+ gc->rightx = get_maxtime(pi);
+ /* let's hope no one gets close to the top of that graph... */
+ gc->topy = 3.0; gc->bottomy = 0.0;
+
+ set_source_rgba(gc, PO2);
+
+ entry = pi->entry;
+ move_to(gc, entry->sec, entry->po2);
+ for (i = 1; i < pi->nr; i++) {
+ entry++;
+ line_to(gc, entry->sec, entry->po2);
+ }
+ cairo_stroke(gc->cr);
+}
+
static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi)
{
int i, incr;
@@ -1257,6 +1286,7 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
lastdepth = -1;
for (i = 0; i < nr_samples; i++) {
int depth;
+ double fo2, pressure;
int delay = 0;
struct sample *sample = dive_sample+i;
@@ -1297,6 +1327,10 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
depth = entry->depth = sample->depth.mm;
entry->cylinderindex = sample->cylinderindex;
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
+ pressure = (depth + 10000) / 10000.0 * 1.01325;
+ fo2 = dive->cylinder[sample->cylinderindex].gasmix.o2.permille / 1000.0;
+ entry->po2 = fo2 * pressure;
+
entry->temperature = sample->temperature.mkelvin;
if (depth || lastdepth)
@@ -1367,10 +1401,17 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
pi->entry[i].same_cylinder = 1;
pi->entry[i].cylinderindex = pi->entry[i-1].cylinderindex;
INTERPOLATED_PRESSURE(pi->entry + i) = GET_PRESSURE(pi->entry + i - 1);
+ pi->entry[i].po2 = pi->entry[i-1].po2;
pi->entry[i+1].sec = sec + 40;
pi->entry[i+1].same_cylinder = 1;
pi->entry[i+1].cylinderindex = pi->entry[i-1].cylinderindex;
INTERPOLATED_PRESSURE(pi->entry + i + 1) = GET_PRESSURE(pi->entry + i - 1);
+ pi->entry[i+1].po2 = pi->entry[i-1].po2;
+ /* make sure the first two pi entries have a sane po2 */
+ if (pi->entry[1].po2 < 0.01)
+ pi->entry[1].po2 = pi->entry[2].po2;
+ if (pi->entry[0].po2 < 0.01)
+ pi->entry[0].po2 = pi->entry[1].po2;
/* the number of actual entries - some computers have lots of
* depth 0 samples at the end of a dive, we want to make sure
* we have exactly one of them at the end */
@@ -1486,6 +1527,9 @@ void plot(struct graphics_context *gc, cairo_rectangle_t *drawing_area, struct d
cairo_close_path(gc->cr);
cairo_stroke(gc->cr);
+// if (graphs_enabled.po2)
+ plot_po2_profile(gc, pi);
+
/* now shift the translation back by half the margin;
* this way we can draw the vertical scales on both sides */
cairo_translate(gc->cr, -drawing_area->x / 2.0, 0);