55#include <lal/LALStdlib.h>
56#include <lal/LALgetopt.h>
57#include <lal/Integrate.h>
58#include <lal/LALString.h>
61#define UNUSED __attribute__ ((unused))
67#define CODES(x) CODES_(x)
85 y = x4*log(
x + sqrt(x2 + 1));
106 ++(*(n = (
INT4 *)
p));
117 ++(*(n = (
INT4 *)
p));
128 ++(*(n = (
INT4 *)
p));
129 y =
x + 1/sqrt(5 -
x);
152int main (
int argc,
char *argv[])
154 const REAL8 depsilon = 1e-13;
171 " Integrate a regular function over a closed interval.\n");
173 expect = 8.153364119811650205L;
178 printf(
"\nXLALREAL8RombergIntegrate exitted with xlalErrno: %d\n",
xlalErrno);
180 printf (
"number of function calls: %d\n", count);
182 printf (
"result: %.15f\n", dresult);
184 printf (
"expect: %.15Lf\n", expect);
185 if (fabsl(dresult - expect) > depsilon*fabsl(expect))
188 fprintf (stderr,
"Integration did not achieve desired accuracy!\n");
202 " Integrate to infinity a function with power-law fall-off.\n");
204 expect = 1.0L/200.0L;
209 printf(
"\nXLALREAL8RombergIntegrate exitted with xlalErrno: %d\n",
xlalErrno);
211 printf (
"number of function calls: %d\n", count);
213 printf (
"result: %.15f\n", dresult);
215 printf (
"expect: %.15Lf\n", expect);
216 if (fabsl(dresult - expect) > depsilon*fabsl(expect))
219 fprintf (stderr,
"Integration did not achieve desired accuracy!\n");
233 " Integrate to infinity a function that falls off exponentially.");
235 expect = 0.0570261239928920483L;
240 printf(
"\nXLALREAL8RombergIntegrate exitted with xlalErrno: %d\n",
xlalErrno);
242 printf (
"number of function calls: %d\n", count);
244 printf (
"result: %.15f\n", dresult);
246 printf (
"expect: %.15Lf\n", expect);
247 if (fabsl(dresult - expect) > depsilon*fabsl(expect))
250 fprintf (stderr,
"Integration did not achieve desired accuracy!\n");
264 " Integrate an integrable singularity at the lower limit.\n");
271 printf(
"\nXLALREAL8RombergIntegrate exitted with xlalErrno: %d\n",
xlalErrno);
273 printf (
"number of function calls: %d\n", count);
275 printf (
"result: %.15f\n", dresult);
277 printf (
"expect: %.15Lf\n", expect);
278 if (fabsl(dresult - expect) > depsilon*fabsl(expect))
281 fprintf (stderr,
"Integration did not achieve desired accuracy!\n");
295 " Integrate an integrable singularity at the upper limit.\n");
302 printf(
"\nXLALREAL8RombergIntegrate exitted with xlalErrno: %d\n",
xlalErrno);
304 printf (
"number of function calls: %d\n", count);
306 printf (
"result: %.15f\n", dresult);
308 printf (
"expect: %.15Lf\n", expect);
309 if (fabsl(dresult - expect) > depsilon*fabsl(expect))
312 fprintf (stderr,
"Integration did not achieve desired accuracy!\n");
327 printf (
"\nChecking error conditions:\n");
330 printf (
"\nUnknown integral type:\r");
337 printf (
"Unknown integral type check passed.\n");
340 printf (
"\nMaximum iterations exceeded:\r");
347 printf (
"Maximum iterations exceeded check passed.\n");
350 printf (
"\nRecursive error:\r");
357 printf (
"Recursive error check passed.\n");
373 fprintf (stderr,
"Options:\n");
374 fprintf (stderr,
" -h print this message\n");
375 fprintf (stderr,
" -q quiet: run silently\n");
376 fprintf (stderr,
" -v verbose: print extra information\n");
377 fprintf (stderr,
" -d level set lalDebugLevel to level\n");
413 fp = freopen (
"/dev/null",
"w", stderr);
416 fprintf(stderr,
"Error: Unable to open /dev/null\n");
419 fp = freopen (
"/dev/null",
"w", stdout);
422 fprintf(stderr,
"Error: Unable to open /dev/null\n");
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[])
REAL8 XLALREAL8RombergIntegrate(REAL8(*f)(REAL8 x, void *params), void *params, REAL8 xmin, REAL8 xmax, IntegralType type)
@ InfiniteDomainExp
integrate infinite domain with exponential falloff
@ ClosedInterval
evaluate integral on a closed interval
@ SingularLowerLimit
integrate an inv sqrt singularity at lower limit
@ SingularUpperLimit
integrate an inv sqrt singularity at upper limit
@ InfiniteDomainPow
integrate infinite domain with power-law falloff
double REAL8
Double precision real floating-point number (8 bytes).
int32_t INT4
Four-byte signed integer.
const char * XLALErrorString(int code)
Returns the error message associated with an error number.
#define XLAL_ERROR_REAL8(...)
Macro to invoke a failure from a XLAL routine returning a REAL8.
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
#define XLAL_ERROR_MAIN(...)
Macro to invoke a failure from a C main() routine.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EMAXITER
Exceeded maximum number of iterations.
@ XLAL_EINVAL
Invalid argument.