SDDSlib
Loading...
Searching...
No Matches
sddsvslopes.c File Reference

Computes straight line fits (slopes and intercepts) of column data in SDDS experiment output files. More...

#include "mdb.h"
#include "scan.h"
#include "match_string.h"
#include "SDDS.h"

Go to the source code of this file.

Macros

#define DEFAULT_EXCLUDED_COLUMNS   3
 
#define DEFAULT_COPY_COLUMNS   2
 

Enumerations

enum  option_type {
  CLO_INDEPENDENT_PARAMETER , CLO_COLUMNS , CLO_EXCLUDE , CLO_VERBOSE ,
  CLO_SDDS_OUTPUT_ROOT , CLO_SLOPE_ERRORS , CLO_PIPE , CLO_MAJOR_ORDER ,
  N_OPTIONS
}
 

Functions

long set_multicolumn_flags (SDDS_TABLE *SDDSin, char ***column, int32_t *columns, char **exclude, long excludes)
 
int main (int argc, char **argv)
 

Variables

char * commandline_option [N_OPTIONS]
 
char * defaultExcludedColumn [DEFAULT_EXCLUDED_COLUMNS]
 
char * defaultCopyColumn [DEFAULT_COPY_COLUMNS]
 
static char * USAGE
 

Detailed Description

Computes straight line fits (slopes and intercepts) of column data in SDDS experiment output files.

This program reads an SDDS input file containing multiple data sets with vectorized column data and a defined independent variable. It performs least squares fitting (LSF) for specified columns against the independent variable across rows and pages. The results, including slopes and intercepts (and optionally slope errors), are written to an output SDDS file.

The independent variable must be a defined parameter. The output file contains one table of slopes and intercepts. The independent parameter of the input file is removed in the output file, but its name is converted to a parameter string.

@usage sddsvslopes <inputfile> <outputfile> [options]

@options -pipe=[input][,output] Read input or output from a pipe. -independentVariable=<name> Name of the independent variable parameter. -columns=<list-of-names> Columns to perform straight line fitting. -excludeColumns=<list-of-names> Columns to exclude from fitting. -sigma Generate errors for slopes using sigma columns. -verbose Print detailed output to stderr. -majorOrder=row|column Specify output file in row or column major order.

@description Computes straight line fits of column data in the input SDDS file using a specified independent variable parameter. The output file contains tables of slopes and intercepts. The independent parameter is removed from the output file and its name is converted to a parameter string.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
L. Emery, M. Borland, C. Saunders, R. Soliday, H. Shang

Definition in file sddsvslopes.c.

Macro Definition Documentation

◆ DEFAULT_COPY_COLUMNS

#define DEFAULT_COPY_COLUMNS   2

Definition at line 76 of file sddsvslopes.c.

◆ DEFAULT_EXCLUDED_COLUMNS

#define DEFAULT_EXCLUDED_COLUMNS   3

Definition at line 70 of file sddsvslopes.c.

Enumeration Type Documentation

◆ option_type

enum option_type

Definition at line 47 of file sddsvslopes.c.

47 {
48 CLO_INDEPENDENT_PARAMETER,
49 CLO_COLUMNS,
50 CLO_EXCLUDE,
51 CLO_VERBOSE,
52 CLO_SDDS_OUTPUT_ROOT,
53 CLO_SLOPE_ERRORS,
54 CLO_PIPE,
55 CLO_MAJOR_ORDER,
56 N_OPTIONS
57};

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 101 of file sddsvslopes.c.

