SDDSlib
Loading...
Searching...
No Matches
sddsinterpset.c
Go to the documentation of this file.
1/**
2 * @file sddsinterpset.c
3 * @brief Perform multiple interpolations on SDDS data sets.
4 *
5 * This program reads an input SDDS file containing references to multiple data files.
6 * For each referenced data file, it performs interpolation based on specified parameters
7 * and writes the results to an output SDDS file. The interpolation behavior can be customized
8 * using various command-line options.
9 *
10 * ### Features:
11 * - Supports piping for input and output.
12 * - Allows specification of polynomial interpolation order.
13 * - Handles out-of-range interpolation points with options like skip, saturate, extrapolate, wrap, abort, or warn.
14 * - Supports both row-major and column-major data ordering.
15 * - Provides verbose output for detailed processing information.
16 *
17 * ### Usage:
18 * ```
19 * sddsinterpset [<input>] [<output>]
20 * [-pipe=[input][,output]]
21 * [-order=<number>]
22 * [-verbose]
23 * [-data=fileColumn=<colName>,interpolate=<colName>,functionof=<colName>,column=<colName> | atValue=<value>]
24 * [-majorOrder=row|column]
25 * [-belowRange={value=<value>|skip|saturate|extrapolate|wrap}[,{abort|warn}]]
26 * [-aboveRange={value=<value>|skip|saturate|extrapolate|wrap}[,{abort|warn}]]
27 * ```
28 *
29 * ### Command-Line Options:
30 * - `-verbose`
31 * Print out detailed processing messages.
32 *
33 * - `-pipe`
34 * Use standard SDDS Toolkit pipe options for input and output.
35 *
36 * - `-order=<number>`
37 * Specify the order of the polynomials used for interpolation.
38 * **Default:** `1` (linear interpolation).
39 *
40 * - `-data`
41 * Define data interpolation parameters:
42 * - `fileColumn=<colName>`: Name of the column in the input file containing data file names.
43 * - `interpolate=<colName>`: Name of the column to interpolate.
44 * - `functionof=<colName>`: Independent variable column name.
45 * - `column=<colName>` or `atValue=<value>`: Specify the interpolation point as a column or a fixed value.
46 *
47 * - `-majorOrder=row|column`
48 * Specify the data ordering for output: `row` or `column`.
49 * **Default:** Inherits from input file.
50 *
51 * - `-belowRange` and `-aboveRange`
52 * Define behavior for out-of-range interpolation points:
53 * - `value=<value>`: Use a specific value.
54 * - `skip`: Discard the offending point.
55 * - `saturate`: Use the nearest endpoint value.
56 * - `extrapolate`: Perform extrapolation beyond data limits.
57 * - `wrap`: Treat data as periodic.
58 * - `abort`: Terminate the program.
59 * - `warn`: Issue a warning without terminating.
60 *
61 * @copyright
62 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
63 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
64 *
65 * @license
66 * This file is distributed under the terms of the Software License Agreement
67 * found in the file LICENSE included with this distribution.
68 *
69 * @author H. Shang, R. Soliday, Xuesong Jiao, M. Borland
70 */
71
72#include "mdb.h"
73#include "SDDS.h"
74#include "scan.h"
75#include "SDDSutils.h"
76#include <ctype.h>
77
78/* Enumeration for option types */
79enum option_type {
80 CLO_ORDER,
81 CLO_PIPE,
82 CLO_BELOWRANGE,
83 CLO_ABOVERANGE,
84 CLO_DATA,
85 CLO_VERBOSE,
86 CLO_MAJOR_ORDER,
87 N_OPTIONS
88};
89
90char *option[N_OPTIONS] = {
91 "order",
92 "pipe",
93 "belowrange",
94 "aboverange",
95 "data",
96 "verbose",
97 "majorOrder",
98};
99
100static const char *USAGE =
101 "Usage: sddsinterpset [<input>] [<output>] \n"
102 " [-pipe=[input][,output]] \n"
103 " [-order=<number>] \n"
104 " [-verbose] \n"
105 " [-data=fileColumn=<colName>,interpolate=<colName>,functionof=<colName>,\n"
106 " column=<colName> | atValue=<value>] \n"
107 " [-majorOrder=row|column] \n"
108 " [-belowRange={value=<value>|skip|saturate|extrapolate|wrap}[,{abort|warn}]] \n"
109 " [-aboveRange={value=<value>|skip|saturate|extrapolate|wrap}[,{abort|warn}]]\n\n"
110 "Options:\n"
111 " -verbose Print detailed processing messages.\n"
112 " -pipe Use standard SDDS Toolkit pipe options for input and output.\n"
113 " -order Specify the order of the polynomials used for interpolation.\n"
114 " Default is 1 (linear interpolation).\n"
115 " -data Define data interpolation parameters:\n"
116 " - fileColumn=<colName> : Column with data file names.\n"
117 " - interpolate=<colName> : Column to interpolate.\n"
118 " - functionof=<colName> : Independent variable column name.\n"
119 " - column=<colName> : Specify interpolation point as a column.\n"
120 " or\n"
121 " - atValue=<value> : Specify a fixed interpolation value.\n"
122 " -majorOrder Specify data ordering for output: 'row' or 'column'.\n"
123 " Default inherits from input file.\n"
124 " -belowRange Define behavior for interpolation points below data range:\n"
125 " Options: value=<value>, skip, saturate, extrapolate, wrap, abort, warn.\n"
126 " -aboveRange Define behavior for interpolation points above data range:\n"
127 " Options: value=<value>, skip, saturate, extrapolate, wrap, abort, warn.\n\n"
128 "Program by Hairong Shang. ("__DATE__
129 " "__TIME__
130 ", SVN revision: " SVN_VERSION ")\n";
131
132#define AT_COLUMN 0x00000001
133#define AT_VALUE 0x00000002
134
135typedef struct {
136 char *fileColumn;
137 char *interpCol;
138 char *funcOfCol;
139 char *atCol;
140 char **file;
141 int64_t files;
142 double atValue;
143 double *colValue;
144 unsigned long hasdata;
145 unsigned long flags;
147
148long checkMonotonicity(double *indepValue, int64_t rows);
149void freedatacontrol(DATA_CONTROL *data_control, long dataControls);
150
151int main(int argc, char **argv) {
152 int i_arg;
153 char *input = NULL, *output = NULL, **interpCol = NULL, **funcOf = NULL;
154 long order = 1, dataControls = 0, valid_option = 1, monotonicity;
155 //long verbose = 0;
156 SCANNED_ARG *s_arg;
157 OUTRANGE_CONTROL aboveRange, belowRange;
158 DATA_CONTROL *data_control = NULL;
159 unsigned long pipeFlags = 0, interpCode = 0, majorOrderFlag;
160 SDDS_DATASET SDDSdata, SDDSout, SDDSin;
161 double *indepValue = NULL, *depenValue = NULL, **out_depenValue = NULL, atValue = 0;
162 int32_t **rowFlag = NULL;
163 long valid_data = 0, index, pages = 0;
164 int64_t *rows = NULL;
165 int64_t i, j, datarows, row;
166 short columnMajorOrder = -1;
167
169 argc = scanargs(&s_arg, argc, argv);
170 if (argc < 3) {
171 fprintf(stderr, "%s", USAGE);
172 exit(EXIT_FAILURE);
173 }
174
175 aboveRange.flags = belowRange.flags = OUTRANGE_SATURATE;
176
177 for (i_arg = 1; i_arg < argc; i_arg++) {
178 if (s_arg[i_arg].arg_type == OPTION) {
179 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
180 case CLO_MAJOR_ORDER:
181 majorOrderFlag = 0;
182 s_arg[i_arg].n_items--;
183 if (s_arg[i_arg].n_items > 0 &&
184 !scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].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 }
189 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
190 columnMajorOrder = 1;
191 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
192 columnMajorOrder = 0;
193 break;
194
195 case CLO_ORDER:
196 if (s_arg[i_arg].n_items != 2 ||
197 sscanf(s_arg[i_arg].list[1], "%ld", &order) != 1 ||
198 order < 1) {
199 SDDS_Bomb("invalid -order syntax/value");
200 }
201 break;
202
203 case CLO_PIPE:
204 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags)) {
205 SDDS_Bomb("invalid -pipe syntax");
206 }
207 break;
208
209 case CLO_ABOVERANGE:
210 s_arg[i_arg].n_items -= 1;
211 if (s_arg[i_arg].n_items < 1 ||
212 !scanItemList(&aboveRange.flags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
213 "value", SDDS_DOUBLE, &aboveRange.value, 1, OUTRANGE_VALUE,
214 "skip", -1, NULL, 0, OUTRANGE_SKIP,
215 "saturate", -1, NULL, 0, OUTRANGE_SATURATE,
216 "extrapolate", -1, NULL, 0, OUTRANGE_EXTRAPOLATE,
217 "wrap", -1, NULL, 0, OUTRANGE_WRAP,
218 "abort", -1, NULL, 0, OUTRANGE_ABORT,
219 "warn", -1, NULL, 0, OUTRANGE_WARN, NULL)) {
220 SDDS_Bomb("invalid -aboveRange syntax/value");
221 }
222 if ((i = bitsSet(aboveRange.flags & (OUTRANGE_VALUE | OUTRANGE_SKIP | OUTRANGE_SATURATE |
223 OUTRANGE_EXTRAPOLATE | OUTRANGE_WRAP | OUTRANGE_ABORT))) > 1) {
224 SDDS_Bomb("incompatible keywords given for -aboveRange");
225 }
226 if (i != 1)
227 aboveRange.flags |= OUTRANGE_SATURATE;
228 break;
229
230 case CLO_VERBOSE:
231 //verbose = 1;
232 break;
233
234 case CLO_BELOWRANGE:
235 s_arg[i_arg].n_items -= 1;
236 if (s_arg[i_arg].n_items < 1 ||
237 !scanItemList(&belowRange.flags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
238 "value", SDDS_DOUBLE, &belowRange.value, 1, OUTRANGE_VALUE,
239 "skip", -1, NULL, 0, OUTRANGE_SKIP,
240 "saturate", -1, NULL, 0, OUTRANGE_SATURATE,
241 "extrapolate", -1, NULL, 0, OUTRANGE_EXTRAPOLATE,
242 "wrap", -1, NULL, 0, OUTRANGE_WRAP,
243 "abort", -1, NULL, 0, OUTRANGE_ABORT,
244 "warn", -1, NULL, 0, OUTRANGE_WARN, NULL)) {
245 SDDS_Bomb("invalid -belowRange syntax/value");
246 }
247 if ((i = bitsSet(belowRange.flags & (OUTRANGE_VALUE | OUTRANGE_SKIP | OUTRANGE_SATURATE |
248 OUTRANGE_EXTRAPOLATE | OUTRANGE_WRAP | OUTRANGE_ABORT))) > 1) {
249 SDDS_Bomb("incompatible keywords given for -belowRange");
250 }
251 if (i != 1)
252 belowRange.flags |= OUTRANGE_SATURATE;
253 break;
254
255 case CLO_DATA:
256 s_arg[i_arg].n_items -= 1;
257 if (s_arg[i_arg].n_items < 4) {
258 SDDS_Bomb("invalid -data syntax");
259 }
260 data_control = SDDS_Realloc(data_control, sizeof(*data_control) * (dataControls + 1));
261 data_control[dataControls].fileColumn = data_control[dataControls].interpCol =
262 data_control[dataControls].funcOfCol = data_control[dataControls].atCol = NULL;
263 data_control[dataControls].file = NULL;
264 data_control[dataControls].files = 0;
265 data_control[dataControls].hasdata = 0;
266 data_control[dataControls].colValue = NULL;
267 data_control[dataControls].flags = 0;
268
269 if (!scanItemList(&data_control[dataControls].flags, s_arg[i_arg].list + 1,
270 &s_arg[i_arg].n_items, 0,
271 "fileColumn", SDDS_STRING, &(data_control[dataControls].fileColumn), 1, 0,
272 "interpolate", SDDS_STRING, &(data_control[dataControls].interpCol), 1, 0,
273 "functionof", SDDS_STRING, &(data_control[dataControls].funcOfCol), 1, 0,
274 "column", SDDS_STRING, &(data_control[dataControls].atCol), 1, AT_COLUMN,
275 "atValue", SDDS_DOUBLE, &(data_control[dataControls].atValue), 1, AT_VALUE, NULL) ||
276 !data_control[dataControls].fileColumn ||
277 !data_control[dataControls].interpCol ||
278 !data_control[dataControls].funcOfCol) {
279 SDDS_Bomb("Invalid -data syntax");
280 }
281
282 if (!(data_control[dataControls].flags & AT_COLUMN) &&
283 !(data_control[dataControls].flags & AT_VALUE)) {
284 SDDS_Bomb("Invalid -data syntax: either column or atValue option should be given.");
285 }
286
287 if ((data_control[dataControls].flags & AT_COLUMN) &&
288 (data_control[dataControls].flags & AT_VALUE)) {
289 SDDS_Bomb("Invalid -data syntax: column and atValue options are not compatible.");
290 }
291
292 valid_option = 1;
293 if (dataControls) {
294 if (match_string(data_control[dataControls].funcOfCol, funcOf, dataControls, EXACT_MATCH) > 0) {
295 fprintf(stderr, "Multiple independent columns provided!\n");
296 exit(EXIT_FAILURE);
297 }
298 if (match_string(data_control[dataControls].interpCol, interpCol, dataControls, EXACT_MATCH) > 0) {
299 fprintf(stderr, "Warning: Interpolate column '%s' has been used.\n", data_control[dataControls].interpCol);
300 valid_option = 0;
301 }
302 }
303
304 if (valid_option) {
305 interpCol = SDDS_Realloc(interpCol, sizeof(*interpCol) * (dataControls + 1));
306 funcOf = SDDS_Realloc(funcOf, sizeof(*funcOf) * (dataControls + 1));
307 interpCol[dataControls] = data_control[dataControls].interpCol;
308 funcOf[dataControls] = data_control[dataControls].funcOfCol;
309 dataControls++;
310 }
311 break;
312
313 default:
314 fprintf(stderr, "Error: Unknown or ambiguous option '%s'\n", s_arg[i_arg].list[0]);
315 exit(EXIT_FAILURE);
316 break;
317 }
318 } else {
319 if (!input)
320 input = s_arg[i_arg].list[0];
321 else if (!output)
322 output = s_arg[i_arg].list[0];
323 else
324 SDDS_Bomb("Too many filenames provided.");
325 }
326 }
327
328 processFilenames("sddsinterpset", &input, &output, pipeFlags, 0, NULL);
329
330 if (!SDDS_InitializeInput(&SDDSin, input))
331 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
332
333 for (i = 0; i < dataControls; i++) {
334 if ((index = SDDS_GetColumnIndex(&SDDSin, data_control[i].fileColumn)) < 0) {
335 fprintf(stderr, "Warning: Column '%s' does not exist in input file '%s'.\n",
336 data_control[i].fileColumn, input);
337 continue;
338 }
339 if (SDDS_GetColumnType(&SDDSin, index) != SDDS_STRING) {
340 fprintf(stderr, "Error: Column '%s' in input file '%s' is not a string column.\n",
341 data_control[i].fileColumn, input);
342 continue;
343 }
344 if (data_control[i].atCol) {
345 if ((index = SDDS_GetColumnIndex(&SDDSin, data_control[i].atCol)) < 0) {
346 fprintf(stderr, "Warning: Column '%s' does not exist in input file '%s'.\n",
347 data_control[i].atCol, input);
348 continue;
349 }
350 if (!SDDS_NUMERIC_TYPE(SDDS_GetColumnType(&SDDSin, index))) {
351 fprintf(stderr, "Error: Column '%s' in input file '%s' is not a numeric column.\n",
352 data_control[i].atCol, input);
353 continue;
354 }
355 }
356 data_control[i].hasdata = 1;
357 valid_data++;
358 }
359
360 if (!valid_data) {
361 fprintf(stderr, "Error: No valid -data options provided for processing.\n");
362 exit(EXIT_FAILURE);
363 }
364
365 if (!SDDS_InitializeCopy(&SDDSout, &SDDSin, output, "w"))
366 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
367
368 if (columnMajorOrder != -1)
369 SDDSout.layout.data_mode.column_major = columnMajorOrder;
370 else
371 SDDSout.layout.data_mode.column_major = SDDSin.layout.data_mode.column_major;
372
373 while (SDDS_ReadPage(&SDDSin) > 0) {
374 rows = SDDS_Realloc(rows, sizeof(*rows) * (pages + 1));
375 out_depenValue = SDDS_Realloc(out_depenValue, sizeof(*out_depenValue) * (pages + 1));
376 rowFlag = SDDS_Realloc(rowFlag, sizeof(*rowFlag) * (pages + 1));
377
378 if (!(rows[pages] = SDDS_CountRowsOfInterest(&SDDSin))) {
379 fprintf(stderr, "Error: No data found in input file '%s'.\n", input);
380 exit(EXIT_FAILURE);
381 }
382
383 rowFlag[pages] = (int32_t *)malloc(sizeof(**rowFlag) * rows[pages]);
384 out_depenValue[pages] = (double *)malloc(sizeof(**out_depenValue) * rows[pages]);
385
386 for (i = 0; i < rows[pages]; i++)
387 rowFlag[pages][i] = 1;
388
389 for (i = 0; i < dataControls; i++) {
390 if (data_control[i].hasdata) {
391 data_control[i].files = rows[pages];
392 if (!(data_control[i].file = (char **)SDDS_GetColumn(&SDDSin, data_control[i].fileColumn))) {
393 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
394 }
395
396 if (data_control[i].atCol) {
397 if (!(data_control[i].colValue = SDDS_GetColumnInDoubles(&SDDSin, data_control[i].atCol))) {
398 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
399 }
400 }
401
402 if (!data_control[i].atCol)
403 atValue = data_control[i].atValue;
404
405 for (j = 0; j < rows[pages]; j++) {
406 if (!SDDS_InitializeInput(&SDDSdata, data_control[i].file[j]))
407 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
408
409 switch (SDDS_CheckColumn(&SDDSdata, data_control[i].interpCol, NULL, SDDS_ANY_NUMERIC_TYPE, NULL)) {
410 case SDDS_CHECK_OKAY:
411 if (j == (rows[pages] - 1)) {
412 if (!pages) {
413 if (!SDDS_TransferColumnDefinition(&SDDSout, &SDDSdata, data_control[i].interpCol, data_control[i].interpCol))
414 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
415 }
416 }
417 break;
418 default:
419 fprintf(stderr, "Error: Column '%s' missing or invalid in file '%s'.\n",
420 data_control[i].interpCol, data_control[i].file[j]);
421 exit(EXIT_FAILURE);
422 break;
423 }
424
425 switch (SDDS_CheckColumn(&SDDSdata, data_control[i].funcOfCol, NULL, SDDS_ANY_NUMERIC_TYPE, NULL)) {
426 case SDDS_CHECK_OKAY:
427 if (j == (rows[pages] - 1)) {
428 if ((!pages) && !(data_control[i].atCol)) {
429 if (!SDDS_TransferColumnDefinition(&SDDSout, &SDDSdata, data_control[i].funcOfCol, data_control[i].funcOfCol))
430 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
431 }
432 }
433 break;
434 default:
435 fprintf(stderr, "Error: Column '%s' missing or invalid in file '%s'.\n",
436 data_control[i].funcOfCol, data_control[i].file[j]);
437 exit(EXIT_FAILURE);
438 break;
439 }
440
441 if (SDDS_ReadPage(&SDDSdata) <= 0)
442 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
443
444 datarows = SDDS_CountRowsOfInterest(&SDDSdata);
445
446 if (!(indepValue = SDDS_GetColumnInDoubles(&SDDSdata, data_control[i].funcOfCol))) {
447 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
448 }
449 if (!(depenValue = SDDS_GetColumnInDoubles(&SDDSdata, data_control[i].interpCol))) {
450 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
451 }
452
453 if (!SDDS_Terminate(&SDDSdata))
454 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
455
456 if (!(monotonicity = checkMonotonicity(indepValue, datarows))) {
457 fprintf(stderr, "Error: Independent (%s) data in file '%s' is not monotonic.\n",
458 data_control[i].funcOfCol, data_control[i].file[j]);
459 exit(EXIT_FAILURE);
460 }
461
462 if (data_control[i].atCol)
463 atValue = data_control[i].colValue[j];
464
465 out_depenValue[pages][j] = interpolate(depenValue, indepValue, datarows, atValue,
466 &belowRange, &aboveRange, order, &interpCode, monotonicity);
467
468 if (interpCode) {
469 if (interpCode & OUTRANGE_ABORT) {
470 fprintf(stderr, "Error: Value %e out of range for column '%s'.\n",
471 atValue, data_control[i].interpCol);
472 exit(EXIT_FAILURE);
473 }
474 if (interpCode & OUTRANGE_WARN)
475 fprintf(stderr, "Warning: Value %e out of range for column '%s'.\n",
476 atValue, data_control[i].interpCol);
477 if (interpCode & OUTRANGE_SKIP)
478 rowFlag[pages][j] = 0;
479 }
480
481 free(depenValue);
482 free(indepValue);
483 }
484 }
485
486 for (j = 0; j < data_control[i].files; j++)
487 free(data_control[i].file[j]);
488 free(data_control[i].file);
489 data_control[i].file = NULL;
490
491 if (data_control[i].colValue) {
492 free(data_control[i].colValue);
493 data_control[i].colValue = NULL;
494 }
495 }
496
497 if (!pages) {
498 if (!SDDS_WriteLayout(&SDDSout))
499 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
500 }
501
502 if (!SDDS_StartTable(&SDDSout, rows[pages]))
503 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
504
505 if (!SDDS_CopyColumns(&SDDSout, &SDDSin))
506 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
507
508 if (!SDDS_CopyParameters(&SDDSout, &SDDSin))
509 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
510
511 for (i = 0; i < dataControls; i++) {
512 if (data_control[i].hasdata) {
513 if (!SDDS_SetColumnFromDoubles(&SDDSout, SDDS_SET_BY_NAME, out_depenValue[pages],
514 rows[pages], data_control[i].interpCol)) {
515 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
516 }
517 if (!(data_control[i].atCol)) {
518 for (row = 0; row < rows[pages]; row++) {
519 if (!SDDS_SetRowValues(&SDDSout, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, row,
520 data_control[i].funcOfCol, data_control[i].atValue, NULL)) {
521 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
522 }
523 }
524 }
525 }
526 }
527
528 if (!SDDS_AssertRowFlags(&SDDSout, SDDS_FLAG_ARRAY, rowFlag[pages], rows[pages]))
529 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
530
531 if (!SDDS_WritePage(&SDDSout))
532 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
533
534 pages++;
535 }
536
537 if (!SDDS_Terminate(&SDDSin))
538 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
539
540 if (!SDDS_Terminate(&SDDSout)) {
541 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
542 exit(EXIT_FAILURE);
543 }
544
545 freedatacontrol(data_control, dataControls);
546
547 if (out_depenValue) {
548 for (i = 0; i < pages; i++) {
549 free(out_depenValue[i]);
550 free(rowFlag[i]);
551 }
552 free(out_depenValue);
553 free(rowFlag);
554 }
555
556 if (interpCol)
557 free(interpCol);
558 if (funcOf)
559 free(funcOf);
560 if (rows)
561 free(rows);
562
563 free_scanargs(&s_arg, argc);
564 return EXIT_SUCCESS;
565}
566
567long checkMonotonicity(double *indepValue, int64_t rows) {
568 if (rows == 1)
569 return 1;
570
571 if (indepValue[rows - 1] > indepValue[0]) {
572 while (--rows > 0)
573 if (indepValue[rows] < indepValue[rows - 1])
574 return 0;
575 return 1;
576 } else {
577 while (--rows > 0)
578 if (indepValue[rows] > indepValue[rows - 1])
579 return 0;
580 return -1;
581 }
582}
583
584void freedatacontrol(DATA_CONTROL *data_control, long dataControls) {
585 long i;
586 for (i = 0; i < dataControls; i++) {
587 free(data_control[i].interpCol);
588 free(data_control[i].funcOfCol);
589 free(data_control[i].fileColumn);
590 if (data_control[i].atCol)
591 free(data_control[i].atCol);
592 }
593 free(data_control);
594}
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_CopyParameters(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:286
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_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_AssertRowFlags(SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
Sets acceptance flags for rows based on specified criteria.
void * SDDS_GetColumn(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves a copy of the data for a specified column, including only rows marked as "of interest".
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
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_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.
int32_t SDDS_TransferColumnDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a column definition from a source dataset to a target dataset.
int32_t SDDS_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.
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
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
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
#define SDDS_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric type.
Definition SDDStypes.h:157
#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
long bitsSet(unsigned long data)
Counts the number of set bits (1s) in the given data.
Definition binary.c:52
double interpolate(double *f, double *x, int64_t n, double xo, OUTRANGE_CONTROL *belowRange, OUTRANGE_CONTROL *aboveRange, long order, unsigned long *returnCode, long M)
Performs interpolation with range control options.
Definition interp.c:160
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
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.