45 repeat = dataType = interpolType = length = 0;
60 void interpolator::cleanup (
void) {
61 if (rx) { free (rx); rx = NULL; }
62 if (ry) { free (ry); ry = NULL; }
63 if (cy) { free (cy); cy = NULL; }
69 int len2 = 2 + len *
sizeof (nr_double_t);
71 ry = (nr_double_t *) malloc (len2 *
sizeof (nr_double_t));
72 memcpy (ry, y, len1 *
sizeof (nr_double_t));
75 rx = (nr_double_t *) malloc (len2 *
sizeof (nr_double_t));
76 memcpy (rx, x, len1 *
sizeof (nr_double_t));
87 int len2 = 2 + len *
sizeof (nr_double_t);
90 ry = (nr_double_t *) malloc (len2 *
sizeof (nr_double_t));
91 for (
int i = 0;
i < len1;
i++) ry[
i] =
real (y->
get (
i));
94 rx = (nr_double_t *) malloc (len2 *
sizeof (nr_double_t));
95 for (
int i = 0;
i < len1;
i++) rx[
i] =
real (x->
get (
i));
112 rx = (nr_double_t *) malloc (len2 *
sizeof (nr_double_t));
113 memcpy (rx, x, len1 *
sizeof (nr_double_t));
128 for (
int i = 0;
i < len1;
i++) cy[
i] = y->
get (
i);
131 rx = (nr_double_t *) malloc (len2 *
sizeof (nr_double_t));
132 for (
int i = 0;
i < len1;
i++) rx[
i] =
real (x->
get (
i));
141 interpolType = interpol;
147 duration = rx[length - 1] - rx[0];
149 if (cy) cy[length - 1] = cy[0];
150 if (ry) ry[length - 1] = ry[0];
154 if (cy != NULL && (domain &
DATA_POLAR) && length > 1) {
157 for (
int i = 0;
i < length;
i++) ang (
i) =
arg (cy[
i]);
160 for (
int i = 0; i < length; i++) {
175 if (repeat & REPEAT_YES) {
183 for (
int i = 0;
i < length;
i++) {
185 iv (i) =
imag (cy[i]);
209 int interpolator::findIndex (nr_double_t
x) {
214 av = lo + ((hi - lo) / 2);
223 if (lo <= length && lo > 0 && x >= rx[lo - 1])
232 int interpolator::findIndex_old (nr_double_t x) {
234 for (
int i = 0;
i < length;
i++) {
235 if (x >= rx[
i]) idx =
i;
241 nr_double_t interpolator::linear (nr_double_t x,
242 nr_double_t x1, nr_double_t x2,
243 nr_double_t y1, nr_double_t y2) {
245 return (y1 + y2) / 2;
247 return ((x2 - x) * y1 + (x - x1) * y2) / (x2 - x1);
251 nr_double_t interpolator::rlinear (nr_double_t x,
int idx) {
252 return linear (x, rx[idx], rx[idx+1], ry[idx], ry[idx+1]);
256 nr_complex_t interpolator::clinear (nr_double_t x,
int idx) {
257 nr_double_t x1, x2, r,
i;
259 x1 = rx[idx]; x2 = rx[idx+1];
260 y1 = cy[idx]; y2 = cy[idx+1];
261 r = linear (x, x1, x2,
real (y1),
real (y2));
262 i = linear (x, x1, x2,
imag (y1),
imag (y2));
271 nr_double_t res = 0.0;
278 else if (length == 1) {
283 x = x -
floor (x / duration) * duration;
293 if (idx == length - 1) idx--;
294 res = rlinear (x, idx);
322 else if (length == 1) {
327 x = x -
floor (x / duration) * duration;
337 if (idx == length - 1) idx--;
338 res = clinear (x, idx);