138#include <sys/types.h>
140# include <sys/time.h>
144#define PARAMETER_MODE 1
147 static char *mode_name[MODES] = {
193char *option[N_OPTIONS] = {
197 "rpndefinitionsfiles",
231char *usageArray[] = {
233 " sddsprocess [<SDDSinputfile>] [<SDDSoutputfile>] [OPTIONS]\n",
236 " -pipe=[input][,output]\n",
237 " Use pipe mode with optional input and output streams.\n",
238 " -ifis={column|parameter},<name>[,...]\n",
239 " Include only the specified columns or parameters.\n",
240 " -ifnot={column|parameter},<name>[,...]\n",
241 " Exclude the specified columns or parameters.\n",
242 " -match={column|parameter},<match-test>[,<match-test>,...]\n",
243 " Filter data based on matching criteria for columns or parameters.\n",
244 " -filter={column|parameter},<range-spec>[,<range-spec>,...]\n",
245 " Apply range-based filtering on specified columns or parameters.\n",
246 " -timeFilter={parameter|column},[,before=YYYY/MM/DD@HH:MM:SS][,after=YYYY/MM/DD@HH:MM:SS][,invert]\n",
247 " Filter data based on time constraints.\n",
248 " -clip=<head>,<tail>,[invert]\n",
249 " Clip the dataset by removing a specified number of rows from the head and tail.\n",
250 " -sparse=<interval>[,<offset>]\n",
251 " Retain every <interval>-th row starting from <offset>.\n",
252 " -sample=<fraction>\n",
253 " Randomly sample rows based on the specified fraction.\n",
254 " -fclip=<head>,<tail>,[invert]\n",
255 " Fractional clipping based on the fraction of rows.\n",
256 " -test={column|parameter},<test>[,autostop][,algebraic]\n",
257 " Apply RPN-based tests on columns or parameters with optional autostop.\n",
258 " -numberTest={column|parameter},<name>[,invert]\n",
259 " Perform numerical tests on specified columns or parameters.\n",
260 " -rpndefinitionsfiles=<filename>[,...]\n",
261 " Specify files containing RPN definitions.\n",
262 " -rpnexpression=<expression>[,repeat][,algebraic]\n",
263 " Define RPN expressions to be evaluated.\n",
264 " -convertunits={column|parameter},<name>,<new-units>,<old-units>[,<factor>]\n",
265 " Convert units of a specified column or parameter.\n",
266 " -define={column|parameter},<name>,{<equation>|@<parameterName>}[,<definition_entries>][,algebraic]\n",
267 " Define new columns or parameters based on equations or existing parameters.\n",
268 " -redefine={column|parameter},<name>,{<equation>|@<parameterName>}[,<definition_entries>][,algebraic]\n",
269 " Redefine existing columns or parameters.\n",
270 " -cast={column|parameter},<newName>,<sourceName>,<newType>\n",
271 " Cast a column or parameter to a new data type.\n",
272 " -scan={column|parameter},<new-name>,<source-name>,<sscanf-string>[,<definition-entries>][,edit=<string>]\n",
273 " Scan and parse data from a source column or parameter.\n",
274 " -edit={column|parameter},<new-name>,<source-name>,<edit-string>[,<definition-entries>]\n",
275 " Edit values of a column or parameter based on specified rules.\n",
276 " -reedit={column|parameter},<name>,<edit-string>[,<definition-entries>]\n",
277 " Re-edit existing columns or parameters.\n",
278 " -print={column|parameter},<new-name>,<sprintf-string>,<source-name>[,...][,<definition-entries>]\n",
279 " Print formatted data from a source to a new column or parameter.\n",
280 " -reprint={column|parameter},<new-name>,<sprintf-string>,<source-name>[,...][,<definition-entries>]\n",
281 " Reprint existing columns or parameters with new formatting.\n",
282 " -format={column|parameter},<new-name>,<source-name>[,stringFormat=<sprintfString>][,doubleFormat=<sprintfString>][,longFormat=<sprintfString>]\n",
283 " Apply formatting to columns or parameters.\n",
284 " -system={column|parameter},<new-name>,<command-name>[,<definition_entries>]\n",
285 " Execute system commands and capture their output.\n",
286 " -evaluate={column|parameter},<new-name>,<expression-name>[,<definition_entries>]\n",
287 " Evaluate expressions to compute new columns or parameters.\n",
288 " -process=<column-name>,<analysis-name>,<result-name>[,description=<string>][,symbol=<string>][,weightBy=<column-name>][,functionOf=<column-name>[,lowerLimit=<value>][,upperLimit=<value>][,position]][,head=<number>][,tail=<number>][fhead=<fraction>][ftail=<fraction>][,topLimit=<value>][,bottomLimit=<value>][,offset=<value>][,factor=<value>][match=<column-name>,value=<string>][,overwrite],[default=<value>]\n",
289 " Perform various processing operations on specified columns.\n",
291 " Display a summary of the processing operations performed.\n",
293 " Enable verbose output for detailed processing information.\n",
295 " Suppress warning messages.\n",
296 " -delete={column|parameter|array},<matching-string>[,...]\n",
297 " Delete specified columns, parameters, or arrays.\n",
298 " -retain={column|parameter|array},<matching-string>[,...]\n",
299 " Retain only the specified columns, parameters, or arrays.\n",
300 " -description=[text=<string>][,contents=<string>]\n",
301 " Add or modify the description of the output SDDS file.\n",
302 " -majorOrder=row|column\n",
303 " Set the major order of the output data (row-major or column-major).\n",
304 " -threads=<number>\n",
305 " Specify the number of threads to use for processing.\n",
307 "Additional Information:\n",
308 " A <match-test> is of the form <name>=<matching-string>[,!], where ! signifies logical negation.\n",
309 " A <logic-operation> is one of & (logical and) or | (logical or), optionally followed by a ! to logically negate the value of the expression.\n",
310 " A <range-spec> is of the form <name>,<lower-value>,<upper-value>[,!].\n",
311 " A <test> is an RPN expression leaving a value on the logic stack.\n",
312 " A <definition-entry> is of the form <entry-name>=<value>, where <entry-name> is one of \"symbol\", \"units\", \"description\", \"format_string\", and \"type\".\n",
315 " sddsprocess reads data from an SDDS file, processes it according to the specified options, and writes the results to a new SDDS file.\n",
316 "Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n",
319#define PARAMETER_OR_COLUMN(is_param) ((is_param) ? "parameter" : "column")
321#define REDEFINABLE_TYPE(type) (SDDS_NUMERIC_TYPE(type) || (type) == SDDS_CHARACTER)
326static long table_number_mem = -1, i_page_mem = -1, n_rows_mem = -1, i_row_mem = -1;
328typedef char *STRING_PAIR[2];
335char **process_name_options(
char **orig_name,
long **orig_flag,
long orig_names,
char **
delete,
long deletes,
336 char **retain,
long retains, STRING_PAIR *rename,
long renames,
338long SDDS_ComputeSetOfColumns(
SDDS_DATASET *SDDS_dataset,
long equ_begin,
long equ_end,
DEFINITION *definition);
344int main(
int argc,
char **argv) {
348 char *description_text, *description_contents;
352 long processing_definitions;
356 long edit_definitions;
358 long equation_definitions;
360 long evaluate_definitions;
362 long scan_definitions;
364 long print_definitions;
366 long format_definitions;
369 long filter_definitions;
371 long time_filter_definitions;
374 long match_definitions;
376 long rpntest_definitions;
378 long numbertest_definitions;
380 long system_definitions;
382 long rpnexpression_definitions;
385 long clip_definitions, fclip_definitions;
387 long sparse_definitions;
389 long sample_definitions;
393 long cast_definitions;
396 char *inputfile, *outputfile;
399 long i, k, i_arg, summarize, verbose, index = 0, tmpfile_used, nowarnings, udfCounter;
400 long page_number, accept;
402 char s[SDDS_MAXLINE];
404 char **rpn_definitions_file, *stringResult;
405 long rpn_definitions_files;
407 long original_parameters;
409 long i_page_memory, table_number_memory, n_rows_memory, row_deletion, skip_page;
410 long random_number_seed;
411 unsigned long pipeFlags, majorOrderFlag;
413 char **retain_column, **delete_column;
414 long retain_columns, delete_columns, rename_columns, edit_column_requests;
416 STRING_PAIR *rename_column;
417 char **orig_column_name, **new_column_name;
418 long *orig_column_flag;
419 int32_t orig_column_names;
421 char **retain_parameter, **delete_parameter;
422 long retain_parameters, delete_parameters, rename_parameters, edit_parameter_requests;
424 STRING_PAIR *rename_parameter;
425 char **orig_parameter_name, **new_parameter_name;
426 long *orig_parameter_flag;
427 int32_t orig_parameter_names;
429 char **retain_array, **delete_array;
430 long retain_arrays, delete_arrays, rename_arrays, edit_array_requests;
432 STRING_PAIR *rename_array;
433 char **orig_array_name, **new_array_name;
434 long *orig_array_flag;
435 int32_t orig_array_names;
436 short columnMajorOrder = -1;
440 char buffer[SDDS_MAXLINE];
444 argc =
scanargs(&s_arg, argc, argv);
445 argc = add_sddsfile_arguments(&s_arg, argc);
447 random_number_seed = (long)time((time_t *)NULL);
448 random_number_seed = 2 * (random_number_seed / 2) + 1;
450 random_1(-labs((
double)random_number_seed));
452 random_1(-FABS((
double)random_number_seed));
455 retain_column = delete_column = NULL;
456 retain_columns = delete_columns = rename_columns = edit_column_requests = 0;
457 rename_column = NULL;
458 edit_column_request = NULL;
460 retain_parameter = delete_parameter = NULL;
461 retain_parameters = delete_parameters = rename_parameters = edit_parameter_requests = 0;
462 rename_parameter = NULL;
463 edit_parameter_request = NULL;
465 retain_array = delete_array = NULL;
466 retain_arrays = delete_arrays = rename_arrays = edit_array_requests = 0;
468 edit_array_request = NULL;
470 description_text = description_contents = NULL;
471 new_parameter_name = new_column_name = new_array_name = NULL;
477 fprintf(stderr,
"%s", *ptr);
480 show_process_modes(stderr);
484 inputfile = outputfile = NULL;
485 rpn_definitions_file = NULL;
486 rpn_definitions_files = 0;
487 summarize = verbose = nowarnings = udfCounter = 0;
489 processing_definition = NULL;
490 processing_definitions = 0;
493 edit_definition = NULL;
494 edit_definitions = 0;
495 equation_definition = NULL;
496 equation_definitions = 0;
497 evaluate_definition = NULL;
498 evaluate_definitions = 0;
499 scan_definition = NULL;
500 scan_definitions = 0;
501 print_definition = NULL;
502 print_definitions = 0;
503 format_definition = NULL;
504 format_definitions = 0;
505 filter_definition = NULL;
506 filter_definitions = 0;
507 time_filter_definition = NULL;
508 time_filter_definitions = 0;
509 match_definition = NULL;
510 match_definitions = 0;
511 rpntest_definition = NULL;
512 rpntest_definitions = 0;
513 numbertest_definition = NULL;
514 numbertest_definitions = 0;
515 system_definition = NULL;
516 system_definitions = 0;
517 rpnexpression_definition = NULL;
518 rpnexpression_definitions = 0;
519 clip_definition = NULL;
520 fclip_definition = NULL;
521 clip_definitions = fclip_definitions = 0;
522 sparse_definition = NULL;
523 sparse_definitions = 0;
524 sample_definition = NULL;
525 sample_definitions = 0;
526 cast_definition = NULL;
527 cast_definitions = 0;
530 ifnot_item.items = 0;
534 for (i_arg = 1; i_arg < argc; i_arg++) {
535 if (s_arg[i_arg].arg_type == OPTION) {
537 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
538 case SET_MAJOR_ORDER:
540 s_arg[i_arg].n_items--;
541 if (s_arg[i_arg].n_items > 0 &&
542 (!
scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
543 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
544 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
545 SDDS_Bomb(
"invalid -majorOrder syntax/values");
546 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
547 columnMajorOrder = 1;
548 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
549 columnMajorOrder = 0;
552 if (s_arg[i_arg].n_items < 3)
554 match_definition = (
MATCH_DEFINITION **)
trealloc(match_definition,
sizeof(*match_definition) * (match_definitions + 1));
555 if (!(match_definition[match_definitions] = process_new_match_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
557 add_definition(&definition, &definitions, (
void *)match_definition[match_definitions], IS_MATCH_DEFINITION);
561 if (s_arg[i_arg].n_items < 3)
563 filter_definition = (
FILTER_DEFINITION **)
trealloc(filter_definition,
sizeof(*filter_definition) * (filter_definitions + 1));
564 if (!(filter_definition[filter_definitions] = process_new_filter_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
566 add_definition(&definition, &definitions, (
void *)filter_definition[filter_definitions], IS_FILTER_DEFINITION);
567 filter_definitions++;
569 case SET_TIME_FILTER:
570 if (s_arg[i_arg].n_items < 3)
573 if (!(time_filter_definition[time_filter_definitions] = process_new_time_filter_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
575 add_definition(&definition, &definitions, (
void *)time_filter_definition[time_filter_definitions], IS_TIME_FILTER_DEFINITION);
576 time_filter_definitions++;
578 case SET_RPN_DEFNS_FILES:
579 if (s_arg[i_arg].n_items < 2)
580 SDDS_Bomb(
"invalid -rpndefinitionsfiles syntax");
581 rpn_definitions_file =
trealloc(rpn_definitions_file,
sizeof(*rpn_definitions_file) * (rpn_definitions_files + s_arg[i_arg].n_items));
582 for (i = 1; i < s_arg[i_arg].n_items; i++)
583 if (!
fexists(rpn_definitions_file[rpn_definitions_files + i - 1] = s_arg[i_arg].list[i]))
584 SDDS_Bomb(
"one or more rpn definitions files do not exist");
585 rpn_definitions_files += s_arg[i_arg].n_items - 1;
587 case SET_RPN_EXPRESSION:
588 if (s_arg[i_arg].n_items < 2 && s_arg[i_arg].n_items > 4)
589 SDDS_Bomb(
"invalid -rpnexpression syntax");
590 rpnexpression_definition = (
RPNEXPRESSION_DEFINITION **)
trealloc(rpnexpression_definition,
sizeof(*rpnexpression_definition) * (rpnexpression_definitions + 1));
591 if (!(rpnexpression_definition[rpnexpression_definitions] = process_new_rpnexpression_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
592 SDDS_Bomb(
"invalid -rpnexpression syntax");
593 add_definition(&definition, &definitions, (
void *)rpnexpression_definition[rpnexpression_definitions], IS_RPNEXPRESSION_DEFINITION);
594 rpnexpression_definitions++;
597 if (s_arg[i_arg].n_items < 4)
599 equation_definition = (
EQUATION_DEFINITION **)
trealloc(equation_definition,
sizeof(*equation_definition) * (equation_definitions + 1));
600 if (!(equation_definition[equation_definitions] = process_new_equation_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
602 equation_definition[equation_definitions]->redefinition = 0;
603 add_definition(&definition, &definitions, (
void *)equation_definition[equation_definitions], IS_EQUATION_DEFINITION);
604 equation_definitions++;
606 case SET_REDEFINITION:
607 if (s_arg[i_arg].n_items < 4)
608 SDDS_Bomb(
"invalid -redefinition syntax");
609 equation_definition = (
EQUATION_DEFINITION **)
trealloc(equation_definition,
sizeof(*equation_definition) * (equation_definitions + 1));
610 if (!(equation_definition[equation_definitions] = process_new_equation_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
611 SDDS_Bomb(
"invalid -redefinition syntax");
612 equation_definition[equation_definitions]->redefinition = 1;
613 add_definition(&definition, &definitions, (
void *)equation_definition[equation_definitions], IS_EQUATION_DEFINITION);
614 equation_definitions++;
617 if (s_arg[i_arg].n_items < 4)
619 evaluate_definition = (
EVALUATE_DEFINITION **)
trealloc(evaluate_definition,
sizeof(*evaluate_definition) * (evaluate_definitions + 1));
620 if (!(evaluate_definition[evaluate_definitions] = process_new_evaluate_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
622 add_definition(&definition, &definitions, (
void *)evaluate_definition[evaluate_definitions], IS_EVALUATE_DEFINITION);
623 evaluate_definitions++;
626 if (s_arg[i_arg].n_items < 3 && s_arg[i_arg].n_items > 5)
628 rpntest_definition = (
RPNTEST_DEFINITION **)
trealloc(rpntest_definition,
sizeof(*rpntest_definition) * (rpntest_definitions + 1));
629 if (!(rpntest_definition[rpntest_definitions] = process_new_rpntest_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
631 add_definition(&definition, &definitions, (
void *)rpntest_definition[rpntest_definitions], IS_RPNTEST_DEFINITION);
632 rpntest_definitions++;
644 processing_definition = (
PROCESSING_DEFINITION **)
trealloc(processing_definition,
sizeof(*processing_definition) * (processing_definitions + 1));
645 if (!(processing_definition[processing_definitions] = record_processing_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
646 SDDS_Bomb(
"invalid -process syntax--parsing problem");
647 add_definition(&definition, &definitions, (
void *)processing_definition[processing_definitions], IS_PROCESSING_DEFINITION);
648 processing_definitions++;
650 case SET_CONVERT_UNITS:
651 if (s_arg[i_arg].n_items != 6)
652 SDDS_Bomb(
"invalid -convertunits syntax--wrong number of items");
654 if (!(conversion[conversions] = process_conversion_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
655 SDDS_Bomb(
"invalid -convertunits syntax");
656 add_definition(&definition, &definitions, (
void *)conversion[conversions], IS_CONVERSION_DEFINITION);
661 if (s_arg[i_arg].n_items < 3)
663 numbertest_definition = (
NUMBERTEST_DEFINITION **)
trealloc(numbertest_definition,
sizeof(*numbertest_definition) * (numbertest_definitions + 1));
664 if (!(numbertest_definition[numbertest_definitions] = process_new_numbertest_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
666 add_definition(&definition, &definitions, (
void *)numbertest_definition[numbertest_definitions], IS_NUMBERTEST_DEFINITION);
667 numbertest_definitions++;
670 if (s_arg[i_arg].n_items < 5)
672 scan_definition = (
SCAN_DEFINITION **)
trealloc(scan_definition,
sizeof(*scan_definition) * (scan_definitions + 1));
673 if (!(scan_definition[scan_definitions] = process_new_scan_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
675 add_definition(&definition, &definitions, (
void *)scan_definition[scan_definitions], IS_SCAN_DEFINITION);
679 if (s_arg[i_arg].n_items < 4)
681 print_definition = (
PRINT_DEFINITION **)
trealloc(print_definition,
sizeof(*print_definition) * (print_definitions + 1));
682 if (!(print_definition[print_definitions] = process_new_print_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
684 print_definition[print_definitions]->reprint = 0;
685 add_definition(&definition, &definitions, (
void *)print_definition[print_definitions], IS_PRINT_DEFINITION);
689 if (s_arg[i_arg].n_items < 4)
691 print_definition = (
PRINT_DEFINITION **)
trealloc(print_definition,
sizeof(*print_definition) * (print_definitions + 1));
692 if (!(print_definition[print_definitions] = process_new_print_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
694 print_definition[print_definitions]->reprint = 1;
695 add_definition(&definition, &definitions, (
void *)print_definition[print_definitions], IS_PRINT_DEFINITION);
699 if (s_arg[i_arg].n_items < 5)
701 edit_definition = (
EDIT_DEFINITION **)
trealloc(edit_definition,
sizeof(*edit_definition) * (edit_definitions + 1));
702 if (!(edit_definition[edit_definitions] = process_new_edit_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, 0)))
704 add_definition(&definition, &definitions, (
void *)edit_definition[edit_definitions], IS_EDIT_DEFINITION);
708 if (s_arg[i_arg].n_items < 4)
710 edit_definition = (
EDIT_DEFINITION **)
trealloc(edit_definition,
sizeof(*edit_definition) * (edit_definitions + 1));
711 if (!(edit_definition[edit_definitions] = process_new_edit_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, 1)))
713 edit_definition[edit_definitions]->reedit = 1;
714 add_definition(&definition, &definitions, (
void *)edit_definition[edit_definitions], IS_EDIT_DEFINITION);
718 if (s_arg[i_arg].n_items < 4)
720 system_definition = (
SYSTEM_DEFINITION **)
trealloc(system_definition,
sizeof(*system_definition) * (system_definitions + 1));
721 if (!(system_definition[system_definitions] = process_new_system_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
723 add_definition(&definition, &definitions, (
void *)system_definition[system_definitions], IS_SYSTEM_DEFINITION);
724 system_definitions++;
727 if (s_arg[i_arg].n_items < 3)
729 add_ifitem(&ifnot_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
732 if (s_arg[i_arg].n_items < 3)
734 add_ifitem(&ifis_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
737 clip_definition = (
CLIP_DEFINITION **)
trealloc(clip_definition,
sizeof(*clip_definition) * (clip_definitions + 1));
738 if (!(clip_definition[clip_definitions] = process_new_clip_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
740 add_definition(&definition, &definitions, (
void *)clip_definition[clip_definitions], IS_CLIP_DEFINITION);
744 fclip_definition = (
FCLIP_DEFINITION **)
trealloc(fclip_definition,
sizeof(*fclip_definition) * (fclip_definitions + 1));
745 if (!(fclip_definition[fclip_definitions] = process_new_fclip_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
747 add_definition(&definition, &definitions, (
void *)fclip_definition[fclip_definitions], IS_FCLIP_DEFINITION);
751 sparse_definition = (
SPARSE_DEFINITION **)
trealloc(sparse_definition,
sizeof(*sparse_definition) * (sparse_definitions + 1));
752 if (!(sparse_definition[sparse_definitions] = process_new_sparse_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
754 add_definition(&definition, &definitions, (
void *)sparse_definition[sparse_definitions], IS_SPARSE_DEFINITION);
755 sparse_definitions++;
758 sample_definition = (
SAMPLE_DEFINITION **)
trealloc(sample_definition,
sizeof(*sample_definition) * (sample_definitions + 1));
759 if (!(sample_definition[sample_definitions] = process_new_sample_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
761 add_definition(&definition, &definitions, (
void *)sample_definition[sample_definitions], IS_SAMPLE_DEFINITION);
762 sample_definitions++;
765 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
769 if (s_arg[i_arg].n_items < 4)
771 format_definition = (
FORMAT_DEFINITION **)
trealloc(format_definition,
sizeof(*format_definition) * (format_definitions + 1));
772 if (!(format_definition[format_definitions] = process_new_format_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
774 add_definition(&definition, &definitions, (
void *)format_definition[format_definitions], IS_FORMAT_DEFINITION);
775 format_definitions++;
778 if (s_arg[i_arg].n_items != 5)
780 cast_definition = (
CAST_DEFINITION **)
trealloc(cast_definition,
sizeof(*cast_definition) * (cast_definitions + 1));
781 if (!(cast_definition[cast_definitions] = process_new_cast_definition(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1)))
783 add_definition(&definition, &definitions, (
void *)cast_definition[cast_definitions], IS_CAST_DEFINITION);
787 if (s_arg[i_arg].n_items < 3)
789 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
791 delete_column =
trealloc(delete_column,
sizeof(*delete_column) * (delete_columns + s_arg[i_arg].n_items - 2));
792 for (i = 2; i < s_arg[i_arg].n_items; i++)
793 delete_column[i - 2 + delete_columns] = s_arg[i_arg].list[i];
794 delete_columns += s_arg[i_arg].n_items - 2;
797 delete_parameter =
trealloc(delete_parameter,
sizeof(*delete_parameter) * (delete_parameters + s_arg[i_arg].n_items - 2));
798 for (i = 2; i < s_arg[i_arg].n_items; i++)
799 delete_parameter[i - 2 + delete_parameters] = s_arg[i_arg].list[i];
800 delete_parameters += s_arg[i_arg].n_items - 2;
803 delete_array =
trealloc(delete_array,
sizeof(*delete_array) * (delete_arrays + s_arg[i_arg].n_items - 2));
804 for (i = 2; i < s_arg[i_arg].n_items; i++)
805 delete_array[i - 2 + delete_arrays] = s_arg[i_arg].list[i];
806 delete_arrays += s_arg[i_arg].n_items - 2;
809 SDDS_Bomb(
"invalid -delete syntax: specify column or parameter keyword");
814 if (s_arg[i_arg].n_items < 3)
816 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
818 retain_column =
trealloc(retain_column,
sizeof(*retain_column) * (retain_columns + s_arg[i_arg].n_items - 2));
819 for (i = 2; i < s_arg[i_arg].n_items; i++)
820 retain_column[i - 2 + retain_columns] = s_arg[i_arg].list[i];
821 retain_columns += s_arg[i_arg].n_items - 2;
824 retain_parameter =
trealloc(retain_parameter,
sizeof(*retain_parameter) * (retain_parameters + s_arg[i_arg].n_items - 2));
825 for (i = 2; i < s_arg[i_arg].n_items; i++)
826 retain_parameter[i - 2 + retain_parameters] = s_arg[i_arg].list[i];
827 retain_parameters += s_arg[i_arg].n_items - 2;
830 retain_array =
trealloc(retain_array,
sizeof(*retain_array) * (retain_arrays + s_arg[i_arg].n_items - 2));
831 for (i = 2; i < s_arg[i_arg].n_items; i++)
832 retain_array[i - 2 + retain_arrays] = s_arg[i_arg].list[i];
833 retain_arrays += s_arg[i_arg].n_items - 2;
836 SDDS_Bomb(
"invalid -retain syntax: specify column or parameter keyword");
840 case SET_DESCRIPTION:
841 s_arg[i_arg].n_items -= 1;
842 if (!
scanItemList(&flags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
844 "contents",
SDDS_STRING, &description_contents, 1, 0, NULL))
845 SDDS_Bomb(
"invalid -description syntax");
848 if (s_arg[i_arg].n_items != 2 ||
849 !sscanf(s_arg[i_arg].list[1],
"%d", &threads) || threads < 1)
853 snprintf(buffer, SDDS_MAXLINE,
"unknown switch: %s", s_arg[i_arg].list[0]);
858 if (inputfile == NULL)
859 inputfile = s_arg[i_arg].list[0];
860 else if (outputfile == NULL)
861 outputfile = s_arg[i_arg].list[0];
863 fprintf(stderr,
"argument %s is invalid: too many filenames (sddsprocess)\n", s_arg[i_arg].list[0]);
869 processFilenames(
"sddsprocess", &inputfile, &outputfile, pipeFlags, nowarnings, &tmpfile_used);
871 if (rpn_definitions_files) {
872 rpn(rpn_definitions_file[0]);
873 if (rpn_check_error())
875 for (i = 1; i < rpn_definitions_files; i++) {
876 sprintf(s,
"\"%s,s\" @", rpn_definitions_file[i]);
878 if (rpn_check_error())
882 rpn(getenv(
"RPN_DEFNS"));
883 if (rpn_check_error())
886 i_page_memory = rpn_create_mem(
"i_page", 0);
887 table_number_memory = rpn_create_mem(
"table_number", 0);
888 n_rows_memory = rpn_create_mem(
"n_rows", 0);
894 if (!check_ifitems(&SDDS_input, &ifnot_item, 0, !nowarnings) ||
895 !check_ifitems(&SDDS_input, &ifis_item, 1, !nowarnings))
897 original_parameters = SDDS_input.layout.n_parameters;
899 if (!description_text)
901 if (!
SDDS_InitializeOutput(&SDDS_output, SDDS_input.layout.data_mode.mode, 1, description_text, description_contents, outputfile)) {
905 if (columnMajorOrder != -1)
906 SDDS_output.layout.data_mode.column_major = columnMajorOrder;
908 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
912 fprintf(stderr,
"Getting column, parameter, and array names from input file.\n");
918 if (orig_column_names && !(new_column_name = process_name_options(orig_column_name, &orig_column_flag, orig_column_names, delete_column, delete_columns, retain_column, retain_columns, rename_column, rename_columns, edit_column_request, edit_column_requests)))
927 fprintf(stderr,
"processing name options\n");
929 if (orig_parameter_names && !(new_parameter_name = process_name_options(orig_parameter_name, &orig_parameter_flag, orig_parameter_names, delete_parameter, delete_parameters, retain_parameter, retain_parameters, rename_parameter, rename_parameters, edit_parameter_request, edit_parameter_requests)))
936 if (orig_array_names && !(new_array_name = process_name_options(orig_array_name, &orig_array_flag, orig_array_names, delete_array, delete_arrays, retain_array, retain_arrays, rename_array, rename_arrays, edit_array_request, edit_array_requests)))
940 for (i = 0; i < orig_parameter_names; i++) {
941 fprintf(stderr,
"parameter %s goes to %s\n", orig_parameter_name[i], orig_parameter_flag[i] ? new_parameter_name[i] :
"<deleted>");
943 for (i = 0; i < orig_array_names; i++) {
944 fprintf(stderr,
"array %s goes to %s\n", orig_array_name[i], orig_array_flag[i] ? new_array_name[i] :
"<deleted>");
946 for (i = 0; i < orig_column_names; i++) {
947 fprintf(stderr,
"column %s goes to %s\n", orig_column_name[i], orig_column_flag[i] ? new_column_name[i] :
"<deleted>");
952 fprintf(stderr,
"Transferring definitions to new file.\n");
954 for (i = 0; i < orig_parameter_names; i++) {
955 if (orig_parameter_flag[i]) {
957 fprintf(stderr,
"unable to transfer parameter %s to %s\n", orig_parameter_name[i], new_parameter_name[i]);
963 for (i = 0; i < orig_array_names; i++) {
964 if (orig_array_flag[i]) {
966 fprintf(stderr,
"unable to transfer array %s to %s\n", orig_array_name[i], new_array_name[i]);
973 for (i = 0; i < orig_column_names; i++) {
974 if (orig_column_flag[i]) {
977 fprintf(stderr,
"unable to transfer column %s to %s\n", orig_column_name[i], new_column_name[i]);
983 for (i = 0; i < orig_column_names; i++) {
984 free(new_column_name[i]);
985 free(orig_column_name[i]);
987 free(new_column_name);
988 free(orig_column_name);
990 expandDefinitions(&definition, &definitions, &SDDS_output);
992 for (i = 0; i < definitions; i++) {
993 switch (definition[i].type) {
994 case IS_EQUATION_DEFINITION:
996 sprintf(s,
"%sUDF%ld", equation_ptr->name, udfCounter++);
999 SDDS_Bomb(
"string copying failed (making udf name)");
1000 if (equation_ptr->equation[0] ==
'@') {
1001 if (equation_ptr->equation[1] ==
'@') {
1006 fprintf(stderr,
"Error (sddsprocess): parameter %s does not exist or is not string type\n", equation_ptr->equation + 2);
1013 fprintf(stderr,
"Error (sddsprocess): parameter %s does not exist or is not string type\n", equation_ptr->equation + 1);
1018 if (strstr(equation_ptr->equation,
"xstr") == NULL)
1019 create_udf(equation_ptr->udf_name, equation_ptr->equation);
1022 equation_ptr->udf_name = equation_ptr->equation;
1024 if (equation_ptr->redefinition) {
1025 if (equation_ptr->is_parameter) {
1027 equation_ptr->redefinition = 0;
1029 equation_ptr->redefinition = 0;
1031 if (equation_ptr->redefinition == 0) {
1032 if (equation_ptr->is_parameter) {
1035 fprintf(stderr,
"Bad parameter string: %s\n", equation_ptr->text);
1040 fprintf(stderr,
"Bad column string: %s\n", equation_ptr->text);
1044 if (equation_ptr->is_parameter) {
1046 fprintf(stderr,
"can't redefine parameter %s--non-numeric\n", equation_ptr->name);
1049 if (equation_ptr->argc && !SDDS_RedefineParameterCL(&SDDS_output, equation_ptr->name, equation_ptr->argv, equation_ptr->argc)) {
1050 fprintf(stderr,
"can't redefine parameter %s as requested\n", equation_ptr->name);
1055 fprintf(stderr,
"can't redefine column %s--non-numeric\n", equation_ptr->name);
1058 if (equation_ptr->argc && !SDDS_RedefineColumnCL(&SDDS_output, equation_ptr->name, equation_ptr->argv, equation_ptr->argc)) {
1059 fprintf(stderr,
"can't redefine column %s as requested\n", equation_ptr->name);
1065 case IS_EDIT_DEFINITION:
1069 edit_ptr->reedit = 0;
1070 else if (!edit_ptr->reedit) {
1071 fprintf(stderr,
"Can't define new -edit %s %s--already exists (sddsprocess)\n", edit_ptr->is_parameter ?
"parameter" :
"column", edit_ptr->new_name);
1074 if (!edit_ptr->reedit) {
1075 if (!(edit_ptr->is_parameter ? SDDS_ProcessParameterString(&SDDS_output, edit_ptr->text, SDDS_WRITEONLY_DEFINITION) : SDDS_ProcessColumnString(&SDDS_output, edit_ptr->text, SDDS_WRITEONLY_DEFINITION))) {
1076 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1081 fprintf(stderr,
"Can't reedit %s %s--not string type (sddsprocess)\n", edit_ptr->is_parameter ?
"parameter" :
"column", edit_ptr->new_name);
1084 if (edit_ptr->argc && !(edit_ptr->is_parameter ? SDDS_RedefineParameterCL(&SDDS_output, edit_ptr->new_name, edit_ptr->argv, edit_ptr->argc) : SDDS_RedefineColumnCL(&SDDS_output, edit_ptr->new_name, edit_ptr->argv, edit_ptr->argc))) {
1085 fprintf(stderr,
"Can't reedit %s %s as requested (sddsprocess)\n", edit_ptr->is_parameter ?
"parameter" :
"column", edit_ptr->new_name);
1090 case IS_SCAN_DEFINITION:
1092 if (scan_ptr->is_parameter) {
1102 case IS_PRINT_DEFINITION:
1106 print_ptr->reprint = 0;
1107 else if (!print_ptr->reprint) {
1108 fprintf(stderr,
"Can't define new -print %s %s--already exists (sddsprocess)\n", print_ptr->is_parameter ?
"parameter" :
"column", print_ptr->new_name);
1111 if (!print_ptr->reprint) {
1112 if (!(print_ptr->is_parameter ? SDDS_ProcessParameterString(&SDDS_output, print_ptr->text, SDDS_WRITEONLY_DEFINITION) : SDDS_ProcessColumnString(&SDDS_output, print_ptr->text, SDDS_WRITEONLY_DEFINITION))) {
1113 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1118 fprintf(stderr,
"Can't reprint %s %s--not string type (sddsprocess)\n", print_ptr->is_parameter ?
"parameter" :
"column", print_ptr->new_name);
1123 case IS_PROCESSING_DEFINITION:
1125 if (!complete_processing_definitions(&processing_ptr, 1, &SDDS_output)) {
1126 fprintf(stderr,
"error: problem completing processing definition\n");
1132 case IS_CONVERSION_DEFINITION:
1134 if (conversion_ptr->is_parameter) {
1136 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1143 fprintf(stderr,
"error: unknown error processing conversion for parameter %s\n", conversion_ptr->name);
1148 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1155 fprintf(stderr,
"error: unknown error processing conversion for column %s\n", conversion_ptr->name);
1160 case IS_SYSTEM_DEFINITION:
1162 if (system_ptr->is_parameter) {
1172 case IS_FORMAT_DEFINITION:
1174 if (strcmp(format_ptr->source, format_ptr->target)) {
1175 if (format_ptr->is_parameter) {
1181 fprintf(stderr,
"Problem setting up to format %s from %s\n", format_ptr->target, format_ptr->source);
1187 case IS_EVALUATE_DEFINITION:
1191 fprintf(stderr,
"Can't define new -evaluate %s %s--already exists (sddsprocess)\n", evaluate_ptr->is_parameter ?
"parameter" :
"column", evaluate_ptr->name);
1195 fprintf(stderr,
"Can't evaluate %s %s--doesn't exist (sddsprocess)\n", evaluate_ptr->is_parameter ?
"parameter" :
"column", evaluate_ptr->source);
1199 fprintf(stderr,
"Can't evaluate %s %s--not string type (sddsprocess)\n", evaluate_ptr->is_parameter ?
"parameter" :
"column", evaluate_ptr->source);
1203 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1207 case IS_FILTER_DEFINITION:
1208 case IS_MATCH_DEFINITION:
1209 case IS_RPNTEST_DEFINITION:
1210 case IS_RPNEXPRESSION_DEFINITION:
1211 case IS_CLIP_DEFINITION:
1212 case IS_FCLIP_DEFINITION:
1213 case IS_SPARSE_DEFINITION:
1214 case IS_SAMPLE_DEFINITION:
1215 case IS_NUMBERTEST_DEFINITION:
1216 case IS_TIME_FILTER_DEFINITION:
1218 case IS_CAST_DEFINITION:
1219 if (!complete_cast_definition(&SDDS_output, (
CAST_DEFINITION *)definition[i].structure, &SDDS_input)) {
1225 fprintf(stderr,
"error: unknown definition type code %ld seen--this shouldn't happen!\n", definition[i].type);
1242 for (i = 0; i < definitions; i++) {
1243 switch (definition[i].type) {
1244 case IS_EQUATION_DEFINITION:
1246 fprintf(stderr,
"%s %s created from equation %s:\n %s\n", equation_ptr->is_parameter ?
"parameter" :
"column", equation_ptr->name, equation_ptr->equation, equation_ptr->text);
1248 case IS_EVALUATE_DEFINITION:
1250 fprintf(stderr,
"evaluating to %s %s from %s\n", evaluate_ptr->is_parameter ?
"parameter" :
"column", evaluate_ptr->name, evaluate_ptr->source);
1252 case IS_EDIT_DEFINITION:
1254 fprintf(stderr,
"%s %s edit from %s using %s:\n %s\n", edit_ptr->is_parameter ?
"parameter" :
"column", edit_ptr->new_name, edit_ptr->source, edit_ptr->edit_command, edit_ptr->text);
1256 case IS_SCAN_DEFINITION:
1258 fprintf(stderr,
"%s %s scanned from %s using %s:\n %s\n", scan_ptr->is_parameter ?
"parameter" :
"column", scan_ptr->new_name, scan_ptr->source, scan_ptr->sscanf_string, scan_ptr->text);
1260 case IS_PRINT_DEFINITION:
1262 fprintf(stderr,
"printing to %s %s from ", print_ptr->is_parameter ?
"parameter" :
"column", print_ptr->new_name);
1263 for (j = 0; j < print_ptr->sources; j++)
1264 fprintf(stderr,
"%s ", print_ptr->source[j]);
1265 fprintf(stderr,
":\n %s\n", print_ptr->text);
1267 case IS_PROCESSING_DEFINITION:
1269 fprintf(stderr,
"column %s will be processed to give %s in parameter %s\n", processing_ptr->column_name, processing_ptr->description, processing_ptr->parameter_name);
1271 case IS_CONVERSION_DEFINITION:
1273 fprintf(stderr,
"%s %s will be converted to %s using factor %e\n", conversion_ptr->is_parameter ?
"parameter" :
"column", conversion_ptr->name, conversion_ptr->new_units, conversion_ptr->factor);
1275 case IS_FILTER_DEFINITION:
1277 show_filters(filter_ptr->is_parameter ?
"parameter" :
"column", filter_ptr->filter_term, filter_ptr->filter_terms);
1279 case IS_TIME_FILTER_DEFINITION:
1281 fprintf(stderr,
"Time filter: <%s> %22.15e, %22.15e\n", time_filter_ptr->name, time_filter_ptr->before, time_filter_ptr->after);
1282 case IS_MATCH_DEFINITION:
1284 show_matches(match_ptr->is_parameter ?
"parameter" :
"column", match_ptr->match_term, match_ptr->match_terms);
1286 case IS_RPNTEST_DEFINITION:
1288 if (rpntest_ptr->autostop)
1289 fprintf(stderr,
"%s-based autostop rpn test:\n %s\n", rpntest_ptr->is_parameter ?
"parameter" :
"column", rpntest_ptr->expression);
1291 fprintf(stderr,
"%s-based rpn test:\n %s\n", rpntest_ptr->is_parameter ?
"parameter" :
"column", rpntest_ptr->expression);
1293 case IS_NUMBERTEST_DEFINITION:
1295 fprintf(stderr,
"%s-based number test:\n %s %s%s\n", numbertest_ptr->is_parameter ?
"parameter" :
"column", numbertest_ptr->name, numbertest_ptr->flags & NUMSCANFILTER_INVERT ?
" inverted" :
"", numbertest_ptr->flags & NUMSCANFILTER_STRICT ?
" strict" :
"");
1297 case IS_RPNEXPRESSION_DEFINITION:
1299 fprintf(stderr,
"%srepeated rpn expression:\n %s\n", (rpnexpression_ptr->repeat ?
"" :
"un"), rpnexpression_ptr->expression);
1301 case IS_SYSTEM_DEFINITION:
1303 fprintf(stderr,
"%s %s system-call from %s:\n %s\n", system_ptr->is_parameter ?
"parameter" :
"column", system_ptr->new_name, system_ptr->source, system_ptr->text);
1305 case IS_FORMAT_DEFINITION:
1307 fprintf(stderr,
"formating %s %s from %s using ", format_ptr->is_parameter ?
"parameter" :
"column", format_ptr->target, format_ptr->source);
1308 fprintf(stderr,
"string: %s double: %s long: %s\n", format_ptr->stringFormat ? format_ptr->stringFormat :
"<none>", format_ptr->doubleFormat ? format_ptr->doubleFormat :
"<none>", format_ptr->longFormat ? format_ptr->longFormat :
"<none>");
1310 case IS_CLIP_DEFINITION:
1312 fprintf(stderr,
"page clip operation:\n head = %" PRId64
" tail = %" PRId64
" invert = %hd\n", clip_ptr->head, clip_ptr->tail, clip_ptr->invert);
1314 case IS_FCLIP_DEFINITION:
1316 fprintf(stderr,
"page clip operation:\n head = %f tail = %f invert = %hd\n", fclip_ptr->fhead, fclip_ptr->ftail, fclip_ptr->invert);
1318 case IS_SPARSE_DEFINITION:
1320 fprintf(stderr,
"page sparse operation:\n interval = %" PRId64
" offset = %" PRId64
"\n", sparse_ptr->interval, sparse_ptr->offset);
1322 case IS_SAMPLE_DEFINITION:
1324 fprintf(stderr,
"page sample operation:\n fraction = %.8g\n", sample_ptr->fraction);
1326 case IS_CAST_DEFINITION:
1328 fprintf(stderr,
"%s %s cast from %s to type %s\n", cast_ptr->isParameter ?
"parameter" :
"column", cast_ptr->newName, cast_ptr->source, cast_ptr->newTypeName);
1331 fprintf(stderr,
"error: unknown definition type code %ld seen--this shouldn't happen!\n", definition[i].type);
1349 fprintf(stderr,
"warning: no rows selected for page %" PRId32
"\n", SDDS_output.page_number);
1353 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1356 fprintf(stderr,
"page number %ld read in, with %" PRId64
" rows of data\n", page_number, n_rows);
1357 for (i = 0; i < original_parameters; i++) {
1358 SDDS_PrintTypedValue(SDDS_output.parameter[i], 0, SDDS_output.layout.parameter_definition[i].type, NULL, stderr, 0);
1359 fputc(
'\n', stderr);
1362 rpn_store((
double)page_number, NULL, table_number_memory);
1363 rpn_store((
double)page_number, NULL, i_page_memory);
1364 row_deletion = skip_page = 0;
1366 while (++i < definitions && !skip_page) {
1367 rpn_store((
double)n_rows, NULL, n_rows_memory);
1368 switch (definition[i].type) {
1369 case IS_CONVERSION_DEFINITION:
1371 if (conversion_ptr->is_parameter) {
1381 fprintf(stderr,
"conversion done: %s %s from %s to %s using factor %e\n", conversion_ptr->is_parameter ?
"parameter" :
"column", conversion_ptr->name, conversion_ptr->old_units, conversion_ptr->new_units, conversion_ptr->factor);
1383 case IS_PROCESSING_DEFINITION:
1386 if (!process_column(&SDDS_output, processing_ptr, &result, &stringResult, !nowarnings, threads))
1389 if (!
SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, processing_ptr->parameter_name, result, NULL)) {
1393 rpn_store(result, NULL, processing_ptr->memory_number);
1395 fprintf(stderr,
"processing result: %s = %e\n", processing_ptr->parameter_name, result);
1397 if (!
SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, processing_ptr->parameter_name, stringResult, NULL)) {
1402 fprintf(stderr,
"processing result: %s = %s\n", processing_ptr->parameter_name, stringResult);
1406 if (!(stringResult = process_string_column(&SDDS_output, processing_ptr, !nowarnings)) ||
1407 !
SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, processing_ptr->parameter_name, stringResult, NULL)) {
1414 case IS_EDIT_DEFINITION:
1416 if (edit_ptr->is_parameter) {
1417 if (!edit_parameter_value(&SDDS_output, edit_ptr->new_name, edit_ptr->source, edit_ptr->edit_command)) {
1418 fprintf(stderr,
"couldn't edit %s to make %s\n", edit_ptr->source, edit_ptr->new_name);
1421 }
else if (n_rows && !edit_column_value(&SDDS_output, edit_ptr->new_name, edit_ptr->source, edit_ptr->edit_command)) {
1422 fprintf(stderr,
"couldn't edit %s to make %s\n", edit_ptr->source, edit_ptr->new_name);
1426 fprintf(stderr,
"edited %s %s to produce %s, using edit-command %s\n", edit_ptr->is_parameter ?
"parameter" :
"column", edit_ptr->source, edit_ptr->new_name, edit_ptr->edit_command);
1428 case IS_SCAN_DEFINITION:
1430 if (scan_ptr->is_parameter) {
1431 if (!scan_parameter_value(&SDDS_output, scan_ptr->new_name, scan_ptr->source, scan_ptr->sscanf_string, scan_ptr->edit)) {
1432 fprintf(stderr,
"couldn't scan %s to make %s\n", scan_ptr->source, scan_ptr->new_name);
1435 }
else if (n_rows && !scan_column_value(&SDDS_output, scan_ptr->new_name, scan_ptr->source, scan_ptr->sscanf_string, scan_ptr->edit)) {
1436 fprintf(stderr,
"couldn't scan %s to make %s\n", scan_ptr->source, scan_ptr->new_name);
1440 fprintf(stderr,
"scanned %s %s to produce %s, using sscanf string %s\n", scan_ptr->is_parameter ?
"parameter" :
"column", scan_ptr->source, scan_ptr->new_name, scan_ptr->sscanf_string);
1442 case IS_PRINT_DEFINITION:
1444 if (print_ptr->is_parameter) {
1445 if (!print_parameter_value(&SDDS_output, print_ptr->new_name, print_ptr->source, print_ptr->sources, print_ptr->printf_string)) {
1446 fprintf(stderr,
"couldn't print to make parameter %s\n", print_ptr->new_name);
1449 }
else if (n_rows && !print_column_value(&SDDS_output, print_ptr->new_name, print_ptr->source, print_ptr->sources, print_ptr->printf_string)) {
1450 fprintf(stderr,
"couldn't print to make column %s\n", print_ptr->new_name);
1454 case IS_EQUATION_DEFINITION:
1456 if (equation_ptr->is_parameter) {
1457 if (!SDDS_ComputeParameter(&SDDS_output,
SDDS_GetParameterIndex(&SDDS_output, equation_ptr->name), equation_ptr->udf_name)) {
1461 }
else if (n_rows) {
1463 while (i < definitions && definition[i].type == IS_EQUATION_DEFINITION) {
1465 if (equation_ptr->is_parameter)
1470 if (!SDDS_ComputeSetOfColumns(&SDDS_output, k, i, definition)) {
1477 fprintf(stderr,
"computed %s %s using expression %s\n", equation_ptr->is_parameter ?
"parameter" :
"column", equation_ptr->name, equation_ptr->equation);
1479 case IS_EVALUATE_DEFINITION:
1481 if (evaluate_ptr->is_parameter) {
1482 if (!SDDS_EvaluateParameter(&SDDS_output, evaluate_ptr)) {
1486 }
else if (n_rows) {
1487 if (!SDDS_EvaluateColumn(&SDDS_output, evaluate_ptr)) {
1493 fprintf(stderr,
"computed %s %s using expressions from %s\n", evaluate_ptr->is_parameter ?
"parameter" :
"column", evaluate_ptr->name, evaluate_ptr->source);
1495 case IS_FORMAT_DEFINITION:
1497 if (format_ptr->is_parameter) {
1498 if (!format_parameter_value(&SDDS_output, format_ptr)) {
1499 fprintf(stderr,
"couldn't format parameter %s\n", format_ptr->target);
1502 }
else if (n_rows && !format_column_value(&SDDS_output, format_ptr)) {
1503 fprintf(stderr,
"couldn't format column %s\n", format_ptr->target);
1507 fprintf(stderr,
"formatted %s %s\n", format_ptr->is_parameter ?
"parameter" :
"column", format_ptr->target);
1509 case IS_TIME_FILTER_DEFINITION:
1511 if (time_filter_ptr->is_parameter) {
1514 fprintf(stderr,
"error: unknown or non-numeric parameter %s given for time filter\n", time_filter_ptr->name);
1521 if (time_filter_ptr->flags & TIMEFILTER_INVERT_GIVEN)
1522 skip_page = !skip_page;
1525 fputs(
" * page outside parameter filter--continuing to next page", stderr);
1528 }
else if (n_rows) {
1531 fprintf(stderr,
" * applying time filter (column %s)", time_filter_ptr->name);
1534 if ((nleft =
SDDS_FilterRowsOfInterest(&SDDS_output, time_filter_ptr->name, time_filter_ptr->after, time_filter_ptr->before, time_filter_ptr->flags & TIMEFILTER_INVERT_GIVEN ? SDDS_NEGATE_EXPRESSION : SDDS_AND)) < 0) {
1539 fprintf(stderr,
"---%" PRId64
" rows left\n", nleft);
1545 case IS_FILTER_DEFINITION:
1547 filter_term = filter_ptr->filter_term;
1548 for (j = 0; j < filter_ptr->filter_terms; j++) {
1549 if (filter_term[j].lowerPar && !
SDDS_GetParameterAsDouble(&SDDS_input, filter_term[j].lowerPar, &(filter_term[j].lower))) {
1550 fprintf(stderr,
"Error: unable to get parameter %s value for the lower filter from input file.\n", filter_term[j].lowerPar);
1554 if (filter_term[j].upperPar && !
SDDS_GetParameterAsDouble(&SDDS_input, filter_term[j].upperPar, &(filter_term[j].upper))) {
1555 fprintf(stderr,
"Error: unable to get parameter %s value for the upper filter from input file.\n", filter_term[j].upperPar);
1559 if (filter_term[j].upper < filter_term[j].lower) {
1560 fprintf(stderr,
"Error: invalid %s filter provided.\n", filter_term[j].name);
1564 if (filter_ptr->is_parameter) {
1566 filter_term = filter_ptr->filter_term;
1567 for (j = 0; j < filter_ptr->filter_terms; j++) {
1570 fprintf(stderr,
"error: unknown or non-numeric parameter %s given for filter\n", filter_term[j].name);
1577 fputs(
" * page failed parameter matching--continuing to next page", stderr);
1581 }
else if (n_rows) {
1583 filter_term = filter_ptr->filter_term;
1584 for (j = 0; j < filter_ptr->filter_terms; j++) {
1586 fprintf(stderr,
" * applying filter term %" PRId64
" (column %s)", j, filter_term[j].name);
1589 if ((nleft =
SDDS_FilterRowsOfInterest(&SDDS_output, filter_term[j].name, filter_term[j].lower, filter_term[j].upper, filter_term[j].logic)) < 0) {
1594 fprintf(stderr,
"---%" PRId64
" rows left\n", nleft);
1601 fprintf(stderr,
"applied %s filter\n", filter_ptr->is_parameter ?
"parameter" :
"column");
1603 case IS_MATCH_DEFINITION:
1605 if (match_ptr->is_parameter) {
1607 match_term = match_ptr->match_term;
1608 for (j = 0; j < match_ptr->match_terms; j++) {
1611 fprintf(stderr,
"error: unknown or numeric parameter %s given for match\n", match_term[j].name);
1621 sprintf(s,
"%c", *pc);
1623 accept =
SDDS_Logic(accept, (match_term[j].logic & SDDS_NOCASE_COMPARE ?
wild_match_ci(s, match_term[j].
string) :
wild_match(s, match_term[j].
string)), match_term[j].logic);
1627 fputs(
" * page failed parameter matching--continuing to next page", stderr);
1631 }
else if (n_rows) {
1632 match_term = match_ptr->match_term;
1633 for (j = 0; j < match_ptr->match_terms; j++)
1641 fprintf(stderr,
"applied %s match\n", match_ptr->is_parameter ?
"parameter" :
"column");
1643 case IS_RPNTEST_DEFINITION:
1645 SDDS_StoreParametersInRpnMemories(&SDDS_output);
1646 if (rpntest_ptr->is_parameter) {
1648 rpn(rpntest_ptr->expression);
1649 if (rpn_check_error())
1651 if (!pop_log(&test_result))
1652 SDDS_Bomb(
"aborted due to rpn logical stack/result error for parameter-based test");
1655 if (!rpntest_ptr->autostop) {
1657 fputs(
" * page failed rpn test--continuing to next page", stderr);
1662 fputs(
" * page failed rpn test--ignore remainder of file", stderr);
1666 }
else if (n_rows) {
1667 if (!SDDS_FilterRowsWithRpnTest(&SDDS_output, rpntest_ptr->expression)) {
1674 fprintf(stderr,
"applied %s-based rpn test:\n %s\n", rpntest_ptr->is_parameter ?
"parameter" :
"column", rpntest_ptr->expression);
1676 case IS_NUMBERTEST_DEFINITION:
1678 if (numbertest_ptr->is_parameter) {
1679 skip_page = !ParameterScansAsNumber(&SDDS_output, numbertest_ptr->name, numbertest_ptr->flags & NUMSCANFILTER_INVERT);
1680 }
else if (n_rows) {
1688 fprintf(stderr,
"applied %s-based %s%snumber test\n", numbertest_ptr->is_parameter ?
"parameter" :
"column", numbertest_ptr->flags & NUMSCANFILTER_INVERT ?
" inverted " :
"", numbertest_ptr->flags & NUMSCANFILTER_STRICT ?
" strict " :
"");
1690 case IS_SYSTEM_DEFINITION:
1692 if (system_ptr->is_parameter) {
1693 if (!system_parameter_value(&SDDS_output, system_ptr->new_name, system_ptr->source)) {
1694 fprintf(stderr,
"couldn't system %s to make %s\n", system_ptr->source, system_ptr->new_name);
1698 }
else if (n_rows && !system_column_value(&SDDS_output, system_ptr->new_name, system_ptr->source)) {
1699 fprintf(stderr,
"couldn't system %s to make %s\n", system_ptr->source, system_ptr->new_name);
1704 fprintf(stderr,
"systemed %s %s to produce %s\n", system_ptr->is_parameter ?
"parameter" :
"column", system_ptr->source, system_ptr->new_name);
1706 case IS_RPNEXPRESSION_DEFINITION:
1708 if (rpnexpression_ptr->repeat == -1)
1710 SDDS_StoreParametersInRpnMemories(&SDDS_output);
1711 SDDS_StoreColumnsInRpnArrays(&SDDS_output);
1712 rpn(rpnexpression_ptr->expression);
1713 if (rpn_check_error())
1717 fprintf(stderr,
"executed rpn expression:\n %s\n", rpnexpression_ptr->expression);
1718 if (!rpnexpression_ptr->repeat)
1719 rpnexpression_ptr->repeat = -1;
1721 case IS_CLIP_DEFINITION:
1726 !
SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, (int64_t)0, (int64_t)(clip_ptr->head - 1), clip_ptr->invert ? 1 : 0)) ||
1727 (n_rows >= clip_ptr->tail && clip_ptr->tail && !
SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, (int64_t)(n_rows - clip_ptr->tail), (int64_t)(n_rows - 1), clip_ptr->invert ? 1 : 0))) {
1734 case IS_FCLIP_DEFINITION:
1737 fclip_ptr->head = fclip_ptr->fhead * n_rows;
1738 fclip_ptr->tail = fclip_ptr->ftail * n_rows;
1741 !
SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, (int64_t)0, (int64_t)(fclip_ptr->head - 1), fclip_ptr->invert ? 1 : 0)) ||
1742 (n_rows >= fclip_ptr->tail && fclip_ptr->tail && !
SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, (int64_t)(n_rows - fclip_ptr->tail), (int64_t)(n_rows - 1), fclip_ptr->invert ? 1 : 0))) {
1749 case IS_SPARSE_DEFINITION:
1751 int32_t *sparse_row_flag;
1753 sparse_row_flag =
tmalloc(
sizeof(*sparse_row_flag) * n_rows);
1754 for (j = 0; j < n_rows; j++)
1755 sparse_row_flag[j] = 0;
1756 for (j = sparse_ptr->offset; j < n_rows; j += sparse_ptr->interval)
1757 sparse_row_flag[j] = 1;
1762 free(sparse_row_flag);
1766 case IS_SAMPLE_DEFINITION:
1768 int32_t *sample_row_flag;
1770 sample_row_flag =
tmalloc(
sizeof(*sample_row_flag) * n_rows);
1771 for (j = 0; j < n_rows; j++)
1772 sample_row_flag[j] =
random_1(1) < sample_ptr->fraction ? 1 : 0;
1777 free(sample_row_flag);
1781 case IS_CAST_DEFINITION:
1783 if (cast_ptr->isParameter) {
1784 if (!cast_parameter_value(&SDDS_output, cast_ptr))
1786 }
else if (n_rows && !cast_column_value(&SDDS_output, cast_ptr)) {
1791 fprintf(stderr,
"error: unknown definition type code %ld seen--this shouldn't happen!\n", definition[i].type);
1795 if (n_rows && row_deletion) {
1803 fprintf(stderr,
"warning: no rows selected for page %" PRId32
"\n", SDDS_output.page_number);
1809 fprintf(stderr,
" %" PRId64
" rows left\n", n_rows);
1815 fprintf(stderr,
" %" PRId64
" rows selected for output\n", n_rows);
1822 if (page_number == 0) {
1823 fprintf(stderr,
"Error: problem reading input file\n");
1837 if (processing_definition)
1838 free_processing_definiton(processing_definition, processing_definitions);
1839 if (equation_definition)
1840 free_equation_definition(equation_definition, equation_definitions);
1842 return EXIT_SUCCESS;
1847 for (i = 0; i < n; i++) {
1848 if (processing_definition[i]->parameter_name)
1849 free(processing_definition[i]->parameter_name);
1850 if (processing_definition[i]->column_name)
1851 free(processing_definition[i]->column_name);
1852 if (processing_definition[i]->description)
1853 free(processing_definition[i]->description);
1854 if (processing_definition[i]->symbol)
1855 free(processing_definition[i]->symbol);
1856 if (processing_definition[i]->functionOf)
1857 free(processing_definition[i]->functionOf);
1858 if (processing_definition[i]->weightBy)
1859 free(processing_definition[i]->weightBy);
1860 if (processing_definition[i]->match_value)
1861 free(processing_definition[i]->match_value);
1862 if (processing_definition[i]->match_column)
1863 free(processing_definition[i]->match_column);
1864 free(processing_definition[i]);
1866 if (processing_definition)
1867 free(processing_definition);
1872 for (i = 0; i < n; i++) {
1873 if (equation_definition[i]->text)
1874 free(equation_definition[i]->text);
1875 if (equation_definition[i]->name)
1876 free(equation_definition[i]->name);
1877 if (equation_definition[i]->equation)
1878 free(equation_definition[i]->equation);
1879 if (equation_definition[i]->udf_name && equation_definition[i]->udf_name != equation_definition[i]->equation)
1880 free(equation_definition[i]->udf_name);
1881 if (equation_definition[i]->editSelection)
1882 free(equation_definition[i]->editSelection);
1883 if (equation_definition[i]->select)
1884 free(equation_definition[i]->select);
1885 if (equation_definition[i]->argv) {
1886 for (j = 0; j < equation_definition[i]->argc; j++)
1887 free(equation_definition[i]->argv[j]);
1888 free(equation_definition[i]->argv);
1890 free(equation_definition[i]);
1892 if (equation_definition)
1893 free(equation_definition);
1902long SDDS_ComputeSetOfColumns(
SDDS_DATASET *SDDS_dataset,
long equ_begin,
long equ_end,
DEFINITION *definition) {
1907 long equations_present;
1909 long column_list_ptr, max_column_list_counter;
1913 column_list_ptr = -1;
1914 max_column_list_counter = 0;
1917 layout = &SDDS_dataset->layout;
1919 column_list_ptr = -1;
1920 max_column_list_counter = 0;
1921 for (equations_present = equ_begin; equations_present < equ_end; equations_present++) {
1924 if (++column_list_ptr >= max_column_list_counter || !column_list)
1925 column_list =
trealloc(column_list,
sizeof(*column_list) * (max_column_list_counter += 4));
1926 column_list[column_list_ptr].column =
SDDS_GetColumnIndex(SDDS_dataset, equation_ptr->name);
1927 if (equation_ptr->equation[0] ==
'@') {
1928 char **equation, *ptr, pfix[IFPF_BUF_SIZE];
1929 if (equation_ptr->equation[1] ==
'@') {
1931 if (!(equation =
SDDS_GetParameter(SDDS_dataset, equation_ptr->equation + 2, NULL)))
1932 SDDS_Bomb(
"unable to read parameter for equation definition");
1933 ptr = addOuterParentheses(*equation);
1934 if2pf(pfix, ptr,
sizeof pfix);
1937 fprintf(stderr,
"error: problem copying argument string\n");
1941 if (!(equation =
SDDS_GetParameter(SDDS_dataset, equation_ptr->equation + 1, NULL)))
1942 SDDS_Bomb(
"unable to read parameter for equation definition");
1945 create_udf(equation_ptr->udf_name, *equation);
1948 cp_str(&column_list[column_list_ptr].equation, equation_ptr->udf_name);
1949 if (column_list[column_list_ptr].column < 0 || column_list[column_list_ptr].column >= layout->n_columns)
1953 if (!SDDS_StoreParametersInRpnMemories(SDDS_dataset))
1955 if (!SDDS_StoreColumnsInRpnArrays(SDDS_dataset))
1958 if (table_number_mem == -1) {
1959 table_number_mem = rpn_create_mem(
"table_number", 0);
1960 i_page_mem = rpn_create_mem(
"i_page", 0);
1961 n_rows_mem = rpn_create_mem(
"n_rows", 0);
1962 i_row_mem = rpn_create_mem(
"i_row", 0);
1965 rpn_store((
double)SDDS_dataset->page_number, NULL, table_number_mem);
1966 rpn_store((
double)SDDS_dataset->page_number, NULL, i_page_mem);
1967 rpn_store((
double)SDDS_dataset->n_rows, NULL, n_rows_mem);
1969 for (j = 0; j < SDDS_dataset->n_rows; j++) {
1971 fprintf(stderr,
"Working on row %ld\n", j);
1973 if (!SDDS_StoreRowInRpnMemories(SDDS_dataset, j))
1975 column_list_ptr = 0;
1976 for (equations_present = equ_begin; equations_present < equ_end; equations_present++, column_list_ptr++) {
1977 column = column_list[column_list_ptr].column;
1979 rpn_store((
double)j, NULL, i_row_mem);
1980 value = rpn(column_list[column_list_ptr].equation);
1981 rpn_store(value, NULL, layout->column_definition[column].memory_number);
1982 if (rpn_check_error()) {
1983 SDDS_SetError(
"Unable to compute rpn expression--rpn error (SDDS_ComputeDefinedColumn)");
1987 fprintf(stderr,
"computed row value: %s = %e\n", layout->column_definition[column].name, value);
1989 switch (layout->column_definition[column].type) {
1991 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
char)value, -1);
1994 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
short)value, -1);
1997 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
unsigned short)value, -1);
2000 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int32_t)value, -1);
2003 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint32_t)value, -1);
2006 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int64_t)value, -1);
2009 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint64_t)value, -1);
2012 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
float)value, -1);
2015 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
double)value, -1);
2018 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
long double)value, -1);
2035 if (!SDDS_StoreParametersInRpnMemories(SDDS_dataset))
2037 if (!SDDS_StoreColumnsInRpnArrays(SDDS_dataset))
2040 if (table_number_mem == -1) {
2041 table_number_mem = rpn_create_mem(
"table_number", 0);
2042 i_page_mem = rpn_create_mem(
"i_page", 0);
2043 n_rows_mem = rpn_create_mem(
"n_rows", 0);
2044 i_row_mem = rpn_create_mem(
"i_row", 0);
2047 rpn_store((
double)SDDS_dataset->page_number, NULL, table_number_mem);
2048 rpn_store((
double)SDDS_dataset->page_number, NULL, i_page_mem);
2049 rpn_store((
double)SDDS_dataset->n_rows, NULL, n_rows_mem);
2051 if (!(equation = (
char **)
SDDS_GetColumn(SDDS_dataset, definition->source)))
2056 for (j = 0; j < SDDS_dataset->n_rows; j++) {
2057 if (!SDDS_StoreRowInRpnMemories(SDDS_dataset, j))
2060 rpn_store((
double)j, NULL, i_row_mem);
2061 value = rpn(equation[j]);
2062 if (rpn_check_error()) {
2063 SDDS_SetError(
"Unable to compute rpn expression--rpn error (SDDS_EvaluateColumn)");
2068 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
char)value, -1);
2071 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
short)value, -1);
2074 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
unsigned short)value, -1);
2077 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int32_t)value, -1);
2080 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint32_t)value, -1);
2083 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int64_t)value, -1);
2086 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint64_t)value, -1);
2089 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
float)value, -1);
2092 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
double)value, -1);
2095 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (
long double)value, -1);
2108 if (!SDDS_StoreParametersInRpnMemories(SDDS_dataset))
2111 if (table_number_mem == -1) {
2112 table_number_mem = rpn_create_mem(
"table_number", 0);
2113 i_page_mem = rpn_create_mem(
"i_page", 0);
2114 n_rows_mem = rpn_create_mem(
"n_rows", 0);
2115 i_row_mem = rpn_create_mem(
"i_row", 0);
2118 rpn_store((
double)SDDS_dataset->page_number, NULL, table_number_mem);
2119 rpn_store((
double)SDDS_dataset->page_number, NULL, i_page_mem);
2120 rpn_store((
double)SDDS_dataset->n_rows, NULL, n_rows_mem);
2122 if (!(equation = (
char **)
SDDS_GetParameter(SDDS_dataset, definition->source, NULL)))
2126 value = rpn(*equation);
2127 fprintf(stderr,
"value = %e\n", value);
2129 if (rpn_check_error()) {
2130 SDDS_SetError(
"Unable to compute rpn expression--rpn error (SDDS_EvaluateParameter)");
2135 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (
char)value, -1);
2138 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (
short)value, -1);
2141 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (
unsigned short)value, -1);
2144 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (int32_t)value, -1);
2147 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (uint32_t)value, -1);
2150 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (int64_t)value, -1);
2153 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (uint64_t)value, -1);
2156 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (
float)value, -1);
2159 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (
double)value, -1);
2162 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (
long double)value, -1);
2169char **process_name_options(
char **orig_name,
long **orig_flag,
long orig_names,
char **
delete,
long deletes,
char **retain,
2170 long retains, STRING_PAIR *rename,
long renames,
EDIT_NAME_REQUEST *edit_request,
long edit_requests) {
2175 *orig_flag =
tmalloc(
sizeof(**orig_flag) * orig_names);
2176 for (i = 0; i < orig_names; i++)
2177 (*orig_flag)[i] = 1;
2180 for (i = 0; i < deletes; i++) {
2185 for (j = 0; j < orig_names; j++) {
2186 for (i = 0; i < deletes; i++) {
2188 (*orig_flag)[j] = 0;
2196 for (i = 0; i < retains; i++) {
2202 for (j = 0; j < orig_names; j++)
2203 (*orig_flag)[j] = 0;
2204 for (j = 0; j < orig_names; j++) {
2205 if ((*orig_flag)[j])
2207 for (i = 0; i < retains; i++) {
2209 (*orig_flag)[j] = 1;
2216 new_name =
tmalloc(
sizeof(*new_name) * orig_names);
2217 for (j = 0; j < orig_names; j++) {
2218 for (i = 0; i < renames; i++) {
2219 if (strcmp(rename[i][0], orig_name[j]) == 0) {
2226 for (i = 0; i < edit_requests; i++) {
2227 char edit_buffer[256];
2230 edit_request[i].match_string = ptr;
2232 strcpy(edit_buffer, new_name[j]);
2233 if (!edit_string(edit_buffer, edit_request[i].edit_string))
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_ChangeParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a parameter definition within the SDDS dataset.
int32_t SDDS_ChangeColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a column definition within the SDDS dataset.
int32_t SDDS_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_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_ProcessParameterString(SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
Process a parameter definition string.
int32_t SDDS_ProcessColumnString(SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
Process a column definition string.
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_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
PARAMETER_DEFINITION * SDDS_GetParameterDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified parameter from the SDDS dataset.
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
int32_t SDDS_ColumnCount(SDDS_DATASET *page)
Retrieves the number of columns in the SDDS dataset.
int32_t SDDS_CheckColumn(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a column exists in the SDDS dataset with the specified name, units, and type.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
int32_t SDDS_DeleteParameterFixedValues(SDDS_DATASET *SDDS_dataset)
Deletes fixed values from all parameters in the SDDS dataset.
void SDDS_ClearErrors()
Clears all recorded error messages from the SDDS error stack.
int32_t SDDS_ApplyFactorToColumn(SDDS_DATASET *SDDS_dataset, char *name, double factor)
Applies a scaling factor to all elements of a specific column in the SDDS dataset.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
int32_t SDDS_NumberOfErrors()
Retrieves the number of errors recorded by SDDS library routines.
int32_t SDDS_ApplyFactorToParameter(SDDS_DATASET *SDDS_dataset, char *name, double factor)
Applies a scaling factor to a specific parameter in the SDDS dataset.
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
int32_t SDDS_CheckParameter(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a parameter exists in the SDDS dataset with the specified name, units, and type.
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.
int32_t SDDS_PrintTypedValue(void *data, int64_t index, int32_t type, char *format, FILE *fp, uint32_t mode)
Prints a data value of a specified type using an optional printf format string.
#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_LONGDOUBLE
Identifier for the long 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.
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
double random_1(long iseed)
Generate a uniform random double in [0,1] using a custom seed initialization.
long fexists(const char *filename)
Checks if a file exists.
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)
void free_scanargs(SCANNED_ARG **scanned, int argc)
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.
int wild_match_ci(char *string, char *template)
Determine whether one string is a case-insensitive wildcard match for another.
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.