- 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;