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

Processes SDDS files by applying various transformations to columns and parameters. More...

#include "mdb.h"
#include "scan.h"
#include "SDDS.h"
#include "SDDSaps.h"
#include "rpn.h"
#include <sys/types.h>
#include <sys/time.h>

Go to the source code of this file.

Classes

struct  EDIT_NAME_REQUEST
 
struct  COLUMN_LIST
 

Macros

#define COLUMN_MODE   0
 
#define PARAMETER_MODE   1
 
#define ARRAY_MODE   2
 
#define MODES   3
 
#define PARAMETER_OR_COLUMN(is_param)
 
#define REDEFINABLE_TYPE(type)
 

Typedefs

typedef char * STRING_PAIR[2]
 

Enumerations

enum  option_type {
  SET_PROCESS , SET_MATCH , SET_FILTER , SET_RPN_DEFNS_FILES ,
  SET_RPN_EXPRESSION , SET_DEFINITION , SET_TEST , SET_SUMMARIZE ,
  SET_VERBOSE , SET_CONVERT_UNITS , SET_SCAN , SET_PRINT ,
  SET_EDIT , SET_SYSTEM , SET_REDEFINITION , SET_NOWARNINGS ,
  SET_IFNOT , SET_IFIS , SET_CLIP , SET_SPARSE ,
  SET_SAMPLE , SET_PIPE , SET_NUMBERTEST , SET_REEDIT ,
  SET_FORMAT , SET_CAST , SET_REPRINT , SET_DELETE ,
  SET_RETAIN , SET_DESCRIPTION , SET_FCLIP , SET_TIME_FILTER ,
  SET_MAJOR_ORDER , SET_EVALUATE , SET_THREADS , N_OPTIONS
}
 

Functions

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)
 
long SDDS_ComputeSetOfColumns (SDDS_DATASET *SDDS_dataset, long equ_begin, long equ_end, DEFINITION *definition)
 
void free_processing_definiton (PROCESSING_DEFINITION **processing_definition, long n)
 
void free_equation_definition (EQUATION_DEFINITION **equation_definition, long n)
 
long SDDS_EvaluateColumn (SDDS_DATASET *SDDS_dataset, EVALUATE_DEFINITION *definition)
 
long SDDS_EvaluateParameter (SDDS_DATASET *SDDS_dataset, EVALUATE_DEFINITION *definition)
 
int main (int argc, char **argv)
 

Variables

static char * mode_name [MODES]
 
char * option [N_OPTIONS]
 
char * usageArray []
 
static long table_number_mem = -1
 
static long i_page_mem = -1
 
static long n_rows_mem = -1
 
static long i_row_mem = -1
 

Detailed Description

Processes SDDS files by applying various transformations to columns and parameters.

This program reads an input SDDS (Self Describing Data Sets) file, processes its columns and parameters based on the specified options, and writes the results to a new SDDS output file. It supports a wide range of operations including filtering, matching, editing, defining new parameters or columns, converting units, and more.

@usage sddsprocess [<SDDSinputfile>] [<SDDSoutputfile>] [OPTIONS]

<SDDSinputfile> : Path to the input SDDS file. If omitted, input is read from standard input. <SDDSoutputfile> : Path to the output SDDS file. If omitted, output is written to standard output.

@options -pipe=[input][,output] Use pipe mode with optional input and output streams.

-ifis={column|parameter},<name>[,...] Include only the specified columns or parameters.

-ifnot={column|parameter},<name>[,...] Exclude the specified columns or parameters.

-match={column|parameter},<match-test>[,<match-test>[,<logic-operation>...]] Filter data based on matching criteria for columns or parameters.

-filter={column|parameter},<range-spec>[,<range-spec>[,<logic-operation>...]] Apply range-based filtering on specified columns or parameters.

-timeFilter={parameter|column},[,before=YYYY/MM/DD@HH:MM:SS][,after=YYYY/MM/DD@HH:MM:SS][,invert] Filter data based on time constraints.

-clip=<head>,<tail>,[invert] Clip the dataset by removing a specified number of rows from the head and tail.

-sparse=<interval>[,<offset>] Retain every <interval>-th row starting from <offset>.

-sample=<fraction> Randomly sample rows based on the specified fraction.

-fclip=<head>,<tail>,[invert] Fractional clipping based on the fraction of rows.

-test={column|parameter},<test>[,autostop][,algebraic] Apply RPN-based tests on columns or parameters with optional autostop.

-numberTest={column|parameter},<name>[,invert] Perform numerical tests on specified columns or parameters.

-rpndefinitionsfiles=<filename>[,...] Specify files containing RPN definitions.

-rpnexpression=<expression>[,repeat][,algebraic] Define RPN expressions to be evaluated.

-convertunits={column|parameter},<name>,<new-units>,<old-units>[,<factor>] Convert units of a specified column or parameter.

-define={column|parameter},<name>,{<equation>|<parameterName>}[,<definition_entries>][,algebraic] Define new columns or parameters based on equations or existing parameters.

-redefine={column|parameter},<name>,{<equation>|<parameterName>}[,<definition_entries>][,algebraic] Redefine existing columns or parameters.

-cast={column|parameter},<newName>,<sourceName>,<newType> Cast a column or parameter to a new data type.

-scan={column|parameter},<new-name>,<source-name>,<sscanf-string>[,<definition-entries>][,edit=<string>] Scan and parse data from a source column or parameter.

-edit={column|parameter},<new-name>,<source-name>,<edit-string>[,<definition-entries>] Edit values of a column or parameter based on specified rules.

-reedit={column|parameter},<name>,<edit-string>[,<definition-entries>] Re-edit existing columns or parameters.

-print={column|parameter},<new-name>,<sprintf-string>,<source-name>[,...][,<definition-entries>] Print formatted data from a source to a new column or parameter.

-reprint={column|parameter},<new-name>,<sprintf-string>,<source-name>[,...][,<definition-entries>] Reprint existing columns or parameters with new formatting.

-format={column|parameter},<new-name>,<source-name>[,stringFormat=<sprintfString>][,doubleFormat=<sprintfString>][,longFormat=<sprintfString>] Apply formatting to columns or parameters.

-system={column|parameter},<new-name>,<command-name>[,<definition_entries>] Execute system commands and capture their output.

-evaluate={column|parameter},<new-name>,<expression-name>[,<definition_entries>] Evaluate expressions to compute new columns or parameters.

-process=<column-name>,<analysis-name>,<result-name>[,description=<string>][,symbol=<string>][,weightBy=<column-name>][,functionOf=<column-name>[,lowerLimit=

][,upperLimit=

][,position]][,head=<number>][,tail=<number>][fhead=<fraction>][ftail=<fraction>][,topLimit=

][,bottomLimit=

][,offset=

][,factor=

][match=<column-name>,value=<string>][,overwrite],[default=

] Perform various processing operations on specified columns.

-summarize Display a summary of the processing operations performed.

-verbose Enable verbose output for detailed processing information.

-nowarnings Suppress warning messages.

-delete={column|parameter|array},<matching-string>[,...] Delete specified columns, parameters, or arrays.

-retain={column|parameter|array},<matching-string>[,...] Retain only the specified columns, parameters, or arrays.

-description=[text=<string>][,contents=<string>] Add or modify the description of the output SDDS file.

-majorOrder=row|column Set the major order of the output data (row-major or column-major).

-threads=<number> Specify the number of threads to use for 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 sddsprocess.c.

Macro Definition Documentation

◆ ARRAY_MODE

#define ARRAY_MODE   2

Definition at line 145 of file sddsprocess.c.

◆ COLUMN_MODE

#define COLUMN_MODE   0

Definition at line 143 of file sddsprocess.c.

◆ MODES

#define MODES   3

Definition at line 146 of file sddsprocess.c.

◆ PARAMETER_MODE

#define PARAMETER_MODE   1

Definition at line 144 of file sddsprocess.c.

◆ PARAMETER_OR_COLUMN

#define PARAMETER_OR_COLUMN ( is_param)
Value:
((is_param) ? "parameter" : "column")

Definition at line 319 of file sddsprocess.c.

◆ REDEFINABLE_TYPE

#define REDEFINABLE_TYPE ( type)
Value:
(SDDS_NUMERIC_TYPE(type) || (type) == SDDS_CHARACTER)
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
Definition SDDStypes.h:138

Definition at line 321 of file sddsprocess.c.

Typedef Documentation

◆ STRING_PAIR

typedef char* STRING_PAIR[2]

Definition at line 328 of file sddsprocess.c.

Enumeration Type Documentation

◆ option_type

enum option_type

Definition at line 154 of file sddsprocess.c.

154 {
155 SET_PROCESS,
156 SET_MATCH,
157 SET_FILTER,
158 SET_RPN_DEFNS_FILES,
159 SET_RPN_EXPRESSION,
160 SET_DEFINITION,
161 SET_TEST,
162 SET_SUMMARIZE,
163 SET_VERBOSE,
164 SET_CONVERT_UNITS,
165 SET_SCAN,
166 SET_PRINT,
167 SET_EDIT,
168 SET_SYSTEM,
169 SET_REDEFINITION,
170 SET_NOWARNINGS,
171 SET_IFNOT,
172 SET_IFIS,
173 SET_CLIP,
174 SET_SPARSE,
175 SET_SAMPLE,
176 SET_PIPE,
177 SET_NUMBERTEST,
178 SET_REEDIT,
179 SET_FORMAT,
180 SET_CAST,
181 SET_REPRINT,
182 SET_DELETE,
183 SET_RETAIN,
184 SET_DESCRIPTION,
185 SET_FCLIP,
186 SET_TIME_FILTER,
187 SET_MAJOR_ORDER,
188 SET_EVALUATE,
189 SET_THREADS,
190 N_OPTIONS
191};

Function Documentation

◆ free_equation_definition()

void free_equation_definition ( EQUATION_DEFINITION ** equation_definition,
long n )

Definition at line 1870 of file sddsprocess.c.

1870 {
1871 long i, j;
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);
1889 }
1890 free(equation_definition[i]);
1891 }
1892 if (equation_definition)
1893 free(equation_definition);
1894}

◆ free_processing_definiton()

void free_processing_definiton ( PROCESSING_DEFINITION ** processing_definition,
long n )

Definition at line 1845 of file sddsprocess.c.

1845 {
1846 long i;
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]);
1865 }
1866 if (processing_definition)
1867 free(processing_definition);
1868}

◆ main()

int main ( int argc,
char ** argv )

Definition at line 344 of file sddsprocess.c.

