SDDSlib
Loading...
Searching...
No Matches
SDDSaps.h
1/*************************************************************************\
2* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.
6* This file is distributed subject to a Software License Agreement found
7* in the file LICENSE that is included with this distribution.
8\*************************************************************************/
9
10/* file: SDDSaps.h
11 * contents: header file for routines used by SDDS command-line applications
12 *
13 * M. Borland, 1993.
14 $Log: not supported by cvs2svn $
15 Revision 1.39 2011/05/16 20:52:13 shang
16 added lower and upper limit parameter for processing_definition so that the lower and upper limit can be obtained from parameters.
17
18 Revision 1.38 2010/12/09 16:13:26 borland
19 The ifnot and ifis options now respect the -nowarnings request.
20
21 Revision 1.37 2010/12/02 22:51:28 borland
22 Added signedlargest and signedsmallest processing modes.
23
24 Revision 1.36 2009/07/10 21:03:21 shang
25 modified the filter option to accept string as parameter name for defining lower and upper limit of the filter
26
27 Revision 1.35 2008/01/15 22:19:17 shang
28 Added -process mode for percentile range computation (prange).
29
30 Revision 1.34 2005/11/15 20:53:58 soliday
31 Updated some routines used by sddsprocess that were causing trouble when
32 compiled with a 64bit compiler.
33
34 Revision 1.33 2005/11/04 22:46:10 soliday
35 Updated code to be compiled by a 64 bit processor.
36
37 Revision 1.32 2003/10/28 19:44:45 borland
38 Added edit qualifier to scan option. Allows pre-editing a string before
39 scanning it, which may save creation of an intermediate parameter or
40 column.
41
42 Revision 1.31 2003/09/23 22:02:56 soliday
43 Added the exclude option in the expandDefinitions function.
44
45 Revision 1.30 2003/07/22 15:21:33 soliday
46 Added the product process.
47
48 Revision 1.29 2003/06/02 21:39:12 soliday
49 Added the function to add parentheses around a string before calling if2pf
50
51 Revision 1.28 2003/04/04 00:49:19 shang
52 added structure for define timefileter and related functions
53
54 Revision 1.27 2003/03/21 23:51:51 borland
55 Added "integral" processing mode.
56
57 Revision 1.26 2002/08/14 17:12:34 soliday
58 Added Open License
59
60 Revision 1.25 2002/04/05 21:55:51 shang
61 remove definitions related to pick function
62
63 Revision 1.24 2002/03/25 21:00:38 shang
64 added FCLIP structure and modified PROCESSING_DEFINITION structure,
65 and defined constants for fclip option, pick process mode, match column
66 and match value
67
68 Revision 1.23 2000/10/07 01:20:38 borland
69 Added 'mode' processing mode. (The mode is the value that occurs most often.)
70
71 Revision 1.22 2000/04/07 15:04:42 soliday
72 Added a lot of missing prototypes.
73
74 Revision 1.21 1999/07/09 15:06:03 soliday
75 Added definitions for isnan, sleep, popen, and pclose for WIN32
76
77 Revision 1.20 1999/06/03 17:04:07 soliday
78 Commented out definition_type_name because it is not used.
79
80 Revision 1.19 1999/05/25 19:01:14 soliday
81 Removed compiler warning on linux.
82
83 Revision 1.18 1998/12/16 21:22:45 borland
84 Renamed SDDS_RedefineParameter and SDDS_RedefineColumn by appending
85 "CL" to the names.
86
87 Revision 1.17 1998/06/24 19:23:48 borland
88 The -process option now allows specifying a string column with the
89 functionOf qualifier for some types of processing. This is allowed
90 if the position qualifier is also given, resulting in the ability to
91 pick out string data based on processing of numeric data.
92
93 Revision 1.16 1998/06/03 17:33:01 borland
94 Added support for templates in -print option. Printing to columns is
95 now faster and also implements printing of information from column
96 metadata (e.g., name, symbol, units).
97
98 Revision 1.15 1998/02/18 23:44:25 borland
99 Added -reprint option.
100
101 Revision 1.14 1996/10/30 21:57:22 borland
102 Added -process mode for percentile computation.
103
104 * Revision 1.13 1996/07/02 01:38:09 borland
105 * Added -cast option to convert between numerical types.
106 *
107 * Revision 1.12 1996/05/23 21:19:14 borland
108 * Added -format option and supporting routines.
109 *
110 * Revision 1.11 1996/02/15 16:16:16 borland
111 * Added -reedit option.
112 *
113 * Revision 1.10 1996/02/12 17:24:53 borland
114 * Added prototype for expandDefinitions(). Added select and editSelection
115 * fields to EQUATION_DEFINITION structure.
116 *
117 * Revision 1.9 1996/01/17 16:44:49 borland
118 * Added support for wildcard strings in units conversion (-convertUnits option).
119 *
120 * Revision 1.8 1996/01/12 19:02:16 borland
121 * Added -numberTest option to sddsprocess, with supporting code in SDDSaps.*.
122 *
123 * Revision 1.7 1995/12/10 02:34:34 borland
124 * Added quartile and decile range -process modes.
125 *
126 * Revision 1.6 1995/10/07 22:43:02 borland
127 * Changed code to use topLimit and bottomLimit consistently rather than
128 * Threshold; redo of earlier change that was somehow lost.
129 *
130 * Revision 1.5 1995/10/07 18:40:44 borland
131 * Added argument to process_column() to carry -nowarnings option from
132 * sddsprocess commandline.
133 *
134 * Revision 1.4 1995/10/06 18:02:45 borland
135 * Added topLimit and bottomLimit qualifiers for sddsprocess -process option;
136 * added code to support this in SDDSaps.
137 *
138 * Revision 1.3 1995/09/12 03:07:51 borland
139 * Changed logic elements of MATCH_TERM and FILTER_TERM to unsigned long.
140 *
141 * Revision 1.2 1995/09/05 21:05:48 saunders
142 * First test release of the SDDS1.5 package.
143 *
144 */
145
146#define COLUMN_BASED 0
147#define PARAMETER_BASED 1
148#define ARRAY_BASED 2
149#define DATA_CLASS_KEYWORDS 3
150
151#if defined(_WIN32)
152/*#define isnan(x) _isnan(x)*/
153# define sleep(sec) Sleep(sec * 1000)
154# define popen(x, y) _popen(x, y)
155# define pclose(x) _pclose(x)
156#endif
157
158extern char *data_class_keyword[DATA_CLASS_KEYWORDS];
159
160typedef struct {
161 char **name;
162 long *type, items;
164
165typedef struct {
166 char *name, *format;
168
169typedef struct {
170 char *text, *name, *equation, *udf_name, *select, *editSelection, *exclude;
171 long is_parameter;
172 long redefinition;
173 char **argv;
174 long argc;
176#define IS_EQUATION_DEFINITION 0
177
178typedef struct {
179 char *text, *sscanf_string, *source, *new_name, *edit;
180 long is_parameter;
182#define IS_SCAN_DEFINITION 1
183
184typedef struct {
185 char *text, *edit_command, *source, *new_name;
186 long is_parameter, reedit;
187 char **argv;
188 long argc;
190#define IS_EDIT_DEFINITION 2
191
192typedef struct {
193 char *text, *printf_string, *new_name, **source;
194 long sources, is_parameter, reprint;
195 char *select, *editSelection, *exclude;
197#define IS_PRINT_DEFINITION 3
198
199typedef struct {
200 char *parameter_name, *column_name, *description, *symbol, *lower_par, *upper_par;
201 char *head_par, *tail_par, *fhead_par, *ftail_par, *offset_par, *factor_par;
202 char *functionOf, *weightBy, *match_value, *match_column;
203 double lowerLimit, upperLimit, offset, factor, fhead, ftail, topLimit, bottomLimit;
204 double percentileLevel, binSize, defaultValue;
205 int32_t head, tail;
206 long type, outputType;
207 long mode, memory_number;
208 unsigned long flags;
210#define IS_PROCESSING_DEFINITION 4
211#define PROCESSING_LOLIM_GIVEN 0x000001UL
212#define PROCESSING_UPLIM_GIVEN 0x000002UL
213#define PROCESSING_INVERT_OFFSET 0x000004UL
214#define PROCESSING_DESCRIP_GIVEN 0x000008UL
215#define PROCESSING_FUNCOF_GIVEN 0x000010UL
216#define PROCESSING_TAIL_GIVEN 0x000020UL
217#define PROCESSING_HEAD_GIVEN 0x000040UL
218#define PROCESSING_SYMBOL_GIVEN 0x000080UL
219#define PROCESSING_WEIGHT_GIVEN 0x000100UL
220#define PROCESSING_POSITION_GIVEN 0x000200UL
221#define PROCESSING_OFFSET_GIVEN 0x000400UL
222#define PROCESSING_FACTOR_GIVEN 0x000800UL
223#define PROCESSING_FTAIL_GIVEN 0x001000UL
224#define PROCESSING_FHEAD_GIVEN 0x002000UL
225#define PROCESSING_TOPLIM_GIVEN 0x004000UL
226#define PROCESSING_BOTLIM_GIVEN 0x008000UL
227#define PROCESSING_PERCLEVEL_GIVEN 0x010000UL
228#define PROCESSING_BINSIZE_GIVEN 0x020000UL
229#define PROCESSING_MATCHCOLUMN_GIVEN 0x040000UL
230#define PROCESSING_MATCHVALUE_GIVEN 0x080000UL
231#define PROCESSING_OVERWRITE_GIVEN 0x100000UL
232#define PROCESSING_DEFAULTVALUE_GIVEN 0x200000UL
233#define PROCESSING_INVERT_FACTOR 0x400000UL
234
235typedef struct {
236 char *name, *new_units, *old_units;
237 double factor;
238 long is_parameter;
240#define IS_CONVERSION_DEFINITION 5
241
242typedef struct {
243 char *name, *string;
244 unsigned long logic;
245} MATCH_TERM;
246
247typedef struct {
248 char *name, *upperPar, *lowerPar;
249 double lower, upper;
250 unsigned long logic;
252
253typedef struct {
254 FILTER_TERM *filter_term;
255 long filter_terms, is_parameter;
257#define IS_FILTER_DEFINITION 6
258
259typedef struct {
260 MATCH_TERM *match_term;
261 long match_terms, is_parameter;
263#define IS_MATCH_DEFINITION 7
264
265typedef struct {
266 char *expression;
267 long autostop, is_parameter;
269#define IS_RPNTEST_DEFINITION 8
270
271typedef struct {
272 char *text, *source, *new_name;
273 long is_parameter;
275#define IS_SYSTEM_DEFINITION 9
276
277typedef struct {
278 char *expression;
279 long repeat;
281#define IS_RPNEXPRESSION_DEFINITION 10
282
283typedef struct {
284 int64_t head, tail;
285 short invert;
287#define IS_CLIP_DEFINITION 11
288
289typedef struct {
290 int64_t interval, offset;
292#define IS_SPARSE_DEFINITION 12
293
294typedef struct {
295 double fraction;
297#define IS_SAMPLE_DEFINITION 13
298
299typedef struct {
300 char *name;
301 short is_parameter;
302 unsigned long flags;
304#define IS_NUMBERTEST_DEFINITION 14
305
306typedef struct {
307 char *target, *source, *stringFormat, *doubleFormat, *longFormat;
308 long is_parameter;
310#define IS_FORMAT_DEFINITION 15
311
312typedef struct {
313 char *source, *newName, *newTypeName;
314 long isParameter;
315 int32_t newType;
317#define IS_CAST_DEFINITION 16
318
319typedef struct {
320 int64_t head, tail;
321 double fhead, ftail;
322 short invert;
324#define IS_FCLIP_DEFINITION 17
325
326typedef struct {
327 char *name;
328 double before, after;
329 unsigned long flags;
330 long is_parameter;
332#define TIMEFILTER_BEFORE_GIVEN 0x00001
333#define TIMEFILTER_AFTER_GIVEN 0x00002
334#define TIMEFILTER_INVERT_GIVEN 0x00004
335
336#define IS_TIME_FILTER_DEFINITION 18
337
338typedef struct {
339 char *text, *name, *source, **argv;
340 long is_parameter;
342#define IS_EVALUATE_DEFINITION 19
343
344#define DEFINITION_TYPES 20
345
346/*
347static char *definition_type_name[DEFINITION_TYPES] = {
348 "define", "scan", "edit", "print", "process", "convert", "filter", "match", "test",
349 "system", "rpn_expression", "clip", "sparse", "sample", "numbertest", "format",
350 "cast",
351 } ;
352*/
353
354typedef struct {
355 long type;
356 void *structure;
357} DEFINITION;
358
359typedef struct {
360 FILE *fp;
361 char *item[4];
362 long columns;
363 int64_t points;
364 long parameter_output;
365 void **definitions;
366 long counter;
368
369#define PROCESS_COLUMN_MEAN 0
370#define PROCESS_COLUMN_RMS 1
371#define PROCESS_COLUMN_SUM 2
372#define PROCESS_COLUMN_STAND_DEV 3
373#define PROCESS_COLUMN_MAD 4
374#define PROCESS_COLUMN_MINIMUM 5
375#define PROCESS_COLUMN_MAXIMUM 6
376#define PROCESS_COLUMN_SMALLEST 7
377#define PROCESS_COLUMN_LARGEST 8
378#define PROCESS_COLUMN_FIRST 9
379#define PROCESS_COLUMN_LAST 10
380#define PROCESS_COLUMN_COUNT 11
381#define PROCESS_COLUMN_SPREAD 12
382#define PROCESS_COLUMN_MEDIAN 13
383#define PROCESS_COLUMN_BASELEVEL 14
384#define PROCESS_COLUMN_TOPLEVEL 15
385#define PROCESS_COLUMN_AMPLITUDE 16
386#define PROCESS_COLUMN_RISETIME 17
387#define PROCESS_COLUMN_FALLTIME 18
388#define PROCESS_COLUMN_FWHM 19
389#define PROCESS_COLUMN_FWTM 20
390#define PROCESS_COLUMN_CENTER 21
391#define PROCESS_COLUMN_ZEROCROSSING 22
392#define PROCESS_COLUMN_FWHA 23
393#define PROCESS_COLUMN_FWTA 24
394#define PROCESS_COLUMN_SIGMA 25
395#define PROCESS_COLUMN_SLOPE 26
396#define PROCESS_COLUMN_INTERCEPT 27
397#define PROCESS_COLUMN_LFSD 28
398#define PROCESS_COLUMN_QRANGE 29
399#define PROCESS_COLUMN_DRANGE 30
400#define PROCESS_COLUMN_PERCENTILE 31
401#define PROCESS_COLUMN_MODE 32
402#define PROCESS_COLUMN_INTEGRAL 33
403#define PROCESS_COLUMN_PRODUCT 34
404#define PROCESS_COLUMN_PRANGE 35
405#define PROCESS_COLUMN_SIGNEDSMALLEST 36
406#define PROCESS_COLUMN_SIGNEDLARGEST 37
407#define PROCESS_COLUMN_GMINTEGRAL 38
408#define PROCESS_COLUMN_CORRELATION 39
409#define N_PROCESS_COLUMN_MODES 40
410#if 0
411extern char *process_column_mode[N_PROCESS_COLUMN_MODES];
412extern char *process_column_name[N_PROCESS_COLUMN_MODES];
413extern char *process_column_description[N_PROCESS_COLUMN_MODES];
414#endif
415
416extern char *addOuterParentheses(char *arg);
417extern void show_process_modes(FILE *fp);
418extern long process_column(SDDS_DATASET *Table, PROCESSING_DEFINITION *processing_ptr, double *result,
419 char **stringResult, long warnings, int threads);
420extern char *process_string_column(SDDS_DATASET *Dataset, PROCESSING_DEFINITION *processing_ptr, long warnings);
421extern long process_filter_request(FILTER_TERM **filter, char **argument, long arguments);
422extern long process_match_request(MATCH_TERM **match, char **argument, long arguments);
423extern void scan_label_parameter(LABEL_PARAMETER *label, char *string);
424extern void show_matches(char *type, MATCH_TERM *match, long matches);
425extern void show_filters(char *type, FILTER_TERM *filter, long filters);
426extern EQUATION_DEFINITION *process_new_equation_definition(char **argument, long arguments);
427extern EVALUATE_DEFINITION *process_new_evaluate_definition(char **argument, long arguments);
428extern EVALUATE_DEFINITION *process_new_evalute_definition(char **argument, long arguments);
429extern SCAN_DEFINITION *process_new_scan_definition(char **argument, long arguments);
430extern CAST_DEFINITION *process_new_cast_definition(char **argument, long arguments);
431extern EDIT_DEFINITION *process_new_edit_definition(char **argument, long arguments, short reedit);
432extern PRINT_DEFINITION *process_new_print_definition(char **argument, long arguments);
433extern FORMAT_DEFINITION *process_new_format_definition(char **argument, long arguments);
434extern PROCESSING_DEFINITION *record_processing_definition(char **argument, long arguments);
435extern PROCESSING_DEFINITION *copyProcessingDefinition(PROCESSING_DEFINITION *source);
436extern void expandProcessingDefinitions(DEFINITION **definition, long *definitions, SDDS_DATASET *SDDS_dataset);
437extern CONVERSION_DEFINITION *copyConversionDefinition(CONVERSION_DEFINITION *source);
438extern void expandConversionDefinitions(DEFINITION **definition, long *definitions, SDDS_DATASET *SDDS_dataset);
439extern void expandDefinitions(DEFINITION **definition, long *definitions, SDDS_DATASET *SDDS_dataset);
440
441extern CONVERSION_DEFINITION *process_conversion_definition(char **argument, long arguments);
442extern FILTER_DEFINITION *process_new_filter_definition(char **argument, long arguments);
443extern TIME_FILTER_DEFINITION *process_new_time_filter_definition(char **argument, long arguments);
444extern MATCH_DEFINITION *process_new_match_definition(char **argument, long arguments);
445extern RPNTEST_DEFINITION *process_new_rpntest_definition(char **argument, long arguments);
446extern NUMBERTEST_DEFINITION *process_new_numbertest_definition(char **argument, long arguments);
447extern RPNEXPRESSION_DEFINITION *process_new_rpnexpression_definition(char **argument, long arguments);
448extern CLIP_DEFINITION *process_new_clip_definition(char **argument, long arguments);
449extern FCLIP_DEFINITION *process_new_fclip_definition(char **argument, long arguments);
450extern SPARSE_DEFINITION *process_new_sparse_definition(char **argument, long arguments);
451extern SAMPLE_DEFINITION *process_new_sample_definition(char **argument, long arguments);
452extern SYSTEM_DEFINITION *process_new_system_definition(char **argument, long arguments);
453extern OUTPUT_REQUEST *process_output_request(char **argument, long arguments, OUTPUT_REQUEST *last_request);
454extern char *determine_item_name(char **argument, OUTPUT_REQUEST *last_request, long index);
455extern void set_up_output(char *filename, OUTPUT_REQUEST *output, LABEL_PARAMETER *label_parameter, long label_parameters,
456 long separate_tables, long announce_openings, SDDS_DATASET *SDDS_dataset);
457extern long complete_processing_definitions(PROCESSING_DEFINITION **processing_definition, long processing_definitions,
458 SDDS_DATASET *SDDS_dataset);
459
460extern long system_column_value(SDDS_DATASET *SDDS_dataset, char *target, char *source);
461extern long system_parameter_value(SDDS_DATASET *SDDS_dataset, char *target, char *source);
462extern long run_on_pipe(char *command, char *buffer, long buffer_length);
463
464/* used for redefining parameters and columns using sddsprocess-style commandline arguments */
465extern long SDDS_RedefineParameterCL(SDDS_DATASET *SDDS_dataset, char *parameter, char **argv, long argc);
466extern long SDDS_RedefineColumnCL(SDDS_DATASET *SDDS_dataset, char *column, char **argv, long argc);
467
468extern long edit_string(char *text, char *edit);
469
470extern long reformatString(char *buffer, long bufferSize, char *string, char *stringFormat,
471 char *doubleFormat, char *longFormat);
472
473extern long cast_column_value(SDDS_DATASET *SDDS_dataset, CAST_DEFINITION *cast);
474extern long cast_parameter_value(SDDS_DATASET *SDDS_dataset, CAST_DEFINITION *cast);
475
476void add_definition(DEFINITION **definition, long *definitions, void *structure, long type);
477long check_ifitems(SDDS_DATASET *SDDS_dataset, IFITEM_LIST *ifitem, long desired, long announce);
478long complete_cast_definition(SDDS_DATASET *SDDSout, CAST_DEFINITION *defi,
479 SDDS_DATASET *SDDSin);
480long edit_parameter_value(SDDS_DATASET *SDDS_dataset, char *target, char *source, char *edit_command);
481long edit_column_value(SDDS_DATASET *SDDS_dataset, char *target, char *source, char *edit_command);
482long scan_parameter_value(SDDS_DATASET *SDDS_dataset, char *target, char *source, char *format,
483 char *edit);
484long scan_column_value(SDDS_DATASET *SDDS_dataset, char *target, char *source, char *format,
485 char *edit);
486long print_parameter_value(SDDS_DATASET *SDDS_dataset, char *target, char **source, long sources, char *format);
487long print_column_value(SDDS_DATASET *SDDS_dataset, char *target, char **source, long sources, char *format);
488long format_parameter_value(SDDS_DATASET *SDDS_dataset, FORMAT_DEFINITION *definition);
489long format_column_value(SDDS_DATASET *SDDS_dataset, FORMAT_DEFINITION *definition);
490long ParameterScansAsNumber(SDDS_DATASET *dataset, char *name, short invert);
491
492/* rpn function for getting logical values */
493extern long pop_log(int32_t *logical);
494
495#define is_logic_character(c) ((c) == '|' || (c) == '&' || (c) == '!')
496
497void add_ifitem(IFITEM_LIST *ifitem, char **name, long names);
498
499#include "scan.h"
500long add_sddsfile_arguments(SCANNED_ARG **scanned, int argc);