53#define PARAMETER_MODE 1
56static char *mode_name[MODES] = {
67#define SET_DESCRIPTION 5
70#define SET_EDIT_NAMES 7
71#define SET_LINES_PER_ROW 8
72#define SET_NOWARNINGS 9
75#define SET_FROMPAGE 12
77#define SET_ACCEPT_ALL_NAMES 14
78#define SET_REMOVEPAGES 15
79#define SET_KEEPPAGES 16
80#define SET_ROWLIMIT 17
81#define SET_MAJOR_ORDER 18
82#define SET_CONVERT_UNITS 19
85char *option[N_OPTIONS] = {
107char *USAGE =
"sddsconvert [<source-file>] [<target-file>]\n\
108[-pipe=[input][,output]]\n\
109[-binary] [-ascii] [-description=<text>,<contents>]\n\
110[-fromPage=<pageNumber>] [-toPage=<pageNumber>]\n\
111[-removePages=<listOfNumbers>] [-keepPages=<listOfNumbers>]\n\
112[-linesperrow=<integer>] [-nowarnings] [-recover[=clip]]\n\
113[-delete={column|parameter|array},<matching-string>[,...]]\n\
114[-retain={column|parameter|array},<matching-string>[,...]]\n\
115[-rename={column|parameter|array},<oldname>=<newname>[,...]]\n\
116[-editnames={column|parameter|array},<wildcard-string>,<edit-string>]\n\
117[-convertUnits={column|parameter|array},<name>,<new-units>,[<old-units>[,<factor>]]\n\
118[-acceptAllNames] [-rowlimit=<number>]\n\
119[-majorOrder=row|column]\n\n\
120sddsconvert converts SDDS files between ASCII and binary, and allows wildcard-based filtering.\n\
121Any element matched by a deletion string is deleted unless matched by a retention string.\n\
122The -acceptAllNames option may force the SDDS library to accept unusual names.\n\
123Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
125typedef char *STRING_PAIR[2];
139static char **process_name_options(
char **orig_name,
long **orig_flag,
long orig_names,
140 char **
delete,
long deletes,
char **retain,
long retains,
141 STRING_PAIR *rename,
long renames,
145 long convert_units_arrays,
CONVERT_UNITS *convert_units_column,
146 long convert_units_columns,
CONVERT_UNITS *convert_units_parameter,
147 long convert_units_parameters) {
149 for (i = 0; i < convert_units_arrays; i++) {
151 convert_units_array[i].new_units,
152 convert_units_array[i].old_units,
153 convert_units_array[i].factor) == 0)
156 for (i = 0; i < convert_units_columns; i++) {
158 convert_units_column[i].new_units,
159 convert_units_column[i].old_units,
160 convert_units_column[i].factor) == 0)
163 for (i = 0; i < convert_units_parameters; i++) {
165 convert_units_parameter[i].new_units,
166 convert_units_parameter[i].old_units,
167 convert_units_parameter[i].factor) == 0)
173int main(
int argc,
char **argv) {
177 char *description_text, *description_contents;
178 long tmpfile_used, noWarnings;
179 char *input, *output, *ptr, *buffer;
180 long ascii_output, binary_output, recover, recovered;
181 unsigned long pipeFlags, majorOrderFlag;
183 char **retain_column, **delete_column;
184 long retain_columns, delete_columns, rename_columns, edit_column_requests;
186 STRING_PAIR *rename_column;
187 char **orig_column_name, **new_column_name;
188 long *orig_column_flag = NULL;
189 int32_t orig_column_names;
191 char **retain_parameter, **delete_parameter;
192 long retain_parameters, delete_parameters, rename_parameters, edit_parameter_requests;
194 STRING_PAIR *rename_parameter;
195 char **orig_parameter_name, **new_parameter_name;
196 long *orig_parameter_flag = NULL;
197 int32_t orig_parameter_names;
199 char **retain_array, **delete_array;
200 long retain_arrays, delete_arrays, rename_arrays, edit_array_requests;
202 STRING_PAIR *rename_array;
203 char **orig_array_name, **new_array_name;
204 long *orig_array_flag = NULL;
205 int32_t orig_array_names;
207 long lines_per_row, pageNumber = 0, fromPage, toPage;
209 long max_size, output_columns;
210 long *removePage, *keepPage;
211 long removePages, keepPages, keep;
213 short column_major = -1;
215 long convert_units_arrays = 0, convert_units_columns = 0, convert_units_parameters = 0;
216 CONVERT_UNITS *convert_units_array = NULL, *convert_units_column = NULL, *convert_units_parameter = NULL;
218 new_column_name = new_parameter_name = new_array_name = NULL;
221 argc =
scanargs(&s_arg, argc, argv);
223 fprintf(stderr,
"%s\n", USAGE);
226 input = output = NULL;
227 ascii_output = binary_output = noWarnings = 0;
229 retain_column = delete_column = NULL;
230 retain_columns = delete_columns = rename_columns = edit_column_requests = 0;
231 rename_column = NULL;
232 edit_column_request = NULL;
234 retain_parameter = delete_parameter = NULL;
235 retain_parameters = delete_parameters = rename_parameters = edit_parameter_requests = 0;
236 rename_parameter = NULL;
237 edit_parameter_request = NULL;
239 retain_array = delete_array = NULL;
240 retain_arrays = delete_arrays = rename_arrays = edit_array_requests = 0;
242 edit_array_request = NULL;
245 description_text = description_contents = NULL;
246 fromPage = toPage = recover = 0;
247 removePage = keepPage = NULL;
248 removePages = keepPages = 0;
252 for (i_arg = 1; i_arg < argc; i_arg++) {
253 if (s_arg[i_arg].arg_type == OPTION) {
255 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
256 case SET_MAJOR_ORDER:
258 s_arg[i_arg].n_items -= 1;
259 if (s_arg[i_arg].n_items > 0 &&
261 &s_arg[i_arg].n_items, 0,
262 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
263 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER,
265 SDDS_Bomb(
"invalid -majorOrder syntax/values");
266 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
268 if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
279 case SET_CONVERT_UNITS:
280 if ((s_arg[i_arg].n_items != 4) && (s_arg[i_arg].n_items != 5) &&
281 (s_arg[i_arg].n_items != 6)) {
282 fprintf(stderr,
"Error (%s): invalid -convertUnits syntax\n", argv[0]);
285 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
287 convert_units_array =
trealloc(convert_units_array,
288 sizeof(*convert_units_array) * (convert_units_arrays + 1));
289 convert_units_array[convert_units_arrays].name = s_arg[i_arg].list[2];
290 convert_units_array[convert_units_arrays].new_units = s_arg[i_arg].list[3];
291 if (s_arg[i_arg].n_items >= 5)
292 convert_units_array[convert_units_arrays].old_units = s_arg[i_arg].list[4];
294 convert_units_array[convert_units_arrays].old_units = NULL;
295 if (s_arg[i_arg].n_items == 6) {
296 if (sscanf(s_arg[i_arg].list[5],
"%lf",
297 &(convert_units_array[convert_units_arrays].factor)) != 1) {
298 fprintf(stderr,
"Error (%s): invalid -convertUnits syntax or value\n", argv[0]);
302 convert_units_array[convert_units_arrays].factor = 1.0;
303 convert_units_arrays++;
306 convert_units_column =
trealloc(convert_units_column,
307 sizeof(*convert_units_column) * (convert_units_columns + 1));
308 convert_units_column[convert_units_columns].name = s_arg[i_arg].list[2];
309 convert_units_column[convert_units_columns].new_units = s_arg[i_arg].list[3];
310 if (s_arg[i_arg].n_items >= 5)
311 convert_units_column[convert_units_columns].old_units = s_arg[i_arg].list[4];
313 convert_units_column[convert_units_columns].old_units = NULL;
314 if (s_arg[i_arg].n_items == 6) {
315 if (sscanf(s_arg[i_arg].list[5],
"%lf",
316 &(convert_units_column[convert_units_columns].factor)) != 1) {
317 fprintf(stderr,
"Error (%s): invalid -convertUnits syntax or value\n", argv[0]);
321 convert_units_column[convert_units_columns].factor = 1.0;
322 convert_units_columns++;
325 convert_units_parameter =
trealloc(convert_units_parameter,
326 sizeof(*convert_units_parameter) * (convert_units_parameters + 1));
327 convert_units_parameter[convert_units_parameters].name = s_arg[i_arg].list[2];
328 convert_units_parameter[convert_units_parameters].new_units = s_arg[i_arg].list[3];
329 if (s_arg[i_arg].n_items >= 5)
330 convert_units_parameter[convert_units_parameters].old_units = s_arg[i_arg].list[4];
332 convert_units_parameter[convert_units_parameters].old_units = NULL;
333 if (s_arg[i_arg].n_items == 6) {
334 if (sscanf(s_arg[i_arg].list[5],
"%lf",
335 &(convert_units_parameter[convert_units_parameters].factor)) != 1) {
336 fprintf(stderr,
"Error (%s): invalid -convertUnits syntax or value\n", argv[0]);
340 convert_units_parameter[convert_units_parameters].factor = 1.0;
341 convert_units_parameters++;
344 fprintf(stderr,
"Error (%s): invalid -convertUnits syntax: specify column, parameter or array\n", argv[0]);
349 if (s_arg[i_arg].n_items < 3) {
350 fprintf(stderr,
"Error (%s): invalid -delete syntax\n", argv[0]);
353 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
355 delete_column =
trealloc(delete_column,
356 sizeof(*delete_column) * (delete_columns + s_arg[i_arg].n_items - 2));
357 for (i = 2; i < s_arg[i_arg].n_items; i++)
358 delete_column[i - 2 + delete_columns] = s_arg[i_arg].list[i];
359 delete_columns += s_arg[i_arg].n_items - 2;
362 delete_parameter =
trealloc(delete_parameter,
363 sizeof(*delete_parameter) * (delete_parameters + s_arg[i_arg].n_items - 2));
364 for (i = 2; i < s_arg[i_arg].n_items; i++)
365 delete_parameter[i - 2 + delete_parameters] = s_arg[i_arg].list[i];
366 delete_parameters += s_arg[i_arg].n_items - 2;
369 delete_array =
trealloc(delete_array,
370 sizeof(*delete_array) * (delete_arrays + s_arg[i_arg].n_items - 2));
371 for (i = 2; i < s_arg[i_arg].n_items; i++)
372 delete_array[i - 2 + delete_arrays] = s_arg[i_arg].list[i];
373 delete_arrays += s_arg[i_arg].n_items - 2;
376 fprintf(stderr,
"Error (%s): invalid -delete syntax: specify column, parameter or array\n", argv[0]);
381 if (s_arg[i_arg].n_items < 3) {
382 fprintf(stderr,
"Error (%s): invalid -retain syntax\n", argv[0]);
385 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
387 retain_column =
trealloc(retain_column,
388 sizeof(*retain_column) * (retain_columns + s_arg[i_arg].n_items - 2));
389 for (i = 2; i < s_arg[i_arg].n_items; i++)
390 retain_column[i - 2 + retain_columns] = s_arg[i_arg].list[i];
391 retain_columns += s_arg[i_arg].n_items - 2;
394 retain_parameter =
trealloc(retain_parameter,
395 sizeof(*retain_parameter) * (retain_parameters + s_arg[i_arg].n_items - 2));
396 for (i = 2; i < s_arg[i_arg].n_items; i++)
397 retain_parameter[i - 2 + retain_parameters] = s_arg[i_arg].list[i];
398 retain_parameters += s_arg[i_arg].n_items - 2;
401 retain_array =
trealloc(retain_array,
402 sizeof(*retain_array) * (retain_arrays + s_arg[i_arg].n_items - 2));
403 for (i = 2; i < s_arg[i_arg].n_items; i++)
404 retain_array[i - 2 + retain_arrays] = s_arg[i_arg].list[i];
405 retain_arrays += s_arg[i_arg].n_items - 2;
408 fprintf(stderr,
"Error (%s): invalid -retain syntax: specify column, parameter or array\n", argv[0]);
413 if (s_arg[i_arg].n_items < 3) {
414 fprintf(stderr,
"Error (%s): invalid -rename syntax\n", argv[0]);
417 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
419 rename_column =
trealloc(rename_column,
420 sizeof(*rename_column) * (rename_columns + s_arg[i_arg].n_items - 2));
421 for (i = 2; i < s_arg[i_arg].n_items; i++) {
422 if (!(ptr = strchr(s_arg[i_arg].list[i],
'='))) {
423 fprintf(stderr,
"Error (%s): invalid -rename syntax\n", argv[0]);
427 rename_column[i - 2 + rename_columns][0] = s_arg[i_arg].list[i];
428 rename_column[i - 2 + rename_columns][1] = ptr;
430 rename_columns += s_arg[i_arg].n_items - 2;
433 rename_parameter =
trealloc(rename_parameter,
434 sizeof(*rename_parameter) * (rename_parameters + s_arg[i_arg].n_items - 2));
435 for (i = 2; i < s_arg[i_arg].n_items; i++) {
436 if (!(ptr = strchr(s_arg[i_arg].list[i],
'='))) {
437 fprintf(stderr,
"Error (%s): invalid -rename syntax\n", argv[0]);
441 rename_parameter[i - 2 + rename_parameters][0] = s_arg[i_arg].list[i];
442 rename_parameter[i - 2 + rename_parameters][1] = ptr;
444 rename_parameters += s_arg[i_arg].n_items - 2;
447 rename_array =
trealloc(rename_array,
448 sizeof(*rename_array) * (rename_arrays + s_arg[i_arg].n_items - 2));
449 for (i = 2; i < s_arg[i_arg].n_items; i++) {
450 if (!(ptr = strchr(s_arg[i_arg].list[i],
'='))) {
451 fprintf(stderr,
"Error (%s): invalid -rename syntax\n", argv[0]);
455 rename_array[i - 2 + rename_arrays][0] = s_arg[i_arg].list[i];
456 rename_array[i - 2 + rename_arrays][1] = ptr;
458 rename_arrays += s_arg[i_arg].n_items - 2;
461 fprintf(stderr,
"Error (%s): invalid -rename syntax: specify column, parameter or array\n", argv[0]);
465 case SET_DESCRIPTION:
466 if (s_arg[i_arg].n_items != 3) {
467 fprintf(stderr,
"Error (%s): invalid -description syntax\n", argv[0]);
470 description_text = s_arg[i_arg].list[1];
471 description_contents = s_arg[i_arg].list[2];
474 if (s_arg[i_arg].n_items < 2) {
475 fprintf(stderr,
"Error (%s): invalid -table syntax\n", argv[0]);
478 if (pageNumber != 0) {
479 fprintf(stderr,
"Error (%s): specify -table once only\n", argv[0]);
482 if (sscanf(s_arg[i_arg].list[1],
"%ld", &pageNumber) != 1 || pageNumber <= 0) {
483 fprintf(stderr,
"Error (%s): invalid -table value\n", argv[0]);
486 fromPage = toPage = pageNumber;
489 if (s_arg[i_arg].n_items < 2) {
490 fprintf(stderr,
"Error (%s): invalid -fromPage syntax\n", argv[0]);
494 fprintf(stderr,
"Error (%s): specify -fromPage once only\n", argv[0]);
497 if (sscanf(s_arg[i_arg].list[1],
"%ld", &fromPage) != 1 || fromPage <= 0) {
498 fprintf(stderr,
"Error (%s): invalid -fromPage value\n", argv[0]);
503 if (s_arg[i_arg].n_items < 2) {
504 fprintf(stderr,
"Error (%s): invalid -toPage syntax\n", argv[0]);
508 fprintf(stderr,
"Error (%s): specify -toPage once only\n", argv[0]);
511 if (sscanf(s_arg[i_arg].list[1],
"%ld", &toPage) != 1 || toPage <= 0) {
512 fprintf(stderr,
"Error (%s): invalid -toPage value\n", argv[0]);
516 case SET_REMOVEPAGES:
517 if (s_arg[i_arg].n_items < 2) {
518 fprintf(stderr,
"Error (%s): invalid -removePages syntax\n", argv[0]);
521 if (removePage != NULL) {
522 fprintf(stderr,
"Error (%s): specify -removePages once only\n", argv[0]);
525 removePages = s_arg[i_arg].n_items - 1;
526 removePage =
trealloc(removePage,
sizeof(*removePage) * (removePages));
527 for (i = 0; i < removePages; i++) {
528 if (sscanf(s_arg[i_arg].list[i + 1],
"%ld", &removePage[i]) != 1 || removePage[i] <= 0) {
529 fprintf(stderr,
"Error (%s): invalid -removePages value\n", argv[0]);
535 if (s_arg[i_arg].n_items < 2) {
536 fprintf(stderr,
"Error (%s): invalid -keepPages syntax\n", argv[0]);
539 if (keepPage != NULL) {
540 fprintf(stderr,
"Error (%s): specify -keepPages once only\n", argv[0]);
543 keepPages = s_arg[i_arg].n_items - 1;
544 keepPage =
trealloc(keepPage,
sizeof(*keepPage) * (keepPages));
545 for (i = 0; i < keepPages; i++) {
546 if (sscanf(s_arg[i_arg].list[i + 1],
"%ld", &keepPage[i]) != 1 || keepPage[i] <= 0) {
547 fprintf(stderr,
"Error (%s): invalid -keepPages value\n", argv[0]);
553 if (s_arg[i_arg].n_items < 4) {
554 fprintf(stderr,
"Error (%s): invalid -editnames syntax\n", argv[0]);
557 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
559 edit_column_request =
trealloc(edit_column_request,
560 sizeof(*edit_column_request) * (edit_column_requests + 1));
561 edit_column_request[edit_column_requests].match_string = s_arg[i_arg].list[2];
562 edit_column_request[edit_column_requests].edit_string = s_arg[i_arg].list[3];
563 edit_column_requests++;
566 edit_parameter_request =
trealloc(edit_parameter_request,
567 sizeof(*edit_parameter_request) * (edit_parameter_requests + 1));
568 edit_parameter_request[edit_parameter_requests].match_string = s_arg[i_arg].list[2];
569 edit_parameter_request[edit_parameter_requests].edit_string = s_arg[i_arg].list[3];
570 edit_parameter_requests++;
573 edit_array_request =
trealloc(edit_array_request,
574 sizeof(*edit_array_request) * (edit_array_requests + 1));
575 edit_array_request[edit_array_requests].match_string = s_arg[i_arg].list[2];
576 edit_array_request[edit_array_requests].edit_string = s_arg[i_arg].list[3];
577 edit_array_requests++;
580 fprintf(stderr,
"Error (%s): invalid -editnames syntax\n", argv[0]);
584 case SET_LINES_PER_ROW:
585 if (s_arg[i_arg].n_items != 2 ||
586 sscanf(s_arg[i_arg].list[1],
"%ld", &lines_per_row) != 1 ||
587 lines_per_row <= 0) {
588 fprintf(stderr,
"Error (%s): invalid -linesperrow syntax\n", argv[0]);
593 if (s_arg[i_arg].n_items != 1) {
594 fprintf(stderr,
"Error (%s): invalid -nowarnings syntax\n", argv[0]);
601 if (s_arg[i_arg].n_items != 1) {
603 if (s_arg[i_arg].n_items > 2 ||
604 strncmp(s_arg[i_arg].list[1],
"clip", strlen(s_arg[i_arg].list[1])) != 0) {
605 fprintf(stderr,
"Error (%s): invalid -recover syntax\n", argv[0]);
611 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags)) {
612 fprintf(stderr,
"Error (%s): invalid -pipe syntax\n", argv[0]);
616 case SET_ACCEPT_ALL_NAMES:
620 if (s_arg[i_arg].n_items != 2 ||
621 sscanf(s_arg[i_arg].list[1],
"%" SCNd64, &rowLimit) != 1 ||
623 fprintf(stderr,
"Error (%s): invalid -rowLimit syntax\n", argv[0]);
629 fprintf(stderr,
"Error (%s): unknown switch: %s\n", argv[0], s_arg[i_arg].list[0]);
634 input = s_arg[i_arg].list[0];
635 else if (output == NULL)
636 output = s_arg[i_arg].list[0];
638 fprintf(stderr,
"Error (%s): too many filenames\n", argv[0]);
644 if (fromPage && toPage && fromPage > toPage) {
645 fprintf(stderr,
"Error (%s): invalid -fromPage and -toPage\n", argv[0]);
649 processFilenames(
"sddsconvert", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
652 fprintf(stderr,
"Initializing input and output files.\n");
659 if (!set_units_conversion(&SDDS_orig, convert_units_array, convert_units_arrays,
660 convert_units_column, convert_units_columns,
661 convert_units_parameter, convert_units_parameters)) {
666 if (!description_text)
670 ascii_output ? SDDS_ASCII : (binary_output ? SDDS_BINARY : SDDS_orig.layout.data_mode.mode),
671 lines_per_row, description_text, description_contents, output)) {
678 if (column_major != -1)
679 SDDS_dataset.layout.data_mode.column_major = column_major;
681 SDDS_dataset.layout.data_mode.column_major = SDDS_orig.layout.data_mode.column_major;
684 fprintf(stderr,
"Getting column, parameter, and array names from input file.\n");
690 if (orig_column_names &&
691 !(new_column_name = process_name_options(orig_column_name, &orig_column_flag, orig_column_names,
692 delete_column, delete_columns,
693 retain_column, retain_columns,
694 rename_column, rename_columns,
695 edit_column_request, edit_column_requests)))
704 fprintf(stderr,
"processing name options\n");
706 if (orig_parameter_names &&
707 !(new_parameter_name = process_name_options(orig_parameter_name, &orig_parameter_flag, orig_parameter_names,
708 delete_parameter, delete_parameters,
709 retain_parameter, retain_parameters,
710 rename_parameter, rename_parameters,
711 edit_parameter_request, edit_parameter_requests)))
718 if (orig_array_names &&
719 !(new_array_name = process_name_options(orig_array_name, &orig_array_flag, orig_array_names,
720 delete_array, delete_arrays,
721 retain_array, retain_arrays,
722 rename_array, rename_arrays,
723 edit_array_request, edit_array_requests)))
727 for (i = 0; i < orig_parameter_names; i++)
728 fprintf(stderr,
"parameter %s goes to %s\n", orig_parameter_name[i],
729 orig_parameter_flag[i] ? new_parameter_name[i] :
"<deleted>");
730 for (i = 0; i < orig_array_names; i++)
731 fprintf(stderr,
"array %s goes to %s\n", orig_array_name[i],
732 orig_array_flag[i] ? new_array_name[i] :
"<deleted>");
733 for (i = 0; i < orig_column_names; i++)
734 fprintf(stderr,
"column %s goes to %s\n", orig_column_name[i],
735 orig_column_flag[i] ? new_column_name[i] :
"<deleted>");
739 fprintf(stderr,
"Transferring definitions to new file\n");
741 for (i = 0; i < orig_parameter_names; i++) {
742 if (orig_parameter_flag[i]) {
744 orig_parameter_name[i], new_parameter_name[i])) {
745 fprintf(stderr,
"unable to transfer parameter %s to %s\n",
746 orig_parameter_name[i], new_parameter_name[i]);
752 for (i = 0; i < orig_array_names; i++) {
753 if (orig_array_flag[i]) {
755 orig_array_name[i], new_array_name[i])) {
756 fprintf(stderr,
"unable to transfer array %s to %s\n",
757 orig_array_name[i], new_array_name[i]);
764 for (i = 0; i < orig_column_names; i++) {
765 if (orig_column_flag[i]) {
768 orig_column_name[i], new_column_name[i])) {
769 fprintf(stderr,
"unable to transfer column %s to %s\n",
770 orig_column_name[i], new_column_name[i]);
778 fprintf(stderr,
"Writing layout.\n");
789 buffer =
tmalloc(max_size *
sizeof(
char));
793 fprintf(stderr,
"Reading file\n");
795 while (!recovered && (pageNumber =
SDDS_ReadPage(&SDDS_orig)) >= 0) {
796 if (pageNumber == 0) {
798 fprintf(stderr,
"error: SDDS data garbled--consider using -recover option\n");
799 fprintf(stderr,
"warning: one or more data pages may be missing\n");
806 fprintf(stderr,
"warning: unable to recover data--pages may be missing\n");
811 if (fromPage && pageNumber < fromPage)
815 for (i = 0; i < removePages; i++) {
816 if (removePage[i] == pageNumber) {
826 for (i = 0; i < keepPages; i++) {
827 if (keepPage[i] == pageNumber) {
835 if ((rows = SDDS_RowCount(&SDDS_orig)) < 0) {
836 fprintf(stderr,
"error: problem counting rows in input page\n");
841 fprintf(stderr,
"error: problem starting output page\n");
846 if (!set_units_conversion(&SDDS_orig, convert_units_array, convert_units_arrays,
847 convert_units_column, convert_units_columns,
848 convert_units_parameter, convert_units_parameters)) {
853 for (i = 0; i < orig_parameter_names; i++) {
854 if (orig_parameter_flag[i]) {
856 fprintf(stderr,
"error: problem getting parameter %s\n", orig_parameter_name[i]);
861 new_parameter_name[i], buffer, NULL)) {
862 fprintf(stderr,
"error: problem setting parameter %s\n", new_parameter_name[i]);
868 for (i = 0; i < orig_array_names; i++) {
870 if (orig_array_flag[i]) {
871 if (!(array =
SDDS_GetArray(&SDDS_orig, orig_array_name[i], NULL))) {
872 fprintf(stderr,
"error: problem getting array %s\n", orig_array_name[i]);
876 if (!
SDDS_SetArray(&SDDS_dataset, new_array_name[i], SDDS_CONTIGUOUS_DATA,
877 array->data, array->dimension)) {
878 fprintf(stderr,
"error: problem setting array %s\n", new_array_name[i]);
887 for (i = 0; i < orig_column_names; i++) {
888 if (orig_column_flag[i]) {
890 fprintf(stderr,
"error: problem getting column %s\n", orig_column_name[i]);
894 if (!
SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, ptr, rows, new_column_name[i])) {
895 fprintf(stderr,
"error: problem setting column %s\n", new_column_name[i]);
903 fprintf(stderr,
"error: problem writing page to file %s\n", output);
907 if (toPage && pageNumber >= toPage)
919 for (i = 0; i < orig_parameter_names; i++) {
920 if (orig_parameter_name[i])
921 free(orig_parameter_name[i]);
922 if (new_parameter_name[i])
923 free(new_parameter_name[i]);
925 if (orig_parameter_name)
926 free(orig_parameter_name);
927 if (new_parameter_name)
928 free(new_parameter_name);
929 if (orig_parameter_flag)
930 free(orig_parameter_flag);
932 for (i = 0; i < orig_column_names; i++) {
933 if (orig_column_name[i])
934 free(orig_column_name[i]);
935 if (new_column_name[i])
936 free(new_column_name[i]);
938 if (orig_column_name)
939 free(orig_column_name);
941 free(new_column_name);
942 if (orig_column_flag)
943 free(orig_column_flag);
945 for (i = 0; i < orig_array_names; i++) {
946 if (orig_array_name[i])
947 free(orig_array_name[i]);
948 if (new_array_name[i])
949 free(new_array_name[i]);
952 free(orig_array_name);
954 free(new_array_name);
956 free(orig_array_flag);
961static char **process_name_options(
char **orig_name,
long **orig_flag,
long orig_names,
962 char **
delete,
long deletes,
char **retain,
long retains,
963 STRING_PAIR *rename,
long renames,
969 *orig_flag =
tmalloc(
sizeof(**orig_flag) * orig_names);
970 for (i = 0; i < orig_names; i++)
974 for (i = 0; i < deletes; i++) {
979 for (j = 0; j < orig_names; j++) {
980 for (i = 0; i < deletes; i++) {
990 for (i = 0; i < retains; i++) {
996 for (j = 0; j < orig_names; j++)
998 for (j = 0; j < orig_names; j++) {
1001 for (i = 0; i < retains; i++) {
1003 (*orig_flag)[j] = 1;
1010 new_name =
tmalloc(
sizeof(*new_name) * orig_names);
1011 for (j = 0; j < orig_names; j++) {
1012 for (i = 0; i < renames; i++) {
1013 if (strcmp(rename[i][0], orig_name[j]) == 0) {
1020 for (i = 0; i < edit_requests; i++) {
1021 char edit_buffer[256];
1024 edit_request[i].match_string = ptr;
1026 strcpy(edit_buffer, new_name[j]);
1027 if (!edit_string(edit_buffer, edit_request[i].edit_string))
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
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_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
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_SetNameValidityFlags(uint32_t flags)
Sets the validity flags for parameter and column names in 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.
void SDDS_FreeArray(SDDS_ARRAY *array)
Frees memory allocated for an SDDS array structure.
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.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
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.
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.
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.