116 {
117 SCANNED_ARG *scanned;
118 SDDS_TABLE inputPage, outputPage, residualPage;
119 char *inputfile, *outputfile;
120 char **column, **excludeColumn;
121 int32_t columns;
122 long excludeColumns;
123 char *indColumnName;
124 long verbose;
125 long iArg, ipage;
126 double *indVar, *indVarOrig;
127 char *indVarUnits;
128 char **intColumn, **slopeColumn, **slopeSigmaColumn, **interceptSigmaColumn;
129 char *Units, *slopeUnits;
130 double *depVar, *depVarOrig;
131 long order;
132 double *coef, *coefsigma, *weight, *diff, *diffOrig, chi;
133 long iCol;
134 int64_t i, j, rows, rowsOrig, iRow;
135 double rmsResidual;
136 double slopeSigma, interceptSigma;
137 char **sigmaColumn, **chiSquaredColumn;
138 long *sigmaColumnExists;
139 long doSlopeSigma, generateSigma, doPreliminaryFit;
140 int64_t validSigmas;
141 double sigmaSum, averageSigma, minSigma;
142 long ascii;
143 char *residualFile;
144 unsigned long pipeFlags;
145 long tmpfile_used, noWarnings;
146 long unsigned int majorOrderFlag;
147 double xMin, xMax;
148 short columnMajorOrder = -1;
149
150 indVar = indVarOrig = depVar = depVarOrig = coef = coefsigma = weight = diff = NULL;
151 intColumn = slopeColumn = slopeSigmaColumn = interceptSigmaColumn = sigmaColumn = chiSquaredColumn = NULL;
152 slopeUnits = NULL;
153 sigmaColumnExists = NULL;
154
156 argc =
scanargs(&scanned, argc, argv);
157 if (argc == 1)
159
160 inputfile = outputfile = NULL;
161 columns = excludeColumns = 0;
162 column = excludeColumn = NULL;
163 indColumnName = NULL;
164 verbose = 0;
165 doSlopeSigma = 0;
166 generateSigma = 0;
167 minSigma = 0;
168 doPreliminaryFit = 0;
169 ascii = 0;
170 pipeFlags = 0;
171 tmpfile_used = 0;
172 noWarnings = 0;
173 residualFile = NULL;
174 xMin = xMax = 0;
175
176 for (iArg = 1; iArg < argc; iArg++) {
177 if (scanned[iArg].arg_type == OPTION) {
179 switch (
match_string(scanned[iArg].list[0], commandline_option, N_OPTIONS, UNIQUE_MATCH)) {
180 case CLO_MAJOR_ORDER:
181 majorOrderFlag = 0;
182 scanned[iArg].n_items--;
183 if (scanned[iArg].n_items > 0 &&
184 (!
scanItemList(&majorOrderFlag, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
185 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
186 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
187 SDDS_Bomb(
"invalid -majorOrder syntax/values");
188 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
189 columnMajorOrder = 1;
190 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
191 columnMajorOrder = 0;
192 break;
193 case CLO_INDEPENDENT_COLUMN:
194 if (!(indColumnName = scanned[iArg].list[1]))
195 SDDS_Bomb(
"no string given for option -independentVariable");
196 break;
197 case CLO_COLUMNS:
198 if (columns)
199 SDDS_Bomb(
"only one -columns option may be given");
200 if (scanned[iArg].n_items < 2)
202 column =
tmalloc(
sizeof(*column) * (columns = scanned[iArg].n_items - 1));
203 for (i = 0; i < columns; i++)
204 column[i] = scanned[iArg].list[i + 1];
205 break;
206 case CLO_EXCLUDE:
207 if (excludeColumns)
208 SDDS_Bomb(
"only one -excludecolumns option may be given");
209 if (scanned[iArg].n_items < 2)
210 SDDS_Bomb(
"invalid -excludecolumns syntax");
211 excludeColumn =
tmalloc(
sizeof(*excludeColumn) * (excludeColumns = scanned[iArg].n_items - 1));
212 for (i = 0; i < excludeColumns; i++)
213 excludeColumn[i] = scanned[iArg].list[i + 1];
214 break;
215 case CLO_VERBOSE:
216 verbose = 1;
217 break;
218 case CLO_ASCII:
219 ascii = 1;
220 break;
221 case CLO_PIPE:
222 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
224 break;
225 case CLO_SIGMA:
226 doSlopeSigma = 1;
227 if (scanned[iArg].n_items > 1) {
228 unsigned long sigmaFlags = 0;
229 scanned[iArg].n_items--;
230 if (!
scanItemList(&sigmaFlags, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
231 "generate", -1, NULL, 0, 1,
233 NULL) ||
234 minSigma < 0)
236 if (sigmaFlags & 1)
237 generateSigma = 1;
238 }
239 break;
240 case CLO_RESIDUAL:
241 if (!(residualFile = scanned[iArg].list[1])) {
242 fprintf(stderr, "No file specified in -residual option.\n");
243 exit(EXIT_FAILURE);
244 }
245 break;
246 case CLO_RANGE:
247 if (scanned[iArg].n_items != 3 ||
248 1 != sscanf(scanned[iArg].list[1], "%lf", &xMin) ||
249 1 != sscanf(scanned[iArg].list[2], "%lf", &xMax) ||
250 xMin >= xMax)
252 break;
253 case CLO_NO_WARNINGS:
254 noWarnings = 1;
255 break;
256 default:
258 break;
259 }
260 } else {
261 if (!inputfile)
262 inputfile = scanned[iArg].list[0];
263 else if (!outputfile)
264 outputfile = scanned[iArg].list[0];
265 else
267 }
268 }
269
270 if (residualFile && outputfile) {
271 if (!strcmp(residualFile, outputfile)) {
272 fprintf(stderr, "Residual file can't be the same as the output file.\n");
273 exit(EXIT_FAILURE);
274 }
275 }
276
277 processFilenames(
"sddsslopes", &inputfile, &outputfile, pipeFlags, noWarnings, &tmpfile_used);
278
279 if (!indColumnName) {
280 fprintf(stderr, "independentVariable not given\n");
281 exit(EXIT_FAILURE);
282 }
283
284 if (!excludeColumns) {
285 excludeColumn = defaultExcludedColumn;
286 excludeColumns = DEFAULT_EXCLUDED_COLUMNS;
287 }
288
289 if (verbose)
290 fprintf(stderr, "Reading file %s.\n", inputfile);
293 while (0 < (ipage = SDDS_ReadTable(&inputPage))) {
294 if (verbose) {
295 fprintf(stderr, "working on page %ld\n", ipage);
296 }
298 rowsOrig = rows;
299
300
301
302 if (ipage == 1) {
303 indVar = (double *)malloc(sizeof(*indVar) * rows);
304 if (!indVar) {
305 fprintf(stderr, "Memory allocation failed for indVar.\n");
306 exit(EXIT_FAILURE);
307 }
308 } else {
309 indVar = (double *)realloc(indVar, sizeof(*indVar) * rows);
310 if (!indVar) {
311 fprintf(stderr, "Memory reallocation failed for indVar.\n");
312 exit(EXIT_FAILURE);
313 }
314 }
315 if (ipage == 1) {
316 if (!
SDDS_FindColumn(&inputPage, FIND_NUMERIC_TYPE, indColumnName, NULL)) {
317 fprintf(stderr, "Something wrong with column %s.\n", indColumnName);
319 exit(EXIT_FAILURE);
320 }
321 }
322
323 if (xMin != xMax) {
326 for (i = j = 0; i < rowsOrig; i++) {
327 if (indVarOrig[i] <= xMax && indVarOrig[i] >= xMin) {
328 indVar[j] = indVarOrig[i];
329 j++;
330 }
331 }
332 } else {
335 }
336 if (ipage == 1) {
339 if (!indVarUnits) {
340 indVarUnits = (char *)malloc(sizeof(*indVarUnits));
341 indVarUnits[0] = 0;
342 }
343 }
344
345
346
347 if (residualFile) {
348 if (ipage == 1) {
349 if (!
SDDS_InitializeOutput(&residualPage, ascii ? SDDS_ASCII : SDDS_BINARY, 1,
"Residual of 2-term fit", NULL, outputfile) ||
352 if (columnMajorOrder != -1)
353 residualPage.layout.data_mode.column_major = columnMajorOrder;
354 else
355 residualPage.layout.data_mode.column_major = inputPage.layout.data_mode.column_major;
358 }
361 }
362
363
364
365
366
367 if (!set_multicolumn_flags(&inputPage, &column, &columns, excludeColumn, excludeColumns)) {
369 exit(EXIT_FAILURE);
370 }
371
372
373
374 if (ipage == 1) {
375 intColumn = (char **)malloc((sizeof(char *) * columns));
376 slopeColumn = (char **)malloc((sizeof(char *) * columns));
377 if (doSlopeSigma) {
378 slopeSigmaColumn = (char **)malloc((sizeof(char *) * columns));
379 interceptSigmaColumn = (char **)malloc((sizeof(char *) * columns));
380 chiSquaredColumn = (char **)malloc((sizeof(char *) * columns));
381 }
382 for (i = 0; i < columns; i++) {
383 intColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("Intercept") + 1)));
384 snprintf(intColumn[i], strlen(column[i]) + strlen("Intercept") + 1, "%sIntercept", column[i]);
385
386 slopeColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("Slope") + 1)));
387 snprintf(slopeColumn[i], strlen(column[i]) + strlen("Slope") + 1, "%sSlope", column[i]);
388
389 if (doSlopeSigma) {
390 slopeSigmaColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("SlopeSigma") + 1)));
391 snprintf(slopeSigmaColumn[i], strlen(column[i]) + strlen("SlopeSigma") + 1, "%sSlopeSigma", column[i]);
392
393 interceptSigmaColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("InterceptSigma") + 1)));
394 snprintf(interceptSigmaColumn[i], strlen(column[i]) + strlen("InterceptSigma") + 1, "%sInterceptSigma", column[i]);
395
396 chiSquaredColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("ChiSquared") + 1)));
397 snprintf(chiSquaredColumn[i], strlen(column[i]) + strlen("ChiSquared") + 1, "%sChiSquared", column[i]);
398 }
399 }
400 }
401
402
403
404 if (ipage == 1) {
405 if (verbose)
406 fprintf(stderr, "Opening file %s.\n", outputfile);
407 if (!
SDDS_InitializeOutput(&outputPage, ascii ? SDDS_ASCII : SDDS_BINARY, 1,
"2-term fit", NULL, outputfile) ||
411 if (columnMajorOrder != -1)
412 outputPage.layout.data_mode.column_major = columnMajorOrder;
413 else
414 outputPage.layout.data_mode.column_major = inputPage.layout.data_mode.column_major;
415 for (iCol = 0; iCol < columns; iCol++) {
418 if (!Units) {
419 Units = (char *)malloc(sizeof(*Units));
420 Units[0] = 0;
421 }
424
425 if (strlen(indVarUnits) && strlen(Units)) {
426 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(Units) + strlen(indVarUnits) + 2));
427 snprintf(slopeUnits, strlen(Units) + strlen(indVarUnits) + 2, "%s/%s", Units, indVarUnits);
428 }
429 if (strlen(indVarUnits) && !strlen(Units)) {
430 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(indVarUnits) + 2));
431 snprintf(slopeUnits, strlen(indVarUnits) + 2, "1/%s", indVarUnits);
432 }
433 if (!strlen(indVarUnits) && strlen(Units)) {
434 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(Units) + 1));
435 strcpy(slopeUnits, indVarUnits);
436 }
437 if (!strlen(indVarUnits) && !strlen(Units)) {
438 slopeUnits = (char *)malloc(sizeof(*slopeUnits));
439 strcpy(slopeUnits, "");
440 }
443 if (doSlopeSigma) {
448 }
449 free(slopeUnits);
450 }
453 }
454
455 if (!SDDS_StartTable(&outputPage, 1) ||
456 !
SDDS_SetParameters(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
"InputFile", inputfile ? inputfile :
"pipe", NULL) ||
457 !
SDDS_SetRowValues(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, 0,
"IndependentVariable", indColumnName, NULL))
459
460
461 if (ipage == 1) {
462 sigmaColumn = (char **)malloc(sizeof(*sigmaColumn) * columns);
463 sigmaColumnExists = (long *)malloc(columns * sizeof(*sigmaColumnExists));
464 for (iCol = 0; iCol < columns; iCol++) {
465 sigmaColumn[iCol] = (char *)malloc(sizeof(**sigmaColumn) * (strlen(column[iCol]) + strlen("Sigma") + 1));
466 snprintf(sigmaColumn[iCol], strlen(column[iCol]) + strlen("Sigma") + 1, "%sSigma", column[iCol]);
468 case SDDS_CHECK_WRONGUNITS:
469 case SDDS_CHECK_OKAY:
470 sigmaColumnExists[iCol] = 1;
471 break;
472 default:
473
474 snprintf(sigmaColumn[iCol], strlen("Sigma") + strlen(column[iCol]) + 1, "Sigma%s", column[iCol]);
476 case SDDS_CHECK_WRONGUNITS:
477 case SDDS_CHECK_OKAY:
478 sigmaColumnExists[iCol] = 1;
479 break;
480 default:
481 sigmaColumnExists[iCol] = 0;
482 }
483 break;
484 }
485 }
486 }
487
488 if (ipage == 1) {
489 weight = (double *)malloc(sizeof(*weight) * rows);
490 diff = (double *)malloc(sizeof(*diff) * rows);
491 order = 1;
492 coef = (double *)malloc(sizeof(*coef) * (order + 1));
493 coefsigma = (double *)malloc(sizeof(*coefsigma) * (order + 1));
494 if (!weight || !diff || !coef || !coefsigma) {
495 fprintf(stderr, "Memory allocation failed.\n");
496 exit(EXIT_FAILURE);
497 }
498 } else {
499 weight = (double *)realloc(weight, sizeof(*weight) * rows);
500 diff = (double *)realloc(diff, sizeof(*diff) * rows);
501 coef = (double *)realloc(coef, sizeof(*coef) * (order + 1));
502 coefsigma = (double *)realloc(coefsigma, sizeof(*coefsigma) * (order + 1));
503 if (!weight || !diff || !coef || !coefsigma) {
504 fprintf(stderr, "Memory reallocation failed.\n");
505 exit(EXIT_FAILURE);
506 }
507 }
508
509 if (ipage == 1) {
510 depVar = (double *)malloc(sizeof(*depVar) * rows);
511 if (!depVar) {
512 fprintf(stderr, "Memory allocation failed for depVar.\n");
513 exit(EXIT_FAILURE);
514 }
515 } else {
516 depVar = (double *)realloc(depVar, sizeof(*depVar) * rows);
517 if (!depVar) {
518 fprintf(stderr, "Memory reallocation failed for depVar.\n");
519 exit(EXIT_FAILURE);
520 }
521 }
522 for (iCol = 0; iCol < columns; iCol++) {
523 if (verbose)
524 fprintf(stderr, "Doing column %s.\n", column[iCol]);
525
526 if (xMin != xMax) {
529 for (i = j = 0; i < rowsOrig; i++) {
530 if (xMin <= indVarOrig[i] && indVarOrig[i] <= xMax) {
531 depVar[j] = depVarOrig[i];
532 j++;
533 }
534 }
535 rows = j;
536 } else {
539 }
540
541
542
543
544
545
546
547
548
549
550
551
552
553 for (iRow = 0; iRow < rows; iRow++)
554 weight[iRow] = 1;
555 if (doSlopeSigma) {
556
557
558
559 if (!generateSigma && sigmaColumnExists[iCol]) {
560 if (verbose)
561 fprintf(stderr, "\tUsing column %s for sigma.\n", sigmaColumn[iCol]);
564 if (minSigma > 0) {
565 for (iRow = 0; iRow < rows; iRow++) {
566 if (weight[iRow] < minSigma)
567 weight[iRow] = minSigma;
568 }
569 }
570
571 validSigmas = rows;
572 sigmaSum = 0;
573 for (iRow = 0; iRow < rows; iRow++) {
574 sigmaSum += weight[iRow];
575 if (!weight[iRow]) {
576 validSigmas--;
577
578
579 }
580 }
581 if (!validSigmas) {
582 if (!noWarnings)
583 fprintf(stderr, "Warning: All sigmas are zero.\n");
584 doPreliminaryFit = 1;
585 } else if (validSigmas != rows) {
586
587 averageSigma = sigmaSum / validSigmas;
588 if (!noWarnings)
589 fprintf(stderr, "Warning: replacing %" PRId64 " invalid sigmas with average (%e)\n", rows - validSigmas, averageSigma);
590 for (iRow = 0; iRow < rows; iRow++) {
591 if (!weight[iRow]) {
592 weight[iRow] = averageSigma;
593 }
594 }
595 }
596 } else {
597 doPreliminaryFit = 1;
598 }
599 }
600
601 if (doPreliminaryFit) {
602 if (verbose)
603 fprintf(stderr, "\tGenerating sigmas from rms residual of a preliminary fit.\n");
604 if (!(
lsfn(indVar, depVar, weight, rows, order, coef, coefsigma, &chi, diff))) {
605 fprintf(stderr, "Problem with call to lsfn\n.");
606 exit(EXIT_FAILURE);
607 }
608 rmsResidual = 0;
609
610 for (iRow = 0; iRow < rows; iRow++) {
611 rmsResidual += sqr(diff[iRow]);
612 }
613 rmsResidual = sqrt(rmsResidual / (rows));
614 for (iRow = 0; iRow < rows; iRow++) {
615 weight[iRow] = rmsResidual;
616 }
617 if (minSigma > 0) {
618 for (iRow = 0; iRow < rows; iRow++) {
619 if (weight[iRow] < minSigma)
620 weight[iRow] = minSigma;
621 }
622 }
623 }
624
625 if (!(
lsfn(indVar, depVar, weight, rows, order, coef, coefsigma, &chi, diff))) {
626 fprintf(stderr, "Problem with call to lsfn\n.");
627 exit(EXIT_FAILURE);
628 }
630 intColumn[iCol], coef[0], slopeColumn[iCol], coef[1], NULL))
632 if (doSlopeSigma) {
633 interceptSigma = coefsigma[0];
634 slopeSigma = coefsigma[1];
636 chiSquaredColumn[iCol], chi, interceptSigmaColumn[iCol],
637 interceptSigma, slopeSigmaColumn[iCol], slopeSigma, NULL))
639 }
640 if (residualFile) {
641 if (xMin != xMax) {
642
643
644
645 diffOrig = (double *)malloc(rowsOrig * sizeof(double));
646 if (!diffOrig) {
647 fprintf(stderr, "Memory allocation failed for diffOrig.\n");
648 exit(EXIT_FAILURE);
649 }
650 for (i = 0; i < rowsOrig; i++) {
651 diffOrig[i] = depVarOrig[i] - coef[0] - coef[1] * indVarOrig[i];
652 }
654 diffOrig, rowsOrig, column[iCol]))
656 free(diffOrig);
657 } else {
659 diff, rows, column[iCol]))
661 }
662 }
663 }
664
665 if (residualFile) {
666 if (!SDDS_WriteTable(&residualPage))
668 }
669
670 if (!SDDS_WriteTable(&outputPage))
672 }
673
674 if (residualFile) {
677 }
680
682 exit(EXIT_FAILURE);
683
684
685 free(indVar);
686 free(indVarOrig);
687 free(depVar);
688 free(depVarOrig);
689 free(coef);
690 free(coefsigma);
691 free(weight);
692 free(diff);
693 if (intColumn) {
694 for (i = 0; i < columns; i++) {
695 free(intColumn[i]);
696 free(slopeColumn[i]);
697 if (doSlopeSigma) {
698 free(slopeSigmaColumn[i]);
699 free(interceptSigmaColumn[i]);
700 free(chiSquaredColumn[i]);
701 }
702 free(sigmaColumn[i]);
703 }
704 free(intColumn);
705 free(slopeColumn);
706 if (doSlopeSigma) {
707 free(slopeSigmaColumn);
708 free(interceptSigmaColumn);
709 free(chiSquaredColumn);
710 }
711 free(sigmaColumn);
712 free(sigmaColumnExists);
713 }
714 free(column);
715 if (excludeColumn && excludeColumn != defaultExcludedColumn)
716 free(excludeColumn);
717
718 return EXIT_SUCCESS;
719}
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
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_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_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_CheckColumn(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a column exists in the SDDS dataset with the specified name, units, and type.
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_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric type.
#define SDDS_DOUBLE
Identifier for the double data type.
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 * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
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.
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.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
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)
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.