101 {
102 SCANNED_ARG *scanned;
103 SDDS_TABLE inputPage, *copiedPage, outputPage;
104 long copiedPages;
105 char *inputfile, *outputfile;
106 char **column, **excludeColumn = NULL;
107 int32_t columns;
108 long excludeColumns;
109 char *indParameterName;
110 char **copyColumn;
111 int32_t copyColumns;
112 long verbose;
113 long slopeErrors;
114 long iArg, i;
115 double *indVar;
116 char *indVarUnits;
117 char **intColumn, **slopeColumn, **slopeSigmaColumn;
118 char *Units, *slopeUnits;
119 double *depVar;
120 long order;
121 double *coef, *coefsigma, *weight, *diff, chi;
122 long iCol, iPage;
123 int64_t rows, iRow;
124 double *slope, slope2, slopeAve, slopeSigma;
125 unsigned long pipeFlags, majorOrderFlag;
126 long tmpfile_used, noWarnings;
127 long generateIndex;
128 short columnMajorOrder = -1;
129
130 copiedPage = NULL;
131 slopeSigmaColumn = NULL;
132 slopeUnits = Units = indVarUnits = NULL;
133 rows = 0;
134 slope = NULL;
135 slope2 = 0;
136 coef = coefsigma = weight = diff = slope = NULL;
137
138 argc = scanargs(&scanned, argc, argv);
139 if (argc == 1)
140 bomb(NULL, USAGE);
141
142 inputfile = outputfile = NULL;
143 columns = excludeColumns = 0;
144 column = excludeColumn = NULL;
145 indParameterName = NULL;
146 verbose = 0;
147 slopeErrors = 0;
148 pipeFlags = 0;
149 tmpfile_used = 0;
150 noWarnings = 0;
151 for (iArg = 1; iArg < argc; iArg++) {
152 if (scanned[iArg].arg_type == OPTION) {
153 delete_chars(scanned[iArg].list[0], "_");
154 switch (match_string(scanned[iArg].list[0], commandline_option, N_OPTIONS, UNIQUE_MATCH)) {
155 case CLO_MAJOR_ORDER:
156 majorOrderFlag = 0;
157 scanned[iArg].n_items--;
158 if (scanned[iArg].n_items > 0 &&
159 (!scanItemList(&majorOrderFlag, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
160 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
161 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
162 SDDS_Bomb("invalid -majorOrder syntax/values");
163 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
164 columnMajorOrder = 1;
165 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
166 columnMajorOrder = 0;
167 break;
168 case CLO_INDEPENDENT_PARAMETER:
169 if (!(indParameterName = scanned[iArg].list[1]))
170 SDDS_Bomb("no string given for option -independentVariable");
171 break;
172 case CLO_COLUMNS:
173 if (columns)
174 SDDS_Bomb("only one -columns option may be given");
175 if (scanned[iArg].n_items < 2)
176 SDDS_Bomb("invalid -columns syntax");
177 column = tmalloc(sizeof(*column) * (columns = scanned[iArg].n_items - 1));
178 for (i = 0; i < columns; i++)
179 column[i] = scanned[iArg].list[i + 1];
180 break;
181 case CLO_EXCLUDE:
182 if (excludeColumns)
183 SDDS_Bomb("only one -excludeColumns option may be given");
184 if (scanned[iArg].n_items < 2)
185 SDDS_Bomb("invalid -excludeColumns syntax");
186 excludeColumn = tmalloc(sizeof(*excludeColumn) * (excludeColumns = scanned[iArg].n_items - 1));
187 for (i = 0; i < excludeColumns; i++)
188 excludeColumn[i] = scanned[iArg].list[i + 1];
189 break;
190 case CLO_VERBOSE:
191 verbose = 1;
192 break;
193 case CLO_PIPE:
194 if (!processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
195 SDDS_Bomb("invalid -pipe syntax");
196 break;
197 case CLO_SLOPE_ERRORS:
198 slopeErrors = 1;
199 break;
200 default:
201 SDDS_Bomb("unrecognized option given");
202 break;
203 }
204 } else {
205 if (!inputfile)
206 inputfile = scanned[iArg].list[0];
207 else if (!outputfile)
208 outputfile = scanned[iArg].list[0];
209 else
210 SDDS_Bomb("too many filenames given");
211 }
212 }
213
214 processFilenames("sddsvslopes", &inputfile, &outputfile, pipeFlags, noWarnings, &tmpfile_used);
215
216 if (!indParameterName)
217 SDDS_Bomb("independentVariable not given");
218
219 if (!excludeColumns) {
220 excludeColumn = defaultExcludedColumn;
221 excludeColumns = DEFAULT_EXCLUDED_COLUMNS;
222 }
223
224 if (verbose)
225 fprintf(stderr, "Reading file %s.\n", inputfile);
226 SDDS_InitializeInput(&inputPage, inputfile);
227 copiedPages = 0;
228 while (SDDS_ReadTable(&inputPage) > 0) {
229 if (!copiedPages) {
230 copiedPage = (SDDS_TABLE *)malloc(sizeof(SDDS_TABLE));
231 rows = SDDS_CountRowsOfInterest(&inputPage);
232 } else {
233 copiedPage = (SDDS_TABLE *)realloc(copiedPage, (copiedPages + 1) * sizeof(SDDS_TABLE));
234 }
235 if (!SDDS_InitializeCopy(&copiedPage[copiedPages], &inputPage, NULL, "m"))
236 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
237 if (!SDDS_CopyTable(&copiedPage[copiedPages], &inputPage))
238 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
239 copiedPages++;
240 }
241 if (copiedPages < 2) {
242 fprintf(stderr, "Insufficient data (i.e., number of data pages) to fit a straight line.\n");
243 exit(EXIT_FAILURE);
244 }
245 switch (SDDS_CheckColumn(&inputPage, "Rootname", NULL, SDDS_STRING, NULL)) {
246 case SDDS_CHECK_WRONGUNITS:
247 case SDDS_CHECK_OKAY:
248 break;
249 default:
250 fprintf(stderr, "Something wrong with column %s.\n", "Rootname");
251 exit(EXIT_FAILURE);
252 }
253 switch (SDDS_CheckColumn(&inputPage, "Index", NULL, SDDS_ANY_INTEGER_TYPE, NULL)) {
254 case SDDS_CHECK_WRONGUNITS:
255 case SDDS_CHECK_OKAY:
256 generateIndex = 0;
257 break;
258 case SDDS_CHECK_NONEXISTENT:
259 generateIndex = 1;
260 break;
261 default:
262 fprintf(stderr, "Something wrong with column %s.\n", "Index");
263 exit(EXIT_FAILURE);
264 }
265 /****************\
266 * make array of independent variable
267 \**************/
268 indVar = (double *)malloc(sizeof(*indVar) * copiedPages);
269 switch (SDDS_CheckParameter(&inputPage, indParameterName, NULL, SDDS_DOUBLE, NULL)) {
270 case SDDS_CHECK_WRONGUNITS:
271 case SDDS_CHECK_OKAY:
272 break;
273 default:
274 fprintf(stderr, "Something wrong with parameter %s.\n", indParameterName);
275 exit(EXIT_FAILURE);
276 }
277 for (iPage = 0; iPage < copiedPages; iPage++) {
278 if (!SDDS_GetParameter(&copiedPage[iPage], indParameterName, &indVar[iPage]))
279 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
280 }
281 if (!SDDS_GetParameterInformation(&inputPage, "units", &indVarUnits, SDDS_GET_BY_NAME, indParameterName))
282 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
283 if (!indVarUnits) {
284 indVarUnits = (char *)malloc(sizeof(*indVarUnits));
285 indVarUnits[0] = 0;
286 }
287 /************************************\
288 * get columns of interest. use set_multicolumn_flags to simply
289 * return new values for array column.
290 \*************************************/
291 if (!set_multicolumn_flags(&inputPage, &column, &columns, excludeColumn, excludeColumns)) {
292 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
293 exit(EXIT_FAILURE);
294 }
295 /************************************\
296 * make column names for the output
297 \*************************************/
298 intColumn = (char **)malloc((sizeof(char *) * columns));
299 slopeColumn = (char **)malloc((sizeof(char *) * columns));
300 if (slopeErrors)
301 slopeSigmaColumn = (char **)malloc((sizeof(char *) * columns));
302 for (i = 0; i < columns; i++) {
303 intColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("Intercept") + 1)));
304 strcat(strcpy(intColumn[i], column[i]), "Intercept");
305 slopeColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("Slope") + 1)));
306 strcat(strcpy(slopeColumn[i], column[i]), "Slope");
307 if (slopeErrors) {
308 slopeSigmaColumn[i] = (char *)malloc((sizeof(char) * (strlen(column[i]) + strlen("SlopeSigma") + 1)));
309 strcat(strcpy(slopeSigmaColumn[i], column[i]), "SlopeSigma");
310 }
311 }
312 /************************************\
313 * Write layout for output file
314 \*************************************/
315 if (verbose)
316 fprintf(stderr, "Opening file %s.\n", outputfile);
317 if (!SDDS_InitializeOutput(&outputPage, SDDS_BINARY, 1, "lsf of sddsvexperiment", NULL, outputfile) ||
318 0 > SDDS_DefineParameter(&outputPage, "InputFile", "InputFile", NULL, "InputFile", NULL, SDDS_STRING, 0) ||
319 0 > SDDS_DefineParameter(&outputPage, "IndependentVariable", "IndependentVariable", NULL, "IndependentVariable", NULL, SDDS_STRING, 0) ||
320 (0 > SDDS_DefineColumn(&outputPage, "Index", NULL, NULL, "Rootname index", NULL, SDDS_LONG64, 0)) ||
321 (0 > SDDS_DefineColumn(&outputPage, "Rootname", NULL, NULL, NULL, NULL, SDDS_STRING, 0)))
322 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
323 if (columnMajorOrder != -1)
324 outputPage.layout.data_mode.column_major = columnMajorOrder;
325 else
326 outputPage.layout.data_mode.column_major = inputPage.layout.data_mode.column_major;
327 for (iCol = 0; iCol < columns; iCol++) {
328 if (!SDDS_GetColumnInformation(&inputPage, "units", &Units, SDDS_GET_BY_NAME, column[iCol]))
329 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
330 if (!Units) {
331 Units = (char *)malloc(sizeof(*Units));
332 Units[0] = 0;
333 }
334 if (0 > SDDS_DefineColumn(&outputPage, intColumn[iCol], NULL, Units, NULL, NULL, SDDS_DOUBLE, 0))
335 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
336 /* units for slopes columns */
337 if (strlen(indVarUnits) && strlen(Units)) {
338 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(Units) + strlen(indVarUnits) + 2));
339 strcat(strcat(strcpy(slopeUnits, Units), "/"), indVarUnits);
340 }
341 if (strlen(indVarUnits) && !strlen(Units)) {
342 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(indVarUnits) + 2));
343 strcat(strcpy(slopeUnits, "1/"), indVarUnits);
344 }
345 if (!strlen(indVarUnits) && strlen(Units)) {
346 slopeUnits = (char *)malloc(sizeof(*slopeUnits) * (strlen(Units) + 2));
347 strcpy(slopeUnits, Units);
348 }
349 if (!strlen(indVarUnits) && !strlen(Units)) {
350 slopeUnits = (char *)malloc(sizeof(*slopeUnits));
351 slopeUnits[0] = '\0';
352 }
353 if (0 > SDDS_DefineColumn(&outputPage, slopeColumn[iCol], NULL, slopeUnits, NULL, NULL, SDDS_DOUBLE, 0))
354 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
355 if (slopeErrors) {
356 if (0 > SDDS_DefineColumn(&outputPage, slopeSigmaColumn[iCol], NULL, slopeUnits, NULL, NULL, SDDS_DOUBLE, 0))
357 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
358 }
359 free(slopeUnits);
360 }
361 if (!SDDS_WriteLayout(&outputPage) ||
362 !SDDS_StartTable(&outputPage, rows) ||
363 !SDDS_SetParameters(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, "InputFile", inputfile ? inputfile : "pipe", NULL) ||
364 !SDDS_SetParameters(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, 0, "IndependentVariable", indParameterName, NULL))
365 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
366
367 /************************************\
368 * Copy columns to output file (usually columns Index and Rootname)
369 \*************************************/
370 copyColumns = DEFAULT_COPY_COLUMNS;
371 copyColumn = defaultCopyColumn;
372 if (!set_multicolumn_flags(&inputPage, &copyColumn, &copyColumns, NULL, 0)) {
373 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
374 exit(EXIT_FAILURE);
375 }
376 if (!SDDS_CopyColumns(&outputPage, &inputPage))
377 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
378 depVar = (double *)malloc(sizeof(*depVar) * copiedPages);
379 weight = (double *)malloc(sizeof(*weight) * copiedPages);
380 diff = (double *)malloc(sizeof(*diff) * copiedPages);
381 order = 1;
382 coef = (double *)malloc(sizeof(*coef) * (order + 1));
383 coefsigma = (double *)malloc(sizeof(*coefsigma) * (order + 1));
384 if (slopeErrors)
385 slope = (double *)malloc(sizeof(*slope) * copiedPages);
386 for (iCol = 0; iCol < columns; iCol++) {
387 for (iPage = 0; iPage < copiedPages; iPage++)
388 weight[iPage] = 1;
389 if (verbose)
390 fprintf(stderr, "Doing column %s.\n", column[iCol]);
391 for (iRow = 0; iRow < rows; iRow++) {
392 for (iPage = 0; iPage < copiedPages; iPage++) {
393 if (!SDDS_GetValue(&copiedPage[iPage], column[iCol], iRow, &depVar[iPage]))
394 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
395 }
396 if (!(lsfn(indVar, depVar, weight, copiedPages, order, coef, coefsigma, &chi, diff))) {
397 fprintf(stderr, "Problem with call to lsfn.\n");
398 exit(EXIT_FAILURE);
399 }
400 if (generateIndex) {
401 if (!SDDS_SetRowValues(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, iRow, "Index", iRow, intColumn[iCol], coef[0], slopeColumn[iCol], coef[1], NULL))
402 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
403 } else {
404 if (!SDDS_SetRowValues(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, iRow, intColumn[iCol], coef[0], slopeColumn[iCol], coef[1], NULL))
405 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
406 }
407 if (slopeErrors) {
408 /* recalculate the slope with a subset of points */
409 slopeAve = slope2 = 0;
410 for (iPage = 0; iPage < copiedPages; iPage++) {
411 weight[iPage] = 1e10;
412 if (iPage)
413 weight[iPage - 1] = 1;
414 if (!(lsfn(indVar, depVar, weight, copiedPages, order, coef, coefsigma, &chi, diff))) {
415 fprintf(stderr, "Problem with call to lsfn.\n");
416 exit(EXIT_FAILURE);
417 }
418 slope[iPage] = coef[1];
419 slopeAve += slope[iPage];
420 slope2 += slope[iPage] * slope[iPage];
421 }
422 slopeSigma = sqrt(slope2 / copiedPages - (slopeAve / copiedPages) * (slopeAve / copiedPages));
423 if (!SDDS_SetRowValues(&outputPage, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, iRow, slopeSigmaColumn[iCol], slopeSigma, NULL))
424 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
425 }
426 }
427 }
428
429 if (!SDDS_WriteTable(&outputPage) || SDDS_Terminate(&inputPage))
430 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
431 for (iPage = 0; iPage < copiedPages; iPage++) {
432 if (!SDDS_Terminate(&copiedPage[iPage]))
433 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
434 }
435
436 if (SDDS_Terminate(&outputPage))
437 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
438 if (tmpfile_used && !replaceFileAndBackUp(inputfile, outputfile))
439 exit(EXIT_FAILURE);
440 SDDS_FreeStringArray(column, columns);
441 free(column);
442 SDDS_FreeStringArray(intColumn, columns);
443 SDDS_FreeStringArray(slopeColumn, columns);
444 free(intColumn);
445 free(slopeColumn);
446 if (slopeErrors) {
447 SDDS_FreeStringArray(slopeSigmaColumn, columns);
448 free(slopeSigmaColumn);
449 }
450
451 free(copiedPage);
452 free(indVar);
453 free(depVar);
454 if (weight)
455 free(weight);
456 if (diff)
457 free(diff);
458 if (slope)
459 free(slope);
460 if (coef)
461 free(coef);
462 if (coefsigma)
463 free(coefsigma);
464 if (Units)
465 free(Units);
466 if (indVarUnits)
467 free(indVarUnits);
468
469 free_scanargs(&scanned, argc);
470
471 return EXIT_SUCCESS;
472}
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,...)
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
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.
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.
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.
Definition SDDS_utils.c:432
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_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.

