54#include <lal/LALStdlib.h>
55#include <lal/LALgetopt.h>
56#include <lal/FindRoot.h>
57#include <lal/LALString.h>
60#define CODES(x) CODES_(x)
86 ASSERT (
y, s, 1,
"Null pointer");
87 ASSERT (
p, s, 1,
"Null pointer");
98 ASSERT (
y, s, 1,
"Null pointer");
99 ASSERT (
p, s, 1,
"Null pointer");
107main (
int argc,
char *argv[])
156 printf (
"\n===== Check Root Finding =====\n\n");
161 printf (
"Initial domain: [%e,%e]\n", dinput.
xmin, dinput.
xmax);
165 TestStatus (&
status, CODES(0), 1);
169 printf (
"Bracket domain: [%e,%e]\n", sinput.
xmin, sinput.
xmax);
172 if (sinput.
xmin > 1 || sinput.
xmax < 1)
174 fprintf (stderr,
"Root not bracketed correctly\n");
179 TestStatus (&
status, CODES(0), 1);
183 printf (
"Bracket domain: [%e,%e]\n", dinput.
xmin, dinput.
xmax);
186 if (dinput.
xmin > 1 || dinput.
xmax < 1)
188 fprintf (stderr,
"Root not bracketed correctly\n");
194 TestStatus (&
status, CODES(0), 1);
198 printf (
"Root = %e (acc = %e)\n", sroot, sinput.
xacc);
201 if (fabs(sroot - 1) > sinput.
xacc)
203 fprintf (stderr,
"Root not found to correct accuracy\n");
209 TestStatus (&
status, CODES(0), 1);
213 printf (
"Root = %.15e (acc = %e)\n", droot, dinput.
xacc);
216 if (fabs(droot - 1) > dinput.
xacc)
218 fprintf (stderr,
"Root not found to correct accuracy\n");
232 printf (
"\n===== Check Errors =====\n");
239 printf (
"\n----- Recursive Error: Code -1 (2 times)\n");
243 TestStatus (&
status, CODES(-1), 1);
246 TestStatus (&
status, CODES(-1), 1);
253 printf (
"\n----- Null Pointer Error: Code 1 (10 times)\n");
288 printf (
"\n----- Invalid Initial Domain: Code 2 (2 times)\n");
307 printf (
"\n----- Maximum Iteration Exceeded: Code 4 (4 times)\n");
311 sinput.
xmin = -1e-18;
314 dinput.
xmin = -1e-18;
340 printf (
"\n----- Root Not Bracketed: Code 8 (2 times)\n");
381 if ((tok = strtok (str,
" ")))
385 if (
status->statusCode == atoi (tok))
390 while ((tok = strtok (NULL,
" ")));
394 if (
status->statusCode == atoi (str))
401 fprintf (stderr,
"\nExiting to system with code %d\n", exitcode);
419 ClearStatus (
status->statusPtr);
434 fprintf (stderr,
"Options:\n");
435 fprintf (stderr,
" -h print this message\n");
436 fprintf (stderr,
" -q quiet: run silently\n");
437 fprintf (stderr,
" -v verbose: print extra information\n");
438 fprintf (stderr,
" -d level set lalDebugLevel to level\n");
474 fp = freopen (
"/dev/null",
"w", stderr);
477 fprintf(stderr,
"Error: Unable to open /dev/null\n");
480 fp = freopen (
"/dev/null",
"w", stdout);
483 fprintf(stderr,
"Error: Unable to open /dev/null\n");
void REPORTSTATUS(LALStatus *status)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
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[])
void LALDBracketRoot(LALStatus *status, DFindRootIn *inout, void *params)
void LALSBracketRoot(LALStatus *status, SFindRootIn *inout, void *params)
#define FINDROOTH_ENULL
Null pointer.
#define FINDROOTH_EIDOM
Invalid initial domain.
#define FINDROOTH_EBRKT
Root not bracketed.
void LALDBisectionFindRoot(LALStatus *status, REAL8 *root, DFindRootIn *input, void *params)
#define FINDROOTH_EMXIT
Maximum iterations exceeded.
void LALSBisectionFindRoot(LALStatus *status, REAL4 *root, SFindRootIn *input, void *params)
double REAL8
Double precision real floating-point number (8 bytes).
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.
These are function pointers to functions that map REAL8 numbers to REAL8 numbers.
REAL8 xacc
The accuracy desired for the root.
REAL8 xmax
The maximum value of the domain interval to look for the root.
void(* function)(LALStatus *s, REAL8 *y, REAL8 x, void *p)
The function to find the root of.
REAL8 xmin
The minimum value of the domain interval to look for the root.
LAL status structure, see The LALStatus structure for more details.
These are function pointers to functions that map REAL4 numbers to REAL4 numbers.
REAL4 xacc
The accuracy desired for the root.
REAL4 xmax
The maximum value of the domain interval to look for the root.
REAL4 xmin
The minimum value of the domain interval to look for the root.
void(* function)(LALStatus *s, REAL4 *y, REAL4 x, void *p)
The function to find the root of.