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

Converts SDDS log-on-change files with various configurable options. More...

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

Go to the source code of this file.

Macros

#define MAXDOUBLE   1.79769313486231570e+308
 

Enumerations

enum  option_type {
  SET_BINARY , SET_ASCII , SET_FLOAT , SET_DOUBLE ,
  SET_SNAPSHOT , SET_PIPE , SET_MININTERVAL , SET_TIME ,
  SET_DELETE , SET_RETAIN , N_OPTIONS
}
 

Functions

long SDDS_SetRowValuesMod (SDDS_DATASET *SDDS_dataset, long mode, int64_t row,...)
 
char ** process_name_options (char **orig_name, long orig_names, char **delete, long deletes, char **retain, long retains, long *num_matched, long **origToNewIndex)
 
int main (int argc, char **argv)
 

Variables

char * option [N_OPTIONS]
 
char * USAGE
 

Detailed Description

Converts SDDS log-on-change files with various configurable options.

This program processes SDDS (Self Describing Data Sets) input files and converts them based on specified command-line options. It supports binary and ASCII output formats, floating and double precision, snapshotting at specific epoch times, piping input/output, filtering by time intervals, and retaining or deleting specific columns based on patterns.

Usage: sddsconvertlogonchange [<input-file>] [<output-file>] [-pipe=[input][,output]] [-binary | -ascii] [-double | -float] [-minimumInterval=<seconds>] [-snapshot=<epochtime>] [-time=[start=<epochtime>][,end=<epochtime>]] [-delete=<matching-string>[,...]] [-retain=<matching-string>[,...]]

Options: -pipe Configure piping for input and/or output. -binary Output in binary format. -ascii Output in ASCII format. -double Use double precision for numerical data. -float Use single precision (float) for numerical data. -minimumInterval Specify the minimum time interval between data points. -snapshot Take a snapshot at the specified epoch time. -time Filter data within the specified start and end epoch times. -delete Delete columns matching the given patterns. -retain Retain only columns matching the given patterns.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
R. Soliday

Definition in file sddsconvertlogonchange.c.

Macro Definition Documentation

◆ MAXDOUBLE

#define MAXDOUBLE   1.79769313486231570e+308

Definition at line 64 of file sddsconvertlogonchange.c.

Enumeration Type Documentation

◆ option_type

enum option_type

Definition at line 49 of file sddsconvertlogonchange.c.

49 {
50 SET_BINARY,
51 SET_ASCII,
52 SET_FLOAT,
53 SET_DOUBLE,
54 SET_SNAPSHOT,
55 SET_PIPE,
56 SET_MININTERVAL,
57 SET_TIME,
58 SET_DELETE,
59 SET_RETAIN,
60 N_OPTIONS
61};

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 86 of file sddsconvertlogonchange.c.

