54#include <lal/LALStdlib.h>
55#include <lal/LALgetopt.h>
56#include <lal/AVFactories.h>
57#include <lal/Interpolate.h>
58#include <lal/LALString.h>
61#define CODES(x) CODES_(x)
69static void TestStatus (
LALStatus *
status,
const char *expectCodes,
int exitCode);
71int main (
int argc,
char *argv[])
73 enum {ArraySize = 10};
91 TestStatus (&
status, CODES(0), 1);
93 TestStatus (&
status, CODES(0), 1);
95 TestStatus (&
status, CODES(0), 1);
97 TestStatus (&
status, CODES(0), 1);
100 printf (
"Initial data:\n");
102 printf (
"y = P(x) = 7 - 8x + 2x^2 + 2x^3 - x^4\n");
104 printf (
"-----------------\n");
108 printf (
"=================\n");
109 for (i = 0; i < ArraySize; ++i)
112 y->data[i] = yy->
data[i] = 7 + xi*(-8 + xi*(2 + xi*(2 - xi)));
114 printf (
"%.0f\t%.0f\n",
x->data[i],
y->data[i]);
117 printf (
"-----------------\n");
120 printf (
"\nInterpolate to x = 0.3:\n");
122 printf (
"---------------------------------\n");
124 printf (
"order\ty\t\tdy\n");
126 printf (
"=================================\n");
129 dintpar.
x = xx->
data;
130 dintpar.
y = yy->
data;
131 for (i = 2; i < ArraySize; ++i)
136 TestStatus (&
status, CODES(0), 1);
138 TestStatus (&
status, CODES(0), 1);
140 printf (
"%d\t%f\t%f\t%f\t%f\n", i - 1,
141 sintout.
y, sintout.
dy, dintout.
y, dintout.
dy);
144 printf (
"---------------------------------\n");
147 printf (
"\nExtrapolate to x = -0.3:\n");
149 printf (
"---------------------------------\n");
151 printf (
"order\ty\t\tdy\n");
153 printf (
"=================================\n");
156 dintpar.
x = xx->
data;
157 dintpar.
y = yy->
data;
158 for (i = 2; i < ArraySize; ++i)
163 TestStatus (&
status, CODES(0), 1);
165 TestStatus (&
status, CODES(0), 1);
167 printf (
"%d\t%f\t%f\t%f\t%f\n", i - 1,
168 sintout.
y, sintout.
dy, dintout.
y, dintout.
dy);
171 printf (
"---------------------------------\n");
175 TestStatus (&
status, CODES(0), 1);
177 TestStatus (&
status, CODES(0), 1);
179 TestStatus (&
status, CODES(0), 1);
181 TestStatus (&
status, CODES(0), 1);
186 TestStatus (&
status, CODES(0), 1);
188 TestStatus (&
status, CODES(0), 1);
190 TestStatus (&
status, CODES(0), 1);
192 TestStatus (&
status, CODES(0), 1);
196 printf (
"\nCheck error conditions:\n");
199 printf (
"\nNull pointer:\r");
205 printf (
"Null pointer check passed.\n");
208 printf (
"\nNull pointer:\r");
214 printf (
"Null pointer check passed.\n");
219 printf (
"\nNull pointer:\r");
225 printf (
"Null pointer check passed.\n");
229 dintpar.
x = xx->
data;
232 printf (
"\nNull pointer:\r");
238 printf (
"Null pointer check passed.\n");
242 dintpar.
y = yy->
data;
245 printf (
"\nInvalid size:\r");
254 printf (
"Invalid size check passed.\n");
256 x->data[1] =
x->data[0] = 2;
261 printf (
"\nZero divide:\r");
270 printf (
"Zero divide check passed.\n");
274 TestStatus (&
status, CODES(0), 1);
276 TestStatus (&
status, CODES(0), 1);
278 TestStatus (&
status, CODES(0), 1);
280 TestStatus (&
status, CODES(0), 1);
307 if ((tok = strtok (str,
" ")))
311 if (
status->statusCode == atoi (tok))
316 while ((tok = strtok (NULL,
" ")));
320 if (
status->statusCode == atoi (str))
327 fprintf (stderr,
"\nExiting to system with code %d\n", exitcode);
341 fprintf (stderr,
"Options:\n");
342 fprintf (stderr,
" -h print this message\n");
343 fprintf (stderr,
" -q quiet: run silently\n");
344 fprintf (stderr,
" -v verbose: print extra information\n");
345 fprintf (stderr,
" -d level set lalDebugLevel to level\n");
381 fp = freopen (
"/dev/null",
"w", stderr);
384 fprintf(stderr,
"Error: Unable to open /dev/null\n");
387 fp = freopen (
"/dev/null",
"w", stdout);
390 fprintf(stderr,
"Error: Unable to open /dev/null\n");
void REPORTSTATUS(LALStatus *status)
void LALCheckMemoryLeaks(void)
int LALgetopt(int argc, char *const *argv, const char *optstring)
static void Usage(const char *program, int exitcode)
static void ParseOptions(int argc, char *argv[])
int main(int argc, char *argv[])
#define INTERPOLATEH_ENULL
Null pointer.
#define INTERPOLATEH_ESIZE
Invalid size.
void LALDPolynomialInterpolation(LALStatus *status, DInterpolateOut *output, REAL8 target, DInterpolatePar *params)
void LALSPolynomialInterpolation(LALStatus *status, SInterpolateOut *output, REAL4 target, SInterpolatePar *params)
#define INTERPOLATEH_EZERO
Zero divide.
REAL8 XLALREAL8PolynomialInterpolation(REAL8 *yout, REAL8 xtarget, REAL8 *y, REAL8 *x, UINT4 n)
float REAL4
Single precision real floating-point number (4 bytes).
size_t XLALStringCopy(char *dst, const char *src, size_t size)
Copy sources string src to destination string dst.
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
const char * XLALErrorString(int code)
Returns the error message associated with an error number.
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
#define XLAL_ERROR_MAIN(...)
Macro to invoke a failure from a C main() routine.
@ XLAL_EFPDIV0
IEEE Division by zero floating point error.
These structures contain the output of the interpolation.
REAL8 y
The interpolated value.
REAL8 dy
The estimated error in the interpolated value.
These structures contain the interpolation parameters; These are the arrays of n domain values and t...
REAL8 * y
The array of values to interpolate.
REAL8 * x
The array of domain values.
UINT4 n
The number of points in the arrays to use in the interpolation.
LAL status structure, see The LALStatus structure for more details.
Vector of type REAL4, see DATATYPE-Vector types for more details.
Vector of type REAL8, see DATATYPE-Vector types for more details.
REAL8 * data
Pointer to the data array.
These structures contain the output of the interpolation.
REAL4 dy
The estimated error in the interpolated value.
REAL4 y
The interpolated value.
These structures contain the interpolation parameters; These are the arrays of n domain values and t...
REAL4 * x
The array of domain values.
UINT4 n
The number of points in the arrays to use in the interpolation.
REAL4 * y
The array of values to interpolate.