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

Combines multiple SDDS files into a single SDDS file with options for merging, appending, and modifying data. More...

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

Go to the source code of this file.

Macros

#define COLUMN_MODE   0
 
#define PARAMETER_MODE   1
 
#define ARRAY_MODE   2
 
#define MODES   3
 
#define SPARSE_AVERAGE   0
 
#define SPARSE_MEDIAN   1
 
#define SPARSE_MINIMUM   2
 
#define SPARSE_MAXIMUM   3
 
#define SPARSE_MODES   4
 
#define ROW_INCREMENT   100
 

Enumerations

enum  option_type {
  SET_MERGE , SET_OVERWRITE , SET_PIPE , SET_DELETE ,
  SET_RETAIN , SET_SPARSE , SET_COLLAPSE , SET_RECOVER ,
  SET_MAJOR_ORDER , SET_APPEND , N_OPTIONS
}
 

Functions

long SDDS_CompareParameterValues (void *param1, void *param2, long type)
 
long keep_element (char *name, char **delete, long deletions, char **retain, long retentions)
 
void * SDDS_GetParameterMod (SDDS_DATASET *SDDS_dataset, SDDS_DATASET *SDDS_output, char *parameter_name, void *memory)
 
int main (int argc, char **argv)
 

Variables

static char * option [N_OPTIONS]
 
char * USAGE
 
char * mode_name [MODES]
 
char * sparse_mode [SPARSE_MODES]
 

Detailed Description

Combines multiple SDDS files into a single SDDS file with options for merging, appending, and modifying data.

Description

sddscombine is a utility that merges data from a series of SDDS (Self Describing Data Sets) files into a single SDDS file. Each page from the input files is added as a separate page in the output file. The tool provides various options to control how the data is combined, including merging pages based on parameters, appending data, deleting or retaining specific columns, parameters, or arrays, and handling sparse data with statistical analysis.

Usage

sddscombine [<SDDSinputfilelist>] [<SDDSoutputfile>]
[-pipe=[input][,output]]
[-delete={column|parameter|array},<matching-string>[,...]]
[-retain={column|parameter|array},<matching-string>[,...]]
[-sparse=<integer>][,{average|median|minimum|maximum}]
[-merge[={<parameter-name>,<npages>}]]
[-append]
[-overWrite]
[-collapse]
[-recover[=clip]]
[-majorOrder=row|column]
License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday, H. Shang

Definition in file sddscombine.c.

Macro Definition Documentation

◆ ARRAY_MODE

#define ARRAY_MODE   2

Definition at line 113 of file sddscombine.c.

◆ COLUMN_MODE

#define COLUMN_MODE   0

Definition at line 111 of file sddscombine.c.

◆ MODES

#define MODES   3

Definition at line 114 of file sddscombine.c.

◆ PARAMETER_MODE

#define PARAMETER_MODE   1

Definition at line 112 of file sddscombine.c.

◆ ROW_INCREMENT

#define ROW_INCREMENT   100

Definition at line 133 of file sddscombine.c.

◆ SPARSE_AVERAGE

#define SPARSE_AVERAGE   0

Definition at line 121 of file sddscombine.c.

◆ SPARSE_MAXIMUM

#define SPARSE_MAXIMUM   3

Definition at line 124 of file sddscombine.c.

◆ SPARSE_MEDIAN

#define SPARSE_MEDIAN   1

Definition at line 122 of file sddscombine.c.

◆ SPARSE_MINIMUM

#define SPARSE_MINIMUM   2

Definition at line 123 of file sddscombine.c.

◆ SPARSE_MODES

#define SPARSE_MODES   4

Definition at line 125 of file sddscombine.c.

Enumeration Type Documentation

◆ option_type

enum option_type

Definition at line 42 of file sddscombine.c.

42 {
43 SET_MERGE,
44 SET_OVERWRITE,
45 SET_PIPE,
46 SET_DELETE,
47 SET_RETAIN,
48 SET_SPARSE,
49 SET_COLLAPSE,
50 SET_RECOVER,
51 SET_MAJOR_ORDER,
52 SET_APPEND,
53 N_OPTIONS
54};

Function Documentation

◆ keep_element()

long keep_element ( char * name,
char ** delete,
long deletions,
char ** retain,
long retentions )

Definition at line 893 of file sddscombine.c.

893 {
894 long i, flag;
895
896 flag = 1;
897
898 if (deletions) {
899 for (i = 0; i < deletions; i++) {
900 if (wild_match(name, delete[i])) {
901 flag = 0;
902 break;
903 }
904 }
905 }
906
907 if (retentions) {
908 if (!deletions)
909 flag = 0;
910 for (i = 0; i < retentions; i++) {
911 if (wild_match(name, retain[i])) {
912 flag = 1;
913 break;
914 }
915 }
916 }
917
918 return flag;
919}
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
Definition wild_match.c:49

◆ main()

int main ( int argc,
char ** argv )

Definition at line 135 of file sddscombine.c.

