SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
sddsvslopes.c
Go to the documentation of this file.
1/**
2 * @file sddsvslopes.c
3 * @brief Computes straight-line fits (slopes and intercepts) of column data in SDDS experiment output files.
4 *
5 * @details
6 * This program reads an SDDS input file containing multiple datasets with vectorized column data and a defined independent variable.
7 * It performs least squares fitting (LSF) for specified columns against the independent variable across rows and pages.
8 * The results, including slopes and intercepts (and optionally slope errors), are written to an output SDDS file.
9 *
10 * - The independent variable must be a defined parameter.
11 * - The output file contains one table of slopes and intercepts.
12 * - The independent parameter of the input file is removed in the output file, but its name is converted to a parameter string.
13 *
14 * @section Usage
15 * ```
16 * sddsvslopes [<inputfile>] [<outputfile>]
17 * [-pipe=[input][,output]]
18 * -independentVariable=<parametername>
19 * [-columns=<list-of-names>]
20 * [-excludeColumns=<list-of-names>]
21 * [-sigma]
22 * [-verbose]
23 * [-majorOrder=row|column]
24 * ```
25 *
26 * @section Options
27 * | Required | Description |
28 * |---------------------------------------|-----------------------------------------------|
29 * | `-independentVariable` | Specifies the name of the independent variable parameter. |
30 *
31 * | Optional | Description |
32 * |---------------------------------------|-----------------------------------------------|
33 * | `-pipe` | Read input or output from a pipe. |
34 * | `-columns` | Columns to perform straight-line fitting. |
35 * | `-excludeColumns` | Columns to exclude from fitting. |
36 * | `-sigma` | Generate errors for slopes using sigma columns.|
37 * | `-verbose` | Print detailed output to stderr. |
38 * | `-majorOrder` | Specify output file in row or column major order. |
39 *
40 * @subsection spec_req Specific Requirements
41 * - If `-excludeColumns` is not provided, default columns `Index`, `ElapsedTime`, and `Rootname` are excluded.
42 *
43 * @copyright
44 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
45 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
46 *
47 * @license
48 * This file is distributed under the terms of the Software License Agreement
49 * found in the file LICENSE included with this distribution.
50 *
51 * @author
52 * L. Emery, M. Borland, C. Saunders, R. Soliday, H. Shang
53 */
54
55#include "mdb.h"
56#include "scan.h"
57#include "match_string.h"
58#include "SDDS.h"
59
60/* Enumeration for option types */
61enum option_type {
62 CLO_INDEPENDENT_PARAMETER,
63 CLO_COLUMNS,
64 CLO_EXCLUDE,
65 CLO_VERBOSE,
66 CLO_SDDS_OUTPUT_ROOT,
67 CLO_SLOPE_ERRORS,
68 CLO_PIPE,
69 CLO_MAJOR_ORDER,
70 N_OPTIONS
71};
72
73char *commandline_option[N_OPTIONS] = {
74 "independentVariable",
75 "columns",
76 "excludeColumns",
77 "verbose",
78 "sddsOutputRoot",
79 "sigma",
80 "pipe",
81 "majorOrder",
82};
83
84#define DEFAULT_EXCLUDED_COLUMNS 3
85char *defaultExcludedColumn[DEFAULT_EXCLUDED_COLUMNS] = {
86 "Index",
87 "ElapsedTime",
88 "Rootname"};
89
90#define DEFAULT_COPY_COLUMNS 2
91char *defaultCopyColumn[DEFAULT_COPY_COLUMNS] = {
92 "Index",
93 "Rootname"};
94
95static char *USAGE =
96 "sddsvslopes [<inputfile>] [<outputfile>]\n"
97 " [-pipe=[input][,output]]\n"
98 " -independentVariable=<parametername>\n"
99 " [-columns=<list-of-names>] \n"
100 " [-excludeColumns=<list-of-names>] \n"
101 " [-sigma] \n"
102 " [-verbose] \n"
103 " [-majorOrder=row|column]\n"
104 "Options:\n"
105 " -pipe=[input][,output] Read input or output from a pipe.\n"
106 " -independentVariable=<name> Name of the independent variable parameter.\n"
107 " -columns=<list-of-names> Columns to perform straight line fitting.\n"
108 " -excludeColumns=<list-of-names> Columns to exclude from fitting.\n"
109 " -sigma Generate errors for slopes using sigma columns.\n"
110 " -verbose Print detailed output to stderr.\n"
111 " -majorOrder=row|column Specify output file in row or column major order.\n"
112 "\nDescription:\n"
113 " Computes straight line fits of column data in the input SDDS file using a specified\n"
114 " independent variable parameter. The output file contains tables of slopes and intercepts.\n"
115 " The independent parameter is removed from the output file and its name is converted\n"
116 " to a parameter string.\n"
117 "\nAuthor:\n"
118 " Louis Emery, ANL (Date: " __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n";
119
120long set_multicolumn_flags(SDDS_TABLE *SDDSin, char ***column, int32_t *columns, char **exclude, long excludes);
121
122int main(int argc, char **argv) {
123 SCANNED_ARG *scanned;
124 SDDS_TABLE inputPage, *copiedPage, outputPage;
125 long copiedPages;
126 char *inputfile, *outputfile;
127 char **column, **excludeColumn = NULL;
128 int32_t columns;
129 long excludeColumns;
130 char *indParameterName;
131 char **copyColumn;
132 int32_t copyColumns;
133 long verbose;
134 long slopeErrors;
135 long iArg, i;
136 double *indVar;
137 char *indVarUnits;
138 char **intColumn, **slopeColumn, **slopeSigmaColumn;
139 char *Units, *slopeUnits;
140 double *depVar;
141 long order;
142 double *coef, *coefsigma, *weight, *diff, chi;
143 long iCol, iPage;
144 int64_t rows, iRow;
145 double *slope, slope2, slopeAve, slopeSigma;
146 unsigned long pipeFlags, majorOrderFlag;
147 long tmpfile_used, noWarnings;
148 long generateIndex;
149 short columnMajorOrder = -1;
150
151 copiedPage = NULL;
152 slopeSigmaColumn = NULL;
153 slopeUnits = Units = indVarUnits = NULL;
154 rows = 0;
155 slope = NULL;
156 slope2 = 0;
157 coef = coefsigma = weight = diff = slope = NULL;
158
159 argc = scanargs(&scanned, argc, argv);
160 if (argc == 1)
161 bomb(NULL, USAGE);
162
163 inputfile = outputfile = NULL;
164 columns = excludeColumns = 0;
165 column = excludeColumn = NULL;
166 indParameterName = NULL;
167 verbose = 0;
168 slopeErrors = 0;
169 pipeFlags = 0;
170 tmpfile_used = 0;
171 noWarnings = 0;
172 for (iArg = 1; iArg < argc; iArg++) {
173 if (scanned[iArg].arg_type == OPTION) {
174 delete_chars(scanned[iArg].list[0], "_");
175 switch (match_string(scanned[iArg].list[0], commandline_option, N_OPTIONS, UNIQUE_MATCH)) {
176 case CLO_MAJOR_ORDER:
177 majorOrderFlag = 0;
178 scanned[iArg].n_items--;
179 if (scanned[iArg].n_items > 0 &&
180 (!scanItemList(&majorOrderFlag, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
181 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
182 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
183 SDDS_Bomb("invalid -majorOrder syntax/values");
184 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
185 columnMajorOrder = 1;
186 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
187 columnMajorOrder = 0;
188 break;
189 case CLO_INDEPENDENT_PARAMETER:
190 if (!(indParameterName = scanned[iArg].list[1]))
191 SDDS_Bomb("no string given for option -independentVariable");
192 break;
193 case CLO_COLUMNS:
194 if (columns)
195 SDDS_Bomb("only one -columns option may be given");
196 if (scanned[iArg].n_items < 2)
197 SDDS_Bomb("invalid -columns syntax");
198 column = tmalloc(sizeof(*column) * (columns = scanned[iArg].n_items - 1));
199 for (i = 0; i < columns; i++)
200 column[i] = scanned[iArg].list[i + 1];
201 break;
202 case CLO_EXCLUDE:
203 if (excludeColumns)
204 SDDS_Bomb("only one -excludeColumns option may be given");
205 if (scanned[iArg].n_items < 2)
206 SDDS_Bomb("invalid -excludeColumns syntax");
207 excludeColumn = tmalloc(sizeof(*excludeColumn) * (excludeColumns = scanned[iArg].n_items - 1));
208 for (i = 0; i < excludeColumns; i++)
209 excludeColumn[i] = scanned[iArg].list[i + 1];
210 break;
211 case CLO_VERBOSE:
212 verbose = 1;
213 break;
214 case CLO_PIPE:
215 if (!processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
216 SDDS_Bomb("invalid -pipe syntax");
217 break;
218 case CLO_SLOPE_ERRORS:
219 slopeErrors = 1;
220 break;
221 default:
222 SDDS_Bomb("unrecognized option given");
223 break;
224 }
225 } else {
226 if (!inputfile)
227 inputfile = scanned[iArg].list[0];
228 else if (!outputfile)
229 outputfile = scanned[iArg].list[0];
230 else
231 SDDS_Bomb("too many filenames given");
232 }
233 }
234
235 processFilenames("sddsvslopes", &inputfile, &outputfile, pipeFlags, noWarnings, &tmpfile_used);
236
237 if (!indParameterName)
238 SDDS_Bomb("independentVariable not given");
239
240 if (!excludeColumns) {
241 excludeColumn = defaultExcludedColumn;
242 excludeColumns = DEFAULT_EXCLUDED_COLUMNS;
243 }
244
245 if (verbose)
246 fprintf(stderr, "Reading file %s.\n", inputfile);
247 SDDS_InitializeInput(&inputPage, inputfile);
248 copiedPages = 0;
249 while (SDDS_ReadTable(&inputPage) > 0) {
250 if (!copiedPages) {
251 copiedPage = (SDDS_TABLE *)malloc(sizeof(SDDS_TABLE));
252 rows = SDDS_CountRowsOfInterest(&inputPage);
253 } else {
254 copiedPage = (SDDS_TABLE *)realloc(copiedPage, (copiedPages + 1) * sizeof(SDDS_TABLE));
255 }
256 if (!SDDS_InitializeCopy(&copiedPage[copiedPages], &inputPage, NULL, "m"))
257 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
258 if (!SDDS_CopyTable(&copiedPage[copiedPages], &inputPage))
259 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
260 copiedPages++;
261 }
262 if (copiedPages < 2) {
263 fprintf(stderr, "Insufficient data (i.e., number of data pages) to fit a straight line.\n");
264 exit(EXIT_FAILURE);
265 }
266 switch (SDDS_CheckColumn(&inputPage, "Rootname", NULL, SDDS_STRING, NULL)) {
267 case SDDS_CHECK_WRONGUNITS:
268 case SDDS_CHECK_OKAY:
269 break;
270 default:
271 fprintf(stderr, "Something wrong with column %s.\n", "Rootname");
272 exit(EXIT_FAILURE);
273 }
274 switch (SDDS_CheckColumn(&inputPage, "Index", NULL, SDDS_ANY_INTEGER_TYPE, NULL)) {
275 case SDDS_CHECK_WRONGUNITS:
276 case SDDS_CHECK_OKAY:
277 generateIndex = 0;
278 break;
279 case SDDS_CHECK_NONEXISTENT:
280 generateIndex = 1;
281 break;
282 default:
283 fprintf(stderr, "Something wrong with column %s.\n", "Index");
284 exit(EXIT_FAILURE);
285 }
286 /****************\
287 * make array of independent variable
288 \**************/
289 indVar = (double *)malloc(sizeof(*indVar) * copiedPages);
290 switch (SDDS_CheckParameter(&inputPage, indParameterName, NULL, SDDS_DOUBLE, NULL)) {
291 case SDDS_CHECK_WRONGUNITS:
292 case SDDS_CHECK_OKAY:
293 break;
294 default:
295 fprintf(stderr, "Something wrong with parameter %s.\n", indParameterName);
296 exit(EXIT_FAILURE);
297 }
298 for (iPage = 0; iPage < copiedPages; iPage++) {
299 if (!SDDS_GetParameter(&copiedPage[iPage], indParameterName, &indVar[iPage]))
300 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
301 }
302 if (!SDDS_GetParameterInformation(&inputPage, "units", &indVarUnits, SDDS_GET_BY_NAME, indParameterName))
303 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
304 if (!indVarUnits) {
305 indVarUnits = (char *)malloc(sizeof(*indVarUnits));
306 indVarUnits[0] = 0;
307 }
308 /************************************\
309 * get columns of interest. use set_multicolumn_flags to simply
310 * return new values for array column.
311 \*************************************/
312 if (!set_multicolumn_flags(&inputPage, &column, &columns, excludeColumn, excludeColumns)) {
313 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
314 exit(EXIT_FAILURE);
315 }
316 /************************************\
317 * make column names for the output
318 \*************************************/
319 intColumn = (char **)malloc((sizeof(char *) * columns));
320 slopeColumn = (char **)malloc((sizeof(char *) * columns));
321 if (slopeErrors)
322 slopeSigmaColumn = (char **)malloc((sizeof(char *) * columns));
323 for (i = 0; i < columns; i++) {
324 intColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("Intercept") + 1)));
325 strcat(strcpy(intColumn[i], column[i]), "Intercept");
326 slopeColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("Slope") + 1)));
327 strcat(strcpy(slopeColumn[i], column[i]), "Slope");
328 if (slopeErrors) {
329 slopeSigmaColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("SlopeSigma") + 1)));
330 strcat(strcpy(slopeSigmaColumn[i], column[i]), "SlopeSigma");
331 }
332 }
333 /************************************\
334 * Write layout for output file
335 \*************************************/
336 if (verbose)
337 fprintf(stderr, "Opening file %s.\n", outputfile);
338 if (!SDDS_InitializeOutput(&outputPage, SDDS_BINARY, 1, "lsf of sddsvexperiment", NULL, outputfile) ||
339 0 > SDDS_DefineParameter(&outputPage, "InputFile", "InputFile", NULL, "InputFile", NULL, SDDS_STRING, 0) ||
340 0 > SDDS_DefineParameter(&outputPage, "IndependentVariable", "IndependentVariable", NULL, "IndependentVariable", NULL, SDDS_STRING, 0) ||
341 (0 > SDDS_DefineColumn(&outputPage, "Index", NULL, NULL, "Rootname index", NULL, SDDS_LONG64, 0)) ||
342 (0 > SDDS_DefineColumn(&outputPage, "Rootname", NULL, NULL, NULL, NULL, SDDS_STRING, 0)))
343 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
344 if (columnMajorOrder != -1)
345 outputPage.layout.data_mode.column_major = columnMajorOrder;
346 else
347 outputPage.layout.data_mode.column_major = inputPage.layout.data_mode.column_major;
348 for (iCol = 0; iCol < columns; iCol++) {
349 if (!SDDS_GetColumnInformation(&inputPage, "units", &Units, SDDS_GET_BY_NAME, column[iCol]))
350 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
351 if (!Units) {
352 Units = (char *)malloc(sizeof(*Units));
353 Units[0] = 0;
354 }
355 if (0 > SDDS_DefineColumn(&outputPage, intColumn[iCol], NULL, Units, NULL, NULL, SDDS_DOUBLE, 0))
356 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
357 /* units for slopes columns */
358 if (strlen(indVarUnits) && strlen(Units)) {
359 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(Units) + strlen(indVarUnits) + 2));
360 strcat(strcat(strcpy(slopeUnits, Units), "/"), indVarUnits);
361 }
362 if (strlen(indVarUnits) && !strlen(Units)) {
363 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(indVarUnits) + 2));
364 strcat(strcpy(slopeUnits, "1/"), indVarUnits);
365 }
366 if (!strlen(indVarUnits) && strlen(Units)) {
367 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(Units) + 2));
368 strcpy(slopeUnits, Units);
369 }
370 if (!strlen(indVarUnits) && !strlen(Units)) {
371 slopeUnits = (char *)malloc(sizeof(*slopeUnits));
372 slopeUnits[0] = '\0';
373 }
374 if (0 > SDDS_DefineColumn(&outputPage, slopeColumn[iCol], NULL, slopeUnits, NULL, NULL, SDDS_DOUBLE, 0))
375 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
376 if (slopeErrors) {
377 if (0 > SDDS_DefineColumn(&outputPage, slopeSigmaColumn[iCol], NULL, slopeUnits, NULL, NULL, SDDS_DOUBLE, 0))
378 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
379 }
380 free(slopeUnits);
381 }
382 if (!SDDS_WriteLayout(&outputPage) ||
383 !SDDS_StartTable(&outputPage, rows) ||
384 !SDDS_SetParameters(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, "InputFile", inputfile ? inputfile : "pipe", NULL) ||
385 !SDDS_SetParameters(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, 0, "IndependentVariable", indParameterName, NULL))
386 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
387
388 /************************************\
389 * Copy columns to output file (usually columns Index and Rootname)
390 \*************************************/
391 copyColumns = DEFAULT_COPY_COLUMNS;
392 copyColumn = defaultCopyColumn;
393 if (!set_multicolumn_flags(&inputPage, &copyColumn, &copyColumns, NULL, 0)) {
394 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
395 exit(EXIT_FAILURE);
396 }
397 if (!SDDS_CopyColumns(&outputPage, &inputPage))
398 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
399 depVar = (double *)malloc(sizeof(*depVar) * copiedPages);
400 weight = (double *)malloc(sizeof(*weight) * copiedPages);
401 diff = (double *)malloc(sizeof(*diff) * copiedPages);
402 order = 1;
403 coef = (double *)malloc(sizeof(*coef) * (order + 1));
404 coefsigma = (double *)malloc(sizeof(*coefsigma) * (order + 1));
405 if (slopeErrors)
406 slope = (double *)malloc(sizeof(*slope) * copiedPages);
407 for (iCol = 0; iCol < columns; iCol++) {
408 for (iPage = 0; iPage < copiedPages; iPage++)
409 weight[iPage] = 1;
410 if (verbose)
411 fprintf(stderr, "Doing column %s.\n", column[iCol]);
412 for (iRow = 0; iRow < rows; iRow++) {
413 for (iPage = 0; iPage < copiedPages; iPage++) {
414 if (!SDDS_GetValue(&copiedPage[iPage], column[iCol], iRow, &depVar[iPage]))
415 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
416 }
417 if (!(lsfn(indVar, depVar, weight, copiedPages, order, coef, coefsigma, &chi, diff))) {
418 fprintf(stderr, "Problem with call to lsfn.\n");
419 exit(EXIT_FAILURE);
420 }
421 if (generateIndex) {
422 if (!SDDS_SetRowValues(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, iRow, "Index", iRow, intColumn[iCol], coef[0], slopeColumn[iCol], coef[1], NULL))
423 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
424 } else {
425 if (!SDDS_SetRowValues(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, iRow, intColumn[iCol], coef[0], slopeColumn[iCol], coef[1], NULL))
426 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
427 }
428 if (slopeErrors) {
429 /* recalculate the slope with a subset of points */
430 slopeAve = slope2 = 0;
431 for (iPage = 0; iPage < copiedPages; iPage++) {
432 weight[iPage] = 1e10;
433 if (iPage)
434 weight[iPage - 1] = 1;
435 if (!(lsfn(indVar, depVar, weight, copiedPages, order, coef, coefsigma, &chi, diff))) {
436 fprintf(stderr, "Problem with call to lsfn.\n");
437 exit(EXIT_FAILURE);
438 }
439 slope[iPage] = coef[1];
440 slopeAve += slope[iPage];
441 slope2 += slope[iPage] * slope[iPage];
442 }
443 slopeSigma = sqrt(slope2 / copiedPages - (slopeAve / copiedPages) * (slopeAve / copiedPages));
444 if (!SDDS_SetRowValues(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, iRow, slopeSigmaColumn[iCol], slopeSigma, NULL))
445 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
446 }
447 }
448 }
449
450 if (!SDDS_WriteTable(&outputPage) || SDDS_Terminate(&inputPage))
451 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
452 for (iPage = 0; iPage < copiedPages; iPage++) {
453 if (!SDDS_Terminate(&copiedPage[iPage]))
454 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
455 }
456
457 if (SDDS_Terminate(&outputPage))
458 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
459 if (tmpfile_used && !replaceFileAndBackUp(inputfile, outputfile))
460 exit(EXIT_FAILURE);
461 SDDS_FreeStringArray(column, columns);
462 free(column);
463 SDDS_FreeStringArray(intColumn, columns);
464 SDDS_FreeStringArray(slopeColumn, columns);
465 free(intColumn);
466 free(slopeColumn);
467 if (slopeErrors) {
468 SDDS_FreeStringArray(slopeSigmaColumn, columns);
469 free(slopeSigmaColumn);
470 }
471
472 free(copiedPage);
473 free(indVar);
474 free(depVar);
475 if (weight)
476 free(weight);
477 if (diff)
478 free(diff);
479 if (slope)
480 free(slope);
481 if (coef)
482 free(coef);
483 if (coefsigma)
484 free(coefsigma);
485 if (Units)
486 free(Units);
487 if (indVarUnits)
488 free(indVarUnits);
489
490 free_scanargs(&scanned, argc);
491
492 return EXIT_SUCCESS;
493}
494
495long set_multicolumn_flags(SDDS_TABLE *SDDSin, char ***column, int32_t *columns, char **exclude, long excludes) {
496 long index, i;
497
498 if (*column) {
499 SDDS_SetColumnFlags(SDDSin, 0);
500 for (i = 0; i < *columns; i++) {
501 if (!SDDS_SetColumnsOfInterest(SDDSin, SDDS_MATCH_STRING, (*column)[i], SDDS_OR))
502 return 0;
503 }
504 } else {
505 SDDS_SetColumnFlags(SDDSin, 1);
506 if (!(*column = SDDS_GetColumnNames(SDDSin, columns)) || *columns == 0) {
507 SDDS_SetError("no columns found");
508 return 0;
509 }
510 for (i = 0; i < *columns; i++) {
511 index = SDDS_GetColumnIndex(SDDSin, (*column)[i]);
512 if (!SDDS_NUMERIC_TYPE(SDDS_GetColumnType(SDDSin, index)) &&
513 !SDDS_AssertColumnFlags(SDDSin, SDDS_INDEX_LIMITS, index, index, 0))
514 return 0;
515 }
516 free(*column);
517 *column = NULL;
518 }
519
520 for (i = 0; i < excludes; i++)
521 if (!SDDS_SetColumnsOfInterest(SDDSin, SDDS_MATCH_STRING, exclude[i], SDDS_NEGATE_MATCH | SDDS_AND))
522 return 0;
523
524 if (!(*column = SDDS_GetColumnNames(SDDSin, columns)) || *columns == 0) {
525 SDDS_SetError("Selected columns not found.");
526 return 0;
527 }
528
529 return 1;
530}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_CopyColumns(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:387
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
Definition SDDS_copy.c:40
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_AssertColumnFlags(SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
Sets acceptance flags for columns based on specified criteria.
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.
void * SDDS_GetParameter(SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
Retrieves the value of a specified parameter from the current data table of a data set.
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.
void * SDDS_GetValue(SDDS_DATASET *SDDS_dataset, char *column_name, int64_t srow_index, void *memory)
Retrieves the value from a specified column and selected row, optionally storing it in provided memor...
int32_t SDDS_GetParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified parameter in the SDDS dataset.
Definition SDDS_info.c:117
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.
Definition SDDS_info.c:41
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_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_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
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.
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
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
int32_t SDDS_CheckParameter(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a parameter exists in the SDDS dataset with the specified name, units, and type.
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
Definition SDDStypes.h:138
#define SDDS_ANY_INTEGER_TYPE
Special identifier used by SDDS_Check*() routines to accept any integer type.
Definition SDDStypes.h:173
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
Definition bomb.c:26
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.
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.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
Definition replacefile.c:75
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
void free_scanargs(SCANNED_ARG **scanned, int argc)
Definition scanargs.c:584
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.