117 int64_t i, matches, arguments, data_class;
118 int64_t need_name, need_operation;
119 char *ptr, **argument, *token;
123 *column_match = *parameter_match = NULL;
126 while ((token =
get_token_t(option_string,
" "))) {
130 argument =
trealloc(argument,
sizeof(*argument) * (arguments + 1));
132 while ((argument[arguments] =
get_token_t(token,
","))) {
134 argument =
trealloc(argument,
sizeof(*argument) * (arguments + 1));
138 switch (data_class =
match_string(argument[0], data_class_keyword, DATA_CLASS_KEYWORDS, UNIQUE_MATCH)) {
141 SDDS_SetError(
"Only one column-based match request is allowed (process_match_request)");
145 case PARAMETER_BASED:
146 if (*parameter_match) {
147 SDDS_SetError(
"Only one parameter-based match request is allowed (process_match_request)");
152 sprintf(s,
"Unrecognized keyword for match-type: %s\nToken was: %s\nspecify column or parameter (process_match_request)", argument[0], t);
161 if (is_logic_character(argument[i][0])) {
168 switch (argument[i][0]) {
170 if (match[matches].logic & SDDS_AND || match[matches].logic & SDDS_OR || match[matches].logic & SDDS_NEGATE_EXPRESSION)
172 match[matches].logic |= SDDS_AND;
175 if (match[matches].logic & SDDS_AND || match[matches].logic & SDDS_OR || match[matches].logic & SDDS_NEGATE_EXPRESSION)
177 match[matches].logic |= SDDS_OR;
180 if (!(match[matches].logic & SDDS_AND || match[matches].logic & SDDS_OR) || match[matches].logic & SDDS_NEGATE_EXPRESSION)
182 match[matches].logic |= SDDS_NEGATE_EXPRESSION;
184 }
while (++i < arguments && is_logic_character(argument[i][0]));
189 }
else if (need_operation > 0)
193 if (is_logic_character(argument[i][0]))
195 if (arguments - i < 1)
197 match =
trealloc(match,
sizeof(*match) * (matches + 1));
198 if (!(ptr = strchr(argument[i],
'=')))
201 match[matches].name = argument[i++];
202 match[matches].string = ptr + 1;
203 match[matches].logic = 0;
204 match[matches].last = 1;
206 match[matches - 1].last = 0;
207 if (arguments - i > 0 && argument[i][0] ==
'!') {
208 match[matches].logic = SDDS_NEGATE_MATCH;
211 if (++need_operation > 0)
215 }
while (arguments > i);
216 match[0].logic |= SDDS_AND;
217 if (data_class == COLUMN_BASED)
218 *column_match = match;
220 *parameter_match = match;
294int32_t
SDDS_ReadIntoMplTable(TABLE *mpl_data,
char *file, int64_t sample_interval, int32_t mpl_flags,
char *SDDS_tags) {
297 int64_t i, new_points, n_rows;
299 char *xname, *yname, *sxname, *syname, *option_string, *ptr;
303 char s[SDDS_MAXLINE];
308 xname = yname = sxname = syname = NULL;
309 xdef = ydef = sxdef = sydef = NULL;
310 xpdef = ypdef = sxpdef = sypdef = titledef = toplinedef = NULL;
317 layout = &SDDS_dataset.layout;
318 if (SDDS_dataset.layout.n_columns < 1 && SDDS_dataset.layout.n_parameters < 1)
336 xname = yname = sxname = syname = option_string = NULL;
337 xdef = ydef = sxdef = sydef = NULL;
338 xpdef = ypdef = sxpdef = sypdef = NULL;
345 if ((yname = strchr(xname,
'+'))) {
347 while ((option_string = strchr(ptr,
','))) {
348 if (option_string != ptr && *(option_string - 1) ==
'\\')
349 ptr = option_string + 1;
351 *option_string++ = 0;
356 if ((sxname = strchr(yname,
'+'))) {
358 if ((syname = strchr(sxname,
'+'))) {
374 if (!xname || !yname) {
375 xname = yname = NULL;
380 if (xname && yname) {
390 if (!xname || !yname) {
394 for (i = 0; i < layout->n_columns; i++) {
397 xname = layout->column_definition[i].name;
399 yname = layout->column_definition[i].name;
404 if (sxname && !syname) {
410 if (!xname || !yname)
414 fprintf(stderr,
"error: column (or parameter) %s does not exist or is non-numeric\n", xname);
421 fprintf(stderr,
"error: column %s does not exist or is non-numeric\n", yname);
426 fprintf(stderr,
"error: column %s does not exist or is non-numeric\n", sxname);
431 fprintf(stderr,
"error: column %s does not exist or is non-numeric\n", syname);
435 if (xdef->symbol && !(mpl_flags & SDDS_NOCOMPRESS_NAMES))
437 if (ydef->symbol && !(mpl_flags & SDDS_NOCOMPRESS_NAMES))
439 if (sxdef && sxdef->symbol && !(mpl_flags & SDDS_NOCOMPRESS_NAMES))
441 if (sydef && sydef->symbol && !(mpl_flags & SDDS_NOCOMPRESS_NAMES))
445 sprintf(s,
"%s (%s)", xdef->symbol ? xdef->symbol : xdef->name, xdef->units);
447 sprintf(s,
"%s", xdef->symbol ? xdef->symbol : xdef->name);
450 sprintf(s,
"%s (%s)", ydef->symbol ? ydef->symbol : ydef->name, ydef->units);
452 sprintf(s,
"%s", ydef->symbol ? ydef->symbol : ydef->name);
454 toplinedef = titledef = NULL;
460 if (layout->description)
471 sprintf(s,
"%s vs %s", ydef->description ? ydef->description : (ydef->symbol ? ydef->symbol : yname), xdef->description ? xdef->description : (xdef->symbol ? xdef->symbol : xname));
473 sprintf(s,
"%s vs %s : %s", ydef->description ? ydef->description : (ydef->symbol ? ydef->symbol : yname), xdef->description ? xdef->description : (xdef->symbol ? xdef->symbol : xname), option_string);
478 fprintf(stderr,
"error: parameter %s does not exist or is non-numeric\n", yname);
483 fprintf(stderr,
"error: parameter %s does not exist or is non-numeric\n", sxname);
488 fprintf(stderr,
"error: parameter %s does not exist or is non-numeric\n", syname);
494 sprintf(s,
"%s (%s)", xpdef->symbol ?
delete_chars(xpdef->symbol,
" ") : xpdef->name, xpdef->units);
496 sprintf(s,
"%s", xpdef->symbol ?
delete_chars(xpdef->symbol,
" ") : xpdef->name);
499 sprintf(s,
"%s (%s)", ypdef->symbol ?
delete_chars(ypdef->symbol,
" ") : ypdef->name, ypdef->units);
501 sprintf(s,
"%s", ypdef->symbol ?
delete_chars(ypdef->symbol,
" ") : ypdef->name);
503 toplinedef = titledef = NULL;
509 if (layout->description)
520 sprintf(s,
"%s vs %s", ypdef->description ? ypdef->description : (ypdef->symbol ? ypdef->symbol : yname), xpdef->description ? xpdef->description : (xpdef->symbol ? xpdef->symbol : xname));
522 sprintf(s,
"%s vs %s : %s", ypdef->description ? ypdef->description : (ypdef->symbol ? ypdef->symbol : yname), xpdef->description ? xpdef->description : (xpdef->symbol ? xpdef->symbol : xname), option_string);
527 mpl_data->c1 = mpl_data->c2 = mpl_data->s1 = mpl_data->s2 = NULL;
528 mpl_data->n_data = 0;
529 mpl_data->flags = (sxname ? SIGMA_X_PRESENT : 0) + (syname ? SIGMA_Y_PRESENT : 0);
531 column_match = parameter_match = NULL;
535 if (!SDDS_dataset.n_rows && xdef)
539 if (parameter_match) {
544 fprintf(stderr,
"error: unknown or numeric parameter %s given for match\n", parameter_match[i].name);
554 sprintf(s,
"%c", *pc);
556 accept =
SDDS_Logic(accept,
wild_match(s, parameter_match[i].
string), parameter_match[i].logic);
557 }
while (!parameter_match[i].last);
573 if (
SDDS_MatchRowsOfInterest(&SDDS_dataset, column_match[i].name, column_match[i].
string, column_match[i].logic) < 0) {
577 }
while (!column_match[i].last);
583 if (!(new_points = ceil((1.0 * n_rows) / sample_interval)))
589 if (!(mpl_data->c1 =
SDDS_Realloc(mpl_data->c1,
sizeof(*mpl_data->c1) * (mpl_data->n_data + new_points))) ||
590 !(mpl_data->c2 =
SDDS_Realloc(mpl_data->c2,
sizeof(*mpl_data->c2) * (mpl_data->n_data + new_points))) ||
591 !(mpl_data->s1 =
SDDS_Realloc(mpl_data->s1,
sizeof(*mpl_data->s1) * (mpl_data->n_data + new_points))) || !(mpl_data->s2 =
SDDS_Realloc(mpl_data->s2,
sizeof(*mpl_data->s2) * (mpl_data->n_data + new_points)))) {
592 SDDS_SetError(
"Allocation failure creating mpl-compatible structure");
596 for (i = 0; i < new_points; i++)
597 mpl_data->c1[i + mpl_data->n_data] = mpl_data->c2[i + mpl_data->n_data] = mpl_data->s1[i + mpl_data->n_data] = mpl_data->s2[i + mpl_data->n_data] = 0;
601 sprintf(s,
"Sampling problem: %" PRId64
" rows created, %" PRId64
" expected", i, new_points);
608 sprintf(s,
"Sampling problem: %" PRId64
" rows created, %" PRId64
" expected", i, new_points);
616 sprintf(s,
"Sampling problem: %" PRId64
" rows created, %" PRId64
" expected", i, new_points);
625 sprintf(s,
"Sampling problem: %" PRId64
" rows created, %" PRId64
" expected", i, new_points);
651 mpl_data->n_data += new_points;
815 char *mplSDDSOutput = NULL;
816 int32_t mplSDDS_datamode = SDDS_BINARY, mplSDDS_disable = 1;
817 int32_t sx_index, sy_index;
820 fprintf(stderr,
"error: NULL mpl TABLE passed (SDDS_WriteMplTable)\n");
824 fprintf(stderr,
"error: NULL filename passed (SDDS_WriteMplTable)\n");
827 if (!mplSDDSOutput) {
828 if (!(mplSDDSOutput = getenv(
"mplSDDSOutput")))
831 if (mplSDDSOutput[0]) {
832 if (strstr(mplSDDSOutput,
"enable"))
834 if (strstr(mplSDDSOutput,
"ascii"))
835 mplSDDS_datamode = SDDS_ASCII;
843 buffer =
SDDS_Malloc(
sizeof(*file) * (strlen(file) + 2));
844 sprintf(buffer,
"%s~", file);
845 if (rename(file, buffer) != 0) {
846 SDDS_SetError(
"Cannot save previous version of output file (SDDS_WriteMplTable)");
854 (mpl_data->topline && !
SDDS_StringIsBlank(mpl_data->topline) &&
SDDS_DefineParameter(&page,
"mplTopline", NULL, NULL, NULL, NULL,
SDDS_STRING, mpl_data->topline) < 0) || (mpl_data->title && !
SDDS_StringIsBlank(mpl_data->title) &&
SDDS_DefineParameter(&page,
"mplTitle", NULL, NULL, NULL, NULL,
SDDS_STRING, mpl_data->title) < 0)) {
855 SDDS_SetError(
"Problem initializing SDDS output of mpl page data (SDDS_WriteMplTable)");
859 SDDS_SetError(
"Unable to define primary mpl columns for SDDS output (SDDS_WriteMplTable)");
862 sx_index = sy_index = -1;
863 if (mpl_data->flags & SIGMA_X_PRESENT && (sx_index =
SDDS_AddMplDefinition(&page, mpl_data->xlab,
"Sigma",
"x", file)) < 0) {
864 SDDS_SetError(
"Unable to define sigma-x column for SDDS output (SDDS_WriteMplTable)");
867 if (mpl_data->flags & SIGMA_Y_PRESENT && (sy_index =
SDDS_AddMplDefinition(&page, mpl_data->ylab,
"Sigma",
"y", file)) < 0) {
868 SDDS_SetError(
"Unable to define sigma-y column for SDDS output (SDDS_WriteMplTable)");
879 if (!
SDDS_SetColumn(&page, SDDS_SET_BY_INDEX, mpl_data->c1, mpl_data->n_data, 0) ||
880 !
SDDS_SetColumn(&page, SDDS_SET_BY_INDEX, mpl_data->c2, mpl_data->n_data, 1) || (sx_index >= 0 && !
SDDS_SetColumn(&page, SDDS_SET_BY_INDEX, mpl_data->s1, mpl_data->n_data, sx_index)) || (sy_index >= 0 && !
SDDS_SetColumn(&page, SDDS_SET_BY_INDEX, mpl_data->s2, mpl_data->n_data, sy_index))) {