135 {
136 SDDS_DATASET SDDS_input, SDDS_output;
137 char **inputfile, *outputfile;
138 long inputfiles, i, i_arg, retval = 0, first_page;
139 long iFile, first_data, sparse, setPageNumber;
140 int32_t sparse_statistics = 0;
141 long merge, nMerge, overwrite, collapse, page, append;
142 int64_t allocated_rows;
143 int32_t columns;
144 SCANNED_ARG *s_arg;
145 long buffer[16];
146 char *param, *last_param, *this_param, *text, *contents, **column;
147 long param_index, param_type, param_size, output_pending;
148 unsigned long pipeFlags, majorOrderFlag;
149
150 char **retain_column, **delete_column;
151 long retain_columns, delete_columns;
152 char **retain_parameter, **delete_parameter;
153 long retain_parameters, delete_parameters;
154 char **retain_array, **delete_array;
155 long retain_arrays, delete_arrays;
156 long nColumns, recover, recovered;
157 short columnMajorOrder = -1;
158
160 argc = scanargs(&s_arg, argc, argv);
161 if (argc < 3)
162 bomb(NULL, USAGE);
163
164 setPageNumber = allocated_rows = param_type = param_size = 0;
165 last_param = this_param = NULL;
166 column = NULL;
167 inputfile = NULL;
168 outputfile = param = NULL;
169 inputfiles = merge = overwrite = collapse = append = nMerge = 0;
170 pipeFlags = 0;
171 sparse = 1;
172 recover = 0;
173
174 retain_column = delete_column = NULL;
175 retain_columns = delete_columns = 0;
176 retain_parameter = delete_parameter = NULL;
177 retain_parameters = delete_parameters = 0;
178 retain_array = delete_array = NULL;
179 retain_arrays = delete_arrays = 0;
180
182 argc = scanargs(&s_arg, argc, argv);
183 if (argc < 3)
184 bomb(NULL, USAGE);
185
186 for (i_arg = 1; i_arg < argc; i_arg++) {
187 if (s_arg[i_arg].arg_type == OPTION) {
188 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
189 case SET_MAJOR_ORDER:
190 majorOrderFlag = 0;
191 s_arg[i_arg].n_items -= 1;
192 if (s_arg[i_arg].n_items > 0 &&
193 (!scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
194 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
195 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
196 SDDS_Bomb("invalid -majorOrder syntax/values");
197 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
198 columnMajorOrder = 1;
199 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
200 columnMajorOrder = 0;
201 break;
202 case SET_MERGE:
203 if (s_arg[i_arg].n_items > 2)
204 bomb("invalid -merge syntax", USAGE);
205 merge = 1;
206 param = NULL;
207 nMerge = -1;
208 if (s_arg[i_arg].n_items == 2) {
209 if (isdigit(s_arg[i_arg].list[1][0])) {
210 if (!sscanf(s_arg[i_arg].list[1], "%ld", &nMerge))
211 bomb("invalid -merge syntax (could not scan number of pages)", USAGE);
212 } else
213 param = s_arg[i_arg].list[1];
214 }
215 break;
216 case SET_APPEND:
217 if (s_arg[i_arg].n_items > 1)
218 bomb("invalid -append syntax", USAGE);
219 append = 1;
220 if (collapse) {
221 SDDS_Bomb("-collapse and -append options cannot be used together");
222 break;
223 }
224 break;
225 case SET_OVERWRITE:
226 overwrite = 1;
227 break;
228 case SET_PIPE:
229 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
230 SDDS_Bomb("invalid -pipe syntax");
231 break;
232 case SET_RECOVER:
233 recover = 1;
234 if (s_arg[i_arg].n_items != 1) {
235 recover = 2;
236 if (s_arg[i_arg].n_items > 2 || strncmp(s_arg[i_arg].list[1], "clip", strlen(s_arg[i_arg].list[1])) != 0)
237 SDDS_Bomb("invalid -recover syntax");
238 }
239 break;
240 case SET_DELETE:
241 if (s_arg[i_arg].n_items < 3)
242 SDDS_Bomb("invalid -delete syntax");
243 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
244 case COLUMN_MODE:
245 delete_column = trealloc(delete_column, sizeof(*delete_column) * (delete_columns + s_arg[i_arg].n_items - 2));
246 for (i = 2; i < s_arg[i_arg].n_items; i++)
247 delete_column[i - 2 + delete_columns] = expand_ranges(s_arg[i_arg].list[i]);
248 delete_columns += s_arg[i_arg].n_items - 2;
249 break;
250 case PARAMETER_MODE:
251 delete_parameter = trealloc(delete_parameter, sizeof(*delete_parameter) * (delete_parameters + s_arg[i_arg].n_items - 2));
252 for (i = 2; i < s_arg[i_arg].n_items; i++)
253 delete_parameter[i - 2 + delete_parameters] = expand_ranges(s_arg[i_arg].list[i]);
254 delete_parameters += s_arg[i_arg].n_items - 2;
255 break;
256 case ARRAY_MODE:
257 delete_array = trealloc(delete_array, sizeof(*delete_array) * (delete_arrays + s_arg[i_arg].n_items - 2));
258 for (i = 2; i < s_arg[i_arg].n_items; i++)
259 delete_array[i - 2 + delete_arrays] = expand_ranges(s_arg[i_arg].list[i]);
260 delete_arrays += s_arg[i_arg].n_items - 2;
261 break;
262 default:
263 SDDS_Bomb("invalid -delete syntax: specify column or parameter keyword");
264 break;
265 }
266 break;
267 case SET_RETAIN:
268 if (s_arg[i_arg].n_items < 3)
269 SDDS_Bomb("invalid -retain syntax");
270 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
271 case COLUMN_MODE:
272 retain_column = trealloc(retain_column, sizeof(*retain_column) * (retain_columns + s_arg[i_arg].n_items - 2));
273 for (i = 2; i < s_arg[i_arg].n_items; i++)
274 retain_column[i - 2 + retain_columns] = expand_ranges(s_arg[i_arg].list[i]);
275 retain_columns += s_arg[i_arg].n_items - 2;
276 break;
277 case PARAMETER_MODE:
278 retain_parameter = trealloc(retain_parameter, sizeof(*retain_parameter) * (retain_parameters + s_arg[i_arg].n_items - 2));
279 for (i = 2; i < s_arg[i_arg].n_items; i++)
280 retain_parameter[i - 2 + retain_parameters] = expand_ranges(s_arg[i_arg].list[i]);
281 retain_parameters += s_arg[i_arg].n_items - 2;
282 break;
283 case ARRAY_MODE:
284 retain_array = trealloc(retain_array, sizeof(*retain_array) * (retain_arrays + s_arg[i_arg].n_items - 2));
285 for (i = 2; i < s_arg[i_arg].n_items; i++)
286 retain_array[i - 2 + retain_arrays] = expand_ranges(s_arg[i_arg].list[i]);
287 retain_arrays += s_arg[i_arg].n_items - 2;
288 break;
289 default:
290 SDDS_Bomb("invalid -retain syntax: specify column or parameter keyword");
291 break;
292 }
293 break;
294 case SET_SPARSE:
295 if ((s_arg[i_arg].n_items >= 2) && (s_arg[i_arg].n_items <= 3)) {
296 if (sscanf(s_arg[i_arg].list[1], "%ld", &sparse) != 1) {
297 bomb("invalid -sparse syntax", USAGE);
298 }
299 if (sparse <= 0) {
300 bomb("invalid -sparse syntax", USAGE);
301 }
302 if (s_arg[i_arg].n_items == 3) {
303 switch (match_string(s_arg[i_arg].list[2], sparse_mode, SPARSE_MODES, 0)) {
304 case SPARSE_AVERAGE:
305 sparse_statistics = 1;
306 break;
307 case SPARSE_MEDIAN:
308 sparse_statistics = 2;
309 break;
310 case SPARSE_MINIMUM:
311 sparse_statistics = 3;
312 break;
313 case SPARSE_MAXIMUM:
314 sparse_statistics = 4;
315 break;
316 default:
317 SDDS_Bomb("invalid -sparse syntax");
318 break;
319 }
320 }
321 } else {
322 bomb("invalid -sparse syntax", USAGE);
323 }
324 break;
325 case SET_COLLAPSE:
326 collapse = 1;
327 if (append) {
328 SDDS_Bomb("-collapse and -append options cannot be used together");
329 break;
330 }
331 break;
332 default:
333 bomb("unrecognized option", USAGE);
334 break;
335 }
336 } else {
337 inputfile = trealloc(inputfile, sizeof(*inputfile) * (inputfiles + 1));
338 inputfile[inputfiles++] = s_arg[i_arg].list[0];
339 }
340 }
341
342 outputfile = NULL;
343 if (inputfiles > 1) {
344 if (pipeFlags & USE_STDIN)
345 SDDS_Bomb("too many input files with -pipe option");
346 if (!(pipeFlags & USE_STDOUT)) {
347 if (!append) {
348 outputfile = inputfile[--inputfiles];
349 if (fexists(outputfile) && !overwrite)
350 SDDS_Bomb("output file exists already--give -overWrite option to force replacement");
351 }
352 }
353 } else if (inputfiles == 1) {
354 if (pipeFlags & USE_STDIN) {
355 outputfile = inputfile[0];
356 inputfile[0] = NULL;
357 }
358 if (pipeFlags & USE_STDOUT && outputfile)
359 SDDS_Bomb("too many filenames given with -pipe=output");
360 } else {
361 if (!(pipeFlags & USE_STDIN) || !(pipeFlags & USE_STDOUT))
362 SDDS_Bomb("too few filenames given");
363 inputfiles = 1;
364 inputfile = tmalloc(sizeof(*inputfile) * 1);
365 inputfile[0] = outputfile = NULL;
366 }
367
368 for (i = 0; i < inputfiles; i++)
369 if (inputfile[i] && outputfile && strcmp(inputfile[i], outputfile) == 0)
370 SDDS_Bomb("Output file is also an input file.");
371
372 if (append) {
373 if (merge) {
374 int64_t rowsPresent;
375 if (!SDDS_InitializeAppendToPage(&SDDS_output, inputfile[0], 100, &rowsPresent))
376 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
377 } else {
378 if (!SDDS_InitializeAppend(&SDDS_output, inputfile[0]))
379 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
380 }
381 iFile = 1;
382 } else {
383 if (!SDDS_InitializeInput(&SDDS_input, inputfile[0]) ||
384 !SDDS_GetDescription(&SDDS_input, &text, &contents) ||
385 !SDDS_InitializeOutput(&SDDS_output, SDDS_BINARY, 0, text, contents, outputfile))
386 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
387 if (columnMajorOrder != -1)
388 SDDS_output.layout.data_mode.column_major = columnMajorOrder;
389 else
390 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
391 iFile = 0;
392 }
393
394 for (; iFile < inputfiles; iFile++) {
395 char **name;
396 int32_t names;
397 if (iFile && !SDDS_InitializeInput(&SDDS_input, inputfile[iFile]))
398 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
399 if (!collapse) {
400 if (!(name = SDDS_GetColumnNames(&SDDS_input, &names)))
401 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
402 for (i = 0; i < names; i++) {
403 if (append) {
404 // We need all files to have the same columns for appending
405 if (keep_element(name[i], delete_column, delete_columns, retain_column, retain_columns) &&
406 (SDDS_GetColumnIndex(&SDDS_output, name[i]) < 0)) {
407 fprintf(stderr, "Error (sddscombine): Problem appending data. Column %s does not exist in first page.\n", name[i]);
408 exit(EXIT_FAILURE);
409 }
410 } else {
411 if (keep_element(name[i], delete_column, delete_columns, retain_column, retain_columns) &&
412 (SDDS_GetColumnIndex(&SDDS_output, name[i]) < 0 &&
413 !SDDS_TransferColumnDefinition(&SDDS_output, &SDDS_input, name[i], name[i])))
414 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
415 }
416 free(name[i]);
417 }
418 free(name);
419 }
420
421 if (!(name = SDDS_GetParameterNames(&SDDS_input, &names)))
422 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
423 for (i = 0; i < names; i++) {
424 if (collapse) {
425 if (keep_element(name[i], delete_parameter, delete_parameters, retain_parameter, retain_parameters) &&
426 (SDDS_GetColumnIndex(&SDDS_output, name[i]) < 0 &&
427 !SDDS_DefineColumnLikeParameter(&SDDS_output, &SDDS_input, name[i], name[i])))
428 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
429 } else {
430 if (append) {
431 if (keep_element(name[i], delete_parameter, delete_parameters, retain_parameter, retain_parameters) &&
432 (SDDS_GetParameterIndex(&SDDS_output, name[i]) < 0)) {
433 fprintf(stderr, "Error (sddscombine): Problem appending data. Parameter %s does not exist in first page.\n", name[i]);
434 exit(EXIT_FAILURE);
435 }
436 } else {
437 if (keep_element(name[i], delete_parameter, delete_parameters, retain_parameter, retain_parameters) &&
438 (SDDS_GetParameterIndex(&SDDS_output, name[i]) < 0 &&
439 !SDDS_TransferParameterDefinition(&SDDS_output, &SDDS_input, name[i], name[i])))
440 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
441 }
442 }
443 free(name[i]);
444 }
445 free(name);
446
447 if (!collapse) {
448 if (!(name = SDDS_GetArrayNames(&SDDS_input, &names)))
449 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
450 for (i = 0; i < names; i++) {
451 if (append) {
452 if (keep_element(name[i], delete_array, delete_arrays, retain_array, retain_arrays) &&
453 (SDDS_GetArrayIndex(&SDDS_output, name[i]) < 0)) {
454 fprintf(stderr, "Error (sddscombine): Problem appending data. Array %s does not exist in first page.\n", name[i]);
455 exit(EXIT_FAILURE);
456 }
457 } else {
458 if (keep_element(name[i], delete_array, delete_arrays, retain_array, retain_arrays) &&
459 (SDDS_GetArrayIndex(&SDDS_output, name[i]) < 0 &&
460 !SDDS_TransferArrayDefinition(&SDDS_output, &SDDS_input, name[i], name[i])))
461 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
462 }
463 free(name[i]);
464 }
465 free(name);
466 }
467 if (inputfiles > 1 && !SDDS_Terminate(&SDDS_input))
468 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
469 }
470
471 if (collapse) {
472 if (!(column = SDDS_GetColumnNames(&SDDS_output, &columns))) {
473 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
474 exit(EXIT_FAILURE);
475 }
476 }
477
478 if (collapse) {
479 if (!merge) {
480 if (SDDS_GetColumnIndex(&SDDS_output, "Filename") < 0 &&
481 SDDS_DefineColumn(&SDDS_output, "Filename", NULL, NULL, "Name of file from which this page came", NULL, SDDS_STRING, 0) < 0)
482 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
483 }
484 if (SDDS_GetColumnIndex(&SDDS_output, "NumberCombined") < 0 &&
485 SDDS_DefineColumn(&SDDS_output, "NumberCombined", NULL, NULL, "Number of files combined to make this file", NULL, SDDS_LONG, 0) < 0)
486 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
487 } else {
488 if (!append) {
489 if (!SDDS_DeleteParameterFixedValues(&SDDS_output)) {
490 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
491 exit(EXIT_FAILURE);
492 }
493 if (!merge) {
494 if (SDDS_GetParameterIndex(&SDDS_output, "Filename") < 0 &&
495 SDDS_DefineParameter(&SDDS_output, "Filename", NULL, NULL, "Name of file from which this page came", NULL, SDDS_STRING, NULL) < 0)
496 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
497 }
498 if (SDDS_GetParameterIndex(&SDDS_output, "NumberCombined") < 0 &&
499 SDDS_DefineParameter(&SDDS_output, "NumberCombined", NULL, NULL, "Number of files combined to make this file", NULL, SDDS_LONG, NULL) < 0)
500 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
501 }
502 }
503
504 if (collapse) {
505 if (SDDS_GetColumnIndex(&SDDS_output, "PageNumber") < 0) {
506 if (SDDS_DefineColumn(&SDDS_output, "PageNumber", NULL, NULL, NULL, NULL, SDDS_LONG, 0) < 0) {
507 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
508 exit(EXIT_FAILURE);
509 }
510 setPageNumber = 1;
511 } else {
512 setPageNumber = 0;
513 }
514 }
515 if (!append) {
516 if (!SDDS_WriteLayout(&SDDS_output)) {
517 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
518 exit(EXIT_FAILURE);
519 }
520 }
521 if (collapse) {
522 if (!SDDS_StartPage(&SDDS_output, allocated_rows = ROW_INCREMENT)) {
523 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
524 exit(EXIT_FAILURE);
525 }
526 }
527 nColumns = SDDS_ColumnCount(&SDDS_output);
528 if (append) {
529 iFile = 1;
530 first_data = 0;
531 output_pending = 1;
532 } else {
533 iFile = 0;
534 first_data = 1; /* indicates no pages copied so far */
535 output_pending = 0;
536 }
537
538 page = 0;
539 for (; iFile < inputfiles; iFile++) {
540 if (inputfiles > 1 && !SDDS_InitializeInput(&SDDS_input, inputfile[iFile])) {
541 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
542 exit(EXIT_FAILURE);
543 }
544 first_page = 1;
545 recovered = 0;
546 while (!recovered && (retval = SDDS_ReadPageSparse(&SDDS_input, 0, nColumns ? sparse : INT64_MAX - 1, 0, sparse_statistics)) >= 0) {
547 page++;
548 if (retval == 0) {
549 if (!recover)
550 break;
551 recovered = 1;
552 if (recover == 2 || !SDDS_ReadRecoveryPossible(&SDDS_input))
553 /* user doesn't want this page, or it can't be recovered */
554 break;
555 }
556 if (param) {
557 if (first_page) {
558 if ((param_index = SDDS_GetParameterIndex(&SDDS_input, param)) < 0)
559 SDDS_Bomb("-merge parameter not in input file(s)");
560 if (param_type) {
561 if (param_type != SDDS_GetParameterType(&SDDS_input, param_index))
562 SDDS_Bomb("-merge parameter changes type in subsequent files");
563 } else {
564 param_size = SDDS_GetTypeSize(param_type = SDDS_GetParameterType(&SDDS_input, param_index));
565 this_param = tmalloc(param_size);
566 last_param = tmalloc(param_size);
567 if (!SDDS_GetParameter(&SDDS_input, param, last_param))
568 SDDS_Bomb("error getting value for -merge parameter");
569 }
570 } else {
571 memcpy(last_param, this_param, param_size);
572 }
573 if (!SDDS_GetParameter(&SDDS_input, param, this_param))
574 SDDS_Bomb("error getting value for -merge parameter");
575 }
576#ifdef DEBUG
577 if (param) {
578 fprintf(stderr, "parameter %s = ", param);
579 SDDS_PrintTypedValue(this_param, 0, param_type, NULL, stderr, 0);
580 fprintf(stderr, " now (was ");
581 SDDS_PrintTypedValue(last_param, 0, param_type, NULL, stderr, 0);
582 fprintf(stderr, ")\n");
583 }
584#endif
585 if (collapse) {
586 if (merge && param) {
587 if (SDDS_CompareParameterValues(this_param, last_param, param_type) != 0 && output_pending) {
588 output_pending = 0;
589 }
590 }
591 if (!merge || (!param && first_data && first_page) || (param && !output_pending)) {
592 if (page > allocated_rows) {
593 if (!SDDS_LengthenTable(&SDDS_output, ROW_INCREMENT)) {
594 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
595 exit(EXIT_FAILURE);
596 }
597 allocated_rows += ROW_INCREMENT;
598 }
599 for (i = 0; i < columns; i++) {
600 if (!SDDS_GetParameterMod(&SDDS_input, &SDDS_output, column[i], buffer)) {
601 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
602 exit(EXIT_FAILURE);
603 }
604 if (!SDDS_SetRowValues(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_REFERENCE, page - 1, column[i], buffer, NULL)) {
605 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
606 exit(EXIT_FAILURE);
607 }
608 }
609 if (!merge) {
610 if (!SDDS_SetRowValues(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, page - 1, "Filename", inputfile[iFile] ? inputfile[iFile] : "stdin", "NumberCombined", inputfiles, NULL)) {
611 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
612 exit(EXIT_FAILURE);
613 }
614 } else {
615 if (!SDDS_SetRowValues(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, page - 1, "NumberCombined", inputfiles, NULL)) {
616 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
617 exit(EXIT_FAILURE);
618 }
619 }
620 if (setPageNumber && !SDDS_SetRowValues(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, page - 1, "PageNumber", page, NULL)) {
621 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
622 exit(EXIT_FAILURE);
623 }
624 first_data = 0;
625 } else if (merge && param && output_pending) {
626 page--;
627 }
628 } else {
629 if (!merge) {
630 if (!SDDS_ClearPage(&SDDS_output) ||
631 !SDDS_CopyPage(&SDDS_output, &SDDS_input)) {
632 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
633 exit(EXIT_FAILURE);
634 }
635 if (SDDS_GetParameterIndex(&SDDS_output, "Filename") >= 0) {
636 if (!SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, "Filename", inputfile[iFile] ? inputfile[iFile] : "stdin", NULL)) {
637 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
638 exit(EXIT_FAILURE);
639 }
640 }
641 if (SDDS_GetParameterIndex(&SDDS_output, "NumberCombined") >= 0) {
642 if (!SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, "NumberCombined", inputfiles, NULL)) {
643 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
644 exit(EXIT_FAILURE);
645 }
646 }
647 if (!SDDS_WritePage(&SDDS_output)) {
648 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
649 exit(EXIT_FAILURE);
650 }
651 } else if (merge && !param) {
652 if (nMerge > 0 && (page - 1) % nMerge == 0 && page != 1) {
653 if (!SDDS_WritePage(&SDDS_output)) {
654 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
655 exit(EXIT_FAILURE);
656 }
657 output_pending = 0;
658 }
659 if ((first_data && first_page) || (nMerge > 0 && (page - 1) % nMerge == 0)) {
660 if (!SDDS_CopyPage(&SDDS_output, &SDDS_input)) {
661 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
662 exit(EXIT_FAILURE);
663 }
664 first_data = 0;
665 } else {
666 if (!SDDS_CopyAdditionalRows(&SDDS_output, &SDDS_input)) {
667 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
668 exit(EXIT_FAILURE);
669 }
670 }
671 } else {
672#ifdef DEBUG
673 if (SDDS_CompareParameterValues(this_param, last_param, param_type) != 0)
674 fprintf(stderr, "Parameter value has changed\n");
675#endif
676 if (SDDS_CompareParameterValues(this_param, last_param, param_type) != 0 && output_pending) {
677 if (SDDS_GetParameterIndex(&SDDS_output, "NumberCombined") >= 0) {
678 if (!SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, "NumberCombined", inputfiles, NULL)) {
679 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
680 exit(EXIT_FAILURE);
681 }
682 }
683 if (!SDDS_WritePage(&SDDS_output)) {
684 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
685 exit(EXIT_FAILURE);
686 }
687 output_pending = 0;
688 }
689 if (!output_pending) {
690 if (!SDDS_CopyPage(&SDDS_output, &SDDS_input)) {
691 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
692 exit(EXIT_FAILURE);
693 }
694 } else {
695 if (!SDDS_CopyAdditionalRows(&SDDS_output, &SDDS_input)) {
696 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
697 exit(EXIT_FAILURE);
698 }
699 }
700 }
701 }
702 if (merge) {
703 output_pending = 1;
704 }
705 first_page = 0;
706 }
707 if (!recovered && (retval == 0 || SDDS_NumberOfErrors() || !SDDS_Terminate(&SDDS_input))) {
708 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
709 exit(EXIT_FAILURE);
710 }
711 }
712 if (!collapse && merge && output_pending) {
713 if (SDDS_GetParameterIndex(&SDDS_output, "NumberCombined") >= 0) {
714 if (!SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, "NumberCombined", inputfiles, NULL)) {
715 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
716 exit(EXIT_FAILURE);
717 }
718 }
719 if (append) {
720 if (!SDDS_UpdatePage(&SDDS_output, FLUSH_TABLE)) {
721 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
722 exit(EXIT_FAILURE);
723 }
724 } else {
725 if (!SDDS_WritePage(&SDDS_output)) {
726 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
727 exit(EXIT_FAILURE);
728 }
729 }
730 }
731 if (collapse) {
732 if (!SDDS_WritePage(&SDDS_output)) {
733 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
734 exit(EXIT_FAILURE);
735 }
736 if (page == 0) {
737 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
738 exit(EXIT_FAILURE);
739 }
740 }
741 if (!SDDS_Terminate(&SDDS_output)) {
742 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
743 exit(EXIT_FAILURE);
744 }
745
746 return EXIT_SUCCESS;
747}
int32_t SDDS_ReadRecoveryPossible(SDDS_DATASET *SDDS_dataset)
Checks if any data in an SDDS page was recovered after an error was detected.
int32_t SDDS_CopyAdditionalRows(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:519
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:578
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_ClearPage(SDDS_DATASET *SDDS_dataset)
void * SDDS_GetParameter(SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
Retrieves the value of a specified parameter from the current data table of a data set.
int32_t SDDS_GetDescription(SDDS_DATASET *SDDS_dataset, char **text, char **contents)
Retrieves the text and contents descriptions from an SDDS dataset.
int32_t SDDS_ReadPageSparse(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
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_InitializeAppend(SDDS_DATASET *SDDS_dataset, const char *filename)
Initializes the SDDS dataset for appending data by adding a new page to an existing file.
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_InitializeAppendToPage(SDDS_DATASET *SDDS_dataset, const char *filename, int64_t updateInterval, int64_t *rowsPresentReturn)
Initializes the SDDS dataset for appending data to the last page of an existing file.
int32_t SDDS_UpdatePage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the current page of the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
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_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_TransferArrayDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers an array definition from a source dataset to a target dataset.
int32_t SDDS_DefineColumnLikeParameter(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Defines a column in the target dataset based on a parameter definition from the source dataset.
int32_t SDDS_TransferParameterDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a parameter definition from a source dataset to a target dataset.
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS 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_ColumnCount(SDDS_DATASET *page)
Retrieves the number of columns in the SDDS dataset.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
Definition SDDS_utils.c:432
int32_t SDDS_DeleteParameterFixedValues(SDDS_DATASET *SDDS_dataset)
Deletes fixed values from all parameters in the SDDS dataset.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
int32_t SDDS_NumberOfErrors()
Retrieves the number of errors recorded by SDDS library routines.
Definition SDDS_utils.c:304
int32_t SDDS_GetTypeSize(int32_t type)
Retrieves the size in bytes of a specified SDDS data type.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
char ** SDDS_GetArrayNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all arrays in the SDDS dataset.
int32_t SDDS_PrintTypedValue(void *data, int64_t index, int32_t type, char *format, FILE *fp, uint32_t mode)
Prints a data value of a specified type using an optional printf format string.
Definition SDDS_utils.c:59
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
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
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
Definition bomb.c:26
long fexists(const char *filename)
Checks if a file exists.
Definition fexists.c:27
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
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

◆ SDDS_CompareParameterValues()

long SDDS_CompareParameterValues ( void * param1,
void * param2,
long type )

Definition at line 851 of file sddscombine.c.

851 {
852 double ddiff;
853 int64_t ldiff;
854 char cdiff;
855
856 switch (type) {
857 case SDDS_FLOAT:
858 ddiff = *((float *)param1) - *((float *)param2);
859 return ddiff < 0 ? -1 : ddiff > 0 ? 1 : 0;
860 case SDDS_DOUBLE:
861 ddiff = *((double *)param1) - *((double *)param2);
862 return ddiff < 0 ? -1 : ddiff > 0 ? 1 : 0;
863 case SDDS_LONG64:
864 ldiff = *((int64_t *)param1) - *((int64_t *)param2);
865 return ldiff < 0 ? -1 : ldiff > 0 ? 1 : 0;
866 case SDDS_ULONG64:
867 ldiff = *((uint64_t *)param1) - *((uint64_t *)param2);
868 return ldiff < 0 ? -1 : ldiff > 0 ? 1 : 0;
869 case SDDS_LONG:
870 ldiff = *((int32_t *)param1) - *((int32_t *)param2);
871 return ldiff < 0 ? -1 : ldiff > 0 ? 1 : 0;
872 case SDDS_ULONG:
873 ldiff = *((uint32_t *)param1) - *((uint32_t *)param2);
874 return ldiff < 0 ? -1 : ldiff > 0 ? 1 : 0;
875 case SDDS_SHORT:
876 ldiff = *((short *)param1) - *((short *)param2);
877 return ldiff < 0 ? -1 : ldiff > 0 ? 1 : 0;
878 case SDDS_USHORT:
879 ldiff = *((unsigned short *)param1) - *((unsigned short *)param2);
880 return ldiff < 0 ? -1 : ldiff > 0 ? 1 : 0;
881 case SDDS_CHARACTER:
882 cdiff = (short)*((char *)param1) - (short)*((char *)param2);
883 return cdiff < 0 ? -1 : cdiff > 0 ? 1 : 0;
884 case SDDS_STRING:
885 return strcmp(*(char **)param1, *(char **)param2);
886 default:
887 SDDS_SetError("Problem doing data comparison--invalid data type (SDDS_CompareParameterValues)");
888 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
889 exit(EXIT_FAILURE);
890 }
891}
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
#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_ULONG64
Identifier for the unsigned 64-bit integer data type.
Definition SDDStypes.h:55
#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_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49

◆ SDDS_GetParameterMod()

void * SDDS_GetParameterMod ( SDDS_DATASET * SDDS_dataset,
SDDS_DATASET * SDDS_output,
char * parameter_name,
void * memory )

Definition at line 749 of file sddscombine.c.

749 {
750 long index, type, size;
751 void *data;
752 float floatdata;
753 double doubledata;
754 uint64_t ulong64data;
755 int64_t long64data;
756 uint32_t ulongdata;
757 int32_t longdata;
758 unsigned short ushortdata;
759 short shortdata;
760 char chardata;
761 char *stringdata;
762 floatdata = 0.0;
763 doubledata = 0.0;
764 ulong64data = 0;
765 long64data = 0;
766 ulongdata = 0;
767 longdata = 0;
768 ushortdata = 0;
769 shortdata = 0;
770 chardata = '\000';
771 stringdata = "";
772
773 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterMod"))
774 return (NULL);
775 if (!parameter_name) {
776 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameterMod)");
777 return (NULL);
778 }
779 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
780 if ((index = SDDS_GetColumnIndex(SDDS_output, parameter_name)) < 0) {
781 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetParameterMod)");
782 return (NULL);
783 }
784 if (!(type = SDDS_GetColumnType(SDDS_output, index))) {
785 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterMod)");
786 return (NULL);
787 }
788 size = SDDS_type_size[type - 1];
789 if (memory)
790 data = memory;
791 else if (!(data = SDDS_Malloc(size))) {
792 SDDS_SetError("Unable to get parameter value--parameter data size is invalid (SDDS_GetParameterMod)");
793 return (NULL);
794 }
795 switch (type) {
796 case SDDS_FLOAT:
797 data = memcpy(data, &floatdata, size);
798 break;
799 case SDDS_DOUBLE:
800 data = memcpy(data, &doubledata, size);
801 break;
802 case SDDS_ULONG64:
803 data = memcpy(data, &ulong64data, size);
804 break;
805 case SDDS_LONG64:
806 data = memcpy(data, &long64data, size);
807 break;
808 case SDDS_ULONG:
809 data = memcpy(data, &ulongdata, size);
810 break;
811 case SDDS_LONG:
812 data = memcpy(data, &longdata, size);
813 break;
814 case SDDS_USHORT:
815 data = memcpy(data, &ushortdata, size);
816 break;
817 case SDDS_SHORT:
818 data = memcpy(data, &shortdata, size);
819 break;
820 case SDDS_CHARACTER:
821 data = memcpy(data, &chardata, size);
822 break;
823 case SDDS_STRING:
824 if (!SDDS_CopyString((char **)data, stringdata))
825 break;
826 }
827 } else {
828 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
829 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterMod)");
830 return (NULL);
831 }
832 if (!SDDS_dataset->parameter || !SDDS_dataset->parameter[index]) {
833 SDDS_SetError("Unable to get parameter value--parameter data array is NULL (SDDS_GetParameterMod)");
834 return (NULL);
835 }
836 size = SDDS_type_size[type - 1];
837 if (memory)
838 data = memory;
839 else if (!(data = SDDS_Malloc(size))) {
840 SDDS_SetError("Unable to get parameter value--parameter data size is invalid (SDDS_GetParameterMod)");
841 return (NULL);
842 }
843 if (type != SDDS_STRING)
844 memcpy(data, SDDS_dataset->parameter[index], size);
845 else if (!SDDS_CopyString((char **)data, *(char **)SDDS_dataset->parameter[index]))
846 return (NULL);
847 }
848 return (data);
849}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
Definition SDDS_utils.c:639
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.
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

Variable Documentation

◆ mode_name

char* mode_name[MODES]
Initial value:
= {
"column",
"parameter",
"array",
}

Definition at line 115 of file sddscombine.c.

115 {
116 "column",
117 "parameter",
118 "array",
119};

◆ option

char* option[N_OPTIONS]
static
Initial value:
= {
"merge",
"overwrite",
"pipe",
"delete",
"retain",
"sparse",
"collapse",
"recover",
"majorOrder",
"append"
}

Definition at line 56 of file sddscombine.c.

56 {
57 "merge",
58 "overwrite",
59 "pipe",
60 "delete",
61 "retain",
62 "sparse",
63 "collapse",
64 "recover",
65 "majorOrder",
66 "append"
67};

◆ sparse_mode

char* sparse_mode[SPARSE_MODES]
Initial value:
= {
"average",
"median",
"minimum",
"maximum"
}

Definition at line 126 of file sddscombine.c.

126 {
127 "average",
128 "median",
129 "minimum",
130 "maximum"
131};

◆ USAGE

char* USAGE

Definition at line 69 of file sddscombine.c.