◆ set_multicolumn_flags()

long set_multicolumn_flags ( SDDS_TABLE * SDDSin,
char *** column,
int32_t * columns,
char ** exclude,
long excludes )

Definition at line 474 of file sddsvslopes.c.

474 {
475 long index, i;
476
477 if (*column) {
478 SDDS_SetColumnFlags(SDDSin, 0);
479 for (i = 0; i < *columns; i++) {
480 if (!SDDS_SetColumnsOfInterest(SDDSin, SDDS_MATCH_STRING, (*column)[i], SDDS_OR))
481 return 0;
482 }
483 } else {
484 SDDS_SetColumnFlags(SDDSin, 1);
485 if (!(*column = SDDS_GetColumnNames(SDDSin, columns)) || *columns == 0) {
486 SDDS_SetError("no columns found");
487 return 0;
488 }
489 for (i = 0; i < *columns; i++) {
490 index = SDDS_GetColumnIndex(SDDSin, (*column)[i]);
491 if (!SDDS_NUMERIC_TYPE(SDDS_GetColumnType(SDDSin, index)) &&
492 !SDDS_AssertColumnFlags(SDDSin, SDDS_INDEX_LIMITS, index, index, 0))
493 return 0;
494 }
495 free(*column);
496 *column = NULL;
497 }
498
499 for (i = 0; i < excludes; i++)
500 if (!SDDS_SetColumnsOfInterest(SDDSin, SDDS_MATCH_STRING, exclude[i], SDDS_NEGATE_MATCH | SDDS_AND))
501 return 0;
502
503 if (!(*column = SDDS_GetColumnNames(SDDSin, columns)) || *columns == 0) {
504 SDDS_SetError("Selected columns not found.");
505 return 0;
506 }
507
508 return 1;
509}
int32_t SDDS_AssertColumnFlags(SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
Sets acceptance flags for columns based on specified criteria.
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.
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.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
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.
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
Definition SDDStypes.h:138

Variable Documentation

◆ commandline_option

char* commandline_option[N_OPTIONS]
Initial value:
= {
"independentVariable",
"columns",
"excludeColumns",
"verbose",
"sddsOutputRoot",
"sigma",
"pipe",
"majorOrder",
}

Definition at line 59 of file sddsvslopes.c.

59 {
60 "independentVariable",
61 "columns",
62 "excludeColumns",
63 "verbose",
64 "sddsOutputRoot",
65 "sigma",
66 "pipe",
67 "majorOrder",
68};

◆ defaultCopyColumn

char* defaultCopyColumn[DEFAULT_COPY_COLUMNS]
Initial value:
= {
"Index",
"Rootname"}

Definition at line 77 of file sddsvslopes.c.

77 {
78 "Index",
79 "Rootname"};

◆ defaultExcludedColumn

char* defaultExcludedColumn[DEFAULT_EXCLUDED_COLUMNS]
Initial value:
= {
"Index",
"ElapsedTime",
"Rootname"}

Definition at line 71 of file sddsvslopes.c.

71 {
72 "Index",
73 "ElapsedTime",
74 "Rootname"};

◆ USAGE

char* USAGE
static
Initial value:
=
"Usage: sddsvslopes <inputfile> <outputfile> [options]\n"
"\nOptions:\n"
" -pipe=[input][,output] Read input or output from a pipe.\n"
" -independentVariable=<name> Name of the independent variable parameter.\n"
" -columns=<list-of-names> Columns to perform straight line fitting.\n"
" -excludeColumns=<list-of-names> Columns to exclude from fitting.\n"
" -sigma Generate errors for slopes using sigma columns.\n"
" -verbose Print detailed output to stderr.\n"
" -majorOrder=row|column Specify output file in row or column major order.\n"
"\nDescription:\n"
" Computes straight line fits of column data in the input SDDS file using a specified\n"
" independent variable parameter. The output file contains tables of slopes and intercepts.\n"
" The independent parameter is removed from the output file and its name is converted\n"
" to a parameter string.\n"
"\nAuthor:\n"
" Louis Emery, ANL (Date: " __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n"

Definition at line 81 of file sddsvslopes.c.