86 {
87 SDDS_DATASET SDDS_input, SDDS_output;
88 long i, i_arg;
89 SCANNED_ARG *s_arg;
90 long tmpfile_used, noWarnings;
91 char *input, *output;
92 long ascii_output, binary_output;
93 unsigned long pipeFlags;
94 long output_type = SDDS_DOUBLE;
95 long snapshot = 0;
96 double epochtime;
97
98 long readbackNameIndex = -1, controlNameIndex = -1;
99 long timeIndex = -1, valueIndex = -1, controlNameIndexIndex = -1, previousRowIndex = -1;
100 double *timeData = NULL, *valueData = NULL, *previousRowData = NULL;
101 int32_t *controlNameIndexData = NULL;
102 SDDS_ARRAY *readbackNameArray = NULL;
103 SDDS_ARRAY *readbackNameArray2 = NULL;
104 long page = 0;
105 int64_t row, rows, snapshotrow = 0, initRow = 0, outrow;
106 double *rowdata = NULL;
107 long *origToNewIndex = NULL;
108 double minimumInterval = -1;
109 double timeInterval, previousTime = 0;
110 int64_t totalRows = 0, currentRows = 0;
111 short filterTime = 0;
112 double startTime = 0, endTime = MAXDOUBLE;
113 int64_t startTimeRow = 0, endTimeRow = 0;
114 unsigned long flags;
115 char **ColumnName = NULL;
116 long ColumnNames;
117 char **retain_name = NULL;
118 long retain_names = 0;
119 char **delete_name = NULL;
120 long delete_names = 0;
121
123 argc = scanargs(&s_arg, argc, argv);
124 if (argc < 3) {
125 fprintf(stderr, "%s", USAGE);
126 exit(EXIT_FAILURE);
127 }
128 input = output = NULL;
129 ascii_output = binary_output = noWarnings = 0;
130
131 tmpfile_used = 0;
132 pipeFlags = 0;
133
134 for (i_arg = 1; i_arg < argc; i_arg++) {
135 if (s_arg[i_arg].arg_type == OPTION) {
136 delete_chars(s_arg[i_arg].list[0], "_");
137 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
138 case SET_BINARY:
139 binary_output = 1;
140 ascii_output = 0;
141 break;
142 case SET_ASCII:
143 ascii_output = 1;
144 binary_output = 0;
145 break;
146 case SET_FLOAT:
147 output_type = SDDS_FLOAT;
148 break;
149 case SET_DOUBLE:
150 output_type = SDDS_DOUBLE;
151 break;
152 case SET_SNAPSHOT:
153 if (s_arg[i_arg].n_items < 2) {
154 fprintf(stderr, "Error: Invalid syntax for -snapshot option.\n");
155 exit(EXIT_FAILURE);
156 }
157 snapshot = 1;
158 if (sscanf(s_arg[i_arg].list[1], "%lf", &epochtime) != 1) {
159 fprintf(stderr, "Error: Invalid value for -snapshot option.\n");
160 exit(EXIT_FAILURE);
161 }
162 break;
163 case SET_PIPE:
164 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags)) {
165 fprintf(stderr, "Error: Invalid syntax for -pipe option.\n");
166 exit(EXIT_FAILURE);
167 }
168 break;
169 case SET_MININTERVAL:
170 if (s_arg[i_arg].n_items < 2) {
171 fprintf(stderr, "Error: Invalid syntax for -minimumInterval option.\n");
172 exit(EXIT_FAILURE);
173 }
174 if (sscanf(s_arg[i_arg].list[1], "%lf", &minimumInterval) != 1) {
175 fprintf(stderr, "Error: Invalid value for -minimumInterval option.\n");
176 exit(EXIT_FAILURE);
177 }
178 break;
179 case SET_TIME:
180 s_arg[i_arg].n_items -= 1;
181 filterTime = 1;
182 if (!scanItemList(&flags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
183 "start", SDDS_DOUBLE, &startTime, 1, 0,
184 "end", SDDS_DOUBLE, &endTime, 1, 0, NULL)) {
185 fprintf(stderr, "Error: Invalid syntax for -time option.\n");
186 exit(EXIT_FAILURE);
187 }
188 s_arg[i_arg].n_items += 1;
189 break;
190 case SET_RETAIN:
191 retain_name = trealloc(retain_name, sizeof(*retain_name) * (retain_names + s_arg[i_arg].n_items - 1));
192 for (i = 1; i < s_arg[i_arg].n_items; i++)
193 retain_name[i - 1 + retain_names] = s_arg[i_arg].list[i];
194 retain_names += s_arg[i_arg].n_items - 1;
195 break;
196 case SET_DELETE:
197 delete_name = trealloc(delete_name, sizeof(*delete_name) * (delete_names + s_arg[i_arg].n_items - 1));
198 for (i = 1; i < s_arg[i_arg].n_items; i++)
199 delete_name[i - 1 + delete_names] = s_arg[i_arg].list[i];
200 delete_names += s_arg[i_arg].n_items - 1;
201 break;
202 default:
203 fprintf(stderr, "Error (%s): Unknown option: %s\n", argv[0], s_arg[i_arg].list[0]);
204 exit(EXIT_FAILURE);
205 break;
206 }
207 } else {
208 if (input == NULL)
209 input = s_arg[i_arg].list[0];
210 else if (output == NULL)
211 output = s_arg[i_arg].list[0];
212 else {
213 fprintf(stderr, "Error: Too many filenames provided.\n");
214 exit(EXIT_FAILURE);
215 }
216 }
217 }
218
219 if ((snapshot == 1) && (minimumInterval >= 0)) {
220 fprintf(stderr, "Error: -snapshot and -minimumInterval options cannot be used together.\n");
221 exit(EXIT_FAILURE);
222 }
223 if ((snapshot == 1) && (filterTime == 1)) {
224 fprintf(stderr, "Error: -snapshot and -time options cannot be used together.\n");
225 exit(EXIT_FAILURE);
226 }
227
228 processFilenames("sddsconvertlogonchange", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
229
230 if (!SDDS_InitializeInput(&SDDS_input, input)) {
231 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
232 exit(EXIT_FAILURE);
233 }
234
235 readbackNameIndex = SDDS_VerifyArrayExists(&SDDS_input, FIND_SPECIFIED_TYPE, SDDS_STRING, "ReadbackName");
236 controlNameIndex = SDDS_VerifyArrayExists(&SDDS_input, FIND_SPECIFIED_TYPE, SDDS_STRING, "ControlName");
237 previousRowIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_NUMERIC_TYPE, "PreviousRow");
238 timeIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_NUMERIC_TYPE, "Time");
239 valueIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_NUMERIC_TYPE, "Value");
240 controlNameIndexIndex = SDDS_VerifyColumnExists(&SDDS_input, FIND_INTEGER_TYPE, "ControlNameIndex");
241 if ((readbackNameIndex == -1) && (controlNameIndex == -1)) {
242 fprintf(stderr, "Error: Both ReadbackName and ControlName arrays are missing from the input file.\n");
243 exit(EXIT_FAILURE);
244 }
245 if (timeIndex == -1) {
246 fprintf(stderr, "Error: Time column is missing.\n");
247 exit(EXIT_FAILURE);
248 }
249 if (valueIndex == -1) {
250 fprintf(stderr, "Error: Value column is missing.\n");
251 exit(EXIT_FAILURE);
252 }
253 if (controlNameIndexIndex == -1) {
254 fprintf(stderr, "Error: ControlNameIndex column is missing.\n");
255 exit(EXIT_FAILURE);
256 }
257
258 if (!SDDS_InitializeOutput(&SDDS_output, ascii_output ? SDDS_ASCII : (binary_output ? SDDS_BINARY : SDDS_input.layout.data_mode.mode), 1, NULL, NULL, output)) {
259 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
260 exit(EXIT_FAILURE);
261 }
262
263 outrow = 0;
264 while (SDDS_ReadTable(&SDDS_input) > 0) {
265 page++;
266 rows = SDDS_RowCount(&SDDS_input);
267 if (page == 1) {
268 if (readbackNameIndex != -1) {
269 readbackNameArray = SDDS_GetArray(&SDDS_input, "ReadbackName", NULL);
270 } else {
271 readbackNameArray = SDDS_GetArray(&SDDS_input, "ControlName", NULL);
272 }
273 if (readbackNameArray == NULL) {
274 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
275 exit(EXIT_FAILURE);
276 }
277
278 origToNewIndex = malloc(sizeof(long) * readbackNameArray->elements);
279 for (i = 0; i < readbackNameArray->elements; i++) {
280 origToNewIndex[i] = -1;
281 }
282
283 ColumnName = process_name_options(((char **)readbackNameArray->data), readbackNameArray->elements, delete_name, delete_names, retain_name, retain_names, &ColumnNames, &origToNewIndex);
284 rowdata = malloc(sizeof(double) * ColumnNames);
285 for (i = 0; i < ColumnNames; i++) {
286 rowdata[i] = 0;
287 }
288
289 if (SDDS_DefineSimpleColumn(&SDDS_output, "Time", NULL, SDDS_DOUBLE) == 0) {
290 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
291 exit(EXIT_FAILURE);
292 }
293 if (SDDS_DefineSimpleColumns(&SDDS_output, ColumnNames, ColumnName, NULL, output_type) == 0) {
294 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
295 exit(EXIT_FAILURE);
296 }
297 if (SDDS_WriteLayout(&SDDS_output) == 0) {
298 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
299 exit(EXIT_FAILURE);
300 }
301 if (snapshot) {
302 if (SDDS_StartTable(&SDDS_output, 1) == 0) {
303 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
304 exit(EXIT_FAILURE);
305 }
306 } else {
307 if (SDDS_StartTable(&SDDS_output, 100) == 0) {
308 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
309 exit(EXIT_FAILURE);
310 }
311 totalRows = 100;
312 }
313 } else {
314 if (readbackNameIndex != -1) {
315 readbackNameArray2 = SDDS_GetArray(&SDDS_input, "ReadbackName", NULL);
316 } else {
317 readbackNameArray2 = SDDS_GetArray(&SDDS_input, "ControlName", NULL);
318 }
319 if (readbackNameArray2 == NULL) {
320 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
321 exit(EXIT_FAILURE);
322 }
323 if (readbackNameArray->elements != readbackNameArray2->elements) {
324 fprintf(stderr, "Error: Multiple pages with differing ReadbackName and/or ControlName columns cannot be processed.\n");
325 exit(EXIT_FAILURE);
326 }
327 for (i = 0; i < readbackNameArray->elements; i++) {
328 if (strcmp((char *)((char **)readbackNameArray->data)[i], (char *)((char **)readbackNameArray2->data)[i]) != 0) {
329 fprintf(stderr, "Error: Multiple pages with differing ReadbackName and/or ControlName columns cannot be processed.\n");
330 exit(EXIT_FAILURE);
331 }
332 }
333 SDDS_FreeArray(readbackNameArray2);
334 }
335 if ((timeData = SDDS_GetColumnInDoubles(&SDDS_input, "Time")) == NULL) {
336 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
337 exit(EXIT_FAILURE);
338 }
339 if ((valueData = SDDS_GetColumnInDoubles(&SDDS_input, "Value")) == NULL) {
340 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
341 exit(EXIT_FAILURE);
342 }
343 if ((controlNameIndexData = SDDS_GetColumnInLong(&SDDS_input, "ControlNameIndex")) == NULL) {
344 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
345 exit(EXIT_FAILURE);
346 }
347 if (snapshot) {
348 snapshotrow = 0;
349 for (row = 0; row < rows; row++) {
350 if (timeData[row] <= epochtime) {
351 snapshotrow = row;
352 } else {
353 break;
354 }
355 }
356 }
357 if (filterTime) {
358 for (row = 0; row < rows; row++) {
359 if (timeData[row] <= startTime) {
360 startTimeRow = row;
361 } else {
362 break;
363 }
364 }
365 for (row = 0; row < rows; row++) {
366 if (timeData[row] <= endTime) {
367 endTimeRow = row;
368 } else {
369 break;
370 }
371 }
372 }
373 if (previousRowIndex != -1) {
374 if ((previousRowData = SDDS_GetColumnInDoubles(&SDDS_input, "PreviousRow")) == NULL) {
375 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
376 exit(EXIT_FAILURE);
377 }
378 for (row = rows - 1; row >= 0; row--) {
379 if (previousRowData[row] == -2) {
380 if (origToNewIndex[controlNameIndexData[row]] == -1) {
381 continue;
382 }
383 initRow = row;
384 break;
385 }
386 }
387 free(previousRowData);
388 }
389
390 if (minimumInterval > 0) {
391 previousTime = timeData[0] - minimumInterval - 1;
392 }
393 for (row = 0; row < rows; row++) {
394 if ((readbackNameArray->elements < controlNameIndexData[row]) ||
395 (controlNameIndexData[row] < 0)) {
396 /* Sometimes there is invalid data in the original file */
397 continue;
398 }
399 if (origToNewIndex[controlNameIndexData[row]] == -1) {
400 continue;
401 }
402 rowdata[origToNewIndex[controlNameIndexData[row]]] = valueData[row];
403 if (previousRowIndex != -1) {
404 if (row < initRow) {
405 continue;
406 }
407 }
408 if (((snapshot == 0) && (filterTime == 0)) ||
409 ((snapshot == 1) && (row == snapshotrow)) ||
410 ((filterTime == 1) && (row >= startTimeRow) && (row <= endTimeRow))) {
411 if (minimumInterval > 0) {
412 timeInterval = timeData[row] - previousTime;
413 if (timeInterval <= minimumInterval) {
414 continue;
415 } else {
416 previousTime = timeData[row];
417 }
418 }
419 if ((snapshot == 0) && (totalRows == currentRows)) {
420 if (SDDS_LengthenTable(&SDDS_output, 100) == 0) {
421 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
422 exit(EXIT_FAILURE);
423 }
424 totalRows += 100;
425 }
426 currentRows++;
427 if (SDDS_SetRowValuesMod(&SDDS_output, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, outrow, 0, &timeData[row], -1) == 0) {
428 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
429 exit(EXIT_FAILURE);
430 }
431 for (i = 0; i < ColumnNames; i++) {
432 if (SDDS_SetRowValuesMod(&SDDS_output, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, outrow, i + 1, &rowdata[i], -1) == 0) {
433 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
434 exit(EXIT_FAILURE);
435 }
436 }
437 if (snapshot)
438 break;
439 outrow++;
440 }
441 }
442 if (timeData)
443 free(timeData);
444 if (valueData)
445 free(valueData);
446 if (controlNameIndexData)
447 free(controlNameIndexData);
448 }
449 if (rowdata)
450 free(rowdata);
451 if (origToNewIndex)
452 free(origToNewIndex);
453
454 if (ColumnName) {
455 for (i = 0; i < ColumnNames; i++) {
456 if (ColumnName[i])
457 free(ColumnName[i]);
458 }
459 free(ColumnName);
460 }
461
462 SDDS_FreeArray(readbackNameArray);
463 if (SDDS_WriteTable(&SDDS_output) == 0) {
464 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
465 exit(EXIT_FAILURE);
466 }
467
468 if (!SDDS_Terminate(&SDDS_input) || !SDDS_Terminate(&SDDS_output)) {
469 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
470 exit(EXIT_FAILURE);
471 }
472
473 if (tmpfile_used && !replaceFileAndBackUp(input, output))
474 exit(EXIT_FAILURE);
475
476 free_scanargs(&s_arg, argc);
477 return EXIT_SUCCESS;
478}
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.
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.
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.
#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_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181
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.

