32char *data_class_keyword[DATA_CLASS_KEYWORDS] = {
39 char *name, *description;
42#define PROCMODE_NORMAL 0x0000UL
43#define PROCMODE_FUNCOF_REQUIRED 0x0001UL
44#define PROCMODE_FUNCOF_UNITS 0x0002UL
45#define PROCMODE_WEIGHT_OK 0x0004UL
46#define PROCMODE_POSITION_OK 0x0008UL
47#define PROCMODE_STRING_OK 0x0010UL
48#define PROCMODE_YoX_UNITS 0x0020UL
49#define PROCMODE_STRINGPOS_OK 0x0040UL
50#define PROCMODE_YtX_UNITS 0x0080UL
51#define PROCMODE_Y_UNITS 0x0100UL
52#define PROCMODE_NO_UNITS x00200UL
54static char *process_column_name[N_PROCESS_COLUMN_MODES] = {NULL};
56 {
"average",
"average of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
57 {
"rms",
"rms of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
58 {
"sum",
"sum of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
59 {
"standarddeviation",
"standard deviation of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
60 {
"mad",
"mean absolute deviation of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
61 {
"minimum",
"minimum of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
62 {
"maximum",
"maximum of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
63 {
"smallest",
"smallest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
64 {
"largest",
"largest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
65 {
"first",
"first ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_STRING_OK},
66 {
"last",
"last ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_STRING_OK},
67 {
"count",
"count ", PROCMODE_NORMAL},
68 {
"spread",
"spread in ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
69 {
"median",
"median of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
70 {
"baselevel",
"base level of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
71 {
"toplevel",
"top level of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
72 {
"amplitude",
"amplitude of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
73 {
"risetime",
"risetime of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
74 {
"falltime",
"falltime of", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
75 {
"fwhm",
"fwhm of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
76 {
"fwtm",
"fwtm of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
77 {
"center",
"center of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
78 {
"zerocrossing",
"zero crossing of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
79 {
"fwha",
"fwha of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
80 {
"fwta",
"fwta of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
81 {
"sigma",
"sigma of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
82 {
"slope",
"slope of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_YoX_UNITS},
83 {
"intercept",
"intercept of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
84 {
"lfsd",
"linear-fit standard deviation of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
85 {
"qrange",
"quartile range", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
86 {
"drange",
"decile range", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
87 {
"percentile",
"percentile", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
88 {
"mode",
"mode of", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
89 {
"integral",
"integral of ", PROCMODE_NORMAL | PROCMODE_FUNCOF_REQUIRED | PROCMODE_YtX_UNITS},
90 {
"product",
"product of ", PROCMODE_NORMAL | PROCMODE_WEIGHT_OK},
91 {
"prange",
"percentile range", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
92 {
"signedsmallest",
"signed smallest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
93 {
"signedlargest",
"signed largest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
94 {
"gmintegral",
"integral of ", PROCMODE_NORMAL | PROCMODE_FUNCOF_REQUIRED | PROCMODE_YtX_UNITS},
95 {
"correlation",
"correlation coefficient", PROCMODE_FUNCOF_REQUIRED}};
100#define SELECT_QUALIFIER 0
101#define EDITSELECTION_QUALIFIER 1
102#define EXCLUDE_QUALIFIER 2
103#define SELECT_QUALIFIERS 3
104static char *selectQualifier[SELECT_QUALIFIERS] = {
105 "select",
"editselection",
"exclude"};
107void GillMillerIntegration1(
double *indepData,
double *data,
long n_data,
double *result);
109void show_process_modes(FILE *fp) {
110 long i, length, maxLength, nPerLine;
114 for (i = 0; i < N_PROCESS_COLUMN_MODES; i++)
115 if ((length = strlen(process_column_data[i].name)) > maxLength)
117 sprintf(format,
"%%%lds%%c", maxLength + 1);
118 nPerLine = 80 / (maxLength + 2);
119 fprintf(fp,
"processing modes:\n");
120 for (i = 0; i < N_PROCESS_COLUMN_MODES; i++)
121 fprintf(fp, format, process_column_data[i].name, (i + 1) % nPerLine ?
' ' :
'\n');
126void add_ifitem(
IFITEM_LIST *ifitem,
char **name,
long names) {
128 if (ifitem->items == 0) {
132 ifitem->name =
trealloc(ifitem->name,
sizeof(*ifitem->name) * (ifitem->items + names - 1));
133 ifitem->type =
trealloc(ifitem->type,
sizeof(*ifitem->type) * (ifitem->items + names - 1));
134 if ((type =
match_string(name[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) < 0)
135 SDDS_Bomb(
"invalid -ifnot syntax---column, parameter, or array keyword required");
136 for (i = 1; i < names; i++)
137 ifitem->type[ifitem->items + i - 1] = type;
139 SDDS_Bomb(
"problem copying names for -ifnot or -ifis option");
140 ifitem->items += names - 1;
145 for (i = 0; i < ifitem->items; i++) {
146 switch (ifitem->type[i]) {
150 case PARAMETER_BASED:
157 SDDS_Bomb(
"internal error---unknown ifitem type");
161 if ((index >= 0) != desired) {
164 fprintf(stderr,
"%s %s does not exist--aborting\n",
165 data_class_keyword[ifitem->type[i]], ifitem->name[i]);
169 fprintf(stderr,
"%s %s exists--aborting\n",
170 data_class_keyword[ifitem->type[i]], ifitem->name[i]);
177FILTER_DEFINITION *process_new_filter_definition(
char **argument,
long arguments) {
180 if (!(defi =
tmalloc(
sizeof(*defi))))
181 SDDS_Bomb(
"memory allocation failure (process_new_filter_definition)");
182 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
184 defi->is_parameter = 0;
186 case PARAMETER_BASED:
187 defi->is_parameter = 1;
190 fprintf(stderr,
"error: column or parameter must be specified for filter\n");
193 if (!(defi->filter_terms =
194 process_filter_request(&(defi->filter_term), argument + 1, arguments - 1)))
201 char *before, *after, *year, *month = NULL, *day = NULL, *hour, *minute, *second;
202 short minute_n, second_n, hour_n;
204 minute_n = second_n = hour_n = 0;
206 before = after = NULL;
207 if (!(defi =
tmalloc(
sizeof(*defi))))
208 SDDS_Bomb(
"memory allocation failure (process_new_filter_definition)");
209 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
211 defi->is_parameter = 0;
213 case PARAMETER_BASED:
214 defi->is_parameter = 1;
217 fprintf(stderr,
"error: column or parameter must be specified for filter\n");
221 defi->before = defi->after = 0;
222 hour = minute = second = 0;
223 defi->name = argument[1];
226 if (!
scanItemList(&defi->flags, argument, &arguments, 0,
227 "before",
SDDS_STRING, &before, 1, TIMEFILTER_BEFORE_GIVEN,
228 "after",
SDDS_STRING, &after, 1, TIMEFILTER_AFTER_GIVEN,
229 "invert", -1, NULL, 0, TIMEFILTER_INVERT_GIVEN,
233 minute_n = second_n = hour_n = 0;
237 SDDS_Bomb(
"invalid \"before\" date given, the specified data should be YYYY/MM/DD@HH:MM:SS");
241 minute_n = atol(minute);
243 second_n = atol(second);
244 hour_n1 = hour_n * 1.0 + minute_n / 60.0 + second_n / 3600.0;
246 SDDS_Bomb(
"invalid -timeFilter before syntax (something wrong with time convert)");
250 minute_n = second_n = hour_n = 0;
254 SDDS_Bomb(
"invalid \"after\" date given, the specified data should be YYYY/MM/DD@HH:MM:SS");
258 minute_n = atol(minute);
260 second_n = atol(second);
261 hour_n1 = hour_n * 1.0 + minute_n / 60.0 + second_n / 3600.0;
263 SDDS_Bomb(
"invalid -timeFilter after syntax (something wrong with time convert)");
266 if (before && after && defi->before < defi->after)
267 SDDS_Bomb(
"Invalid -timeFilter syntx, before date is earlier than the after date!");
277MATCH_DEFINITION *process_new_match_definition(
char **argument,
long arguments) {
280 if (!(defi =
tmalloc(
sizeof(*defi))))
281 SDDS_Bomb(
"memory allocation failure (process_new_match_definition)");
282 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
284 defi->is_parameter = 0;
286 case PARAMETER_BASED:
287 defi->is_parameter = 1;
290 fprintf(stderr,
"error: column or parameter must be specified for match\n");
293 if (!(defi->match_terms =
294 process_match_request(&(defi->match_term), argument + 1, arguments - 1)))
299long process_filter_request(
FILTER_TERM **filter,
char **argument,
long arguments) {
300 long i, filters, max_filters;
301 long need_name, need_operation;
305 max_filters = (arguments + 1) / 3 + 1;
306 *filter =
tmalloc(
sizeof(**filter) * max_filters);
311 if (is_logic_character(argument[i][0])) {
318 switch (argument[i][0]) {
320 if ((*filter)[filters].logic & SDDS_AND || (*filter)[filters].logic & SDDS_OR ||
321 (*filter)[filters].logic & SDDS_NEGATE_EXPRESSION)
323 (*filter)[filters].logic |= SDDS_AND;
326 if ((*filter)[filters].logic & SDDS_AND || (*filter)[filters].logic & SDDS_OR ||
327 (*filter)[filters].logic & SDDS_NEGATE_EXPRESSION)
329 (*filter)[filters].logic |= SDDS_OR;
332 if (!((*filter)[filters].logic & SDDS_AND || (*filter)[filters].logic & SDDS_OR) ||
333 (*filter)[filters].logic & SDDS_NEGATE_EXPRESSION)
335 (*filter)[filters].logic |= SDDS_NEGATE_EXPRESSION;
337 }
while (++i < arguments && is_logic_character(argument[i][0]));
342 }
else if (need_operation > 0)
346 if (is_logic_character(argument[i][0]))
348 if (arguments - i < 3)
350 if (filters + 1 >= max_filters)
351 *filter =
trealloc(*filter,
sizeof(**filter) * (max_filters += 2));
352 (*filter)[filters].name = argument[i++];
353 if (sscanf(argument[i],
"%lf", &(*filter)[filters].lower) != 1)
354 (*filter)[filters].lowerPar = argument[i];
356 (*filter)[filters].lowerPar = NULL;
358 if (sscanf(argument[i],
"%lf", &(*filter)[filters].upper) != 1)
359 (*filter)[filters].upperPar = argument[i];
361 (*filter)[filters].upperPar = NULL;
363 if ((*filter)[filters].lowerPar == NULL && (*filter)[filters].upperPar == NULL && (*filter)[filters].upper < (*filter)[filters].lower)
365 (*filter)[filters].logic = 0;
366 if (arguments - i > 0 && argument[i][0] ==
'!') {
367 (*filter)[filters].logic = SDDS_NEGATE_MATCH;
370 if (++need_operation > 0)
374 }
while (arguments > i);
375 (*filter)[0].logic |= SDDS_AND;
379long process_match_request(
MATCH_TERM **match,
char **argument,
long arguments) {
380 long i, matches, max_matches;
381 long need_name, need_operation;
386 max_matches = (arguments + 1) / 3 + 1;
387 *match =
tmalloc(
sizeof(**match) * max_matches);
392 if (is_logic_character(argument[i][0])) {
399 switch (argument[i][0]) {
401 if ((*match)[matches].logic & SDDS_AND || (*match)[matches].logic & SDDS_OR ||
402 (*match)[matches].logic & SDDS_NEGATE_EXPRESSION)
404 (*match)[matches].logic |= SDDS_AND;
407 if ((*match)[matches].logic & SDDS_AND || (*match)[matches].logic & SDDS_OR ||
408 (*match)[matches].logic & SDDS_NEGATE_EXPRESSION)
410 (*match)[matches].logic |= SDDS_OR;
413 if (!((*match)[matches].logic & SDDS_AND || (*match)[matches].logic & SDDS_OR) ||
414 (*match)[matches].logic & SDDS_NEGATE_EXPRESSION)
416 (*match)[matches].logic |= SDDS_NEGATE_EXPRESSION;
418 }
while (++i < arguments && is_logic_character(argument[i][0]));
423 }
else if (need_operation > 0)
427 if (is_logic_character(argument[i][0]))
429 if (arguments - i < 1)
431 if (matches + 1 >= max_matches)
432 *match =
trealloc(*match,
sizeof(**match) * (max_matches += 2));
433 if (!(ptr = strchr(argument[i],
'=')))
436 (*match)[matches].logic = 0;
437 if (*(ptr + 1) ==
'+') {
438 (*match)[matches].logic |= SDDS_NOCASE_COMPARE;
441 if (*(ptr + 1) ==
'@') {
442 (*match)[matches].logic |= SDDS_INDIRECT_MATCH;
445 (*match)[matches].name = argument[i++];
446 (*match)[matches].string = ptr + 1;
447 if (arguments - i > 0 && argument[i][0] ==
'!') {
448 (*match)[matches].logic |= SDDS_NEGATE_MATCH;
451 if (++need_operation > 0)
455 }
while (arguments > i);
456 (*match)[0].logic |= SDDS_AND;
462 label->format = NULL;
463 if ((ptr = strchr(
string,
'='))) {
465 label->format = ptr + 1;
467 label->name = string;
470void show_matches(
char *type,
MATCH_TERM *match,
long matches) {
472 fprintf(stderr,
"\n %s matching logic:\n", type);
473 for (i = 0; i < matches; i++) {
474 if (match[i].logic & SDDS_NEGATE_MATCH)
475 fprintf(stderr,
" <%s> != ", match[i].name);
477 fprintf(stderr,
" <%s> == ", match[i].name);
478 if (match[i].logic & SDDS_INDIRECT_MATCH)
479 fprintf(stderr,
"<%s>", match[i].
string);
481 fprintf(stderr,
"\"%s\"", match[i].
string);
482 if (match[i].logic & SDDS_NOCASE_COMPARE)
483 fprintf(stderr,
" (case insensitive)\n");
485 fprintf(stderr,
" (case sensitive)\n");
487 if (match[i].logic & SDDS_AND)
488 fprintf(stderr,
"&& ");
489 if (match[i].logic & SDDS_OR)
490 fprintf(stderr,
"|| ");
492 if (match[i].logic & SDDS_NEGATE_EXPRESSION)
498void show_filters(
char *type,
FILTER_TERM *filter,
long filters) {
500 fprintf(stderr,
"\n %s filtering logic:\n", type);
501 for (i = 0; i < filters; i++) {
502 if (filter[i].logic & SDDS_NEGATE_MATCH)
503 fprintf(stderr,
" !( <%s>:[%22.15e, %22.15e] ) ", filter[i].name, filter[i].lower, filter[i].upper);
505 fprintf(stderr,
" <%s>:[%22.15e, %22.15e] ", filter[i].name, filter[i].lower, filter[i].upper);
507 if (filter[i].logic & SDDS_AND)
508 fprintf(stderr,
"&& ");
509 if (filter[i].logic & SDDS_OR)
510 fprintf(stderr,
"|| ");
512 if (filter[i].logic & SDDS_NEGATE_EXPRESSION)
519 static char s[SDDS_MAXLINE];
520 char *ptr, *equation;
521 long i, code, algebraic = 0;
523 char pfix[IFPF_BUF_SIZE];
525 if (!(defi =
tmalloc(
sizeof(*defi))))
526 SDDS_Bomb(
"memory allocation failure (process_new_equation_definition)");
527 defi->name = defi->text = defi->equation = defi->udf_name =
528 defi->editSelection = defi->select = defi->exclude = NULL;
530 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
532 defi->is_parameter = 0;
533 sprintf(s,
"&column name=\"%s\", ", argument[1]);
535 case PARAMETER_BASED:
536 defi->is_parameter = 1;
537 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
540 fprintf(stderr,
"error: column or parameter must be specified for definition\n");
545 for (i = 3; i < arguments; i++) {
546 if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0) {
555 if (argument[2][0] ==
'@') {
557 equation = malloc(
sizeof(
char) * strlen(argument[2]) + 1);
558 sprintf(equation,
"@%s", argument[2]);
560 ptr = addOuterParentheses(argument[2]);
561 if2pf(pfix, ptr,
sizeof pfix);
565 fprintf(stderr,
"error: problem copying argument string\n");
570 defi->argv =
tmalloc(
sizeof(*defi->argv) * (arguments - 3));
572 defi->argv =
tmalloc(
sizeof(*defi->argv) * 1);
575 equation = argument[2];
577 defi->argv =
tmalloc(
sizeof(*defi->argv) * (arguments - 2));
579 defi->argv =
tmalloc(
sizeof(*defi->argv) * 1);
582 for (i = 3; i < arguments; i++) {
583 if (!(ptr = strchr(argument[i],
'='))) {
584 if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0)
586 fprintf(stderr,
"error: invalid definition-entry: %s\n", argument[i]);
590 switch (code =
match_string(argument[i], selectQualifier, SELECT_QUALIFIERS, 0)) {
591 case SELECT_QUALIFIER:
594 case EDITSELECTION_QUALIFIER:
597 case EXCLUDE_QUALIFIER:
607 fprintf(stderr,
"error: problem copying argument string\n");
612 strcat(s, argument[i]);
618 if (!strstr(s,
", type=")) {
619 strcat(s,
" type=\"double\", ");
625 SDDS_Bomb(
"string copying failed (process_new_equation_definition)");
630 static char s[SDDS_MAXLINE];
634 if (!(defi =
tmalloc(
sizeof(*defi))))
635 SDDS_Bomb(
"memory allocation failure (process_new_evaluate_definition)");
636 defi->name = defi->text = defi->source = NULL;
637 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
639 defi->is_parameter = 0;
640 sprintf(s,
"&column name=\"%s\", ", argument[1]);
642 case PARAMETER_BASED:
643 defi->is_parameter = 1;
644 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
647 fprintf(stderr,
"error: column or parameter must be specified for definition\n");
652 defi->name = argument[1];
653 defi->source = argument[2];
655 for (i = 3; i < arguments; i++) {
657 strcat(s, argument[i]);
659 if (!strstr(s,
", type=")) {
660 strcat(s,
" type=double, ");
664 SDDS_Bomb(
"string copying failed (process_new_evaluate_definition)");
668SCAN_DEFINITION *process_new_scan_definition(
char **argument,
long arguments) {
669 static char s[SDDS_MAXLINE];
674 if (!(defi =
tmalloc(
sizeof(*defi))))
675 SDDS_Bomb(
"memory allocation failure (process_new_scan_definition)");
676 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
678 defi->is_parameter = 0;
679 sprintf(s,
"&column name=\"%s\", ", argument[1]);
681 case PARAMETER_BASED:
682 defi->is_parameter = 1;
683 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
686 fprintf(stderr,
"error: column or parameter must be specified for scan\n");
689 defi->new_name = argument[1];
690 defi->source = argument[2];
691 defi->sscanf_string = argument[3];
693 for (i = 4; i < arguments; i++) {
694 if (!(ptr = strchr(argument[i],
'=')))
697 if (strncasecmp(argument[i],
"edit", strlen(argument[i])) == 0) {
701 strcat(s, argument[i]);
707 if (!strstr(s,
", type="))
708 strcat(s,
" type=\"double\", ");
711 SDDS_Bomb(
"unable to copy text of scan definition (process_new_scan_definition)");
715CAST_DEFINITION *process_new_cast_definition(
char **argument,
long arguments) {
718 if (!(defi =
tmalloc(
sizeof(*defi))))
719 SDDS_Bomb(
"memory allocation failure (process_new_cast_definition)");
720 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
722 defi->isParameter = 0;
724 case PARAMETER_BASED:
725 defi->isParameter = 1;
728 fprintf(stderr,
"error: column or parameter must be specified for cast\n");
731 defi->newName = argument[1];
732 defi->source = argument[2];
733 defi->newTypeName = argument[3];
734 if (strcmp(defi->newName, defi->source) == 0) {
735 fprintf(stderr,
"error: can't cast something to the same name (sddsprocess)\n");
746 sprintf(s,
"Unable to cast parameter %s to unknown type %s from column %s",
747 defi->newName, defi->newTypeName, defi->source);
751 if (defi->isParameter) {
753 defi->source, defi->newName) ||
755 SDDS_BY_NAME, defi->newName)) {
756 sprintf(s,
"Unable to cast parameter %s to type %s from column %s",
757 defi->newName, defi->newTypeName, defi->source);
763 defi->source, defi->newName) ||
765 SDDS_BY_NAME, defi->newName)) {
766 sprintf(s,
"Unable to cast column %s to type %s from column %s",
767 defi->newName, defi->newTypeName, defi->source);
776 static char s[SDDS_MAXLINE];
780#define NUMBERTEST_QUALIFIERS 2
781 static char *numbertestQualifier[NUMBERTEST_QUALIFIERS] = {
785 static unsigned long numbertestFlag[NUMBERTEST_QUALIFIERS] = {
786 NUMSCANFILTER_INVERT,
787 NUMSCANFILTER_STRICT,
790 if (!(defi =
tmalloc(
sizeof(*defi))))
791 SDDS_Bomb(
"memory allocation failure (process_new_numbertest_definition)");
792 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
794 defi->is_parameter = 0;
795 sprintf(s,
"&column name=\"%s\", ", argument[1]);
797 case PARAMETER_BASED:
798 defi->is_parameter = 1;
799 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
802 fprintf(stderr,
"error: column or parameter must be specified for numbertest\n");
805 defi->name = argument[1];
807 for (i = 2; i < arguments; i++) {
808 switch (j =
match_string(argument[i], numbertestQualifier, NUMBERTEST_QUALIFIERS, 0)) {
810 fprintf(stderr,
"error: unknown qualifer to -numberTest: %s\n", argument[i]);
814 defi->flags |= numbertestFlag[j];
821EDIT_DEFINITION *process_new_edit_definition(
char **argument,
long arguments,
short reedit) {
822 static char s[SDDS_MAXLINE];
824 long i, offset, hasType;
827 if (!(defi =
tmalloc(
sizeof(*defi))))
828 SDDS_Bomb(
"memory allocation failure (process_new_edit_definition)");
829 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
831 defi->is_parameter = 0;
832 sprintf(s,
"&column name=\"%s\", ", argument[1]);
834 case PARAMETER_BASED:
835 defi->is_parameter = 1;
836 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
839 fprintf(stderr,
"error: column or parameter must be specified for edit\n");
842 defi->new_name = argument[1];
844 defi->source = argument[2];
845 defi->edit_command = argument[3];
848 defi->source = defi->new_name;
849 defi->edit_command = argument[2];
852 if (arguments > offset) {
853 defi->argv =
tmalloc(
sizeof(*defi->argv) * (arguments - offset));
855 SDDS_Bomb(
"string array copy failed (process_new_edit_definition)");
856 defi->argc = arguments - offset;
862 for (i = offset; i < arguments; i++) {
863 if (!(ptr = strchr(argument[i],
'=')))
866 if (strcmp(argument[i],
"type") == 0)
868 strcat(s, argument[i]);
874 strcat(s,
" type=string &end");
878 SDDS_Bomb(
"unable to copy text of edit definition (process_new_edit_definition)");
882long edit_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *edit_command) {
884 long target_type, target_index, source_index;
886 static char s[SDDS_MAXLINE];
894 fprintf(stderr,
"error: source column %s has wrong type for editing--must be string\n", source);
899 fprintf(stderr,
"error: target column %s has wrong type for editing--must be string or character\n", target);
913 for (i = 0; i < rows; i++) {
914 if (!source_value[i])
917 strcpy(s, source_value[i]);
919 fprintf(stderr,
"error: unable to edit source string \"%s\" to make %s\n", source_value[i], target);
923 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s, -1)) ||
925 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s[0], -1))) {
940long edit_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *edit_command) {
941 char *source_value, **ptr;
942 long target_type, target_index, source_index;
943 static char s[SDDS_MAXLINE];
951 fprintf(stderr,
"error: source parameter %s has wrong type for editing--must be string\n", source);
956 fprintf(stderr,
"error: target parameter %s has wrong type for editing--must be string or character\n", target);
964 if (!(source_value = *ptr))
967 strcpy(s, source_value);
969 fprintf(stderr,
"error: unable to edit source string \"%s\" to make %s\n", source_value, target);
973 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) ||
975 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s[0], -1))) {
987 request =
tmalloc(
sizeof(*request));
988 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
990 request->parameter_output = 0;
992 case PARAMETER_BASED:
993 request->parameter_output = 1;
996 fprintf(stderr,
"error: column or parameter must be specified for output\n");
1003 request->points = 0;
1004 request->counter = 0;
1006 if (!(request->item[0] = determine_item_name(argument, last_request, 0)))
1009 if (!(request->item[1] = determine_item_name(argument, last_request, 1)))
1012 request->item[2] = request->item[3] = NULL;
1013 request->columns = 2;
1018 request->columns = 3;
1019 if (!(request->item[2] = determine_item_name(argument, last_request, 2)))
1025 request->columns = 4;
1026 if (!(request->item[3] = determine_item_name(argument, last_request, 3)))
1032char *determine_item_name(
char **argument,
OUTPUT_REQUEST *last_request,
long index) {
1033 if (strcmp(argument[index],
".") == 0) {
1036 return (last_request->item[index]);
1038 return (argument[index]);
1042 long separate_pages,
long announce_openings,
SDDS_DATASET *SDDS_dataset) {
1047 char *mplTitle, *mplTopline;
1049 output->fp =
fopen_e(filename,
"w", 0);
1050 if (announce_openings)
1051 fprintf(stderr,
"file opened: %s\n", filename);
1052 if (!output->parameter_output) {
1054 coldef[0] = coldef[1] = coldef[2] = coldef[3] = NULL;
1062 fputs(coldef[0]->symbol ? coldef[0]->symbol : output->item[0], output->fp);
1063 if (coldef[0]->units && !
is_blank(coldef[0]->units))
1064 fprintf(output->fp,
" (%s)", coldef[0]->units);
1065 fprintf(output->fp,
"\n%s", coldef[1]->symbol ? coldef[1]->symbol : output->item[1]);
1066 if (coldef[1]->units && !
is_blank(coldef[1]->units))
1067 fprintf(output->fp,
" (%s)", coldef[1]->units);
1068 if (label_parameters) {
1069 fputc(
'\n', output->fp);
1070 for (j = 0; j < label_parameters; j++) {
1079 fprintf(output->fp,
"%s=", pardefptr->symbol ? pardefptr->symbol : label_parameter[j].name);
1081 (label_parameter[j].format ? label_parameter[j].format : pardefptr->format_string), output->fp,
1083 if (pardefptr->units) {
1084 if (isdigit(pardefptr->units[0]))
1085 fputc(
' ', output->fp);
1086 fprintf(output->fp,
"%s%s", pardefptr->units, j == label_parameters - 1 ?
"\n" :
" ");
1088 fprintf(output->fp,
"%s", j == label_parameters - 1 ?
"\n" :
" ");
1092 fprintf(output->fp,
"\n%s vs %s\n",
1093 coldef[1]->description ? coldef[1]->description : (coldef[1]->symbol ? coldef[1]->symbol : output->item[1]),
1094 coldef[0]->description ? coldef[0]->description : (coldef[0]->symbol ? coldef[0]->symbol : output->item[0]));
1098 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
1100 fprintf(output->fp,
"\n%s\n", mplTitle);
1106 pardef[0] = pardef[1] = pardef[2] = pardef[3] = NULL;
1114 fputs(pardef[0]->symbol ? pardef[0]->symbol : output->item[0], output->fp);
1115 if (pardef[0]->units && !
is_blank(pardef[0]->units))
1116 fprintf(output->fp,
" (%s)", pardef[0]->units);
1117 fprintf(output->fp,
"\n%s", pardef[1]->symbol ? pardef[1]->symbol : output->item[1]);
1118 if (pardef[1]->units && !
is_blank(pardef[1]->units))
1119 fprintf(output->fp,
" (%s)", pardef[1]->units);
1120 if (label_parameters) {
1121 fputc(
'\n', output->fp);
1122 for (j = 0; j < label_parameters; j++) {
1131 fprintf(output->fp,
"%s=", pardefptr->symbol ? pardefptr->symbol : label_parameter[j].name);
1133 (label_parameter[j].format ? label_parameter[j].format : pardefptr->format_string), output->fp,
1135 if (pardefptr->units) {
1136 if (isdigit(pardefptr->units[0]))
1137 fputc(
' ', output->fp);
1138 fprintf(output->fp,
"%s%s", pardefptr->units, j == label_parameters - 1 ?
"\n" :
" ");
1140 fprintf(output->fp,
"%s", j == label_parameters - 1 ?
"\n" :
" ");
1144 fprintf(output->fp,
"\n%s vs %s\n",
1145 pardef[1]->description ? pardef[1]->description : (pardef[1]->symbol ? pardef[1]->symbol : output->item[1]),
1146 pardef[0]->description ? pardef[0]->description : (pardef[0]->symbol ? pardef[0]->symbol : output->item[0]));
1150 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
1152 fprintf(output->fp,
"\n%s\n", mplTitle);
1158 fprintf(output->fp,
"Data extracted from SDDS file %s", SDDS_dataset->layout.filename);
1160 fprintf(output->fp,
", page %" PRId32, SDDS_dataset->page_number);
1163 SDDS_SetError(
"Unable to get value of parameter mplTopline");
1164 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
1166 fprintf(output->fp,
"%s", mplTopline);
1169 fprintf(output->fp,
"\n%-10" PRId64
"\n", SDDS_dataset->n_rows);
1175 double *result,
char **stringResult,
long warnings,
int threads) {
1176 double *data, *indepData, *weightData;
1177 long i1, i2 = 0, i2save, mode;
1179 int64_t i, n_data, count;
1180 double min, max, top, base, point1, point2;
1181 double slope, intercept, variance;
1182 long returnValue, matchfound;
1183 char **stringData, **matchData;
1185 double quartilePoint[2] = {25.0, 75.0}, quartileResult[2];
1186 double decilePoint[2] = {10.0, 90.0}, decileResult[2];
1187 double percentilePoint[2], percentileResult[2];
1192 mode = processing_ptr->mode;
1194 fprintf(stderr,
"process_column: column=%s, mode=%s\n", processing_ptr->column_name,
1195 process_column_data[mode].name);
1198 *stringResult = NULL;
1200 if (mode != PROCESS_COLUMN_COUNT)
1201 *result = processing_ptr->defaultValue;
1207 &processing_ptr->lowerLimit))
1208 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1210 &processing_ptr->upperLimit))
1211 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1214 &processing_ptr->head))
1215 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1217 &processing_ptr->tail))
1218 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1220 &processing_ptr->fhead))
1221 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1223 &processing_ptr->ftail))
1224 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1225 if (processing_ptr->offset_par) {
1226 if (
wild_match(processing_ptr->offset_par,
"%s*")) {
1227 sprintf(temp_str, processing_ptr->offset_par, processing_ptr->column_name);
1229 &processing_ptr->offset))
1230 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1232 &processing_ptr->offset))
1233 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1235 if (processing_ptr->factor_par) {
1236 if (
wild_match(processing_ptr->factor_par,
"%s*")) {
1237 sprintf(temp_str, processing_ptr->factor_par, processing_ptr->column_name);
1239 &processing_ptr->factor))
1240 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1242 &processing_ptr->factor))
1243 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1245 if ((processing_ptr->flags & PROCESSING_INVERT_OFFSET) && (processing_ptr->flags & PROCESSING_OFFSET_GIVEN))
1246 processing_ptr->offset *=-1;
1247 if ((processing_ptr->flags & PROCESSING_FACTOR_GIVEN) && (processing_ptr->flags & PROCESSING_INVERT_FACTOR))
1248 processing_ptr->factor = 1/processing_ptr->factor;
1251 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1252 indepData = weightData = NULL;
1253 stringData = matchData = NULL;
1256 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1257 if (processing_ptr->functionOf &&
1260 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1261 if (processing_ptr->functionOf &&
1263 !(stringData =
SDDS_GetColumn(Dataset, processing_ptr->functionOf)))
1264 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1267 if (processing_ptr->flags & (PROCESSING_LOLIM_GIVEN | PROCESSING_UPLIM_GIVEN | PROCESSING_TAIL_GIVEN | PROCESSING_HEAD_GIVEN | PROCESSING_FTAIL_GIVEN | PROCESSING_FHEAD_GIVEN | PROCESSING_MATCHCOLUMN_GIVEN | PROCESSING_TOPLIM_GIVEN | PROCESSING_BOTLIM_GIVEN)) {
1268 keep =
tmalloc(
sizeof(*keep) * n_data);
1269 for (i = 0; i < n_data; i++)
1272 if (processing_ptr->flags & PROCESSING_MATCHCOLUMN_GIVEN) {
1273 if (!(matchData =
SDDS_GetColumn(Dataset, processing_ptr->match_column)))
1274 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1275 for (i = 0; i < n_data; i++)
1277 for (i = 0; i < n_data; i++) {
1278 if (
wild_match(matchData[i], processing_ptr->match_value)) {
1283 for (i = 0; i < n_data; i++)
1288 fprintf(stderr,
"Warning: no values in column %s match %s.\n",
1289 processing_ptr->match_column, processing_ptr->match_value);
1292 *result = processing_ptr->defaultValue;
1296 if (processing_ptr->flags & PROCESSING_LOLIM_GIVEN && indepData) {
1298 fprintf(stderr,
"lower limit processing: value %e\n", processing_ptr->lowerLimit);
1300 for (i = 0; i < n_data; i++)
1301 if (processing_ptr->lowerLimit > indepData[i])
1305 if (processing_ptr->flags & PROCESSING_UPLIM_GIVEN && indepData) {
1307 fprintf(stderr,
"upper limit processing: value %e\n", processing_ptr->upperLimit);
1309 for (i = 0; i < n_data; i++) {
1310 if (processing_ptr->upperLimit < indepData[i])
1312 if (isinf(indepData[i]) || isnan(indepData[i]))
1317 if (processing_ptr->flags & PROCESSING_TOPLIM_GIVEN) {
1318 for (i = 0; i < n_data; i++) {
1319 if (processing_ptr->topLimit < data[i])
1321 if (isinf(data[i]) || isnan(data[i]))
1326 if (processing_ptr->flags & PROCESSING_BOTLIM_GIVEN) {
1327 for (i = 0; i < n_data; i++)
1328 if (processing_ptr->bottomLimit > data[i])
1332 if (processing_ptr->flags & PROCESSING_HEAD_GIVEN) {
1335 fprintf(stderr,
"head processing: %ld points\n", processing_ptr->head);
1337 if (processing_ptr->head > 0) {
1339 for (i = 0; i < n_data && count < processing_ptr->head; i++)
1342 for (; i < n_data; i++)
1346 for (i = 0; i < n_data && count < -processing_ptr->head; i++)
1354 if (processing_ptr->flags & PROCESSING_FHEAD_GIVEN) {
1357 head = fabs(n_data * processing_ptr->fhead + 0.5);
1358 if (processing_ptr->fhead > 0) {
1359 for (i = 0; i < n_data && count < head; i++)
1362 for (; i < n_data; i++)
1365 for (i = 0; i < n_data && count < head; i++)
1372 if (processing_ptr->flags & PROCESSING_TAIL_GIVEN) {
1375 fprintf(stderr,
"tail processing: %ld points\n", processing_ptr->tail);
1377 if (processing_ptr->tail > 0) {
1378 for (i = n_data - 1; i >= 0 && count < processing_ptr->tail; i--)
1384 for (i = n_data - 1; i >= 0 && count < -processing_ptr->tail; i--)
1391 if (processing_ptr->flags & PROCESSING_FTAIL_GIVEN) {
1394 tail = fabs(processing_ptr->ftail * n_data + 0.5);
1395 if (processing_ptr->ftail > 0) {
1396 for (i = n_data - 1; i >= 0 && count < tail; i--)
1402 for (i = n_data - 1; i >= 0 && count < tail; i--)
1411 for (i = j = 0; i < n_data; i++) {
1416 indepData[j] = indepData[i];
1418 free(stringData[j]);
1419 stringData[j] = stringData[i];
1420 stringData[i] = NULL;
1423 weightData[j] = weightData[i];
1430 fprintf(stderr,
"%" PRId64
" points kept\n", n_data);
1442 fprintf(stderr,
"warning: no matches found");
1443 if (mode != PROCESS_COLUMN_COUNT) {
1444 *result = processing_ptr->defaultValue;
1445 *stringResult = NULL;
1449 *stringResult = NULL;
1454 if (processing_ptr->flags & PROCESSING_OFFSET_GIVEN) {
1456 fprintf(stderr,
"offsetting by %f\n", processing_ptr->offset);
1458 for (i = 0; i < n_data; i++)
1459 data[i] += processing_ptr->offset;
1462 if (processing_ptr->flags & PROCESSING_FACTOR_GIVEN) {
1464 fprintf(stderr,
"multiplying by %f\n", processing_ptr->factor);
1466 for (i = 0; i < n_data; i++)
1467 data[i] *= processing_ptr->factor;
1471 fprintf(stderr,
"data points:\n");
1472 for (i = 0; i < n_data; i++)
1473 fprintf(stderr,
"%e%c", data[i], (i + 1) % 8 == 0 ?
'\n' :
' ');
1474 fputc(
'\n', stderr);
1480 case PROCESS_COLUMN_ZEROCROSSING:
1481 for (i = 0; i < n_data - 1; i++) {
1484 if ((data[i] < 0 && data[i + 1] >= 0) || (data[i] > 0 && data[i + 1] <= 0))
1487 if (i != n_data - 1) {
1490 *result = indepData[i];
1492 *result = indepData[i] + (indepData[i + 1] - indepData[i]) / (data[i + 1] - data[i]) * (-data[i]);
1495 *stringResult = stringData[i];
1496 stringData[i] = NULL;
1501 case PROCESS_COLUMN_MEAN:
1507 case PROCESS_COLUMN_RMS:
1513 case PROCESS_COLUMN_SUM:
1516 for (i = sum = 0; i < n_data; i++)
1517 sum += data[i] * weightData[i];
1522 case PROCESS_COLUMN_PRODUCT:
1525 for (i = 0; i < n_data; i++)
1526 product *= data[i] * weightData[i];
1530 for (i = 0; i < n_data; i++)
1535 case PROCESS_COLUMN_STAND_DEV:
1541 case PROCESS_COLUMN_SIGMA:
1546 *result /= sqrt(1.0 * n_data);
1548 case PROCESS_COLUMN_MAD:
1554 case PROCESS_COLUMN_SIGNEDSMALLEST:
1556 for (i = 1; i < n_data; i++)
1557 if (fabs(data[imin]) > fabs(data[i]))
1559 *result = data[imin];
1560 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1562 *result = indepData[imin];
1564 *stringResult = stringData[imin];
1565 stringData[imin] = NULL;
1569 case PROCESS_COLUMN_SIGNEDLARGEST:
1571 for (i = 1; i < n_data; i++)
1572 if (fabs(data[imax]) < fabs(data[i]))
1574 *result = data[imax];
1575 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1577 *result = indepData[imax];
1579 *stringResult = stringData[imax];
1580 stringData[imax] = NULL;
1584 case PROCESS_COLUMN_SMALLEST:
1585 case PROCESS_COLUMN_LARGEST:
1586 for (i = 0; i < n_data; i++)
1587 data[i] = fabs(data[i]);
1592 case PROCESS_COLUMN_SMALLEST:
1593 *result = data[i1 = imin];
1595 case PROCESS_COLUMN_LARGEST:
1596 *result = data[i1 = imax];
1599 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1601 *result = indepData[i1];
1603 *stringResult = stringData[i1];
1604 stringData[i1] = NULL;
1609 case PROCESS_COLUMN_MINIMUM:
1610 case PROCESS_COLUMN_MAXIMUM:
1611 case PROCESS_COLUMN_SPREAD:
1618 case PROCESS_COLUMN_MINIMUM:
1622 case PROCESS_COLUMN_MAXIMUM:
1626 case PROCESS_COLUMN_SMALLEST:
1627 if (fabs(min) < fabs(max)) {
1629 *result = fabs(min);
1632 *result = fabs(max);
1635 case PROCESS_COLUMN_LARGEST:
1636 if (fabs(min) > fabs(max)) {
1638 *result = fabs(min);
1641 *result = fabs(max);
1644 case PROCESS_COLUMN_SPREAD:
1645 *result = max - min;
1648 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1650 *result = indepData[i1];
1652 *stringResult = stringData[i1];
1653 stringData[i1] = NULL;
1658 case PROCESS_COLUMN_FIRST:
1661 case PROCESS_COLUMN_LAST:
1662 *result = data[n_data - 1];
1664 case PROCESS_COLUMN_COUNT:
1667 case PROCESS_COLUMN_MEDIAN:
1671 case PROCESS_COLUMN_MODE:
1672 if (processing_ptr->flags & PROCESSING_BINSIZE_GIVEN) {
1673 if (
computeMode(result, data, n_data, processing_ptr->binSize, 0) <= 0)
1675 }
else if (
computeMode(result, data, n_data, 0, 100) <= 0)
1678 case PROCESS_COLUMN_BASELEVEL:
1679 case PROCESS_COLUMN_TOPLEVEL:
1680 case PROCESS_COLUMN_AMPLITUDE:
1681 case PROCESS_COLUMN_RISETIME:
1682 case PROCESS_COLUMN_FALLTIME:
1683 case PROCESS_COLUMN_FWHA:
1684 case PROCESS_COLUMN_FWTA:
1685 case PROCESS_COLUMN_CENTER:
1686 case PROCESS_COLUMN_FWHM:
1687 case PROCESS_COLUMN_FWTM:
1692 if ((top - base) < 0.75 * (data[imax] - base))
1695 case PROCESS_COLUMN_BASELEVEL:
1698 case PROCESS_COLUMN_TOPLEVEL:
1701 case PROCESS_COLUMN_AMPLITUDE:
1702 *result = top - base;
1704 case PROCESS_COLUMN_RISETIME:
1705 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1706 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, indepData, &point2)) < 0)
1709 *result = point2 - point1;
1711 case PROCESS_COLUMN_FALLTIME:
1712 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.9, -1, indepData, &point1)) < 0 ||
1713 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0)
1716 *result = point2 - point1;
1718 case PROCESS_COLUMN_FWHA:
1719 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1720 (i2 = i2save =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1721 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1723 fprintf(stderr,
"warning: couldn't find crossing point for FWHA of %s\n",
1724 processing_ptr->column_name);
1725 fprintf(stderr,
"top, base = %e, %e min, max = %e, %e\n", top, base,
1726 data[imin], data[imax]);
1728 fprintf(stderr,
"#1: %ld, (%e, %e)\n",
1729 i1, indepData[i1], data[i1]);
1731 fprintf(stderr,
"#2: %ld, (%e, %e)\n",
1732 i2save, indepData[i2save], data[i2save]);
1734 fprintf(stderr,
"#2a: %ld, (%e, %e)\n",
1735 i2, indepData[i2], data[i2]);
1737 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1738 (i2 = i2save =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1739 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1742 *result = point2 - point1;
1745 *result = point2 - point1;
1747 case PROCESS_COLUMN_FWTA:
1748 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1749 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1750 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0) {
1751 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1752 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1753 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0) {
1756 *result = point2 - point1;
1759 *result = point2 - point1;
1761 case PROCESS_COLUMN_FWHM:
1762 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.5, 1, indepData, &point1)) < 0 ||
1763 (i2 = i2save =
findCrossingPoint(i1, data, n_data, top * 0.9, -1, NULL, NULL)) < 0 ||
1764 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.5, -1, indepData, &point2)) < 0) {
1766 fprintf(stderr,
"warning: couldn't find crossing point for FWHM of %s\n",
1767 processing_ptr->column_name);
1768 fprintf(stderr,
"top, base = %e, %e\n", top, base);
1770 fprintf(stderr,
"#1: %ld, (%e, %e)\n",
1771 i1, indepData[i1], data[i1]);
1773 fprintf(stderr,
"#2: %ld, (%e, %e)\n",
1774 i2save, indepData[i2save], data[i2save]);
1776 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.5, 1, indepData, &point1)) < 0 ||
1777 (i2 = i2save =
findCrossingPoint(i1, data, n_data, top * 0.9, 1, NULL, NULL)) < 0 ||
1778 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.5, -1, indepData, &point2)) < 0) {
1781 *result = point2 - point1;
1784 *result = point2 - point1;
1786 case PROCESS_COLUMN_FWTM:
1787 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.1, 1, indepData, &point1)) < 0 ||
1789 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.1, -1, indepData, &point2)) < 0) {
1790 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.1, 1, indepData, &point1)) < 0 ||
1792 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.1, -1, indepData, &point2)) < 0) {
1795 *result = point2 - point1;
1798 *result = point2 - point1;
1800 case PROCESS_COLUMN_CENTER:
1801 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1802 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1803 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1804 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1805 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1806 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1809 *result = (point1 + point2) / 2;
1812 *result = (point1 + point2) / 2;
1817 case PROCESS_COLUMN_SLOPE:
1818 case PROCESS_COLUMN_INTERCEPT:
1819 case PROCESS_COLUMN_LFSD:
1824 case PROCESS_COLUMN_SLOPE:
1827 case PROCESS_COLUMN_INTERCEPT:
1828 *result = intercept;
1830 case PROCESS_COLUMN_LFSD:
1831 *result = sqrt(variance);
1835 case PROCESS_COLUMN_INTEGRAL:
1838 case PROCESS_COLUMN_GMINTEGRAL:
1839 GillMillerIntegration1(indepData, data, n_data, result);
1841 case PROCESS_COLUMN_QRANGE:
1845 *result = quartileResult[1] - quartileResult[0];
1847 case PROCESS_COLUMN_DRANGE:
1851 *result = decileResult[1] - decileResult[0];
1853 case PROCESS_COLUMN_PERCENTILE:
1854 if (!
compute_percentiles(percentileResult, &processing_ptr->percentileLevel, 1, data, n_data))
1857 *result = percentileResult[0];
1861 case PROCESS_COLUMN_PRANGE:
1862 percentilePoint[1] = 50 + processing_ptr->percentileLevel / 2.0;
1863 percentilePoint[0] = 50 - processing_ptr->percentileLevel / 2.0;
1867 *result = percentileResult[1] - percentileResult[0];
1871 case PROCESS_COLUMN_CORRELATION:
1888 for (i = 0; i < n_data; i++)
1890 free(stringData[i]);
1895 fprintf(stderr,
"warning: processing of %s with mode %s failed--value %e returned\n",
1896 processing_ptr->column_name,
1897 process_column_name[processing_ptr->mode],
1898 processing_ptr->defaultValue);
1899 *result = processing_ptr->defaultValue;
1900 *stringResult = NULL;
1906 char **data, *result, **matchData;
1907 long mode, matchfound;
1908 int64_t i, n_data, count;
1911 mode = processing_ptr->mode;
1918 if (!(data =
SDDS_GetColumn(Dataset, processing_ptr->column_name)))
1919 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1922 if (processing_ptr->flags & (PROCESSING_TAIL_GIVEN | PROCESSING_HEAD_GIVEN |
1923 PROCESSING_FTAIL_GIVEN | PROCESSING_FHEAD_GIVEN |
1924 PROCESSING_MATCHCOLUMN_GIVEN)) {
1925 keep =
tmalloc(
sizeof(*keep) * n_data);
1926 for (i = 0; i < n_data; i++)
1930 if (processing_ptr->flags & PROCESSING_MATCHCOLUMN_GIVEN) {
1931 if (!(matchData =
SDDS_GetColumn(Dataset, processing_ptr->match_column)))
1932 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1933 for (i = 0; i < n_data; i++)
1935 for (i = 0; i < n_data; i++) {
1936 if (
wild_match(matchData[i], processing_ptr->match_value)) {
1941 for (i = 0; i < n_data; i++)
1946 fprintf(stderr,
"Warning: no values in column %s match %s.\n",
1947 processing_ptr->match_column, processing_ptr->match_value);
1949 for (i = 0; i < n_data; i++)
1956 if (processing_ptr->flags & PROCESSING_HEAD_GIVEN) {
1958 for (i = 0; i < n_data && count < processing_ptr->head; i++)
1961 for (; i < n_data; i++)
1965 if (processing_ptr->flags & PROCESSING_FHEAD_GIVEN) {
1968 head = n_data * processing_ptr->fhead + 0.5;
1969 for (i = 0; i < n_data && count < head; i++)
1972 for (; i < n_data; i++)
1976 if (processing_ptr->flags & PROCESSING_TAIL_GIVEN) {
1978 for (i = n_data - 1; i >= 0 && count < processing_ptr->tail; i--)
1985 if (processing_ptr->flags & PROCESSING_FTAIL_GIVEN) {
1988 tail = processing_ptr->ftail * n_data + 0.5;
1989 for (i = n_data - 1; i >= 0 && count < tail; i--)
1998 for (i = j = 0; i < n_data; i++) {
2010 case PROCESS_COLUMN_FIRST:
2013 case PROCESS_COLUMN_LAST:
2017 SDDS_Bomb(
"invalid processing mode for string data (sddsprocess)");
2023 fprintf(stderr,
"warning, no matches found.");
2026 for (i = 0; i < n_data; i++)
2034static char *PROCESSING_USAGE =
2035 " [-process=<column-name>,<analysis-name>,<result-name>[,description=<string>][,symbol=<string>][,weightBy=<column-name>]\n\
2036 [,match=<column-name>,value=<match-string>]\n\
2037 [,head=<number>][,tail=<number>][fhead=<fraction>][ftail=<fraction>][,topLimit=<value>][,bottomLimit=<value>]\n\
2038 [,functionOf=<column-name>[,lowerLimit=<value>|@parameter_name][,upperLimit=<value>|@<parameter_name>][,position]]\n\
2039 [,offset=<value>][,factor=<value>][match=<column-name>,value=<string>][,overwrite],[default=<value>]]\n\
2040 [,binSize=<value>]\n";
2044 char *lower_str = NULL, *upper_str = NULL;
2045 char *head_str=NULL, *tail_str=NULL, *fhead_str=NULL, *ftail_str=NULL, *offset_str=NULL, *factor_str=NULL;
2046 char *invert_str=NULL;
2049 bomb(
"invalid -process syntax--wrong number of arguments", PROCESSING_USAGE);
2051 if (process_column_name[0] == NULL) {
2053 for (i = 0; i < N_PROCESS_COLUMN_MODES; i++)
2054 process_column_name[i] = process_column_data[i].name;
2056 pd->lower_par = pd->upper_par = pd->head_par = pd->tail_par = pd->fhead_par = pd->ftail_par = pd->offset_par=pd->factor_par=NULL;
2057 if ((pd->mode =
match_string(argument[1], process_column_name, N_PROCESS_COLUMN_MODES, 0)) < 0) {
2058 fprintf(stderr,
"invalid -process mode: %s\n", argument[1]);
2059 show_process_modes(stderr);
2066 pd->defaultValue = DBL_MAX;
2068 "functionof",
SDDS_STRING, &pd->functionOf, 1, PROCESSING_FUNCOF_GIVEN,
2069 "weightby",
SDDS_STRING, &pd->weightBy, 1, PROCESSING_WEIGHT_GIVEN,
2070 "description",
SDDS_STRING, &pd->description, 1, PROCESSING_DESCRIP_GIVEN,
2071 "symbol",
SDDS_STRING, &pd->symbol, 1, PROCESSING_SYMBOL_GIVEN,
2072 "toplimit",
SDDS_DOUBLE, &pd->topLimit, 1, PROCESSING_TOPLIM_GIVEN,
2073 "bottomlimit",
SDDS_DOUBLE, &pd->bottomLimit, 1, PROCESSING_BOTLIM_GIVEN,
2074 "lowerlimit",
SDDS_STRING, &lower_str, 1, PROCESSING_LOLIM_GIVEN,
2075 "upperlimit",
SDDS_STRING, &upper_str, 1, PROCESSING_UPLIM_GIVEN,
2076 "head",
SDDS_STRING, &head_str, 1, PROCESSING_HEAD_GIVEN,
2077 "tail",
SDDS_STRING, &tail_str, 1, PROCESSING_TAIL_GIVEN,
2078 "fhead",
SDDS_STRING, &fhead_str, 1, PROCESSING_FHEAD_GIVEN,
2079 "ftail",
SDDS_STRING, &ftail_str, 1, PROCESSING_FTAIL_GIVEN,
2080 "position", -1, NULL, 0, PROCESSING_POSITION_GIVEN,
2081 "offset",
SDDS_STRING, &offset_str, 1, PROCESSING_OFFSET_GIVEN,
2082 "factor",
SDDS_STRING, &factor_str, 1, PROCESSING_FACTOR_GIVEN,
2083 "percentlevel",
SDDS_DOUBLE, &pd->percentileLevel, 1, PROCESSING_PERCLEVEL_GIVEN,
2084 "binsize",
SDDS_DOUBLE, &pd->binSize, 1, PROCESSING_BINSIZE_GIVEN,
2085 "match",
SDDS_STRING, &pd->match_column, 1, PROCESSING_MATCHCOLUMN_GIVEN,
2086 "value",
SDDS_STRING, &pd->match_value, 1, PROCESSING_MATCHVALUE_GIVEN,
2087 "overwrite", -1, NULL, 0, PROCESSING_OVERWRITE_GIVEN,
2089 "default",
SDDS_DOUBLE, &pd->defaultValue, 1, PROCESSING_DEFAULTVALUE_GIVEN,
2091 bomb(
"invalid -process syntax", PROCESSING_USAGE);
2094 pd->flags |= PROCESSING_INVERT_OFFSET;
2096 pd->flags |= PROCESSING_INVERT_FACTOR;
2098 pd->flags |= PROCESSING_INVERT_OFFSET;
2099 pd->flags |= PROCESSING_INVERT_FACTOR;
2101 fprintf(stdout,
"Warning, invalid invert %s provided for process.\n", invert_str);
2109 }
else if (!
get_double(&pd->lowerLimit, lower_str)) {
2110 bomb(
"invalid lower limit provided for -process option", PROCESSING_USAGE);
2117 }
else if (!
get_double(&pd->upperLimit, upper_str)) {
2118 bomb(
"invalid upper limit provided for -process option", PROCESSING_USAGE);
2125 }
else if (!
get_int(&pd->head, head_str)) {
2126 bomb(
"invalid head provided for -process option", PROCESSING_USAGE);
2133 }
else if (!
get_int(&pd->tail, tail_str)) {
2134 bomb(
"invalid tail provided for -process option", PROCESSING_USAGE);
2141 }
else if (!
get_double(&pd->fhead, fhead_str)) {
2142 bomb(
"invalid fhead provided for -process option", PROCESSING_USAGE);
2149 }
else if (!
get_double(&pd->ftail, ftail_str)) {
2150 bomb(
"invalid ftail provided for -process option", PROCESSING_USAGE);
2160 }
else if (!
get_double(&pd->offset, offset_str)) {
2161 bomb(
"invalid offset provided for -process option", PROCESSING_USAGE);
2171 }
else if (!
get_double(&pd->factor, factor_str)) {
2172 bomb(
"invalid factor provided for -process option", PROCESSING_USAGE);
2176 if (pd->flags & PROCESSING_BINSIZE_GIVEN && pd->binSize <= 0)
2177 SDDS_Bomb(
"invalid -process syntax---bin size is zero");
2178 if (pd->flags & PROCESSING_FACTOR_GIVEN && pd->factor == 0)
2179 SDDS_Bomb(
"invalid -process syntax---factor field is zero");
2180 if ((process_column_data[pd->mode].flags & PROCMODE_FUNCOF_REQUIRED) &&
2181 !(pd->flags & PROCESSING_FUNCOF_GIVEN))
2182 SDDS_Bomb(
"invalid -process syntax---functionOf option required for given mode");
2183 if (pd->flags & PROCESSING_WEIGHT_GIVEN &&
2184 !(process_column_data[pd->mode].flags & PROCMODE_WEIGHT_OK))
2185 SDDS_Bomb(
"invalid -process specification---weightBy option not available for given mode");
2186 if (pd->flags & PROCESSING_POSITION_GIVEN) {
2187 if (!(pd->flags & PROCESSING_FUNCOF_GIVEN))
2188 SDDS_Bomb(
"invalid -process syntax---functionOf required with position option");
2189 if (!(process_column_data[pd->mode].flags & PROCMODE_POSITION_OK))
2190 SDDS_Bomb(
"invalid -process syntax---position option not permitted for given mode");
2192 if (pd->flags & PROCESSING_LOLIM_GIVEN && pd->flags & PROCESSING_UPLIM_GIVEN &&
2193 pd->lowerLimit > pd->upperLimit)
2194 SDDS_Bomb(
"invalid -process syntax---lowerLimit>upperLimit");
2195 if (pd->flags & PROCESSING_TOPLIM_GIVEN && pd->flags & PROCESSING_BOTLIM_GIVEN && pd->topLimit < pd->bottomLimit)
2196 SDDS_Bomb(
"invalid -process syntax---bottomLimit>topLimit");
2197 if (pd->flags & PROCESSING_HEAD_GIVEN && !pd->head_par && pd->head == 0)
2198 SDDS_Bomb(
"invalid -process syntax---head=0");
2199 if (pd->flags & PROCESSING_FHEAD_GIVEN && !pd->fhead_par && pd->fhead == 0)
2200 SDDS_Bomb(
"invalid -process syntax---fhead=0");
2201 if (pd->flags & PROCESSING_TAIL_GIVEN && !pd->tail_par && pd->tail == 0)
2202 SDDS_Bomb(
"invalid -process syntax---tail=0");
2203 if (pd->flags & PROCESSING_FTAIL_GIVEN && !pd->ftail_par && pd->ftail == 0)
2204 SDDS_Bomb(
"invalid -process syntax---ftail=0");
2205 if (pd->flags & (PROCESSING_LOLIM_GIVEN | PROCESSING_UPLIM_GIVEN) && !(pd->flags & PROCESSING_FUNCOF_GIVEN))
2206 SDDS_Bomb(
"invalid -process syntax---must give -functionOf with limit options");
2207 if (pd->mode == PROCESS_COLUMN_PERCENTILE && !(pd->flags & PROCESSING_PERCLEVEL_GIVEN))
2208 SDDS_Bomb(
"invalid -process syntax---must give percentLevel with percentile processing");
2209 if (pd->flags & PROCESSING_MATCHCOLUMN_GIVEN && !(pd->flags & PROCESSING_MATCHVALUE_GIVEN))
2210 SDDS_Bomb(
"invalid -process syntax---must give value for match column");
2229 long processing_definitions,
2231 static char s[SDDS_MAXLINE], t[SDDS_MAXLINE];
2232 long i, index, index1;
2246 for (i = 0; i < processing_definitions; i++) {
2247 if ((index =
SDDS_GetColumnIndex(SDDS_dataset, processing_definition[i]->column_name)) < 0) {
2248 sprintf(s,
"column %s does not exist", processing_definition[i]->column_name);
2252 switch (processing_definition[i]->type =
2253 processing_definition[i]->outputType =
2256 if (!(process_column_data[processing_definition[i]->mode].flags & PROCMODE_STRING_OK)) {
2257 fprintf(stderr,
"column %s has the wrong type for processing (sddsprocess)\n",
2258 processing_definition[i]->column_name);
2274 fprintf(stderr,
"column %s has the wrong type for processing (sddsprocess)\n",
2275 processing_definition[i]->column_name);
2279 if (processing_definition[i]->flags & PROCESSING_DESCRIP_GIVEN) {
2280 if (strstr(processing_definition[i]->description,
"%s")) {
2281 sprintf(s, processing_definition[i]->description,
2282 processing_definition[i]->column_name);
2283 free(processing_definition[i]->description);
2287 sprintf(s,
"%s%s", process_column_data[processing_definition[i]->mode].description,
2288 processing_definition[i]->column_name);
2291 if (strstr(processing_definition[i]->parameter_name,
"%s")) {
2292 sprintf(s, processing_definition[i]->parameter_name, processing_definition[i]->column_name);
2293 free(processing_definition[i]->parameter_name);
2296 if (processing_definition[i]->flags & PROCESSING_WEIGHT_GIVEN &&
2298 sprintf(s,
"column %s does not exist", processing_definition[i]->weightBy);
2302 if (processing_definition[i]->flags & PROCESSING_MATCHCOLUMN_GIVEN &&
2304 sprintf(s,
"column %s does not exist", processing_definition[i]->match_column);
2308 if (processing_definition[i]->flags & PROCESSING_FUNCOF_GIVEN) {
2309 if ((index1 =
SDDS_GetColumnIndex(SDDS_dataset, processing_definition[i]->functionOf)) < 0) {
2310 sprintf(s,
"column %s does not exist", processing_definition[i]->functionOf);
2314 if (processing_definition[i]->flags & PROCESSING_POSITION_GIVEN &&
2316 !(process_column_data[processing_definition[i]->mode].flags & PROCMODE_STRINGPOS_OK)) {
2317 sprintf(s,
"Can't have string column for position data with %s processing",
2318 process_column_data[processing_definition[i]->mode].name);
2323 if (processing_definition[i]->outputType !=
SDDS_STRING)
2324 sprintf(s,
"¶meter name=\"%s\", type=double, description=\"%s\", ",
2325 processing_definition[i]->parameter_name, processing_definition[i]->description);
2327 sprintf(s,
"¶meter name=\"%s\", type=string, description=\"%s\", ",
2328 processing_definition[i]->parameter_name, processing_definition[i]->description);
2329 if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_FUNCOF_UNITS ||
2330 (processing_definition[i]->flags & PROCESSING_FUNCOF_GIVEN &&
2331 processing_definition[i]->flags & PROCESSING_POSITION_GIVEN)) {
2332 if (SDDS_dataset->layout.column_definition[index1].units) {
2333 sprintf(t,
"units=\"%s\", ", SDDS_dataset->layout.column_definition[index1].units);
2336 }
else if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_YoX_UNITS) {
2340 sprintf(t,
"units=\"(%s)/(%s)\", ",
2341 SDDS_dataset->layout.column_definition[index].units,
2342 SDDS_dataset->layout.column_definition[index1].units);
2344 sprintf(t,
"units=\"%s\", ",
2345 SDDS_dataset->layout.column_definition[index].units);
2347 sprintf(t,
"units=\"1/(%s)\", ",
2348 SDDS_dataset->layout.column_definition[index1].units);
2350 }
else if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_YtX_UNITS) {
2354 sprintf(t,
"units=\"%s*%s\", ",
2355 SDDS_dataset->layout.column_definition[index].units,
2356 SDDS_dataset->layout.column_definition[index1].units);
2358 sprintf(t,
"units=\"%s\", ",
2359 SDDS_dataset->layout.column_definition[index].units);
2361 sprintf(t,
"units=\"%s\", ",
2362 SDDS_dataset->layout.column_definition[index1].units);
2364 }
else if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_Y_UNITS) {
2365 if (SDDS_dataset->layout.column_definition[index].units) {
2366 sprintf(t,
"units=\"%s\", ", SDDS_dataset->layout.column_definition[index].units);
2370 if (processing_definition[i]->symbol) {
2371 sprintf(t,
"symbol=\"%s\", ", processing_definition[i]->symbol);
2376 processing_definition[i]->flags & PROCESSING_OVERWRITE_GIVEN) {
2377 pardef1.name = pardef1.symbol = pardef1.units = pardef1.description =
2378 pardef1.format_string = pardef1.fixed_value = NULL;
2381 SDDS_PARAMETER_FIELDS, s)) {
2398 processing_definition[i]->memory_number = pardef->memory_number;
2407 request =
tmalloc(
sizeof(*request));
2410 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
2412 request->is_parameter = 0;
2414 case PARAMETER_BASED:
2415 request->is_parameter = 1;
2423 request->name = argument[0];
2424 request->new_units = argument[1];
2425 request->old_units = argument[2];
2426 if (sscanf(argument[3],
"%lf", &request->factor) != 1)
2434char *substituteString(
char *
template,
char *pattern,
char *replacement) {
2435 char *ptr, *ptr0, *buffer, c;
2436 long count = 0, patternLength, newLength;
2438 if (!(patternLength = strlen(pattern)))
2440 if (!(ptr =
template))
2442 while ((ptr = strstr(ptr, pattern))) {
2444 ptr += patternLength;
2446 if ((newLength = strlen(
template) - count * patternLength + count * strlen(replacement) + 1) <= 0 ||
2447 !(buffer = malloc(newLength *
sizeof(*buffer))))
2452 while (ptr0 && *ptr0 && (ptr = strstr(ptr0, pattern))) {
2455 strcat(buffer, ptr0);
2456 strcat(buffer, replacement);
2458 ptr0 = ptr = ptr + patternLength;
2461 strcat(buffer, ptr0);
2466 long names, idef, jdef, is_parameter, templates, itemplate, definitionType, i, j;
2467 char **name, **wildcardName, *editSelection, **target, **excludeWildcardName = NULL;
2470 char editBuffer[SDDS_MAXLINE];
2471 long maxTemplates = 10, requireWildcard;
2474 short isPointer, isBase;
2483 if (!(targetData =
SDDS_Malloc(
sizeof(*targetData) * maxTemplates)))
2486 for (idef = 0; idef < *definitions; idef++) {
2487 editSelection = NULL;
2488 requireWildcard = 0;
2491 for (i = 0; i < maxTemplates; i++) {
2492 targetData[i].isPointer = 0;
2494 switch (definitionType = (*definition)[idef].type) {
2495 case IS_EQUATION_DEFINITION:
2513 case IS_PRINT_DEFINITION:
2515 wildcardName = &((
PRINT_DEFINITION *)(*definition)[idef].structure)->select;
2516 excludeWildcardName = &((
PRINT_DEFINITION *)(*definition)[idef].structure)->exclude;
2517 is_parameter = ((
PRINT_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2518 editSelection = ((
PRINT_DEFINITION *)(*definition)[idef].structure)->editSelection;
2526 if (((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources + 2 > maxTemplates) {
2527 maxTemplates = 2 * ((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources + 2;
2528 if (!(targetData =
SDDS_Realloc(targetData,
sizeof(*targetData) * maxTemplates)))
2531 for (i = 0; i < ((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources; i++) {
2532 targetData[i + 2].isPointer = 1;
2534 targetData[i + 2].isBase = 1;
2535 targetData[i + 2].arraySize =
sizeof(*(((
PRINT_DEFINITION *)(*definition)[idef].structure)->source)) *
2538 targetData[i + 2].isBase = 0;
2539 targetData[i + 2].index = i;
2544 templates = ((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources + 2;
2546 case IS_SCAN_DEFINITION:
2548 wildcardName = &((
SCAN_DEFINITION *)(*definition)[idef].structure)->source;
2549 requireWildcard = 1;
2550 is_parameter = ((
SCAN_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2562 case IS_EDIT_DEFINITION:
2564 wildcardName = &((
EDIT_DEFINITION *)(*definition)[idef].structure)->source;
2565 requireWildcard = 1;
2566 is_parameter = ((
EDIT_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2578 case IS_PROCESSING_DEFINITION:
2581 requireWildcard = 1;
2603 case IS_CONVERSION_DEFINITION:
2606 requireWildcard = 1;
2613 case IS_SYSTEM_DEFINITION:
2616 requireWildcard = 1;
2617 is_parameter = ((
SYSTEM_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2629 case IS_CAST_DEFINITION:
2631 wildcardName = &((
CAST_DEFINITION *)(*definition)[idef].structure)->source;
2632 requireWildcard = 1;
2633 is_parameter = ((
CAST_DEFINITION *)(*definition)[idef].structure)->isParameter;
2643 wildcardName = NULL;
2647 if ((!wildcardName || !*wildcardName) || (requireWildcard && !
has_wildcards(*wildcardName))) {
2648 if (wildcardName && *wildcardName)
2654 if ((excludeWildcardName == NULL) || (*excludeWildcardName == NULL)) {
2656 *wildcardName, SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2657 fprintf(stderr,
"Error (expandDefinitions): unable to find match to parameter name %s\n", *wildcardName);
2662 if ((names =
SDDS_MatchParameters(SDDS_dataset, &name, SDDS_MATCH_EXCLUDE_STRING, FIND_ANY_TYPE,
2663 *wildcardName, *excludeWildcardName,
2664 SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2665 fprintf(stderr,
"Error (expandDefinitions): unable to find match to parameter name %s\n", *wildcardName);
2671 if ((excludeWildcardName == NULL) || (*excludeWildcardName == NULL)) {
2672 if ((names =
SDDS_MatchColumns(SDDS_dataset, &name, SDDS_MATCH_STRING, FIND_ANY_TYPE,
2673 *wildcardName, SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2674 fprintf(stderr,
"Error (expandDefinitions): unable to find match to column name %s\n", *wildcardName);
2679 if ((names =
SDDS_MatchColumns(SDDS_dataset, &name, SDDS_MATCH_EXCLUDE_STRING, FIND_ANY_TYPE,
2680 *wildcardName, *excludeWildcardName,
2681 SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2682 fprintf(stderr,
"Error (expandDefinitions): unable to find match to column name %s\n", *wildcardName);
2690 *definition =
SDDS_Realloc(*definition,
sizeof(**definition) * (*definitions - 1 + names));
2691 for (jdef = *definitions - 1; jdef > idef; jdef--) {
2692 (*definition)[jdef + names - 1].structure = (*definition)[jdef].structure;
2693 (*definition)[jdef + names - 1].type = (*definition)[jdef].type;
2695 for (jdef = names - 1; jdef >= 0; jdef--) {
2697 if (!(defStruct = (*definition)[idef + jdef].structure = calloc(1, structSize)))
2698 SDDS_Bomb(
"memory allocation failure (expandDefinitions)");
2699 memcpy((
char *)defStruct, (
char *)(*definition)[idef].structure, structSize);
2701 defStruct = (*definition)[idef + jdef].structure;
2702 (*definition)[idef + jdef].type = definitionType;
2703 for (itemplate = 0; itemplate < templates; itemplate++) {
2704 if (targetData[itemplate].isPointer) {
2706 if (targetData[itemplate].isBase) {
2707 *(
char ***)((
char *)defStruct + targetData[itemplate].offset) =
2710 ptr = *(
char ***)((
char *)defStruct + targetData[itemplate].offset);
2711 target = ptr + targetData[itemplate].index;
2713 target = (
char **)((
char *)defStruct + targetData[itemplate].offset);
2715 substituteString(targetData[itemplate].
template,
"%s", name[jdef])) &&
2716 targetData[itemplate].
template) {
2717 fputs(
"Error: problem doing pattern substitution (expandDefinitions)\n", stderr);
2718 fprintf(stderr,
"template is \"%s\", instance is \"%s\"\n",
2719 targetData[itemplate].
template, name[jdef]);
2724 *definitions += names - 1;
2726 for (j = 0; j < names; j++)
2733long scan_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *format,
2734 char *edit_command) {
2735 char **source_value, char_value, *sourcePtr;
2736 long target_type, target_index, source_index;
2739 double double_value;
2740 int64_t long64_value;
2743 static char s[SDDS_MAXLINE];
2751 fprintf(stderr,
"error: source column %s has wrong type for scanning--must be string\n", source);
2766 for (i = 0; i < rows; i++) {
2767 sourcePtr = source_value[i];
2768 if (!source_value[i]) {
2774 }
else if (edit_command && strlen(edit_command)) {
2775 strncpy(s, source_value[i], SDDS_MAXLINE - 1);
2778 fprintf(stderr,
"error: unable to preedit source string \"%s\" to scan into %s\n", source_value[i], target);
2782 switch (target_type) {
2784 if (sscanf(sourcePtr, format, &double_value) != 1) {
2785 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
2788 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, double_value, -1)) {
2794 if (sscanf(sourcePtr, format, &float_value) != 1) {
2795 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
2798 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, float_value, -1)) {
2804 if (sscanf(sourcePtr, format, &long64_value) != 1) {
2805 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
2808 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, long64_value, -1)) {
2814 if (sscanf(sourcePtr, format, &long_value) != 1) {
2815 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
2818 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, long_value, -1)) {
2824 if (sscanf(sourcePtr, format, &short_value) != 1) {
2825 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
2828 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, short_value, -1)) {
2834 if (sscanf(sourcePtr, format, &char_value) != 1) {
2835 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
2838 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, char_value, -1)) {
2844 if (sscanf(sourcePtr, format, s) != 1) {
2845 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
2848 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s, -1)) {
2854 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (scan_column_value)");
2861long scan_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *format,
2862 char *edit_command) {
2863 char *source_value, **ptr, char_value;
2864 long target_type, target_index, source_index;
2866 double double_value;
2867 int64_t long64_value;
2870 static char s[SDDS_MAXLINE];
2878 fprintf(stderr,
"error: source parameter %s has wrong type for scanning--must be string\n", source);
2887 source_value = *ptr;
2888 if (!source_value) {
2893 }
else if (edit_command) {
2894 strncpy(s, source_value, SDDS_MAXLINE - 1);
2896 fprintf(stderr,
"error: unable to preedit source string \"%s\" for scanning into %s\n", source_value, target);
2902 switch (target_type) {
2904 if (sscanf(source_value, format, &double_value) != 1) {
2905 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
2906 fputs(format, stderr);
2907 fputc(
'\n', stderr);
2910 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, double_value, -1)) {
2916 if (sscanf(source_value, format, &float_value) != 1) {
2917 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
2918 fputs(format, stderr);
2919 fputc(
'\n', stderr);
2922 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, float_value, -1)) {
2928 if (sscanf(source_value, format, &long64_value) != 1) {
2929 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
2930 fputs(format, stderr);
2931 fputc(
'\n', stderr);
2934 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, long64_value, -1)) {
2940 if (sscanf(source_value, format, &long_value) != 1) {
2941 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
2942 fputs(format, stderr);
2943 fputc(
'\n', stderr);
2946 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, long_value, -1)) {
2952 if (sscanf(source_value, format, &short_value) != 1) {
2953 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
2954 fputs(format, stderr);
2955 fputc(
'\n', stderr);
2958 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, short_value, -1)) {
2964 if (sscanf(source_value, format, &char_value) != 1) {
2965 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
2966 fputs(format, stderr);
2967 fputc(
'\n', stderr);
2970 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, char_value, -1)) {
2976 if (sscanf(source_value, format, s) != 1) {
2977 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
2978 fputs(format, stderr);
2979 fputc(
'\n', stderr);
2982 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) {
2988 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (scan_parameter_value)");
2995PRINT_DEFINITION *process_new_print_definition(
char **argument,
long arguments) {
2996 static char s[SDDS_MAXLINE];
2998 long i, hasType, code;
3002 if (!(defi =
tmalloc(
sizeof(*defi))))
3003 SDDS_Bomb(
"memory allocation failure (process_new_print_definition)");
3004 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3006 defi->is_parameter = 0;
3007 sprintf(s,
"&column name=\"%s\", ", argument[1]);
3009 case PARAMETER_BASED:
3010 defi->is_parameter = 1;
3011 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
3014 fprintf(stderr,
"error: column or parameter must be specified for print\n");
3017 defi->new_name = argument[1];
3018 defi->source = NULL;
3020 defi->printf_string = argument[2];
3022 for (i = 3; i < arguments; i++) {
3023 if (!(ptr = strchr(argument[i],
'='))) {
3025 defi->source =
trealloc(defi->source,
sizeof(*defi->source) * (defi->sources + 1));
3026 defi->source[defi->sources++] = argument[i];
3030 for (; i < arguments; i++) {
3032 if (!(ptr = strchr(argument[i],
'='))) {
3033 fprintf(stderr,
"error: invalid definition-entry: %s\n", argument[i]);
3037 switch (code =
match_string(argument[i], selectQualifier, SELECT_QUALIFIERS, 0)) {
3038 case SELECT_QUALIFIER:
3039 defi->select = ptr + 1;
3041 case EDITSELECTION_QUALIFIER:
3042 defi->editSelection = ptr + 1;
3044 case EXCLUDE_QUALIFIER:
3045 defi->exclude = ptr + 1;
3054 strcat(s, argument[i]);
3055 if (strcmp(argument[i],
"type") == 0)
3063 strcat(s,
" type=string &end");
3067 SDDS_Bomb(
"unable to copy text of print definition (process_new_print_definition)");
3071long print_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char **source,
long sources,
char *format) {
3072 char *print_pos, **ptr, *fptr1, *fptr2 = NULL, *fptr3, *cptr;
3073 long source_type, source_index, target_index, target_type;
3075 static char s[SDDS_MAXLINE];
3076 static char *info = NULL;
3078 if (!info && !(info = malloc(
sizeof(
double) * 2)))
3079 SDDS_Bomb(
"Allocation failure in print_parameter_value");
3087 fprintf(stderr,
"error: target parameter %s has wrong type for printing--must be string or character\n", target);
3094 for (i = 0; i < sources; i++) {
3095 print_pos = s + strlen(s);
3099 if ((cptr = strrchr(source[i],
'.'))) {
3106 if (strcmp(cptr + 1,
"type") == 0) {
3108 return bombre(
"internal error: type of data-type information is not long", NULL, 0);
3114 if (source_type ==
SDDS_STRING && *(
char **)info == NULL)
3122 ptr = (
char **)info;
3130 if (!(fptr2 = strchr(fptr3,
'%'))) {
3131 fprintf(stderr,
"Error: invalid sprintf string\n");
3134 if (*(fptr2 + 1) ==
'%')
3136 else if (fptr2 != format && *(fptr2 - 1) ==
'\\')
3145 if ((fptr2 = strchr(fptr2 + 1,
'%')) && i != (sources - 1))
3149 switch (source_type) {
3151 sprintf(print_pos, fptr1, *(
double *)ptr);
3154 sprintf(print_pos, fptr1, *(
float *)ptr);
3157 sprintf(print_pos, fptr1, *(int64_t *)ptr);
3160 sprintf(print_pos, fptr1, *(uint64_t *)ptr);
3163 sprintf(print_pos, fptr1, *(int32_t *)ptr);
3166 sprintf(print_pos, fptr1, *(uint32_t *)ptr);
3169 sprintf(print_pos, fptr1, *(
short *)ptr);
3172 sprintf(print_pos, fptr1, *(
unsigned short *)ptr);
3175 sprintf(print_pos, fptr1, *(
char *)ptr);
3178 sprintf(print_pos, fptr1, *(
char **)ptr);
3182 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (print_parameter_value)");
3185 if (!(fptr1 = fptr2))
3192 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) ||
3194 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s[0], -1))) {
3201long print_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char **source,
long sources,
char *format) {
3202 char *print_pos, **ptr, *fptr1, *fptr2 = NULL, *fptr3, *cptr;
3203 long target_index, target_type;
3206 static char s[SDDS_MAXLINE];
3207 static long firstCall = 1;
3209 long source_type, source_index;
3210 short is_parameter, is_column, use_info;
3222 fprintf(stderr,
"error: target column %s has wrong type for printing--must be string or character\n", target);
3231 if (!(sourceData =
SDDS_Malloc(
sizeof(*sourceData) * sources)))
3232 SDDS_Bomb(
"Memory allocation failure doing printing.");
3233 for (i = 0; i < sources; i++) {
3234 print_pos = s + strlen(s);
3235 sourceData[i].is_column = sourceData[i].is_parameter =
3236 sourceData[i].use_info = 0;
3238 ((sourceData[i].source_type =
SDDS_GetColumnType(SDDS_dataset, sourceData[i].source_index)) >= 0))
3239 sourceData[i].is_column = 1;
3242 sourceData[i].is_parameter = 1;
3243 else if ((cptr = strrchr(source[i],
'.'))) {
3245 if ((sourceData[i].source_type =
3247 sourceData[i].is_parameter = 1;
3248 else if ((sourceData[i].source_type =
3250 sourceData[i].is_column = 1;
3255 if (strcmp(cptr + 1,
"type") == 0) {
3256 if (sourceData[i].source_type !=
SDDS_LONG)
3257 return bombre(
"internal error: type of data-type information is not long", NULL, 0);
3262 sourceData[i].use_info = 1;
3263 if (sourceData[i].source_type ==
SDDS_STRING && sourceData[i].info == NULL)
3266 sprintf(s,
"Unable to find print source %s.", source[i]);
3273 for (j = 0; j < rows; j++) {
3278 for (i = 0; i < sources; i++) {
3279 print_pos = s + strlen(s);
3280 if (sourceData[i].is_column && !sourceData[i].use_info) {
3281 if (!(ptr =
SDDS_GetValue(SDDS_dataset, source[i], j, NULL))) {
3288 fprintf(stderr,
"error: -print option for column %s uses source %s which is defined\n",
3290 fprintf(stderr,
"as both a column and a parameter\n");
3293 fprintf(stderr,
"warning: -print option for column %s uses source %s which is defined\n",
3295 fprintf(stderr,
"as both a column and a parameter---column values are used!\n");
3299 if (sourceData[i].is_parameter && !sourceData[i].use_info) {
3301 SDDS_SetError(
"Unable to get print source parameter value.");
3306 if (sourceData[i].use_info)
3307 ptr = &sourceData[i].info;
3310 if (!(fptr2 = strchr(fptr3,
'%'))) {
3311 fprintf(stderr,
"Error: invalid sprintf string\n");
3314 if (*(fptr2 + 1) ==
'%')
3316 else if (fptr2 != format && *(fptr2 - 1) ==
'\\')
3325 if ((fptr2 = strchr(fptr2 + 1,
'%')) && i != (sources - 1))
3329 switch (sourceData[i].source_type) {
3331 sprintf(print_pos, fptr1, *(
double *)ptr);
3334 sprintf(print_pos, fptr1, *(
float *)ptr);
3337 sprintf(print_pos, fptr1, *(int64_t *)ptr);
3340 sprintf(print_pos, fptr1, *(uint64_t *)ptr);
3343 sprintf(print_pos, fptr1, *(int32_t *)ptr);
3346 sprintf(print_pos, fptr1, *(uint32_t *)ptr);
3349 sprintf(print_pos, fptr1, *(
short *)ptr);
3352 sprintf(print_pos, fptr1, *(
unsigned short *)ptr);
3355 sprintf(print_pos, fptr1, *(
char *)ptr);
3358 sprintf(print_pos, fptr1, *(
char **)ptr);
3359 if (!sourceData[i].use_info)
3363 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (print_column_value)");
3366 if (!sourceData[i].use_info)
3368 if (!(fptr1 = fptr2))
3373 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, target_index, s, -1)) ||
3375 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, target_index, s[0],
3386FORMAT_DEFINITION *process_new_format_definition(
char **argument,
long arguments) {
3388 unsigned long flags;
3390 if (!(defi =
tmalloc(
sizeof(*defi))))
3391 SDDS_Bomb(
"memory allocation failure (process_new_format_definition)");
3392 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3394 defi->is_parameter = 0;
3396 case PARAMETER_BASED:
3397 defi->is_parameter = 1;
3400 fprintf(stderr,
"error: column or parameter must be specified for format\n");
3403 defi->target = argument[1];
3404 defi->source = argument[2];
3405 defi->stringFormat = NULL;
3406 defi->doubleFormat = NULL;
3407 defi->longFormat = NULL;
3412 "stringformat",
SDDS_STRING, &defi->stringFormat, 1, 0,
3413 "doubleformat",
SDDS_STRING, &defi->doubleFormat, 1, 0,
3414 "longformat",
SDDS_STRING, &defi->longFormat, 1, 0,
3416 bomb(
"invalid -format syntax", NULL);
3422 static char *buffer = NULL;
3423 static long bufferSize = 0;
3424 char *ptr, *doubleFormat, *longFormat, *stringFormat;
3425 long target_index, source_index, bufferRequired;
3432 fprintf(stderr,
"error: target parameter %s has wrong type for formatting--must be string\n", definition->source);
3436 fprintf(stderr,
"error: target parameter %s has wrong type for formatting--must be string\n", definition->target);
3443 if ((bufferRequired = 2 * strlen(ptr) + 1024) > bufferSize) {
3445 bufferSize = bufferRequired;
3446 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * bufferRequired))) {
3452 if (!(doubleFormat = definition->doubleFormat))
3453 doubleFormat =
"%21.15e";
3454 if (!(longFormat = definition->longFormat))
3456 if (!(stringFormat = definition->stringFormat))
3457 stringFormat =
"%s";
3459 if (!reformatString(buffer, bufferSize, ptr, stringFormat, doubleFormat, longFormat))
3462 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, buffer, -1)) {
3469long reformatString(
char *buffer,
long bufferSize,
char *
string,
char *stringFormat,
3470 char *doubleFormat,
char *longFormat) {
3471 long bufferUseLimit, length, lValue;
3473 char *bufferPosition, *token0, *token1;
3475 bufferPosition = buffer;
3477 bufferUseLimit = bufferSize * 0.9 + 1;
3480 while ((token0 = strtok(token1,
" "))) {
3484 if (sscanf(token0,
"%ld", &lValue) == 1)
3485 sprintf(bufferPosition, longFormat, lValue);
3487 fprintf(stderr,
"Error: problem formatting token %s as long integer.\n", token0);
3491 if (sscanf(token0,
"%lf", &dValue) == 1)
3492 sprintf(bufferPosition, doubleFormat, dValue);
3494 fprintf(stderr,
"Error: problem formatting token %s as double.\n", token0);
3498 sprintf(bufferPosition, stringFormat, token0);
3499 if ((length = strlen(buffer)) > bufferUseLimit) {
3500 fprintf(stderr,
"Error: format buffer overflow (sddsprocess).\n");
3503 bufferPosition = buffer + length;
3504 *bufferPosition =
' ';
3505 *++bufferPosition = 0;
3507 if ((--bufferPosition) >= buffer)
3508 *bufferPosition = 0;
3513 static char *buffer = NULL;
3514 static long bufferSize = 0;
3515 char **ptr, *longFormat, *doubleFormat, *stringFormat;
3516 long source_index, target_index, bufferRequired;
3525 fprintf(stderr,
"error: target column %s has wrong type for formatting--must be string\n", definition->source);
3529 fprintf(stderr,
"error: target column %s has wrong type for formatting--must be string\n", definition->target);
3541 if (!(doubleFormat = definition->doubleFormat))
3542 doubleFormat =
"%21.15e";
3543 if (!(longFormat = definition->longFormat))
3545 if (!(stringFormat = definition->stringFormat))
3546 stringFormat =
"%s";
3548 for (row = 0; row < rows; row++) {
3549 if ((bufferRequired = 2 * strlen(ptr[row]) + 1024) > bufferSize) {
3550 bufferSize = bufferRequired;
3551 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * bufferRequired))) {
3556 if (!reformatString(buffer, bufferSize, ptr[row], stringFormat, doubleFormat, longFormat)) {
3557 fprintf(stderr,
"Error: problem formatting string >%s< (sddsprocess).\n",
3561 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, row, target_index, buffer, -1)) {
3569void add_definition(
DEFINITION **definition,
long *definitions,
void *structure,
long type) {
3570 *definition =
trealloc(*definition,
sizeof(**definition) * (*definitions + 1));
3571 (*definition)[*definitions].structure = structure;
3572 (*definition)[*definitions].type = type;
3578 int i, algebraic = 0;
3579 char pfix[IFPF_BUF_SIZE];
3581 if (!(defi =
tmalloc(
sizeof(*defi))))
3582 SDDS_Bomb(
"memory allocation failure (process_new_print_definition)");
3583 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3585 defi->is_parameter = 0;
3587 case PARAMETER_BASED:
3588 defi->is_parameter = 1;
3591 fprintf(stderr,
"error: column or parameter must be specified for rpntest\n");
3596 for (i = 2; i < arguments; i++) {
3597 if (strncmp(argument[i],
"autostop", strlen(argument[i])) == 0)
3599 else if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0)
3606 ptr = addOuterParentheses(argument[1]);
3607 if2pf(pfix, ptr,
sizeof pfix);
3610 fprintf(stderr,
"error: problem copying argument string\n");
3614 defi->expression = argument[1];
3620 int i, algebraic = 0;
3621 char pfix[IFPF_BUF_SIZE];
3625 if (!(defi =
tmalloc(
sizeof(*defi))))
3626 SDDS_Bomb(
"memory allocation failure (process_new_rpnexpression_definition)");
3629 for (i = 1; i < arguments; i++) {
3630 if (strncmp(argument[i],
"repeat", strlen(argument[i])) == 0)
3632 else if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0)
3639 ptr = addOuterParentheses(argument[0]);
3640 if2pf(pfix, ptr,
sizeof pfix);
3643 fprintf(stderr,
"error: problem copying argument string\n");
3647 defi->expression = argument[0];
3651CLIP_DEFINITION *process_new_clip_definition(
char **argument,
long arguments) {
3654 if (arguments < 2 || arguments > 3)
3656 if (!(defi =
tmalloc(
sizeof(*defi))))
3657 SDDS_Bomb(
"memory allocation failure (process_new_clip_definition)");
3658 if (sscanf(argument[0],
"%" SCNd64, &defi->head) != 1 ||
3659 sscanf(argument[1],
"%" SCNd64, &defi->tail) != 1 ||
3660 defi->head < 0 || defi->tail < 0)
3664 if (arguments == 3) {
3665 if (strncmp(argument[2],
"invert", strlen(argument[2])) != 0)
3671FCLIP_DEFINITION *process_new_fclip_definition(
char **argument,
long arguments) {
3674 if (arguments < 2 || arguments > 3)
3676 if (!(defi =
tmalloc(
sizeof(*defi))))
3677 SDDS_Bomb(
"memory allocation failure (process_new_clip_definition)");
3678 if (sscanf(argument[0],
"%le", &defi->fhead) != 1 ||
3679 sscanf(argument[1],
"%le", &defi->ftail) != 1 ||
3680 defi->fhead < 0 || defi->ftail < 0)
3684 if (arguments == 3) {
3685 if (strncmp(argument[2],
"invert", strlen(argument[2])) != 0)
3691SPARSE_DEFINITION *process_new_sparse_definition(
char **argument,
long arguments) {
3694 if (arguments < 1 || arguments > 2)
3696 if (!(defi =
tmalloc(
sizeof(*defi))))
3697 SDDS_Bomb(
"memory allocation failure (process_new_sparse_definition)");
3698 if (sscanf(argument[0],
"%" SCNd64, &defi->interval) != 1 || defi->interval <= 0 ||
3699 (arguments == 2 && (sscanf(argument[1],
"%" SCNd64, &defi->offset) != 1 || defi->offset < 0)))
3704SAMPLE_DEFINITION *process_new_sample_definition(
char **argument,
long arguments) {
3709 if (!(defi =
tmalloc(
sizeof(*defi))))
3710 SDDS_Bomb(
"memory allocation failure (process_new_sample_definition)");
3711 if (sscanf(argument[0],
"%lf", &defi->fraction) != 1)
3716SYSTEM_DEFINITION *process_new_system_definition(
char **argument,
long arguments) {
3717 static char s[SDDS_MAXLINE];
3722 if (!(defi =
tmalloc(
sizeof(*defi))))
3723 SDDS_Bomb(
"memory allocation failure (process_new_system_definition)");
3724 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3726 defi->is_parameter = 0;
3727 sprintf(s,
"&column name=\"%s\", ", argument[1]);
3729 case PARAMETER_BASED:
3730 defi->is_parameter = 1;
3731 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
3734 fprintf(stderr,
"error: column or parameter must be specified for system\n");
3737 defi->new_name = argument[1];
3738 defi->source = argument[2];
3739 for (i = 3; i < arguments; i++) {
3740 if (!(ptr = strchr(argument[i],
'=')))
3743 if (strcmp(argument[i],
"type") == 0)
3745 strcat(s, argument[i]);
3750 strcat(s,
" type=string &end");
3752 SDDS_Bomb(
"unable to copy text of system definition (process_new_system_definition)");
3756long system_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source) {
3757 char **source_value, *command;
3759 long target_index, source_index;
3760 static char s[SDDS_MAXLINE];
3768 fprintf(stderr,
"error: source column %s has wrong type for system call--must be string\n", source);
3772 fprintf(stderr,
"error: target column %s has wrong type for system call--must be string\n", target);
3786 for (i = 0; i < rows; i++) {
3788 if ((command = source_value[i]) && !run_on_pipe(command, s, SDDS_MAXLINE)) {
3789 sprintf(s,
"Problem with subprocess call (system_column_value)---command was\n%s\n",
3794 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s, -1)) {
3802long system_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source) {
3803 char *command, **ptr;
3804 long target_index, source_index;
3805 static char s[SDDS_MAXLINE];
3813 fprintf(stderr,
"error: source parameter %s has wrong type for system call--must be string\n", source);
3817 fprintf(stderr,
"error: target parameter %s has wrong type for system call--must be string\n", target);
3826 if ((command = *ptr) && !run_on_pipe(command, s, SDDS_MAXLINE)) {
3827 sprintf(s,
"Problem with subprocess call (system_parameter_value)---command was\n%s\n",
3832 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) {
3842long run_on_pipe(
char *command,
char *buffer,
long buffer_length) {
3846 if (!(fp = popen(command,
"r")))
3849 if (!fgets(buffer, buffer_length, fp)) {
3853 if (buffer[(length = strlen(buffer)) - 1] ==
'\n')
3854 buffer[length - 1] = 0;
3860long SDDS_RedefineParameterCL(
SDDS_DATASET *SDDS_dataset,
char *parameter,
char **argv,
long argc) {
3861 char *value, *keyword;
3864 for (i = 0; i < argc; i++) {
3866 if (!(value = strchr(argv[i],
'='))) {
3867 fprintf(stderr,
"error: missing = in qualifier string for redefine: %s\n", argv[i]);
3873 fprintf(stderr,
"Problem redefining %s for %s\n",
3874 keyword, parameter);
3884long SDDS_RedefineColumnCL(
SDDS_DATASET *SDDS_dataset,
char *column,
char **argv,
long argc) {
3885 char *value, *keyword;
3888 for (i = 0; i < argc; i++) {
3890 if (!(value = strchr(argv[i],
'='))) {
3891 fprintf(stderr,
"error: missing = in qualifier string for redefine: %s\n", argv[i]);
3897 fprintf(stderr,
"Problem redefining %s for %s\n",
3907long add_sddsfile_arguments(SCANNED_ARG **scanned,
int argc) {
3908 long iarg, datacode, index, argc_got;
3911 static char *choice[2] = {
"column",
"parameter"};
3912 char *dataname, *filename, **argv_got;
3913 SCANNED_ARG *sa_got;
3918 for (iarg = 0; iarg < argc; iarg++) {
3919 if (!((*scanned)[iarg].arg_type == OPTION) ||
3920 strcmp((*scanned)[iarg].list[0],
"getargs") != 0 ||
3921 (*scanned)[iarg].n_items != 3 ||
3922 !(dataname = strchr((*scanned)[iarg].list[2],
'=')) || (*dataname++ = 0) ||
3923 ((datacode =
match_string((*scanned)[iarg].list[2], choice, 2, 0)) < 0))
3925 filename = (*scanned)[iarg].list[1];
3930 fprintf(stderr,
"error: %s %s not found in file %s--can't process -getargs request\n",
3931 choice[datacode], dataname, filename);
3937 fprintf(stderr,
"error: %s %s from file %s does not have string type--can't use for -getargs\n",
3938 choice[datacode], dataname, filename);
3952 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
3953 argv_got =
trealloc(argv_got,
sizeof(*argv_got) * (rows + argc_got));
3954 for (j = 0; j < rows; j++) {
3956 argv_got[argc_got + j] = column[j];
3966 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
3967 argv_got =
trealloc(argv_got,
sizeof(*argv_got) * (argc_got + 1));
3968 argv_got[argc_got] = parameter;
3976 argc_got =
scanargsg(&sa_got, argc_got, argv_got);
3977 *scanned =
trealloc(*scanned,
sizeof(**scanned) * (argc + argc_got));
3979 for (j = argc - 1; j > iarg; j--)
3980 (*scanned)[j + argc_got - 1] = (*scanned)[j];
3981 for (j = 0; j < argc_got; j++)
3982 (*scanned)[j + iarg] = sa_got[j];
3983 argc += argc_got - 1;
3984 iarg += argc_got - 1;
3989long ParameterScansAsNumber(
SDDS_DATASET *dataset,
char *name,
short invert) {
3993 fprintf(stderr,
"Error: parameter %s nonexistent or not string type---can't use with -numberTest\n",
4002 if (sscanf(*ptr,
"%lf", &value) != 1) {
4011 char **source_value, **target_value;
4012 long target_index, source_index, size;
4014 long source_type, target_type;
4019 sprintf(s,
"Unable to cast %s to %s--column not found", cast->source,
4027 sprintf(s,
"source column %s has wrong type for casting--must be number\n",
4036 sprintf(s,
"target column %s has wrong type for casting--must be number\n",
4057 for (i = 0; i < rows; i++) {
4059 (
void *)((
char *)target_value + size * i))) {
4069 int32_t targetIndex, sourceIndex;
4070 static char s[SDDS_MAXLINE];
4078 sprintf(s,
"error: source parameter %s has wrong type for casting--must be number\n",
4085 fprintf(stderr,
"error: target parameter %s has wrong type for casting--must be number\n",
4096 SDDS_BY_INDEX | SDDS_PASS_BY_VALUE,
4097 targetIndex, doubleValue, -1)) {
4104char *addOuterParentheses(
char *arg) {
4106 ptr =
tmalloc(
sizeof(*ptr) * (strlen(arg) + 2));
4107 sprintf(ptr,
"(%s)", arg);
4111void GillMillerIntegration1(
double *indepData,
double *data,
long n_data,
double *result) {
4113 integral =
tmalloc(
sizeof(*integral) * n_data);
4115 *result = integral[n_data - 1];
int GillMillerIntegration(double *integral, double *error, double *f, double *x, long n)
Performs numerical integration using the Gill-Miller method.
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_SetParametersFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_ChangeParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a parameter definition within the SDDS dataset.
int32_t SDDS_GetParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified parameter in the SDDS dataset.
int32_t SDDS_ChangeColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a column definition within the SDDS dataset.
int32_t SDDS_GetColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified column in the SDDS dataset.
int32_t SDDS_ProcessParameterString(SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
Process a parameter definition string.
int32_t SDDS_ParseNamelist(void *data, SDDS_FIELD_INFORMATION *fieldInfo, int32_t fieldInfos, char *s)
Parse a namelist string and populate the corresponding data structure.
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_TransferParameterDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a parameter definition from a source dataset to a target dataset.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
PARAMETER_DEFINITION * SDDS_GetParameterDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified parameter from the SDDS dataset.
int32_t SDDS_FreeParameterDefinition(PARAMETER_DEFINITION *source)
Frees memory allocated for a parameter definition.
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_MatchParameters(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves parameter names from an SDDS dataset based on specified criteria.
void * SDDS_CastValue(void *data, int64_t index, int32_t data_type, int32_t desired_type, void *memory)
Casts a value from one SDDS data type to another.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
int32_t SDDS_IdentifyType(char *typeName)
Identifies the SDDS data type based on its string name.
int32_t SDDS_GetTypeSize(int32_t type)
Retrieves the size in bytes of a specified SDDS data type.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_MatchColumns(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves column names from an SDDS dataset based on specified criteria.
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
int32_t SDDS_CheckParameter(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a parameter exists in the SDDS dataset with the specified name, units, and type.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
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.
void SDDS_Free(void *mem)
Free memory previously allocated by SDDS_Malloc.
COLUMN_DEFINITION * SDDS_GetColumnDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified column from the SDDS dataset.
Header file for routines used by SDDS command-line applications.
long edit_string(char *text, char *edit)
Edits the provided text based on the specified edit commands.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
long bombre(char *error, char *usage, long return_value)
Reports error messages to the terminal and returns a specified value.
int get_double(double *dptr, char *s)
Parses a double value from the given string.
long tokenIsNumber(char *token)
Checks if the given token represents a valid number.
int get_int(int *iptr, char *s)
Parses an integer value from the given string.
long tokenIsInteger(char *token)
Checks if the given token represents a valid integer.
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
void edit_strings(char **string, long strings, char *buffer, char *edit)
Applies edit commands to an array of strings.
int index_min_max(int64_t *imin, int64_t *imax, double *list, int64_t n)
Finds the indices of the minimum and maximum values in a list of doubles.
FILE * fopen_e(char *file, char *open_mode, long mode)
Opens a file with error checking, messages, and aborts.
char * get_token_tq(char *s, char *ts, char *te, char *qs, char *qe)
Extracts a token from a string with support for multiple delimiter and quotation sets.
long is_blank(char *s)
Determine whether a string is composed entirely of whitespace characters.
double linearCorrelationCoefficient(double *data1, double *data2, short *accept1, short *accept2, long rows, long *count)
Compute the linear correlation coefficient for two data sets.
long unweightedLinearFit(double *xData, double *yData, long nData, double *slope, double *intercept, double *variance)
Performs an unweighted linear fit on the provided data.
double getTimeInSecs()
Get the current time in seconds since the Epoch with high resolution.
long computeMode(double *result, double *data, long pts, double binSize, long bins)
Computes the mode of a dataset using histogram binning.
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.
int strncmp_case_insensitive(char *s1, char *s2, long n)
Compares up to a specified number of characters of two strings in a case-insensitive manner.
double weightedStDevThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted standard deviation of an array of doubles using multiple threads.
double standardDeviationThreaded(double *x, long n, long numThreads)
Calculates the standard deviation of an array of doubles using multiple threads.
double rmsValueThreaded(double *y, long n, long numThreads)
Calculates the RMS (Root Mean Square) value of an array of doubles using multiple threads.
double arithmeticAverageThreaded(double *y, long n, long numThreads)
Calculates the arithmetic average of an array of doubles using multiple threads.
double weightedRMSThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted RMS (Root Mean Square) value of an array of doubles using multiple threads.
double meanAbsoluteDeviationThreaded(double *y, long n, long numThreads)
Calculates the mean absolute deviation of an array of doubles using multiple threads.
double weightedMADThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted mean absolute deviation of an array of doubles using multiple threads.
double weightedAverageThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted average of an array of doubles using multiple threads.
int scanargsg(SCANNED_ARG **scanned, int argc, char **argv)
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.
short TimeBreakdownToEpoch(short year, short jDay, short month, short day, double hour, double *epochTime)
Converts a broken-down time into epoch time.
long findTopBaseLevels(double *top, double *base, double *data, int64_t points, long bins, double sigmasRequired)
Finds the top-level and base-level of a dataset.
int64_t findCrossingPoint(int64_t start, double *data, int64_t points, double level, long direction, double *indepData, double *location)
Finds the crossing point in the data where the data crosses a specified level.
long trapazoidIntegration(double *x, double *y, long n, double *integral)
Computes the integral of a dataset using the trapezoidal rule.
int has_wildcards(char *template)
Check if a template string contains any wildcard characters.
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
char * unescape_wildcards(char *template)
Remove escape characters from wildcard characters in a template string.