SDDSlib
Loading...
Searching...
No Matches
sddsbaseline.c
Go to the documentation of this file.
1/**
2 * @file sddsbaseline.c
3 * @brief Baseline subtraction tool for SDDS datasets.
4 *
5 * This program processes SDDS datasets to subtract a baseline from specified columns.
6 * The baseline can be computed using various methods and selection criteria.
7 * Options allow for nonnegative constraints, despiking, and multiple repeats.
8 *
9 * Usage:
10 * sddsbaseline [<input>] [<output>]
11 * [-pipe=<in>[,<out>]]
12 * [-columns=<listOfNames>]
13 * [-nonnegative [-despike=passes=<number>,widthlimit=<value>] [-repeats=<count>]]
14 * [-select={endpoints=<number> | outsideFWHA=<multiplier> | antioutlier=<passes>}]
15 * [-method={average|fit[,terms=<number>]}]
16 * [-majorOrder=row|column]
17 *
18 * Options:
19 * -pipe Specify input and/or output pipes.
20 * -columns List of columns to process.
21 * -nonnegative Forces all values to be nonnegative after baseline subtraction.
22 * This is accomplished by setting all negative values to 0.
23 * -despike Specify that positive features narrower than widthLimit shall be set to zero.
24 * Parameters:
25 * passes=<number> Number of despike passes.
26 * widthlimit=<value> Width limit for despiking.
27 * -repeats Specify how many times to apply the baseline removal algorithm.
28 * Meaningful only if used in combination with -nonnegative.
29 * -select Specify how to select points to include in baseline determination.
30 * Options:
31 * endpoints=<number>
32 * outsideFWHA=<multiplier>
33 * antioutlier=<passes>
34 * -method Specify how to process selected points in order to compute baseline.
35 * Options:
36 * average
37 * fit[,terms=<number>]
38 * -majorOrder Specify write output in row or column major order.
39 *
40 * @copyright
41 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
42 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
43 *
44 * @license
45 * This file is distributed under the terms of the Software License Agreement
46 * found in the file LICENSE included with this distribution.
47 *
48 * @author M. Borland, R. Soliday, H. Shang
49 */
50
51#include "mdb.h"
52#include "scan.h"
53#include "SDDS.h"
54
55/* Enumeration for option types */
56enum option_type {
57 CLO_PIPE,
58 CLO_COLUMNS,
59 CLO_METHOD,
60 CLO_SELECT,
61 CLO_NONNEGATIVE,
62 CLO_REPEATS,
63 CLO_DESPIKE,
64 CLO_MAJOR_ORDER,
65 N_OPTIONS
66};
67
68static char *option[N_OPTIONS] = {
69 "pipe",
70 "columns",
71 "method",
72 "select",
73 "nonnegative",
74 "repeats",
75 "despike",
76 "majorOrder",
77};
78
79char *USAGE =
80 "Usage: sddsbaseline [<input>] [<output>]\n"
81 " [-pipe=<in>[,<out>]]\n"
82 " [-columns=<listOfNames>]\n"
83 " [-nonnegative [-despike=passes=<number>,widthlimit=<value>] [-repeats=<count>]]\n"
84 " [-select={endpoints=<number> | outsideFWHA=<multiplier> | antioutlier=<passes>}]\n"
85 " [-method={average|fit[,terms=<number>]}]\n"
86 " [-majorOrder=row|column]\n\n"
87 "Options:\n"
88 " -pipe Specify input and/or output pipes.\n"
89 " -columns List of columns to process.\n"
90 " -nonnegative Forces all values to be nonnegative after baseline subtraction.\n"
91 " This is accomplished by setting all negative values to 0.\n"
92 " -despike Specify that positive features narrower than widthLimit shall be set to zero.\n"
93 " Parameters:\n"
94 " passes=<number> Number of despike passes.\n"
95 " widthlimit=<value> Width limit for despiking.\n"
96 " -repeats Specify how many times to apply the baseline removal algorithm.\n"
97 " Meaningful only if used in combination with -nonnegative.\n"
98 " -select Specify how to select points to include in baseline determination.\n"
99 " Options:\n"
100 " endpoints=<number>\n"
101 " outsideFWHA=<multiplier>\n"
102 " antioutlier=<passes>\n"
103 " -method Specify how to process selected points in order to compute baseline.\n"
104 " Options:\n"
105 " average\n"
106 " fit[,terms=<number>]\n"
107 " -majorOrder Specify write output in row or column major order.\n\n"
108 "Program by Michael Borland.("__DATE__" "__TIME__", SVN revision: " SVN_VERSION ")\n";
109
110#define SELECT_ENDPOINTS 0x0001U
111#define SELECT_OUTSIDEFWHA 0x0002U
112#define SELECT_ANTIOUTLIER 0x0004U
113
114#define METHOD_FIT 0x0001U
115#define METHOD_AVERAGE 0x0002U
116
117long resolveColumnNames(SDDS_DATASET *SDDSin, char ***column, int32_t *columns);
118void selectEndpoints(short *selected, int64_t rows, long endPoints);
119void selectOutsideFWHA(double *data, double *indepData, short *selected, int64_t rows, double fwhaLimit);
120void selectAntiOutlier(double *data, short *selected, int64_t rows, long passes);
121void fitAndRemoveBaseline(double *data, double *indepData, short *selected, int64_t rows, long terms);
122void averageAndRemoveBaseline(double *data, short *selected, int64_t rows);
123void despikeProfile(double *data, int64_t rows, long widthLimit, long passes);
124
125int main(int argc, char **argv) {
126 int iArg;
127 char **inputColumn;
128 char *input, *output;
129 long readCode, repeats, repeat, fitTerms = 2;
130 int64_t rows, i, j;
131 int32_t columns;
132 unsigned long pipeFlags, methodFlags, selectFlags, dummyFlags, majorOrderFlag;
133 SCANNED_ARG *scanned;
134 SDDS_DATASET SDDSin, SDDSout;
135 double *data, *indepData;
136 int32_t endPoints, antiOutlierPasses;
137 short *selected;
138 double outsideFWHA;
139 long nonnegative;
140 int32_t despikePasses, despikeWidthLimit;
141 short columnMajorOrder = -1;
142
144 argc = scanargs(&scanned, argc, argv);
145 if (argc < 2)
146 bomb(NULL, USAGE);
147
148 output = input = NULL;
149 inputColumn = NULL;
150 columns = nonnegative = 0;
151 repeats = 1;
152 pipeFlags = methodFlags = selectFlags = dummyFlags = 0;
153 endPoints = antiOutlierPasses = 0;
154 outsideFWHA = 0;
155 despikePasses = 0;
156 despikeWidthLimit = 2;
157
158 for (iArg = 1; iArg < argc; iArg++) {
159 if (scanned[iArg].arg_type == OPTION) {
160 /* process options here */
161 switch (match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
162 case CLO_MAJOR_ORDER:
163 majorOrderFlag = 0;
164 scanned[iArg].n_items -= 1;
165 if (scanned[iArg].n_items > 0 &&
166 (!scanItemList(&majorOrderFlag, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
167 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
168 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
169 SDDS_Bomb("invalid -majorOrder syntax/values");
170 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
171 columnMajorOrder = 1;
172 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
173 columnMajorOrder = 0;
174 break;
175 case CLO_COLUMNS:
176 if (scanned[iArg].n_items < 2)
177 SDDS_Bomb("invalid -columns syntax");
178 inputColumn = tmalloc(sizeof(*inputColumn) * (columns = scanned[iArg].n_items - 1));
179 for (i = 0; i < columns; i++)
180 inputColumn[i] = scanned[iArg].list[i + 1];
181 break;
182 case CLO_PIPE:
183 if (!processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
184 SDDS_Bomb("invalid -pipe syntax");
185 break;
186 case CLO_METHOD:
187 if (!(scanned[iArg].n_items -= 1))
188 SDDS_Bomb("invalid -method syntax");
189 if (!scanItemList(&methodFlags, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
190 "average", -1, NULL, 0, METHOD_AVERAGE,
191 "fit", -1, NULL, 0, METHOD_FIT,
192 "terms", SDDS_LONG, &fitTerms, 1, 0, NULL) ||
193 bitsSet(methodFlags) != 1 || fitTerms < 2)
194 SDDS_Bomb("invalid -method syntax/values");
195 break;
196 case CLO_SELECT:
197 if (!(scanned[iArg].n_items -= 1))
198 SDDS_Bomb("invalid -select syntax");
199 if (!scanItemList(&selectFlags, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
200 "endpoints", SDDS_LONG, &endPoints, 1, SELECT_ENDPOINTS,
201 "outsidefwha", SDDS_DOUBLE, &outsideFWHA, 1, SELECT_OUTSIDEFWHA,
202 "antioutlier", SDDS_LONG, &antiOutlierPasses, 1, SELECT_ANTIOUTLIER, NULL) ||
203 bitsSet(selectFlags) != 1)
204 SDDS_Bomb("invalid -select syntax/values");
205 break;
206 case CLO_NONNEGATIVE:
207 nonnegative = 1;
208 break;
209 case CLO_REPEATS:
210 if (scanned[iArg].n_items != 2 ||
211 sscanf(scanned[iArg].list[1], "%ld", &repeats) != 1 ||
212 repeats <= 0)
213 SDDS_Bomb("invalid -repeats syntax");
214 break;
215 case CLO_DESPIKE:
216 despikePasses = 1;
217 if (!(scanned[iArg].n_items -= 1))
218 SDDS_Bomb("invalid -despike syntax");
219 if (!scanItemList(&dummyFlags, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
220 "passes", SDDS_LONG, &despikePasses, 1, 0,
221 "widthlimit", SDDS_LONG, &despikeWidthLimit, 1, 0, NULL) ||
222 despikePasses < 0 ||
223 despikeWidthLimit < 1)
224 SDDS_Bomb("invalid -despike syntax/values");
225 break;
226 default:
227 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
228 exit(EXIT_FAILURE);
229 break;
230 }
231 } else {
232 if (!input)
233 input = scanned[iArg].list[0];
234 else if (!output)
235 output = scanned[iArg].list[0];
236 else
237 SDDS_Bomb("too many filenames seen");
238 }
239 }
240
241 if (!bitsSet(selectFlags))
242 SDDS_Bomb("no -select option given");
243 if (!bitsSet(methodFlags))
244 SDDS_Bomb("no -method option given");
245
246 if (!nonnegative && despikePasses)
247 SDDS_Bomb("not meaningful to despike without setting -nonnegative");
248 if (!nonnegative && repeats > 1)
249 SDDS_Bomb("not meaningful to repeat without setting -nonnegative");
250
251 processFilenames("sddsbaseline", &input, &output, pipeFlags, 0, NULL);
252
253 if (!columns)
254 SDDS_Bomb("supply the names of columns to process with the -columns option");
255
256 if (!SDDS_InitializeInput(&SDDSin, input))
257 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
258
259 if (!resolveColumnNames(&SDDSin, &inputColumn, &columns))
260 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
261 if (!columns)
262 SDDS_Bomb("no columns selected for processing");
263
264 if (!SDDS_InitializeCopy(&SDDSout, &SDDSin, output, "w"))
265 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
266 if (!SDDS_DefineSimpleColumn(&SDDSout, "SelectedForBaselineDetermination", NULL, SDDS_SHORT))
267 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
268 if (columnMajorOrder != -1)
269 SDDSout.layout.data_mode.column_major = columnMajorOrder;
270 else
271 SDDSout.layout.data_mode.column_major = SDDSin.layout.data_mode.column_major;
272 if (!SDDS_WriteLayout(&SDDSout))
273 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
274
275 indepData = NULL;
276 selected = NULL;
277 while ((readCode = SDDS_ReadPage(&SDDSin)) > 0) {
278 if (!SDDS_CopyPage(&SDDSout, &SDDSin))
279 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
280 if ((rows = SDDS_CountRowsOfInterest(&SDDSin))) {
281 if (!(indepData = SDDS_Realloc(indepData, sizeof(*indepData) * rows)) ||
282 !(selected = SDDS_Realloc(selected, sizeof(*selected) * rows)))
283 SDDS_Bomb("memory allocation failure");
284 for (i = 0; i < rows; i++)
285 indepData[i] = i;
286 for (i = 0; i < columns; i++) {
287 if (!(data = SDDS_GetColumnInDoubles(&SDDSin, inputColumn[i])))
288 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
289 for (repeat = 0; repeat < repeats; repeat++) {
290 for (j = 0; j < rows; j++)
291 selected[j] = 0;
292 switch (selectFlags) {
293 case SELECT_ENDPOINTS:
294 selectEndpoints(selected, rows, endPoints);
295 break;
296 case SELECT_OUTSIDEFWHA:
297 selectOutsideFWHA(data, indepData, selected, rows, outsideFWHA);
298 break;
299 case SELECT_ANTIOUTLIER:
300 selectAntiOutlier(data, selected, rows, antiOutlierPasses);
301 break;
302 default:
303 SDDS_Bomb("invalid select flag");
304 break;
305 }
306 switch (methodFlags) {
307 case METHOD_FIT:
308 fitAndRemoveBaseline(data, indepData, selected, rows, fitTerms);
309 break;
310 case METHOD_AVERAGE:
311 averageAndRemoveBaseline(data, selected, rows);
312 break;
313 default:
314 break;
315 }
316 if (nonnegative) {
317 for (j = 0; j < rows; j++)
318 if (data[j] < 0)
319 data[j] = 0;
320 if (despikePasses)
321 despikeProfile(data, rows, despikeWidthLimit, despikePasses);
322 }
323 }
324 if (!SDDS_SetColumnFromDoubles(&SDDSout, SDDS_SET_BY_NAME, data, rows, inputColumn[i]) ||
325 !SDDS_SetColumn(&SDDSout, SDDS_SET_BY_NAME, selected, rows, "SelectedForBaselineDetermination"))
326 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
327 free(data);
328 }
329 }
330 if (!SDDS_WritePage(&SDDSout))
331 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
332 }
333 if (!SDDS_Terminate(&SDDSin)) {
334 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
335 return EXIT_FAILURE;
336 }
337 if (!SDDS_Terminate(&SDDSout)) {
338 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
339 return EXIT_FAILURE;
340 }
341 if (indepData)
342 free(indepData);
343 if (selected)
344 free(selected);
345 return EXIT_SUCCESS;
346}
347
348long resolveColumnNames(SDDS_DATASET *SDDSin, char ***column, int32_t *columns) {
349 long i;
350
351 SDDS_SetColumnFlags(SDDSin, 0);
352 for (i = 0; i < *columns; i++) {
353 if (!SDDS_SetColumnsOfInterest(SDDSin, SDDS_MATCH_STRING, (*column)[i], SDDS_OR))
354 return 0;
355 }
356 free(*column);
357 if (!(*column = SDDS_GetColumnNames(SDDSin, columns)) || *columns == 0) {
358 SDDS_SetError("no columns found");
359 return 0;
360 }
361 return 1;
362}
363
364void selectEndpoints(short *selected, int64_t rows, long endPoints) {
365 int64_t i;
366 for (i = 0; i < endPoints && i < rows; i++)
367 selected[i] = 1;
368 for (i = rows - 1; i > rows - endPoints - 1 && i >= 0; i--)
369 selected[i] = 1;
370}
371
372void selectOutsideFWHA(double *data, double *indepData, short *selected, int64_t rows, double fwhaLimit) {
373 double top, base, fwha;
374 int64_t i, i1, i2, i2save;
375 int64_t imin, imax;
376 double point1, point2;
377
378 if (rows < 3 || fwhaLimit <= 0)
379 return;
380
381 index_min_max(&imin, &imax, data, rows);
382 if (!data[imax])
383 return;
384
385 if (!findTopBaseLevels(&top, &base, data, rows, 50, 2.0))
386 return;
387
388 if ((i1 = findCrossingPoint(0, data, rows, (top - base) * 0.5 + base, 1, indepData, &point1)) < 0 ||
389 (i2 = i2save = findCrossingPoint(i1, data, rows, (top - base) * 0.9 + base, -1, NULL, NULL)) < 0 ||
390 (i2 = findCrossingPoint(i2, data, rows, (top - base) * 0.5 + base, -1, indepData, &point2)) < 0) {
391 return;
392 }
393 fwha = point2 - point1;
394
395 for (i = 0; i < rows; i++)
396 selected[i] = 1;
397 for (i = imax - fwha * fwhaLimit; i <= imax + fwha * fwhaLimit; i++) {
398 if (i < 0)
399 continue;
400 if (i >= rows)
401 break;
402 selected[i] = 0;
403 }
404}
405
406void selectAntiOutlier(double *data, short *selected, int64_t rows, long passes) {
407 double ave, sum2, limit;
408 int64_t i, count;
409
410 for (i = 0; i < rows; i++)
411 selected[i] = 1;
412 while (--passes >= 0) {
413 for (i = ave = count = 0; i < rows; i++)
414 if (selected[i]) {
415 ave += data[i];
416 count++;
417 }
418 if (!count)
419 break;
420 ave /= count;
421 for (i = sum2 = 0; i < rows; i++)
422 if (selected[i])
423 sum2 += sqr(data[i] - ave);
424 limit = 2 * sqrt(sum2 / count);
425 for (i = 0; i < rows; i++)
426 if (selected[i] && fabs(data[i] - ave) > limit)
427 selected[i] = 0;
428 }
429}
430
431void fitAndRemoveBaseline(double *data0, double *indepData0, short *selected, int64_t rows, long fitTerms) {
432 double *data, *indepData = NULL;
433 int64_t count, i, j;
434 double chi;
435 double *coef, *sCoef;
436
437 if (!(coef = malloc(sizeof(*coef) * fitTerms)) || !(sCoef = malloc(sizeof(*sCoef) * fitTerms)))
438 SDDS_Bomb("allocation failure (fitAndRemoveBaseline)");
439 for (i = count = 0; i < rows; i++)
440 if (selected[i])
441 count++;
442 if (count < 3)
443 return;
444 if (!(data = malloc(sizeof(*data) * count)) || !(indepData = malloc(sizeof(*indepData) * count)))
445 SDDS_Bomb("memory allocation failure");
446 for (i = j = 0; i < rows; i++) {
447 if (selected[i]) {
448 data[j] = data0[i];
449 indepData[j] = indepData0[i];
450 j++;
451 }
452 }
453
454 if (!lsfn(indepData, data, NULL, (long)count, fitTerms - 1, coef, sCoef, &chi, NULL))
455 return;
456
457 for (i = 0; i < rows; i++) {
458 double term;
459 term = 1;
460 for (j = 0; j < fitTerms; j++) {
461 data0[i] -= term * coef[j];
462 term *= indepData0[i];
463 }
464 }
465
466 free(data);
467 free(indepData);
468 free(coef);
469 free(sCoef);
470}
471
472void averageAndRemoveBaseline(double *data, short *selected, int64_t rows) {
473 int64_t i, count;
474 double ave;
475 for (i = count = ave = 0; i < rows; i++)
476 if (selected[i]) {
477 count++;
478 ave += data[i];
479 }
480
481 if (count) {
482 ave /= count;
483 for (i = 0; i < rows; i++)
484 data[i] -= ave;
485 }
486}
487
488void despikeProfile(double *data, int64_t rows, long widthLimit, long passes) {
489 int64_t i, i0, i1, j;
490 while (--passes >= 0) {
491 for (i = 0; i < rows; i++) {
492 if (i == 0) {
493 if (data[i] != 0)
494 continue;
495 } else if (!(data[i - 1] == 0 && data[i] != 0))
496 continue;
497 i0 = i;
498 for (i1 = i + 1; i1 < rows; i1++)
499 if (!data[i1])
500 break;
501 if ((i1 - i0) <= widthLimit)
502 for (j = i0; j < i1; j++)
503 data[j] = 0;
504 }
505 }
506}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
Definition SDDS_copy.c:40
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:578
int32_t SDDS_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows,...)
Sets the values for a single data column using double-precision floating-point numbers.
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.
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
int32_t SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Sets the acceptance flags for columns based on specified naming criteria.
int32_t SDDS_SetColumnFlags(SDDS_DATASET *SDDS_dataset, int32_t column_flag_value)
Sets the acceptance flags for all columns in the current data table of a data set.
double * SDDS_GetColumnInDoubles(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves the data of a specified numerical column as an array of doubles, considering only rows mark...
int32_t SDDS_InitializeInput(SDDS_DATASET *SDDS_dataset, char *filename)
Definition SDDS_input.c:49
int32_t SDDS_Terminate(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_ReadPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
Definition SDDS_utils.c:432
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
#define SDDS_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
long bitsSet(unsigned long data)
Counts the number of set bits (1s) in the given data.
Definition binary.c:52
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
Definition bomb.c:26
int index_min_max(int64_t *imin, int64_t *imax, double *list, int64_t n)
Finds the indices of the minimum and maximum values in a list of doubles.
Definition findMinMax.c:116
long lsfn(double *xd, double *yd, double *sy, long nd, long nf, double *coef, double *s_coef, double *chi, double *diff)
Computes nth order polynomial least squares fit.
Definition lsfn.c:34
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)
Definition scanargs.c:36
long processPipeOption(char **item, long items, unsigned long *flags)
Definition scanargs.c:356
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
Definition scanargs.c:390
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.
long findTopBaseLevels(double *top, double *base, double *data, int64_t points, long bins, double sigmasRequired)
Finds the top-level and base-level of a dataset.
Definition topbase.c:36
int64_t findCrossingPoint(int64_t start, double *data, int64_t points, double level, long direction, double *indepData, double *location)
Finds the crossing point in the data where the data crosses a specified level.
Definition topbase.c:118