summaryrefslogtreecommitdiff
path: root/ao-tools/lib/cc-period.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2009-09-06 20:26:17 -0700
committerKeith Packard <keithp@keithp.com>2009-09-06 20:26:17 -0700
commit932f1539b38567e565fd484171c13539b1467308 (patch)
tree485485df3cef45614c861da39b987bedb0aec190 /ao-tools/lib/cc-period.c
parent9177f5f4e9d832558ddd9ab227c4511f6201e7e5 (diff)
Color plots, integrate only flight portion of data.
Telemetry files have piles of pad data which shouldn't be integrated into the velocity data as it tends to generate huge values from the noise of the sensor. Also make the data lines colored to keep them visually distinct from the rest of the plot image. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/lib/cc-period.c')
-rw-r--r--ao-tools/lib/cc-period.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/ao-tools/lib/cc-period.c b/ao-tools/lib/cc-period.c
index c74cf9dc..2a4e5952 100644
--- a/ao-tools/lib/cc-period.c
+++ b/ao-tools/lib/cc-period.c
@@ -17,35 +17,27 @@
#include "cc.h"
#include <stdlib.h>
+#include <math.h>
struct cc_perioddata *
cc_period_make(struct cc_timedata *td, double start_time, double stop_time)
{
int len = stop_time - start_time + 1;
struct cc_perioddata *pd;
- int i;
- double prev_time;
- double next_time;
- double interval;
+ int i, j;
+ double t;
pd = calloc(1, sizeof (struct cc_perioddata));
pd->start = start_time;
pd->step = 1;
pd->num = len;
pd->data = calloc(len, sizeof(double));
- prev_time = start_time;
- for (i = 0; i < td->num; i++) {
- if (start_time <= td->data[i].time && td->data[i].time <= stop_time) {
- int pos = td->data[i].time - start_time;
-
- if (i < td->num - 1 && td->data[i+1].time < stop_time)
- next_time = (td->data[i].time + td->data[i+1].time) / 2.0;
- else
- next_time = stop_time;
- interval = next_time - prev_time;
- pd->data[pos] = td->data[i].value * interval;
- prev_time = next_time;
- }
+ j = 0;
+ for (i = 0; i < pd->num; i++) {
+ t = start_time + i * pd->step;
+ while (j < td->num - 1 && fabs(t - td->data[j].time) > fabs(t - td->data[j+1].time))
+ j++;
+ pd->data[i] = td->data[j].value;
}
return pd;
}