344 {
345 SDDS_DATASET SDDS_input, SDDS_output;
346 PARAMETER_DEFINITION *pardefptr;
347 long output_columns;
348 char *description_text, *description_contents;
349 unsigned long flags;
350
351 PROCESSING_DEFINITION **processing_definition, *processing_ptr;
352 long processing_definitions;
353 CONVERSION_DEFINITION **conversion, *conversion_ptr;
354 long conversions;
355 EDIT_DEFINITION **edit_definition, *edit_ptr;
356 long edit_definitions;
357 EQUATION_DEFINITION **equation_definition, *equation_ptr;
358 long equation_definitions;
359 EVALUATE_DEFINITION **evaluate_definition, *evaluate_ptr;
360 long evaluate_definitions;
361 SCAN_DEFINITION **scan_definition, *scan_ptr;
362 long scan_definitions;
363 PRINT_DEFINITION **print_definition, *print_ptr;
364 long print_definitions;
365 FORMAT_DEFINITION **format_definition, *format_ptr;
366 long format_definitions;
367 FILTER_TERM *filter_term;
368 FILTER_DEFINITION **filter_definition, *filter_ptr;
369 long filter_definitions;
370 TIME_FILTER_DEFINITION **time_filter_definition, *time_filter_ptr;
371 long time_filter_definitions;
372 MATCH_TERM *match_term;
373 MATCH_DEFINITION **match_definition, *match_ptr;
374 long match_definitions;
375 RPNTEST_DEFINITION **rpntest_definition, *rpntest_ptr;
376 long rpntest_definitions;
377 NUMBERTEST_DEFINITION **numbertest_definition, *numbertest_ptr;
378 long numbertest_definitions;
379 SYSTEM_DEFINITION **system_definition, *system_ptr;
380 long system_definitions;
381 RPNEXPRESSION_DEFINITION **rpnexpression_definition, *rpnexpression_ptr;
382 long rpnexpression_definitions;
383 CLIP_DEFINITION **clip_definition, *clip_ptr;
384 FCLIP_DEFINITION **fclip_definition, *fclip_ptr;
385 long clip_definitions, fclip_definitions;
386 SPARSE_DEFINITION **sparse_definition, *sparse_ptr;
387 long sparse_definitions;
388 SAMPLE_DEFINITION **sample_definition, *sample_ptr;
389 long sample_definitions;
390 DEFINITION *definition;
391 long definitions;
392 CAST_DEFINITION **cast_definition, *cast_ptr;
393 long cast_definitions;
394
395 IFITEM_LIST ifnot_item, ifis_item;
396 char *inputfile, *outputfile;
397
398 int64_t n_rows, j;
399 long i, k, i_arg, summarize, verbose, index = 0, tmpfile_used, nowarnings, udfCounter;
400 long page_number, accept;
401 SCANNED_ARG *s_arg;
402 char s[SDDS_MAXLINE];
403
404 char **rpn_definitions_file, *stringResult;
405 long rpn_definitions_files;
406 int32_t test_result;
407 long original_parameters;
408 double result;
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;
412
413 char **retain_column, **delete_column;
414 long retain_columns, delete_columns, rename_columns, edit_column_requests;
415 EDIT_NAME_REQUEST *edit_column_request;
416 STRING_PAIR *rename_column;
417 char **orig_column_name, **new_column_name;
418 long *orig_column_flag;
419 int32_t orig_column_names;
420
421 char **retain_parameter, **delete_parameter;
422 long retain_parameters, delete_parameters, rename_parameters, edit_parameter_requests;
423 EDIT_NAME_REQUEST *edit_parameter_request;
424 STRING_PAIR *rename_parameter;
425 char **orig_parameter_name, **new_parameter_name;
426 long *orig_parameter_flag;
427 int32_t orig_parameter_names;
428
429 char **retain_array, **delete_array;
430 long retain_arrays, delete_arrays, rename_arrays, edit_array_requests;
431 EDIT_NAME_REQUEST *edit_array_request;
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;
437
438 int threads = 1;
439
440 char buffer[SDDS_MAXLINE];
441
443
444 argc = scanargs(&s_arg, argc, argv);
445 argc = add_sddsfile_arguments(&s_arg, argc);
446
447 random_number_seed = (long)time((time_t *)NULL);
448 random_number_seed = 2 * (random_number_seed / 2) + 1;
449#if defined(_WIN32)
450 random_1(-labs((double)random_number_seed));
451#else
452 random_1(-FABS((double)random_number_seed));
453#endif
454
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;
459
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;
464
465 retain_array = delete_array = NULL;
466 retain_arrays = delete_arrays = rename_arrays = edit_array_requests = 0;
467 rename_array = NULL;
468 edit_array_request = NULL;
469
470 description_text = description_contents = NULL;
471 new_parameter_name = new_column_name = new_array_name = NULL;
472
473 if (argc < 3) {
474 char **ptr;
475 ptr = usageArray;
476 while (*ptr) {
477 fprintf(stderr, "%s", *ptr);
478 ptr++;
479 }
480 show_process_modes(stderr);
481 exit(EXIT_FAILURE);
482 }
483
484 inputfile = outputfile = NULL;
485 rpn_definitions_file = NULL;
486 rpn_definitions_files = 0;
487 summarize = verbose = nowarnings = udfCounter = 0;
488
489 processing_definition = NULL;
490 processing_definitions = 0;
491 conversion = NULL;
492 conversions = 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;
528 definition = NULL;
529 definitions = 0;
530 ifnot_item.items = 0;
531 ifis_item.items = 0;
532 pipeFlags = 0;
533
534 for (i_arg = 1; i_arg < argc; i_arg++) {
535 if (s_arg[i_arg].arg_type == OPTION) {
536 delete_chars(s_arg[i_arg].list[0], "_");
537 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
538 case SET_MAJOR_ORDER:
539 majorOrderFlag = 0;
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;
550 break;
551 case SET_MATCH:
552 if (s_arg[i_arg].n_items < 3)
553 SDDS_Bomb("invalid -match syntax");
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)))
556 SDDS_Bomb("invalid -match syntax");
557 add_definition(&definition, &definitions, (void *)match_definition[match_definitions], IS_MATCH_DEFINITION);
558 match_definitions++;
559 break;
560 case SET_FILTER:
561 if (s_arg[i_arg].n_items < 3)
562 SDDS_Bomb("invalid -filter syntax");
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)))
565 SDDS_Bomb("invalid -filter syntax");
566 add_definition(&definition, &definitions, (void *)filter_definition[filter_definitions], IS_FILTER_DEFINITION);
567 filter_definitions++;
568 break;
569 case SET_TIME_FILTER:
570 if (s_arg[i_arg].n_items < 3)
571 SDDS_Bomb("invalid -timeFilter syntax");
572 time_filter_definition = (TIME_FILTER_DEFINITION **)trealloc(time_filter_definition, sizeof(*time_filter_definition) * (filter_definitions + 1));
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)))
574 SDDS_Bomb("invalid -timeFilter syntax");
575 add_definition(&definition, &definitions, (void *)time_filter_definition[time_filter_definitions], IS_TIME_FILTER_DEFINITION);
576 time_filter_definitions++;
577 break;
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;
586 break;
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++;
595 break;
596 case SET_DEFINITION:
597 if (s_arg[i_arg].n_items < 4)
598 SDDS_Bomb("invalid -definition syntax");
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)))
601 SDDS_Bomb("invalid -definition syntax");
602 equation_definition[equation_definitions]->redefinition = 0;
603 add_definition(&definition, &definitions, (void *)equation_definition[equation_definitions], IS_EQUATION_DEFINITION);
604 equation_definitions++;
605 break;
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++;
615 break;
616 case SET_EVALUATE:
617 if (s_arg[i_arg].n_items < 4)
618 SDDS_Bomb("invalid -evaluate syntax");
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)))
621 SDDS_Bomb("invalid -definition syntax");
622 add_definition(&definition, &definitions, (void *)evaluate_definition[evaluate_definitions], IS_EVALUATE_DEFINITION);
623 evaluate_definitions++;
624 break;
625 case SET_TEST:
626 if (s_arg[i_arg].n_items < 3 && s_arg[i_arg].n_items > 5)
627 SDDS_Bomb("invalid -test syntax");
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)))
630 SDDS_Bomb("invalid -test syntax");
631 add_definition(&definition, &definitions, (void *)rpntest_definition[rpntest_definitions], IS_RPNTEST_DEFINITION);
632 rpntest_definitions++;
633 break;
634 case SET_SUMMARIZE:
635 summarize = 1;
636 break;
637 case SET_VERBOSE:
638 verbose = 1;
639 break;
640 case SET_NOWARNINGS:
641 nowarnings = 1;
642 break;
643 case SET_PROCESS:
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++;
649 break;
650 case SET_CONVERT_UNITS:
651 if (s_arg[i_arg].n_items != 6)
652 SDDS_Bomb("invalid -convertunits syntax--wrong number of items");
653 conversion = (CONVERSION_DEFINITION **)trealloc(conversion, sizeof(*conversion) * (conversions + 1));
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);
657 conversions++;
658 break;
659 case SET_NUMBERTEST:
660 /* -numberTest={col | param},<name>[,invert] */
661 if (s_arg[i_arg].n_items < 3)
662 SDDS_Bomb("invalid -numberTest syntax");
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)))
665 SDDS_Bomb("invalid -numberTest syntax");
666 add_definition(&definition, &definitions, (void *)numbertest_definition[numbertest_definitions], IS_NUMBERTEST_DEFINITION);
667 numbertest_definitions++;
668 break;
669 case SET_SCAN:
670 if (s_arg[i_arg].n_items < 5)
671 SDDS_Bomb("invalid -scan syntax");
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)))
674 SDDS_Bomb("invalid -scan syntax");
675 add_definition(&definition, &definitions, (void *)scan_definition[scan_definitions], IS_SCAN_DEFINITION);
676 scan_definitions++;
677 break;
678 case SET_PRINT:
679 if (s_arg[i_arg].n_items < 4)
680 SDDS_Bomb("invalid -print syntax");
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)))
683 SDDS_Bomb("invalid -print syntax");
684 print_definition[print_definitions]->reprint = 0;
685 add_definition(&definition, &definitions, (void *)print_definition[print_definitions], IS_PRINT_DEFINITION);
686 print_definitions++;
687 break;
688 case SET_REPRINT:
689 if (s_arg[i_arg].n_items < 4)
690 SDDS_Bomb("invalid -print syntax");
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)))
693 SDDS_Bomb("invalid -print syntax");
694 print_definition[print_definitions]->reprint = 1;
695 add_definition(&definition, &definitions, (void *)print_definition[print_definitions], IS_PRINT_DEFINITION);
696 print_definitions++;
697 break;
698 case SET_EDIT:
699 if (s_arg[i_arg].n_items < 5)
700 SDDS_Bomb("invalid -edit syntax");
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)))
703 SDDS_Bomb("invalid -edit syntax");
704 add_definition(&definition, &definitions, (void *)edit_definition[edit_definitions], IS_EDIT_DEFINITION);
705 edit_definitions++;
706 break;
707 case SET_REEDIT:
708 if (s_arg[i_arg].n_items < 4)
709 SDDS_Bomb("invalid -reedit syntax");
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)))
712 SDDS_Bomb("invalid -reedit syntax");
713 edit_definition[edit_definitions]->reedit = 1;
714 add_definition(&definition, &definitions, (void *)edit_definition[edit_definitions], IS_EDIT_DEFINITION);
715 edit_definitions++;
716 break;
717 case SET_SYSTEM:
718 if (s_arg[i_arg].n_items < 4)
719 SDDS_Bomb("invalid -system syntax");
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)))
722 SDDS_Bomb("invalid -system syntax");
723 add_definition(&definition, &definitions, (void *)system_definition[system_definitions], IS_SYSTEM_DEFINITION);
724 system_definitions++;
725 break;
726 case SET_IFNOT:
727 if (s_arg[i_arg].n_items < 3)
728 SDDS_Bomb("invalid -ifnot syntax");
729 add_ifitem(&ifnot_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
730 break;
731 case SET_IFIS:
732 if (s_arg[i_arg].n_items < 3)
733 SDDS_Bomb("invalid -ifis syntax");
734 add_ifitem(&ifis_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
735 break;
736 case SET_CLIP:
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)))
739 SDDS_Bomb("invalid -clip syntax");
740 add_definition(&definition, &definitions, (void *)clip_definition[clip_definitions], IS_CLIP_DEFINITION);
741 clip_definitions++;
742 break;
743 case SET_FCLIP:
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)))
746 SDDS_Bomb("invalid -fclip syntax");
747 add_definition(&definition, &definitions, (void *)fclip_definition[fclip_definitions], IS_FCLIP_DEFINITION);
748 fclip_definitions++;
749 break;
750 case SET_SPARSE:
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)))
753 SDDS_Bomb("invalid -sparse syntax");
754 add_definition(&definition, &definitions, (void *)sparse_definition[sparse_definitions], IS_SPARSE_DEFINITION);
755 sparse_definitions++;
756 break;
757 case SET_SAMPLE:
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)))
760 SDDS_Bomb("invalid -sample syntax");
761 add_definition(&definition, &definitions, (void *)sample_definition[sample_definitions], IS_SAMPLE_DEFINITION);
762 sample_definitions++;
763 break;
764 case SET_PIPE:
765 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
766 SDDS_Bomb("invalid -pipe syntax");
767 break;
768 case SET_FORMAT:
769 if (s_arg[i_arg].n_items < 4)
770 SDDS_Bomb("invalid -format syntax");
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)))
773 SDDS_Bomb("invalid -format syntax");
774 add_definition(&definition, &definitions, (void *)format_definition[format_definitions], IS_FORMAT_DEFINITION);
775 format_definitions++;
776 break;
777 case SET_CAST:
778 if (s_arg[i_arg].n_items != 5)
779 SDDS_Bomb("invalid -cast syntax");
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)))
782 SDDS_Bomb("invalid -cast syntax");
783 add_definition(&definition, &definitions, (void *)cast_definition[cast_definitions], IS_CAST_DEFINITION);
784 cast_definitions++;
785 break;
786 case SET_DELETE:
787 if (s_arg[i_arg].n_items < 3)
788 SDDS_Bomb("invalid -delete syntax");
789 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
790 case COLUMN_MODE:
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;
795 break;
796 case PARAMETER_MODE:
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;
801 break;
802 case ARRAY_MODE:
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;
807 break;
808 default:
809 SDDS_Bomb("invalid -delete syntax: specify column or parameter keyword");
810 break;
811 }
812 break;
813 case SET_RETAIN:
814 if (s_arg[i_arg].n_items < 3)
815 SDDS_Bomb("invalid -retain syntax");
816 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
817 case COLUMN_MODE:
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;
822 break;
823 case PARAMETER_MODE:
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;
828 break;
829 case ARRAY_MODE:
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;
834 break;
835 default:
836 SDDS_Bomb("invalid -retain syntax: specify column or parameter keyword");
837 break;
838 }
839 break;
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,
843 "text", SDDS_STRING, &description_text, 1, 0,
844 "contents", SDDS_STRING, &description_contents, 1, 0, NULL))
845 SDDS_Bomb("invalid -description syntax");
846 break;
847 case SET_THREADS:
848 if (s_arg[i_arg].n_items != 2 ||
849 !sscanf(s_arg[i_arg].list[1], "%d", &threads) || threads < 1)
850 SDDS_Bomb("invalid -threads syntax");
851 break;
852 default:
853 snprintf(buffer, SDDS_MAXLINE, "unknown switch: %s", s_arg[i_arg].list[0]);
854 SDDS_Bomb(buffer);
855 break;
856 }
857 } else {
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];
862 else {
863 fprintf(stderr, "argument %s is invalid: too many filenames (sddsprocess)\n", s_arg[i_arg].list[0]);
864 exit(EXIT_FAILURE);
865 }
866 }
867 }
868
869 processFilenames("sddsprocess", &inputfile, &outputfile, pipeFlags, nowarnings, &tmpfile_used);
870
871 if (rpn_definitions_files) {
872 rpn(rpn_definitions_file[0]);
873 if (rpn_check_error())
874 exit(EXIT_FAILURE);
875 for (i = 1; i < rpn_definitions_files; i++) {
876 sprintf(s, "\"%s,s\" @", rpn_definitions_file[i]);
877 rpn(s);
878 if (rpn_check_error())
879 exit(EXIT_FAILURE);
880 }
881 } else {
882 rpn(getenv("RPN_DEFNS"));
883 if (rpn_check_error())
884 exit(EXIT_FAILURE);
885 }
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);
889
890 if (!SDDS_InitializeInput(&SDDS_input, inputfile)) {
891 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
892 exit(EXIT_FAILURE);
893 }
894 if (!check_ifitems(&SDDS_input, &ifnot_item, 0, !nowarnings) ||
895 !check_ifitems(&SDDS_input, &ifis_item, 1, !nowarnings))
896 exit(EXIT_SUCCESS);
897 original_parameters = SDDS_input.layout.n_parameters;
898
899 if (!description_text)
900 SDDS_GetDescription(&SDDS_input, &description_text, &description_contents);
901 if (!SDDS_InitializeOutput(&SDDS_output, SDDS_input.layout.data_mode.mode, 1, description_text, description_contents, outputfile)) {
902 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
903 exit(EXIT_FAILURE);
904 }
905 if (columnMajorOrder != -1)
906 SDDS_output.layout.data_mode.column_major = columnMajorOrder;
907 else
908 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
909 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
910
911#ifdef DEBUG
912 fprintf(stderr, "Getting column, parameter, and array names from input file.\n");
913#endif
914 if (!(orig_column_name = SDDS_GetColumnNames(&SDDS_input, &orig_column_names))) {
915 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
916 exit(EXIT_FAILURE);
917 }
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)))
919 exit(EXIT_FAILURE);
920
921 if (!(orig_parameter_name = SDDS_GetParameterNames(&SDDS_input, &orig_parameter_names))) {
922 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
923 exit(EXIT_FAILURE);
924 }
925
926#ifdef DEBUG
927 fprintf(stderr, "processing name options\n");
928#endif
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)))
930 exit(EXIT_FAILURE);
931
932 if (!(orig_array_name = SDDS_GetArrayNames(&SDDS_input, &orig_array_names))) {
933 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
934 exit(EXIT_FAILURE);
935 }
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)))
937 exit(EXIT_FAILURE);
938
939#ifdef DEBUG
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>");
942 }
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>");
945 }
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>");
948 }
949#endif
950
951#ifdef DEBUG
952 fprintf(stderr, "Transferring definitions to new file.\n");
953#endif
954 for (i = 0; i < orig_parameter_names; i++) {
955 if (orig_parameter_flag[i]) {
956 if (!SDDS_TransferParameterDefinition(&SDDS_output, &SDDS_input, orig_parameter_name[i], new_parameter_name[i])) {
957 fprintf(stderr, "unable to transfer parameter %s to %s\n", orig_parameter_name[i], new_parameter_name[i]);
958 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
959 exit(EXIT_FAILURE);
960 }
961 }
962 }
963 for (i = 0; i < orig_array_names; i++) {
964 if (orig_array_flag[i]) {
965 if (!SDDS_TransferArrayDefinition(&SDDS_output, &SDDS_input, orig_array_name[i], new_array_name[i])) {
966 fprintf(stderr, "unable to transfer array %s to %s\n", orig_array_name[i], new_array_name[i]);
967 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
968 exit(EXIT_FAILURE);
969 }
970 }
971 }
972 output_columns = 0;
973 for (i = 0; i < orig_column_names; i++) {
974 if (orig_column_flag[i]) {
975 output_columns++;
976 if (!SDDS_TransferColumnDefinition(&SDDS_output, &SDDS_input, orig_column_name[i], new_column_name[i])) {
977 fprintf(stderr, "unable to transfer column %s to %s\n", orig_column_name[i], new_column_name[i]);
978 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
979 exit(EXIT_FAILURE);
980 }
981 }
982 }
983 for (i = 0; i < orig_column_names; i++) {
984 free(new_column_name[i]);
985 free(orig_column_name[i]);
986 }
987 free(new_column_name);
988 free(orig_column_name);
989
990 expandDefinitions(&definition, &definitions, &SDDS_output);
991
992 for (i = 0; i < definitions; i++) {
993 switch (definition[i].type) {
994 case IS_EQUATION_DEFINITION:
995 equation_ptr = (EQUATION_DEFINITION *)definition[i].structure;
996 sprintf(s, "%sUDF%ld", equation_ptr->name, udfCounter++);
997 delete_chars(s, " ");
998 if (!SDDS_CopyString(&equation_ptr->udf_name, s))
999 SDDS_Bomb("string copying failed (making udf name)");
1000 if (equation_ptr->equation[0] == '@') {
1001 if (equation_ptr->equation[1] == '@') {
1002 /* parameter contains algebraic notation */
1003 if ((index = SDDS_GetParameterIndex(&SDDS_output, equation_ptr->equation + 2)) < 0 ||
1004 SDDS_GetParameterType(&SDDS_input, index) != SDDS_STRING) {
1005 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1006 fprintf(stderr, "Error (sddsprocess): parameter %s does not exist or is not string type\n", equation_ptr->equation + 2);
1007 exit(EXIT_FAILURE);
1008 }
1009 } else {
1010 if ((index = SDDS_GetParameterIndex(&SDDS_output, equation_ptr->equation + 1)) < 0 ||
1011 SDDS_GetParameterType(&SDDS_input, index) != SDDS_STRING) {
1012 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1013 fprintf(stderr, "Error (sddsprocess): parameter %s does not exist or is not string type\n", equation_ptr->equation + 1);
1014 exit(EXIT_FAILURE);
1015 }
1016 }
1017 } else {
1018 if (strstr(equation_ptr->equation, "xstr") == NULL)
1019 create_udf(equation_ptr->udf_name, equation_ptr->equation);
1020 else
1021 /* This works around a bug in rpn that results in a stack overflow for definitions that use the 'xstr' function */
1022 equation_ptr->udf_name = equation_ptr->equation;
1023 }
1024 if (equation_ptr->redefinition) {
1025 if (equation_ptr->is_parameter) {
1026 if ((index = SDDS_GetParameterIndex(&SDDS_output, equation_ptr->name)) < 0)
1027 equation_ptr->redefinition = 0;
1028 } else if ((index = SDDS_GetColumnIndex(&SDDS_output, equation_ptr->name)) < 0)
1029 equation_ptr->redefinition = 0;
1030 }
1031 if (equation_ptr->redefinition == 0) {
1032 if (equation_ptr->is_parameter) {
1033 if (!SDDS_ProcessParameterString(&SDDS_output, equation_ptr->text, SDDS_WRITEONLY_DEFINITION)) {
1034 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1035 fprintf(stderr, "Bad parameter string: %s\n", equation_ptr->text);
1036 exit(EXIT_FAILURE);
1037 }
1038 } else if (!SDDS_ProcessColumnString(&SDDS_output, equation_ptr->text, SDDS_WRITEONLY_DEFINITION)) {
1039 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1040 fprintf(stderr, "Bad column string: %s\n", equation_ptr->text);
1041 exit(EXIT_FAILURE);
1042 }
1043 } else {
1044 if (equation_ptr->is_parameter) {
1045 if (!REDEFINABLE_TYPE(SDDS_GetParameterType(&SDDS_output, index))) {
1046 fprintf(stderr, "can't redefine parameter %s--non-numeric\n", equation_ptr->name);
1047 exit(EXIT_FAILURE);
1048 }
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);
1051 exit(EXIT_FAILURE);
1052 }
1053 } else {
1054 if (!REDEFINABLE_TYPE(SDDS_GetColumnType(&SDDS_output, index))) {
1055 fprintf(stderr, "can't redefine column %s--non-numeric\n", equation_ptr->name);
1056 exit(EXIT_FAILURE);
1057 }
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);
1060 exit(EXIT_FAILURE);
1061 }
1062 }
1063 }
1064 break;
1065 case IS_EDIT_DEFINITION:
1066 edit_ptr = (EDIT_DEFINITION *)definition[i].structure;
1067 index = edit_ptr->is_parameter ? SDDS_GetParameterIndex(&SDDS_output, edit_ptr->new_name) : SDDS_GetColumnIndex(&SDDS_output, edit_ptr->new_name);
1068 if (index < 0)
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);
1072 exit(EXIT_FAILURE);
1073 }
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);
1077 exit(EXIT_FAILURE);
1078 }
1079 } else {
1080 if ((edit_ptr->is_parameter ? SDDS_GetParameterType(&SDDS_output, index) : SDDS_GetColumnType(&SDDS_output, index)) != SDDS_STRING) {
1081 fprintf(stderr, "Can't reedit %s %s--not string type (sddsprocess)\n", edit_ptr->is_parameter ? "parameter" : "column", edit_ptr->new_name);
1082 exit(EXIT_FAILURE);
1083 }
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);
1086 exit(EXIT_FAILURE);
1087 }
1088 }
1089 break;
1090 case IS_SCAN_DEFINITION:
1091 scan_ptr = (SCAN_DEFINITION *)definition[i].structure;
1092 if (scan_ptr->is_parameter) {
1093 if (!SDDS_ProcessParameterString(&SDDS_output, scan_ptr->text, SDDS_WRITEONLY_DEFINITION)) {
1094 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1095 exit(EXIT_FAILURE);
1096 }
1097 } else if (!SDDS_ProcessColumnString(&SDDS_output, scan_ptr->text, SDDS_WRITEONLY_DEFINITION)) {
1098 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1099 exit(EXIT_FAILURE);
1100 }
1101 break;
1102 case IS_PRINT_DEFINITION:
1103 print_ptr = (PRINT_DEFINITION *)definition[i].structure;
1104 index = print_ptr->is_parameter ? SDDS_GetParameterIndex(&SDDS_output, print_ptr->new_name) : SDDS_GetColumnIndex(&SDDS_output, print_ptr->new_name);
1105 if (index < 0)
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);
1109 exit(EXIT_FAILURE);
1110 }
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);
1114 exit(EXIT_FAILURE);
1115 }
1116 } else {
1117 if ((print_ptr->is_parameter ? SDDS_GetParameterType(&SDDS_output, index) : SDDS_GetColumnType(&SDDS_output, index)) != SDDS_STRING) {
1118 fprintf(stderr, "Can't reprint %s %s--not string type (sddsprocess)\n", print_ptr->is_parameter ? "parameter" : "column", print_ptr->new_name);
1119 exit(EXIT_FAILURE);
1120 }
1121 }
1122 break;
1123 case IS_PROCESSING_DEFINITION:
1124 processing_ptr = (PROCESSING_DEFINITION *)definition[i].structure;
1125 if (!complete_processing_definitions(&processing_ptr, 1, &SDDS_output)) {
1126 fprintf(stderr, "error: problem completing processing definition\n");
1127 if (SDDS_NumberOfErrors())
1128 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1129 exit(EXIT_FAILURE);
1130 }
1131 break;
1132 case IS_CONVERSION_DEFINITION:
1133 conversion_ptr = (CONVERSION_DEFINITION *)definition[i].structure;
1134 if (conversion_ptr->is_parameter) {
1135 if ((j = SDDS_GetParameterIndex(&SDDS_output, conversion_ptr->name)) < 0)
1136 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1137 if (SDDS_CheckParameter(&SDDS_output, conversion_ptr->name, conversion_ptr->old_units, SDDS_GetParameterType(&SDDS_output, j), stderr) != SDDS_CHECK_OKAY)
1138 exit(EXIT_FAILURE);
1139 if (!SDDS_ChangeParameterInformation(&SDDS_output, "units", conversion_ptr->new_units, SDDS_SET_BY_NAME, conversion_ptr->name)) {
1140 if (SDDS_NumberOfErrors())
1141 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1142 else
1143 fprintf(stderr, "error: unknown error processing conversion for parameter %s\n", conversion_ptr->name);
1144 exit(EXIT_FAILURE);
1145 }
1146 } else {
1147 if ((j = SDDS_GetColumnIndex(&SDDS_output, conversion_ptr->name)) < 0)
1148 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1149 if (SDDS_CheckColumn(&SDDS_output, conversion_ptr->name, conversion_ptr->old_units, SDDS_GetColumnType(&SDDS_output, j), stderr) != SDDS_CHECK_OKAY)
1150 exit(EXIT_FAILURE);
1151 if (!SDDS_ChangeColumnInformation(&SDDS_output, "units", conversion_ptr->new_units, SDDS_SET_BY_NAME, conversion_ptr->name)) {
1152 if (SDDS_NumberOfErrors())
1153 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1154 else
1155 fprintf(stderr, "error: unknown error processing conversion for column %s\n", conversion_ptr->name);
1156 exit(EXIT_FAILURE);
1157 }
1158 }
1159 break;
1160 case IS_SYSTEM_DEFINITION:
1161 system_ptr = (SYSTEM_DEFINITION *)definition[i].structure;
1162 if (system_ptr->is_parameter) {
1163 if (!SDDS_ProcessParameterString(&SDDS_output, system_ptr->text, SDDS_WRITEONLY_DEFINITION)) {
1164 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1165 exit(EXIT_FAILURE);
1166 }
1167 } else if (!SDDS_ProcessColumnString(&SDDS_output, system_ptr->text, SDDS_WRITEONLY_DEFINITION)) {
1168 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1169 exit(EXIT_FAILURE);
1170 }
1171 break;
1172 case IS_FORMAT_DEFINITION:
1173 format_ptr = (FORMAT_DEFINITION *)definition[i].structure;
1174 if (strcmp(format_ptr->source, format_ptr->target)) {
1175 if (format_ptr->is_parameter) {
1176 if (!SDDS_TransferParameterDefinition(&SDDS_output, &SDDS_output, format_ptr->source, format_ptr->target)) {
1177 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1178 exit(EXIT_FAILURE);
1179 }
1180 } else if (!SDDS_TransferColumnDefinition(&SDDS_output, &SDDS_output, format_ptr->source, format_ptr->target)) {
1181 fprintf(stderr, "Problem setting up to format %s from %s\n", format_ptr->target, format_ptr->source);
1182 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1183 exit(EXIT_FAILURE);
1184 }
1185 }
1186 break;
1187 case IS_EVALUATE_DEFINITION:
1188 evaluate_ptr = (EVALUATE_DEFINITION *)definition[i].structure;
1189 index = evaluate_ptr->is_parameter ? SDDS_GetParameterIndex(&SDDS_output, evaluate_ptr->name) : SDDS_GetColumnIndex(&SDDS_output, evaluate_ptr->name);
1190 if (index >= 0) {
1191 fprintf(stderr, "Can't define new -evaluate %s %s--already exists (sddsprocess)\n", evaluate_ptr->is_parameter ? "parameter" : "column", evaluate_ptr->name);
1192 exit(EXIT_FAILURE);
1193 }
1194 if ((index = evaluate_ptr->is_parameter ? SDDS_GetParameterIndex(&SDDS_output, evaluate_ptr->source) : SDDS_GetColumnIndex(&SDDS_output, evaluate_ptr->source)) < 0) {
1195 fprintf(stderr, "Can't evaluate %s %s--doesn't exist (sddsprocess)\n", evaluate_ptr->is_parameter ? "parameter" : "column", evaluate_ptr->source);
1196 exit(EXIT_FAILURE);
1197 }
1198 if ((evaluate_ptr->is_parameter ? SDDS_GetParameterType(&SDDS_output, index) : SDDS_GetColumnType(&SDDS_output, index)) != SDDS_STRING) {
1199 fprintf(stderr, "Can't evaluate %s %s--not string type (sddsprocess)\n", evaluate_ptr->is_parameter ? "parameter" : "column", evaluate_ptr->source);
1200 exit(EXIT_FAILURE);
1201 }
1202 if (!(evaluate_ptr->is_parameter ? SDDS_ProcessParameterString(&SDDS_output, evaluate_ptr->text, SDDS_WRITEONLY_DEFINITION) : SDDS_ProcessColumnString(&SDDS_output, evaluate_ptr->text, SDDS_WRITEONLY_DEFINITION))) {
1203 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1204 exit(EXIT_FAILURE);
1205 }
1206 break;
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:
1217 break;
1218 case IS_CAST_DEFINITION:
1219 if (!complete_cast_definition(&SDDS_output, (CAST_DEFINITION *)definition[i].structure, &SDDS_input)) {
1220 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1221 exit(EXIT_FAILURE);
1222 }
1223 break;
1224 default:
1225 fprintf(stderr, "error: unknown definition type code %ld seen--this shouldn't happen!\n", definition[i].type);
1226 exit(EXIT_FAILURE);
1227 break;
1228 }
1229 }
1230
1231 if (!SDDS_DeleteParameterFixedValues(&SDDS_output)) {
1232 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1233 exit(EXIT_FAILURE);
1234 }
1235
1236 if (!SDDS_WriteLayout(&SDDS_output)) {
1237 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1238 exit(EXIT_FAILURE);
1239 }
1240
1241 if (summarize) {
1242 for (i = 0; i < definitions; i++) {
1243 switch (definition[i].type) {
1244 case IS_EQUATION_DEFINITION:
1245 equation_ptr = (EQUATION_DEFINITION *)definition[i].structure;
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);
1247 break;
1248 case IS_EVALUATE_DEFINITION:
1249 evaluate_ptr = (EVALUATE_DEFINITION *)definition[i].structure;
1250 fprintf(stderr, "evaluating to %s %s from %s\n", evaluate_ptr->is_parameter ? "parameter" : "column", evaluate_ptr->name, evaluate_ptr->source);
1251 break;
1252 case IS_EDIT_DEFINITION:
1253 edit_ptr = (EDIT_DEFINITION *)definition[i].structure;
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);
1255 break;
1256 case IS_SCAN_DEFINITION:
1257 scan_ptr = (SCAN_DEFINITION *)definition[i].structure;
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);
1259 break;
1260 case IS_PRINT_DEFINITION:
1261 print_ptr = (PRINT_DEFINITION *)definition[i].structure;
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);
1266 break;
1267 case IS_PROCESSING_DEFINITION:
1268 processing_ptr = (PROCESSING_DEFINITION *)definition[i].structure;
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);
1270 break;
1271 case IS_CONVERSION_DEFINITION:
1272 conversion_ptr = (CONVERSION_DEFINITION *)definition[i].structure;
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);
1274 break;
1275 case IS_FILTER_DEFINITION:
1276 filter_ptr = (FILTER_DEFINITION *)definition[i].structure;
1277 show_filters(filter_ptr->is_parameter ? "parameter" : "column", filter_ptr->filter_term, filter_ptr->filter_terms);
1278 break;
1279 case IS_TIME_FILTER_DEFINITION:
1280 time_filter_ptr = (TIME_FILTER_DEFINITION *)definition[i].structure;
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:
1283 match_ptr = (MATCH_DEFINITION *)definition[i].structure;
1284 show_matches(match_ptr->is_parameter ? "parameter" : "column", match_ptr->match_term, match_ptr->match_terms);
1285 break;
1286 case IS_RPNTEST_DEFINITION:
1287 rpntest_ptr = (RPNTEST_DEFINITION *)definition[i].structure;
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);
1290 else
1291 fprintf(stderr, "%s-based rpn test:\n %s\n", rpntest_ptr->is_parameter ? "parameter" : "column", rpntest_ptr->expression);
1292 break;
1293 case IS_NUMBERTEST_DEFINITION:
1294 numbertest_ptr = (NUMBERTEST_DEFINITION *)definition[i].structure;
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" : "");
1296 break;
1297 case IS_RPNEXPRESSION_DEFINITION:
1298 rpnexpression_ptr = (RPNEXPRESSION_DEFINITION *)definition[i].structure;
1299 fprintf(stderr, "%srepeated rpn expression:\n %s\n", (rpnexpression_ptr->repeat ? "" : "un"), rpnexpression_ptr->expression);
1300 break;
1301 case IS_SYSTEM_DEFINITION:
1302 system_ptr = (SYSTEM_DEFINITION *)definition[i].structure;
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);
1304 break;
1305 case IS_FORMAT_DEFINITION:
1306 format_ptr = (FORMAT_DEFINITION *)definition[i].structure;
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>");
1309 break;
1310 case IS_CLIP_DEFINITION:
1311 clip_ptr = (CLIP_DEFINITION *)definition[i].structure;
1312 fprintf(stderr, "page clip operation:\n head = %" PRId64 " tail = %" PRId64 " invert = %hd\n", clip_ptr->head, clip_ptr->tail, clip_ptr->invert);
1313 break;
1314 case IS_FCLIP_DEFINITION:
1315 fclip_ptr = (FCLIP_DEFINITION *)definition[i].structure;
1316 fprintf(stderr, "page clip operation:\n head = %f tail = %f invert = %hd\n", fclip_ptr->fhead, fclip_ptr->ftail, fclip_ptr->invert);
1317 break;
1318 case IS_SPARSE_DEFINITION:
1319 sparse_ptr = (SPARSE_DEFINITION *)definition[i].structure;
1320 fprintf(stderr, "page sparse operation:\n interval = %" PRId64 " offset = %" PRId64 "\n", sparse_ptr->interval, sparse_ptr->offset);
1321 break;
1322 case IS_SAMPLE_DEFINITION:
1323 sample_ptr = (SAMPLE_DEFINITION *)definition[i].structure;
1324 fprintf(stderr, "page sample operation:\n fraction = %.8g\n", sample_ptr->fraction);
1325 break;
1326 case IS_CAST_DEFINITION:
1327 cast_ptr = (CAST_DEFINITION *)definition[i].structure;
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);
1329 break;
1330 default:
1331 fprintf(stderr, "error: unknown definition type code %ld seen--this shouldn't happen!\n", definition[i].type);
1332 exit(EXIT_FAILURE);
1333 break;
1334 }
1335 }
1336 }
1337
1338 while ((page_number = SDDS_ReadPage(&SDDS_input)) > 0) {
1339 if (!SDDS_CopyPage(&SDDS_output, &SDDS_input)) {
1340 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1341 exit(EXIT_FAILURE);
1342 }
1343 if (!SDDS_SetRowFlags(&SDDS_output, 1)) {
1344 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1345 exit(EXIT_FAILURE);
1346 }
1347 if ((n_rows = SDDS_CountRowsOfInterest(&SDDS_output)) <= 0 && SDDS_ColumnCount(&SDDS_output) != 0) {
1348 if (!nowarnings)
1349 fprintf(stderr, "warning: no rows selected for page %" PRId32 "\n", SDDS_output.page_number);
1350 if (n_rows == 0)
1352 else
1353 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1354 }
1355 if (verbose) {
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);
1360 }
1361 }
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;
1365 i = -1;
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:
1370 conversion_ptr = (CONVERSION_DEFINITION *)definition[i].structure;
1371 if (conversion_ptr->is_parameter) {
1372 if (!SDDS_ApplyFactorToParameter(&SDDS_output, conversion_ptr->name, conversion_ptr->factor)) {
1373 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1374 exit(EXIT_FAILURE);
1375 }
1376 } else if (n_rows && !SDDS_ApplyFactorToColumn(&SDDS_output, conversion_ptr->name, conversion_ptr->factor)) {
1377 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1378 exit(EXIT_FAILURE);
1379 }
1380 if (verbose)
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);
1382 break;
1383 case IS_PROCESSING_DEFINITION:
1384 processing_ptr = (PROCESSING_DEFINITION *)definition[i].structure;
1385 if (processing_ptr->type != SDDS_STRING) {
1386 if (!process_column(&SDDS_output, processing_ptr, &result, &stringResult, !nowarnings, threads))
1387 exit(EXIT_FAILURE);
1388 if (processing_ptr->outputType != SDDS_STRING) {
1389 if (!SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, processing_ptr->parameter_name, result, NULL)) {
1390 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1391 exit(EXIT_FAILURE);
1392 }
1393 rpn_store(result, NULL, processing_ptr->memory_number);
1394 if (verbose)
1395 fprintf(stderr, "processing result: %s = %e\n", processing_ptr->parameter_name, result);
1396 } else {
1397 if (!SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, processing_ptr->parameter_name, stringResult, NULL)) {
1398 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1399 exit(EXIT_FAILURE);
1400 }
1401 if (verbose)
1402 fprintf(stderr, "processing result: %s = %s\n", processing_ptr->parameter_name, stringResult);
1403 free(stringResult);
1404 }
1405 } else {
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)) {
1408 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1409 exit(EXIT_FAILURE);
1410 }
1411 free(stringResult);
1412 }
1413 break;
1414 case IS_EDIT_DEFINITION:
1415 edit_ptr = (EDIT_DEFINITION *)definition[i].structure;
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);
1419 exit(EXIT_FAILURE);
1420 }
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);
1423 exit(EXIT_FAILURE);
1424 }
1425 if (verbose)
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);
1427 break;
1428 case IS_SCAN_DEFINITION:
1429 scan_ptr = (SCAN_DEFINITION *)definition[i].structure;
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);
1433 exit(EXIT_FAILURE);
1434 }
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);
1437 exit(EXIT_FAILURE);
1438 }
1439 if (verbose)
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);
1441 break;
1442 case IS_PRINT_DEFINITION:
1443 print_ptr = (PRINT_DEFINITION *)definition[i].structure;
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);
1447 exit(EXIT_FAILURE);
1448 }
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);
1451 exit(EXIT_FAILURE);
1452 }
1453 break;
1454 case IS_EQUATION_DEFINITION:
1455 equation_ptr = (EQUATION_DEFINITION *)definition[i].structure;
1456 if (equation_ptr->is_parameter) {
1457 if (!SDDS_ComputeParameter(&SDDS_output, SDDS_GetParameterIndex(&SDDS_output, equation_ptr->name), equation_ptr->udf_name)) {
1458 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1459 exit(EXIT_FAILURE);
1460 }
1461 } else if (n_rows) {
1462 k = i++;
1463 while (i < definitions && definition[i].type == IS_EQUATION_DEFINITION) {
1464 equation_ptr = (EQUATION_DEFINITION *)definition[i].structure;
1465 if (equation_ptr->is_parameter)
1466 break;
1467 else
1468 i++;
1469 }
1470 if (!SDDS_ComputeSetOfColumns(&SDDS_output, k, i, definition)) {
1471 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1472 exit(EXIT_FAILURE);
1473 }
1474 i--;
1475 }
1476 if (verbose)
1477 fprintf(stderr, "computed %s %s using expression %s\n", equation_ptr->is_parameter ? "parameter" : "column", equation_ptr->name, equation_ptr->equation);
1478 break;
1479 case IS_EVALUATE_DEFINITION:
1480 evaluate_ptr = (EVALUATE_DEFINITION *)definition[i].structure;
1481 if (evaluate_ptr->is_parameter) {
1482 if (!SDDS_EvaluateParameter(&SDDS_output, evaluate_ptr)) {
1483 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1484 exit(EXIT_FAILURE);
1485 }
1486 } else if (n_rows) {
1487 if (!SDDS_EvaluateColumn(&SDDS_output, evaluate_ptr)) {
1488 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1489 exit(EXIT_FAILURE);
1490 }
1491 }
1492 if (verbose)
1493 fprintf(stderr, "computed %s %s using expressions from %s\n", evaluate_ptr->is_parameter ? "parameter" : "column", evaluate_ptr->name, evaluate_ptr->source);
1494 break;
1495 case IS_FORMAT_DEFINITION:
1496 format_ptr = (FORMAT_DEFINITION *)definition[i].structure;
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);
1500 exit(EXIT_FAILURE);
1501 }
1502 } else if (n_rows && !format_column_value(&SDDS_output, format_ptr)) {
1503 fprintf(stderr, "couldn't format column %s\n", format_ptr->target);
1504 exit(EXIT_FAILURE);
1505 }
1506 if (verbose)
1507 fprintf(stderr, "formatted %s %s\n", format_ptr->is_parameter ? "parameter" : "column", format_ptr->target);
1508 break;
1509 case IS_TIME_FILTER_DEFINITION:
1510 time_filter_ptr = (TIME_FILTER_DEFINITION *)definition[i].structure;
1511 if (time_filter_ptr->is_parameter) {
1512 if (!(pardefptr = SDDS_GetParameterDefinition(&SDDS_output, time_filter_ptr->name)) ||
1513 (pardefptr->type == SDDS_STRING || pardefptr->type == SDDS_CHARACTER)) {
1514 fprintf(stderr, "error: unknown or non-numeric parameter %s given for time filter\n", time_filter_ptr->name);
1515 exit(EXIT_FAILURE);
1516 }
1517 accept = SDDS_ItemInsideWindow(SDDS_GetParameter(&SDDS_output, time_filter_ptr->name, &result), 0, pardefptr->type, time_filter_ptr->after, time_filter_ptr->before);
1518
1519 if (!accept)
1520 skip_page = 1;
1521 if (time_filter_ptr->flags & TIMEFILTER_INVERT_GIVEN)
1522 skip_page = !skip_page;
1523 if (skip_page) {
1524 if (verbose)
1525 fputs(" * page outside parameter filter--continuing to next page", stderr);
1526 continue;
1527 }
1528 } else if (n_rows) {
1529 int64_t nleft;
1530 if (verbose) {
1531 fprintf(stderr, " * applying time filter (column %s)", time_filter_ptr->name);
1532 fflush(stderr);
1533 }
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) {
1535 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1536 exit(EXIT_FAILURE);
1537 }
1538 if (verbose) {
1539 fprintf(stderr, "---%" PRId64 " rows left\n", nleft);
1540 fflush(stderr);
1541 }
1542 row_deletion = 1;
1543 }
1544 break;
1545 case IS_FILTER_DEFINITION:
1546 filter_ptr = (FILTER_DEFINITION *)definition[i].structure;
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);
1551 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1552 exit(EXIT_FAILURE);
1553 }
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);
1556 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1557 exit(EXIT_FAILURE);
1558 }
1559 if (filter_term[j].upper < filter_term[j].lower) {
1560 fprintf(stderr, "Error: invalid %s filter provided.\n", filter_term[j].name);
1561 exit(EXIT_FAILURE);
1562 }
1563 }
1564 if (filter_ptr->is_parameter) {
1565 accept = 1;
1566 filter_term = filter_ptr->filter_term;
1567 for (j = 0; j < filter_ptr->filter_terms; j++) {
1568 if (!(pardefptr = SDDS_GetParameterDefinition(&SDDS_output, filter_term[j].name)) ||
1569 (pardefptr->type == SDDS_STRING || pardefptr->type == SDDS_CHARACTER)) {
1570 fprintf(stderr, "error: unknown or non-numeric parameter %s given for filter\n", filter_term[j].name);
1571 exit(EXIT_FAILURE);
1572 }
1573 accept = SDDS_Logic(accept, SDDS_ItemInsideWindow(SDDS_GetParameter(&SDDS_output, filter_term[j].name, &result), 0, pardefptr->type, filter_term[j].lower, filter_term[j].upper), filter_term[j].logic);
1574 }
1575 if (!accept) {
1576 if (verbose)
1577 fputs(" * page failed parameter matching--continuing to next page", stderr);
1578 skip_page = 1;
1579 continue;
1580 }
1581 } else if (n_rows) {
1582 int64_t nleft;
1583 filter_term = filter_ptr->filter_term;
1584 for (j = 0; j < filter_ptr->filter_terms; j++) {
1585 if (verbose) {
1586 fprintf(stderr, " * applying filter term %" PRId64 " (column %s)", j, filter_term[j].name);
1587 fflush(stderr);
1588 }
1589 if ((nleft = SDDS_FilterRowsOfInterest(&SDDS_output, filter_term[j].name, filter_term[j].lower, filter_term[j].upper, filter_term[j].logic)) < 0) {
1590 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1591 exit(EXIT_FAILURE);
1592 }
1593 if (verbose) {
1594 fprintf(stderr, "---%" PRId64 " rows left\n", nleft);
1595 fflush(stderr);
1596 }
1597 }
1598 row_deletion = 1;
1599 }
1600 if (verbose)
1601 fprintf(stderr, "applied %s filter\n", filter_ptr->is_parameter ? "parameter" : "column");
1602 break;
1603 case IS_MATCH_DEFINITION:
1604 match_ptr = (MATCH_DEFINITION *)definition[i].structure;
1605 if (match_ptr->is_parameter) {
1606 accept = 1;
1607 match_term = match_ptr->match_term;
1608 for (j = 0; j < match_ptr->match_terms; j++) {
1609 if (!(pardefptr = SDDS_GetParameterDefinition(&SDDS_output, match_term[j].name)) ||
1610 !(pardefptr->type == SDDS_STRING || pardefptr->type == SDDS_CHARACTER)) {
1611 fprintf(stderr, "error: unknown or numeric parameter %s given for match\n", match_term[j].name);
1612 exit(EXIT_FAILURE);
1613 }
1614 if (pardefptr->type == SDDS_STRING) {
1615 char **ppc;
1616 ppc = SDDS_GetParameter(&SDDS_output, match_term[j].name, NULL);
1617 strcpy(s, *ppc);
1618 } else {
1619 char *pc;
1620 pc = SDDS_GetParameter(&SDDS_output, match_term[j].name, NULL);
1621 sprintf(s, "%c", *pc);
1622 }
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);
1624 }
1625 if (!accept) {
1626 if (verbose)
1627 fputs(" * page failed parameter matching--continuing to next page", stderr);
1628 skip_page = 1;
1629 continue;
1630 }
1631 } else if (n_rows) {
1632 match_term = match_ptr->match_term;
1633 for (j = 0; j < match_ptr->match_terms; j++)
1634 if (SDDS_MatchRowsOfInterest(&SDDS_output, match_term[j].name, match_term[j].string, match_term[j].logic) < 0) {
1635 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1636 exit(EXIT_FAILURE);
1637 }
1638 row_deletion = 1;
1639 }
1640 if (verbose)
1641 fprintf(stderr, "applied %s match\n", match_ptr->is_parameter ? "parameter" : "column");
1642 break;
1643 case IS_RPNTEST_DEFINITION:
1644 rpntest_ptr = (RPNTEST_DEFINITION *)definition[i].structure;
1645 SDDS_StoreParametersInRpnMemories(&SDDS_output);
1646 if (rpntest_ptr->is_parameter) {
1647 rpn_clear();
1648 rpn(rpntest_ptr->expression);
1649 if (rpn_check_error())
1650 exit(EXIT_FAILURE);
1651 if (!pop_log(&test_result))
1652 SDDS_Bomb("aborted due to rpn logical stack/result error for parameter-based test");
1653 rpn_clear();
1654 if (!test_result) {
1655 if (!rpntest_ptr->autostop) {
1656 if (verbose)
1657 fputs(" * page failed rpn test--continuing to next page", stderr);
1658 skip_page = 1;
1659 continue;
1660 } else {
1661 if (verbose)
1662 fputs(" * page failed rpn test--ignore remainder of file", stderr);
1663 exit(EXIT_FAILURE);
1664 }
1665 }
1666 } else if (n_rows) {
1667 if (!SDDS_FilterRowsWithRpnTest(&SDDS_output, rpntest_ptr->expression)) {
1668 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1669 exit(EXIT_FAILURE);
1670 }
1671 row_deletion = 1;
1672 }
1673 if (verbose)
1674 fprintf(stderr, "applied %s-based rpn test:\n %s\n", rpntest_ptr->is_parameter ? "parameter" : "column", rpntest_ptr->expression);
1675 break;
1676 case IS_NUMBERTEST_DEFINITION:
1677 numbertest_ptr = (NUMBERTEST_DEFINITION *)definition[i].structure;
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) {
1681 if (SDDS_FilterRowsByNumScan(&SDDS_output, numbertest_ptr->name, numbertest_ptr->flags) == -1) {
1682 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1683 exit(EXIT_FAILURE);
1684 }
1685 row_deletion = 1;
1686 }
1687 if (verbose)
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 " : "");
1689 break;
1690 case IS_SYSTEM_DEFINITION:
1691 system_ptr = (SYSTEM_DEFINITION *)definition[i].structure;
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);
1695 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1696 exit(EXIT_FAILURE);
1697 }
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);
1700 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1701 exit(EXIT_FAILURE);
1702 }
1703 if (verbose)
1704 fprintf(stderr, "systemed %s %s to produce %s\n", system_ptr->is_parameter ? "parameter" : "column", system_ptr->source, system_ptr->new_name);
1705 break;
1706 case IS_RPNEXPRESSION_DEFINITION:
1707 rpnexpression_ptr = (RPNEXPRESSION_DEFINITION *)definition[i].structure;
1708 if (rpnexpression_ptr->repeat == -1)
1709 continue;
1710 SDDS_StoreParametersInRpnMemories(&SDDS_output);
1711 SDDS_StoreColumnsInRpnArrays(&SDDS_output);
1712 rpn(rpnexpression_ptr->expression);
1713 if (rpn_check_error())
1714 exit(EXIT_FAILURE);
1715 rpn_clear();
1716 if (verbose)
1717 fprintf(stderr, "executed rpn expression:\n %s\n", rpnexpression_ptr->expression);
1718 if (!rpnexpression_ptr->repeat)
1719 rpnexpression_ptr->repeat = -1; /* already done, don't repeat */
1720 break;
1721 case IS_CLIP_DEFINITION:
1722 if (n_rows) {
1723 clip_ptr = (CLIP_DEFINITION *)definition[i].structure;
1724 if (!SDDS_SetRowFlags(&SDDS_output, clip_ptr->invert ? 0 : 1) ||
1725 (clip_ptr->head &&
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))) {
1728 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1729 exit(EXIT_FAILURE);
1730 }
1731 row_deletion = 1;
1732 }
1733 break;
1734 case IS_FCLIP_DEFINITION:
1735 if (n_rows) {
1736 fclip_ptr = (FCLIP_DEFINITION *)definition[i].structure;
1737 fclip_ptr->head = fclip_ptr->fhead * n_rows;
1738 fclip_ptr->tail = fclip_ptr->ftail * n_rows;
1739 if (!SDDS_SetRowFlags(&SDDS_output, fclip_ptr->invert ? 0 : 1) ||
1740 (fclip_ptr->head &&
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))) {
1743 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1744 exit(EXIT_FAILURE);
1745 }
1746 row_deletion = 1;
1747 }
1748 break;
1749 case IS_SPARSE_DEFINITION:
1750 if (n_rows) {
1751 int32_t *sparse_row_flag;
1752 sparse_ptr = (SPARSE_DEFINITION *)definition[i].structure;
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;
1758 if (!SDDS_AssertRowFlags(&SDDS_output, SDDS_FLAG_ARRAY, sparse_row_flag, n_rows)) {
1759 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1760 exit(EXIT_FAILURE);
1761 }
1762 free(sparse_row_flag);
1763 row_deletion = 1;
1764 }
1765 break;
1766 case IS_SAMPLE_DEFINITION:
1767 if (n_rows) {
1768 int32_t *sample_row_flag;
1769 sample_ptr = (SAMPLE_DEFINITION *)definition[i].structure;
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;
1773 if (!SDDS_AssertRowFlags(&SDDS_output, SDDS_FLAG_ARRAY, sample_row_flag, n_rows)) {
1774 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1775 exit(EXIT_FAILURE);
1776 }
1777 free(sample_row_flag);
1778 row_deletion = 1;
1779 }
1780 break;
1781 case IS_CAST_DEFINITION:
1782 cast_ptr = (CAST_DEFINITION *)definition[i].structure;
1783 if (cast_ptr->isParameter) {
1784 if (!cast_parameter_value(&SDDS_output, cast_ptr))
1785 exit(EXIT_FAILURE);
1786 } else if (n_rows && !cast_column_value(&SDDS_output, cast_ptr)) {
1787 exit(EXIT_FAILURE);
1788 }
1789 break;
1790 default:
1791 fprintf(stderr, "error: unknown definition type code %ld seen--this shouldn't happen!\n", definition[i].type);
1792 exit(EXIT_FAILURE);
1793 break;
1794 }
1795 if (n_rows && row_deletion) {
1796 if (i != (definitions - 1) && !SDDS_DeleteUnsetRows(&SDDS_output)) {
1797 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1798 exit(EXIT_FAILURE);
1799 }
1800 if ((n_rows = SDDS_CountRowsOfInterest(&SDDS_output)) <= 0 &&
1801 SDDS_ColumnCount(&SDDS_output) != 0) {
1802 if (!nowarnings)
1803 fprintf(stderr, "warning: no rows selected for page %" PRId32 "\n", SDDS_output.page_number);
1804 if (SDDS_NumberOfErrors())
1805 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1806 continue;
1807 }
1808 if (verbose)
1809 fprintf(stderr, " %" PRId64 " rows left\n", n_rows);
1810 }
1811 }
1812 if (skip_page)
1813 continue;
1814 if (verbose)
1815 fprintf(stderr, " %" PRId64 " rows selected for output\n", n_rows);
1816 if (!SDDS_WritePage(&SDDS_output)) {
1817 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1818 exit(EXIT_FAILURE);
1819 }
1820 }
1821
1822 if (page_number == 0) {
1823 fprintf(stderr, "Error: problem reading input file\n");
1824 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1825 exit(EXIT_FAILURE);
1826 }
1827
1828 if (!SDDS_Terminate(&SDDS_input) || !SDDS_Terminate(&SDDS_output)) {
1829 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1830 exit(EXIT_FAILURE);
1831 }
1832
1833 if (tmpfile_used && !replaceFileAndBackUp(inputfile, outputfile))
1834 exit(EXIT_FAILURE);
1835 free_scanargs(&s_arg, argc);
1836
1837 if (processing_definition)
1838 free_processing_definiton(processing_definition, processing_definitions);
1839 if (equation_definition)
1840 free_equation_definition(equation_definition, equation_definitions);
1841
1842 return EXIT_SUCCESS;
1843}
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:578
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_AssertRowFlags(SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
Sets acceptance flags for rows based on specified criteria.
double * SDDS_GetParameterAsDouble(SDDS_DATASET *SDDS_dataset, char *parameter_name, double *memory)
Retrieves the value of a specified parameter as a double from the current data table of an SDDS datas...
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
int64_t SDDS_FilterRowsByNumScan(SDDS_DATASET *SDDS_dataset, char *filter_column, uint32_t mode)
Filters rows of interest in an SDDS dataset based on numeric scanning of a specified column.
int32_t SDDS_SetRowFlags(SDDS_DATASET *SDDS_dataset, int32_t row_flag_value)
Sets the acceptance flags for all rows in the current data table of a data set.
int32_t SDDS_ItemInsideWindow(void *data, int64_t index, int32_t type, double lower_limit, double upper_limit)
Checks whether a data item is within a specified numeric window.
int64_t SDDS_MatchRowsOfInterest(SDDS_DATASET *SDDS_dataset, char *selection_column, char *label_to_match, int32_t logic)
Matches and marks rows of interest in an SDDS dataset based on label matching.
int32_t SDDS_Logic(int32_t previous, int32_t match, uint32_t logic)
Applies logical operations to determine the new state of a row flag based on previous and current mat...
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_DeleteUnsetRows(SDDS_DATASET *SDDS_dataset)
Deletes rows from an SDDS dataset that are not marked as "of interest".
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_FilterRowsOfInterest(SDDS_DATASET *SDDS_dataset, char *filter_column, double lower_limit, double upper_limit, int32_t logic)
Filters rows of interest in an SDDS dataset based on numeric ranges in a specified column.
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.
Definition SDDS_info.c:485
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.
Definition SDDS_info.c:364
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_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.
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.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
Definition SDDS_utils.c:432
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.
Definition SDDS_utils.c:318
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.
Definition SDDS_utils.c:288
int32_t SDDS_NumberOfErrors()
Retrieves the number of errors recorded by SDDS library routines.
Definition SDDS_utils.c:304
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.
Definition SDDS_utils.c:342
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.
Definition SDDS_utils.c:856
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.
Definition SDDS_utils.c:59
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
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.
double random_1(long iseed)
Generate a uniform random double in [0,1] using a custom seed initialization.
Definition drand.c:175
long fexists(const char *filename)
Checks if a file exists.
Definition fexists.c:27
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
void free_scanargs(SCANNED_ARG **scanned, int argc)
Definition scanargs.c:584
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.
Definition wild_match.c:220
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
Definition wild_match.c:49

◆ process_name_options()

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 )

