summaryrefslogtreecommitdiff
path: root/ao-tools/lib
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2009-09-06 16:24:35 -0700
committerKeith Packard <keithp@keithp.com>2009-09-06 16:24:35 -0700
commit32d3536706324808df6cd02248a236302b831571 (patch)
treee3d0343c0725a60987633a50917bc82f959c333c /ao-tools/lib
parentd0eac989b1ffc8ae30ba12da403eb4bf1ad42d6b (diff)
Add plots to ao-postflight using the plplot library
It's not perfect, but it generates .svg plot output. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/lib')
-rw-r--r--ao-tools/lib/cc-analyse.c174
-rw-r--r--ao-tools/lib/cc-process.c18
-rw-r--r--ao-tools/lib/cc.h29
3 files changed, 203 insertions, 18 deletions
diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c
index 0e020115..cdb16f02 100644
--- a/ao-tools/lib/cc-analyse.c
+++ b/ao-tools/lib/cc-analyse.c
@@ -39,6 +39,26 @@ cc_timedata_min(struct cc_timedata *d, double min_time, double max_time)
}
int
+cc_timedata_min_mag(struct cc_timedata *d, double min_time, double max_time)
+{
+ int i;
+ int set = 0;
+ int min_i = -1;
+ double min;
+
+ if (d->num == 0)
+ return -1;
+ for (i = 0; i < d->num; i++)
+ if (min_time <= d->data[i].time && d->data[i].time <= max_time)
+ if (!set || fabs(d->data[i].value) < min) {
+ min_i = i;
+ min = fabs(d->data[i].value);
+ set = 1;
+ }
+ return min_i;
+}
+
+int
cc_timedata_max(struct cc_timedata *d, double min_time, double max_time)
{
int i;
@@ -59,22 +79,80 @@ cc_timedata_max(struct cc_timedata *d, double min_time, double max_time)
}
int
+cc_timedata_max_mag(struct cc_timedata *d, double min_time, double max_time)
+{
+ int i;
+ double max;
+ int max_i = -1;
+ int set = 0;
+
+ if (d->num == 0)
+ return -1;
+ for (i = 0; i < d->num; i++)
+ if (min_time <= d->data[i].time && d->data[i].time <= max_time)
+ if (!set || fabs(d->data[i].value) > max) {
+ max_i = i;
+ max = fabs(d->data[i].value);
+ set = 1;
+ }
+ return max_i;
+}
+
+double
+cc_timedata_average(struct cc_timedata *td, double start_time, double stop_time)
+{
+ int i;
+ double prev_time;
+ double next_time;
+ double interval;
+ double sum = 0.0;
+ double period = 0.0;
+
+ prev_time = start_time;
+ for (i = 0; i < td->num; i++) {
+ if (start_time <= td->data[i].time && td->data[i].time <= stop_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;
+ sum += td->data[i].value * interval;
+ period += interval;
+ prev_time = next_time;
+ }
+ }
+ return sum / period;
+}
+
+int
+cc_perioddata_limits(struct cc_perioddata *d, double min_time, double max_time, int *start, int *stop)
+{
+ double start_d, stop_d;
+
+ if (d->num == 0)
+ return 0;
+ start_d = ceil((min_time - d->start) / d->step);
+ if (start_d < 0)
+ start_d = 0;
+ stop_d = floor((max_time - d->start) / d->step);
+ if (stop_d >= d->num)
+ stop_d = d->num - 1;
+ if (stop_d < start_d)
+ return 0;
+ *start = (int) start_d;
+ *stop = (int) stop_d;
+ return 1;
+}
+
+int
cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time)
{
- int start, stop;
int i;
double min;
int min_i;
+ int start, stop;
- if (d->num == 0)
- return -1;
- start = (int) ceil((min_time - d->start) / d->step);
- if (start < 0)
- start = 0;
- stop = (int) floor((max_time - d->start) / d->step);
- if (stop >= d->num)
- stop = d->num - 1;
- if (stop < start)
+ if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop))
return -1;
min = d->data[start];
min_i = start;
@@ -87,6 +165,26 @@ cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time)
}
int
+cc_perioddata_min_mag(struct cc_perioddata *d, double min_time, double max_time)
+{
+ int start, stop;
+ int i;
+ double min;
+ int min_i;
+
+ if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop))
+ return -1;
+ min = d->data[start];
+ min_i = start;
+ for (i = start + 1; i <= stop; i++)
+ if (fabs(d->data[i]) < min) {
+ min = fabs(d->data[i]);
+ min_i = i;
+ }
+ return min_i;
+}
+
+int
cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time)
{
int start, stop;
@@ -94,15 +192,27 @@ cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time)
double max;
int max_i;
- if (d->num == 0)
+ if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop))
return -1;
- start = (int) ceil((min_time - d->start) / d->step);
- if (start < 0)
- start = 0;
- stop = (int) floor((max_time - d->start) / d->step);
- if (stop >= d->num)
- stop = d->num - 1;
- if (stop < start)
+ max = d->data[start];
+ max_i = start;
+ for (i = start + 1; i <= stop; i++)
+ if (d->data[i] > max) {
+ max = d->data[i];
+ max_i = i;
+ }
+ return max_i;
+}
+
+int
+cc_perioddata_max_mag(struct cc_perioddata *d, double min_time, double max_time)
+{
+ int start, stop;
+ int i;
+ double max;
+ int max_i;
+
+ if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop))
return -1;
max = d->data[start];
max_i = start;
@@ -113,3 +223,31 @@ cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time)
}
return max_i;
}
+
+double
+cc_perioddata_average(struct cc_perioddata *d, double min_time, double max_time)
+{
+ int start, stop;
+ int i;
+ double sum = 0.0;
+
+ if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop))
+ return 0.0;
+ for (i = start; i <= stop; i++)
+ sum += d->data[i];
+ return sum / (stop - start + 1);
+}
+
+double
+cc_perioddata_average_mag(struct cc_perioddata *d, double min_time, double max_time)
+{
+ int start, stop;
+ int i;
+ double sum = 0.0;
+
+ if (!cc_perioddata_limits(d, min_time, max_time, &start, &stop))
+ return 0.0;
+ for (i = start; i <= stop; i++)
+ sum += fabs(d->data[i]);
+ return sum / (stop - start + 1);
+}
diff --git a/ao-tools/lib/cc-process.c b/ao-tools/lib/cc-process.c
index e906b635..469ad2f2 100644
--- a/ao-tools/lib/cc-process.c
+++ b/ao-tools/lib/cc-process.c
@@ -138,3 +138,21 @@ cc_flight_cook(struct cc_flightraw *raw)
cooked->state.time_offset = raw->state.time_offset;
return cooked;
}
+
+#define if_free(x) ((x) ? free(x) : (void) 0)
+
+void
+cc_flightcooked_free(struct cc_flightcooked *cooked)
+{
+ if_free(cooked->accel_accel.data);
+ if_free(cooked->accel_speed.data);
+ if_free(cooked->accel_pos.data);
+ if_free(cooked->pres_pos.data);
+ if_free(cooked->pres_speed.data);
+ if_free(cooked->pres_accel.data);
+ if_free(cooked->gps_lat.data);
+ if_free(cooked->gps_lon.data);
+ if_free(cooked->gps_alt.data);
+ if_free(cooked->state.data);
+ free(cooked);
+}
diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h
index 356794e0..4e9aadc4 100644
--- a/ao-tools/lib/cc.h
+++ b/ao-tools/lib/cc.h
@@ -266,14 +266,41 @@ int
cc_timedata_min(struct cc_timedata *d, double min_time, double max_time);
int
+cc_timedata_min_mag(struct cc_timedata *d, double min_time, double max_time);
+
+int
cc_timedata_max(struct cc_timedata *d, double min_time, double max_time);
int
+cc_timedata_max_mag(struct cc_timedata *d, double min_time, double max_time);
+
+double
+cc_timedata_average(struct cc_timedata *d, double min_time, double max_time);
+
+double
+cc_timedata_average_mag(struct cc_timedata *d, double min_time, double max_time);
+
+int
+cc_perioddata_limits(struct cc_perioddata *d, double min_time, double max_time, int *start, int *stop);
+
+int
cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time);
int
+cc_perioddata_min_mag(struct cc_perioddata *d, double min_time, double max_time);
+
+int
cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time);
+int
+cc_perioddata_max_mag(struct cc_perioddata *d, double min_time, double max_time);
+
+double
+cc_perioddata_average(struct cc_perioddata *d, double min_time, double max_time);
+
+double
+cc_perioddata_average_mag(struct cc_perioddata *d, double min_time, double max_time);
+
double *
cc_low_pass(double *data, int data_len, double omega_pass, double omega_stop, double error);
@@ -295,5 +322,7 @@ cc_perioddata_differentiate(struct cc_perioddata *i);
struct cc_flightcooked *
cc_flight_cook(struct cc_flightraw *raw);
+void
+cc_flightcooked_free(struct cc_flightcooked *cooked);
#endif /* _CC_H_ */