68char *option[N_OPTIONS] = {
83 "Usage: sddsgfit [<inputfile>] [<outputfile>] [-pipe=[input][,output]]\n"
84 " -columns=<x-name>,<y-name>[,ySigma=<sy-name>]\n"
85 " -fitRange=<lower>|@<parameter-name>,<upper>|@<parameter-name>\n"
87 " -verbosity=<integer>\n"
88 " -stepSize=<factor>\n"
89 " -tolerance=<value>\n"
90 " -guesses=[baseline=<value>|@<parameter-name>][,mean=<value>|@<parameter-name>]"
91 "[,height=<value>|@<parameter-name>][,sigma=<value>|@<parameter-name>]\n"
92 " -fixValue=[baseline=<value>|@<parameter-name>][,mean=<value>|@<parameter-name>]"
93 "[,height=<value>|@<parameter-name>][,sigma=<value>|@<parameter-name>]\n"
94 " -limits=[evaluations=<number>][,passes=<number>]\n"
95 " -majorOrder=row|column\n\n"
96 "Performs a Gaussian fit of the form:\n"
97 " y = <baseline> + <height> * exp(-0.5 * (x - <mean>)^2 / <sigma>^2)\n"
98 "Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
100void report(
double res,
double *a,
long pass,
long n_eval,
long n_dimen);
101void setupOutputFile(
SDDS_DATASET *OutputTable,
long *xIndex,
long *yIndex,
long *syIndex,
long *fitIndex,
102 long *residualIndex,
long fullOutput,
char *output,
SDDS_DATASET *InputTable,
103 char *xName,
char *yName,
char *syName,
short columnMajorOrder);
104long computeStartingPoint(
double *a,
double *da,
double *x,
double *y, int64_t n,
unsigned long guessFlags,
105 double sigmaGuess,
double meanGuess,
double baselineGuess,
double heightGuess,
107double fitFunction(
double *a,
long *invalid);
108int64_t makeFilteredCopy(
double **xFit,
double **yFit,
double **syFit,
double *x,
double *y,
double *sy,
109 int64_t n,
double lower,
double upper);
111static double *xDataFit = NULL, *yDataFit = NULL, *syDataFit = NULL;
112static int64_t nDataFit = 0;
114#define GUESS_BASELINE_GIVEN 0x0001
115#define FIX_BASELINE_GIVEN (0x0001 << 4)
116#define GUESS_HEIGHT_GIVEN 0x0002
117#define FIX_HEIGHT_GIVEN (0x0002 << 4)
118#define GUESS_MEAN_GIVEN 0x0004
119#define FIX_MEAN_GIVEN (0x0004 << 4)
120#define GUESS_SIGMA_GIVEN 0x0008
121#define FIX_SIGMA_GIVEN (0x0008 << 4)
123#define BASELINE_INDEX 0
124#define HEIGHT_INDEX 1
128int main(
int argc,
char **argv) {
129 double *xData = NULL, *yData = NULL, *syData = NULL;
134 char *input, *output, *xName, *yName, *syName;
135 long xIndex, yIndex, fitIndex, residualIndex, syIndex_out, retval;
136 double *fitData, *residualData, rmsResidual, chiSqr, sigLevel;
137 unsigned long guessFlags, dummyFlags, pipeFlags, majorOrderFlag;
138 double sigmaGuess, meanGuess, baselineGuess, heightGuess;
139 double tolerance, stepSize;
140 double a[4], da[4], lower, upper, result;
141 double aLow[4], aHigh[4];
142 short disable[4] = {0, 0, 0, 0};
143 int32_t nEvalMax = 5000, nPassMax = 100;
144 long nEval, verbosity, fullOutput = 0;
146 short columnMajorOrder = -1;
147 char *lowerPar, *upperPar, *baselineGuessPar, *sigmaGuessPar, *meanGuessPar, *heightGuessPar;
150 argc =
scanargs(&s_arg, argc, argv);
151 if (argc < 2 || argc > (2 + N_OPTIONS)) {
155 for (i = 0; i < 4; i++) {
156 aLow[i] = -(aHigh[i] = DBL_MAX);
158 aLow[SIGMA_INDEX] = 0;
159 input = output = NULL;
163 guessFlags = sigmaGuess = heightGuess = baselineGuess = meanGuess = pipeFlags = 0;
164 xName = yName = syName = NULL;
166 lowerPar = upperPar = sigmaGuessPar = heightGuessPar = baselineGuessPar = meanGuessPar = NULL;
168 for (i_arg = 1; i_arg < argc; i_arg++) {
169 if (s_arg[i_arg].arg_type == OPTION) {
170 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
171 case SET_MAJOR_ORDER:
173 s_arg[i_arg].n_items--;
174 if (s_arg[i_arg].n_items > 0 && (!
scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1,
175 &s_arg[i_arg].n_items, 0,
"row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
176 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL))) {
177 SDDS_Bomb(
"invalid -majorOrder syntax/values");
179 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER) {
180 columnMajorOrder = 1;
181 }
else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER) {
182 columnMajorOrder = 0;
187 if (s_arg[i_arg].n_items != 3) {
190 if (s_arg[i_arg].list[1][0] ==
'@') {
191 cp_str(&lowerPar, s_arg[i_arg].list[1] + 1);
192 }
else if (sscanf(s_arg[i_arg].list[1],
"%lf", &lower) != 1) {
193 SDDS_Bomb(
"invalid fitRange lower value provided");
195 if (s_arg[i_arg].list[2][0] ==
'@') {
196 cp_str(&upperPar, s_arg[i_arg].list[2] + 1);
197 }
else if (sscanf(s_arg[i_arg].list[2],
"%lf", &upper) != 1) {
198 SDDS_Bomb(
"invalid fitRange upper value provided");
203 if (s_arg[i_arg].n_items != 2 ||
204 sscanf(s_arg[i_arg].list[1],
"%lf", &tolerance) != 1 ||
206 SDDS_Bomb(
"incorrect -tolerance syntax");
211 if (s_arg[i_arg].n_items != 2 ||
212 sscanf(s_arg[i_arg].list[1],
"%lf", &stepSize) != 1 ||
219 if (s_arg[i_arg].n_items != 2 ||
220 sscanf(s_arg[i_arg].list[1],
"%ld", &verbosity) != 1) {
221 SDDS_Bomb(
"incorrect -verbosity syntax");
226 if (s_arg[i_arg].n_items < 2) {
229 s_arg[i_arg].n_items -= 1;
230 dummyFlags = guessFlags;
231 if (!
scanItemList(&guessFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
232 "baseline",
SDDS_STRING, &baselineGuessPar, 1, GUESS_BASELINE_GIVEN,
233 "height",
SDDS_STRING, &heightGuessPar, 1, GUESS_HEIGHT_GIVEN,
234 "mean",
SDDS_STRING, &meanGuessPar, 1, GUESS_MEAN_GIVEN,
235 "sigma",
SDDS_STRING, &sigmaGuessPar, 1, GUESS_SIGMA_GIVEN, NULL)) {
238 if (baselineGuessPar) {
239 if (baselineGuessPar[0] ==
'@') {
242 if (sscanf(baselineGuessPar,
"%lf", &baselineGuess) != 1) {
243 SDDS_Bomb(
"Invalid baseline guess value provided.");
245 free(baselineGuessPar);
246 baselineGuessPar = NULL;
249 if (heightGuessPar) {
250 if (heightGuessPar[0] ==
'@') {
253 if (sscanf(heightGuessPar,
"%lf", &heightGuess) != 1) {
254 SDDS_Bomb(
"Invalid height guess value provided.");
256 free(heightGuessPar);
257 heightGuessPar = NULL;
261 if (meanGuessPar[0] ==
'@') {
264 if (sscanf(meanGuessPar,
"%lf", &meanGuess) != 1) {
265 SDDS_Bomb(
"Invalid mean guess value provided.");
272 if (sigmaGuessPar[0] ==
'@') {
275 if (sscanf(sigmaGuessPar,
"%lf", &sigmaGuess) != 1) {
276 SDDS_Bomb(
"Invalid sigma guess value provided.");
279 sigmaGuessPar = NULL;
282 if ((dummyFlags >> 4) & guessFlags) {
283 SDDS_Bomb(
"can't have -fixedValue and -guesses for the same item");
285 guessFlags |= dummyFlags;
289 if (s_arg[i_arg].n_items < 2) {
292 s_arg[i_arg].n_items -= 1;
293 dummyFlags = guessFlags;
294 if (!
scanItemList(&guessFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
295 "baseline",
SDDS_STRING, &baselineGuessPar, 1, FIX_BASELINE_GIVEN,
296 "height",
SDDS_STRING, &heightGuessPar, 1, FIX_HEIGHT_GIVEN,
297 "mean",
SDDS_STRING, &meanGuessPar, 1, FIX_MEAN_GIVEN,
298 "sigma",
SDDS_STRING, &sigmaGuessPar, 1, FIX_SIGMA_GIVEN, NULL)) {
301 if (dummyFlags & (guessFlags >> 4)) {
302 SDDS_Bomb(
"can't have -fixValue and -guesses for the same item");
304 guessFlags |= dummyFlags;
305 if (baselineGuessPar) {
306 if (baselineGuessPar[0] ==
'@') {
309 if (sscanf(baselineGuessPar,
"%lf", &baselineGuess) != 1) {
310 SDDS_Bomb(
"Invalid baseline guess value provided.");
312 free(baselineGuessPar);
313 baselineGuessPar = NULL;
316 if (heightGuessPar) {
317 if (heightGuessPar[0] ==
'@') {
320 if (sscanf(heightGuessPar,
"%lf", &heightGuess) != 1) {
321 SDDS_Bomb(
"Invalid height guess value provided.");
323 free(heightGuessPar);
324 heightGuessPar = NULL;
328 if (meanGuessPar[0] ==
'@') {
331 if (sscanf(meanGuessPar,
"%lf", &meanGuess) != 1) {
332 SDDS_Bomb(
"Invalid mean guess value provided.");
339 if (sigmaGuessPar[0] ==
'@') {
342 if (sscanf(sigmaGuessPar,
"%lf", &sigmaGuess) != 1) {
343 SDDS_Bomb(
"Invalid sigma guess value provided.");
346 sigmaGuessPar = NULL;
352 if (s_arg[i_arg].n_items != 3 && s_arg[i_arg].n_items != 4) {
355 xName = s_arg[i_arg].list[1];
356 yName = s_arg[i_arg].list[2];
357 s_arg[i_arg].n_items -= 3;
358 if (!
scanItemList(&dummyFlags, s_arg[i_arg].list + 3, &s_arg[i_arg].n_items, 0,
369 if (s_arg[i_arg].n_items < 2) {
372 s_arg[i_arg].n_items -= 1;
373 if (!
scanItemList(&dummyFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
374 "evaluations",
SDDS_LONG, &nEvalMax, 1, 0,
375 "passes",
SDDS_LONG, &nPassMax, 1, 0, NULL) ||
376 nEvalMax <= 0 || nPassMax <= 0) {
382 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags)) {
388 fprintf(stderr,
"error: unknown/ambiguous option: %s\n", s_arg[i_arg].list[0]);
394 input = s_arg[i_arg].list[0];
395 }
else if (output == NULL) {
396 output = s_arg[i_arg].list[0];
405 for (i = 0; i < 4; i++) {
406 if ((guessFlags >> 4) & (1 << i)) {
411 if (!xName || !yName) {
412 SDDS_Bomb(
"-columns option must be given");
420 (syName && !
SDDS_FindColumn(&InputTable, FIND_NUMERIC_TYPE, syName, NULL))) {
421 SDDS_Bomb(
"one or more of the given data columns is nonexistent or nonnumeric");
424 setupOutputFile(&OutputTable, &xIndex, &yIndex, &syIndex_out, &fitIndex, &residualIndex,
425 fullOutput, output, &InputTable, xName, yName, syName, columnMajorOrder);
428 xData = yData = syData = NULL;
429 fitData = residualData = NULL;
460 if ((nDataFit = makeFilteredCopy(&xDataFit, &yDataFit, &syDataFit, xData, yData, syData, nData, lower, upper)) < 5) {
470 if (!computeStartingPoint(a, da, xDataFit, yDataFit, nDataFit, guessFlags, sigmaGuess, meanGuess,
471 baselineGuess, heightGuess, stepSize)) {
472 fprintf(stderr,
"error: couldn't compute starting point for page %ld--skipping\n", retval);
476 fprintf(stderr,
"starting values: sigma=%.6e mean=%.6e baseline=%.6e height=%.6e\n",
477 a[SIGMA_INDEX], a[MEAN_INDEX], a[BASELINE_INDEX], a[HEIGHT_INDEX]);
480 fprintf(stderr,
"starting steps: sigma=%.6e mean=%.6e baseline=%.6e height=%.6e\n",
481 da[SIGMA_INDEX], da[MEAN_INDEX], da[BASELINE_INDEX], da[HEIGHT_INDEX]);
484 nEval =
simplexMin(&result, a, da, aLow, aHigh, disable, 4, -DBL_MAX, tolerance,
485 fitFunction, (verbosity > 0 ? report : NULL),
486 nEvalMax, nPassMax, 12, 3, 1.0, 0);
487 if (xData != xDataFit) {
496 fprintf(stderr,
"%ld evaluations of fit function required, giving result %e\n", nEval, result);
499 fitData =
trealloc(fitData,
sizeof(*fitData) * nData);
500 residualData =
trealloc(residualData,
sizeof(*residualData) * nData);
501 for (i = 0, result = 0; i < nData; i++) {
502 fitData[i] = a[BASELINE_INDEX] + a[HEIGHT_INDEX] * exp(-
ipow((xData[i] - a[MEAN_INDEX]) / a[SIGMA_INDEX], 2) / 2);
503 residualData[i] = yData[i] - fitData[i];
504 result += sqr(residualData[i]);
506 rmsResidual = sqrt(result / nData);
508 for (i = 0, chiSqr = 0; i < nData; i++) {
509 chiSqr += sqr(residualData[i] / syData[i]);
512 double sy2 = result / (nData - 4);
513 for (i = 0, chiSqr = 0; i < nData; i++) {
514 chiSqr += sqr(residualData[i]) / sy2;
519 fprintf(stderr,
"sigma: %.15e\nmean: %.15e\nbaseline: %.15e\nheight: %.15e\n",
520 a[SIGMA_INDEX], a[MEAN_INDEX], a[BASELINE_INDEX], a[HEIGHT_INDEX]);
524 fprintf(stderr,
"Significance level: %.5e\n", sigLevel);
526 fprintf(stderr,
"RMS deviation: %.15e\n", rmsResidual);
531 !
SDDS_SetColumn(&OutputTable, SDDS_SET_BY_INDEX, xData, nData, xIndex) ||
532 !
SDDS_SetColumn(&OutputTable, SDDS_SET_BY_INDEX, fitData, nData, fitIndex) ||
534 "gfitSigma", a[SIGMA_INDEX],
535 "gfitMean", a[MEAN_INDEX],
536 "gfitBaseline", a[BASELINE_INDEX],
537 "gfitHeight", a[HEIGHT_INDEX],
538 "gfitRmsResidual", rmsResidual,
539 "gfitSigLevel", sigLevel, NULL) ||
541 (!
SDDS_SetColumn(&OutputTable, SDDS_SET_BY_INDEX, yData, nData, yIndex) ||
542 !
SDDS_SetColumn(&OutputTable, SDDS_SET_BY_INDEX, residualData, nData, residualIndex) ||
543 (syName && !
SDDS_SetColumn(&OutputTable, SDDS_SET_BY_INDEX, syData, nData, syIndex_out)))) ||
575 if (baselineGuessPar) {
576 free(baselineGuessPar);
578 if (heightGuessPar) {
579 free(heightGuessPar);
588void setupOutputFile(
SDDS_DATASET *OutputTable,
long *xIndex,
long *yIndex,
long *syIndex,
long *fitIndex,
589 long *residualIndex,
long fullOutput,
char *output,
SDDS_DATASET *InputTable,
590 char *xName,
char *yName,
char *syName,
short columnMajorOrder) {
591 char *name, *yUnits, *description, *xUnits;
593 static char *residualNamePart =
"Residual";
594 static char *residualDescriptionPart =
"Residual of Gaussian fit to ";
605 if (columnMajorOrder != -1) {
606 OutputTable->layout.data_mode.column_major = columnMajorOrder;
608 OutputTable->layout.data_mode.column_major = InputTable->layout.data_mode.column_major;
611 name =
tmalloc(
sizeof(*name) * (strlen(yName) + strlen(residualNamePart) + 1));
612 description =
tmalloc(
sizeof(*description) * (strlen(yName) + strlen(residualDescriptionPart) + 1));
625 sprintf(name,
"%s%s", yName, residualNamePart);
626 sprintf(description,
"%s%s", yName, residualDescriptionPart);
632 sprintf(name,
"%sFit", yName);
633 sprintf(description,
"Gaussian fit to %s", yName);
638 if (
SDDS_DefineParameter(OutputTable,
"gfitBaseline", NULL, yUnits,
"Baseline from Gaussian fit",
646 SDDS_DefineParameter(OutputTable,
"gfitRmsResidual", NULL, yUnits,
"RMS residual from Gaussian fit",
648 SDDS_DefineParameter(OutputTable,
"gfitSigLevel", NULL, NULL,
"Significance level from chi-squared test",
659double fitFunction(
double *a,
long *invalid) {
660 double sum, tmp, mean, sigma, base, norm;
664 sigma = a[SIGMA_INDEX];
665 mean = a[MEAN_INDEX];
666 base = a[BASELINE_INDEX];
667 norm = a[HEIGHT_INDEX];
670 for (i = sum = 0; i < nDataFit; i++) {
671 tmp = (xDataFit[i] - mean) / sigma;
672 tmp = yDataFit[i] - base - norm * exp(-sqr(tmp) / 2);
675 return (sum / nDataFit);
677 for (i = sum = 0; i < nDataFit; i++) {
678 tmp = (xDataFit[i] - mean) / sigma;
679 tmp = (yDataFit[i] - base - norm * exp(-sqr(tmp) / 2)) / syDataFit[i];
682 return (sum / nDataFit);
686void report(
double y,
double *x,
long pass,
long nEval,
long n_dimen) {
689 fprintf(stderr,
"pass %ld, after %ld evaluations: result = %.16e\na = ", pass, nEval, y);
690 for (i = 0; i < n_dimen; i++) {
691 fprintf(stderr,
"%.8e ", x[i]);
696long computeStartingPoint(
double *a,
double *da,
double *x,
double *y, int64_t n,
unsigned long guessFlags,
697 double sigmaGuess,
double meanGuess,
double baselineGuess,
double heightGuess,
699 double xhalf, dhalf, ymin, ymax, xcenter, tmp, xmax, xmin;
708 ymax = xmax = -DBL_MAX;
709 ymin = xmin = DBL_MAX;
710 for (i = 0; i < n; i++) {
711 if (xmax < fabs(x[i])) {
714 if (xmin > fabs(x[i])) {
729 for (i = 0; i < n; i++) {
730 tmp = fabs((fabs(y[i] - ymax) / (ymax - ymin)) - 0.5);
736 if (dhalf != DBL_MAX) {
737 a[SIGMA_INDEX] = fabs(xhalf - xcenter) / 1.177;
739 a[SIGMA_INDEX] = xmax - xmin;
741 a[MEAN_INDEX] = xcenter;
742 a[BASELINE_INDEX] = ymin;
743 a[HEIGHT_INDEX] = ymax - ymin;
745 if (guessFlags & (GUESS_SIGMA_GIVEN + FIX_SIGMA_GIVEN)) {
746 a[SIGMA_INDEX] = sigmaGuess;
748 if (guessFlags & (GUESS_MEAN_GIVEN + FIX_MEAN_GIVEN)) {
749 a[MEAN_INDEX] = meanGuess;
751 if (guessFlags & (GUESS_BASELINE_GIVEN + FIX_BASELINE_GIVEN)) {
752 a[BASELINE_INDEX] = baselineGuess;
754 if (guessFlags & (GUESS_HEIGHT_GIVEN + FIX_HEIGHT_GIVEN)) {
755 a[HEIGHT_INDEX] = heightGuess;
759 for (i = 0; i < 4; i++) {
760 if (!(da[i] = a[i] * stepSize))
767int64_t makeFilteredCopy(
double **xFit,
double **yFit,
double **syFit,
double *x,
double *y,
768 double *sy, int64_t n,
double lower,
double upper) {
771 if (!(*xFit = (
double *)malloc(
sizeof(**xFit) * n)) ||
772 !(*yFit = (
double *)malloc(
sizeof(**yFit) * n)) ||
773 (sy && !(*syFit = (
double *)malloc(
sizeof(**syFit) * n)))) {
777 for (i = j = 0; i < n; i++) {
778 if (x[i] < lower || x[i] > upper) {
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_CopyParameters(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_ChangeColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a column definition within the SDDS dataset.
int32_t SDDS_GetColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified column in the SDDS dataset.
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_DefineColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length)
Defines a data column within the SDDS dataset.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
int32_t SDDS_TransferColumnDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a column definition from a source dataset to a target dataset.
int32_t SDDS_TransferAllParameterDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
Transfers all parameter definitions from a source dataset to a target dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
char * SDDS_FindColumn(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Finds the first column in the SDDS dataset that matches the specified criteria.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
double ipow(const double x, const int64_t p)
Compute x raised to the power p (x^p).
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
void free_scanargs(SCANNED_ARG **scanned, int argc)
long scanItemList(unsigned long *flags, char **item, long *items, unsigned long mode,...)
Scans a list of items and assigns values based on provided keywords and types.
double ChiSqrSigLevel(double ChiSquared0, long nu)
Computes the probability that a chi-squared variable exceeds a given value.
long simplexMin(double *yReturn, double *xGuess, double *dxGuess, double *xLowerLimit, double *xUpperLimit, short *disable, long dimensions, double target, double tolerance, double(*func)(double *x, long *invalid), void(*report)(double ymin, double *xmin, long pass, long evals, long dims), long maxEvaluations, long maxPasses, long maxDivisions, double divisorFactor, double passRangeFactor, unsigned long flags)
Top-level convenience function for simplex-based minimization.