◆ process_name_options()

char ** process_name_options ( char ** orig_name,
long orig_names,
char ** delete,
long deletes,
char ** retain,
long retains,
long * num_matched,
long ** origToNewIndex )

Definition at line 632 of file sddsconvertlogonchange.c.

632 {
633 long i, j;
634 char **new_name;
635 char *ptr = NULL;
636 long *orig_flag = NULL;
637
638 orig_flag = tmalloc(sizeof(*orig_flag) * orig_names);
639 for (i = 0; i < orig_names; i++)
640 orig_flag[i] = 1;
641
642 if (deletes) {
643 for (i = 0; i < deletes; i++) {
644 ptr = expand_ranges(delete[i]);
645 /* free(delete[i]); */ /* freed by free_scanargs */
646 delete[i] = ptr;
647 }
648 for (j = 0; j < orig_names; j++) {
649 for (i = 0; i < deletes; i++) {
650 if (wild_match(orig_name[j], delete[i])) {
651 orig_flag[j] = 0;
652 break;
653 }
654 }
655 }
656 for (i = 0; i < deletes; i++) {
657 if (delete[i])
658 free(delete[i]);
659 }
660 }
661
662 if (retains) {
663 for (i = 0; i < retains; i++) {
664 ptr = expand_ranges(retain[i]);
665 /* free(retain[i]); */ /* freed by free_scanargs */
666 retain[i] = ptr;
667 }
668 if (!deletes)
669 for (j = 0; j < orig_names; j++)
670 orig_flag[j] = 0;
671 for (j = 0; j < orig_names; j++) {
672 if (orig_flag[j])
673 continue;
674 for (i = 0; i < retains; i++) {
675 if (wild_match(orig_name[j], retain[i])) {
676 orig_flag[j] = 1;
677 break;
678 }
679 }
680 }
681 for (i = 0; i < retains; i++) {
682 if (retain[i])
683 free(retain[i]);
684 }
685 }
686
687 *num_matched = 0;
688 for (j = 0; j < orig_names; j++) {
689 if (orig_flag[j])
690 (*num_matched)++;
691 }
692 new_name = tmalloc(sizeof(*new_name) * (*num_matched));
693 i = 0;
694 for (j = 0; j < orig_names; j++) {
695 if (orig_flag[j]) {
696 (*origToNewIndex)[j] = i;
697 SDDS_CopyString(new_name + i, orig_name[j]);
698 i++;
699 }
700 }
701 free(orig_flag);
702
703 return (new_name);
704}
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
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
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

