34double interp(
double *f,
double *x,
long n,
double xo,
long warnings,
long order,
long *returnCode) {
35 long hi, lo, mid, offset;
41 printf(
"warning: only one point--returning value for that point\n");
48 printf(
"warning: %22.15e outside [%22.15e,%22.15e] (interp)\n",
53 if (xo > x[hi = n - 1]) {
55 printf(
"warning: %22.15e outside [%22.15e,%22.15e] (interp)\n",
62 while ((hi - lo) > 1) {
72 printf(
"warning: %22.15e outside [%22.15e,%22.15e] (interp)\n",
77 if (xo < x[hi = n - 1]) {
79 printf(
"warning: %22.15e outside [%22.15e,%22.15e] (interp)\n",
86 while ((hi - lo) > 1) {
95 offset = lo - (order - 1) / 2;
96 offset = MAX(offset, 0);
97 offset = MIN(offset, n - order - 1);
98 offset = MAX(offset, 0);
99 return LagrangeInterp(x + offset, f + offset, order + 1, xo, returnCode);
160double interpolate(
double *f,
double *x, int64_t n,
double xo, OUTRANGE_CONTROL *belowRange,
161 OUTRANGE_CONTROL *aboveRange,
long order,
unsigned long *returnCode,
long M) {
163 int64_t hi, lo, mid, offset;
164 double result, below, above;
177 if ((xo * M > x[hi] * M && M > 0) || (xo * M < x[lo] * M && M < 0)) {
178 if (aboveRange->flags & OUTRANGE_SKIP) {
179 *returnCode = OUTRANGE_SKIP;
181 }
else if (aboveRange->flags & OUTRANGE_ABORT) {
182 *returnCode = OUTRANGE_ABORT;
184 }
else if (aboveRange->flags & OUTRANGE_WARN)
185 *returnCode = OUTRANGE_WARN;
186 if (aboveRange->flags & OUTRANGE_VALUE) {
187 *returnCode |= OUTRANGE_VALUE;
188 return aboveRange->value;
190 if (aboveRange->flags & OUTRANGE_WRAP) {
192 *returnCode |= OUTRANGE_WRAP;
193 if ((delta = x[hi] - x[lo]) == 0)
195 while (xo * M > x[hi] * M)
197 }
else if (aboveRange->flags & OUTRANGE_SATURATE || !(aboveRange->flags & OUTRANGE_EXTRAPOLATE)) {
198 *returnCode |= OUTRANGE_SATURATE;
202 if ((xo * M < x[lo] * M && M > 0) || (xo * M > x[hi] * M && M < 0)) {
203 if (belowRange->flags & OUTRANGE_SKIP) {
204 *returnCode = OUTRANGE_SKIP;
206 }
else if (belowRange->flags & OUTRANGE_ABORT) {
207 *returnCode = OUTRANGE_ABORT;
209 }
else if (belowRange->flags & OUTRANGE_WARN)
210 *returnCode = OUTRANGE_WARN;
211 if (belowRange->flags & OUTRANGE_VALUE) {
212 *returnCode |= OUTRANGE_VALUE;
213 return belowRange->value;
215 if (belowRange->flags & OUTRANGE_WRAP) {
217 *returnCode |= OUTRANGE_WRAP;
218 if ((delta = x[hi] - x[lo]) == 0)
220 while (xo * M < x[lo] * M)
222 }
else if (belowRange->flags & OUTRANGE_SATURATE || !(belowRange->flags & OUTRANGE_EXTRAPOLATE)) {
223 *returnCode |= OUTRANGE_SATURATE;
230 if (aboveRange->flags & OUTRANGE_WARN || belowRange->flags & OUTRANGE_WARN)
231 *returnCode = OUTRANGE_WARN;
238 if (xo * M < x[0] * M)
240 else if (xo * M > x[n - 1] * M)
244 while ((hi - lo) > 1) {
246 if (xo * M < x[mid] * M)
256 offset = lo - (order - 1) / 2;
257 offset = MAX(offset, 0);
258 offset = MIN(offset, n - order - 1);
259 result =
LagrangeInterp(x + offset, f + offset, order + 1, xo, &code);
261 bomb(
"zero denominator in LagrangeInterp", NULL);
short interp_short(short *f, double *x, int64_t n, double xo, long warnings, short order, unsigned long *returnCode, long *next_start_pos)
Performs interpolation for short integer data types.
double LagrangeInterp(double *x, double *f, long order1, double x0, long *returnCode)
Performs Lagrange interpolation of data.
double interpolate(double *f, double *x, int64_t n, double xo, OUTRANGE_CONTROL *belowRange, OUTRANGE_CONTROL *aboveRange, long order, unsigned long *returnCode, long M)
Performs interpolation with range control options.
double interp(double *f, double *x, long n, double xo, long warnings, long order, long *returnCode)
Performs simple linear interpolation of data.