2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 string[*] parse_data(file f) {
20 while (!File::end(f)) {
21 string l = File::fgets(f);
24 return String::parse_csv(l);
26 return (string[0]) {};
29 public typedef struct {
37 public record_t parse_record(file f, real accel_scale) {
38 string[*] data = parse_data(f);
40 return (record_t) { .done = true };
45 switch (string_to_integer(data[0])) {
61 .time = string_to_real(data[time_off]),
62 .height = imprecise(string_to_real(data[height_off])),
63 .acceleration = imprecise(string_to_real(data[accel_off]) * accel_scale),
64 .pressure = imprecise(string_to_real(data[pres_off]))
68 public void dump(file f) {
70 record_t r = parse_record(f, 1);
73 printf ("%f %f %f\n", r.time, r.height, r.acceleration);