◆ SDDS_SetRowValuesMod()

long SDDS_SetRowValuesMod ( SDDS_DATASET * SDDS_dataset,
long mode,
int64_t row,
... )

Definition at line 480 of file sddsconvertlogonchange.c.

480 {
481 va_list argptr;
482 int32_t index;
483 long retval;
484 SDDS_LAYOUT *layout;
485 char *name;
486 char buffer[200];
487
488 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowValues"))
489 return (0);
490 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) ||
491 !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
492 SDDS_SetError("Unable to set column values--unknown mode (SDDS_SetRowValues)");
493 return (0);
494 }
495 /*
496 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_SetRowValues"))
497 return(0);
498 */
499 row -= SDDS_dataset->first_row_in_mem;
500 if (row >= SDDS_dataset->n_rows_allocated) {
501 sprintf(buffer, "Unable to set column values--row number (%" PRId64 ") exceeds allocated memory (%" PRId64 ") (SDDS_SetRowValues)", row, SDDS_dataset->n_rows_allocated);
502 SDDS_SetError(buffer);
503 return (0);
504 }
505 if (row > SDDS_dataset->n_rows - 1)
506 SDDS_dataset->n_rows = row + 1;
507
508 va_start(argptr, row);
509 layout = &SDDS_dataset->layout;
510
511 /* Variable arguments are pairs of (index, value), where index is a long integer */
512 retval = -1;
513#ifdef DEBUG
514 fprintf(stderr, "setting row %" PRId64 " (mem slot %" PRId64 ")\n", row + SDDS_dataset->first_row_in_mem, row);
515#endif
516 do {
517 if (mode & SDDS_SET_BY_INDEX) {
518 if ((index = va_arg(argptr, int32_t)) == -1) {
519 retval = 1;
520 break;
521 }
522 if (index < 0 || index >= layout->n_columns) {
523 SDDS_SetError("Unable to set column values--index out of range (SDDS_SetRowValues)");
524 retval = 0;
525 break;
526 }
527#ifdef DEBUG
528 fprintf(stderr, "Setting values for column #%ld\n", index);
529#endif
530 } else {
531 if ((name = va_arg(argptr, char *)) == NULL) {
532 retval = 1;
533 break;
534 }
535#ifdef DEBUG
536 fprintf(stderr, "Setting values for column %s\n", name);
537#endif
538 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0) {
539 SDDS_SetError("Unable to set column values--name not recognized (SDDS_SetRowValues)");
540 retval = 0;
541 break;
542 }
543 }
544 switch (layout->column_definition[index].type) {
545 case SDDS_SHORT:
546 if (mode & SDDS_PASS_BY_VALUE)
547 *(((short *)SDDS_dataset->data[index]) + row) = (short)va_arg(argptr, int);
548 else
549 *(((short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, short *));
550 break;
551 case SDDS_USHORT:
552 if (mode & SDDS_PASS_BY_VALUE)
553 *(((unsigned short *)SDDS_dataset->data[index]) + row) = (unsigned short)va_arg(argptr, unsigned int);
554 else
555 *(((unsigned short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, unsigned short *));
556 break;
557 case SDDS_LONG:
558 if (mode & SDDS_PASS_BY_VALUE)
559 *(((int32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int32_t);
560 else
561 *(((int32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int32_t *));
562 break;
563 case SDDS_ULONG:
564 if (mode & SDDS_PASS_BY_VALUE)
565 *(((uint32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint32_t);
566 else
567 *(((uint32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint32_t *));
568 break;
569 case SDDS_LONG64:
570 if (mode & SDDS_PASS_BY_VALUE)
571 *(((int64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int64_t);
572 else
573 *(((int64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int64_t *));
574 break;
575 case SDDS_ULONG64:
576 if (mode & SDDS_PASS_BY_VALUE)
577 *(((uint64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint64_t);
578 else
579 *(((uint64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint64_t *));
580 break;
581 case SDDS_FLOAT:
582 if (mode & SDDS_PASS_BY_VALUE)
583 *(((float *)SDDS_dataset->data[index]) + row) = (float)va_arg(argptr, double);
584 else
585 *(((float *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, double *));
586 break;
587 case SDDS_DOUBLE:
588 if (mode & SDDS_PASS_BY_VALUE)
589 *(((double *)SDDS_dataset->data[index]) + row) = va_arg(argptr, double);
590 else
591 *(((double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, double *));
592 break;
593 case SDDS_LONGDOUBLE:
594 if (mode & SDDS_PASS_BY_VALUE)
595 *(((long double *)SDDS_dataset->data[index]) + row) = va_arg(argptr, long double);
596 else
597 *(((long double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, long double *));
598 break;
599 case SDDS_STRING:
600 if (((char **)SDDS_dataset->data[index])[row]) {
601 free(((char **)SDDS_dataset->data[index])[row]);
602 ((char **)SDDS_dataset->data[index])[row] = NULL;
603 }
604 if (mode & SDDS_PASS_BY_VALUE) {
605 if (!SDDS_CopyString((char **)SDDS_dataset->data[index] + row, va_arg(argptr, char *))) {
606 SDDS_SetError("Unable to set string column value--allocation failure (SDDS_SetRowValues)");
607 retval = 0;
608 }
609 } else {
610 if (!SDDS_CopyString((char **)SDDS_dataset->data[index] + row, *(va_arg(argptr, char **)))) {
611 SDDS_SetError("Unable to set string column value--allocation failure (SDDS_SetRowValues)");
612 retval = 0;
613 }
614 }
615 break;
616 case SDDS_CHARACTER:
617 if (mode & SDDS_PASS_BY_VALUE)
618 *(((char *)SDDS_dataset->data[index]) + row) = (char)va_arg(argptr, int);
619 else
620 *(((char *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, char *));
621 break;
622 default:
623 SDDS_SetError("Unknown data type encountered (SDDS_SetRowValues)");
624 retval = 0;
625 break;
626 }
627 } while (retval == -1);
628 va_end(argptr);
629 return (retval);
630}
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_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
Definition SDDStypes.h:67
#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_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

Variable Documentation

◆ option

char* option[N_OPTIONS]
Initial value:
= {
"binary", "ascii", "float", "double", "snapshot", "pipe",
"minimuminterval", "time", "delete", "retain"}

Definition at line 67 of file sddsconvertlogonchange.c.

67 {
68 "binary", "ascii", "float", "double", "snapshot", "pipe",
69 "minimuminterval", "time", "delete", "retain"};

◆ USAGE

char* USAGE
Initial value:
=
"Usage: sddsconvertlogonchange [<input-file>] [<output-file>]\n"
" [-pipe=[input][,output]]\n"
" [-binary | -ascii]\n"
" [-double | -float]\n"
" [-minimumInterval=<seconds>]\n"
" [-snapshot=<epochtime>]\n"
" [-time=[start=<epochtime>][,end=<epochtime>]]\n"
" [-delete=<matching-string>[,...]]\n"
" [-retain=<matching-string>[,...]]\n\n"
"Program by Robert Soliday. (Compiled on " __DATE__ " at " __TIME__ ", SVN revision: " SVN_VERSION ")\n"

Definition at line 71 of file sddsconvertlogonchange.c.