Definition at line 2169 of file sddsprocess.c.

2170 {
2171 long i, j;
2172 char **new_name;
2173 char *ptr;
2174
2175 *orig_flag = tmalloc(sizeof(**orig_flag) * orig_names);
2176 for (i = 0; i < orig_names; i++)
2177 (*orig_flag)[i] = 1;
2178
2179 if (deletes) {
2180 for (i = 0; i < deletes; i++) {
2181 ptr = expand_ranges(delete[i]);
2182 /* free(delete[i]); */
2183 delete[i] = ptr;
2184 }
2185 for (j = 0; j < orig_names; j++) {
2186 for (i = 0; i < deletes; i++) {
2187 if (wild_match(orig_name[j], delete[i])) {
2188 (*orig_flag)[j] = 0;
2189 break;
2190 }
2191 }
2192 }
2193 }
2194
2195 if (retains) {
2196 for (i = 0; i < retains; i++) {
2197 ptr = expand_ranges(retain[i]);
2198 /* free(retain[i]); */
2199 retain[i] = ptr;
2200 }
2201 if (!deletes)
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])
2206 continue;
2207 for (i = 0; i < retains; i++) {
2208 if (wild_match(orig_name[j], retain[i])) {
2209 (*orig_flag)[j] = 1;
2210 break;
2211 }
2212 }
2213 }
2214 }
2215
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) {
2220 SDDS_CopyString(new_name + j, rename[i][1]);
2221 break;
2222 }
2223 }
2224 if (i == renames)
2225 SDDS_CopyString(new_name + j, orig_name[j]);
2226 for (i = 0; i < edit_requests; i++) {
2227 char edit_buffer[256];
2228 ptr = expand_ranges(edit_request[i].match_string);
2229 /*free(edit_request[i].match_string); */
2230 edit_request[i].match_string = ptr;
2231 if (wild_match(new_name[j], edit_request[i].match_string)) {
2232 strcpy(edit_buffer, new_name[j]);
2233 if (!edit_string(edit_buffer, edit_request[i].edit_string))
2234 SDDS_Bomb("error editing name");
2235 /*free(new_name[j]); */
2236 SDDS_CopyString(&new_name[j], edit_buffer);
2237 }
2238 }
2239 }
2240
2241 return (new_name);
2242}
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
Definition wild_match.c:429

