175 {
178 REFDATA *new_data, rename_data, *take_RefData, *replace_RefData;
179 long j, i_arg, reuse, reusePage, endWarning, k;
180 int64_t i, i1, i2, i3, rows1, rows2, rows2Max;
181 SCANNED_ARG *s_arg;
182 char s[200], *ptr;
183
184 char **take_column, **leave_column, **replace_column, **replace_parameter, **replace_array, **output_column = NULL;
185 char **inputfile, **referfile;
186 char **match_column, **equate_column;
187 long take_columns, replace_columns, leave_columns, match_columns, equate_columns, leave_all_columns, replace_parameters, replace_arrays;
188 int32_t output_columns = 0;
189 char *input1, *input2, *output;
190 long tmpfile_used, retval1, retval2, inputfiles, referfiles;
191 long wildMatch;
193 long transfers;
194 long warnings;
196 unsigned long pipeFlags, majorOrderFlag;
197 long fillIn, keyGroups = 0;
198 KEYED_EQUIVALENT **keyGroup = NULL;
199 long outputInitialized;
200 int z, it, itm, datatype1, datatype2;
201 long col;
202 int firstRun, copyInput1Only;
203 char **string1, **string2;
204 double *value1, *value2;
205 long matched;
206 short columnMajorOrder = -1;
207
208 EDIT_NAME_REQUEST *edit_column_request, *edit_parameter_request, *edit_array_request;
209 long edit_column_requests, edit_parameter_requests, edit_array_requests;
210
212 argc =
scanargs(&s_arg, argc, argv);
213 if (argc < 3) {
214 fprintf(stderr, "%s", USAGE);
215 exit(EXIT_FAILURE);
216 }
217
218 SDDS_ref = NULL;
219 take_RefData = replace_RefData = NULL;
220 new_data = NULL;
221
222 rename_data.columns = rename_data.parameters = rename_data.arrays = 0;
223 rename_data.new_column = rename_data.orig_column = rename_data.new_parameter = rename_data.orig_parameter = rename_data.new_array = rename_data.orig_array = NULL;
224 edit_column_request = edit_parameter_request = edit_array_request = NULL;
225 edit_column_requests = edit_parameter_requests = edit_array_requests = 0;
226
227 input1 = input2 = output = NULL;
228 take_column = leave_column = replace_column = replace_parameter = replace_array = NULL;
229 match_column = equate_column = NULL;
230 inputfile = referfile = NULL;
231 take_columns = leave_columns = replace_columns = match_columns = equate_columns = reuse = reusePage = replace_parameters = replace_arrays = 0;
232 tmpfile_used = inputfiles = referfiles = 0;
233 transfer = NULL;
234 transfers = 0;
235 ifnot_item.items = ifis_item.items = 0;
236 warnings = 1;
237 pipeFlags = 0;
238 fillIn = 0;
239 outputInitialized = 0;
240 rows1 = rows2 = output_columns = 0;
241 string1 = string2 = NULL;
242 wildMatch = 0;
243
244 for (i_arg = 1; i_arg < argc; i_arg++) {
245 if (s_arg[i_arg].arg_type == OPTION) {
247 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
248 case SET_MAJOR_ORDER:
249 majorOrderFlag = 0;
250 s_arg[i_arg].n_items--;
251 if (s_arg[i_arg].n_items > 0 &&
252 (!
scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
253 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
254 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
255 SDDS_Bomb(
"invalid -majorOrder syntax/values");
256 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
257 columnMajorOrder = 1;
258 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
259 columnMajorOrder = 0;
260 break;
261 case SET_LEAVE_COLUMNS:
262 if (s_arg[i_arg].n_items < 2)
264 leave_column =
trealloc(leave_column,
sizeof(*leave_column) * (leave_columns + s_arg[i_arg].n_items - 1));
265 for (i = 1; i < s_arg[i_arg].n_items; i++)
266 leave_column[i - 1 + leave_columns] = s_arg[i_arg].list[i];
267 leave_columns += s_arg[i_arg].n_items - 1;
268 break;
269 case SET_TAKE_COLUMNS:
270 if (s_arg[i_arg].n_items < 2)
272 take_column =
trealloc(take_column,
sizeof(*take_column) * (take_columns + s_arg[i_arg].n_items - 1));
273 for (i = 1; i < s_arg[i_arg].n_items; i++)
274 take_column[i - 1 + take_columns] = s_arg[i_arg].list[i];
275 take_columns += s_arg[i_arg].n_items - 1;
276 break;
277 case SET_WILD_MATCH:
278 wildMatch = 1;
279
280 case SET_MATCH_COLUMN:
281 if (s_arg[i_arg].n_items != 2)
282 SDDS_Bomb(
"invalid -match or -wildMatch syntax");
283 if (match_columns != 0)
284 SDDS_Bomb(
"only one -match or -wildMatch option may be given");
285 match_column =
tmalloc(
sizeof(*match_column) * 2);
286 if ((ptr = strchr(s_arg[i_arg].list[1], '=')))
287 *ptr++ = 0;
288 else
289 ptr = s_arg[i_arg].list[1];
290 match_column[0] = s_arg[i_arg].list[1];
291 match_column[1] = ptr;
292 match_columns = 1;
293 break;
294 case SET_EQUATE_COLUMN:
295 if (s_arg[i_arg].n_items != 2)
297 if (equate_columns != 0)
298 SDDS_Bomb(
"only one -equate option may be given");
299 equate_column =
tmalloc(
sizeof(*equate_column) * 2);
300 if ((ptr = strchr(s_arg[i_arg].list[1], '=')))
301 *ptr++ = 0;
302 else
303 ptr = s_arg[i_arg].list[1];
304 equate_column[0] = s_arg[i_arg].list[1];
305 equate_column[1] = ptr;
306 equate_columns = 1;
307 break;
308 case SET_REPLACE:
309 if (s_arg[i_arg].n_items < 3)
311 switch (
match_string(s_arg[i_arg].list[1], replace_type, REPLACE_TYPES, 0)) {
312 case COLUMN_REPLACE:
313 replace_column =
trealloc(replace_column,
sizeof(*replace_column) * (replace_columns + s_arg[i_arg].n_items - 2));
314 for (i = 2; i < s_arg[i_arg].n_items; i++)
315 replace_column[i - 2 + replace_columns] = s_arg[i_arg].list[i];
316 replace_columns += s_arg[i_arg].n_items - 2;
317 break;
318 case PARAMETER_REPLACE:
319 replace_parameter =
trealloc(replace_parameter,
sizeof(*replace_parameter) * (replace_parameters + s_arg[i_arg].n_items - 2));
320 for (i = 2; i < s_arg[i_arg].n_items; i++)
321 replace_parameter[i - 2 + replace_parameters] = s_arg[i_arg].list[i];
322 replace_parameters += s_arg[i_arg].n_items - 2;
323 break;
324 case ARRAY_REPLACE:
325 replace_array =
trealloc(replace_array,
sizeof(*replace_array) * (replace_arrays + s_arg[i_arg].n_items - 2));
326 for (i = 2; i < s_arg[i_arg].n_items; i++)
327 replace_array[i - 2 + replace_arrays] = s_arg[i_arg].list[i];
328 replace_arrays += s_arg[i_arg].n_items - 2;
329 break;
330 default:
332 break;
333 }
334 break;
335 case SET_TRANSFER:
336 if (s_arg[i_arg].n_items < 3)
338 transfer =
trealloc(transfer,
sizeof(*transfer) * (transfers + s_arg[i_arg].n_items - 2));
339 switch (
match_string(s_arg[i_arg].list[1], transfer_type, TRANSFER_TYPES, 0)) {
340 case PARAMETER_TRANSFER:
341 for (i = 2; i < s_arg[i_arg].n_items; i++) {
342 transfer[i - 2 + transfers].type = PARAMETER_TRANSFER;
343 transfer[i - 2 + transfers].name = s_arg[i_arg].list[i];
344 }
345 break;
346 case ARRAY_TRANSFER:
347 for (i = 2; i < s_arg[i_arg].n_items; i++) {
348 transfer[i - 2 + transfers].type = ARRAY_TRANSFER;
349 transfer[i - 2 + transfers].name = s_arg[i_arg].list[i];
350 }
351 break;
352 default:
354 break;
355 }
356 transfers += s_arg[i_arg].n_items - 2;
357 break;
358 case SET_REUSE:
359 if (s_arg[i_arg].n_items == 1)
360 reuse = 1;
361 else {
362 char *reuseOptions[2] = {"rows", "page"};
363 for (i = 1; i < s_arg[i_arg].n_items; i++) {
364 switch (
match_string(s_arg[i_arg].list[i], reuseOptions, 2, 0)) {
365 case 0:
366 reuse = 1;
367 break;
368 case 1:
369 reusePage = 1;
370 break;
371 default:
373 break;
374 }
375 }
376 }
377 break;
378 case SET_IFNOT:
379 if (s_arg[i_arg].n_items < 3)
381 add_ifitem(&ifnot_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
382 break;
383 case SET_NOWARNINGS:
384 warnings = 0;
385 break;
386 case SET_IFIS:
387 if (s_arg[i_arg].n_items < 3)
389 add_ifitem(&ifis_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
390 break;
391 case SET_PIPE:
392 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
394 break;
395 case SET_FILLIN:
396 fillIn = 1;
397 break;
398 case SET_RENAME:
399 if (s_arg[i_arg].n_items < 3)
401 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
402 case COLUMN_MODE:
403 k = rename_data.columns;
404 rename_data.new_column =
trealloc(rename_data.new_column,
sizeof(
char *) * (k + s_arg[i_arg].n_items - 2));
405 rename_data.orig_column =
trealloc(rename_data.orig_column,
sizeof(
char *) * (k + s_arg[i_arg].n_items - 2));
406 for (i = 2; i < s_arg[i_arg].n_items; i++) {
407 if (!(ptr = strchr(s_arg[i_arg].list[i], '=')))
409 *ptr++ = 0;
410 rename_data.orig_column[k + i - 2] = s_arg[i_arg].list[i];
411 rename_data.new_column[k + i - 2] = ptr;
412 }
413 rename_data.columns += s_arg[i_arg].n_items - 2;
414 break;
415 case PARAMETER_MODE:
416 k = rename_data.parameters;
417 rename_data.new_parameter =
trealloc(rename_data.new_parameter,
sizeof(
char *) * (k + s_arg[i_arg].n_items - 2));
418 rename_data.orig_parameter =
trealloc(rename_data.orig_parameter,
sizeof(
char *) * (k + s_arg[i_arg].n_items - 2));
419 for (i = 2; i < s_arg[i_arg].n_items; i++) {
420 if (!(ptr = strchr(s_arg[i_arg].list[i], '=')))
422 *ptr++ = 0;
423 rename_data.orig_parameter[k + i - 2] = s_arg[i_arg].list[i];
424 rename_data.new_parameter[k + i - 2] = ptr;
425 }
426 rename_data.parameters += s_arg[i_arg].n_items - 2;
427 break;
428 case ARRAY_MODE:
429 k = rename_data.arrays;
430 rename_data.new_array =
trealloc(rename_data.new_array,
sizeof(
char *) * (k + s_arg[i_arg].n_items - 2));
431 rename_data.orig_array =
trealloc(rename_data.orig_array,
sizeof(
char *) * (k + s_arg[i_arg].n_items - 2));
432 for (i = 2; i < s_arg[i_arg].n_items; i++) {
433 if (!(ptr = strchr(s_arg[i_arg].list[i], '=')))
435 *ptr++ = 0;
436 rename_data.orig_array[k + i - 2] = s_arg[i_arg].list[i];
437 rename_data.new_array[k + i - 2] = ptr;
438 }
439 rename_data.arrays += s_arg[i_arg].n_items - 2;
440 break;
441 default:
442 SDDS_Bomb(
"invalid -rename syntax: specify column, parameter, or array keyword");
443 break;
444 }
445 break;
446 case SET_EDIT_NAMES:
447 if (s_arg[i_arg].n_items != 4)
449 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
450 case COLUMN_MODE:
451 edit_column_request =
trealloc(edit_column_request,
sizeof(*edit_column_request) * (edit_column_requests + 1));
452 edit_column_request[edit_column_requests].match_string = s_arg[i_arg].list[2];
453 edit_column_request[edit_column_requests].edit_string = s_arg[i_arg].list[3];
454 edit_column_requests++;
455 break;
456 case PARAMETER_MODE:
457 edit_parameter_request =
trealloc(edit_parameter_request,
sizeof(*edit_parameter_request) * (edit_parameter_requests + 1));
458 edit_parameter_request[edit_parameter_requests].match_string = s_arg[i_arg].list[2];
459 edit_parameter_request[edit_parameter_requests].edit_string = s_arg[i_arg].list[3];
460 edit_parameter_requests++;
461 break;
462 case ARRAY_MODE:
463 edit_array_request =
trealloc(edit_array_request,
sizeof(*edit_array_request) * (edit_array_requests + 1));
464 edit_array_request[edit_array_requests].match_string = s_arg[i_arg].list[2];
465 edit_array_request[edit_array_requests].edit_string = s_arg[i_arg].list[3];
466 edit_array_requests++;
467 break;
468 default:
469 SDDS_Bomb(
"invalid -editnames syntax: specify column, parameter, or array keyword");
470 break;
471 }
472 break;
473 default:
474 fprintf(stderr, "error: unknown switch: %s\n", s_arg[i_arg].list[0]);
476 break;
477 }
478 } else {
479 inputfile =
trealloc(inputfile,
sizeof(*inputfile) * (inputfiles + 1));
480 inputfile[inputfiles++] = s_arg[i_arg].list[0];
481 }
482 }
483
484 if (inputfiles == 0) {
485 SDDS_Bomb(
"too few reference files given");
486 } else {
487 if (!(pipeFlags & USE_STDIN) && !(pipeFlags & USE_STDOUT)) {
488 if (inputfiles < 2) {
489 SDDS_Bomb(
"too few reference files given");
490 } else if (inputfiles == 2) {
491 input1 = output = inputfile[0];
492 referfile =
trealloc(referfile,
sizeof(*referfile) * (referfiles + 1));
493 referfile[0] = inputfile[1];
494 referfiles++;
495 } else {
496 input1 = inputfile[0];
497 output = inputfile[--inputfiles];
498 for (z = 1; z < inputfiles; z++) {
499 referfile =
trealloc(referfile,
sizeof(*referfile) * (referfiles + 1));
500 referfile[z - 1] = inputfile[z];
501 referfiles++;
502 }
503 }
504 } else if (!(pipeFlags & USE_STDIN) && (pipeFlags & USE_STDOUT)) {
505 if (inputfiles < 2) {
506 SDDS_Bomb(
"too few reference files given");
507 } else {
508 input1 = inputfile[0];
509 for (z = 1; z < inputfiles; z++) {
510 referfile =
trealloc(referfile,
sizeof(*referfile) * (referfiles + 1));
511 referfile[z - 1] = inputfile[z];
512 referfiles++;
513 }
514 }
515 } else if ((pipeFlags & USE_STDIN) && !(pipeFlags & USE_STDOUT)) {
516 if (inputfiles < 2) {
517 SDDS_Bomb(
"too few reference files given");
518 } else {
519 output = inputfile[--inputfiles];
520 for (z = 0; z < inputfiles; z++) {
521 referfile =
trealloc(referfile,
sizeof(*referfile) * (referfiles + 1));
522 referfile[z] = inputfile[z];
523 referfiles++;
524 }
525 }
526 } else {
527 for (z = 0; z < inputfiles; z++) {
528 referfile =
trealloc(referfile,
sizeof(*referfile) * (referfiles + 1));
529 referfile[z] = inputfile[z];
530 referfiles++;
531 }
532 }
533 }
534
535 processFilenames(
"sddsxref", &input1, &output, pipeFlags, !warnings, &tmpfile_used);
536
537 if (equate_columns && match_columns)
538 SDDS_Bomb(
"only one of -equate or -match may be given");
539
542 exit(EXIT_FAILURE);
543 }
544
545 if (!check_ifitems(&SDDS_1, &ifnot_item, 0, warnings) || !check_ifitems(&SDDS_1, &ifis_item, 1, warnings))
546 exit(EXIT_SUCCESS);
547
548 for (it = 0; it < ifnot_item.items; it++) {
549 switch (ifnot_item.type[it]) {
550 case COLUMN_BASED:
551 leave_column =
trealloc(leave_column,
sizeof(*leave_column) * (leave_columns + 1));
552 leave_column[leave_columns] = ifnot_item.name[it];
553 leave_columns++;
554 break;
555 case PARAMETER_BASED:
556 for (itm = 0; itm < transfers; itm++) {
557 if (strcmp(transfer[itm].name, ifnot_item.name[it]) == 0) {
558 SDDS_Bomb(
"Excluded item is a part of -transfer list.");
559 exit(EXIT_FAILURE);
560 }
561 }
562 break;
563 case ARRAY_BASED:
564 for (itm = 0; itm < transfers; itm++) {
565 if (strcmp(transfer[itm].name, ifnot_item.name[it]) == 0) {
566 SDDS_Bomb(
"Excluded item is a part of -transfer list.");
567 exit(EXIT_FAILURE);
568 }
569 }
570 break;
571 default:
572 SDDS_Bomb(
"internal error---unknown ifitem type");
573 exit(EXIT_FAILURE);
574 break;
575 }
576 }
577
578
579 new_data = malloc(sizeof(*new_data) * referfiles);
580 for (z = 0; z < referfiles; z++) {
581 SDDS_ref =
trealloc(SDDS_ref,
sizeof(*SDDS_ref) * (z + 1));
582 input2 = referfile[z];
585 exit(EXIT_FAILURE);
586 }
587
588 take_RefData =
trealloc(take_RefData,
sizeof(*take_RefData) * (z + 1));
589 take_RefData[z].columns = 0;
590 replace_RefData =
trealloc(replace_RefData,
sizeof(*replace_RefData) * (z + 1));
591 replace_RefData[z].columns = replace_RefData[z].parameters = replace_RefData[z].arrays = 0;
592
593 add_newnames(&SDDS_ref[z], &new_data[z], rename_data, edit_column_request, edit_column_requests,
594 edit_parameter_request, edit_parameter_requests, edit_array_request, edit_array_requests, z + 1);
595
598 if (take_columns) {
600 for (i = 0; i < take_columns; i++) {
602 sprintf(s, "error: column %s not found in file %s take_columns %ld SDDS_ref[z] %" PRId64 "\n", take_column[i], input2, take_columns, SDDS_ref[z].n_rows);
605 }
608 }
609 }
610
611 leave_all_columns = 0;
612 if (leave_columns == 1 && strcmp(leave_column[0], "*") == 0)
613 leave_all_columns = 1;
614 else {
615 if (!take_columns)
617 for (i = 0; i < leave_columns; i++) {
620 continue;
623 }
624
625 if (!(take_RefData[z].orig_column = (
char **)
SDDS_GetColumnNames(&SDDS_ref[z], &take_RefData[z].columns))) {
626 SDDS_SetError(
"error: no columns selected to take from input file");
628 }
629 }
630 if (replace_columns) {
632 for (i = 0; i < replace_columns; i++) {
634 sprintf(s, "error: column %s not found in file %s replace_columns %ld SDDS_ref[z] %" PRId64 "\n", replace_column[i], input2, replace_columns, SDDS_ref[z].n_rows);
637 }
640 }
641 if (!(replace_RefData[z].orig_column = (
char **)
SDDS_GetColumnNames(&SDDS_ref[z], &replace_RefData[z].columns))) {
642 SDDS_SetError(
"error: no columns selected to replace from input file");
644 }
645 }
646 if (match_columns) {
649 sprintf(s, "error: column %s not found or not string type in file %s", match_column[0], input1 ? input1 : "stdin");
652 }
655 sprintf(s, "error: column %s not found or not string type in file %s", match_column[1], input2);
658 }
659 }
660 if (equate_columns) {
663 sprintf(s, "error: column %s not found or not numeric type in file %s", equate_column[0], input1 ? input1 : "stdin");
666 }
669 sprintf(s, "error: column %s not found or not numeric type in file %s", equate_column[1], input2);
672 }
673 }
674 } else {
675 take_RefData[z].columns = 0;
676 leave_all_columns = 1;
677 }
678 if (!take_RefData[z].columns && !leave_all_columns && warnings)
679 fprintf(stderr, "warning: there are no columns being taken from %s that are not already in %s\n", input2, input1 ? input1 : "stdin");
680
681 if (leave_all_columns)
682 take_RefData[z].columns = 0;
683
684 if (!outputInitialized) {
687 exit(EXIT_FAILURE);
688 }
689 outputInitialized = 1;
690 if (columnMajorOrder != -1)
691 SDDS_output.layout.data_mode.column_major = columnMajorOrder;
692 else
693 SDDS_output.layout.data_mode.column_major = SDDS_1.layout.data_mode.column_major;
694 }
695
696
697 if (take_RefData[z].columns)
698 take_RefData[z].new_column = (char **)malloc(sizeof(char *) * take_RefData[z].columns);
699
700 for (i = 0; i < take_RefData[z].columns; i++) {
701 k = 0;
702
703
704 if (new_data[z].columns) {
705 k =
match_string(take_RefData[z].orig_column[i], new_data[z].orig_column, new_data[z].columns, EXACT_MATCH);
706 if (k == -1)
707 SDDS_CopyString(&take_RefData[z].new_column[i], take_RefData[z].orig_column[i]);
708 else
709 SDDS_CopyString(&take_RefData[z].new_column[i], new_data[z].new_column[k]);
710 } else
711 SDDS_CopyString(&take_RefData[z].new_column[i], take_RefData[z].orig_column[i]);
713 free(take_RefData[z].new_column[i]);
714 free(take_RefData[z].orig_column[i]);
715 for (j = i; j < take_RefData[z].columns - 1; j++)
716 take_RefData[z].orig_column[j] = take_RefData[z].orig_column[j + 1];
717 take_RefData[z].columns -= 1;
718 i--;
719 if (take_RefData[z].columns == 0)
720 break;
721 } else {
722
725 }
726 }
727
728 if (!take_RefData[z].columns && !leave_all_columns && warnings)
729 fprintf(stderr, "warning: there are no columns being taken from %s that are not already in %s\n", input2, input1 ? input1 : "stdin");
730 output_columns = 0;
731 if (take_RefData[z].columns &&
732 (!(output_column = (
char **)
SDDS_GetColumnNames(&SDDS_output, &output_columns)) || output_columns == 0)) {
735 }
736 if (output_columns) {
737 for (i = 0; i < output_columns; i++)
738 free(output_column[i]);
739 free(output_column);
740 }
741
742 for (i = 0; i < replace_RefData[z].columns; i++) {
744 if (warnings) {
745 fprintf(stderr, "Warning, %s replace column does not exist in the input1, ignore.\n", replace_RefData[z].orig_column[i]);
746 }
747 } else {
748
754 if (warnings) {
756 fprintf(stderr, "Warning: cannot replace a numeric column with a string column, replace %s ignored.\n", replace_RefData[z].orig_column[i]);
758 fprintf(stderr, "Warning: cannot replace a string column with a numeric column, replace %s ignored.\n", replace_RefData[z].orig_column[i]);
759 }
760 } else {
761 if (datatype1 != datatype2) {
762 if (warnings)
763 fprintf(stderr, "Warning, replace column %s has different data type as the column in input1; redefining the column type\n", replace_RefData[z].orig_column[i]);
765 fprintf(stderr, "Problem redefining column type for %s\n", replace_RefData[z].orig_column[i]);
766 exit(EXIT_FAILURE);
767 }
768 }
769
770 take_RefData[z].orig_column =
trealloc(take_RefData[z].orig_column,
sizeof(*(take_RefData[z].orig_column)) * (take_RefData[z].columns + 1));
771 take_RefData[z].new_column =
trealloc(take_RefData[z].new_column,
sizeof(*(take_RefData[z].new_column)) * (take_RefData[z].columns + 1));
772 SDDS_CopyString(&take_RefData[z].orig_column[take_RefData[z].columns], replace_RefData[z].orig_column[i]);
773 SDDS_CopyString(&take_RefData[z].new_column[take_RefData[z].columns], replace_RefData[z].orig_column[i]);
774 take_RefData[z].columns++;
775 }
776 }
777 free(replace_RefData[z].orig_column[i]);
778 }
779
780 take_RefData[z].parameters = take_RefData[z].arrays = 0;
781 if (transfers) {
782 if (!expandTransferRequests(&take_RefData[z].orig_parameter, &take_RefData[z].parameters, PARAMETER_TRANSFER, transfer, transfers, &SDDS_ref[z]) ||
783 !expandTransferRequests(&take_RefData[z].orig_array, &take_RefData[z].arrays, ARRAY_TRANSFER, transfer, transfers, &SDDS_ref[z]))
785 }
786
787
788 if (take_RefData[z].parameters)
789 take_RefData[z].new_parameter = (char **)malloc(sizeof(char *) * take_RefData[z].parameters);
790 if (take_RefData[z].arrays)
791 take_RefData[z].new_array = (char **)malloc(sizeof(char *) * take_RefData[z].arrays);
792
793 for (i = 0; i < take_RefData[z].parameters; i++) {
794 k = 0;
795 if (new_data[z].parameters) {
796 k =
match_string(take_RefData[z].orig_parameter[i], new_data[z].orig_parameter, new_data[z].parameters, EXACT_MATCH);
797 if (k != -1)
798 SDDS_CopyString(&take_RefData[z].new_parameter[i], new_data[z].new_parameter[k]);
799 else
800 SDDS_CopyString(&take_RefData[z].new_parameter[i], take_RefData[z].orig_parameter[i]);
801 } else
802 SDDS_CopyString(&take_RefData[z].new_parameter[i], take_RefData[z].orig_parameter[i]);
804 free(take_RefData[z].orig_parameter[i]);
805 free(take_RefData[z].new_parameter[i]);
806 for (col = i; col < take_RefData[z].parameters - 1; col++)
807 take_RefData[z].orig_parameter[col] = take_RefData[z].orig_parameter[col + 1];
808 take_RefData[z].parameters -= 1;
809 i--;
810 if (take_RefData[z].parameters == 0)
811 break;
812 } else {
815 }
816 }
817
818 for (i = 0; i < take_RefData[z].arrays; i++) {
819 k = 0;
820 if (new_data[z].arrays) {
821 k =
match_string(take_RefData[z].orig_array[i], new_data[z].orig_array, new_data[z].arrays, EXACT_MATCH);
822 if (k == -1)
823 SDDS_CopyString(&take_RefData[z].new_array[i], take_RefData[z].orig_array[i]);
824 else
825 SDDS_CopyString(&take_RefData[z].new_array[i], new_data[z].new_array[k]);
826 } else
827 SDDS_CopyString(&take_RefData[z].new_array[i], take_RefData[z].orig_array[i]);
829 free(take_RefData[z].orig_array[i]);
830 free(take_RefData[z].new_array[i]);
831 for (col = i; col < take_RefData[z].arrays - 1; col++)
832 take_RefData[z].orig_array[col] = take_RefData[z].orig_array[col + 1];
833 take_RefData[z].arrays -= 1;
834 i--;
835 if (take_RefData[z].arrays == 0)
836 break;
837 } else {
840 }
841 }
842
843
844 if (replace_parameters) {
845 for (i = 0; i < replace_parameters; i++) {
846 replace_RefData[z].parameters +=
SDDS_MatchParameters(&SDDS_ref[z], &replace_RefData[z].orig_parameter, SDDS_MATCH_STRING, FIND_ANY_TYPE, replace_parameter[i], SDDS_OR | SDDS_1_PREVIOUS);
847 }
848
849
850 for (i = 0; i < replace_RefData[z].parameters; i++) {
852 if (warnings) {
853 fprintf(stderr, "Warning, parameter %s replace parameter does not exist in the input1, ignore.\n", replace_RefData[z].orig_parameter[i]);
854 }
855 } else {
856
862 if (warnings) {
864 fprintf(stderr, "Warning: cannot replace a numeric parameter with a string parameter, replace %s ignored.\n", replace_RefData[z].orig_parameter[i]);
866 fprintf(stderr, "Warning: cannot replace a string parameter with a numeric parameter, replace %s ignored.\n", replace_RefData[z].orig_parameter[i]);
867 }
868 } else {
869 if (datatype1 != datatype2) {
870 if (warnings)
871 fprintf(stderr, "Warning, replace parameter %s type is different from input1, redefining parameter type.\n", replace_RefData[z].orig_parameter[i]);
872
874 fprintf(stderr, "Problem redefining parameter type for %s\n", replace_RefData[z].orig_parameter[i]);
875 exit(EXIT_FAILURE);
876 }
877 }
878
879 take_RefData[z].orig_parameter =
trealloc(take_RefData[z].orig_parameter,
sizeof(*(take_RefData[z].orig_parameter)) * (take_RefData[z].parameters + 1));
880 take_RefData[z].new_parameter =
trealloc(take_RefData[z].new_parameter,
sizeof(*(take_RefData[z].new_parameter)) * (take_RefData[z].parameters + 1));
881 SDDS_CopyString(&take_RefData[z].orig_parameter[take_RefData[z].parameters], replace_RefData[z].orig_parameter[i]);
882 SDDS_CopyString(&take_RefData[z].new_parameter[take_RefData[z].parameters], replace_RefData[z].orig_parameter[i]);
883 take_RefData[z].parameters++;
884 }
885 }
886 free(replace_RefData[z].orig_parameter[i]);
887 }
888
889 if (replace_arrays) {
890 for (i = 0; i < replace_arrays; i++) {
891 replace_RefData[z].arrays +=
SDDS_MatchArrays(&SDDS_ref[z], &replace_RefData[z].orig_array, SDDS_MATCH_STRING, FIND_ANY_TYPE, replace_array[i], SDDS_OR | SDDS_1_PREVIOUS);
892 }
893
894 for (i = 0; i < replace_RefData[z].arrays; i++) {
896 if (warnings) {
897 fprintf(stderr, "Warning, array %s replace array does not exist in the input, ignore.\n", replace_RefData[z].orig_array[i]);
898 }
899 } else {
900
906 if (warnings) {
908 fprintf(stderr, "Warning: cannot replace a numeric array with a string array, replace %s ignored.\n", replace_RefData[z].orig_array[i]);
910 fprintf(stderr, "Warning: cannot replace a string array with a numeric array, replace %s ignored.\n", replace_RefData[z].orig_array[i]);
911 }
912 } else {
913 if (datatype1 != datatype2) {
914 if (warnings)
915 fprintf(stderr, "Warning, replace array %s has different data type as the array in input1; redefining\n", replace_RefData[z].orig_array[i]);
917 fprintf(stderr, "Problem redefining array type for %s\n", replace_RefData[z].orig_array[i]);
918 exit(EXIT_FAILURE);
919 }
920 }
921
922 take_RefData[z].orig_array =
trealloc(take_RefData[z].orig_array,
sizeof(*(take_RefData[z].orig_array)) * (take_RefData[z].arrays + 1));
923 SDDS_CopyString(&take_RefData[z].orig_array[take_RefData[z].arrays], replace_RefData[z].orig_array[i]);
924 SDDS_CopyString(&take_RefData[z].new_array[take_RefData[z].arrays], replace_RefData[z].orig_array[i]);
925 take_RefData[z].arrays++;
926 }
927 }
928 free(replace_RefData[z].orig_array[i]);
929 }
930 }
931 }
932 }
933
936
937 free(leave_column);
938 if (take_columns) {
940 free(take_column);
941 }
942
943 endWarning = 0;
944
946 copyInput1Only = 0;
951 }
955 }
958 SDDS_SetError(
"Problem copying parameter or array data from first input file");
960 }
961
962 for (z = 0; z < referfiles; z++) {
963 input2 = referfile[z];
964 if (!reusePage) {
965 if ((retval2 =
SDDS_ReadPage(&SDDS_ref[z])) <= 0 && !endWarning) {
966 if (warnings)
967 fprintf(stderr, "warning: %s ends prematurely\n", input2 ? input2 : "stdin");
968 endWarning = 1;
969 }
970 } else {
971 if (retval1 == 1 && (retval2 =
SDDS_ReadPage(&SDDS_ref[z])) <= 0) {
972 if (!endWarning && warnings)
973 fprintf(stderr, "warning: %s has no data\n", input2 ? input2 : "stdin");
974 endWarning = 1;
975 } else
977 }
978
979 if (take_RefData[z].columns &&
983
984
985 if (!CopyParametersFromSecondInput(&SDDS_output, &SDDS_ref[z], take_RefData[z])) {
986 SDDS_SetError(
"Problem copying parameter from second input file");
988 }
989 if (!CopyArraysFromSecondInput(&SDDS_output, &SDDS_ref[z], take_RefData[z])) {
990 SDDS_SetError(
"Problem copying parameter from second input file");
992 }
993 }
994
995 firstRun = 1;
996 for (z = rows2Max = 0; z < referfiles; z++) {
997 input2 = referfile[z];
999 rows2Max = rows2 > rows2Max ? rows2 : rows2Max;
1000
1001 if (!firstRun) {
1002
1003
1004
1005 rows1 = SDDS_RowCount(&SDDS_output);
1006 }
1007 if (take_RefData[z].columns) {
1008 if (!rows2) {
1010 SDDS_SetError(
"Problem setting row flags for output file.");
1011 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1012 }
1013 } else if (rows1) {
1014 if (match_columns) {
1015 if (firstRun) {
1016 if (!(string1 = (
char **)
SDDS_GetColumn(&SDDS_1, match_column[0]))) {
1017 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1018 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1019 }
1020 } else {
1021 if (!(string1 = (
char **)
SDDS_GetColumn(&SDDS_output, match_column[0]))) {
1022 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1023 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1024 }
1025 }
1026 if (!(string2 = (
char **)
SDDS_GetColumn(&SDDS_ref[z], match_column[1]))) {
1027 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[1], input2);
1028 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1029 }
1030 if (!wildMatch)
1032 i3 = 0;
1033 for (i1 = 0; i1 < rows1; i1++) {
1034 if (firstRun) {
1036 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1038 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1039 }
1040 }
1041 matched = 0;
1042 if ((&SDDS_output)->row_flag[i1]) {
1043 if (!wildMatch) {
1045 matched = 1;
1046 } else {
1047 if ((i2 =
match_string(string1[i3], string2, rows2, WILDCARD_MATCH)) >= 0)
1048 matched = 1;
1049 }
1050 if (matched) {
1051 if (!CopyRowToNewColumn(&SDDS_output, i1, &SDDS_ref[z], i2, take_RefData[z], take_RefData[z].columns, input2)) {
1052 fprintf(stderr, "error in copying data to output!\n");
1053 exit(EXIT_FAILURE);
1054 }
1055 } else {
1057 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1058 if (warnings)
1059 fprintf(stderr, "warning: no match for row %" PRId64 " (%s = \"%s\")\n", i3, match_column[0], string1[i3]);
1060 }
1061 i3++;
1062 }
1063 }
1064 firstRun = 0;
1065 if (string1) {
1066 for (i = 0; i < i3; i++)
1067 free(string1[i]);
1068 free(string1);
1069 }
1070 if (string2) {
1071 for (i = 0; i < rows2; i++)
1072 free(string2[i]);
1073 free(string2);
1074 }
1075
1076 for (i = 0; i < keyGroups; i++) {
1077 free(keyGroup[i]->equivalent);
1078 free(keyGroup[i]);
1079 }
1080 free(keyGroup);
1081 } else if (equate_columns) {
1082 if (firstRun) {
1084 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1085 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1086 }
1087 } else {
1089 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1090 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1091 }
1092 }
1094 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[1], input2);
1095 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1096 }
1097
1098 i3 = 0;
1100 for (i1 = 0; i1 < rows1; i1++) {
1101 if (firstRun) {
1103 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1105 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1106 }
1107 }
1108 if ((&SDDS_output)->row_flag[i1]) {
1110 if (!CopyRowToNewColumn(&SDDS_output, i1, &SDDS_ref[z], i2, take_RefData[z], take_RefData[z].columns, input2)) {
1111 fprintf(stderr, "error in copying data to output!\n");
1112 exit(EXIT_FAILURE);
1113 }
1114 } else {
1116 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1117 if (warnings)
1118 fprintf(stderr, "warning: no equal for row %" PRId64 " (%s = %g)\n", i3, equate_column[0], value1[i3]);
1119 }
1120 i3++;
1121 }
1122 }
1123 firstRun = 0;
1124 if (i3 && equate_columns)
1125 free(value1);
1126 if (rows2 && equate_columns)
1127 free(value2);
1128 for (i = 0; i < keyGroups; i++) {
1129 free(keyGroup[i]->equivalent);
1130 free(keyGroup[i]);
1131 }
1132 free(keyGroup);
1133 } else {
1134 for (i1 = 0; i1 < rows1; i1++) {
1135 i2 = i1;
1136 if (i2 >= rows2) {
1137 if (!reuse) {
1138 if (fillIn) {
1140 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1142 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1143 }
1144 }
1145 if (warnings)
1146 fprintf(stderr, "warning: no row in file 2 for row %" PRId64 " in file 1\n", i1);
1147 continue;
1148 } else
1149 i2 = rows2 - 1;
1150 }
1151 if (firstRun) {
1153 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1155 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1156 }
1157 }
1158 if (take_RefData[z].columns &&
1159 !CopyRowToNewColumn(&SDDS_output, i1, &SDDS_ref[z], i2, take_RefData[z], take_RefData[z].columns, input2)) {
1160 fprintf(stderr, "error in copying data to output!\n");
1161 exit(EXIT_FAILURE);
1162 }
1163 }
1164 firstRun = 0;
1165 }
1166 }
1167 } else {
1168 if (rows2) {
1169 if (rows1) {
1170 if (match_columns) {
1171 if (firstRun) {
1172 if (!(string1 = (
char **)
SDDS_GetColumn(&SDDS_1, match_column[0]))) {
1173 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1174 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1175 }
1176 } else {
1177 if (!(string1 = (
char **)
SDDS_GetColumn(&SDDS_output, match_column[0]))) {
1178 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1179 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1180 }
1181 }
1182 if (!(string2 = (
char **)
SDDS_GetColumn(&SDDS_ref[z], match_column[1]))) {
1183 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[1], input2);
1184 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1185 }
1187 i3 = 0;
1188 for (i1 = 0; i1 < rows1; i1++) {
1189 if (firstRun) {
1191 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1193 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1194 }
1195 }
1196 if ((&SDDS_output)->row_flag[i1]) {
1199 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1200 if (warnings)
1201 fprintf(stderr, "warning: no match for row %" PRId64 " (%s = \"%s\")\n", i3, match_column[0], string1[i3]);
1202 }
1203 i3++;
1204 }
1205 }
1206 firstRun = 0;
1207 if (string1) {
1208 for (i = 0; i < i3; i++)
1209 free(string1[i]);
1210 free(string1);
1211 }
1212 if (string2) {
1213 for (i = 0; i < rows2; i++)
1214 free(string2[i]);
1215 free(string2);
1216 }
1217
1218 for (i = 0; i < keyGroups; i++) {
1219 free(keyGroup[i]->equivalent);
1220 free(keyGroup[i]);
1221 }
1222 free(keyGroup);
1223 } else if (equate_columns) {
1224 if (firstRun) {
1226 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1227 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1228 }
1229 } else {
1231 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1232 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1233 }
1234 }
1236 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[1], input2);
1237 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1238 }
1240 i3 = 0;
1241 for (i1 = 0; i1 < rows1; i1++) {
1242 if (firstRun) {
1244 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1246 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1247 }
1248 }
1249 if ((&SDDS_output)->row_flag[i1]) {
1252 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1253 if (warnings)
1254 fprintf(stderr, "warning: no equal for row %" PRId64 " (%s = %g)\n", i3, equate_column[0], value1[i3]);
1255 }
1256 i3++;
1257 }
1258 }
1259 firstRun = 0;
1260 if (i3 && equate_columns)
1261 free(value1);
1262 if (rows2 && equate_columns)
1263 free(value2);
1264 for (i = 0; i < keyGroups; i++) {
1265 free(keyGroup[i]->equivalent);
1266 free(keyGroup[i]);
1267 }
1268 free(keyGroup);
1269 }
1270 }
1271 }
1272 copyInput1Only++;
1273 }
1274 }
1275 if ((rows2Max == 0 && fillIn) || (copyInput1Only == referfiles && !match_columns && !equate_columns)) {
1277 SDDS_SetError(
"Problem copying tabular data for output file.");
1278 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1279 }
1280 }
1281
1284 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1285 }
1286 }
1287
1288 for (z = 0; z < referfiles; z++) {
1289 free(referfile[z]);
1290
1291 if (take_RefData[z].columns) {
1292 for (i = 0; i < take_RefData[z].columns; i++) {
1293 free(take_RefData[z].new_column[i]);
1294 free(take_RefData[z].orig_column[i]);
1295 }
1296 free(take_RefData[z].new_column);
1297 free(take_RefData[z].orig_column);
1298 }
1299
1300 if (take_RefData[z].parameters) {
1301 for (i = 0; i < take_RefData[z].parameters; i++) {
1302 free(take_RefData[z].new_parameter[i]);
1303 free(take_RefData[z].orig_parameter[i]);
1304 }
1305 free(take_RefData[z].new_parameter);
1306 free(take_RefData[z].orig_parameter);
1307 }
1308
1309 if (take_RefData[z].arrays) {
1310 for (i = 0; i < take_RefData[z].arrays; i++) {
1311 free(take_RefData[z].new_array[i]);
1312 free(take_RefData[z].orig_array[i]);
1313 }
1314 free(take_RefData[z].new_array);
1315 free(take_RefData[z].orig_array);
1316 }
1317
1318 if (new_data[z].columns) {
1319 for (i = 0; i < new_data[z].columns; i++) {
1320 free(new_data[z].new_column[i]);
1321 free(new_data[z].orig_column[i]);
1322 }
1323 free(new_data[z].new_column);
1324 free(new_data[z].orig_column);
1325 }
1326
1327 if (new_data[z].parameters) {
1328 for (i = 0; i < new_data[z].parameters; i++) {
1329 free(new_data[z].new_parameter[i]);
1330 free(new_data[z].orig_parameter[i]);
1331 }
1332 free(new_data[z].new_parameter);
1333 free(new_data[z].orig_parameter);
1334 }
1335 if (new_data[z].arrays) {
1336 for (i = 0; i < new_data[z].arrays; i++) {
1337 free(new_data[z].new_array[i]);
1338 free(new_data[z].orig_array[i]);
1339 }
1340 free(new_data[z].new_array);
1341 free(new_data[z].orig_array);
1342 }
1343 }
1344 if (new_data)
1345 free(new_data);
1346
1347 if (edit_column_requests) {
1348 for (i = 0; i < edit_column_requests; i++) {
1350 free(edit_column_request[i].edit_string);
1351 }
1352 free(edit_column_request);
1353 }
1354 if (edit_parameter_requests) {
1355 for (i = 0; i < edit_parameter_requests; i++) {
1357 free(edit_parameter_request[i].edit_string);
1358 }
1359 free(edit_parameter_request);
1360 }
1361
1362 if (edit_array_requests) {
1363 for (i = 0; i < edit_array_requests; i++) {
1365 free(edit_array_request[i].edit_string);
1366 }
1367 free(edit_array_request);
1368 }
1369
1370 free(take_RefData);
1371 if (replace_RefData)
1372 free(replace_RefData);
1373 free(referfile);
1374 free(inputfile);
1375
1376 if (match_columns)
1377 free(match_column);
1378 if (equate_columns)
1379 free(equate_column);
1380
1381
1384 exit(EXIT_FAILURE);
1385 }
1386 for (z = 0; z < referfiles; z++) {
1389 exit(EXIT_FAILURE);
1390 }
1391 }
1392 free(SDDS_ref);
1393
1395 exit(EXIT_FAILURE);
1396 free(input1);
1397 free(output);
1398 return EXIT_SUCCESS;
1399}
int32_t SDDS_CopyColumns(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_CopyParameters(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
int32_t SDDS_CopyRowDirect(SDDS_DATASET *SDDS_target, int64_t target_row, SDDS_DATASET *SDDS_source, int64_t source_row)
int32_t SDDS_CopyArrays(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_ClearPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_ChangeParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a parameter definition within the SDDS dataset.
int32_t SDDS_ChangeArrayInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in an array definition within the SDDS dataset.
int32_t SDDS_ChangeColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a column definition within the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_TransferColumnDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a column definition from a source dataset to a target dataset.
int32_t SDDS_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_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_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
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_ColumnCount(SDDS_DATASET *page)
Retrieves the number of columns in the SDDS dataset.
int32_t SDDS_GetArrayType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of an array in the SDDS dataset by its index.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
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.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
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.
KEYED_EQUIVALENT ** MakeSortedKeyGroups(long *keyGroups, long keyType, void *data, long points)
Create sorted key groups from data.
long FindMatchingKeyGroup(KEYED_EQUIVALENT **keyGroup, long keyGroups, long keyType, void *searchKeyData, long reuse)
Find a matching key group for a search key.
int has_wildcards(char *template)
Check if a template string contains any wildcard characters.