SDDSlib
Loading...
Searching...
No Matches
sddsconvertalarmlog.c
Go to the documentation of this file.
1/**
2 * @file sddsconvertalarmlog.c
3 * @brief Converts SDDS log files with options to filter and format data.
4 *
5 * ## Usage
6 * ```
7 * sddsconvertalarmlog[<input-file>] [<output-file>]
8 * ```
9 *
10 * ## Options
11 * - `-pipe=[input][,output]`
12 * Use pipe for input and/or output.
13 * - `-binary`
14 * Output in binary format.
15 * - `-ascii`
16 * Output in ASCII format.
17 * - `-double`
18 * Use double precision for output.
19 * - `-float`
20 * Use float precision for output.
21 * - `-minimumInterval=<seconds>`
22 * Set minimum interval between data points.
23 * - `-snapshot=<epochtime>`
24 * Take a snapshot at the specified epoch time.
25 * - `-time=[start=<epochtime>][,end=<epochtime>]`
26 * Filter data by time range.
27 * - `-delete={<matching-string>[,...]}`
28 * Delete columns matching the pattern.
29 * - `-retain={<matching-string>[,...]}`
30 * Retain only columns matching the pattern.
31 *
32 * @copyright
33 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
34 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
35 *
36 * @license
37 * This file is distributed under the terms of the Software License Agreement
38 * found in the file LICENSE included with this distribution.
39 *
40 * @author R. Soliday
41 */
42
43#include "mdb.h"
44#include "SDDS.h"
45#include "scan.h"
46
47/* Enumeration for option types */
48enum option_type {
49 SET_BINARY,
50 SET_ASCII,
51 SET_FLOAT,
52 SET_DOUBLE,
53 SET_SNAPSHOT,
54 SET_PIPE,
55 SET_MININTERVAL,
56 SET_TIME,
57 SET_DELETE,
58 SET_RETAIN,
59 N_OPTIONS
60};
61
62#if !defined(MAXDOUBLE)
63# define MAXDOUBLE 1.79769313486231570e+308
64#endif
65
66char *option[N_OPTIONS] = {
67 "binary",
68 "ascii",
69 "float",
70 "double",
71 "snapshot",
72 "pipe",
73 "minimuminterval",
74 "time",
75 "delete",
76 "retain"
77};
78
79char *USAGE =
80 "Usage: sddsconvertalarmlog [<input-file>] [<output-file>]\n"
81 "\nOptions:\n"
82 " -pipe=[input][,output] Use pipe for input and/or output.\n"
83 " -binary Output in binary format.\n"
84 " -ascii Output in ASCII format.\n"
85 " -double Use double precision for output.\n"
86 " -float Use float precision for output.\n"
87 " -minimumInterval=<seconds> Set minimum interval between data points.\n"
88 " -snapshot=<epochtime> Take a snapshot at the specified epoch time.\n"
89 " -time=[start=<epochtime>][,end=<epochtime>]\n"
90 " Filter data by time range.\n"
91 " -delete={<matching-string>[,...]} Delete columns matching the pattern.\n"
92 " -retain={<matching-string>[,...]} Retain only columns matching the pattern.\n"
93 "\nProgram by Robert Soliday. (" __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n";
94
95long SDDS_SetRowValuesMod(SDDS_DATASET *SDDS_dataset, long mode, int64_t row, ...);
96char **process_name_options(char **orig_name, long orig_names, char **delete, long deletes, char **retain, long retains, long *num_matched, long **origToNewIndex);
97
98int main(int argc, char **argv) {
99 SDDS_DATASET SDDS_input, SDDS_output;
100 long i, i_arg;
101 SCANNED_ARG *s_arg;
102 long tmpfile_used, noWarnings;
103 char *input, *output;
104 long ascii_output, binary_output;
105 unsigned long pipeFlags;
106 long output_type = SDDS_DOUBLE;
107 long snapshot = 0;
108 double epochtime;
109
110 long readbackNameIndex = -1, controlNameIndex = -1;
111 long timeIndex = -1, valueIndex = -1, controlNameIndexIndex = -1, previousRowIndex = -1;
112 double *timeData = NULL, *valueData = NULL, *previousRowData = NULL;
113 int32_t *controlNameIndexData = NULL;
114 SDDS_ARRAY *readbackNameArray = NULL;
115 SDDS_ARRAY *readbackNameArray2 = NULL;
116 long page = 0;
117 int64_t row, rows, snapshotrow = 0, initRow = 0, outrow;
118 double *rowdata = NULL;
119 long *origToNewIndex = NULL;
120 double minimumInterval = -1;
121 double timeInterval, previousTime = 0;
122 int64_t totalRows = 0, currentRows = 0;
123 short filterTime = 0;
124 double startTime = 0, endTime = MAXDOUBLE;
125 int64_t startTimeRow = 0, endTimeRow = 0;
126 unsigned long flags;
127 char **ColumnName = NULL;
128 long ColumnNames;
129 char **retain_name = NULL;
130 long retain_names = 0;
131 char **delete_name = NULL;
132 long delete_names = 0;
133
135 argc = scanargs(&s_arg, argc, argv);
136 if (argc < 3) {
137 fprintf(stderr, "%s", USAGE);
138 exit(EXIT_FAILURE);
139 }
140 input = output = NULL;
141 ascii_output = binary_output = noWarnings = 0;
142
143 tmpfile_used = 0;
144 pipeFlags = 0;
145
146 for (i_arg = 1; i_arg < argc; i_arg++) {
147 if (s_arg[i_arg].arg_type == OPTION) {
148 delete_chars(s_arg[i_arg].list[0], "_");
149 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
150 case SET_BINARY:
151 binary_output = 1;
152 ascii_output = 0;
153 break;
154 case SET_ASCII:
155 ascii_output = 1;
156 binary_output = 0;
157 break;
158 case SET_FLOAT:
159 output_type = SDDS_FLOAT;
160 break;
161 case SET_DOUBLE:
162 output_type = SDDS_DOUBLE;
163 break;
164 case SET_SNAPSHOT:
165 if (s_arg[i_arg].n_items < 2) {
166 fprintf(stderr, "invalid -snapshot syntax\n");
167 exit(EXIT_FAILURE);
168 }
169 snapshot = 1;
170 if (sscanf(s_arg[i_arg].list[1], "%lf", &epochtime) != 1) {
171 fprintf(stderr, "invalid -snapshot syntax or value\n");
172 exit(EXIT_FAILURE);
173 }
174 break;
175 case SET_PIPE:
176 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags)) {
177 fprintf(stderr, "invalid -pipe syntax\n");
178 exit(EXIT_FAILURE);
179 }
180 break;
181 case SET_MININTERVAL:
182 if (s_arg[i_arg].n_items < 2) {
183 fprintf(stderr, "invalid -minimumInterval syntax\n");
184 exit(EXIT_FAILURE);
185 }
186 if (sscanf(s_arg[i_arg].list[1], "%lf", &minimumInterval) != 1) {
187 fprintf(stderr, "invalid -minimumInterval syntax or value\n");
188 exit(EXIT_FAILURE);
189 }
190 break;
191 case SET_TIME:
192 s_arg[i_arg].n_items -= 1;
193 filterTime = 1;
194 if (!scanItemList(&flags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
195 "start", SDDS_DOUBLE, &startTime, 1, 0,
196 "end", SDDS_DOUBLE, &endTime, 1, 0, NULL)) {
197 fprintf(stderr, "invalid -time syntax\n");
198 exit(EXIT_FAILURE);
199 }
200 s_arg[i_arg].n_items += 1;
201 break;
202 case SET_RETAIN:
203 retain_name = trealloc(retain_name, sizeof(*retain_name) * (retain_names + s_arg[i_arg].n_items - 1));
204 for (i = 1; i < s_arg[i_arg].n_items; i++)
205 retain_name[i - 1 + retain_names] = s_arg[i_arg].list[i];
206 retain_names += s_arg[i_arg].n_items - 1;
207 break;
208 case SET_DELETE:
209 delete_name = trealloc(delete_name, sizeof(*delete_name) * (delete_names + s_arg[i_arg].n_items - 1));
210 for (i = 1; i < s_arg[i_arg].n_items; i++)
211 delete_name[i - 1 + delete_names] = s_arg[i_arg].list[i];
212 delete_names += s_arg[i_arg].n_items - 1;
213 break;
214 default:
215 fprintf(stderr, "Error (%s): unknown switch: %s\n", argv[0], s_arg[i_arg].list[0]);
216 exit(EXIT_FAILURE);
217 break;
218 }
219 } else {
220 if (input == NULL)
221 input = s_arg[i_arg].list[0];
222 else if (output == NULL)
223 output = s_arg[i_arg].list[0];
224 else {
225 fprintf(stderr, "too many filenames\n");
226 exit(EXIT_FAILURE);
227 }
228 }
229 }
230
231 if ((snapshot == 1) && (minimumInterval >= 0)) {
232 fprintf(stderr, "-snapshot and -minimumInterval options cannot be used together\n");
233 exit(EXIT_FAILURE);
234 }
235 if ((snapshot == 1) && (filterTime == 1)) {
236 fprintf(stderr, "-snapshot and -time options cannot be used together\n");
237 exit(EXIT_FAILURE);
238 }
239
240 processFilenames("sddsconvertalarmlog", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
241
242 if (!SDDS_InitializeInput(&SDDS_input, input)) {
243 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
244 exit(EXIT_FAILURE);
245 }
246
247 readbackNameIndex = SDDS_VerifyArrayExists(&SDDS_input, FIND_SPECIFIED_TYPE, SDDS_STRING, "ReadbackName");
248 controlNameIndex = SDDS_VerifyArrayExists(&SDDS_input, FIND_SPECIFIED_TYPE, SDDS_STRING, "ControlName");
249 previousRowIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_NUMERIC_TYPE, "PreviousRow");
250 timeIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_NUMERIC_TYPE, "Time");
251 valueIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_NUMERIC_TYPE, "Value");
252 controlNameIndexIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_INTEGER_TYPE, "ControlNameIndex");
253 if ((readbackNameIndex == -1) && (controlNameIndex == -1)) {
254 fprintf(stderr, "Error: ReadbackName and ControlName arrays are both missing from the input file.\n");
255 exit(EXIT_FAILURE);
256 }
257 if (timeIndex == -1) {
258 fprintf(stderr, "Error: Time column is missing\n");
259 exit(EXIT_FAILURE);
260 }
261 if (valueIndex == -1) {
262 fprintf(stderr, "Error: Value column is missing\n");
263 exit(EXIT_FAILURE);
264 }
265 if (controlNameIndexIndex == -1) {
266 fprintf(stderr, "Error: ControlNameIndex column is missing\n");
267 exit(EXIT_FAILURE);
268 }
269
270 if (!SDDS_InitializeOutput(&SDDS_output, ascii_output ? SDDS_ASCII : (binary_output ? SDDS_BINARY : SDDS_input.layout.data_mode.mode), 1, NULL, NULL, output)) {
271 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
272 exit(EXIT_FAILURE);
273 }
274
275 outrow = 0;
276 while (SDDS_ReadTable(&SDDS_input) > 0) {
277 page++;
278 rows = SDDS_RowCount(&SDDS_input);
279 if (page == 1) {
280 if (readbackNameIndex != -1) {
281 readbackNameArray = SDDS_GetArray(&SDDS_input, "ReadbackName", NULL);
282 } else {
283 readbackNameArray = SDDS_GetArray(&SDDS_input, "ControlName", NULL);
284 }
285 if (readbackNameArray == NULL) {
286 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
287 exit(EXIT_FAILURE);
288 }
289
290 origToNewIndex = malloc(sizeof(long) * readbackNameArray->elements);
291 for (i = 0; i < readbackNameArray->elements; i++) {
292 origToNewIndex[i] = -1;
293 }
294
295 ColumnName = process_name_options(((char **)readbackNameArray->data), readbackNameArray->elements, delete_name, delete_names, retain_name, retain_names, &ColumnNames, &origToNewIndex);
296 rowdata = malloc(sizeof(double) * ColumnNames);
297 for (i = 0; i < ColumnNames; i++) {
298 rowdata[i] = 0;
299 }
300
301 if (SDDS_DefineSimpleColumn(&SDDS_output, "Time", NULL, SDDS_DOUBLE) == 0) {
302 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
303 exit(EXIT_FAILURE);
304 }
305 if (SDDS_DefineSimpleColumns(&SDDS_output, ColumnNames, ColumnName, NULL, output_type) == 0) {
306 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
307 exit(EXIT_FAILURE);
308 }
309 if (SDDS_WriteLayout(&SDDS_output) == 0) {
310 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
311 exit(EXIT_FAILURE);
312 }
313 if (snapshot) {
314 if (SDDS_StartTable(&SDDS_output, 1) == 0) {
315 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
316 exit(EXIT_FAILURE);
317 }
318 } else {
319 if (SDDS_StartTable(&SDDS_output, 100) == 0) {
320 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
321 exit(EXIT_FAILURE);
322 }
323 totalRows = 100;
324 }
325 } else {
326 if (readbackNameIndex != -1) {
327 readbackNameArray2 = SDDS_GetArray(&SDDS_input, "ReadbackName", NULL);
328 } else {
329 readbackNameArray2 = SDDS_GetArray(&SDDS_input, "ControlName", NULL);
330 }
331 if (readbackNameArray2 == NULL) {
332 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
333 exit(EXIT_FAILURE);
334 }
335 if (readbackNameArray->elements != readbackNameArray2->elements) {
336 fprintf(stderr, "Error: Unable to process multiple pages with different ReadbackName and/or ControlName columns\n");
337 exit(EXIT_FAILURE);
338 }
339 for (i = 0; i < readbackNameArray->elements; i++) {
340 if (strcmp((char *)((char **)readbackNameArray->data)[i], (char *)((char **)readbackNameArray2->data)[i]) != 0) {
341 fprintf(stderr, "Error: Unable to process multiple pages with different ReadbackName and/or ControlName columns\n");
342 exit(EXIT_FAILURE);
343 }
344 }
345 SDDS_FreeArray(readbackNameArray2);
346 }
347 if ((timeData = SDDS_GetColumnInDoubles(&SDDS_input, "Time")) == NULL) {
348 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
349 exit(EXIT_FAILURE);
350 }
351 if ((valueData = SDDS_GetColumnInDoubles(&SDDS_input, "Value")) == NULL) {
352 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
353 exit(EXIT_FAILURE);
354 }
355 if ((controlNameIndexData = SDDS_GetColumnInLong(&SDDS_input, "ControlNameIndex")) == NULL) {
356 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
357 exit(EXIT_FAILURE);
358 }
359 if (snapshot) {
360 snapshotrow = 0;
361 for (row = 0; row < rows; row++) {
362 if (timeData[row] <= epochtime) {
363 snapshotrow = row;
364 } else {
365 break;
366 }
367 }
368 }
369 if (filterTime) {
370 for (row = 0; row < rows; row++) {
371 if (timeData[row] <= startTime) {
372 startTimeRow = row;
373 } else {
374 break;
375 }
376 }
377 for (row = 0; row < rows; row++) {
378 if (timeData[row] <= endTime) {
379 endTimeRow = row;
380 } else {
381 break;
382 }
383 }
384 }
385 if (previousRowIndex != -1) {
386 if ((previousRowData = SDDS_GetColumnInDoubles(&SDDS_input, "PreviousRow")) == NULL) {
387 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
388 exit(EXIT_FAILURE);
389 }
390 for (row = rows - 1; row >= 0; row--) {
391 if (previousRowData[row] == -2) {
392 if (origToNewIndex[controlNameIndexData[row]] == -1) {
393 continue;
394 }
395 initRow = row;
396 break;
397 }
398 }
399 free(previousRowData);
400 }
401
402 if (minimumInterval > 0) {
403 previousTime = timeData[0] - minimumInterval - 1;
404 }
405 for (row = 0; row < rows; row++) {
406 if ((readbackNameArray->elements < controlNameIndexData[row]) ||
407 (controlNameIndexData[row] < 0)) {
408 /*sometimes there is invalid data in the original file */
409 continue;
410 }
411 if (origToNewIndex[controlNameIndexData[row]] == -1) {
412 continue;
413 }
414 rowdata[origToNewIndex[controlNameIndexData[row]]] = valueData[row];
415 if (previousRowIndex != -1) {
416 if (row < initRow) {
417 continue;
418 }
419 }
420 if (((snapshot == 0) && (filterTime == 0)) ||
421 ((snapshot == 1) && (row == snapshotrow)) ||
422 ((filterTime == 1) && (row >= startTimeRow) && (row <= endTimeRow))) {
423 if (minimumInterval > 0) {
424 timeInterval = timeData[row] - previousTime;
425 if (timeInterval <= minimumInterval) {
426 continue;
427 } else {
428 previousTime = timeData[row];
429 }
430 }
431 if ((snapshot == 0) && (totalRows == currentRows)) {
432 if (SDDS_LengthenTable(&SDDS_output, 100) == 0) {
433 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
434 exit(EXIT_FAILURE);
435 }
436 totalRows += 100;
437 }
438 currentRows++;
439 if (SDDS_SetRowValuesMod(&SDDS_output, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, outrow, 0, &timeData[row], -1) == 0) {
440 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
441 exit(EXIT_FAILURE);
442 }
443 for (i = 0; i < ColumnNames; i++) {
444 if (SDDS_SetRowValuesMod(&SDDS_output, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, outrow, i + 1, &rowdata[i], -1) == 0) {
445 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
446 exit(EXIT_FAILURE);
447 }
448 }
449 if (snapshot)
450 break;
451 outrow++;
452 }
453 }
454 if (timeData)
455 free(timeData);
456 if (valueData)
457 free(valueData);
458 if (controlNameIndexData)
459 free(controlNameIndexData);
460 }
461 if (rowdata)
462 free(rowdata);
463 if (origToNewIndex)
464 free(origToNewIndex);
465
466 if (ColumnName) {
467 for (i = 0; i < ColumnNames; i++) {
468 if (ColumnName[i])
469 free(ColumnName[i]);
470 }
471 free(ColumnName);
472 }
473
474 SDDS_FreeArray(readbackNameArray);
475 if (SDDS_WriteTable(&SDDS_output) == 0) {
476 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
477 exit(EXIT_FAILURE);
478 }
479
480 if (!SDDS_Terminate(&SDDS_input) || !SDDS_Terminate(&SDDS_output)) {
481 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
482 exit(EXIT_FAILURE);
483 }
484
485 if (tmpfile_used && !replaceFileAndBackUp(input, output))
486 exit(EXIT_FAILURE);
487
488 free_scanargs(&s_arg, argc);
489 return EXIT_SUCCESS;
490}
491
492long SDDS_SetRowValuesMod(SDDS_DATASET *SDDS_dataset, long mode, int64_t row, ...) {
493 va_list argptr;
494 int32_t index;
495 long retval;
496 SDDS_LAYOUT *layout;
497 char *name;
498 char buffer[200];
499
500 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowValues"))
501 return (0);
502 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) ||
503 !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
504 SDDS_SetError("Unable to set column values--unknown mode (SDDS_SetRowValues)");
505 return (0);
506 }
507 /*
508 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_SetRowValues"))
509 return(0);
510 */
511 row -= SDDS_dataset->first_row_in_mem;
512 if (row >= SDDS_dataset->n_rows_allocated) {
513 sprintf(buffer, "Unable to set column values--row number (%" PRId64 ") exceeds exceeds allocated memory (%" PRId64 ") (SDDS_SetRowValues)", row, SDDS_dataset->n_rows_allocated);
514 SDDS_SetError(buffer);
515 return (0);
516 }
517 if (row > SDDS_dataset->n_rows - 1)
518 SDDS_dataset->n_rows = row + 1;
519
520 va_start(argptr, row);
521 layout = &SDDS_dataset->layout;
522
523 /* variable arguments are pairs of (index, value), where index is a long integer */
524 retval = -1;
525#ifdef DEBUG
526 fprintf(stderr, "setting row %" PRId64 " (mem slot %" PRId64 ")\n", row + SDDS_dataset->first_row_in_mem, row);
527#endif
528 do {
529 if (mode & SDDS_SET_BY_INDEX) {
530 if ((index = va_arg(argptr, int32_t)) == -1) {
531 retval = 1;
532 break;
533 }
534 if (index < 0 || index >= layout->n_columns) {
535 SDDS_SetError("Unable to set column values--index out of range (SDDS_SetRowValues)");
536 retval = 0;
537 break;
538 }
539#ifdef DEBUG
540 fprintf(stderr, "Setting values for column #%ld\n", index);
541#endif
542 } else {
543 if ((name = va_arg(argptr, char *)) == NULL) {
544 retval = 1;
545 break;
546 }
547#ifdef DEBUG
548 fprintf(stderr, "Setting values for column %s\n", name);
549#endif
550 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0) {
551 SDDS_SetError("Unable to set column values--name not recognized (SDDS_SetRowValues)");
552 retval = 0;
553 break;
554 }
555 }
556 switch (layout->column_definition[index].type) {
557 case SDDS_SHORT:
558 if (mode & SDDS_PASS_BY_VALUE)
559 *(((short *)SDDS_dataset->data[index]) + row) = (short)va_arg(argptr, int);
560 else
561 *(((short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, short *));
562 break;
563 case SDDS_USHORT:
564 if (mode & SDDS_PASS_BY_VALUE)
565 *(((unsigned short *)SDDS_dataset->data[index]) + row) = (unsigned short)va_arg(argptr, unsigned int);
566 else
567 *(((unsigned short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, unsigned short *));
568 break;
569 case SDDS_LONG:
570 if (mode & SDDS_PASS_BY_VALUE)
571 *(((int32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int32_t);
572 else
573 *(((int32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int32_t *));
574 break;
575 case SDDS_ULONG:
576 if (mode & SDDS_PASS_BY_VALUE)
577 *(((uint32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint32_t);
578 else
579 *(((uint32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint32_t *));
580 break;
581 case SDDS_LONG64:
582 if (mode & SDDS_PASS_BY_VALUE)
583 *(((int64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int64_t);
584 else
585 *(((int64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int64_t *));
586 break;
587 case SDDS_ULONG64:
588 if (mode & SDDS_PASS_BY_VALUE)
589 *(((uint64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint64_t);
590 else
591 *(((uint64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint64_t *));
592 break;
593 case SDDS_FLOAT:
594 if (mode & SDDS_PASS_BY_VALUE)
595 *(((float *)SDDS_dataset->data[index]) + row) = (float)va_arg(argptr, double);
596 else
597 *(((float *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, double *));
598 break;
599 case SDDS_DOUBLE:
600 if (mode & SDDS_PASS_BY_VALUE)
601 *(((double *)SDDS_dataset->data[index]) + row) = va_arg(argptr, double);
602 else
603 *(((double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, double *));
604 break;
605 case SDDS_LONGDOUBLE:
606 if (mode & SDDS_PASS_BY_VALUE)
607 *(((long double *)SDDS_dataset->data[index]) + row) = va_arg(argptr, long double);
608 else
609 *(((long double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, long double *));
610 break;
611 case SDDS_STRING:
612 if (((char **)SDDS_dataset->data[index])[row]) {
613 free(((char **)SDDS_dataset->data[index])[row]);
614 ((char **)SDDS_dataset->data[index])[row] = NULL;
615 }
616 if (mode & SDDS_PASS_BY_VALUE) {
617 if (!SDDS_CopyString((char **)SDDS_dataset->data[index] + row, va_arg(argptr, char *))) {
618 SDDS_SetError("Unable to set string column value--allocation failure (SDDS_SetRowValues)");
619 retval = 0;
620 }
621 } else {
622 if (!SDDS_CopyString((char **)SDDS_dataset->data[index] + row, *(va_arg(argptr, char **)))) {
623 SDDS_SetError("Unable to set string column value--allocation failure (SDDS_SetRowValues)");
624 retval = 0;
625 }
626 }
627 break;
628 case SDDS_CHARACTER:
629 if (mode & SDDS_PASS_BY_VALUE)
630 *(((char *)SDDS_dataset->data[index]) + row) = (char)va_arg(argptr, int);
631 else
632 *(((char *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, char *));
633 break;
634 default:
635 SDDS_SetError("Unknown data type encountered (SDDS_SetRowValues");
636 retval = 0;
637 break;
638 }
639 } while (retval == -1);
640 va_end(argptr);
641 return (retval);
642}
643
644char **process_name_options(char **orig_name, long orig_names, char **delete, long deletes, char **retain, long retains, long *num_matched, long **origToNewIndex) {
645 long i, j;
646 char **new_name;
647 char *ptr = NULL;
648 long *orig_flag = NULL;
649
650 orig_flag = tmalloc(sizeof(*orig_flag) * orig_names);
651 for (i = 0; i < orig_names; i++)
652 (orig_flag)[i] = 1;
653
654 if (deletes) {
655 for (i = 0; i < deletes; i++) {
656 ptr = expand_ranges(delete[i]);
657 /*free(delete[i]); */ /* freed by free_scanargs */
658 delete[i] = ptr;
659 }
660 for (j = 0; j < orig_names; j++) {
661 for (i = 0; i < deletes; i++) {
662 if (wild_match(orig_name[j], delete[i])) {
663 (orig_flag)[j] = 0;
664 break;
665 }
666 }
667 }
668 for (i = 0; i < deletes; i++) {
669 if (delete[i])
670 free(delete[i]);
671 }
672 }
673
674 if (retains) {
675 for (i = 0; i < retains; i++) {
676 ptr = expand_ranges(retain[i]);
677 /*free(retain[i]); */ /* freed by free_scanargs */
678 retain[i] = ptr;
679 }
680 if (!deletes)
681 for (j = 0; j < orig_names; j++)
682 (orig_flag)[j] = 0;
683 for (j = 0; j < orig_names; j++) {
684 if ((orig_flag)[j])
685 continue;
686 for (i = 0; i < retains; i++) {
687 if (wild_match(orig_name[j], retain[i])) {
688 (orig_flag)[j] = 1;
689 break;
690 }
691 }
692 }
693 for (i = 0; i < retains; i++) {
694 if (retain[i])
695 free(retain[i]);
696 }
697 }
698
699 *num_matched = 0;
700 for (j = 0; j < orig_names; j++) {
701 if (orig_flag[j])
702 (*num_matched)++;
703 }
704 new_name = tmalloc(sizeof(*new_name) * (*num_matched));
705 i = 0;
706 for (j = 0; j < orig_names; j++) {
707 if (orig_flag[j]) {
708 (*origToNewIndex)[j] = i;
709 SDDS_CopyString(new_name + i, orig_name[j]);
710 i++;
711 }
712 }
713 free(orig_flag);
714
715 return (new_name);
716}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
SDDS_ARRAY * SDDS_GetArray(SDDS_DATASET *SDDS_dataset, char *array_name, SDDS_ARRAY *memory)
Retrieves an array from the current data table of an SDDS dataset.
int32_t * SDDS_GetColumnInLong(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves the data of a specified numerical column as an array of 32-bit integers,...
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_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_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_DefineSimpleColumns(SDDS_DATASET *SDDS_dataset, int32_t number, char **name, char **unit, int32_t type)
Defines multiple simple data columns of the same data type within the SDDS dataset.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
void SDDS_FreeArray(SDDS_ARRAY *array)
Frees memory allocated for an SDDS array structure.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
int32_t SDDS_VerifyArrayExists(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Verifies the existence of an array in the SDDS dataset based on specified criteria.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552
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_VerifyColumnExists(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Verifies the existence of a column in the SDDS dataset based on specified criteria.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
Definition SDDS_utils.c:856
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
Definition SDDStypes.h:67
#define SDDS_FLOAT
Identifier for the float data type.
Definition SDDStypes.h:43
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
Definition SDDStypes.h:55
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
#define SDDS_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
Definition SDDStypes.h:79
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
Definition SDDStypes.h:31
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
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.
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
Definition wild_match.c:429
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
Definition wild_match.c:49