◆ SDDS_ComputeSetOfColumns()

long SDDS_ComputeSetOfColumns ( SDDS_DATASET * SDDS_dataset,
long equ_begin,
long equ_end,
DEFINITION * definition )

Definition at line 1902 of file sddsprocess.c.

1902 {
1903 EQUATION_DEFINITION *equation_ptr;
1904 long column;
1905 SDDS_LAYOUT *layout;
1906 double value;
1907 long equations_present;
1908 COLUMN_LIST *column_list;
1909 long column_list_ptr, max_column_list_counter;
1910 int64_t j;
1911
1912 column_list = NULL;
1913 column_list_ptr = -1;
1914 max_column_list_counter = 0;
1915 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ComputeColumn"))
1916 return (0);
1917 layout = &SDDS_dataset->layout;
1918 column_list = NULL;
1919 column_list_ptr = -1;
1920 max_column_list_counter = 0;
1921 for (equations_present = equ_begin; equations_present < equ_end; equations_present++) {
1922 equation_ptr = (EQUATION_DEFINITION *)definition[equations_present].structure;
1923
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] == '@') {
1930 /* Parameter contains algebraic notation */
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);
1935 free(ptr);
1936 if (!SDDS_CopyString(equation, pfix)) {
1937 fprintf(stderr, "error: problem copying argument string\n");
1938 return 0;
1939 }
1940 } else {
1941 if (!(equation = SDDS_GetParameter(SDDS_dataset, equation_ptr->equation + 1, NULL)))
1942 SDDS_Bomb("unable to read parameter for equation definition");
1943 }
1944
1945 create_udf(equation_ptr->udf_name, *equation);
1946 free(*equation);
1947 }
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)
1950 return (0);
1951 }
1952
1953 if (!SDDS_StoreParametersInRpnMemories(SDDS_dataset))
1954 return (0);
1955 if (!SDDS_StoreColumnsInRpnArrays(SDDS_dataset))
1956 return 0;
1957
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);
1963 }
1964
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);
1968
1969 for (j = 0; j < SDDS_dataset->n_rows; j++) {
1970#if defined(DEBUG)
1971 fprintf(stderr, "Working on row %ld\n", j);
1972#endif
1973 if (!SDDS_StoreRowInRpnMemories(SDDS_dataset, j))
1974 return (0);
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;
1978 rpn_clear();
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)");
1984 return (0);
1985 }
1986#if defined(DEBUG)
1987 fprintf(stderr, "computed row value: %s = %e\n", layout->column_definition[column].name, value);
1988#endif
1989 switch (layout->column_definition[column].type) {
1990 case SDDS_CHARACTER:
1991 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (char)value, -1);
1992 break;
1993 case SDDS_SHORT:
1994 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (short)value, -1);
1995 break;
1996 case SDDS_USHORT:
1997 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (unsigned short)value, -1);
1998 break;
1999 case SDDS_LONG:
2000 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int32_t)value, -1);
2001 break;
2002 case SDDS_ULONG:
2003 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint32_t)value, -1);
2004 break;
2005 case SDDS_LONG64:
2006 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int64_t)value, -1);
2007 break;
2008 case SDDS_ULONG64:
2009 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint64_t)value, -1);
2010 break;
2011 case SDDS_FLOAT:
2012 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (float)value, -1);
2013 break;
2014 case SDDS_DOUBLE:
2015 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (double)value, -1);
2016 break;
2017 case SDDS_LONGDOUBLE:
2018 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (long double)value, -1);
2019 break;
2020 }
2021 }
2022 }
2023
2024 return (1);
2025}
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
Definition SDDStypes.h:67
#define SDDS_FLOAT
Identifier for the float data type.
Definition SDDStypes.h:43
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
Definition SDDStypes.h:55
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
#define SDDS_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
Definition SDDStypes.h:79
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
Definition SDDStypes.h:31
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
Definition cp_str.c:28

