summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-09 21:38:00 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-10 11:54:07 +0100
commit7c9b89e442e992751e23a5d223e196df17a347b6 (patch)
tree0b160053932b34b52e867e4476524fbe2f248b09 /profile.c
parent51003eaed71ea823dc8ce88e7de0e785a50b24cb (diff)
downloadsubsurface-7c9b89e442e992751e23a5d223e196df17a347b6.tar.gz
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>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/profile.c b/profile.c
index 9b0dcb600..a4d32a78e 100644
--- a/profile.c
+++ b/profile.c
@@ -44,6 +44,7 @@ struct plot_info {
int temperature;
/* Depth info */
int depth;
+ int ceiling;
int smoothed;
double po2, pn2, phe;
velocity_t velocity;
@@ -185,11 +186,11 @@ static void dump_pi (struct plot_info *pi)
pi->maxpressure, pi->mintemp, pi->maxtemp);
for (i = 0; i < pi->nr; i++)
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,
pi->entry[i].pressure[0], pi->entry[i].pressure[1],
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);
printf(" }\n");
@@ -294,6 +295,7 @@ static void plot_text(struct graphics_context *gc, const text_render_options_t *
cairo_show_text(cr, buffer);
}
+/* collect all event names and whether we display them */
struct ev_select {
char *ev_name;
gboolean plot_ev;
@@ -314,12 +316,12 @@ void evn_foreach(void (*callback)(const char *, int *, void *), void *data)
void remember_event(const char *eventname)
{
- int i=0, len;
+ int i = 0, len;
if (!eventname || (len = strlen(eventname)) == 0)
return;
while (i < evn_used) {
- if (!strncmp(eventname,ev_namelist[i].ev_name,len))
+ if (!strncmp(eventname, ev_namelist[i].ev_name, len))
return;
i++;
}
@@ -1509,10 +1511,12 @@ static int get_cylinder_index(struct dive *dive, struct event *ev)
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) {
- if (!strcmp(event->name, "gaschange"))
+ if (!strcmp(event->name, name))
return event;
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)
{
int i = 0, cylinderindex = 0;
- struct event *ev = get_next_gaschange(dive->events);
+ struct event *ev = get_next_event(dive->events, "gaschange");
if (!ev)
return;
@@ -1545,7 +1549,7 @@ static void check_gas_change_events(struct dive *dive, struct plot_info *pi)
do {
i = set_cylinder_index(pi, i, cylinderindex, ev->time.seconds);
cylinderindex = get_cylinder_index(dive, ev);
- ev = get_next_gaschange(ev->next);
+ ev = get_next_event(ev->next, "gaschange");
} while (ev);
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)
{
int count = 0;
- struct event *ev = get_next_gaschange(dive->events);
+ struct event *ev = get_next_event(dive->events, "gaschange");
while (ev) {
count++;
- ev = get_next_gaschange(ev->next);
+ ev = get_next_event(ev->next, "gaschange");
}
return count;
}
@@ -1574,14 +1578,14 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
{
int cylinderindex = -1;
int lastdepth, lastindex;
- int i, pi_idx, nr, sec, cyl;
+ int i, pi_idx, nr, sec, cyl, ceiling = 0;
size_t alloc_size;
struct plot_info *pi;
pr_track_t *track_pr[MAX_CYLINDERS] = {NULL, };
pr_track_t *pr_track, *current;
gboolean missing_pr = FALSE;
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 */
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_idx = 2; /* the two extra events at the 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) {
entry = pi->entry + pi_idx;
entry->sec = ev->time.seconds;
entry->depth = 0; /* is that always correct ? */
pi_idx++;
- ev = get_next_gaschange(ev->next);
+ ev = get_next_event(ev->next, "gaschange");
}
if (ev && ev->time.seconds == dive_sample->time.seconds) {
/* 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;
lastindex = 0;
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;
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) {
/* insert two fake plot info structures for the end of
* the old tank and the start of the new tank */
@@ -1630,10 +1646,12 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
(sample->depth.mm - (sample-1)->depth.mm) / 2;
} else
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;
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) {
/* 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) */
entry->sec = ev->time.seconds;
entry->depth = sample->depth.mm;
+ entry->ceiling = ceiling;
pi_idx++;
entry = pi->entry + i + pi_idx;
- ev = get_next_gaschange(ev->next);
+ ev = get_next_event(ev->next, "gaschange");
delay = 1;
}
sec = entry->sec = sample->time.seconds + delay;
depth = entry->depth = sample->depth.mm;
+ entry->ceiling = ceiling;
entry->cylinderindex = sample->cylinderindex;
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
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? */
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;
check_gas_change_events(dive, pi);