diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-01-02 21:21:36 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-03 20:43:14 -0800 |
commit | 3c31d0401dd9e4be2aa51e1bb2b72e0bc162cb9d (patch) | |
tree | 6c8936c2d6f0d2ad2c355a9155a21af8550a8fa6 /profile.c | |
parent | 8dbe3528b4ae6ab01d913d41d696c20319004508 (diff) | |
download | subsurface-3c31d0401dd9e4be2aa51e1bb2b72e0bc162cb9d.tar.gz |
First stab at deco calculations
This seems to give us roughly the right data but needs a lot more testing.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -40,6 +40,7 @@ struct plot_data { int temperature; /* Depth info */ int depth; + int ceiling; int ndl; int stoptime; int stopdepth; @@ -1539,10 +1540,13 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer struct plot_data *entry = NULL; struct event *ev; double amb_pressure, po2; + int surface_pressure = dive->surface_pressure.mbar ? dive->surface_pressure.mbar : 1013; /* The plot-info is embedded in the graphics context */ pi = &gc->pi; + /* reset deco information to start the calculation */ + clear_deco(); /* we want to potentially add synthetic plot_info elements for the gas changes */ nr = dc->samples + 4 + 2 * count_gas_change_events(dc); if (last_pi_entry) @@ -1724,6 +1728,24 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer current->pressure_time += (entry->sec - (entry-1)->sec) * depth_to_mbar((entry->depth + (entry-1)->depth) / 2, dive) / 1000.0; missing_pr |= !SENSOR_PRESSURE(entry); + /* and now let's try to do some deco calculations */ + if (i > 0) { + int j; + int t0 = (entry - 1)->sec; + int t1 = entry->sec; + float ceiling_pressure = 0; + for (j = t0; j < t1; j++) { + int depth = 0.5 + (entry - 1)->depth + (j - t0) * (entry->depth - (entry - 1)->depth) / (t1 - t0); + double min_pressure = add_segment(depth_to_mbar(depth, dive) / 1000.0, &dive->cylinder[cylinderindex].gasmix); + if (min_pressure > ceiling_pressure) + ceiling_pressure = min_pressure; + } + ceiling_pressure = ceiling_pressure * 1000.0 + 0.5; + if (ceiling_pressure > surface_pressure) + entry->ceiling = rel_mbar_to_depth(ceiling_pressure - surface_pressure, dive); + else + entry->ceiling = 0; + } } if (entry) @@ -1965,6 +1987,11 @@ static void plot_string(struct plot_data *entry, char *buf, size_t bufsize, memcpy(buf2, buf, bufsize); snprintf(buf, bufsize, "%s\nT:%.1f %s", buf2, tempvalue, temp_unit); } + if (entry->ceiling) { + depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit); + memcpy(buf2, buf, bufsize); + snprintf(buf, bufsize, "%s\nCalculated ceiling %.0f %s", buf2, depthvalue, depth_unit); + } if (entry->stopdepth) { depthvalue = get_depth_units(entry->stopdepth, NULL, &depth_unit); memcpy(buf2, buf, bufsize); |