◆ SDDS_EvaluateColumn()

long SDDS_EvaluateColumn ( SDDS_DATASET * SDDS_dataset,
EVALUATE_DEFINITION * definition )

Definition at line 2027 of file sddsprocess.c.

2027 {
2028 double value;
2029 char **equation;
2030 long type, column;
2031 int64_t j;
2032
2033 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ComputeColumn"))
2034 return (0);
2035 if (!SDDS_StoreParametersInRpnMemories(SDDS_dataset))
2036 return (0);
2037 if (!SDDS_StoreColumnsInRpnArrays(SDDS_dataset))
2038 return 0;
2039
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);
2045 }
2046
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);
2050
2051 if (!(equation = (char **)SDDS_GetColumn(SDDS_dataset, definition->source)))
2052 return 0;
2053
2054 type = SDDS_GetColumnType(SDDS_dataset, column = SDDS_GetColumnIndex(SDDS_dataset, definition->name));
2055
2056 for (j = 0; j < SDDS_dataset->n_rows; j++) {
2057 if (!SDDS_StoreRowInRpnMemories(SDDS_dataset, j))
2058 return (0);
2059 rpn_clear();
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)");
2064 return (0);
2065 }
2066 switch (type) {
2067 case SDDS_CHARACTER:
2068 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (char)value, -1);
2069 break;
2070 case SDDS_SHORT:
2071 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (short)value, -1);
2072 break;
2073 case SDDS_USHORT:
2074 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (unsigned short)value, -1);
2075 break;
2076 case SDDS_LONG:
2077 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int32_t)value, -1);
2078 break;
2079 case SDDS_ULONG:
2080 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint32_t)value, -1);
2081 break;
2082 case SDDS_LONG64:
2083 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (int64_t)value, -1);
2084 break;
2085 case SDDS_ULONG64:
2086 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (uint64_t)value, -1);
2087 break;
2088 case SDDS_FLOAT:
2089 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (float)value, -1);
2090 break;
2091 case SDDS_DOUBLE:
2092 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (double)value, -1);
2093 break;
2094 case SDDS_LONGDOUBLE:
2095 SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, column, (long double)value, -1);
2096 break;
2097 }
2098 }
2099
2100 return (1);
2101}
void * SDDS_GetColumn(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves a copy of the data for a specified column, including only rows marked as "of interest".

◆ SDDS_EvaluateParameter()

long SDDS_EvaluateParameter ( SDDS_DATASET * SDDS_dataset,
EVALUATE_DEFINITION * definition )

Definition at line 2103 of file sddsprocess.c.

2103 {
2104 double value;
2105 char **equation;
2106 long parameter;
2107
2108 if (!SDDS_StoreParametersInRpnMemories(SDDS_dataset))
2109 return (0);
2110
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);
2116 }
2117
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);
2121
2122 if (!(equation = (char **)SDDS_GetParameter(SDDS_dataset, definition->source, NULL)))
2123 return 0;
2124
2125 rpn_clear();
2126 value = rpn(*equation);
2127 fprintf(stderr, "value = %e\n", value);
2128 free(*equation);
2129 if (rpn_check_error()) {
2130 SDDS_SetError("Unable to compute rpn expression--rpn error (SDDS_EvaluateParameter)");
2131 return (0);
2132 }
2133 switch (SDDS_GetParameterType(SDDS_dataset, parameter = SDDS_GetParameterIndex(SDDS_dataset, definition->name))) {
2134 case SDDS_CHARACTER:
2135 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (char)value, -1);
2136 break;
2137 case SDDS_SHORT:
2138 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (short)value, -1);
2139 break;
2140 case SDDS_USHORT:
2141 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (unsigned short)value, -1);
2142 break;
2143 case SDDS_LONG:
2144 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (int32_t)value, -1);
2145 break;
2146 case SDDS_ULONG:
2147 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (uint32_t)value, -1);
2148 break;
2149 case SDDS_LONG64:
2150 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (int64_t)value, -1);
2151 break;
2152 case SDDS_ULONG64:
2153 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (uint64_t)value, -1);
2154 break;
2155 case SDDS_FLOAT:
2156 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (float)value, -1);
2157 break;
2158 case SDDS_DOUBLE:
2159 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (double)value, -1);
2160 break;
2161 case SDDS_LONGDOUBLE:
2162 SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, parameter, (long double)value, -1);
2163 break;
2164 }
2165
2166 return (1);
2167}

