mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Plot pO2 graph based on sample information, if available
This should give closed circuit divers with a supported dive computer correct partial pressure plots. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
9d80e7bfe4
commit
3b425b4c13
1 changed files with 25 additions and 6 deletions
31
profile.c
31
profile.c
|
@ -41,6 +41,7 @@ struct plot_data {
|
||||||
int ndl;
|
int ndl;
|
||||||
int stoptime;
|
int stoptime;
|
||||||
int stopdepth;
|
int stopdepth;
|
||||||
|
int cns;
|
||||||
int smoothed;
|
int smoothed;
|
||||||
double po2, pn2, phe;
|
double po2, pn2, phe;
|
||||||
velocity_t velocity;
|
velocity_t velocity;
|
||||||
|
@ -1704,14 +1705,14 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
|
||||||
{
|
{
|
||||||
int cylinderindex = -1;
|
int cylinderindex = -1;
|
||||||
int lastdepth, lastindex;
|
int lastdepth, lastindex;
|
||||||
int i, pi_idx, nr, sec, cyl, stoptime, ndl, stopdepth;
|
int i, pi_idx, nr, sec, cyl, stoptime, ndl, stopdepth, cns;
|
||||||
struct plot_info *pi;
|
struct plot_info *pi;
|
||||||
pr_track_t *track_pr[MAX_CYLINDERS] = {NULL, };
|
pr_track_t *track_pr[MAX_CYLINDERS] = {NULL, };
|
||||||
pr_track_t *pr_track, *current;
|
pr_track_t *pr_track, *current;
|
||||||
gboolean missing_pr = FALSE;
|
gboolean missing_pr = FALSE;
|
||||||
struct plot_data *entry = NULL;
|
struct plot_data *entry = NULL;
|
||||||
struct event *ev;
|
struct event *ev;
|
||||||
double amb_pressure;
|
double amb_pressure, po2;
|
||||||
|
|
||||||
/* The plot-info is embedded in the graphics context */
|
/* The plot-info is embedded in the graphics context */
|
||||||
pi = &gc->pi;
|
pi = &gc->pi;
|
||||||
|
@ -1755,6 +1756,8 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
|
||||||
pi->has_ndl |= ndl;
|
pi->has_ndl |= ndl;
|
||||||
stopdepth = sample->stopdepth.mm;
|
stopdepth = sample->stopdepth.mm;
|
||||||
stoptime = sample->stoptime.seconds;
|
stoptime = sample->stoptime.seconds;
|
||||||
|
po2 = sample->po2 / 1000.0;
|
||||||
|
cns = sample->cns;
|
||||||
while (ev && ev->time.seconds < sample->time.seconds) {
|
while (ev && ev->time.seconds < sample->time.seconds) {
|
||||||
/* insert two fake plot info structures for the end of
|
/* insert two fake plot info structures for the end of
|
||||||
* the old tank and the start of the new tank */
|
* the old tank and the start of the new tank */
|
||||||
|
@ -1775,9 +1778,13 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
|
||||||
entry->stopdepth = stopdepth;
|
entry->stopdepth = stopdepth;
|
||||||
entry->stoptime = stoptime;
|
entry->stoptime = stoptime;
|
||||||
entry->ndl = ndl;
|
entry->ndl = ndl;
|
||||||
|
entry->cns = cns;
|
||||||
|
entry->po2 = po2;
|
||||||
(entry + 1)->stopdepth = stopdepth;
|
(entry + 1)->stopdepth = stopdepth;
|
||||||
(entry + 1)->stoptime = stoptime;
|
(entry + 1)->stoptime = stoptime;
|
||||||
(entry + 1)->ndl = ndl;
|
(entry + 1)->ndl = ndl;
|
||||||
|
(entry + 1)->cns = cns;
|
||||||
|
(entry + 1)->po2 = po2;
|
||||||
pi_idx += 2;
|
pi_idx += 2;
|
||||||
entry = pi->entry + i + pi_idx;
|
entry = pi->entry + i + pi_idx;
|
||||||
ev = get_next_event(ev->next, "gaschange");
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
|
@ -1791,6 +1798,8 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
|
||||||
entry->stopdepth = stopdepth;
|
entry->stopdepth = stopdepth;
|
||||||
entry->stoptime = stoptime;
|
entry->stoptime = stoptime;
|
||||||
entry->ndl = ndl;
|
entry->ndl = ndl;
|
||||||
|
entry->cns = cns;
|
||||||
|
entry->po2 = po2;
|
||||||
pi_idx++;
|
pi_idx++;
|
||||||
entry = pi->entry + i + pi_idx;
|
entry = pi->entry + i + pi_idx;
|
||||||
ev = get_next_event(ev->next, "gaschange");
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
|
@ -1801,6 +1810,8 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
|
||||||
entry->stopdepth = stopdepth;
|
entry->stopdepth = stopdepth;
|
||||||
entry->stoptime = stoptime;
|
entry->stoptime = stoptime;
|
||||||
entry->ndl = ndl;
|
entry->ndl = ndl;
|
||||||
|
entry->cns = cns;
|
||||||
|
entry->po2 = po2;
|
||||||
entry->cylinderindex = sample->cylinderindex;
|
entry->cylinderindex = sample->cylinderindex;
|
||||||
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
|
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
|
||||||
entry->temperature = sample->temperature.mkelvin;
|
entry->temperature = sample->temperature.mkelvin;
|
||||||
|
@ -1858,10 +1869,18 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
|
||||||
|
|
||||||
if (!fo2)
|
if (!fo2)
|
||||||
fo2 = AIR_PERMILLE;
|
fo2 = AIR_PERMILLE;
|
||||||
entry->po2 = fo2 / 1000.0 * amb_pressure;
|
if (entry->po2) {
|
||||||
entry->phe = fhe / 1000.0 * amb_pressure;
|
/* we have an O2 partial pressure in the sample - so this
|
||||||
entry->pn2 = (1000 - fo2 - fhe) / 1000.0 * amb_pressure;
|
* is likely a CC dive... use that instead of the value
|
||||||
|
* from the cylinder info */
|
||||||
|
double ratio = (double)fhe / (1000.0 - fo2);
|
||||||
|
entry->phe = (amb_pressure - entry->po2) * ratio;
|
||||||
|
entry->pn2 = amb_pressure - entry->po2 - entry->phe;
|
||||||
|
} else {
|
||||||
|
entry->po2 = fo2 / 1000.0 * amb_pressure;
|
||||||
|
entry->phe = fhe / 1000.0 * amb_pressure;
|
||||||
|
entry->pn2 = (1000 - fo2 - fhe) / 1000.0 * amb_pressure;
|
||||||
|
}
|
||||||
/* finally, do the discrete integration to get the SAC rate equivalent */
|
/* finally, do the discrete integration to get the SAC rate equivalent */
|
||||||
current->pressure_time += (entry->sec - (entry-1)->sec) *
|
current->pressure_time += (entry->sec - (entry-1)->sec) *
|
||||||
depth_to_mbar((entry->depth + (entry-1)->depth) / 2, dive) / 1000.0;
|
depth_to_mbar((entry->depth + (entry-1)->depth) / 2, dive) / 1000.0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue