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

Program to copy and manipulate SDDS files. More...

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

Go to the source code of this file.

Classes

struct  EDIT_NAME_REQUEST
 
struct  CONVERT_UNITS
 

Macros

#define COLUMN_MODE   0
 
#define PARAMETER_MODE   1
 
#define ARRAY_MODE   2
 
#define MODES   3
 
#define SET_BINARY   0
 
#define SET_ASCII   1
 
#define SET_DELETE   2
 
#define SET_RETAIN   3
 
#define SET_RENAME   4
 
#define SET_DESCRIPTION   5
 
#define SET_TABLE   6
 
#define SET_EDIT_NAMES   7
 
#define SET_LINES_PER_ROW   8
 
#define SET_NOWARNINGS   9
 
#define SET_RECOVER   10
 
#define SET_PIPE   11
 
#define SET_FROMPAGE   12
 
#define SET_TOPAGE   13
 
#define SET_ACCEPT_ALL_NAMES   14
 
#define SET_REMOVEPAGES   15
 
#define SET_KEEPPAGES   16
 
#define SET_ROWLIMIT   17
 
#define SET_MAJOR_ORDER   18
 
#define SET_CONVERT_UNITS   19
 
#define N_OPTIONS   20
 

Typedefs

typedef char * STRING_PAIR[2]
 

Functions

static char ** process_name_options (char **orig_name, long **orig_flag, long orig_names, char **delete, long deletes, char **retain, long retains, STRING_PAIR *rename, long renames, EDIT_NAME_REQUEST *edit_request, long edit_requests)
 
static int set_units_conversion (SDDS_DATASET *SDDS_orig, CONVERT_UNITS *convert_units_array, long convert_units_arrays, CONVERT_UNITS *convert_units_column, long convert_units_columns, CONVERT_UNITS *convert_units_parameter, long convert_units_parameters)
 
int main (int argc, char **argv)
 

Variables

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

Detailed Description

Program to copy and manipulate SDDS files.

This utility copies an SDDS (Self Describing Data Set) file and provides various operations:

  • Conversion between ASCII and binary formats.
  • Filtering of columns, parameters, or arrays using wildcard patterns.
  • Renaming SDDS elements such as columns, parameters, and arrays.
  • Converting units for specified elements.
  • Configuring output data layout and other properties.

Users can also selectively remove or retain pages, rename elements, and apply additional transformations using command-line options.

@usage

sddsconvert [<source-file>] [<target-file>]
[-pipe=[input][,output]]
[-binary] [-ascii] [-description=<text>,<contents>]
[-fromPage=<pageNumber>] [-toPage=<pageNumber>]
[-removePages=<listOfNumbers>] [-keepPages=<listOfNumbers>]
[-linesperrow=<integer>] [-nowarnings] [-recover[=clip]]
[-delete={column|parameter|array},<matching-string>[,...]]
[-retain={column|parameter|array},<matching-string>[,...]]
[-rename={column|parameter|array},<oldname>=<newname>[,...]]
[-editnames={column|parameter|array},<wildcard-string>,<edit-string>]
[-convertUnits={column|parameter|array},<name>,<new-units>[,<old-units>[,<factor>]]]
[-acceptAllNames] [-rowlimit=<number>]
[-majorOrder=row|column]
Note
  • If a deletion pattern matches an element also matched by a retention pattern, the retention takes precedence.
  • The -acceptAllNames option relaxes naming restrictions in the SDDS library.
  • Page filtering and ordering options allow fine-grained control over data processing.
License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday, H. Shang

Definition in file sddsconvert.c.

Macro Definition Documentation

◆ ARRAY_MODE

#define ARRAY_MODE   2

Definition at line 54 of file sddsconvert.c.

◆ COLUMN_MODE

#define COLUMN_MODE   0

Definition at line 52 of file sddsconvert.c.

◆ MODES

#define MODES   3

Definition at line 55 of file sddsconvert.c.

◆ N_OPTIONS

#define N_OPTIONS   20

Definition at line 83 of file sddsconvert.c.

◆ PARAMETER_MODE

#define PARAMETER_MODE   1

Definition at line 53 of file sddsconvert.c.

◆ SET_ACCEPT_ALL_NAMES

#define SET_ACCEPT_ALL_NAMES   14

Definition at line 77 of file sddsconvert.c.

◆ SET_ASCII

#define SET_ASCII   1

Definition at line 63 of file sddsconvert.c.

◆ SET_BINARY

#define SET_BINARY   0

Definition at line 62 of file sddsconvert.c.

◆ SET_CONVERT_UNITS

#define SET_CONVERT_UNITS   19

Definition at line 82 of file sddsconvert.c.

◆ SET_DELETE

#define SET_DELETE   2

Definition at line 64 of file sddsconvert.c.

◆ SET_DESCRIPTION

#define SET_DESCRIPTION   5

Definition at line 67 of file sddsconvert.c.

◆ SET_EDIT_NAMES

#define SET_EDIT_NAMES   7

Definition at line 70 of file sddsconvert.c.

◆ SET_FROMPAGE

#define SET_FROMPAGE   12

Definition at line 75 of file sddsconvert.c.

◆ SET_KEEPPAGES

#define SET_KEEPPAGES   16

Definition at line 79 of file sddsconvert.c.

◆ SET_LINES_PER_ROW

#define SET_LINES_PER_ROW   8

Definition at line 71 of file sddsconvert.c.

◆ SET_MAJOR_ORDER

#define SET_MAJOR_ORDER   18

Definition at line 81 of file sddsconvert.c.

◆ SET_NOWARNINGS

#define SET_NOWARNINGS   9

Definition at line 72 of file sddsconvert.c.

◆ SET_PIPE

#define SET_PIPE   11

Definition at line 74 of file sddsconvert.c.

◆ SET_RECOVER

#define SET_RECOVER   10

Definition at line 73 of file sddsconvert.c.

◆ SET_REMOVEPAGES

#define SET_REMOVEPAGES   15

Definition at line 78 of file sddsconvert.c.

◆ SET_RENAME

#define SET_RENAME   4

Definition at line 66 of file sddsconvert.c.

◆ SET_RETAIN

#define SET_RETAIN   3

Definition at line 65 of file sddsconvert.c.

◆ SET_ROWLIMIT

#define SET_ROWLIMIT   17

Definition at line 80 of file sddsconvert.c.

◆ SET_TABLE

#define SET_TABLE   6

Definition at line 69 of file sddsconvert.c.

◆ SET_TOPAGE

#define SET_TOPAGE   13

Definition at line 76 of file sddsconvert.c.

Typedef Documentation

◆ STRING_PAIR

typedef char* STRING_PAIR[2]

Definition at line 125 of file sddsconvert.c.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 173 of file sddsconvert.c.

173 {
174 SDDS_DATASET SDDS_dataset, SDDS_orig;
175 long i, i_arg;
176 SCANNED_ARG *s_arg;
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;
182
183 char **retain_column, **delete_column;
184 long retain_columns, delete_columns, rename_columns, edit_column_requests;
185 EDIT_NAME_REQUEST *edit_column_request;
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;
190
191 char **retain_parameter, **delete_parameter;
192 long retain_parameters, delete_parameters, rename_parameters, edit_parameter_requests;
193 EDIT_NAME_REQUEST *edit_parameter_request;
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;
198
199 char **retain_array, **delete_array;
200 long retain_arrays, delete_arrays, rename_arrays, edit_array_requests;
201 EDIT_NAME_REQUEST *edit_array_request;
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;
206
207 long lines_per_row, pageNumber = 0, fromPage, toPage;
208 int64_t rows;
209 long max_size, output_columns;
210 long *removePage, *keepPage;
211 long removePages, keepPages, keep;
212 int64_t rowLimit;
213 short column_major = -1;
214
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;
217
218 new_column_name = new_parameter_name = new_array_name = NULL;
219
221 argc = scanargs(&s_arg, argc, argv);
222 if (argc < 3) {
223 fprintf(stderr, "%s\n", USAGE);
224 return 1;
225 }
226 input = output = NULL;
227 ascii_output = binary_output = noWarnings = 0;
228
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;
233
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;
238
239 retain_array = delete_array = NULL;
240 retain_arrays = delete_arrays = rename_arrays = edit_array_requests = 0;
241 rename_array = NULL;
242 edit_array_request = NULL;
243
244 tmpfile_used = 0;
245 description_text = description_contents = NULL;
246 fromPage = toPage = recover = 0;
247 removePage = keepPage = NULL;
248 removePages = keepPages = 0;
249 lines_per_row = 1;
250 pipeFlags = 0;
251
252 for (i_arg = 1; i_arg < argc; i_arg++) {
253 if (s_arg[i_arg].arg_type == OPTION) {
254 delete_chars(s_arg[i_arg].list[0], "_");
255 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
256 case SET_MAJOR_ORDER:
257 majorOrderFlag = 0;
258 s_arg[i_arg].n_items -= 1;
259 if (s_arg[i_arg].n_items > 0 &&
260 (!scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1,
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,
264 NULL)))
265 SDDS_Bomb("invalid -majorOrder syntax/values");
266 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
267 column_major = 1;
268 if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
269 column_major = 0;
270 break;
271 case SET_BINARY:
272 binary_output = 1;
273 ascii_output = 0;
274 break;
275 case SET_ASCII:
276 ascii_output = 1;
277 binary_output = 0;
278 break;
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]);
283 return 1;
284 }
285 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
286 case ARRAY_MODE:
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];
293 else
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]);
299 return 1;
300 }
301 } else
302 convert_units_array[convert_units_arrays].factor = 1.0;
303 convert_units_arrays++;
304 break;
305 case COLUMN_MODE:
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];
312 else
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]);
318 return 1;
319 }
320 } else
321 convert_units_column[convert_units_columns].factor = 1.0;
322 convert_units_columns++;
323 break;
324 case PARAMETER_MODE:
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];
331 else
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]);
337 return 1;
338 }
339 } else
340 convert_units_parameter[convert_units_parameters].factor = 1.0;
341 convert_units_parameters++;
342 break;
343 default:
344 fprintf(stderr, "Error (%s): invalid -convertUnits syntax: specify column, parameter or array\n", argv[0]);
345 return 1;
346 }
347 break;
348 case SET_DELETE:
349 if (s_arg[i_arg].n_items < 3) {
350 fprintf(stderr, "Error (%s): invalid -delete syntax\n", argv[0]);
351 return 1;
352 }
353 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
354 case COLUMN_MODE:
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;
360 break;
361 case PARAMETER_MODE:
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;
367 break;
368 case ARRAY_MODE:
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;
374 break;
375 default:
376 fprintf(stderr, "Error (%s): invalid -delete syntax: specify column, parameter or array\n", argv[0]);
377 return 1;
378 }
379 break;
380 case SET_RETAIN:
381 if (s_arg[i_arg].n_items < 3) {
382 fprintf(stderr, "Error (%s): invalid -retain syntax\n", argv[0]);
383 return 1;
384 }
385 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
386 case COLUMN_MODE:
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;
392 break;
393 case PARAMETER_MODE:
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;
399 break;
400 case ARRAY_MODE:
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;
406 break;
407 default:
408 fprintf(stderr, "Error (%s): invalid -retain syntax: specify column, parameter or array\n", argv[0]);
409 return 1;
410 }
411 break;
412 case SET_RENAME:
413 if (s_arg[i_arg].n_items < 3) {
414 fprintf(stderr, "Error (%s): invalid -rename syntax\n", argv[0]);
415 return 1;
416 }
417 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
418 case COLUMN_MODE:
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]);
424 return 1;
425 }
426 *ptr++ = 0;
427 rename_column[i - 2 + rename_columns][0] = s_arg[i_arg].list[i];
428 rename_column[i - 2 + rename_columns][1] = ptr;
429 }
430 rename_columns += s_arg[i_arg].n_items - 2;
431 break;
432 case PARAMETER_MODE:
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]);
438 return 1;
439 }
440 *ptr++ = 0;
441 rename_parameter[i - 2 + rename_parameters][0] = s_arg[i_arg].list[i];
442 rename_parameter[i - 2 + rename_parameters][1] = ptr;
443 }
444 rename_parameters += s_arg[i_arg].n_items - 2;
445 break;
446 case ARRAY_MODE:
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]);
452 return 1;
453 }
454 *ptr++ = 0;
455 rename_array[i - 2 + rename_arrays][0] = s_arg[i_arg].list[i];
456 rename_array[i - 2 + rename_arrays][1] = ptr;
457 }
458 rename_arrays += s_arg[i_arg].n_items - 2;
459 break;
460 default:
461 fprintf(stderr, "Error (%s): invalid -rename syntax: specify column, parameter or array\n", argv[0]);
462 return 1;
463 }
464 break;
465 case SET_DESCRIPTION:
466 if (s_arg[i_arg].n_items != 3) {
467 fprintf(stderr, "Error (%s): invalid -description syntax\n", argv[0]);
468 return 1;
469 }
470 description_text = s_arg[i_arg].list[1];
471 description_contents = s_arg[i_arg].list[2];
472 break;
473 case SET_TABLE:
474 if (s_arg[i_arg].n_items < 2) {
475 fprintf(stderr, "Error (%s): invalid -table syntax\n", argv[0]);
476 return 1;
477 }
478 if (pageNumber != 0) {
479 fprintf(stderr, "Error (%s): specify -table once only\n", argv[0]);
480 return 1;
481 }
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]);
484 return 1;
485 }
486 fromPage = toPage = pageNumber;
487 break;
488 case SET_FROMPAGE:
489 if (s_arg[i_arg].n_items < 2) {
490 fprintf(stderr, "Error (%s): invalid -fromPage syntax\n", argv[0]);
491 return 1;
492 }
493 if (fromPage != 0) {
494 fprintf(stderr, "Error (%s): specify -fromPage once only\n", argv[0]);
495 return 1;
496 }
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]);
499 return 1;
500 }
501 break;
502 case SET_TOPAGE:
503 if (s_arg[i_arg].n_items < 2) {
504 fprintf(stderr, "Error (%s): invalid -toPage syntax\n", argv[0]);
505 return 1;
506 }
507 if (toPage != 0) {
508 fprintf(stderr, "Error (%s): specify -toPage once only\n", argv[0]);
509 return 1;
510 }
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]);
513 return 1;
514 }
515 break;
516 case SET_REMOVEPAGES:
517 if (s_arg[i_arg].n_items < 2) {
518 fprintf(stderr, "Error (%s): invalid -removePages syntax\n", argv[0]);
519 return 1;
520 }
521 if (removePage != NULL) {
522 fprintf(stderr, "Error (%s): specify -removePages once only\n", argv[0]);
523 return 1;
524 }
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]);
530 return 1;
531 }
532 }
533 break;
534 case SET_KEEPPAGES:
535 if (s_arg[i_arg].n_items < 2) {
536 fprintf(stderr, "Error (%s): invalid -keepPages syntax\n", argv[0]);
537 return 1;
538 }
539 if (keepPage != NULL) {
540 fprintf(stderr, "Error (%s): specify -keepPages once only\n", argv[0]);
541 return 1;
542 }
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]);
548 return 1;
549 }
550 }
551 break;
552 case SET_EDIT_NAMES:
553 if (s_arg[i_arg].n_items < 4) {
554 fprintf(stderr, "Error (%s): invalid -editnames syntax\n", argv[0]);
555 return 1;
556 }
557 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
558 case COLUMN_MODE:
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++;
564 break;
565 case PARAMETER_MODE:
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++;
571 break;
572 case ARRAY_MODE:
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++;
578 break;
579 default:
580 fprintf(stderr, "Error (%s): invalid -editnames syntax\n", argv[0]);
581 return 1;
582 }
583 break;
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]);
589 return 1;
590 }
591 break;
592 case SET_NOWARNINGS:
593 if (s_arg[i_arg].n_items != 1) {
594 fprintf(stderr, "Error (%s): invalid -nowarnings syntax\n", argv[0]);
595 return 1;
596 }
597 noWarnings = 1;
598 break;
599 case SET_RECOVER:
600 recover = 1;
601 if (s_arg[i_arg].n_items != 1) {
602 recover = 2;
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]);
606 return 1;
607 }
608 }
609 break;
610 case SET_PIPE:
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]);
613 return 1;
614 }
615 break;
616 case SET_ACCEPT_ALL_NAMES:
617 SDDS_SetNameValidityFlags(SDDS_ALLOW_ANY_NAME);
618 break;
619 case SET_ROWLIMIT:
620 if (s_arg[i_arg].n_items != 2 ||
621 sscanf(s_arg[i_arg].list[1], "%" SCNd64, &rowLimit) != 1 ||
622 rowLimit < 0) {
623 fprintf(stderr, "Error (%s): invalid -rowLimit syntax\n", argv[0]);
624 return 1;
625 }
626 SDDS_SetRowLimit(rowLimit);
627 break;
628 default:
629 fprintf(stderr, "Error (%s): unknown switch: %s\n", argv[0], s_arg[i_arg].list[0]);
630 return 1;
631 }
632 } else {
633 if (input == NULL)
634 input = s_arg[i_arg].list[0];
635 else if (output == NULL)
636 output = s_arg[i_arg].list[0];
637 else {
638 fprintf(stderr, "Error (%s): too many filenames\n", argv[0]);
639 return 1;
640 }
641 }
642 }
643
644 if (fromPage && toPage && fromPage > toPage) {
645 fprintf(stderr, "Error (%s): invalid -fromPage and -toPage\n", argv[0]);
646 return 1;
647 }
648
649 processFilenames("sddsconvert", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
650
651#ifdef DEBUG
652 fprintf(stderr, "Initializing input and output files.\n");
653#endif
654 if (!SDDS_InitializeInput(&SDDS_orig, input)) {
655 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
656 return 1;
657 }
658
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)) {
662 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
663 return 1;
664 }
665
666 if (!description_text)
667 SDDS_GetDescription(&SDDS_orig, &description_text, &description_contents);
668
669 if (!SDDS_InitializeOutput(&SDDS_dataset,
670 ascii_output ? SDDS_ASCII : (binary_output ? SDDS_BINARY : SDDS_orig.layout.data_mode.mode),
671 lines_per_row, description_text, description_contents, output)) {
672 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
673 return 1;
674 }
675
676 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
677
678 if (column_major != -1)
679 SDDS_dataset.layout.data_mode.column_major = column_major;
680 else
681 SDDS_dataset.layout.data_mode.column_major = SDDS_orig.layout.data_mode.column_major;
682
683#ifdef DEBUG
684 fprintf(stderr, "Getting column, parameter, and array names from input file.\n");
685#endif
686 if (!(orig_column_name = SDDS_GetColumnNames(&SDDS_orig, &orig_column_names))) {
687 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
688 return 1;
689 }
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)))
696 return 1;
697
698 if (!(orig_parameter_name = SDDS_GetParameterNames(&SDDS_orig, &orig_parameter_names))) {
699 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
700 return 1;
701 }
702
703#ifdef DEBUG
704 fprintf(stderr, "processing name options\n");
705#endif
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)))
712 return 1;
713
714 if (!(orig_array_name = SDDS_GetArrayNames(&SDDS_orig, &orig_array_names))) {
715 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
716 return 1;
717 }
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)))
724 return 1;
725
726#ifdef DEBUG
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>");
736#endif
737
738#ifdef DEBUG
739 fprintf(stderr, "Transferring definitions to new file\n");
740#endif
741 for (i = 0; i < orig_parameter_names; i++) {
742 if (orig_parameter_flag[i]) {
743 if (!SDDS_TransferParameterDefinition(&SDDS_dataset, &SDDS_orig,
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]);
747 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
748 return 1;
749 }
750 }
751 }
752 for (i = 0; i < orig_array_names; i++) {
753 if (orig_array_flag[i]) {
754 if (!SDDS_TransferArrayDefinition(&SDDS_dataset, &SDDS_orig,
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]);
758 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
759 return 1;
760 }
761 }
762 }
763 output_columns = 0;
764 for (i = 0; i < orig_column_names; i++) {
765 if (orig_column_flag[i]) {
766 output_columns++;
767 if (!SDDS_TransferColumnDefinition(&SDDS_dataset, &SDDS_orig,
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]);
771 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
772 return 1;
773 }
774 }
775 }
776
777#ifdef DEBUG
778 fprintf(stderr, "Writing layout.\n");
779#endif
780 if (!SDDS_WriteLayout(&SDDS_dataset)) {
781 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
782 return 1;
783 }
784
785 max_size = 0;
786 for (i = 0; i < SDDS_NUM_TYPES; i++)
787 if (max_size < SDDS_type_size[i])
788 max_size = SDDS_type_size[i];
789 buffer = tmalloc(max_size * sizeof(char));
790
791 recovered = 0;
792#ifdef DEBUG
793 fprintf(stderr, "Reading file\n");
794#endif
795 while (!recovered && (pageNumber = SDDS_ReadPage(&SDDS_orig)) >= 0) {
796 if (pageNumber == 0) {
797 if (!recover) {
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");
800 break;
801 } else {
802 if (recover != 2 && SDDS_ReadRecoveryPossible(&SDDS_orig))
803 recovered = 1;
804 else {
805 if (recover != 2)
806 fprintf(stderr, "warning: unable to recover data--pages may be missing\n");
807 break;
808 }
809 }
810 }
811 if (fromPage && pageNumber < fromPage)
812 continue;
813 if (removePages) {
814 keep = 1;
815 for (i = 0; i < removePages; i++) {
816 if (removePage[i] == pageNumber) {
817 keep = 0;
818 break;
819 }
820 }
821 if (!keep)
822 continue;
823 }
824 if (keepPages) {
825 keep = 0;
826 for (i = 0; i < keepPages; i++) {
827 if (keepPage[i] == pageNumber) {
828 keep = 1;
829 break;
830 }
831 }
832 if (!keep)
833 continue;
834 }
835 if ((rows = SDDS_RowCount(&SDDS_orig)) < 0) {
836 fprintf(stderr, "error: problem counting rows in input page\n");
837 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
838 return 1;
839 }
840 if (!SDDS_StartPage(&SDDS_dataset, rows)) {
841 fprintf(stderr, "error: problem starting output page\n");
842 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
843 return 1;
844 }
845
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)) {
849 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
850 return 1;
851 }
852
853 for (i = 0; i < orig_parameter_names; i++) {
854 if (orig_parameter_flag[i]) {
855 if (!SDDS_GetParameter(&SDDS_orig, orig_parameter_name[i], buffer)) {
856 fprintf(stderr, "error: problem getting parameter %s\n", orig_parameter_name[i]);
857 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
858 return 1;
859 }
860 if (!SDDS_SetParameters(&SDDS_dataset, SDDS_SET_BY_NAME | SDDS_PASS_BY_REFERENCE,
861 new_parameter_name[i], buffer, NULL)) {
862 fprintf(stderr, "error: problem setting parameter %s\n", new_parameter_name[i]);
863 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
864 return 1;
865 }
866 }
867 }
868 for (i = 0; i < orig_array_names; i++) {
869 SDDS_ARRAY *array;
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]);
873 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
874 return 1;
875 }
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]);
879 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
880 return 1;
881 }
882 SDDS_FreeArray(array);
883 }
884 }
885
886 if (SDDS_CountRowsOfInterest(&SDDS_orig)) {
887 for (i = 0; i < orig_column_names; i++) {
888 if (orig_column_flag[i]) {
889 if (!(ptr = SDDS_GetInternalColumn(&SDDS_orig, orig_column_name[i]))) {
890 fprintf(stderr, "error: problem getting column %s\n", orig_column_name[i]);
891 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
892 return 1;
893 }
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]);
896 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
897 return 1;
898 }
899 }
900 }
901 }
902 if (!SDDS_WritePage(&SDDS_dataset)) {
903 fprintf(stderr, "error: problem writing page to file %s\n", output);
904 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
905 return 1;
906 }
907 if (toPage && pageNumber >= toPage)
908 break;
909 }
910
911 if (!SDDS_Terminate(&SDDS_orig) || !SDDS_Terminate(&SDDS_dataset)) {
912 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
913 return 1;
914 }
915
916 if (tmpfile_used && !replaceFileAndBackUp(input, output))
917 return 1;
918
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]);
924 }
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);
931
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]);
937 }
938 if (orig_column_name)
939 free(orig_column_name);
940 if (new_column_name)
941 free(new_column_name);
942 if (orig_column_flag)
943 free(orig_column_flag);
944
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]);
950 }
951 if (orig_array_name)
952 free(orig_array_name);
953 if (new_array_name)
954 free(new_array_name);
955 if (orig_array_flag)
956 free(orig_array_flag);
957
958 return 0;
959}
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.
Definition SDDS_data.c:62
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.
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
SDDS_ARRAY * SDDS_GetArray(SDDS_DATASET *SDDS_dataset, char *array_name, SDDS_ARRAY *memory)
Retrieves an array from the current data table of an SDDS dataset.
void * SDDS_GetInternalColumn(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves an internal pointer to the data of a specified column, including all rows.
void * SDDS_GetParameter(SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
Retrieves the value of a specified parameter from the current data table of a data set.
int32_t SDDS_GetDescription(SDDS_DATASET *SDDS_dataset, char **text, char **contents)
Retrieves the text and contents descriptions from an SDDS dataset.
int64_t SDDS_SetRowLimit(int64_t limit)
int32_t SDDS_InitializeInput(SDDS_DATASET *SDDS_dataset, char *filename)
Definition SDDS_input.c:49
int32_t SDDS_Terminate(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_ReadPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
int32_t SDDS_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.
Definition SDDS_utils.c:432
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
char ** SDDS_GetArrayNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all arrays in the SDDS dataset.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
Definition SDDStypes.h:97
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
Definition replacefile.c:75
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
Definition scanargs.c:36
long processPipeOption(char **item, long items, unsigned long *flags)
Definition scanargs.c:356
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
Definition scanargs.c:390
long scanItemList(unsigned long *flags, char **item, long *items, unsigned long mode,...)
Scans a list of items and assigns values based on provided keywords and types.

◆ process_name_options()

static char ** process_name_options ( char ** orig_name,
long ** orig_flag,
long orig_names,
char ** delete,
long deletes,
char ** retain,
long retains,
STRING_PAIR * rename,
long renames,
EDIT_NAME_REQUEST * edit_request,
long edit_requests )
static

Definition at line 961 of file sddsconvert.c.

964 {
965 long i, j;
966 char **new_name;
967 char *ptr;
968
969 *orig_flag = tmalloc(sizeof(**orig_flag) * orig_names);
970 for (i = 0; i < orig_names; i++)
971 (*orig_flag)[i] = 1;
972
973 if (deletes) {
974 for (i = 0; i < deletes; i++) {
975 ptr = expand_ranges(delete[i]);
976 free(delete[i]);
977 delete[i] = ptr;
978 }
979 for (j = 0; j < orig_names; j++) {
980 for (i = 0; i < deletes; i++) {
981 if (wild_match(orig_name[j], delete[i])) {
982 (*orig_flag)[j] = 0;
983 break;
984 }
985 }
986 }
987 }
988
989 if (retains) {
990 for (i = 0; i < retains; i++) {
991 ptr = expand_ranges(retain[i]);
992 free(retain[i]);
993 retain[i] = ptr;
994 }
995 if (!deletes)
996 for (j = 0; j < orig_names; j++)
997 (*orig_flag)[j] = 0;
998 for (j = 0; j < orig_names; j++) {
999 if ((*orig_flag)[j])
1000 continue;
1001 for (i = 0; i < retains; i++) {
1002 if (wild_match(orig_name[j], retain[i])) {
1003 (*orig_flag)[j] = 1;
1004 break;
1005 }
1006 }
1007 }
1008 }
1009
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) {
1014 SDDS_CopyString(new_name + j, rename[i][1]);
1015 break;
1016 }
1017 }
1018 if (i == renames)
1019 SDDS_CopyString(new_name + j, orig_name[j]);
1020 for (i = 0; i < edit_requests; i++) {
1021 char edit_buffer[256];
1022 ptr = expand_ranges(edit_request[i].match_string);
1023 free(edit_request[i].match_string);
1024 edit_request[i].match_string = ptr;
1025 if (wild_match(new_name[j], edit_request[i].match_string)) {
1026 strcpy(edit_buffer, new_name[j]);
1027 if (!edit_string(edit_buffer, edit_request[i].edit_string))
1028 SDDS_Bomb("error editing name");
1029 free(new_name[j]);
1030 SDDS_CopyString(&new_name[j], edit_buffer);
1031 }
1032 }
1033 }
1034
1035 return new_name;
1036}
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
Definition SDDS_utils.c:856
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
Definition wild_match.c:429
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
Definition wild_match.c:49

◆ set_units_conversion()

static int set_units_conversion ( SDDS_DATASET * SDDS_orig,
CONVERT_UNITS * convert_units_array,
long convert_units_arrays,
CONVERT_UNITS * convert_units_column,
long convert_units_columns,
CONVERT_UNITS * convert_units_parameter,
long convert_units_parameters )
static

Definition at line 144 of file sddsconvert.c.

147 {
148 long i;
149 for (i = 0; i < convert_units_arrays; i++) {
150 if (SDDS_SetArrayUnitsConversion(SDDS_orig, convert_units_array[i].name,
151 convert_units_array[i].new_units,
152 convert_units_array[i].old_units,
153 convert_units_array[i].factor) == 0)
154 return 0;
155 }
156 for (i = 0; i < convert_units_columns; i++) {
157 if (SDDS_SetColumnUnitsConversion(SDDS_orig, convert_units_column[i].name,
158 convert_units_column[i].new_units,
159 convert_units_column[i].old_units,
160 convert_units_column[i].factor) == 0)
161 return 0;
162 }
163 for (i = 0; i < convert_units_parameters; i++) {
164 if (SDDS_SetParameterUnitsConversion(SDDS_orig, convert_units_parameter[i].name,
165 convert_units_parameter[i].new_units,
166 convert_units_parameter[i].old_units,
167 convert_units_parameter[i].factor) == 0)
168 return 0;
169 }
170 return 1;
171}
int32_t SDDS_SetParameterUnitsConversion(SDDS_DATASET *SDDS_dataset, char *parameter_name, char *new_units, char *old_units, double factor)
Sets unit conversions for a specified parameter in an SDDS dataset.
int32_t SDDS_SetColumnUnitsConversion(SDDS_DATASET *SDDS_dataset, char *column_name, char *new_units, char *old_units, double factor)
Sets unit conversions for a specified column in an SDDS dataset.
int32_t SDDS_SetArrayUnitsConversion(SDDS_DATASET *SDDS_dataset, char *array_name, char *new_units, char *old_units, double factor)
Sets unit conversions for a specified array in an SDDS dataset.