Variable Documentation

◆ i_page_mem

long i_page_mem = -1
static

Definition at line 326 of file sddsprocess.c.

◆ i_row_mem

long i_row_mem = -1
static

Definition at line 326 of file sddsprocess.c.

◆ mode_name

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

Definition at line 147 of file sddsprocess.c.

147 {
148 "column",
149 "parameter",
150 "array",
151 };

◆ n_rows_mem

long n_rows_mem = -1
static

Definition at line 326 of file sddsprocess.c.

◆ option

char* option[N_OPTIONS]

Definition at line 193 of file sddsprocess.c.

193 {
194 "process",
195 "match",
196 "filter",
197 "rpndefinitionsfiles",
198 "rpnexpression",
199 "define",
200 "test",
201 "summarize",
202 "verbose",
203 "convertunits",
204 "scan",
205 "print",
206 "edit",
207 "system",
208 "redefine",
209 "nowarnings",
210 "ifnot",
211 "ifis",
212 "clip",
213 "sparse",
214 "sample",
215 "pipe",
216 "numbertest",
217 "reedit",
218 "format",
219 "cast",
220 "reprint",
221 "delete",
222 "retain",
223 "description",
224 "fclip",
225 "timeFilter",
226 "majorOrder",
227 "evaluate",
228 "threads",
229};

◆ table_number_mem

long table_number_mem = -1
static

Definition at line 326 of file sddsprocess.c.

◆ usageArray

char* usageArray[]

Definition at line 231 of file sddsprocess.c.

231 {
232 "Usage:\n",
233 " sddsprocess [<SDDSinputfile>] [<SDDSoutputfile>] [OPTIONS]\n",
234 "\n",
235 "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",
290 " -summarize\n",
291 " Display a summary of the processing operations performed.\n",
292 " -verbose\n",
293 " Enable verbose output for detailed processing information.\n",
294 " -nowarnings\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",
306 "\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",
313 "\n",
314 "Description:\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",
317 NULL};