263# include <sys/time.h>
268char *data_class_keyword[DATA_CLASS_KEYWORDS] = {
278 char *name, *description;
281#define PROCMODE_NORMAL 0x0000UL
282#define PROCMODE_FUNCOF_REQUIRED 0x0001UL
283#define PROCMODE_FUNCOF_UNITS 0x0002UL
284#define PROCMODE_WEIGHT_OK 0x0004UL
285#define PROCMODE_POSITION_OK 0x0008UL
286#define PROCMODE_STRING_OK 0x0010UL
287#define PROCMODE_YoX_UNITS 0x0020UL
288#define PROCMODE_STRINGPOS_OK 0x0040UL
289#define PROCMODE_YtX_UNITS 0x0080UL
290#define PROCMODE_Y_UNITS 0x0100UL
291#define PROCMODE_NO_UNITS x00200UL
293static char *process_column_name[N_PROCESS_COLUMN_MODES] = {NULL};
295 {
"average",
"average of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
296 {
"rms",
"rms of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
297 {
"sum",
"sum of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
298 {
"standarddeviation",
"standard deviation of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
299 {
"mad",
"mean absolute deviation of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
300 {
"minimum",
"minimum of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
301 {
"maximum",
"maximum of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
302 {
"smallest",
"smallest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
303 {
"largest",
"largest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
304 {
"first",
"first ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_STRING_OK},
305 {
"last",
"last ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_STRING_OK},
306 {
"count",
"count ", PROCMODE_NORMAL},
307 {
"spread",
"spread in ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
308 {
"median",
"median of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
309 {
"baselevel",
"base level of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
310 {
"toplevel",
"top level of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
311 {
"amplitude",
"amplitude of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
312 {
"risetime",
"risetime of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
313 {
"falltime",
"falltime of", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
314 {
"fwhm",
"fwhm of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
315 {
"fwtm",
"fwtm of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
316 {
"center",
"center of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
317 {
"zerocrossing",
"zero crossing of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
318 {
"fwha",
"fwha of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
319 {
"fwta",
"fwta of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_FUNCOF_UNITS},
320 {
"sigma",
"sigma of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_WEIGHT_OK},
321 {
"slope",
"slope of ", PROCMODE_FUNCOF_REQUIRED | PROCMODE_YoX_UNITS},
322 {
"intercept",
"intercept of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
323 {
"lfsd",
"linear-fit standard deviation of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
324 {
"qrange",
"quartile range", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
325 {
"drange",
"decile range", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
326 {
"percentile",
"percentile", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
327 {
"mode",
"mode of", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
328 {
"integral",
"integral of ", PROCMODE_NORMAL | PROCMODE_FUNCOF_REQUIRED | PROCMODE_YtX_UNITS},
329 {
"product",
"product of ", PROCMODE_NORMAL | PROCMODE_WEIGHT_OK},
330 {
"prange",
"percentile range", PROCMODE_NORMAL | PROCMODE_Y_UNITS},
331 {
"signedsmallest",
"signed smallest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
332 {
"signedlargest",
"signed largest of ", PROCMODE_NORMAL | PROCMODE_Y_UNITS | PROCMODE_POSITION_OK | PROCMODE_STRINGPOS_OK},
333 {
"gmintegral",
"integral of ", PROCMODE_NORMAL | PROCMODE_FUNCOF_REQUIRED | PROCMODE_YtX_UNITS},
334 {
"correlation",
"correlation coefficient", PROCMODE_FUNCOF_REQUIRED}};
339#define SELECT_QUALIFIER 0
340#define EDITSELECTION_QUALIFIER 1
341#define EXCLUDE_QUALIFIER 2
342#define SELECT_QUALIFIERS 3
343static char *selectQualifier[SELECT_QUALIFIERS] = {
344 "select",
"editselection",
"exclude"};
346void GillMillerIntegration1(
double *indepData,
double *data,
long n_data,
double *result);
348void show_process_modes(FILE *fp) {
349 long i, length, maxLength, nPerLine;
353 for (i = 0; i < N_PROCESS_COLUMN_MODES; i++)
354 if ((length = strlen(process_column_data[i].name)) > maxLength)
356 sprintf(format,
"%%%lds%%c", maxLength + 1);
357 nPerLine = 80 / (maxLength + 2);
358 fprintf(fp,
"processing modes:\n");
359 for (i = 0; i < N_PROCESS_COLUMN_MODES; i++)
360 fprintf(fp, format, process_column_data[i].name, (i + 1) % nPerLine ?
' ' :
'\n');
365void add_ifitem(
IFITEM_LIST *ifitem,
char **name,
long names) {
367 if (ifitem->items == 0) {
371 ifitem->name =
trealloc(ifitem->name,
sizeof(*ifitem->name) * (ifitem->items + names - 1));
372 ifitem->type =
trealloc(ifitem->type,
sizeof(*ifitem->type) * (ifitem->items + names - 1));
373 if ((type =
match_string(name[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) < 0)
374 SDDS_Bomb(
"invalid -ifnot syntax---column, parameter, or array keyword required");
375 for (i = 1; i < names; i++)
376 ifitem->type[ifitem->items + i - 1] = type;
378 SDDS_Bomb(
"problem copying names for -ifnot or -ifis option");
379 ifitem->items += names - 1;
384 for (i = 0; i < ifitem->items; i++) {
385 switch (ifitem->type[i]) {
389 case PARAMETER_BASED:
396 SDDS_Bomb(
"internal error---unknown ifitem type");
400 if ((index >= 0) != desired) {
403 fprintf(stderr,
"%s %s does not exist--aborting\n",
404 data_class_keyword[ifitem->type[i]], ifitem->name[i]);
408 fprintf(stderr,
"%s %s exists--aborting\n",
409 data_class_keyword[ifitem->type[i]], ifitem->name[i]);
416FILTER_DEFINITION *process_new_filter_definition(
char **argument,
long arguments) {
419 if (!(defi =
tmalloc(
sizeof(*defi))))
420 SDDS_Bomb(
"memory allocation failure (process_new_filter_definition)");
421 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
423 defi->is_parameter = 0;
425 case PARAMETER_BASED:
426 defi->is_parameter = 1;
429 fprintf(stderr,
"error: column or parameter must be specified for filter\n");
432 if (!(defi->filter_terms =
433 process_filter_request(&(defi->filter_term), argument + 1, arguments - 1)))
440 char *before, *after, *year, *month = NULL, *day = NULL, *hour, *minute, *second;
441 short minute_n, second_n, hour_n;
443 minute_n = second_n = hour_n = 0;
445 before = after = NULL;
446 if (!(defi =
tmalloc(
sizeof(*defi))))
447 SDDS_Bomb(
"memory allocation failure (process_new_filter_definition)");
448 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
450 defi->is_parameter = 0;
452 case PARAMETER_BASED:
453 defi->is_parameter = 1;
456 fprintf(stderr,
"error: column or parameter must be specified for filter\n");
460 defi->before = defi->after = 0;
461 hour = minute = second = 0;
462 defi->name = argument[1];
465 if (!
scanItemList(&defi->flags, argument, &arguments, 0,
466 "before",
SDDS_STRING, &before, 1, TIMEFILTER_BEFORE_GIVEN,
467 "after",
SDDS_STRING, &after, 1, TIMEFILTER_AFTER_GIVEN,
468 "invert", -1, NULL, 0, TIMEFILTER_INVERT_GIVEN,
472 minute_n = second_n = hour_n = 0;
476 SDDS_Bomb(
"invalid \"before\" date given, the specified data should be YYYY/MM/DD@HH:MM:SS");
480 minute_n = atol(minute);
482 second_n = atol(second);
483 hour_n1 = hour_n * 1.0 + minute_n / 60.0 + second_n / 3600.0;
485 SDDS_Bomb(
"invalid -timeFilter before syntax (something wrong with time convert)");
489 minute_n = second_n = hour_n = 0;
493 SDDS_Bomb(
"invalid \"after\" date given, the specified data should be YYYY/MM/DD@HH:MM:SS");
497 minute_n = atol(minute);
499 second_n = atol(second);
500 hour_n1 = hour_n * 1.0 + minute_n / 60.0 + second_n / 3600.0;
502 SDDS_Bomb(
"invalid -timeFilter after syntax (something wrong with time convert)");
505 if (before && after && defi->before < defi->after)
506 SDDS_Bomb(
"Invalid -timeFilter syntx, before date is earlier than the after date!");
516MATCH_DEFINITION *process_new_match_definition(
char **argument,
long arguments) {
519 if (!(defi =
tmalloc(
sizeof(*defi))))
520 SDDS_Bomb(
"memory allocation failure (process_new_match_definition)");
521 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
523 defi->is_parameter = 0;
525 case PARAMETER_BASED:
526 defi->is_parameter = 1;
529 fprintf(stderr,
"error: column or parameter must be specified for match\n");
532 if (!(defi->match_terms =
533 process_match_request(&(defi->match_term), argument + 1, arguments - 1)))
538long process_filter_request(
FILTER_TERM **filter,
char **argument,
long arguments) {
539 long i, filters, max_filters;
540 long need_name, need_operation;
544 max_filters = (arguments + 1) / 3 + 1;
545 *filter =
tmalloc(
sizeof(**filter) * max_filters);
550 if (is_logic_character(argument[i][0])) {
557 switch (argument[i][0]) {
559 if ((*filter)[filters].logic & SDDS_AND || (*filter)[filters].logic & SDDS_OR ||
560 (*filter)[filters].logic & SDDS_NEGATE_EXPRESSION)
562 (*filter)[filters].logic |= SDDS_AND;
565 if ((*filter)[filters].logic & SDDS_AND || (*filter)[filters].logic & SDDS_OR ||
566 (*filter)[filters].logic & SDDS_NEGATE_EXPRESSION)
568 (*filter)[filters].logic |= SDDS_OR;
571 if (!((*filter)[filters].logic & SDDS_AND || (*filter)[filters].logic & SDDS_OR) ||
572 (*filter)[filters].logic & SDDS_NEGATE_EXPRESSION)
574 (*filter)[filters].logic |= SDDS_NEGATE_EXPRESSION;
576 }
while (++i < arguments && is_logic_character(argument[i][0]));
581 }
else if (need_operation > 0)
585 if (is_logic_character(argument[i][0]))
587 if (arguments - i < 3)
589 if (filters + 1 >= max_filters)
590 *filter =
trealloc(*filter,
sizeof(**filter) * (max_filters += 2));
591 (*filter)[filters].name = argument[i++];
592 if (sscanf(argument[i],
"%lf", &(*filter)[filters].lower) != 1)
593 (*filter)[filters].lowerPar = argument[i];
595 (*filter)[filters].lowerPar = NULL;
597 if (sscanf(argument[i],
"%lf", &(*filter)[filters].upper) != 1)
598 (*filter)[filters].upperPar = argument[i];
600 (*filter)[filters].upperPar = NULL;
602 if ((*filter)[filters].lowerPar == NULL && (*filter)[filters].upperPar == NULL && (*filter)[filters].upper < (*filter)[filters].lower)
604 (*filter)[filters].logic = 0;
605 if (arguments - i > 0 && argument[i][0] ==
'!') {
606 (*filter)[filters].logic = SDDS_NEGATE_MATCH;
609 if (++need_operation > 0)
613 }
while (arguments > i);
614 (*filter)[0].logic |= SDDS_AND;
618long process_match_request(
MATCH_TERM **match,
char **argument,
long arguments) {
619 long i, matches, max_matches;
620 long need_name, need_operation;
625 max_matches = (arguments + 1) / 3 + 1;
626 *match =
tmalloc(
sizeof(**match) * max_matches);
631 if (is_logic_character(argument[i][0])) {
638 switch (argument[i][0]) {
640 if ((*match)[matches].logic & SDDS_AND || (*match)[matches].logic & SDDS_OR ||
641 (*match)[matches].logic & SDDS_NEGATE_EXPRESSION)
643 (*match)[matches].logic |= SDDS_AND;
646 if ((*match)[matches].logic & SDDS_AND || (*match)[matches].logic & SDDS_OR ||
647 (*match)[matches].logic & SDDS_NEGATE_EXPRESSION)
649 (*match)[matches].logic |= SDDS_OR;
652 if (!((*match)[matches].logic & SDDS_AND || (*match)[matches].logic & SDDS_OR) ||
653 (*match)[matches].logic & SDDS_NEGATE_EXPRESSION)
655 (*match)[matches].logic |= SDDS_NEGATE_EXPRESSION;
657 }
while (++i < arguments && is_logic_character(argument[i][0]));
662 }
else if (need_operation > 0)
666 if (is_logic_character(argument[i][0]))
668 if (arguments - i < 1)
670 if (matches + 1 >= max_matches)
671 *match =
trealloc(*match,
sizeof(**match) * (max_matches += 2));
672 if (!(ptr = strchr(argument[i],
'=')))
675 (*match)[matches].logic = 0;
676 if (*(ptr + 1) ==
'+') {
677 (*match)[matches].logic |= SDDS_NOCASE_COMPARE;
680 if (*(ptr + 1) ==
'@') {
681 (*match)[matches].logic |= SDDS_INDIRECT_MATCH;
684 (*match)[matches].name = argument[i++];
685 (*match)[matches].string = ptr + 1;
686 if (arguments - i > 0 && argument[i][0] ==
'!') {
687 (*match)[matches].logic |= SDDS_NEGATE_MATCH;
690 if (++need_operation > 0)
694 }
while (arguments > i);
695 (*match)[0].logic |= SDDS_AND;
701 label->format = NULL;
702 if ((ptr = strchr(
string,
'='))) {
704 label->format = ptr + 1;
706 label->name = string;
709void show_matches(
char *type,
MATCH_TERM *match,
long matches) {
711 fprintf(stderr,
"\n %s matching logic:\n", type);
712 for (i = 0; i < matches; i++) {
713 if (match[i].logic & SDDS_NEGATE_MATCH)
714 fprintf(stderr,
" <%s> != ", match[i].name);
716 fprintf(stderr,
" <%s> == ", match[i].name);
717 if (match[i].logic & SDDS_INDIRECT_MATCH)
718 fprintf(stderr,
"<%s>", match[i].
string);
720 fprintf(stderr,
"\"%s\"", match[i].
string);
721 if (match[i].logic & SDDS_NOCASE_COMPARE)
722 fprintf(stderr,
" (case insensitive)\n");
724 fprintf(stderr,
" (case sensitive)\n");
726 if (match[i].logic & SDDS_AND)
727 fprintf(stderr,
"&& ");
728 if (match[i].logic & SDDS_OR)
729 fprintf(stderr,
"|| ");
731 if (match[i].logic & SDDS_NEGATE_EXPRESSION)
737void show_filters(
char *type,
FILTER_TERM *filter,
long filters) {
739 fprintf(stderr,
"\n %s filtering logic:\n", type);
740 for (i = 0; i < filters; i++) {
741 if (filter[i].logic & SDDS_NEGATE_MATCH)
742 fprintf(stderr,
" !( <%s>:[%22.15e, %22.15e] ) ", filter[i].name, filter[i].lower, filter[i].upper);
744 fprintf(stderr,
" <%s>:[%22.15e, %22.15e] ", filter[i].name, filter[i].lower, filter[i].upper);
746 if (filter[i].logic & SDDS_AND)
747 fprintf(stderr,
"&& ");
748 if (filter[i].logic & SDDS_OR)
749 fprintf(stderr,
"|| ");
751 if (filter[i].logic & SDDS_NEGATE_EXPRESSION)
758 static char s[SDDS_MAXLINE];
759 char *ptr, *equation;
760 long i, code, algebraic = 0;
762 char pfix[IFPF_BUF_SIZE];
764 if (!(defi =
tmalloc(
sizeof(*defi))))
765 SDDS_Bomb(
"memory allocation failure (process_new_equation_definition)");
766 defi->name = defi->text = defi->equation = defi->udf_name =
767 defi->editSelection = defi->select = defi->exclude = NULL;
769 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
771 defi->is_parameter = 0;
772 sprintf(s,
"&column name=\"%s\", ", argument[1]);
774 case PARAMETER_BASED:
775 defi->is_parameter = 1;
776 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
779 fprintf(stderr,
"error: column or parameter must be specified for definition\n");
784 for (i = 3; i < arguments; i++) {
785 if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0) {
794 if (argument[2][0] ==
'@') {
796 equation = malloc(
sizeof(
char) * strlen(argument[2]) + 1);
797 sprintf(equation,
"@%s", argument[2]);
799 ptr = addOuterParentheses(argument[2]);
800 if2pf(pfix, ptr,
sizeof pfix);
804 fprintf(stderr,
"error: problem copying argument string\n");
809 defi->argv =
tmalloc(
sizeof(*defi->argv) * (arguments - 3));
811 defi->argv =
tmalloc(
sizeof(*defi->argv) * 1);
814 equation = argument[2];
816 defi->argv =
tmalloc(
sizeof(*defi->argv) * (arguments - 2));
818 defi->argv =
tmalloc(
sizeof(*defi->argv) * 1);
821 for (i = 3; i < arguments; i++) {
822 if (!(ptr = strchr(argument[i],
'='))) {
823 if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0)
825 fprintf(stderr,
"error: invalid definition-entry: %s\n", argument[i]);
829 switch (code =
match_string(argument[i], selectQualifier, SELECT_QUALIFIERS, 0)) {
830 case SELECT_QUALIFIER:
833 case EDITSELECTION_QUALIFIER:
836 case EXCLUDE_QUALIFIER:
846 fprintf(stderr,
"error: problem copying argument string\n");
851 strcat(s, argument[i]);
857 if (!strstr(s,
", type=")) {
858 strcat(s,
" type=\"double\", ");
864 SDDS_Bomb(
"string copying failed (process_new_equation_definition)");
869 static char s[SDDS_MAXLINE];
873 if (!(defi =
tmalloc(
sizeof(*defi))))
874 SDDS_Bomb(
"memory allocation failure (process_new_evaluate_definition)");
875 defi->name = defi->text = defi->source = NULL;
876 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
878 defi->is_parameter = 0;
879 sprintf(s,
"&column name=\"%s\", ", argument[1]);
881 case PARAMETER_BASED:
882 defi->is_parameter = 1;
883 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
886 fprintf(stderr,
"error: column or parameter must be specified for definition\n");
891 defi->name = argument[1];
892 defi->source = argument[2];
894 for (i = 3; i < arguments; i++) {
896 strcat(s, argument[i]);
898 if (!strstr(s,
", type=")) {
899 strcat(s,
" type=double, ");
903 SDDS_Bomb(
"string copying failed (process_new_evaluate_definition)");
907SCAN_DEFINITION *process_new_scan_definition(
char **argument,
long arguments) {
908 static char s[SDDS_MAXLINE];
913 if (!(defi =
tmalloc(
sizeof(*defi))))
914 SDDS_Bomb(
"memory allocation failure (process_new_scan_definition)");
915 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
917 defi->is_parameter = 0;
918 sprintf(s,
"&column name=\"%s\", ", argument[1]);
920 case PARAMETER_BASED:
921 defi->is_parameter = 1;
922 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
925 fprintf(stderr,
"error: column or parameter must be specified for scan\n");
928 defi->new_name = argument[1];
929 defi->source = argument[2];
930 defi->sscanf_string = argument[3];
932 for (i = 4; i < arguments; i++) {
933 if (!(ptr = strchr(argument[i],
'=')))
936 if (strncasecmp(argument[i],
"edit", strlen(argument[i])) == 0) {
940 strcat(s, argument[i]);
946 if (!strstr(s,
", type="))
947 strcat(s,
" type=\"double\", ");
950 SDDS_Bomb(
"unable to copy text of scan definition (process_new_scan_definition)");
954CAST_DEFINITION *process_new_cast_definition(
char **argument,
long arguments) {
957 if (!(defi =
tmalloc(
sizeof(*defi))))
958 SDDS_Bomb(
"memory allocation failure (process_new_cast_definition)");
959 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
961 defi->isParameter = 0;
963 case PARAMETER_BASED:
964 defi->isParameter = 1;
967 fprintf(stderr,
"error: column or parameter must be specified for cast\n");
970 defi->newName = argument[1];
971 defi->source = argument[2];
972 defi->newTypeName = argument[3];
973 if (strcmp(defi->newName, defi->source) == 0) {
974 fprintf(stderr,
"error: can't cast something to the same name (sddsprocess)\n");
985 sprintf(s,
"Unable to cast parameter %s to unknown type %s from column %s",
986 defi->newName, defi->newTypeName, defi->source);
990 if (defi->isParameter) {
992 defi->source, defi->newName) ||
994 SDDS_BY_NAME, defi->newName)) {
995 sprintf(s,
"Unable to cast parameter %s to type %s from column %s",
996 defi->newName, defi->newTypeName, defi->source);
1002 defi->source, defi->newName) ||
1004 SDDS_BY_NAME, defi->newName)) {
1005 sprintf(s,
"Unable to cast column %s to type %s from column %s",
1006 defi->newName, defi->newTypeName, defi->source);
1015 static char s[SDDS_MAXLINE];
1019#define NUMBERTEST_QUALIFIERS 2
1020 static char *numbertestQualifier[NUMBERTEST_QUALIFIERS] = {
1024 static unsigned long numbertestFlag[NUMBERTEST_QUALIFIERS] = {
1025 NUMSCANFILTER_INVERT,
1026 NUMSCANFILTER_STRICT,
1029 if (!(defi =
tmalloc(
sizeof(*defi))))
1030 SDDS_Bomb(
"memory allocation failure (process_new_numbertest_definition)");
1031 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
1033 defi->is_parameter = 0;
1034 sprintf(s,
"&column name=\"%s\", ", argument[1]);
1036 case PARAMETER_BASED:
1037 defi->is_parameter = 1;
1038 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
1041 fprintf(stderr,
"error: column or parameter must be specified for numbertest\n");
1044 defi->name = argument[1];
1046 for (i = 2; i < arguments; i++) {
1047 switch (j =
match_string(argument[i], numbertestQualifier, NUMBERTEST_QUALIFIERS, 0)) {
1049 fprintf(stderr,
"error: unknown qualifer to -numberTest: %s\n", argument[i]);
1053 defi->flags |= numbertestFlag[j];
1060EDIT_DEFINITION *process_new_edit_definition(
char **argument,
long arguments,
short reedit) {
1061 static char s[SDDS_MAXLINE];
1063 long i, offset, hasType;
1066 if (!(defi =
tmalloc(
sizeof(*defi))))
1067 SDDS_Bomb(
"memory allocation failure (process_new_edit_definition)");
1068 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
1070 defi->is_parameter = 0;
1071 sprintf(s,
"&column name=\"%s\", ", argument[1]);
1073 case PARAMETER_BASED:
1074 defi->is_parameter = 1;
1075 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
1078 fprintf(stderr,
"error: column or parameter must be specified for edit\n");
1081 defi->new_name = argument[1];
1083 defi->source = argument[2];
1084 defi->edit_command = argument[3];
1087 defi->source = defi->new_name;
1088 defi->edit_command = argument[2];
1091 if (arguments > offset) {
1092 defi->argv =
tmalloc(
sizeof(*defi->argv) * (arguments - offset));
1094 SDDS_Bomb(
"string array copy failed (process_new_edit_definition)");
1095 defi->argc = arguments - offset;
1101 for (i = offset; i < arguments; i++) {
1102 if (!(ptr = strchr(argument[i],
'=')))
1105 if (strcmp(argument[i],
"type") == 0)
1107 strcat(s, argument[i]);
1113 strcat(s,
" type=string &end");
1117 SDDS_Bomb(
"unable to copy text of edit definition (process_new_edit_definition)");
1121long edit_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *edit_command) {
1122 char **source_value;
1123 long target_type, target_index, source_index;
1125 static char s[SDDS_MAXLINE];
1133 fprintf(stderr,
"error: source column %s has wrong type for editing--must be string\n", source);
1138 fprintf(stderr,
"error: target column %s has wrong type for editing--must be string or character\n", target);
1152 for (i = 0; i < rows; i++) {
1153 if (!source_value[i])
1156 strcpy(s, source_value[i]);
1157 if (!edit_string(s, edit_command)) {
1158 fprintf(stderr,
"error: unable to edit source string \"%s\" to make %s\n", source_value[i], target);
1162 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s, -1)) ||
1164 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s[0], -1))) {
1179long edit_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *edit_command) {
1180 char *source_value, **ptr;
1181 long target_type, target_index, source_index;
1182 static char s[SDDS_MAXLINE];
1190 fprintf(stderr,
"error: source parameter %s has wrong type for editing--must be string\n", source);
1195 fprintf(stderr,
"error: target parameter %s has wrong type for editing--must be string or character\n", target);
1203 if (!(source_value = *ptr))
1206 strcpy(s, source_value);
1207 if (!edit_string(s, edit_command)) {
1208 fprintf(stderr,
"error: unable to edit source string \"%s\" to make %s\n", source_value, target);
1212 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) ||
1214 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s[0], -1))) {
1226 request =
tmalloc(
sizeof(*request));
1227 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
1229 request->parameter_output = 0;
1231 case PARAMETER_BASED:
1232 request->parameter_output = 1;
1235 fprintf(stderr,
"error: column or parameter must be specified for output\n");
1242 request->points = 0;
1243 request->counter = 0;
1245 if (!(request->item[0] = determine_item_name(argument, last_request, 0)))
1248 if (!(request->item[1] = determine_item_name(argument, last_request, 1)))
1251 request->item[2] = request->item[3] = NULL;
1252 request->columns = 2;
1257 request->columns = 3;
1258 if (!(request->item[2] = determine_item_name(argument, last_request, 2)))
1264 request->columns = 4;
1265 if (!(request->item[3] = determine_item_name(argument, last_request, 3)))
1271char *determine_item_name(
char **argument,
OUTPUT_REQUEST *last_request,
long index) {
1272 if (strcmp(argument[index],
".") == 0) {
1275 return (last_request->item[index]);
1277 return (argument[index]);
1281 long separate_pages,
long announce_openings,
SDDS_DATASET *SDDS_dataset) {
1286 char *mplTitle, *mplTopline;
1288 output->fp =
fopen_e(filename,
"w", 0);
1289 if (announce_openings)
1290 fprintf(stderr,
"file opened: %s\n", filename);
1291 if (!output->parameter_output) {
1293 coldef[0] = coldef[1] = coldef[2] = coldef[3] = NULL;
1301 fputs(coldef[0]->symbol ? coldef[0]->symbol : output->item[0], output->fp);
1302 if (coldef[0]->units && !
is_blank(coldef[0]->units))
1303 fprintf(output->fp,
" (%s)", coldef[0]->units);
1304 fprintf(output->fp,
"\n%s", coldef[1]->symbol ? coldef[1]->symbol : output->item[1]);
1305 if (coldef[1]->units && !
is_blank(coldef[1]->units))
1306 fprintf(output->fp,
" (%s)", coldef[1]->units);
1307 if (label_parameters) {
1308 fputc(
'\n', output->fp);
1309 for (j = 0; j < label_parameters; j++) {
1318 fprintf(output->fp,
"%s=", pardefptr->symbol ? pardefptr->symbol : label_parameter[j].name);
1320 (label_parameter[j].format ? label_parameter[j].format : pardefptr->format_string), output->fp,
1322 if (pardefptr->units) {
1323 if (isdigit(pardefptr->units[0]))
1324 fputc(
' ', output->fp);
1325 fprintf(output->fp,
"%s%s", pardefptr->units, j == label_parameters - 1 ?
"\n" :
" ");
1327 fprintf(output->fp,
"%s", j == label_parameters - 1 ?
"\n" :
" ");
1331 fprintf(output->fp,
"\n%s vs %s\n",
1332 coldef[1]->description ? coldef[1]->description : (coldef[1]->symbol ? coldef[1]->symbol : output->item[1]),
1333 coldef[0]->description ? coldef[0]->description : (coldef[0]->symbol ? coldef[0]->symbol : output->item[0]));
1337 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
1339 fprintf(output->fp,
"\n%s\n", mplTitle);
1345 pardef[0] = pardef[1] = pardef[2] = pardef[3] = NULL;
1353 fputs(pardef[0]->symbol ? pardef[0]->symbol : output->item[0], output->fp);
1354 if (pardef[0]->units && !
is_blank(pardef[0]->units))
1355 fprintf(output->fp,
" (%s)", pardef[0]->units);
1356 fprintf(output->fp,
"\n%s", pardef[1]->symbol ? pardef[1]->symbol : output->item[1]);
1357 if (pardef[1]->units && !
is_blank(pardef[1]->units))
1358 fprintf(output->fp,
" (%s)", pardef[1]->units);
1359 if (label_parameters) {
1360 fputc(
'\n', output->fp);
1361 for (j = 0; j < label_parameters; j++) {
1370 fprintf(output->fp,
"%s=", pardefptr->symbol ? pardefptr->symbol : label_parameter[j].name);
1372 (label_parameter[j].format ? label_parameter[j].format : pardefptr->format_string), output->fp,
1374 if (pardefptr->units) {
1375 if (isdigit(pardefptr->units[0]))
1376 fputc(
' ', output->fp);
1377 fprintf(output->fp,
"%s%s", pardefptr->units, j == label_parameters - 1 ?
"\n" :
" ");
1379 fprintf(output->fp,
"%s", j == label_parameters - 1 ?
"\n" :
" ");
1383 fprintf(output->fp,
"\n%s vs %s\n",
1384 pardef[1]->description ? pardef[1]->description : (pardef[1]->symbol ? pardef[1]->symbol : output->item[1]),
1385 pardef[0]->description ? pardef[0]->description : (pardef[0]->symbol ? pardef[0]->symbol : output->item[0]));
1389 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
1391 fprintf(output->fp,
"\n%s\n", mplTitle);
1397 fprintf(output->fp,
"Data extracted from SDDS file %s", SDDS_dataset->layout.filename);
1399 fprintf(output->fp,
", page %" PRId32, SDDS_dataset->page_number);
1402 SDDS_SetError(
"Unable to get value of parameter mplTopline");
1403 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
1405 fprintf(output->fp,
"%s", mplTopline);
1408 fprintf(output->fp,
"\n%-10" PRId64
"\n", SDDS_dataset->n_rows);
1414 double *result,
char **stringResult,
long warnings,
int threads) {
1415 double *data, *indepData, *weightData;
1416 long i1, i2 = 0, i2save, mode;
1418 int64_t i, n_data, count;
1419 double min, max, top, base, point1, point2;
1420 double slope, intercept, variance;
1421 long returnValue, matchfound;
1422 char **stringData, **matchData;
1424 double quartilePoint[2] = {25.0, 75.0}, quartileResult[2];
1425 double decilePoint[2] = {10.0, 90.0}, decileResult[2];
1426 double percentilePoint[2], percentileResult[2];
1431 mode = processing_ptr->mode;
1433 fprintf(stderr,
"process_column: column=%s, mode=%s\n", processing_ptr->column_name,
1434 process_column_data[mode].name);
1437 *stringResult = NULL;
1439 if (mode != PROCESS_COLUMN_COUNT)
1440 *result = processing_ptr->defaultValue;
1446 &processing_ptr->lowerLimit))
1447 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1449 &processing_ptr->upperLimit))
1450 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1453 &processing_ptr->head))
1454 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1456 &processing_ptr->tail))
1457 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1459 &processing_ptr->fhead))
1460 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1462 &processing_ptr->ftail))
1463 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1464 if (processing_ptr->offset_par) {
1465 if (
wild_match(processing_ptr->offset_par,
"%s*")) {
1466 sprintf(temp_str, processing_ptr->offset_par, processing_ptr->column_name);
1468 &processing_ptr->offset))
1469 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1471 &processing_ptr->offset))
1472 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1474 if (processing_ptr->factor_par) {
1475 if (
wild_match(processing_ptr->factor_par,
"%s*")) {
1476 sprintf(temp_str, processing_ptr->factor_par, processing_ptr->column_name);
1478 &processing_ptr->factor))
1479 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1481 &processing_ptr->factor))
1482 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1484 if ((processing_ptr->flags & PROCESSING_INVERT_OFFSET) && (processing_ptr->flags & PROCESSING_OFFSET_GIVEN))
1485 processing_ptr->offset *=-1;
1486 if ((processing_ptr->flags & PROCESSING_FACTOR_GIVEN) && (processing_ptr->flags & PROCESSING_INVERT_FACTOR))
1487 processing_ptr->factor = 1/processing_ptr->factor;
1490 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1491 indepData = weightData = NULL;
1492 stringData = matchData = NULL;
1495 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1496 if (processing_ptr->functionOf &&
1499 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1500 if (processing_ptr->functionOf &&
1502 !(stringData =
SDDS_GetColumn(Dataset, processing_ptr->functionOf)))
1503 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1506 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)) {
1507 keep =
tmalloc(
sizeof(*keep) * n_data);
1508 for (i = 0; i < n_data; i++)
1511 if (processing_ptr->flags & PROCESSING_MATCHCOLUMN_GIVEN) {
1512 if (!(matchData =
SDDS_GetColumn(Dataset, processing_ptr->match_column)))
1513 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1514 for (i = 0; i < n_data; i++)
1516 for (i = 0; i < n_data; i++) {
1517 if (
wild_match(matchData[i], processing_ptr->match_value)) {
1522 for (i = 0; i < n_data; i++)
1527 fprintf(stderr,
"Warning: no values in column %s match %s.\n",
1528 processing_ptr->match_column, processing_ptr->match_value);
1531 *result = processing_ptr->defaultValue;
1535 if (processing_ptr->flags & PROCESSING_LOLIM_GIVEN && indepData) {
1537 fprintf(stderr,
"lower limit processing: value %e\n", processing_ptr->lowerLimit);
1539 for (i = 0; i < n_data; i++)
1540 if (processing_ptr->lowerLimit > indepData[i])
1544 if (processing_ptr->flags & PROCESSING_UPLIM_GIVEN && indepData) {
1546 fprintf(stderr,
"upper limit processing: value %e\n", processing_ptr->upperLimit);
1548 for (i = 0; i < n_data; i++) {
1549 if (processing_ptr->upperLimit < indepData[i])
1551 if (isinf(indepData[i]) || isnan(indepData[i]))
1556 if (processing_ptr->flags & PROCESSING_TOPLIM_GIVEN) {
1557 for (i = 0; i < n_data; i++) {
1558 if (processing_ptr->topLimit < data[i])
1560 if (isinf(data[i]) || isnan(data[i]))
1565 if (processing_ptr->flags & PROCESSING_BOTLIM_GIVEN) {
1566 for (i = 0; i < n_data; i++)
1567 if (processing_ptr->bottomLimit > data[i])
1571 if (processing_ptr->flags & PROCESSING_HEAD_GIVEN) {
1574 fprintf(stderr,
"head processing: %ld points\n", processing_ptr->head);
1576 if (processing_ptr->head > 0) {
1578 for (i = 0; i < n_data && count < processing_ptr->head; i++)
1581 for (; i < n_data; i++)
1585 for (i = 0; i < n_data && count < -processing_ptr->head; i++)
1593 if (processing_ptr->flags & PROCESSING_FHEAD_GIVEN) {
1596 head = fabs(n_data * processing_ptr->fhead + 0.5);
1597 if (processing_ptr->fhead > 0) {
1598 for (i = 0; i < n_data && count < head; i++)
1601 for (; i < n_data; i++)
1604 for (i = 0; i < n_data && count < head; i++)
1611 if (processing_ptr->flags & PROCESSING_TAIL_GIVEN) {
1614 fprintf(stderr,
"tail processing: %ld points\n", processing_ptr->tail);
1616 if (processing_ptr->tail > 0) {
1617 for (i = n_data - 1; i >= 0 && count < processing_ptr->tail; i--)
1623 for (i = n_data - 1; i >= 0 && count < -processing_ptr->tail; i--)
1630 if (processing_ptr->flags & PROCESSING_FTAIL_GIVEN) {
1633 tail = fabs(processing_ptr->ftail * n_data + 0.5);
1634 if (processing_ptr->ftail > 0) {
1635 for (i = n_data - 1; i >= 0 && count < tail; i--)
1641 for (i = n_data - 1; i >= 0 && count < tail; i--)
1650 for (i = j = 0; i < n_data; i++) {
1655 indepData[j] = indepData[i];
1657 free(stringData[j]);
1658 stringData[j] = stringData[i];
1659 stringData[i] = NULL;
1662 weightData[j] = weightData[i];
1669 fprintf(stderr,
"%" PRId64
" points kept\n", n_data);
1681 fprintf(stderr,
"warning: no matches found");
1682 if (mode != PROCESS_COLUMN_COUNT) {
1683 *result = processing_ptr->defaultValue;
1684 *stringResult = NULL;
1688 *stringResult = NULL;
1693 if (processing_ptr->flags & PROCESSING_OFFSET_GIVEN) {
1695 fprintf(stderr,
"offsetting by %f\n", processing_ptr->offset);
1697 for (i = 0; i < n_data; i++)
1698 data[i] += processing_ptr->offset;
1701 if (processing_ptr->flags & PROCESSING_FACTOR_GIVEN) {
1703 fprintf(stderr,
"multiplying by %f\n", processing_ptr->factor);
1705 for (i = 0; i < n_data; i++)
1706 data[i] *= processing_ptr->factor;
1710 fprintf(stderr,
"data points:\n");
1711 for (i = 0; i < n_data; i++)
1712 fprintf(stderr,
"%e%c", data[i], (i + 1) % 8 == 0 ?
'\n' :
' ');
1713 fputc(
'\n', stderr);
1719 case PROCESS_COLUMN_ZEROCROSSING:
1720 for (i = 0; i < n_data - 1; i++) {
1723 if ((data[i] < 0 && data[i + 1] >= 0) || (data[i] > 0 && data[i + 1] <= 0))
1726 if (i != n_data - 1) {
1729 *result = indepData[i];
1731 *result = indepData[i] + (indepData[i + 1] - indepData[i]) / (data[i + 1] - data[i]) * (-data[i]);
1734 *stringResult = stringData[i];
1735 stringData[i] = NULL;
1740 case PROCESS_COLUMN_MEAN:
1746 case PROCESS_COLUMN_RMS:
1752 case PROCESS_COLUMN_SUM:
1755 for (i = sum = 0; i < n_data; i++)
1756 sum += data[i] * weightData[i];
1761 case PROCESS_COLUMN_PRODUCT:
1764 for (i = 0; i < n_data; i++)
1765 product *= data[i] * weightData[i];
1769 for (i = 0; i < n_data; i++)
1774 case PROCESS_COLUMN_STAND_DEV:
1780 case PROCESS_COLUMN_SIGMA:
1785 *result /= sqrt(1.0 * n_data);
1787 case PROCESS_COLUMN_MAD:
1793 case PROCESS_COLUMN_SIGNEDSMALLEST:
1795 for (i = 1; i < n_data; i++)
1796 if (fabs(data[imin]) > fabs(data[i]))
1798 *result = data[imin];
1799 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1801 *result = indepData[imin];
1803 *stringResult = stringData[imin];
1804 stringData[imin] = NULL;
1808 case PROCESS_COLUMN_SIGNEDLARGEST:
1810 for (i = 1; i < n_data; i++)
1811 if (fabs(data[imax]) < fabs(data[i]))
1813 *result = data[imax];
1814 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1816 *result = indepData[imax];
1818 *stringResult = stringData[imax];
1819 stringData[imax] = NULL;
1823 case PROCESS_COLUMN_SMALLEST:
1824 case PROCESS_COLUMN_LARGEST:
1825 for (i = 0; i < n_data; i++)
1826 data[i] = fabs(data[i]);
1831 case PROCESS_COLUMN_SMALLEST:
1832 *result = data[i1 = imin];
1834 case PROCESS_COLUMN_LARGEST:
1835 *result = data[i1 = imax];
1838 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1840 *result = indepData[i1];
1842 *stringResult = stringData[i1];
1843 stringData[i1] = NULL;
1848 case PROCESS_COLUMN_MINIMUM:
1849 case PROCESS_COLUMN_MAXIMUM:
1850 case PROCESS_COLUMN_SPREAD:
1857 case PROCESS_COLUMN_MINIMUM:
1861 case PROCESS_COLUMN_MAXIMUM:
1865 case PROCESS_COLUMN_SMALLEST:
1866 if (fabs(min) < fabs(max)) {
1868 *result = fabs(min);
1871 *result = fabs(max);
1874 case PROCESS_COLUMN_LARGEST:
1875 if (fabs(min) > fabs(max)) {
1877 *result = fabs(min);
1880 *result = fabs(max);
1883 case PROCESS_COLUMN_SPREAD:
1884 *result = max - min;
1887 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1889 *result = indepData[i1];
1891 *stringResult = stringData[i1];
1892 stringData[i1] = NULL;
1897 case PROCESS_COLUMN_FIRST:
1900 case PROCESS_COLUMN_LAST:
1901 *result = data[n_data - 1];
1903 case PROCESS_COLUMN_COUNT:
1906 case PROCESS_COLUMN_MEDIAN:
1910 case PROCESS_COLUMN_MODE:
1911 if (processing_ptr->flags & PROCESSING_BINSIZE_GIVEN) {
1912 if (
computeMode(result, data, n_data, processing_ptr->binSize, 0) <= 0)
1914 }
else if (
computeMode(result, data, n_data, 0, 100) <= 0)
1917 case PROCESS_COLUMN_BASELEVEL:
1918 case PROCESS_COLUMN_TOPLEVEL:
1919 case PROCESS_COLUMN_AMPLITUDE:
1920 case PROCESS_COLUMN_RISETIME:
1921 case PROCESS_COLUMN_FALLTIME:
1922 case PROCESS_COLUMN_FWHA:
1923 case PROCESS_COLUMN_FWTA:
1924 case PROCESS_COLUMN_CENTER:
1925 case PROCESS_COLUMN_FWHM:
1926 case PROCESS_COLUMN_FWTM:
1931 if ((top - base) < 0.75 * (data[imax] - base))
1934 case PROCESS_COLUMN_BASELEVEL:
1937 case PROCESS_COLUMN_TOPLEVEL:
1940 case PROCESS_COLUMN_AMPLITUDE:
1941 *result = top - base;
1943 case PROCESS_COLUMN_RISETIME:
1944 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1945 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, indepData, &point2)) < 0)
1948 *result = point2 - point1;
1950 case PROCESS_COLUMN_FALLTIME:
1951 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.9, -1, indepData, &point1)) < 0 ||
1952 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0)
1955 *result = point2 - point1;
1957 case PROCESS_COLUMN_FWHA:
1958 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1959 (i2 = i2save =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1960 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1962 fprintf(stderr,
"warning: couldn't find crossing point for FWHA of %s\n",
1963 processing_ptr->column_name);
1964 fprintf(stderr,
"top, base = %e, %e min, max = %e, %e\n", top, base,
1965 data[imin], data[imax]);
1967 fprintf(stderr,
"#1: %ld, (%e, %e)\n",
1968 i1, indepData[i1], data[i1]);
1970 fprintf(stderr,
"#2: %ld, (%e, %e)\n",
1971 i2save, indepData[i2save], data[i2save]);
1973 fprintf(stderr,
"#2a: %ld, (%e, %e)\n",
1974 i2, indepData[i2], data[i2]);
1976 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1977 (i2 = i2save =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1978 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1981 *result = point2 - point1;
1984 *result = point2 - point1;
1986 case PROCESS_COLUMN_FWTA:
1987 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1988 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1989 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0) {
1990 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1991 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1992 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0) {
1995 *result = point2 - point1;
1998 *result = point2 - point1;
2000 case PROCESS_COLUMN_FWHM:
2001 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.5, 1, indepData, &point1)) < 0 ||
2002 (i2 = i2save =
findCrossingPoint(i1, data, n_data, top * 0.9, -1, NULL, NULL)) < 0 ||
2003 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.5, -1, indepData, &point2)) < 0) {
2005 fprintf(stderr,
"warning: couldn't find crossing point for FWHM of %s\n",
2006 processing_ptr->column_name);
2007 fprintf(stderr,
"top, base = %e, %e\n", top, base);
2009 fprintf(stderr,
"#1: %ld, (%e, %e)\n",
2010 i1, indepData[i1], data[i1]);
2012 fprintf(stderr,
"#2: %ld, (%e, %e)\n",
2013 i2save, indepData[i2save], data[i2save]);
2015 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.5, 1, indepData, &point1)) < 0 ||
2016 (i2 = i2save =
findCrossingPoint(i1, data, n_data, top * 0.9, 1, NULL, NULL)) < 0 ||
2017 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.5, -1, indepData, &point2)) < 0) {
2020 *result = point2 - point1;
2023 *result = point2 - point1;
2025 case PROCESS_COLUMN_FWTM:
2026 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.1, 1, indepData, &point1)) < 0 ||
2028 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.1, -1, indepData, &point2)) < 0) {
2029 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.1, 1, indepData, &point1)) < 0 ||
2031 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.1, -1, indepData, &point2)) < 0) {
2034 *result = point2 - point1;
2037 *result = point2 - point1;
2039 case PROCESS_COLUMN_CENTER:
2040 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
2041 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
2042 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
2043 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
2044 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
2045 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
2048 *result = (point1 + point2) / 2;
2051 *result = (point1 + point2) / 2;
2056 case PROCESS_COLUMN_SLOPE:
2057 case PROCESS_COLUMN_INTERCEPT:
2058 case PROCESS_COLUMN_LFSD:
2063 case PROCESS_COLUMN_SLOPE:
2066 case PROCESS_COLUMN_INTERCEPT:
2067 *result = intercept;
2069 case PROCESS_COLUMN_LFSD:
2070 *result = sqrt(variance);
2074 case PROCESS_COLUMN_INTEGRAL:
2077 case PROCESS_COLUMN_GMINTEGRAL:
2078 GillMillerIntegration1(indepData, data, n_data, result);
2080 case PROCESS_COLUMN_QRANGE:
2084 *result = quartileResult[1] - quartileResult[0];
2086 case PROCESS_COLUMN_DRANGE:
2090 *result = decileResult[1] - decileResult[0];
2092 case PROCESS_COLUMN_PERCENTILE:
2093 if (!
compute_percentiles(percentileResult, &processing_ptr->percentileLevel, 1, data, n_data))
2096 *result = percentileResult[0];
2100 case PROCESS_COLUMN_PRANGE:
2101 percentilePoint[1] = 50 + processing_ptr->percentileLevel / 2.0;
2102 percentilePoint[0] = 50 - processing_ptr->percentileLevel / 2.0;
2106 *result = percentileResult[1] - percentileResult[0];
2110 case PROCESS_COLUMN_CORRELATION:
2127 for (i = 0; i < n_data; i++)
2129 free(stringData[i]);
2134 fprintf(stderr,
"warning: processing of %s with mode %s failed--value %e returned\n",
2135 processing_ptr->column_name,
2136 process_column_name[processing_ptr->mode],
2137 processing_ptr->defaultValue);
2138 *result = processing_ptr->defaultValue;
2139 *stringResult = NULL;
2145 char **data, *result, **matchData;
2146 long mode, matchfound;
2147 int64_t i, n_data, count;
2150 mode = processing_ptr->mode;
2157 if (!(data =
SDDS_GetColumn(Dataset, processing_ptr->column_name)))
2158 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
2161 if (processing_ptr->flags & (PROCESSING_TAIL_GIVEN | PROCESSING_HEAD_GIVEN |
2162 PROCESSING_FTAIL_GIVEN | PROCESSING_FHEAD_GIVEN |
2163 PROCESSING_MATCHCOLUMN_GIVEN)) {
2164 keep =
tmalloc(
sizeof(*keep) * n_data);
2165 for (i = 0; i < n_data; i++)
2169 if (processing_ptr->flags & PROCESSING_MATCHCOLUMN_GIVEN) {
2170 if (!(matchData =
SDDS_GetColumn(Dataset, processing_ptr->match_column)))
2171 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
2172 for (i = 0; i < n_data; i++)
2174 for (i = 0; i < n_data; i++) {
2175 if (
wild_match(matchData[i], processing_ptr->match_value)) {
2180 for (i = 0; i < n_data; i++)
2185 fprintf(stderr,
"Warning: no values in column %s match %s.\n",
2186 processing_ptr->match_column, processing_ptr->match_value);
2188 for (i = 0; i < n_data; i++)
2195 if (processing_ptr->flags & PROCESSING_HEAD_GIVEN) {
2197 for (i = 0; i < n_data && count < processing_ptr->head; i++)
2200 for (; i < n_data; i++)
2204 if (processing_ptr->flags & PROCESSING_FHEAD_GIVEN) {
2207 head = n_data * processing_ptr->fhead + 0.5;
2208 for (i = 0; i < n_data && count < head; i++)
2211 for (; i < n_data; i++)
2215 if (processing_ptr->flags & PROCESSING_TAIL_GIVEN) {
2217 for (i = n_data - 1; i >= 0 && count < processing_ptr->tail; i--)
2224 if (processing_ptr->flags & PROCESSING_FTAIL_GIVEN) {
2227 tail = processing_ptr->ftail * n_data + 0.5;
2228 for (i = n_data - 1; i >= 0 && count < tail; i--)
2237 for (i = j = 0; i < n_data; i++) {
2249 case PROCESS_COLUMN_FIRST:
2252 case PROCESS_COLUMN_LAST:
2256 SDDS_Bomb(
"invalid processing mode for string data (sddsprocess)");
2262 fprintf(stderr,
"warning, no matches found.");
2265 for (i = 0; i < n_data; i++)
2273static char *PROCESSING_USAGE =
2274 " [-process=<column-name>,<analysis-name>,<result-name>[,description=<string>][,symbol=<string>][,weightBy=<column-name>]\n\
2275 [,match=<column-name>,value=<match-string>]\n\
2276 [,head=<number>][,tail=<number>][fhead=<fraction>][ftail=<fraction>][,topLimit=<value>][,bottomLimit=<value>]\n\
2277 [,functionOf=<column-name>[,lowerLimit=<value>|@parameter_name][,upperLimit=<value>|@<parameter_name>][,position]]\n\
2278 [,offset=<value>][,factor=<value>][match=<column-name>,value=<string>][,overwrite],[default=<value>]]\n\
2279 [,binSize=<value>]\n";
2283 char *lower_str = NULL, *upper_str = NULL;
2284 char *head_str=NULL, *tail_str=NULL, *fhead_str=NULL, *ftail_str=NULL, *offset_str=NULL, *factor_str=NULL;
2285 char *invert_str=NULL;
2288 bomb(
"invalid -process syntax--wrong number of arguments", PROCESSING_USAGE);
2290 if (process_column_name[0] == NULL) {
2292 for (i = 0; i < N_PROCESS_COLUMN_MODES; i++)
2293 process_column_name[i] = process_column_data[i].name;
2295 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;
2296 if ((pd->mode =
match_string(argument[1], process_column_name, N_PROCESS_COLUMN_MODES, 0)) < 0) {
2297 fprintf(stderr,
"invalid -process mode: %s\n", argument[1]);
2298 show_process_modes(stderr);
2305 pd->defaultValue = DBL_MAX;
2307 "functionof",
SDDS_STRING, &pd->functionOf, 1, PROCESSING_FUNCOF_GIVEN,
2308 "weightby",
SDDS_STRING, &pd->weightBy, 1, PROCESSING_WEIGHT_GIVEN,
2309 "description",
SDDS_STRING, &pd->description, 1, PROCESSING_DESCRIP_GIVEN,
2310 "symbol",
SDDS_STRING, &pd->symbol, 1, PROCESSING_SYMBOL_GIVEN,
2311 "toplimit",
SDDS_DOUBLE, &pd->topLimit, 1, PROCESSING_TOPLIM_GIVEN,
2312 "bottomlimit",
SDDS_DOUBLE, &pd->bottomLimit, 1, PROCESSING_BOTLIM_GIVEN,
2313 "lowerlimit",
SDDS_STRING, &lower_str, 1, PROCESSING_LOLIM_GIVEN,
2314 "upperlimit",
SDDS_STRING, &upper_str, 1, PROCESSING_UPLIM_GIVEN,
2315 "head",
SDDS_STRING, &head_str, 1, PROCESSING_HEAD_GIVEN,
2316 "tail",
SDDS_STRING, &tail_str, 1, PROCESSING_TAIL_GIVEN,
2317 "fhead",
SDDS_STRING, &fhead_str, 1, PROCESSING_FHEAD_GIVEN,
2318 "ftail",
SDDS_STRING, &ftail_str, 1, PROCESSING_FTAIL_GIVEN,
2319 "position", -1, NULL, 0, PROCESSING_POSITION_GIVEN,
2320 "offset",
SDDS_STRING, &offset_str, 1, PROCESSING_OFFSET_GIVEN,
2321 "factor",
SDDS_STRING, &factor_str, 1, PROCESSING_FACTOR_GIVEN,
2322 "percentlevel",
SDDS_DOUBLE, &pd->percentileLevel, 1, PROCESSING_PERCLEVEL_GIVEN,
2323 "binsize",
SDDS_DOUBLE, &pd->binSize, 1, PROCESSING_BINSIZE_GIVEN,
2324 "match",
SDDS_STRING, &pd->match_column, 1, PROCESSING_MATCHCOLUMN_GIVEN,
2325 "value",
SDDS_STRING, &pd->match_value, 1, PROCESSING_MATCHVALUE_GIVEN,
2326 "overwrite", -1, NULL, 0, PROCESSING_OVERWRITE_GIVEN,
2328 "default",
SDDS_DOUBLE, &pd->defaultValue, 1, PROCESSING_DEFAULTVALUE_GIVEN,
2330 bomb(
"invalid -process syntax", PROCESSING_USAGE);
2333 pd->flags |= PROCESSING_INVERT_OFFSET;
2335 pd->flags |= PROCESSING_INVERT_FACTOR;
2337 pd->flags |= PROCESSING_INVERT_OFFSET;
2338 pd->flags |= PROCESSING_INVERT_FACTOR;
2340 fprintf(stdout,
"Warning, invalid invert %s provided for process.\n", invert_str);
2348 }
else if (!
get_double(&pd->lowerLimit, lower_str)) {
2349 bomb(
"invalid lower limit provided for -process option", PROCESSING_USAGE);
2356 }
else if (!
get_double(&pd->upperLimit, upper_str)) {
2357 bomb(
"invalid upper limit provided for -process option", PROCESSING_USAGE);
2364 }
else if (!
get_int(&pd->head, head_str)) {
2365 bomb(
"invalid head provided for -process option", PROCESSING_USAGE);
2372 }
else if (!
get_int(&pd->tail, tail_str)) {
2373 bomb(
"invalid tail provided for -process option", PROCESSING_USAGE);
2380 }
else if (!
get_double(&pd->fhead, fhead_str)) {
2381 bomb(
"invalid fhead provided for -process option", PROCESSING_USAGE);
2388 }
else if (!
get_double(&pd->ftail, ftail_str)) {
2389 bomb(
"invalid ftail provided for -process option", PROCESSING_USAGE);
2399 }
else if (!
get_double(&pd->offset, offset_str)) {
2400 bomb(
"invalid offset provided for -process option", PROCESSING_USAGE);
2410 }
else if (!
get_double(&pd->factor, factor_str)) {
2411 bomb(
"invalid factor provided for -process option", PROCESSING_USAGE);
2415 if (pd->flags & PROCESSING_BINSIZE_GIVEN && pd->binSize <= 0)
2416 SDDS_Bomb(
"invalid -process syntax---bin size is zero");
2417 if (pd->flags & PROCESSING_FACTOR_GIVEN && pd->factor == 0)
2418 SDDS_Bomb(
"invalid -process syntax---factor field is zero");
2419 if ((process_column_data[pd->mode].flags & PROCMODE_FUNCOF_REQUIRED) &&
2420 !(pd->flags & PROCESSING_FUNCOF_GIVEN))
2421 SDDS_Bomb(
"invalid -process syntax---functionOf option required for given mode");
2422 if (pd->flags & PROCESSING_WEIGHT_GIVEN &&
2423 !(process_column_data[pd->mode].flags & PROCMODE_WEIGHT_OK))
2424 SDDS_Bomb(
"invalid -process specification---weightBy option not available for given mode");
2425 if (pd->flags & PROCESSING_POSITION_GIVEN) {
2426 if (!(pd->flags & PROCESSING_FUNCOF_GIVEN))
2427 SDDS_Bomb(
"invalid -process syntax---functionOf required with position option");
2428 if (!(process_column_data[pd->mode].flags & PROCMODE_POSITION_OK))
2429 SDDS_Bomb(
"invalid -process syntax---position option not permitted for given mode");
2431 if (pd->flags & PROCESSING_LOLIM_GIVEN && pd->flags & PROCESSING_UPLIM_GIVEN &&
2432 pd->lowerLimit > pd->upperLimit)
2433 SDDS_Bomb(
"invalid -process syntax---lowerLimit>upperLimit");
2434 if (pd->flags & PROCESSING_TOPLIM_GIVEN && pd->flags & PROCESSING_BOTLIM_GIVEN && pd->topLimit < pd->bottomLimit)
2435 SDDS_Bomb(
"invalid -process syntax---bottomLimit>topLimit");
2436 if (pd->flags & PROCESSING_HEAD_GIVEN && !pd->head_par && pd->head == 0)
2437 SDDS_Bomb(
"invalid -process syntax---head=0");
2438 if (pd->flags & PROCESSING_FHEAD_GIVEN && !pd->fhead_par && pd->fhead == 0)
2439 SDDS_Bomb(
"invalid -process syntax---fhead=0");
2440 if (pd->flags & PROCESSING_TAIL_GIVEN && !pd->tail_par && pd->tail == 0)
2441 SDDS_Bomb(
"invalid -process syntax---tail=0");
2442 if (pd->flags & PROCESSING_FTAIL_GIVEN && !pd->ftail_par && pd->ftail == 0)
2443 SDDS_Bomb(
"invalid -process syntax---ftail=0");
2444 if (pd->flags & (PROCESSING_LOLIM_GIVEN | PROCESSING_UPLIM_GIVEN) && !(pd->flags & PROCESSING_FUNCOF_GIVEN))
2445 SDDS_Bomb(
"invalid -process syntax---must give -functionOf with limit options");
2446 if (pd->mode == PROCESS_COLUMN_PERCENTILE && !(pd->flags & PROCESSING_PERCLEVEL_GIVEN))
2447 SDDS_Bomb(
"invalid -process syntax---must give percentLevel with percentile processing");
2448 if (pd->flags & PROCESSING_MATCHCOLUMN_GIVEN && !(pd->flags & PROCESSING_MATCHVALUE_GIVEN))
2449 SDDS_Bomb(
"invalid -process syntax---must give value for match column");
2468 long processing_definitions,
2470 static char s[SDDS_MAXLINE], t[SDDS_MAXLINE];
2471 long i, index, index1;
2485 for (i = 0; i < processing_definitions; i++) {
2486 if ((index =
SDDS_GetColumnIndex(SDDS_dataset, processing_definition[i]->column_name)) < 0) {
2487 sprintf(s,
"column %s does not exist", processing_definition[i]->column_name);
2491 switch (processing_definition[i]->type =
2492 processing_definition[i]->outputType =
2495 if (!(process_column_data[processing_definition[i]->mode].flags & PROCMODE_STRING_OK)) {
2496 fprintf(stderr,
"column %s has the wrong type for processing (sddsprocess)\n",
2497 processing_definition[i]->column_name);
2513 fprintf(stderr,
"column %s has the wrong type for processing (sddsprocess)\n",
2514 processing_definition[i]->column_name);
2518 if (processing_definition[i]->flags & PROCESSING_DESCRIP_GIVEN) {
2519 if (strstr(processing_definition[i]->description,
"%s")) {
2520 sprintf(s, processing_definition[i]->description,
2521 processing_definition[i]->column_name);
2522 free(processing_definition[i]->description);
2526 sprintf(s,
"%s%s", process_column_data[processing_definition[i]->mode].description,
2527 processing_definition[i]->column_name);
2530 if (strstr(processing_definition[i]->parameter_name,
"%s")) {
2531 sprintf(s, processing_definition[i]->parameter_name, processing_definition[i]->column_name);
2532 free(processing_definition[i]->parameter_name);
2535 if (processing_definition[i]->flags & PROCESSING_WEIGHT_GIVEN &&
2537 sprintf(s,
"column %s does not exist", processing_definition[i]->weightBy);
2541 if (processing_definition[i]->flags & PROCESSING_MATCHCOLUMN_GIVEN &&
2543 sprintf(s,
"column %s does not exist", processing_definition[i]->match_column);
2547 if (processing_definition[i]->flags & PROCESSING_FUNCOF_GIVEN) {
2548 if ((index1 =
SDDS_GetColumnIndex(SDDS_dataset, processing_definition[i]->functionOf)) < 0) {
2549 sprintf(s,
"column %s does not exist", processing_definition[i]->functionOf);
2553 if (processing_definition[i]->flags & PROCESSING_POSITION_GIVEN &&
2555 !(process_column_data[processing_definition[i]->mode].flags & PROCMODE_STRINGPOS_OK)) {
2556 sprintf(s,
"Can't have string column for position data with %s processing",
2557 process_column_data[processing_definition[i]->mode].name);
2562 if (processing_definition[i]->outputType !=
SDDS_STRING)
2563 sprintf(s,
"¶meter name=\"%s\", type=double, description=\"%s\", ",
2564 processing_definition[i]->parameter_name, processing_definition[i]->description);
2566 sprintf(s,
"¶meter name=\"%s\", type=string, description=\"%s\", ",
2567 processing_definition[i]->parameter_name, processing_definition[i]->description);
2568 if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_FUNCOF_UNITS ||
2569 (processing_definition[i]->flags & PROCESSING_FUNCOF_GIVEN &&
2570 processing_definition[i]->flags & PROCESSING_POSITION_GIVEN)) {
2571 if (SDDS_dataset->layout.column_definition[index1].units) {
2572 sprintf(t,
"units=\"%s\", ", SDDS_dataset->layout.column_definition[index1].units);
2575 }
else if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_YoX_UNITS) {
2579 sprintf(t,
"units=\"(%s)/(%s)\", ",
2580 SDDS_dataset->layout.column_definition[index].units,
2581 SDDS_dataset->layout.column_definition[index1].units);
2583 sprintf(t,
"units=\"%s\", ",
2584 SDDS_dataset->layout.column_definition[index].units);
2586 sprintf(t,
"units=\"1/(%s)\", ",
2587 SDDS_dataset->layout.column_definition[index1].units);
2589 }
else if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_YtX_UNITS) {
2593 sprintf(t,
"units=\"%s*%s\", ",
2594 SDDS_dataset->layout.column_definition[index].units,
2595 SDDS_dataset->layout.column_definition[index1].units);
2597 sprintf(t,
"units=\"%s\", ",
2598 SDDS_dataset->layout.column_definition[index].units);
2600 sprintf(t,
"units=\"%s\", ",
2601 SDDS_dataset->layout.column_definition[index1].units);
2603 }
else if (process_column_data[processing_definition[i]->mode].flags & PROCMODE_Y_UNITS) {
2604 if (SDDS_dataset->layout.column_definition[index].units) {
2605 sprintf(t,
"units=\"%s\", ", SDDS_dataset->layout.column_definition[index].units);
2609 if (processing_definition[i]->symbol) {
2610 sprintf(t,
"symbol=\"%s\", ", processing_definition[i]->symbol);
2615 processing_definition[i]->flags & PROCESSING_OVERWRITE_GIVEN) {
2616 pardef1.name = pardef1.symbol = pardef1.units = pardef1.description =
2617 pardef1.format_string = pardef1.fixed_value = NULL;
2620 SDDS_PARAMETER_FIELDS, s)) {
2637 processing_definition[i]->memory_number = pardef->memory_number;
2646 request =
tmalloc(
sizeof(*request));
2649 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
2651 request->is_parameter = 0;
2653 case PARAMETER_BASED:
2654 request->is_parameter = 1;
2662 request->name = argument[0];
2663 request->new_units = argument[1];
2664 request->old_units = argument[2];
2665 if (sscanf(argument[3],
"%lf", &request->factor) != 1)
2673char *substituteString(
char *
template,
char *pattern,
char *replacement) {
2674 char *ptr, *ptr0, *buffer, c;
2675 long count = 0, patternLength, newLength;
2677 if (!(patternLength = strlen(pattern)))
2679 if (!(ptr =
template))
2681 while ((ptr = strstr(ptr, pattern))) {
2683 ptr += patternLength;
2685 if ((newLength = strlen(
template) - count * patternLength + count * strlen(replacement) + 1) <= 0 ||
2686 !(buffer = malloc(newLength *
sizeof(*buffer))))
2691 while (ptr0 && *ptr0 && (ptr = strstr(ptr0, pattern))) {
2694 strcat(buffer, ptr0);
2695 strcat(buffer, replacement);
2697 ptr0 = ptr = ptr + patternLength;
2700 strcat(buffer, ptr0);
2705 long names, idef, jdef, is_parameter, templates, itemplate, definitionType, i, j;
2706 char **name, **wildcardName, *editSelection, **target, **excludeWildcardName = NULL;
2709 char editBuffer[SDDS_MAXLINE];
2710 long maxTemplates = 10, requireWildcard;
2713 short isPointer, isBase;
2722 if (!(targetData =
SDDS_Malloc(
sizeof(*targetData) * maxTemplates)))
2725 for (idef = 0; idef < *definitions; idef++) {
2726 editSelection = NULL;
2727 requireWildcard = 0;
2730 for (i = 0; i < maxTemplates; i++) {
2731 targetData[i].isPointer = 0;
2733 switch (definitionType = (*definition)[idef].type) {
2734 case IS_EQUATION_DEFINITION:
2752 case IS_PRINT_DEFINITION:
2754 wildcardName = &((
PRINT_DEFINITION *)(*definition)[idef].structure)->select;
2755 excludeWildcardName = &((
PRINT_DEFINITION *)(*definition)[idef].structure)->exclude;
2756 is_parameter = ((
PRINT_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2757 editSelection = ((
PRINT_DEFINITION *)(*definition)[idef].structure)->editSelection;
2765 if (((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources + 2 > maxTemplates) {
2766 maxTemplates = 2 * ((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources + 2;
2767 if (!(targetData =
SDDS_Realloc(targetData,
sizeof(*targetData) * maxTemplates)))
2770 for (i = 0; i < ((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources; i++) {
2771 targetData[i + 2].isPointer = 1;
2773 targetData[i + 2].isBase = 1;
2774 targetData[i + 2].arraySize =
sizeof(*(((
PRINT_DEFINITION *)(*definition)[idef].structure)->source)) *
2777 targetData[i + 2].isBase = 0;
2778 targetData[i + 2].index = i;
2783 templates = ((
PRINT_DEFINITION *)(*definition)[idef].structure)->sources + 2;
2785 case IS_SCAN_DEFINITION:
2787 wildcardName = &((
SCAN_DEFINITION *)(*definition)[idef].structure)->source;
2788 requireWildcard = 1;
2789 is_parameter = ((
SCAN_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2801 case IS_EDIT_DEFINITION:
2803 wildcardName = &((
EDIT_DEFINITION *)(*definition)[idef].structure)->source;
2804 requireWildcard = 1;
2805 is_parameter = ((
EDIT_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2817 case IS_PROCESSING_DEFINITION:
2820 requireWildcard = 1;
2842 case IS_CONVERSION_DEFINITION:
2845 requireWildcard = 1;
2852 case IS_SYSTEM_DEFINITION:
2855 requireWildcard = 1;
2856 is_parameter = ((
SYSTEM_DEFINITION *)(*definition)[idef].structure)->is_parameter;
2868 case IS_CAST_DEFINITION:
2870 wildcardName = &((
CAST_DEFINITION *)(*definition)[idef].structure)->source;
2871 requireWildcard = 1;
2872 is_parameter = ((
CAST_DEFINITION *)(*definition)[idef].structure)->isParameter;
2882 wildcardName = NULL;
2886 if ((!wildcardName || !*wildcardName) || (requireWildcard && !
has_wildcards(*wildcardName))) {
2887 if (wildcardName && *wildcardName)
2893 if ((excludeWildcardName == NULL) || (*excludeWildcardName == NULL)) {
2895 *wildcardName, SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2896 fprintf(stderr,
"Error (expandDefinitions): unable to find match to parameter name %s\n", *wildcardName);
2901 if ((names =
SDDS_MatchParameters(SDDS_dataset, &name, SDDS_MATCH_EXCLUDE_STRING, FIND_ANY_TYPE,
2902 *wildcardName, *excludeWildcardName,
2903 SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2904 fprintf(stderr,
"Error (expandDefinitions): unable to find match to parameter name %s\n", *wildcardName);
2910 if ((excludeWildcardName == NULL) || (*excludeWildcardName == NULL)) {
2911 if ((names =
SDDS_MatchColumns(SDDS_dataset, &name, SDDS_MATCH_STRING, FIND_ANY_TYPE,
2912 *wildcardName, SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2913 fprintf(stderr,
"Error (expandDefinitions): unable to find match to column name %s\n", *wildcardName);
2918 if ((names =
SDDS_MatchColumns(SDDS_dataset, &name, SDDS_MATCH_EXCLUDE_STRING, FIND_ANY_TYPE,
2919 *wildcardName, *excludeWildcardName,
2920 SDDS_AND | SDDS_1_PREVIOUS)) <= 0) {
2921 fprintf(stderr,
"Error (expandDefinitions): unable to find match to column name %s\n", *wildcardName);
2929 *definition =
SDDS_Realloc(*definition,
sizeof(**definition) * (*definitions - 1 + names));
2930 for (jdef = *definitions - 1; jdef > idef; jdef--) {
2931 (*definition)[jdef + names - 1].structure = (*definition)[jdef].structure;
2932 (*definition)[jdef + names - 1].type = (*definition)[jdef].type;
2934 for (jdef = names - 1; jdef >= 0; jdef--) {
2936 if (!(defStruct = (*definition)[idef + jdef].structure = calloc(1, structSize)))
2937 SDDS_Bomb(
"memory allocation failure (expandDefinitions)");
2938 memcpy((
char *)defStruct, (
char *)(*definition)[idef].structure, structSize);
2940 defStruct = (*definition)[idef + jdef].structure;
2941 (*definition)[idef + jdef].type = definitionType;
2942 for (itemplate = 0; itemplate < templates; itemplate++) {
2943 if (targetData[itemplate].isPointer) {
2945 if (targetData[itemplate].isBase) {
2946 *(
char ***)((
char *)defStruct + targetData[itemplate].offset) =
2949 ptr = *(
char ***)((
char *)defStruct + targetData[itemplate].offset);
2950 target = ptr + targetData[itemplate].index;
2952 target = (
char **)((
char *)defStruct + targetData[itemplate].offset);
2954 substituteString(targetData[itemplate].
template,
"%s", name[jdef])) &&
2955 targetData[itemplate].
template) {
2956 fputs(
"Error: problem doing pattern substitution (expandDefinitions)\n", stderr);
2957 fprintf(stderr,
"template is \"%s\", instance is \"%s\"\n",
2958 targetData[itemplate].
template, name[jdef]);
2963 *definitions += names - 1;
2965 for (j = 0; j < names; j++)
2972long scan_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *format,
2973 char *edit_command) {
2974 char **source_value, char_value, *sourcePtr;
2975 long target_type, target_index, source_index;
2978 double double_value;
2979 int64_t long64_value;
2982 static char s[SDDS_MAXLINE];
2990 fprintf(stderr,
"error: source column %s has wrong type for scanning--must be string\n", source);
3005 for (i = 0; i < rows; i++) {
3006 sourcePtr = source_value[i];
3007 if (!source_value[i]) {
3013 }
else if (edit_command && strlen(edit_command)) {
3014 strncpy(s, source_value[i], SDDS_MAXLINE - 1);
3016 if (!edit_string(s, edit_command)) {
3017 fprintf(stderr,
"error: unable to preedit source string \"%s\" to scan into %s\n", source_value[i], target);
3021 switch (target_type) {
3023 if (sscanf(sourcePtr, format, &double_value) != 1) {
3024 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
3027 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, double_value, -1)) {
3033 if (sscanf(sourcePtr, format, &float_value) != 1) {
3034 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
3037 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, float_value, -1)) {
3043 if (sscanf(sourcePtr, format, &long64_value) != 1) {
3044 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
3047 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, long64_value, -1)) {
3053 if (sscanf(sourcePtr, format, &long_value) != 1) {
3054 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
3057 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, long_value, -1)) {
3063 if (sscanf(sourcePtr, format, &short_value) != 1) {
3064 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
3067 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, short_value, -1)) {
3073 if (sscanf(sourcePtr, format, &char_value) != 1) {
3074 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
3077 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, char_value, -1)) {
3083 if (sscanf(sourcePtr, format, s) != 1) {
3084 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\n", sourcePtr, target);
3087 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s, -1)) {
3093 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (scan_column_value)");
3100long scan_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source,
char *format,
3101 char *edit_command) {
3102 char *source_value, **ptr, char_value;
3103 long target_type, target_index, source_index;
3105 double double_value;
3106 int64_t long64_value;
3109 static char s[SDDS_MAXLINE];
3117 fprintf(stderr,
"error: source parameter %s has wrong type for scanning--must be string\n", source);
3126 source_value = *ptr;
3127 if (!source_value) {
3132 }
else if (edit_command) {
3133 strncpy(s, source_value, SDDS_MAXLINE - 1);
3134 if (!edit_string(s, edit_command)) {
3135 fprintf(stderr,
"error: unable to preedit source string \"%s\" for scanning into %s\n", source_value, target);
3141 switch (target_type) {
3143 if (sscanf(source_value, format, &double_value) != 1) {
3144 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
3145 fputs(format, stderr);
3146 fputc(
'\n', stderr);
3149 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, double_value, -1)) {
3155 if (sscanf(source_value, format, &float_value) != 1) {
3156 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
3157 fputs(format, stderr);
3158 fputc(
'\n', stderr);
3161 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, float_value, -1)) {
3167 if (sscanf(source_value, format, &long64_value) != 1) {
3168 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
3169 fputs(format, stderr);
3170 fputc(
'\n', stderr);
3173 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, long64_value, -1)) {
3179 if (sscanf(source_value, format, &long_value) != 1) {
3180 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
3181 fputs(format, stderr);
3182 fputc(
'\n', stderr);
3185 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, long_value, -1)) {
3191 if (sscanf(source_value, format, &short_value) != 1) {
3192 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
3193 fputs(format, stderr);
3194 fputc(
'\n', stderr);
3197 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, short_value, -1)) {
3203 if (sscanf(source_value, format, &char_value) != 1) {
3204 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
3205 fputs(format, stderr);
3206 fputc(
'\n', stderr);
3209 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, char_value, -1)) {
3215 if (sscanf(source_value, format, s) != 1) {
3216 fprintf(stderr,
"error: unable to scan source string \"%s\" to make %s\nsscanf string was:", source_value, target);
3217 fputs(format, stderr);
3218 fputc(
'\n', stderr);
3221 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) {
3227 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (scan_parameter_value)");
3234PRINT_DEFINITION *process_new_print_definition(
char **argument,
long arguments) {
3235 static char s[SDDS_MAXLINE];
3237 long i, hasType, code;
3241 if (!(defi =
tmalloc(
sizeof(*defi))))
3242 SDDS_Bomb(
"memory allocation failure (process_new_print_definition)");
3243 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3245 defi->is_parameter = 0;
3246 sprintf(s,
"&column name=\"%s\", ", argument[1]);
3248 case PARAMETER_BASED:
3249 defi->is_parameter = 1;
3250 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
3253 fprintf(stderr,
"error: column or parameter must be specified for print\n");
3256 defi->new_name = argument[1];
3257 defi->source = NULL;
3259 defi->printf_string = argument[2];
3261 for (i = 3; i < arguments; i++) {
3262 if (!(ptr = strchr(argument[i],
'='))) {
3264 defi->source =
trealloc(defi->source,
sizeof(*defi->source) * (defi->sources + 1));
3265 defi->source[defi->sources++] = argument[i];
3269 for (; i < arguments; i++) {
3271 if (!(ptr = strchr(argument[i],
'='))) {
3272 fprintf(stderr,
"error: invalid definition-entry: %s\n", argument[i]);
3276 switch (code =
match_string(argument[i], selectQualifier, SELECT_QUALIFIERS, 0)) {
3277 case SELECT_QUALIFIER:
3278 defi->select = ptr + 1;
3280 case EDITSELECTION_QUALIFIER:
3281 defi->editSelection = ptr + 1;
3283 case EXCLUDE_QUALIFIER:
3284 defi->exclude = ptr + 1;
3293 strcat(s, argument[i]);
3294 if (strcmp(argument[i],
"type") == 0)
3302 strcat(s,
" type=string &end");
3306 SDDS_Bomb(
"unable to copy text of print definition (process_new_print_definition)");
3310long print_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char **source,
long sources,
char *format) {
3311 char *print_pos, **ptr, *fptr1, *fptr2 = NULL, *fptr3, *cptr;
3312 long source_type, source_index, target_index, target_type;
3314 static char s[SDDS_MAXLINE];
3315 static char *info = NULL;
3317 if (!info && !(info = malloc(
sizeof(
double) * 2)))
3318 SDDS_Bomb(
"Allocation failure in print_parameter_value");
3326 fprintf(stderr,
"error: target parameter %s has wrong type for printing--must be string or character\n", target);
3333 for (i = 0; i < sources; i++) {
3334 print_pos = s + strlen(s);
3338 if ((cptr = strrchr(source[i],
'.'))) {
3345 if (strcmp(cptr + 1,
"type") == 0) {
3347 return bombre(
"internal error: type of data-type information is not long", NULL, 0);
3353 if (source_type ==
SDDS_STRING && *(
char **)info == NULL)
3361 ptr = (
char **)info;
3369 if (!(fptr2 = strchr(fptr3,
'%'))) {
3370 fprintf(stderr,
"Error: invalid sprintf string\n");
3373 if (*(fptr2 + 1) ==
'%')
3375 else if (fptr2 != format && *(fptr2 - 1) ==
'\\')
3384 if ((fptr2 = strchr(fptr2 + 1,
'%')) && i != (sources - 1))
3388 switch (source_type) {
3390 sprintf(print_pos, fptr1, *(
double *)ptr);
3393 sprintf(print_pos, fptr1, *(
float *)ptr);
3396 sprintf(print_pos, fptr1, *(int64_t *)ptr);
3399 sprintf(print_pos, fptr1, *(uint64_t *)ptr);
3402 sprintf(print_pos, fptr1, *(int32_t *)ptr);
3405 sprintf(print_pos, fptr1, *(uint32_t *)ptr);
3408 sprintf(print_pos, fptr1, *(
short *)ptr);
3411 sprintf(print_pos, fptr1, *(
unsigned short *)ptr);
3414 sprintf(print_pos, fptr1, *(
char *)ptr);
3417 sprintf(print_pos, fptr1, *(
char **)ptr);
3421 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (print_parameter_value)");
3424 if (!(fptr1 = fptr2))
3431 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) ||
3433 !
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s[0], -1))) {
3440long print_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char **source,
long sources,
char *format) {
3441 char *print_pos, **ptr, *fptr1, *fptr2 = NULL, *fptr3, *cptr;
3442 long target_index, target_type;
3445 static char s[SDDS_MAXLINE];
3446 static long firstCall = 1;
3448 long source_type, source_index;
3449 short is_parameter, is_column, use_info;
3461 fprintf(stderr,
"error: target column %s has wrong type for printing--must be string or character\n", target);
3470 if (!(sourceData =
SDDS_Malloc(
sizeof(*sourceData) * sources)))
3471 SDDS_Bomb(
"Memory allocation failure doing printing.");
3472 for (i = 0; i < sources; i++) {
3473 print_pos = s + strlen(s);
3474 sourceData[i].is_column = sourceData[i].is_parameter =
3475 sourceData[i].use_info = 0;
3477 ((sourceData[i].source_type =
SDDS_GetColumnType(SDDS_dataset, sourceData[i].source_index)) >= 0))
3478 sourceData[i].is_column = 1;
3481 sourceData[i].is_parameter = 1;
3482 else if ((cptr = strrchr(source[i],
'.'))) {
3484 if ((sourceData[i].source_type =
3486 sourceData[i].is_parameter = 1;
3487 else if ((sourceData[i].source_type =
3489 sourceData[i].is_column = 1;
3494 if (strcmp(cptr + 1,
"type") == 0) {
3495 if (sourceData[i].source_type !=
SDDS_LONG)
3496 return bombre(
"internal error: type of data-type information is not long", NULL, 0);
3501 sourceData[i].use_info = 1;
3502 if (sourceData[i].source_type ==
SDDS_STRING && sourceData[i].info == NULL)
3505 sprintf(s,
"Unable to find print source %s.", source[i]);
3512 for (j = 0; j < rows; j++) {
3517 for (i = 0; i < sources; i++) {
3518 print_pos = s + strlen(s);
3519 if (sourceData[i].is_column && !sourceData[i].use_info) {
3520 if (!(ptr =
SDDS_GetValue(SDDS_dataset, source[i], j, NULL))) {
3527 fprintf(stderr,
"error: -print option for column %s uses source %s which is defined\n",
3529 fprintf(stderr,
"as both a column and a parameter\n");
3532 fprintf(stderr,
"warning: -print option for column %s uses source %s which is defined\n",
3534 fprintf(stderr,
"as both a column and a parameter---column values are used!\n");
3538 if (sourceData[i].is_parameter && !sourceData[i].use_info) {
3540 SDDS_SetError(
"Unable to get print source parameter value.");
3545 if (sourceData[i].use_info)
3546 ptr = &sourceData[i].info;
3549 if (!(fptr2 = strchr(fptr3,
'%'))) {
3550 fprintf(stderr,
"Error: invalid sprintf string\n");
3553 if (*(fptr2 + 1) ==
'%')
3555 else if (fptr2 != format && *(fptr2 - 1) ==
'\\')
3564 if ((fptr2 = strchr(fptr2 + 1,
'%')) && i != (sources - 1))
3568 switch (sourceData[i].source_type) {
3570 sprintf(print_pos, fptr1, *(
double *)ptr);
3573 sprintf(print_pos, fptr1, *(
float *)ptr);
3576 sprintf(print_pos, fptr1, *(int64_t *)ptr);
3579 sprintf(print_pos, fptr1, *(uint64_t *)ptr);
3582 sprintf(print_pos, fptr1, *(int32_t *)ptr);
3585 sprintf(print_pos, fptr1, *(uint32_t *)ptr);
3588 sprintf(print_pos, fptr1, *(
short *)ptr);
3591 sprintf(print_pos, fptr1, *(
unsigned short *)ptr);
3594 sprintf(print_pos, fptr1, *(
char *)ptr);
3597 sprintf(print_pos, fptr1, *(
char **)ptr);
3598 if (!sourceData[i].use_info)
3602 SDDS_Bomb(
"error: unknown type encountered--this shouldn't happen (print_column_value)");
3605 if (!sourceData[i].use_info)
3607 if (!(fptr1 = fptr2))
3612 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, target_index, s, -1)) ||
3614 !
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, j, target_index, s[0],
3625FORMAT_DEFINITION *process_new_format_definition(
char **argument,
long arguments) {
3627 unsigned long flags;
3629 if (!(defi =
tmalloc(
sizeof(*defi))))
3630 SDDS_Bomb(
"memory allocation failure (process_new_format_definition)");
3631 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3633 defi->is_parameter = 0;
3635 case PARAMETER_BASED:
3636 defi->is_parameter = 1;
3639 fprintf(stderr,
"error: column or parameter must be specified for format\n");
3642 defi->target = argument[1];
3643 defi->source = argument[2];
3644 defi->stringFormat = NULL;
3645 defi->doubleFormat = NULL;
3646 defi->longFormat = NULL;
3651 "stringformat",
SDDS_STRING, &defi->stringFormat, 1, 0,
3652 "doubleformat",
SDDS_STRING, &defi->doubleFormat, 1, 0,
3653 "longformat",
SDDS_STRING, &defi->longFormat, 1, 0,
3655 bomb(
"invalid -format syntax", NULL);
3661 static char *buffer = NULL;
3662 static long bufferSize = 0;
3663 char *ptr, *doubleFormat, *longFormat, *stringFormat;
3664 long target_index, source_index, bufferRequired;
3671 fprintf(stderr,
"error: target parameter %s has wrong type for formatting--must be string\n", definition->source);
3675 fprintf(stderr,
"error: target parameter %s has wrong type for formatting--must be string\n", definition->target);
3682 if ((bufferRequired = 2 * strlen(ptr) + 1024) > bufferSize) {
3684 bufferSize = bufferRequired;
3685 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * bufferRequired))) {
3691 if (!(doubleFormat = definition->doubleFormat))
3692 doubleFormat =
"%21.15e";
3693 if (!(longFormat = definition->longFormat))
3695 if (!(stringFormat = definition->stringFormat))
3696 stringFormat =
"%s";
3698 if (!reformatString(buffer, bufferSize, ptr, stringFormat, doubleFormat, longFormat))
3701 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, buffer, -1)) {
3708long reformatString(
char *buffer,
long bufferSize,
char *
string,
char *stringFormat,
3709 char *doubleFormat,
char *longFormat) {
3710 long bufferUseLimit, length, lValue;
3712 char *bufferPosition, *token0, *token1;
3714 bufferPosition = buffer;
3716 bufferUseLimit = bufferSize * 0.9 + 1;
3719 while ((token0 = strtok(token1,
" "))) {
3723 if (sscanf(token0,
"%ld", &lValue) == 1)
3724 sprintf(bufferPosition, longFormat, lValue);
3726 fprintf(stderr,
"Error: problem formatting token %s as long integer.\n", token0);
3730 if (sscanf(token0,
"%lf", &dValue) == 1)
3731 sprintf(bufferPosition, doubleFormat, dValue);
3733 fprintf(stderr,
"Error: problem formatting token %s as double.\n", token0);
3737 sprintf(bufferPosition, stringFormat, token0);
3738 if ((length = strlen(buffer)) > bufferUseLimit) {
3739 fprintf(stderr,
"Error: format buffer overflow (sddsprocess).\n");
3742 bufferPosition = buffer + length;
3743 *bufferPosition =
' ';
3744 *++bufferPosition = 0;
3746 if ((--bufferPosition) >= buffer)
3747 *bufferPosition = 0;
3752 static char *buffer = NULL;
3753 static long bufferSize = 0;
3754 char **ptr, *longFormat, *doubleFormat, *stringFormat;
3755 long source_index, target_index, bufferRequired;
3764 fprintf(stderr,
"error: target column %s has wrong type for formatting--must be string\n", definition->source);
3768 fprintf(stderr,
"error: target column %s has wrong type for formatting--must be string\n", definition->target);
3780 if (!(doubleFormat = definition->doubleFormat))
3781 doubleFormat =
"%21.15e";
3782 if (!(longFormat = definition->longFormat))
3784 if (!(stringFormat = definition->stringFormat))
3785 stringFormat =
"%s";
3787 for (row = 0; row < rows; row++) {
3788 if ((bufferRequired = 2 * strlen(ptr[row]) + 1024) > bufferSize) {
3789 bufferSize = bufferRequired;
3790 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * bufferRequired))) {
3795 if (!reformatString(buffer, bufferSize, ptr[row], stringFormat, doubleFormat, longFormat)) {
3796 fprintf(stderr,
"Error: problem formatting string >%s< (sddsprocess).\n",
3800 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, row, target_index, buffer, -1)) {
3808void add_definition(
DEFINITION **definition,
long *definitions,
void *structure,
long type) {
3809 *definition =
trealloc(*definition,
sizeof(**definition) * (*definitions + 1));
3810 (*definition)[*definitions].structure = structure;
3811 (*definition)[*definitions].type = type;
3817 int i, algebraic = 0;
3818 char pfix[IFPF_BUF_SIZE];
3820 if (!(defi =
tmalloc(
sizeof(*defi))))
3821 SDDS_Bomb(
"memory allocation failure (process_new_print_definition)");
3822 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3824 defi->is_parameter = 0;
3826 case PARAMETER_BASED:
3827 defi->is_parameter = 1;
3830 fprintf(stderr,
"error: column or parameter must be specified for rpntest\n");
3835 for (i = 2; i < arguments; i++) {
3836 if (strncmp(argument[i],
"autostop", strlen(argument[i])) == 0)
3838 else if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0)
3845 ptr = addOuterParentheses(argument[1]);
3846 if2pf(pfix, ptr,
sizeof pfix);
3849 fprintf(stderr,
"error: problem copying argument string\n");
3853 defi->expression = argument[1];
3859 int i, algebraic = 0;
3860 char pfix[IFPF_BUF_SIZE];
3864 if (!(defi =
tmalloc(
sizeof(*defi))))
3865 SDDS_Bomb(
"memory allocation failure (process_new_rpnexpression_definition)");
3868 for (i = 1; i < arguments; i++) {
3869 if (strncmp(argument[i],
"repeat", strlen(argument[i])) == 0)
3871 else if (strncmp(argument[i],
"algebraic", strlen(argument[i])) == 0)
3878 ptr = addOuterParentheses(argument[0]);
3879 if2pf(pfix, ptr,
sizeof pfix);
3882 fprintf(stderr,
"error: problem copying argument string\n");
3886 defi->expression = argument[0];
3890CLIP_DEFINITION *process_new_clip_definition(
char **argument,
long arguments) {
3893 if (arguments < 2 || arguments > 3)
3895 if (!(defi =
tmalloc(
sizeof(*defi))))
3896 SDDS_Bomb(
"memory allocation failure (process_new_clip_definition)");
3897 if (sscanf(argument[0],
"%" SCNd64, &defi->head) != 1 ||
3898 sscanf(argument[1],
"%" SCNd64, &defi->tail) != 1 ||
3899 defi->head < 0 || defi->tail < 0)
3903 if (arguments == 3) {
3904 if (strncmp(argument[2],
"invert", strlen(argument[2])) != 0)
3910FCLIP_DEFINITION *process_new_fclip_definition(
char **argument,
long arguments) {
3913 if (arguments < 2 || arguments > 3)
3915 if (!(defi =
tmalloc(
sizeof(*defi))))
3916 SDDS_Bomb(
"memory allocation failure (process_new_clip_definition)");
3917 if (sscanf(argument[0],
"%le", &defi->fhead) != 1 ||
3918 sscanf(argument[1],
"%le", &defi->ftail) != 1 ||
3919 defi->fhead < 0 || defi->ftail < 0)
3923 if (arguments == 3) {
3924 if (strncmp(argument[2],
"invert", strlen(argument[2])) != 0)
3930SPARSE_DEFINITION *process_new_sparse_definition(
char **argument,
long arguments) {
3933 if (arguments < 1 || arguments > 2)
3935 if (!(defi =
tmalloc(
sizeof(*defi))))
3936 SDDS_Bomb(
"memory allocation failure (process_new_sparse_definition)");
3937 if (sscanf(argument[0],
"%" SCNd64, &defi->interval) != 1 || defi->interval <= 0 ||
3938 (arguments == 2 && (sscanf(argument[1],
"%" SCNd64, &defi->offset) != 1 || defi->offset < 0)))
3943SAMPLE_DEFINITION *process_new_sample_definition(
char **argument,
long arguments) {
3948 if (!(defi =
tmalloc(
sizeof(*defi))))
3949 SDDS_Bomb(
"memory allocation failure (process_new_sample_definition)");
3950 if (sscanf(argument[0],
"%lf", &defi->fraction) != 1)
3955SYSTEM_DEFINITION *process_new_system_definition(
char **argument,
long arguments) {
3956 static char s[SDDS_MAXLINE];
3961 if (!(defi =
tmalloc(
sizeof(*defi))))
3962 SDDS_Bomb(
"memory allocation failure (process_new_system_definition)");
3963 switch (
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, 0)) {
3965 defi->is_parameter = 0;
3966 sprintf(s,
"&column name=\"%s\", ", argument[1]);
3968 case PARAMETER_BASED:
3969 defi->is_parameter = 1;
3970 sprintf(s,
"¶meter name=\"%s\", ", argument[1]);
3973 fprintf(stderr,
"error: column or parameter must be specified for system\n");
3976 defi->new_name = argument[1];
3977 defi->source = argument[2];
3978 for (i = 3; i < arguments; i++) {
3979 if (!(ptr = strchr(argument[i],
'=')))
3982 if (strcmp(argument[i],
"type") == 0)
3984 strcat(s, argument[i]);
3989 strcat(s,
" type=string &end");
3991 SDDS_Bomb(
"unable to copy text of system definition (process_new_system_definition)");
3995long system_column_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source) {
3996 char **source_value, *command;
3998 long target_index, source_index;
3999 static char s[SDDS_MAXLINE];
4007 fprintf(stderr,
"error: source column %s has wrong type for system call--must be string\n", source);
4011 fprintf(stderr,
"error: target column %s has wrong type for system call--must be string\n", target);
4025 for (i = 0; i < rows; i++) {
4027 if ((command = source_value[i]) && !run_on_pipe(command, s, SDDS_MAXLINE)) {
4028 sprintf(s,
"Problem with subprocess call (system_column_value)---command was\n%s\n",
4033 if (!
SDDS_SetRowValues(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i, target_index, s, -1)) {
4041long system_parameter_value(
SDDS_DATASET *SDDS_dataset,
char *target,
char *source) {
4042 char *command, **ptr;
4043 long target_index, source_index;
4044 static char s[SDDS_MAXLINE];
4052 fprintf(stderr,
"error: source parameter %s has wrong type for system call--must be string\n", source);
4056 fprintf(stderr,
"error: target parameter %s has wrong type for system call--must be string\n", target);
4065 if ((command = *ptr) && !run_on_pipe(command, s, SDDS_MAXLINE)) {
4066 sprintf(s,
"Problem with subprocess call (system_parameter_value)---command was\n%s\n",
4071 if (!
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, target_index, s, -1)) {
4081long run_on_pipe(
char *command,
char *buffer,
long buffer_length) {
4085 if (!(fp = popen(command,
"r")))
4088 if (!fgets(buffer, buffer_length, fp)) {
4092 if (buffer[(length = strlen(buffer)) - 1] ==
'\n')
4093 buffer[length - 1] = 0;
4099long SDDS_RedefineParameterCL(
SDDS_DATASET *SDDS_dataset,
char *parameter,
char **argv,
long argc) {
4100 char *value, *keyword;
4103 for (i = 0; i < argc; i++) {
4105 if (!(value = strchr(argv[i],
'='))) {
4106 fprintf(stderr,
"error: missing = in qualifier string for redefine: %s\n", argv[i]);
4112 fprintf(stderr,
"Problem redefining %s for %s\n",
4113 keyword, parameter);
4123long SDDS_RedefineColumnCL(
SDDS_DATASET *SDDS_dataset,
char *column,
char **argv,
long argc) {
4124 char *value, *keyword;
4127 for (i = 0; i < argc; i++) {
4129 if (!(value = strchr(argv[i],
'='))) {
4130 fprintf(stderr,
"error: missing = in qualifier string for redefine: %s\n", argv[i]);
4136 fprintf(stderr,
"Problem redefining %s for %s\n",
4146long add_sddsfile_arguments(SCANNED_ARG **scanned,
int argc) {
4147 long iarg, datacode, index, argc_got;
4150 static char *choice[2] = {
"column",
"parameter"};
4151 char *dataname, *filename, **argv_got;
4152 SCANNED_ARG *sa_got;
4157 for (iarg = 0; iarg < argc; iarg++) {
4158 if (!((*scanned)[iarg].arg_type == OPTION) ||
4159 strcmp((*scanned)[iarg].list[0],
"getargs") != 0 ||
4160 (*scanned)[iarg].n_items != 3 ||
4161 !(dataname = strchr((*scanned)[iarg].list[2],
'=')) || (*dataname++ = 0) ||
4162 ((datacode =
match_string((*scanned)[iarg].list[2], choice, 2, 0)) < 0))
4164 filename = (*scanned)[iarg].list[1];
4169 fprintf(stderr,
"error: %s %s not found in file %s--can't process -getargs request\n",
4170 choice[datacode], dataname, filename);
4176 fprintf(stderr,
"error: %s %s from file %s does not have string type--can't use for -getargs\n",
4177 choice[datacode], dataname, filename);
4191 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
4192 argv_got =
trealloc(argv_got,
sizeof(*argv_got) * (rows + argc_got));
4193 for (j = 0; j < rows; j++) {
4195 argv_got[argc_got + j] = column[j];
4205 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
4206 argv_got =
trealloc(argv_got,
sizeof(*argv_got) * (argc_got + 1));
4207 argv_got[argc_got] = parameter;
4215 argc_got =
scanargsg(&sa_got, argc_got, argv_got);
4216 *scanned =
trealloc(*scanned,
sizeof(**scanned) * (argc + argc_got));
4218 for (j = argc - 1; j > iarg; j--)
4219 (*scanned)[j + argc_got - 1] = (*scanned)[j];
4220 for (j = 0; j < argc_got; j++)
4221 (*scanned)[j + iarg] = sa_got[j];
4222 argc += argc_got - 1;
4223 iarg += argc_got - 1;
4228long ParameterScansAsNumber(
SDDS_DATASET *dataset,
char *name,
short invert) {
4232 fprintf(stderr,
"Error: parameter %s nonexistent or not string type---can't use with -numberTest\n",
4241 if (sscanf(*ptr,
"%lf", &value) != 1) {
4250 char **source_value, **target_value;
4251 long target_index, source_index, size;
4253 long source_type, target_type;
4258 sprintf(s,
"Unable to cast %s to %s--column not found", cast->source,
4266 sprintf(s,
"source column %s has wrong type for casting--must be number\n",
4275 sprintf(s,
"target column %s has wrong type for casting--must be number\n",
4296 for (i = 0; i < rows; i++) {
4298 (
void *)((
char *)target_value + size * i))) {
4308 int32_t targetIndex, sourceIndex;
4309 static char s[SDDS_MAXLINE];
4317 sprintf(s,
"error: source parameter %s has wrong type for casting--must be number\n",
4324 fprintf(stderr,
"error: target parameter %s has wrong type for casting--must be number\n",
4335 SDDS_BY_INDEX | SDDS_PASS_BY_VALUE,
4336 targetIndex, doubleValue, -1)) {
4343char *addOuterParentheses(
char *arg) {
4345 ptr =
tmalloc(
sizeof(*ptr) * (strlen(arg) + 2));
4346 sprintf(ptr,
"(%s)", arg);
4350void GillMillerIntegration1(
double *indepData,
double *data,
long n_data,
double *result) {
4352 integral =
tmalloc(
sizeof(*integral) * n_data);
4354 *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.
#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.