read_one needs to initialize rec_int_ms if it hasn't been already

This commit is contained in:
Sean C. Rhea
2006-11-22 21:06:18 +00:00
parent 1ef0903826
commit 509282b0b8

View File

@@ -38,7 +38,7 @@ struct point
static struct point *head, *tail; static struct point *head, *tail;
time_t start_since_epoch; time_t start_since_epoch;
static double last_secs; static double last_secs;
static int rec_int_ms = 1.26 * 1000.0; static int rec_int_ms;
static int static int
secs_to_interval(double secs) secs_to_interval(double secs)
@@ -61,6 +61,17 @@ add_point(double secs, double watts)
tail = p; tail = p;
} }
static void
config_cb(unsigned interval, unsigned rec_int,
unsigned wheel_sz_mm, void *context)
{
double new_rec_int_ms = rec_int * 1.26 * 1000.0;
interval = wheel_sz_mm = 0;
context = NULL;
assert((rec_int_ms == 0.0) || (rec_int_ms == new_rec_int_ms));
rec_int_ms = new_rec_int_ms;
}
static void static void
time_cb(struct tm *time, time_t since_epoch, void *context) time_cb(struct tm *time, time_t since_epoch, void *context)
{ {
@@ -174,8 +185,8 @@ update_cpi_file(struct cpi_file_info *info,
start_since_epoch = 0; start_since_epoch = 0;
last_secs = 0.0; last_secs = 0.0;
pt_read_raw(in, 0 /* not compat */, NULL, NULL, pt_read_raw(in, 0 /* not compat */, NULL,
&time_cb, &data_cb, &error_cb); &config_cb, &time_cb, &data_cb, &error_cb);
total_intervals = secs_to_interval(tail->secs); total_intervals = secs_to_interval(tail->secs);
bests = (double*) calloc(total_intervals + 1, sizeof(double)); bests = (double*) calloc(total_intervals + 1, sizeof(double));
@@ -248,6 +259,8 @@ read_one(const char *inname, double *bests[], int *bestlen)
fprintf(stderr, "Bad match on line %d: %s", lineno, line); fprintf(stderr, "Bad match on line %d: %s", lineno, line);
exit(1); exit(1);
} }
if (rec_int_ms == 0)
rec_int_ms = mins * 60.0 * 1000.0;
interval = secs_to_interval(mins * 60.0); interval = secs_to_interval(mins * 60.0);
while (interval >= *bestlen) { while (interval >= *bestlen) {
tmp = calloc(*bestlen * 2, sizeof(double)); tmp = calloc(*bestlen * 2, sizeof(double));