98 {
102 long i, i_arg, j, found, k, m, n;
103 SCANNED_ARG *s_arg;
104 char *input = NULL, *output = NULL, *ptr = NULL, *buffer = NULL;
105 char *description_text = NULL, *description_contents = NULL;
106 unsigned long pipeFlags = 0;
107 long noWarnings = 0, tmpfile_used = 1;
108 long virtual_rows, max_size, pageNumber, vrows;
109 int64_t rows;
110
111 char **orig_column_name = NULL, **orig_parameter_name = NULL, **orig_array_name = NULL;
112 int32_t orig_column_names = 0, orig_parameter_names = 0, orig_array_names = 0;
113 char **new_array_name = NULL;
114 long new_array_names = 0;
115
116 long converted_array_names = 0;
117
119 argc =
scanargs(&s_arg, argc, argv);
120 if (argc < 3) {
122 }
123
124 for (i_arg = 1; i_arg < argc; i_arg++) {
125 if (s_arg[i_arg].arg_type == OPTION) {
127 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
128 case SET_CONVERT:
129 if (s_arg[i_arg].n_items < 2) {
131 }
132 ca =
trealloc(ca,
sizeof(*ca) * (converted_array_names + 1));
133
134 ca[converted_array_names].name = s_arg[i_arg].list[1];
135
136 if ((s_arg[i_arg].n_items > 2) && (strchr(s_arg[i_arg].list[2], '=') == NULL)) {
137 ca[converted_array_names].new_name = s_arg[i_arg].list[2];
138 i = 3;
139 } else {
140 ca[converted_array_names].new_name = s_arg[i_arg].list[1];
141 i = 2;
142 }
143
144 ca[converted_array_names].d[0] = NULL;
145 ca[converted_array_names].d[1] = NULL;
146 ca[converted_array_names].d[2] = NULL;
147 while (i < s_arg[i_arg].n_items) {
148 if (!(ptr = strchr(s_arg[i_arg].list[i], '='))) {
150 }
151 *ptr++ = 0;
152 switch (
match_string(s_arg[i_arg].list[i], dim_option, DIM_OPTIONS, 0)) {
153 case DIM_0:
154 ca[converted_array_names].d[0] = ptr;
155 break;
156 case DIM_1:
157 ca[converted_array_names].d[1] = ptr;
158 break;
159 case DIM_2:
160 ca[converted_array_names].d[2] = ptr;
161 break;
162 default:
164 }
165 i++;
166 }
167 converted_array_names++;
168 break;
169
170 case SET_NOWARNINGS:
171 if (s_arg[i_arg].n_items != 1) {
173 }
174 noWarnings = 1;
175 break;
176
177 case SET_PIPE:
178 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags)) {
180 }
181 break;
182 }
183 } else {
184 if (input == NULL) {
185 input = s_arg[i_arg].list[0];
186 } else if (output == NULL) {
187 output = s_arg[i_arg].list[0];
188 } else {
190 }
191 }
192 }
193
194 processFilenames(
"sddsarray2column", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
195
198 exit(EXIT_FAILURE);
199 }
200
201 if (!description_text) {
203 }
204
205 if (!
SDDS_InitializeOutput(&SDDS_dataset, SDDS_orig.layout.data_mode.mode, 1, description_text, description_contents, output)) {
207 exit(EXIT_FAILURE);
208 }
209
211
212
214 if (!orig_parameter_name) {
216 exit(EXIT_FAILURE);
217 }
218
220 if (!orig_column_name) {
222 exit(EXIT_FAILURE);
223 }
224
226 if (!orig_array_name) {
228 exit(EXIT_FAILURE);
229 }
230
231
232 for (j = 0; j < converted_array_names; j++) {
233 for (i = 0; i < orig_column_names; i++) {
234 if (strcmp(orig_column_name[i], ca[j].new_name) == 0) {
235 fprintf(stderr, "Error: Column '%s' already exists.\n", orig_column_name[i]);
236 exit(EXIT_FAILURE);
237 }
238 }
239 for (i = 0; i < converted_array_names; i++) {
240 if ((i != j) && (strcmp(ca[i].new_name, ca[j].new_name) == 0)) {
241 fprintf(stderr, "Error: Cannot convert two arrays to the same column name '%s'.\n", ca[j].new_name);
242 exit(EXIT_FAILURE);
243 }
244 }
245 found = 0;
246 for (i = 0; i < orig_array_names; i++) {
247 if (strcmp(orig_array_name[i], ca[j].name) == 0) {
248 found = 1;
249 break;
250 }
251 }
252 if (!found) {
253 fprintf(stderr, "Error: Array '%s' does not exist.\n", ca[j].name);
254 exit(EXIT_FAILURE);
255 }
256 }
257
258
259 for (i = 0; i < orig_array_names; i++) {
260 found = 0;
261 for (j = 0; j < converted_array_names; j++) {
262 if (strcmp(orig_array_name[i], ca[j].name) == 0) {
263 found = 1;
264 break;
265 }
266 }
267 if (!found) {
268 new_array_name =
trealloc(new_array_name,
sizeof(*new_array_name) * (new_array_names + 1));
269 new_array_name[new_array_names] = orig_array_name[i];
270 new_array_names++;
271 }
272 }
273
274
275 for (i = 0; i < orig_parameter_names; i++) {
278 exit(EXIT_FAILURE);
279 }
280 }
281
282 for (i = 0; i < orig_column_names; i++) {
285 exit(EXIT_FAILURE);
286 }
287 }
288
289 for (i = 0; i < new_array_names; i++) {
291 fprintf(stderr, "Unable to transfer array '%s' to '%s'.\n", new_array_name[i], new_array_name[i]);
293 exit(EXIT_FAILURE);
294 }
295 }
296
297 for (i = 0; i < converted_array_names; i++) {
299 if (!ardef) {
300 fprintf(stderr, "Error: Unknown array named '%s'.\n", ca[i].name);
301 exit(EXIT_FAILURE);
302 }
303 ca[i].type = ardef->type;
304 if (
SDDS_DefineColumn(&SDDS_dataset, ca[i].new_name, ardef->symbol, ardef->units, ardef->description, ardef->format_string, ardef->type, ardef->field_length) < 0) {
306 fprintf(stderr, "Error: Unable to define new column '%s'.\n", ca[i].new_name);
307 exit(EXIT_FAILURE);
308 }
310 }
311
314 }
315
316
317 max_size = 0;
321 }
322 }
323 buffer =
tmalloc(max_size *
sizeof(
char));
324
326 if (pageNumber == 0) {
327 fprintf(stderr, "Error: SDDS data garbled.\n");
328 fprintf(stderr, "Warning: One or more data pages may be missing.\n");
329 break;
330 }
331 rows = SDDS_RowCount(&SDDS_orig);
332 if (rows < 0) {
333 fprintf(stderr, "Error: Problem counting rows in input page.\n");
335 }
337 fprintf(stderr, "Error: Problem starting output page.\n");
339 }
340
341 for (i = 0; i < orig_parameter_names; i++) {
343 fprintf(stderr, "Error: Problem getting parameter '%s'.\n", orig_parameter_name[i]);
345 }
346 if (!
SDDS_SetParameters(&SDDS_dataset, SDDS_SET_BY_NAME | SDDS_PASS_BY_REFERENCE, orig_parameter_name[i], buffer, NULL)) {
347 fprintf(stderr, "Error: Problem setting parameter '%s'.\n", orig_parameter_name[i]);
349 }
350 }
351
352 if (rows) {
353 for (i = 0; i < orig_column_names; i++) {
355 if (!ptr) {
356 fprintf(stderr, "Error: Problem getting column '%s'.\n", orig_column_name[i]);
358 }
359 if (!
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, ptr, rows, orig_column_name[i])) {
360 fprintf(stderr, "Error: Problem setting column '%s'.\n", orig_column_name[i]);
362 }
363 }
364 }
365
366 for (i = 0; i < new_array_names; i++) {
369 if (!array) {
370 fprintf(stderr, "Error: Problem getting array '%s'.\n", new_array_name[i]);
372 }
373 if (!
SDDS_SetArray(&SDDS_dataset, new_array_name[i], SDDS_CONTIGUOUS_DATA, array->data, array->dimension)) {
374 fprintf(stderr, "Error: Problem setting array '%s'.\n", new_array_name[i]);
376 }
378 }
379
380 virtual_rows = -1;
381 for (i = 0; i < converted_array_names; i++) {
384 if (!array) {
385 fprintf(stderr, "Error: Problem getting array '%s'.\n", ca[i].name);
387 }
388
389 if ((ca[i].d[0] == NULL) && (ca[i].d[1] == NULL) && (ca[i].d[2] == NULL)) {
390 if ((orig_column_names) && (array->elements != rows)) {
391 fprintf(stderr, "Error: Cannot convert '%s' because existing columns have a different number of rows.\n", ca[i].name);
392 exit(EXIT_FAILURE);
393 }
394 if ((virtual_rows >= 0) && (array->elements != virtual_rows)) {
395 fprintf(stderr, "Error: The number of array elements are not the same.\n");
396 exit(EXIT_FAILURE);
397 }
398 if ((!orig_column_names) && (virtual_rows == -1)) {
402 }
403 }
404 virtual_rows = array->elements;
405 if (!
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, array->data, virtual_rows, ca[i].new_name)) {
406 fprintf(stderr, "Error: Problem setting column '%s'.\n", ca[i].new_name);
408 }
409 } else {
410 vrows = 0;
411 ca[i].dims[0] = ca[i].dims[1] = ca[i].dims[2] = 0;
412 for (j = 0; j < array->definition->dimensions; j++) {
413 ca[i].dim[j] = NULL;
414 if (ca[i].d[j] == NULL) {
415 ca[i].dims[j] = array->dimension[j];
416 ca[i].dim[j] = malloc(sizeof(long) * ca[i].dims[j]);
417 for (k = 0; k < ca[i].dims[j]; k++) {
418 ca[i].dim[j][k] = k;
419 }
420 } else {
421 ptr = strtok(ca[i].d[j], ",");
422 while (ptr != NULL) {
423 ca[i].dim[j] = realloc(ca[i].dim[j], sizeof(long) * (ca[i].dims[j] + 1));
424 if (!ca[i].dim[j]) {
425 fprintf(stderr, "Error: Memory allocation failed for dimension indices.\n");
426 exit(EXIT_FAILURE);
427 }
428
429 if ((sscanf(ptr, "%ld", &ca[i].dim[j][ca[i].dims[j]]) != 1) ||
430 (ca[i].dim[j][ca[i].dims[j]] < 0) ||
431 (ca[i].dim[j][ca[i].dims[j]] >= array->dimension[j])) {
432 fprintf(stderr, "Error: Invalid value for d%ld: '%s'.\n", j + 1, ptr);
433 exit(EXIT_FAILURE);
434 }
435 ca[i].dims[j]++;
436 ptr = strtok(NULL, ",");
437 }
438 }
439 if (j == 0) {
440 vrows = ca[i].dims[j];
441 } else {
442 vrows *= ca[i].dims[j];
443 }
444 }
445
446 if ((orig_column_names) && (vrows != rows)) {
447 fprintf(stderr, "Error: Cannot convert '%s' because existing columns have a different number of rows.\n", ca[i].name);
448 exit(EXIT_FAILURE);
449 }
450 if ((virtual_rows >= 0) && (vrows != virtual_rows)) {
451 fprintf(stderr, "Error: The number of array elements are not the same.\n");
452 exit(EXIT_FAILURE);
453 }
454 if ((!orig_column_names) && (virtual_rows == -1)) {
458 }
459 }
460 virtual_rows = vrows;
461
462 n = 0;
463 switch (ca[i].type) {
465 ca[i].data = malloc(sizeof(short) * vrows);
466 if (ca[i].dims[1] == 0) {
467 for (j = 0; j < ca[i].dims[0]; j++) {
468 ((short *)ca[i].data)[n++] = ((short *)array->data)[ca[i].dim[0][j]];
469 }
470 } else if (ca[i].dims[2] == 0) {
471 for (j = 0; j < ca[i].dims[0]; j++) {
472 for (k = 0; k < ca[i].dims[1]; k++) {
473 ((short *)ca[i].data)[n++] = ((short *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
474 }
475 }
476 } else {
477 for (j = 0; j < ca[i].dims[0]; j++) {
478 for (k = 0; k < ca[i].dims[1]; k++) {
479 for (m = 0; m < ca[i].dims[2]; m++) {
480 ((short *)ca[i].data)[n++] = ((short *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
481 ca[i].dim[1][k] * array->dimension[2] +
482 ca[i].dim[2][m]];
483 }
484 }
485 }
486 }
487 break;
488
490 ca[i].data = malloc(sizeof(unsigned short) * vrows);
491 if (ca[i].dims[1] == 0) {
492 for (j = 0; j < ca[i].dims[0]; j++) {
493 ((unsigned short *)ca[i].data)[n++] = ((unsigned short *)array->data)[ca[i].dim[0][j]];
494 }
495 } else if (ca[i].dims[2] == 0) {
496 for (j = 0; j < ca[i].dims[0]; j++) {
497 for (k = 0; k < ca[i].dims[1]; k++) {
498 ((unsigned short *)ca[i].data)[n++] = ((unsigned short *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
499 }
500 }
501 } else {
502 for (j = 0; j < ca[i].dims[0]; j++) {
503 for (k = 0; k < ca[i].dims[1]; k++) {
504 for (m = 0; m < ca[i].dims[2]; m++) {
505 ((unsigned short *)ca[i].data)[n++] = ((unsigned short *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
506 ca[i].dim[1][k] * array->dimension[2] +
507 ca[i].dim[2][m]];
508 }
509 }
510 }
511 }
512 break;
513
515 ca[i].data = malloc(sizeof(int32_t) * vrows);
516 if (ca[i].dims[1] == 0) {
517 for (j = 0; j < ca[i].dims[0]; j++) {
518 ((int32_t *)ca[i].data)[n++] = ((int32_t *)array->data)[ca[i].dim[0][j]];
519 }
520 } else if (ca[i].dims[2] == 0) {
521 for (j = 0; j < ca[i].dims[0]; j++) {
522 for (k = 0; k < ca[i].dims[1]; k++) {
523 ((int32_t *)ca[i].data)[n++] = ((int32_t *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
524 }
525 }
526 } else {
527 for (j = 0; j < ca[i].dims[0]; j++) {
528 for (k = 0; k < ca[i].dims[1]; k++) {
529 for (m = 0; m < ca[i].dims[2]; m++) {
530 ((int32_t *)ca[i].data)[n++] = ((int32_t *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
531 ca[i].dim[1][k] * array->dimension[2] +
532 ca[i].dim[2][m]];
533 }
534 }
535 }
536 }
537 break;
538
540 ca[i].data = malloc(sizeof(uint32_t) * vrows);
541 if (ca[i].dims[1] == 0) {
542 for (j = 0; j < ca[i].dims[0]; j++) {
543 ((uint32_t *)ca[i].data)[n++] = ((uint32_t *)array->data)[ca[i].dim[0][j]];
544 }
545 } else if (ca[i].dims[2] == 0) {
546 for (j = 0; j < ca[i].dims[0]; j++) {
547 for (k = 0; k < ca[i].dims[1]; k++) {
548 ((uint32_t *)ca[i].data)[n++] = ((uint32_t *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
549 }
550 }
551 } else {
552 for (j = 0; j < ca[i].dims[0]; j++) {
553 for (k = 0; k < ca[i].dims[1]; k++) {
554 for (m = 0; m < ca[i].dims[2]; m++) {
555 ((uint32_t *)ca[i].data)[n++] = ((uint32_t *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
556 ca[i].dim[1][k] * array->dimension[2] +
557 ca[i].dim[2][m]];
558 }
559 }
560 }
561 }
562 break;
563
565 ca[i].data = malloc(sizeof(int64_t) * vrows);
566 if (ca[i].dims[1] == 0) {
567 for (j = 0; j < ca[i].dims[0]; j++) {
568 ((int64_t *)ca[i].data)[n++] = ((int64_t *)array->data)[ca[i].dim[0][j]];
569 }
570 } else if (ca[i].dims[2] == 0) {
571 for (j = 0; j < ca[i].dims[0]; j++) {
572 for (k = 0; k < ca[i].dims[1]; k++) {
573 ((int64_t *)ca[i].data)[n++] = ((int64_t *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
574 }
575 }
576 } else {
577 for (j = 0; j < ca[i].dims[0]; j++) {
578 for (k = 0; k < ca[i].dims[1]; k++) {
579 for (m = 0; m < ca[i].dims[2]; m++) {
580 ((int64_t *)ca[i].data)[n++] = ((int64_t *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
581 ca[i].dim[1][k] * array->dimension[2] +
582 ca[i].dim[2][m]];
583 }
584 }
585 }
586 }
587 break;
588
590 ca[i].data = malloc(sizeof(uint64_t) * vrows);
591 if (ca[i].dims[1] == 0) {
592 for (j = 0; j < ca[i].dims[0]; j++) {
593 ((uint64_t *)ca[i].data)[n++] = ((uint64_t *)array->data)[ca[i].dim[0][j]];
594 }
595 } else if (ca[i].dims[2] == 0) {
596 for (j = 0; j < ca[i].dims[0]; j++) {
597 for (k = 0; k < ca[i].dims[1]; k++) {
598 ((uint64_t *)ca[i].data)[n++] = ((uint64_t *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
599 }
600 }
601 } else {
602 for (j = 0; j < ca[i].dims[0]; j++) {
603 for (k = 0; k < ca[i].dims[1]; k++) {
604 for (m = 0; m < ca[i].dims[2]; m++) {
605 ((uint64_t *)ca[i].data)[n++] = ((uint64_t *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
606 ca[i].dim[1][k] * array->dimension[2] +
607 ca[i].dim[2][m]];
608 }
609 }
610 }
611 }
612 break;
613
615 ca[i].data = malloc(sizeof(float) * vrows);
616 if (ca[i].dims[1] == 0) {
617 for (j = 0; j < ca[i].dims[0]; j++) {
618 ((float *)ca[i].data)[n++] = ((float *)array->data)[ca[i].dim[0][j]];
619 }
620 } else if (ca[i].dims[2] == 0) {
621 for (j = 0; j < ca[i].dims[0]; j++) {
622 for (k = 0; k < ca[i].dims[1]; k++) {
623 ((float *)ca[i].data)[n++] = ((float *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
624 }
625 }
626 } else {
627 for (j = 0; j < ca[i].dims[0]; j++) {
628 for (k = 0; k < ca[i].dims[1]; k++) {
629 for (m = 0; m < ca[i].dims[2]; m++) {
630 ((float *)ca[i].data)[n++] = ((float *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
631 ca[i].dim[1][k] * array->dimension[2] +
632 ca[i].dim[2][m]];
633 }
634 }
635 }
636 }
637 break;
638
640 ca[i].data = malloc(sizeof(double) * vrows);
641 if (ca[i].dims[1] == 0) {
642 for (j = 0; j < ca[i].dims[0]; j++) {
643 ((double *)ca[i].data)[n++] = ((double *)array->data)[ca[i].dim[0][j]];
644 }
645 } else if (ca[i].dims[2] == 0) {
646 for (j = 0; j < ca[i].dims[0]; j++) {
647 for (k = 0; k < ca[i].dims[1]; k++) {
648 ((double *)ca[i].data)[n++] = ((double *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
649 }
650 }
651 } else {
652 for (j = 0; j < ca[i].dims[0]; j++) {
653 for (k = 0; k < ca[i].dims[1]; k++) {
654 for (m = 0; m < ca[i].dims[2]; m++) {
655 ((double *)ca[i].data)[n++] = ((double *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
656 ca[i].dim[1][k] * array->dimension[2] +
657 ca[i].dim[2][m]];
658 }
659 }
660 }
661 }
662 break;
663
665 ca[i].data = malloc(sizeof(char *) * vrows);
666 if (ca[i].dims[1] == 0) {
667 for (j = 0; j < ca[i].dims[0]; j++) {
668 ((char **)ca[i].data)[n++] = ((char **)array->data)[ca[i].dim[0][j]];
669 }
670 } else if (ca[i].dims[2] == 0) {
671 for (j = 0; j < ca[i].dims[0]; j++) {
672 for (k = 0; k < ca[i].dims[1]; k++) {
673 ((char **)ca[i].data)[n++] = ((char **)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
674 }
675 }
676 } else {
677 for (j = 0; j < ca[i].dims[0]; j++) {
678 for (k = 0; k < ca[i].dims[1]; k++) {
679 for (m = 0; m < ca[i].dims[2]; m++) {
680 ((char **)ca[i].data)[n++] = ((char **)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
681 ca[i].dim[1][k] * array->dimension[2] +
682 ca[i].dim[2][m]];
683 }
684 }
685 }
686 }
687 break;
688
690 ca[i].data = malloc(sizeof(char) * vrows);
691 if (ca[i].dims[1] == 0) {
692 for (j = 0; j < ca[i].dims[0]; j++) {
693 ((char *)ca[i].data)[n++] = ((char *)array->data)[ca[i].dim[0][j]];
694 }
695 } else if (ca[i].dims[2] == 0) {
696 for (j = 0; j < ca[i].dims[0]; j++) {
697 for (k = 0; k < ca[i].dims[1]; k++) {
698 ((char *)ca[i].data)[n++] = ((char *)array->data)[ca[i].dim[0][j] * array->dimension[1] + ca[i].dim[1][k]];
699 }
700 }
701 } else {
702 for (j = 0; j < ca[i].dims[0]; j++) {
703 for (k = 0; k < ca[i].dims[1]; k++) {
704 for (m = 0; m < ca[i].dims[2]; m++) {
705 ((char *)ca[i].data)[n++] = ((char *)array->data)[ca[i].dim[0][j] * (array->dimension[1] * array->dimension[2]) +
706 ca[i].dim[1][k] * array->dimension[2] +
707 ca[i].dim[2][m]];
708 }
709 }
710 }
711 }
712 break;
713
714 default:
715 fprintf(stderr, "Error: Unsupported data type for array '%s'.\n", ca[i].name);
716 exit(EXIT_FAILURE);
717 }
718
719 if (!
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, ca[i].data, virtual_rows, ca[i].new_name)) {
720 fprintf(stderr, "Error: Problem setting column '%s'.\n", ca[i].new_name);
722 }
723
724 for (j = 0; j < array->definition->dimensions; j++) {
725 if (ca[i].dim[j] != NULL) {
726 free(ca[i].dim[j]);
727 }
728 }
729 if (ca[i].data != NULL) {
730 free(ca[i].data);
731 }
732 }
733 }
734
736 fprintf(stderr, "Error: Problem writing page to file '%s'.\n", output);
738 }
739 }
740
743 exit(EXIT_FAILURE);
744 }
745
747 exit(EXIT_FAILURE);
748 }
749
750 if (ca != NULL) {
751 free(ca);
752 }
753 if (buffer != NULL) {
754 free(buffer);
755 }
756 for (i = 0; i < orig_array_names; i++) {
757 if (orig_array_name[i] != NULL) {
758 free(orig_array_name[i]);
759 }
760 }
761 if (orig_array_name != NULL) {
762 free(orig_array_name);
763 }
764 for (i = 0; i < orig_parameter_names; i++) {
765 if (orig_parameter_name[i] != NULL) {
766 free(orig_parameter_name[i]);
767 }
768 }
769 if (orig_parameter_name != NULL) {
770 free(orig_parameter_name);
771 }
772 for (i = 0; i < orig_column_names; i++) {
773 if (orig_column_name[i] != NULL) {
774 free(orig_column_name[i]);
775 }
776 }
777 if (orig_column_name != NULL) {
778 free(orig_column_name);
779 }
780 if (description_text != NULL) {
781 free(description_text);
782 }
783 if (description_contents != NULL) {
784 free(description_contents);
785 }
786
787 return EXIT_SUCCESS;
788}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
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_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_SetArray(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t *dimension)
Sets the values of an array variable in the SDDS dataset using specified dimensions.
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_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_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.
void SDDS_FreeArray(SDDS_ARRAY *array)
Frees memory allocated for an SDDS array structure.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
ARRAY_DEFINITION * SDDS_GetArrayDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified array from the SDDS dataset.
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters 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.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
char ** SDDS_GetArrayNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all arrays in the SDDS dataset.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
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)