Variable Documentation

◆ mode_name

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

Definition at line 56 of file sddsconvert.c.

56 {
57 "column",
58 "parameter",
59 "array",
60};

◆ option

char* option[N_OPTIONS]
Initial value:
= {
"binary",
"ascii",
"delete",
"retain",
"rename",
"description",
"table",
"editnames",
"linesperrow",
"nowarnings",
"recover",
"pipe",
"frompage",
"topage",
"acceptallnames",
"removepages",
"keeppages",
"rowlimit",
"majororder",
"convertunits"}

Definition at line 85 of file sddsconvert.c.

85 {
86 "binary",
87 "ascii",
88 "delete",
89 "retain",
90 "rename",
91 "description",
92 "table",
93 "editnames",
94 "linesperrow",
95 "nowarnings",
96 "recover",
97 "pipe",
98 "frompage",
99 "topage",
100 "acceptallnames",
101 "removepages",
102 "keeppages",
103 "rowlimit",
104 "majororder",
105 "convertunits"};

◆ USAGE

char* USAGE
Initial value:
= "sddsconvert [<source-file>] [<target-file>]\n\
[-pipe=[input][,output]]\n\
[-binary] [-ascii] [-description=<text>,<contents>]\n\
[-fromPage=<pageNumber>] [-toPage=<pageNumber>]\n\
[-removePages=<listOfNumbers>] [-keepPages=<listOfNumbers>]\n\
[-linesperrow=<integer>] [-nowarnings] [-recover[=clip]]\n\
[-delete={column|parameter|array},<matching-string>[,...]]\n\
[-retain={column|parameter|array},<matching-string>[,...]]\n\
[-rename={column|parameter|array},<oldname>=<newname>[,...]]\n\
[-editnames={column|parameter|array},<wildcard-string>,<edit-string>]\n\
[-convertUnits={column|parameter|array},<name>,<new-units>,[<old-units>[,<factor>]]\n\
[-acceptAllNames] [-rowlimit=<number>]\n\
[-majorOrder=row|column]\n\n\
sddsconvert converts SDDS files between ASCII and binary, and allows wildcard-based filtering.\n\
Any element matched by a deletion string is deleted unless matched by a retention string.\n\
The -acceptAllNames option may force the SDDS library to accept unusual names.\n\
Program by Michael Borland. (" __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n"

Definition at line 107 of file sddsconvert.c.