mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Process ceiling events and store ceiling data in plot_info
This just creates the infrastructure but doesn't yet do anything useful with the data. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
51003eaed7
commit
7c9b89e442
1 changed files with 39 additions and 19 deletions
52
profile.c
52
profile.c
|
@ -44,6 +44,7 @@ struct plot_info {
|
||||||
int temperature;
|
int temperature;
|
||||||
/* Depth info */
|
/* Depth info */
|
||||||
int depth;
|
int depth;
|
||||||
|
int ceiling;
|
||||||
int smoothed;
|
int smoothed;
|
||||||
double po2, pn2, phe;
|
double po2, pn2, phe;
|
||||||
velocity_t velocity;
|
velocity_t velocity;
|
||||||
|
@ -185,11 +186,11 @@ static void dump_pi (struct plot_info *pi)
|
||||||
pi->maxpressure, pi->mintemp, pi->maxtemp);
|
pi->maxpressure, pi->mintemp, pi->maxtemp);
|
||||||
for (i = 0; i < pi->nr; i++)
|
for (i = 0; i < pi->nr; i++)
|
||||||
printf(" entry[%d]:{same_cylinder:%d cylinderindex:%d sec:%d pressure:{%d,%d}\n"
|
printf(" entry[%d]:{same_cylinder:%d cylinderindex:%d sec:%d pressure:{%d,%d}\n"
|
||||||
" time:%d:%02d temperature:%d depth:%d smoothed:%d po2:%lf phe:%lf pn2:%lf sum-pp %lf}\n",
|
" time:%d:%02d temperature:%d depth:%d ceiling:%d smoothed:%d po2:%lf phe:%lf pn2:%lf sum-pp %lf}\n",
|
||||||
i, pi->entry[i].same_cylinder, pi->entry[i].cylinderindex, pi->entry[i].sec,
|
i, pi->entry[i].same_cylinder, pi->entry[i].cylinderindex, pi->entry[i].sec,
|
||||||
pi->entry[i].pressure[0], pi->entry[i].pressure[1],
|
pi->entry[i].pressure[0], pi->entry[i].pressure[1],
|
||||||
pi->entry[i].sec / 60, pi->entry[i].sec % 60,
|
pi->entry[i].sec / 60, pi->entry[i].sec % 60,
|
||||||
pi->entry[i].temperature, pi->entry[i].depth, pi->entry[i].smoothed,
|
pi->entry[i].temperature, pi->entry[i].depth, pi->entry[i].ceiling, pi->entry[i].smoothed,
|
||||||
pi->entry[i].po2, pi->entry[i].phe, pi->entry[i].pn2,
|
pi->entry[i].po2, pi->entry[i].phe, pi->entry[i].pn2,
|
||||||
pi->entry[i].po2 + pi->entry[i].phe + pi->entry[i].pn2);
|
pi->entry[i].po2 + pi->entry[i].phe + pi->entry[i].pn2);
|
||||||
printf(" }\n");
|
printf(" }\n");
|
||||||
|
@ -294,6 +295,7 @@ static void plot_text(struct graphics_context *gc, const text_render_options_t *
|
||||||
cairo_show_text(cr, buffer);
|
cairo_show_text(cr, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* collect all event names and whether we display them */
|
||||||
struct ev_select {
|
struct ev_select {
|
||||||
char *ev_name;
|
char *ev_name;
|
||||||
gboolean plot_ev;
|
gboolean plot_ev;
|
||||||
|
@ -1509,10 +1511,12 @@ static int get_cylinder_index(struct dive *dive, struct event *ev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct event *get_next_gaschange(struct event *event)
|
static struct event *get_next_event(struct event *event, char *name)
|
||||||
{
|
{
|
||||||
|
if (!name || !*name)
|
||||||
|
return NULL;
|
||||||
while (event) {
|
while (event) {
|
||||||
if (!strcmp(event->name, "gaschange"))
|
if (!strcmp(event->name, name))
|
||||||
return event;
|
return event;
|
||||||
event = event->next;
|
event = event->next;
|
||||||
}
|
}
|
||||||
|
@ -1537,7 +1541,7 @@ static int set_cylinder_index(struct plot_info *pi, int i, int cylinderindex, un
|
||||||
static void check_gas_change_events(struct dive *dive, struct plot_info *pi)
|
static void check_gas_change_events(struct dive *dive, struct plot_info *pi)
|
||||||
{
|
{
|
||||||
int i = 0, cylinderindex = 0;
|
int i = 0, cylinderindex = 0;
|
||||||
struct event *ev = get_next_gaschange(dive->events);
|
struct event *ev = get_next_event(dive->events, "gaschange");
|
||||||
|
|
||||||
if (!ev)
|
if (!ev)
|
||||||
return;
|
return;
|
||||||
|
@ -1545,7 +1549,7 @@ static void check_gas_change_events(struct dive *dive, struct plot_info *pi)
|
||||||
do {
|
do {
|
||||||
i = set_cylinder_index(pi, i, cylinderindex, ev->time.seconds);
|
i = set_cylinder_index(pi, i, cylinderindex, ev->time.seconds);
|
||||||
cylinderindex = get_cylinder_index(dive, ev);
|
cylinderindex = get_cylinder_index(dive, ev);
|
||||||
ev = get_next_gaschange(ev->next);
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
} while (ev);
|
} while (ev);
|
||||||
set_cylinder_index(pi, i, cylinderindex, ~0u);
|
set_cylinder_index(pi, i, cylinderindex, ~0u);
|
||||||
}
|
}
|
||||||
|
@ -1554,11 +1558,11 @@ static void check_gas_change_events(struct dive *dive, struct plot_info *pi)
|
||||||
static int count_gas_change_events(struct dive *dive)
|
static int count_gas_change_events(struct dive *dive)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
struct event *ev = get_next_gaschange(dive->events);
|
struct event *ev = get_next_event(dive->events, "gaschange");
|
||||||
|
|
||||||
while (ev) {
|
while (ev) {
|
||||||
count++;
|
count++;
|
||||||
ev = get_next_gaschange(ev->next);
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -1574,14 +1578,14 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
|
||||||
{
|
{
|
||||||
int cylinderindex = -1;
|
int cylinderindex = -1;
|
||||||
int lastdepth, lastindex;
|
int lastdepth, lastindex;
|
||||||
int i, pi_idx, nr, sec, cyl;
|
int i, pi_idx, nr, sec, cyl, ceiling = 0;
|
||||||
size_t alloc_size;
|
size_t alloc_size;
|
||||||
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, *ceil_ev;
|
||||||
|
|
||||||
/* we want to potentially add synthetic plot_info elements for the gas changes */
|
/* we want to potentially add synthetic plot_info elements for the gas changes */
|
||||||
nr = nr_samples + 4 + 2 * count_gas_change_events(dive);
|
nr = nr_samples + 4 + 2 * count_gas_change_events(dive);
|
||||||
|
@ -1593,18 +1597,20 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
|
||||||
pi->nr = nr;
|
pi->nr = nr;
|
||||||
pi_idx = 2; /* the two extra events at the start */
|
pi_idx = 2; /* the two extra events at the start */
|
||||||
/* check for gas changes before the samples start */
|
/* check for gas changes before the samples start */
|
||||||
ev = get_next_gaschange(dive->events);
|
ev = get_next_event(dive->events, "gaschange");
|
||||||
while (ev && ev->time.seconds < dive_sample->time.seconds) {
|
while (ev && ev->time.seconds < dive_sample->time.seconds) {
|
||||||
entry = pi->entry + pi_idx;
|
entry = pi->entry + pi_idx;
|
||||||
entry->sec = ev->time.seconds;
|
entry->sec = ev->time.seconds;
|
||||||
entry->depth = 0; /* is that always correct ? */
|
entry->depth = 0; /* is that always correct ? */
|
||||||
pi_idx++;
|
pi_idx++;
|
||||||
ev = get_next_gaschange(ev->next);
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
}
|
}
|
||||||
if (ev && ev->time.seconds == dive_sample->time.seconds) {
|
if (ev && ev->time.seconds == dive_sample->time.seconds) {
|
||||||
/* we already have a sample at the time of the event */
|
/* we already have a sample at the time of the event */
|
||||||
ev = get_next_gaschange(ev->next);
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
}
|
}
|
||||||
|
/* find the first deco/ceiling event (if any) */
|
||||||
|
ceil_ev = get_next_event(dive->events, "ceiling");
|
||||||
sec = 0;
|
sec = 0;
|
||||||
lastindex = 0;
|
lastindex = 0;
|
||||||
lastdepth = -1;
|
lastdepth = -1;
|
||||||
|
@ -1614,6 +1620,16 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
|
||||||
struct sample *sample = dive_sample+i;
|
struct sample *sample = dive_sample+i;
|
||||||
|
|
||||||
entry = pi->entry + i + pi_idx;
|
entry = pi->entry + i + pi_idx;
|
||||||
|
while (ceil_ev && ceil_ev->time.seconds <= sample->time.seconds) {
|
||||||
|
struct event *next_ceil_ev = get_next_event(dive->events, "ceiling");
|
||||||
|
if (!next_ceil_ev || next_ceil_ev->time.seconds > sample->time.seconds)
|
||||||
|
break;
|
||||||
|
ceil_ev = next_ceil_ev;
|
||||||
|
}
|
||||||
|
if (ceil_ev && ceil_ev->time.seconds <= sample->time.seconds) {
|
||||||
|
ceiling = ceil_ev->value;
|
||||||
|
ceil_ev = get_next_event(dive->events, "ceiling");
|
||||||
|
}
|
||||||
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 */
|
||||||
|
@ -1631,9 +1647,11 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
|
||||||
} else
|
} else
|
||||||
entry->depth = sample->depth.mm;
|
entry->depth = sample->depth.mm;
|
||||||
(entry + 1)->depth = entry->depth;
|
(entry + 1)->depth = entry->depth;
|
||||||
|
entry->ceiling = ceiling;
|
||||||
|
(entry + 1)->ceiling = ceiling;
|
||||||
pi_idx += 2;
|
pi_idx += 2;
|
||||||
entry = pi->entry + i + pi_idx;
|
entry = pi->entry + i + pi_idx;
|
||||||
ev = get_next_gaschange(ev->next);
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
}
|
}
|
||||||
if (ev && ev->time.seconds == sample->time.seconds) {
|
if (ev && ev->time.seconds == sample->time.seconds) {
|
||||||
/* we already have a sample at the time of the event
|
/* we already have a sample at the time of the event
|
||||||
|
@ -1641,13 +1659,15 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
|
||||||
* real even by one second (to keep time monotonous) */
|
* real even by one second (to keep time monotonous) */
|
||||||
entry->sec = ev->time.seconds;
|
entry->sec = ev->time.seconds;
|
||||||
entry->depth = sample->depth.mm;
|
entry->depth = sample->depth.mm;
|
||||||
|
entry->ceiling = ceiling;
|
||||||
pi_idx++;
|
pi_idx++;
|
||||||
entry = pi->entry + i + pi_idx;
|
entry = pi->entry + i + pi_idx;
|
||||||
ev = get_next_gaschange(ev->next);
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
delay = 1;
|
delay = 1;
|
||||||
}
|
}
|
||||||
sec = entry->sec = sample->time.seconds + delay;
|
sec = entry->sec = sample->time.seconds + delay;
|
||||||
depth = entry->depth = sample->depth.mm;
|
depth = entry->depth = sample->depth.mm;
|
||||||
|
entry->ceiling = ceiling;
|
||||||
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;
|
||||||
|
@ -1666,7 +1686,7 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
|
||||||
entry->depth = 0; /* why are there gas changes after the dive is over? */
|
entry->depth = 0; /* why are there gas changes after the dive is over? */
|
||||||
pi_idx++;
|
pi_idx++;
|
||||||
entry = pi->entry + i + pi_idx;
|
entry = pi->entry + i + pi_idx;
|
||||||
ev = get_next_gaschange(ev->next);
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
}
|
}
|
||||||
nr = nr_samples + pi_idx - 2;
|
nr = nr_samples + pi_idx - 2;
|
||||||
check_gas_change_events(dive, pi);
|
check_gas_change_events(dive, pi);
|
||||||
|
|
Loading…
Add table
Reference in a new issue