/************************************************************** FILLGAPS.C This function linearly interpolates across gaps in a vector. It returns the number of gaps filled. If the gap is at the beginning or end, it is filled with the nearest good value. The number of gaps filled is returned, or n if the situation is hopeless. */ #include "common.h" #include "vector.h" int fill_gaps(float *f, int n) { double fo, df; int i; int n0 = 0, n1 = 0, ngaps = 0; while (n0 < n) { while ((n0 < n) && (good_float(f[n0]))) n0++; /* Now n0 is n or the beginning of a bad section. */ n1 = n0; while ((n1 < n) && (!good_float(f[n1]))) n1++; /* Now n1 is n or the beginning of a good section. */ /* If either is n, both should be n */ /* cases: disaster: n0 = 0 and n1 = n bad start: n0 = 0, n1