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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 string[*] parse_data(file f) {
21 while (!File::end(f)) {
22 string l = File::fgets(f);
25 return String::parse_csv(l);
27 return (string[0]) {};
30 public typedef struct {
38 public record_t parse_record(file f, real accel_scale) {
39 string[*] data = parse_data(f);
41 return (record_t) { .done = true };
46 switch (string_to_integer(data[0])) {
62 .time = string_to_real(data[time_off]),
63 .height = imprecise(string_to_real(data[height_off])),
64 .acceleration = imprecise(string_to_real(data[accel_off]) * accel_scale),
65 .pressure = imprecise(string_to_real(data[pres_off]))
69 public void dump(file f) {
71 record_t r = parse_record(f, 1);
74 printf ("%f %f %f\n", r.time, r.height, r.acceleration);