152 {
153 int iArg;
154 char *boundaryFile, *boundaryColumn, *boundaryColumnUnits;
155 double *boundaryValue;
156 int64_t nBoundaryValues;
157 char **abscissaName, **columnName, **excludeName;
158 long columnNames, excludeNames, abscissaNames, column, offset;
159 long givenLowerLimits, givenUpperLimits;
160 char *input, *output;
161 long readCode, binsGiven;
162 int64_t i, rows, bins, writeBins;
163 long lowerLimitGiven, upperLimitGiven, doSides, doSeparate;
164 double autoBinsTarget;
165 long autoBinsMinimum, autoBinsMaximum;
166 char *weightColumn;
167 double *weightData;
168 short normMode = NORMALIZE_NO;
169 unsigned long pipeFlags;
170 SCANNED_ARG *scanned;
172 double binSize, *lowerLimit = NULL, *upperLimit = NULL, *givenLowerLimit, *givenUpperLimit, *dx = NULL, range, middle;
173 double **inputData, *abscissa, *histogram, *minValue, *maxValue, transferLimit, *cdf, sum;
174 long *abscissaIndex, *histogramIndex, *cdfIndex;
175 double expandRange, maxRange;
176 char *CDFONLY;
177 unsigned long dummyFlags, majorOrderFlag;
178 short columnMajorOrder = -1;
179
181 argc =
scanargs(&scanned, argc, argv);
182 if (argc < 3 || argc > (3 + N_OPTIONS)) {
183 fprintf(stderr, "%s", USAGE);
184 exit(EXIT_FAILURE);
185 }
186
187 minValue = maxValue = NULL;
188 output = input = NULL;
189 pipeFlags = 0;
190 abscissaName = NULL;
191 boundaryFile = boundaryColumn = boundaryColumnUnits = NULL;
192 boundaryValue = NULL;
193 offset = 0;
194 columnName = excludeName = NULL;
195 columnNames = excludeNames = abscissaNames = 0;
196 givenLowerLimits = givenUpperLimits = 0;
197 givenLowerLimit = givenUpperLimit = NULL;
198 bins = binsGiven = binSize = doSides = doSeparate = 0;
199 lowerLimitGiven = upperLimitGiven = 0;
200 expandRange = 0;
201 cdfOnly = 0;
202 freOnly = 1;
203 autoBinsTarget = 0;
204 autoBinsMinimum = autoBinsMaximum = 0;
205 weightColumn = NULL;
206 weightData = NULL;
207
208 for (iArg = 1; iArg < argc; iArg++) {
209 if (scanned[iArg].arg_type == OPTION) {
210
211 switch (
match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
212 case SET_MAJOR_ORDER:
213 majorOrderFlag = 0;
214 scanned[iArg].n_items--;
215 if (scanned[iArg].n_items > 0 && (!
scanItemList(&majorOrderFlag, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
"row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
"column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
216 SDDS_Bomb(
"invalid -majorOrder syntax/values");
217 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
218 columnMajorOrder = 1;
219 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
220 columnMajorOrder = 0;
221 break;
222 case SET_PIPE:
223 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
225 break;
226 case SET_COLUMNS:
227 if (columnName)
228 SDDS_Bomb(
"only one -columns option may be given");
229 if (scanned[iArg].n_items < 2)
231 if (!(columnName =
SDDS_Realloc(columnName,
sizeof(*columnName) * (columnNames + scanned[iArg].n_items - 1))))
233 for (i = 1; i < scanned[iArg].n_items; i++)
234 columnName[columnNames + i - 1] = scanned[iArg].list[i];
235 columnNames += scanned[iArg].n_items - 1;
236 break;
237 case SET_ABSCISSA:
238 if (abscissaName)
239 SDDS_Bomb(
"only one -abscissa option may be given");
240 if (scanned[iArg].n_items >= 2) {
241 if (!(abscissaName =
SDDS_Realloc(abscissaName,
sizeof(*abscissaName) * (abscissaNames + scanned[iArg].n_items - 1))))
243 for (i = 1; i < scanned[iArg].n_items; i++)
244 abscissaName[abscissaNames + i - 1] = scanned[iArg].list[i];
245 abscissaNames += scanned[iArg].n_items - 1;
246 }
247 break;
248 case SET_BINS:
249 if (binsGiven)
250 SDDS_Bomb(
"-bins specified more than once");
251 binsGiven = 1;
252 if (sscanf(scanned[iArg].list[1], "%" SCNd64, &bins) != 1 || bins <= 0)
253 SDDS_Bomb(
"invalid value for bins---give a positive value");
254 break;
255 case SET_SIZEOFBINS:
256 if (sscanf(scanned[iArg].list[1], "%le", &binSize) != 1 || binSize <= 0)
257 SDDS_Bomb(
"invalid value for bin size---give a positive value");
258 break;
259 case SET_AUTOBINS:
260 if (scanned[iArg].n_items < 2)
262 scanned[iArg].n_items -= 1;
263 autoBinsTarget = autoBinsMinimum = autoBinsMaximum = 0;
264 if (!
scanItemList(&dummyFlags, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
266 "minimum",
SDDS_LONG, &autoBinsMinimum, 1, 0,
267 "maximum",
SDDS_LONG, &autoBinsMaximum, 1, 0, NULL) ||
268 autoBinsTarget <= 0 || autoBinsMinimum < 0 || autoBinsMaximum < 0)
269 SDDS_Bomb(
"incorrect -autoBins syntax or values");
270 break;
271 case SET_EXCLUDE:
272 if (excludeName)
273 SDDS_Bomb(
"only one -exclude option may be given");
274 if (scanned[iArg].n_items < 2)
276 if (!(excludeName =
SDDS_Realloc(excludeName,
sizeof(*excludeName) * (excludeNames + scanned[iArg].n_items - 1))))
278 for (i = 1; i < scanned[iArg].n_items; i++)
279 excludeName[excludeNames + i - 1] = scanned[iArg].list[i];
280 excludeNames += scanned[iArg].n_items - 1;
281 break;
282 case SET_LOWERLIMIT:
283 if (lowerLimitGiven)
284 SDDS_Bomb(
"-lowerLimit specified more than once");
285 lowerLimitGiven = 1;
286 if (!(givenLowerLimit =
SDDS_Realloc(givenLowerLimit,
sizeof(*givenLowerLimit) * (givenLowerLimits + scanned[iArg].n_items - 1))))
287 SDDS_Bomb(
"SET_LOWERLIMIT: memory allocation failure");
288 for (i = 1; i < scanned[iArg].n_items; i++) {
289 if (sscanf(scanned[iArg].list[i], "%lf", &transferLimit) != 1)
290 SDDS_Bomb(
"invalid value for -lowerLimit");
291 givenLowerLimit[givenLowerLimits + i - 1] = transferLimit;
292 }
293 givenLowerLimits += scanned[iArg].n_items - 1;
294 break;
295 case SET_UPPERLIMIT:
296 if (upperLimitGiven)
297 SDDS_Bomb(
"-upperLimit specified more than once");
298 upperLimitGiven = 1;
299 if (!(givenUpperLimit =
SDDS_Realloc(givenUpperLimit,
sizeof(*givenUpperLimit) * (givenUpperLimits + scanned[iArg].n_items - 1))))
300 SDDS_Bomb(
"SET_UPPERLIMIT: memory allocation failure");
301 for (i = 1; i < scanned[iArg].n_items; i++) {
302 if (sscanf(scanned[iArg].list[i], "%lf", &transferLimit) != 1)
303 SDDS_Bomb(
"invalid value for -upperLimit");
304 givenUpperLimit[givenUpperLimits + i - 1] = transferLimit;
305 }
306 givenUpperLimits += scanned[iArg].n_items - 1;
307 break;
308 case SET_SIDES:
309 doSides = DO_SIDES;
310 if (scanned[iArg].n_items == 2) {
311 static char *sideOpt[2] = {"close", "against"};
312 switch (
match_string(scanned[iArg].list[1], sideOpt, 2, 0)) {
313 case 0:
314 doSides = DO_CLOSE_SIDES;
315 break;
316 case 1:
317 doSides = DO_AGAINST_SIDES;
318 break;
319 default:
321 break;
322 }
323 }
324 break;
325 case SET_SEPARATE:
326 doSeparate = 1;
327 break;
328 case SET_EXPAND:
329 if (scanned[iArg].n_items != 2 ||
330 sscanf(scanned[iArg].list[1], "%lf", &expandRange) != 1 || expandRange <= 0)
332 break;
333 case SET_CDF:
334 if (scanned[iArg].n_items == 1)
335 cdfOnly = 0;
336 else {
337 if (scanned[iArg].n_items > 2)
339 CDFONLY = scanned[iArg].list[1];
340 if (strcmp(CDFONLY, "only") != 0)
341 SDDS_Bomb(
"invalid -cdf value, it should be -cdf or -cdf=only");
342 cdfOnly = 1;
343 }
344 freOnly = 0;
345 break;
346 case SET_BOUNDARYDATA:
347 if (scanned[iArg].n_items != 3 ||
348 !(boundaryFile = scanned[iArg].list[1]) ||
349 !strlen(boundaryFile) ||
350 !(boundaryColumn = scanned[iArg].list[2]) ||
351 !strlen(boundaryColumn))
352 SDDS_Bomb(
"invalid -boundaryData syntax or values");
353 break;
354 case SET_WEIGHT:
355 if (scanned[iArg].n_items != 2 ||
356 !(weightColumn = scanned[iArg].list[1]) ||
357 !strlen(weightColumn))
358 SDDS_Bomb(
"invalid -weightColumn syntax or values");
359 break;
360 case SET_NORMALIZE:
361 if (scanned[iArg].n_items == 1)
362 normMode = NORMALIZE_SUM;
363 else if (scanned[iArg].n_items != 2 ||
364 (normMode =
match_string(scanned[iArg].list[1], normalize_option, N_NORMALIZE_OPTIONS, 0)) < 0)
366 break;
367 default:
368 fprintf(stderr, "Error: unknown or ambiguous option: %s\n", scanned[iArg].list[0]);
369 fprintf(stderr, "%s", USAGE);
370 exit(EXIT_FAILURE);
371 break;
372 }
373 } else {
374 if (!input)
375 input = scanned[iArg].list[0];
376 else if (!output)
377 output = scanned[iArg].list[0];
378 else
380 }
381 }
382
383 if (boundaryColumn && (abscissaNames > 0 || doSeparate))
384 SDDS_Bomb(
"-boundaryData option is incompatible with -abscissa and -separate options");
385
386 if (columnNames <= 0)
387 SDDS_Bomb(
"Supply the names of columns to histogram with -columns");
388
390
393 exit(EXIT_FAILURE);
394 }
395
396 if ((columnNames = expandColumnPairNames(&SDDSin, &columnName, NULL, columnNames, excludeName, excludeNames, FIND_NUMERIC_TYPE, 0)) <= 0) {
398 SDDS_Bomb(
"No quantities selected to histogram.");
399 }
400
401 if (doSeparate) {
402 if (abscissaNames <= 0) {
403 if (!(abscissaName =
SDDS_Realloc(abscissaName,
sizeof(*abscissaName) * (abscissaNames + columnNames))))
405 abscissaNames = 0;
406 for (i = 0; i < columnNames; i++) {
407 abscissaName[abscissaNames + i] = columnName[i];
408 }
409 abscissaNames += columnNames;
410 }
411 if (columnNames > 1) {
412 if (abscissaNames > 0) {
413 if (columnNames != abscissaNames)
414 SDDS_Bomb(
"the number of abscissa names must match the number of columns");
415 }
416 if (givenLowerLimits)
417 if (columnNames != givenLowerLimits)
418 SDDS_Bomb(
"the number of lower limits must match the number of columns");
419 if (givenUpperLimits)
420 if (columnNames != givenUpperLimits)
421 SDDS_Bomb(
"the number of upper limits must match the number of columns");
422 } else {
423
424 if (abscissaNames > 0) {
425 if (columnNames != abscissaNames)
426 abscissaNames = 1;
427 }
428 if (givenLowerLimits)
429 if (columnNames != givenLowerLimits)
430 givenLowerLimits = 1;
431 if (givenUpperLimits)
432 if (columnNames != givenUpperLimits)
433 givenUpperLimits = 1;
434 }
435 } else if (boundaryFile) {
436 if (!(boundaryValue = ReadBoundaryData(boundaryFile, boundaryColumn, &nBoundaryValues, &boundaryColumnUnits))) {
437 SDDS_Bomb(
"Problem reading boundary data");
438 }
439 } else {
440 if (abscissaNames <= 0)
441 SDDS_Bomb(
"Supply the name of the abscissa with -abscissaName");
442 abscissaNames = 1;
443 }
444
445 SetUpOutput(&SDDSout, &SDDSin, &abscissaIndex, &cdfIndex, &histogramIndex, output, columnName, columnNames, abscissaName, abscissaNames, boundaryColumn, boundaryColumnUnits, columnMajorOrder, normMode);
446
447 if (!(inputData = (double **)malloc(columnNames * sizeof(*inputData))) ||
448 !(minValue = (double *)malloc(columnNames * sizeof(*minValue))) ||
449 !(maxValue = (double *)malloc(columnNames * sizeof(*maxValue))))
451
452 if (((binSize ? 1 : 0) + (binsGiven ? 1 : 0) + (autoBinsTarget ? 1 : 0)) > 1)
453 SDDS_Bomb(
"Specify only one of -binSize, -bins, or -autoBins");
454 if (!binSize && !binsGiven && !autoBinsTarget) {
455 binsGiven = 1;
456 bins = 20;
457 }
458
459 abscissa = histogram = cdf = NULL;
460
464
465 if (rows) {
468
469 for (column = 0; column < columnNames; column++) {
472 }
473
474 if (!boundaryColumn) {
475 if (!(lowerLimit = (double *)malloc(sizeof(*lowerLimit) * columnNames)))
477 if (!(upperLimit = (double *)malloc(sizeof(*upperLimit) * columnNames)))
479 if (!(dx = (double *)malloc(sizeof(*dx) * columnNames)))
481
482 if (doSeparate) {
483 for (column = 0; column < columnNames; column++) {
484 find_min_max(&minValue[column], &maxValue[column], inputData[column], rows);
485 lowerLimit[column] = givenLowerLimits ? givenLowerLimit[column] : minValue[column];
486 upperLimit[column] = givenUpperLimits ? givenUpperLimit[column] : maxValue[column];
487 }
488 } else {
489 for (column = 0; column < columnNames; column++)
490 find_min_max(&minValue[column], &maxValue[column], inputData[column], rows);
491 lowerLimit[0] = givenLowerLimits ? givenLowerLimit[0] :
min_in_array(minValue, columnNames);
492 upperLimit[0] = givenUpperLimits ? givenUpperLimit[0] :
max_in_array(maxValue, columnNames);
493 for (column = 1; column < columnNames; column++) {
494 lowerLimit[column] = lowerLimit[0];
495 upperLimit[column] = upperLimit[0];
496 }
497 }
498
499 range = (1 + expandRange) * (upperLimit[0] - lowerLimit[0]);
500 if (autoBinsTarget) {
501 bins = (int64_t)(rows / autoBinsTarget);
502 if (autoBinsMinimum) {
503 if (bins < autoBinsMinimum)
504 bins = autoBinsMinimum;
505 } else if (bins < 5) {
506 bins = 5;
507 }
508 if (autoBinsMaximum) {
509 if (bins > autoBinsMaximum)
510 bins = autoBinsMaximum;
511 } else if (bins > rows)
512 bins = rows;
513 }
514
515 if (binSize) {
516 maxRange = range;
517 for (column = 0; column < columnNames; column++) {
518 range = (1 + expandRange) * (upperLimit[column] - lowerLimit[column]);
519 range = ((range / binSize) + 1) * binSize;
520 if (range > maxRange)
521 maxRange = range;
522 middle = (lowerLimit[column] + upperLimit[column]) / 2;
523 lowerLimit[column] = middle - range / 2;
524 upperLimit[column] = middle + range / 2;
525 }
526 range = maxRange;
527 if (!doSeparate) {
530 dx[0] = binSize;
531 }
532 bins = maxRange / binSize + 0.5;
533 if (bins < 1 && !doSides)
534 bins = 2;
535 if (doSeparate)
536 for (column = 0; column < columnNames; column++) {
537 range = upperLimit[column] - lowerLimit[column];
538 upperLimit[column] += (maxRange - range) / 2;
539 lowerLimit[column] -= (maxRange - range) / 2;
540 dx[column] = binSize;
541 }
542 } else {
543 if (doSeparate) {
544 for (column = 0; column < columnNames; column++) {
545 range = (1 + expandRange) * (upperLimit[column] - lowerLimit[column]);
546 middle = (upperLimit[column] + lowerLimit[column]) / 2;
547 upperLimit[column] = middle + range / 2;
548 lowerLimit[column] = middle - range / 2;
549 if (upperLimit[column] == lowerLimit[column]) {
550 if (fabs(upperLimit[column]) < sqrt(DBL_MIN)) {
551 upperLimit[column] = sqrt(DBL_MIN);
552 lowerLimit[column] = -sqrt(DBL_MIN);
553 } else {
554 lowerLimit[column] = upperLimit[column] * (1 - 10000 * DBL_EPSILON);
555 upperLimit[column] = upperLimit[column] * (1 + 10000 * DBL_EPSILON);
556 }
557 }
558 dx[column] = (upperLimit[column] - lowerLimit[column]) / bins;
559 }
560 } else {
561 range = (1 + expandRange) * (upperLimit[0] - lowerLimit[0]);
562 middle = (upperLimit[0] + lowerLimit[0]) / 2;
563 upperLimit[0] = middle + range / 2;
564 lowerLimit[0] = middle - range / 2;
565 if (upperLimit[0] == lowerLimit[0]) {
566 if (fabs(upperLimit[0]) < sqrt(DBL_MIN)) {
567 upperLimit[0] = sqrt(DBL_MIN);
568 lowerLimit[0] = -sqrt(DBL_MIN);
569 } else {
570 lowerLimit[0] = upperLimit[0] * (1 - 10000 * DBL_EPSILON);
571 upperLimit[0] = upperLimit[0] * (1 + 10000 * DBL_EPSILON);
572 }
573 }
574 dx[0] = (upperLimit[0] - lowerLimit[0]) / bins;
575 }
576 }
577 if (!binsGiven || !abscissa) {
578 if (!(abscissa =
SDDS_Realloc(abscissa,
sizeof(*abscissa) * (bins + 2))) ||
579 !(cdf =
SDDS_Realloc(cdf,
sizeof(*cdf) * (bins + 2))) ||
580 !(histogram =
SDDS_Realloc(histogram,
sizeof(*histogram) * (bins + 2))))
582 }
583 writeBins = bins + (doSides ? 2 : 0);
584 offset = doSides ? 0 : 1;
585 } else {
586 bins = writeBins = nBoundaryValues;
587 abscissa = NULL;
589 !(histogram =
SDDS_Realloc(histogram,
sizeof(*histogram) * bins)))
591 }
592
595
596 if (boundaryColumn) {
597 for (column = 0; column < columnNames; column++) {
598 MakeBoundaryHistogram(histogram, cdf, boundaryValue, nBoundaryValues, inputData[column], weightData, rows);
599 NormalizeHistogram(histogram, nBoundaryValues, normMode);
600 if (!cdfOnly && !
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, histogram, writeBins, histogramIndex[column]))
602 if (!freOnly && !
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, cdf, writeBins, cdfIndex[column]))
604 free(inputData[column]);
605 }
606 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_NAME, boundaryValue, writeBins, boundaryColumn))
608 } else if (!doSeparate) {
609 for (i = -1; i < bins + 1; i++)
610 abscissa[i + 1] = (i + 0.5) * dx[0] + lowerLimit[0];
611 switch (doSides) {
612 case DO_CLOSE_SIDES:
613 abscissa[0] = abscissa[1] - dx[0] / 2;
614 abscissa[bins + 1] = abscissa[bins] + dx[0] / 2;
615 break;
616 case DO_AGAINST_SIDES:
617 abscissa[0] = abscissa[1];
618 abscissa[bins + 1] = abscissa[bins];
619 break;
620 }
621 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, abscissa + offset, writeBins, abscissaIndex[0]))
623 for (column = 0; column < columnNames; column++) {
624 histogram[0] = histogram[bins + 1] = 0;
625 if (!weightColumn)
626 make_histogram(histogram + 1, bins, lowerLimit[0], upperLimit[0], inputData[column], rows, 1);
627 else
628 make_histogram_weighted(histogram + 1, bins, lowerLimit[0], upperLimit[0], inputData[column], rows, 1, weightData);
629 NormalizeHistogram(histogram, bins, normMode);
630 sum = 0;
631 for (i = 0; i <= bins + 1; i++)
632 sum += histogram[i];
633 for (i = 0; i <= bins + 1; i++) {
634 if (!i)
635 cdf[i] = histogram[i] / sum;
636 else
637 cdf[i] = cdf[i - 1] + histogram[i] / sum;
638 }
639 if (!cdfOnly) {
640 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, histogram + offset, writeBins, histogramIndex[column]))
642 }
643 if (!freOnly) {
644 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, cdf + offset, writeBins, cdfIndex[column]))
646 }
647 free(inputData[column]);
648 }
649 } else {
650 for (column = 0; column < columnNames; column++) {
651 for (i = -1; i < bins + 1; i++)
652 abscissa[i + 1] = (i + 0.5) * dx[column] + lowerLimit[column];
653 switch (doSides) {
654 case DO_CLOSE_SIDES:
655 abscissa[0] = abscissa[1] - dx[column] / 2;
656 abscissa[bins + 1] = abscissa[bins] + dx[column] / 2;
657 break;
658 case DO_AGAINST_SIDES:
659 abscissa[0] = abscissa[1];
660 abscissa[bins + 1] = abscissa[bins];
661 break;
662 }
663 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, abscissa + offset, writeBins, abscissaIndex[column]))
665 histogram[0] = histogram[bins + 1] = 0;
666 if (!weightColumn)
667 make_histogram(histogram + 1, bins, lowerLimit[column], upperLimit[column], inputData[column], rows, 1);
668 else
669 make_histogram_weighted(histogram + 1, bins, lowerLimit[column], upperLimit[column], inputData[column], rows, 1, weightData);
670 NormalizeHistogram(histogram, bins + 2, normMode);
671 sum = 0;
672 for (i = 0; i <= bins + 1; i++)
673 sum += histogram[i];
674 for (i = 0; i <= bins + 1; i++) {
675 if (!i)
676 cdf[i] = histogram[i] / sum;
677 else
678 cdf[i] = cdf[i - 1] + histogram[i] / sum;
679 }
680 if (!cdfOnly) {
681 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, histogram + offset, writeBins, histogramIndex[column]))
683 }
684 if (!freOnly) {
685 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_INDEX, cdf + offset, writeBins, cdfIndex[column]))
687 }
688 free(inputData[column]);
689 }
690 }
691 } else {
694 }
695 if (weightData) {
696 free(weightData);
697 weightData = NULL;
698 }
701 }
702
705 exit(EXIT_FAILURE);
706 }
709 exit(EXIT_FAILURE);
710 }
711
712 free(histogram);
713 free(cdf);
714 free(abscissa);
715 if (minValue)
716 free(minValue);
717 if (maxValue)
718 free(maxValue);
719 if (lowerLimit)
720 free(lowerLimit);
721 if (upperLimit)
722 free(upperLimit);
723 if (dx)
724 free(dx);
725
726 return EXIT_SUCCESS;
727}
int32_t SDDS_CopyParameters(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
int find_min_max(double *min, double *max, double *list, int64_t n)
Finds the minimum and maximum values in a list of doubles.
double max_in_array(double *array, long n)
Finds the maximum value in an array of doubles.
double min_in_array(double *array, long n)
Finds the minimum value in an array of doubles.
long make_histogram_weighted(double *hist, long n_bins, double lo, double hi, double *data, long n_pts, long new_start, double *weight)
Compiles a weighted histogram from data points.
long make_histogram(double *hist, long n_bins, double lo, double hi, double *data, int64_t n_pts, long new_start)
Compiles a histogram from data points.
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 scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
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.