191 {
192 int iArg;
193 char *input, *output, *meanPar, *sigmaPar, *maxPar, *minPar;
194 long i, mainInputOpened, haltonID = 0, requireInput = 0;
195 unsigned long pipeFlags, majorOrderFlag;
196 SCANNED_ARG *scanned;
198 long randomNumberSeed = 0;
200 long samples, seqRequests, randomizationGroups = 0;
201 int64_t j, values;
202 double *sample, *IVValue, *CDFValue;
203 char msgBuffer[1000];
205 long verbose, optimalHalton = 0;
206 short columnMajorOrder = -1;
207 int threads = 1;
208 int *dataFilePageStatus = NULL;
209
211 argc =
scanargs(&scanned, argc, argv);
212 if (argc < 2) {
213 fprintf(stderr, "%s%s%s\n", USAGE1, USAGE2, USAGE3);
214 return EXIT_FAILURE;
215 }
216 seqRequest = NULL;
217 seqRequests = 0;
218 output = input = NULL;
219 pipeFlags = 0;
220 samples = values = 0;
221 sample = IVValue = CDFValue = NULL;
222 verbose = 0;
223 maxPar = minPar = meanPar = sigmaPar = NULL;
224
225 for (iArg = 1; iArg < argc; iArg++) {
226 if (scanned[iArg].arg_type == OPTION) {
227
228 switch (
match_string(scanned[iArg].list[0], option, CLO_OPTIONS, 0)) {
229 case CLO_MAJOR_ORDER:
230 majorOrderFlag = 0;
231 scanned[iArg].n_items--;
232 if (scanned[iArg].n_items > 0 &&
233 (!
scanItemList(&majorOrderFlag, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
234 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
235 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
236 SDDS_Bomb(
"invalid -majorOrder syntax/values");
237 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
238 columnMajorOrder = 1;
239 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
240 columnMajorOrder = 0;
241 break;
242 case CLO_COLUMNS:
243 if (scanned[iArg].n_items < 3)
245 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
247 scanned[iArg].n_items -= 1;
248 memset(seqRequest + seqRequests, 0, sizeof(*seqRequest));
249
250 seqRequest[seqRequests].randomizationGroup = -1;
251 seqRequest[seqRequests].factor = 1;
252 seqRequest[seqRequests].offset = 0;
254 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
255 "datafile",
SDDS_STRING, &seqRequest[seqRequests].dataFileName, 1, SEQ_DATAFILE,
256 "independentvariable",
SDDS_STRING, &seqRequest[seqRequests].indepName, 1, SEQ_INDEPNAME,
257 "cdf",
SDDS_STRING, &seqRequest[seqRequests].CDFName, 1, SEQ_CDFNAME,
258 "df",
SDDS_STRING, &seqRequest[seqRequests].DFName, 1, SEQ_DFNAME,
259 "output",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
260 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN,
261 "haltonradix",
SDDS_LONG, &seqRequest[seqRequests].haltonRadix, 1, SEQ_HALTONRADIX,
262 "haltonoffset",
SDDS_LONG, &seqRequest[seqRequests].haltonOffset, 1, SEQ_HALTONOFFSET,
263 "randomize", -1, NULL, 0, SEQ_RANDOMIZE,
264 "group",
SDDS_LONG, &seqRequest[seqRequests].randomizationGroup, 1, SEQ_RANDOMGROUP,
265 "factor",
SDDS_DOUBLE, &seqRequest[seqRequests].factor, 1, 0,
266 "offset",
SDDS_DOUBLE, &seqRequest[seqRequests].offset, 1, 0, NULL) ||
267 bitsSet(seqRequest[seqRequests].flags & (SEQ_INDEPNAME + SEQ_CDFNAME + SEQ_DFNAME)) != 2)
269 if (seqRequest[seqRequests].flags & SEQ_RANDOMGROUP && seqRequest[seqRequests].randomizationGroup <= 0)
270 SDDS_Bomb(
"use a positive integer for the randomization group ID");
271 if (seqRequest[seqRequests].flags & SEQ_CDFNAME && seqRequest[seqRequests].flags & SEQ_DFNAME)
272 SDDS_Bomb(
"give df or cdf for -columns, not both");
273 if (seqRequest[seqRequests].flags & SEQ_HALTONRADIX && !
is_prime(seqRequest[seqRequests].haltonRadix))
274 SDDS_Bomb(
"halton radix must be a prime number");
275 seqRequests++;
276 scanned[iArg].n_items += 1;
277 break;
278 case CLO_GAUSSIAN:
279 if (scanned[iArg].n_items < 2)
281 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
283 memset(seqRequest + seqRequests, 0, sizeof(*seqRequest));
284 scanned[iArg].n_items -= 1;
285 seqRequest[seqRequests].randomizationGroup = -1;
286 seqRequest[seqRequests].mean = 0;
287 seqRequest[seqRequests].sigma = 1;
289 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
290 "columnName",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
293 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
295 seqRequest[seqRequests].flags |= SEQ_DIRECT_GAUSSIAN;
296 if (!(seqRequest[seqRequests].flags & SEQ_OUTPUTNAME) || !(seqRequest[seqRequests].outputName))
297 SDDS_Bomb(
"columnName is not provided for gaussian distribution/");
298 if (meanPar) {
301 else if (!
get_double(&seqRequest[seqRequests].mean, meanPar))
302 SDDS_Bomb(
"Invalid value given for mean value of -gaussian distribution.");
303 free(meanPar);
304 meanPar = NULL;
305 }
306 if (sigmaPar) {
309 else if (!
get_double(&seqRequest[seqRequests].sigma, sigmaPar))
310 SDDS_Bomb(
"Invalid value given for sigma value of -gaussian distribution.");
311 free(sigmaPar);
312 sigmaPar = NULL;
313 }
314 seqRequests++;
315 scanned[iArg].n_items += 1;
316 break;
317 case CLO_UNIFORM:
318 if (scanned[iArg].n_items < 2)
320 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
322 memset(seqRequest + seqRequests, 0, sizeof(*seqRequest));
323 scanned[iArg].n_items -= 1;
324 memset(seqRequest + seqRequests, 0, sizeof(*seqRequest));
325 seqRequest[seqRequests].randomizationGroup = -1;
326 seqRequest[seqRequests].min = 0;
327 seqRequest[seqRequests].max = 1;
329 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
330 "columnName",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
333 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
335 seqRequest[seqRequests].flags |= SEQ_DIRECT_UNIFORM;
336 if (!(seqRequest[seqRequests].flags & SEQ_OUTPUTNAME) ||
337 !(seqRequest[seqRequests].outputName))
338 SDDS_Bomb(
"columnName is not provided for uniform distribution/");
339 if (minPar) {
342 else if (!
get_double(&seqRequest[seqRequests].min, minPar))
343 SDDS_Bomb(
"Invalid value given for minimum value of -uniform distribution.");
344 free(minPar);
345 minPar = NULL;
346 }
347 if (maxPar) {
350 else if (!
get_double(&seqRequest[seqRequests].max, maxPar))
351 SDDS_Bomb(
"Invalid value given for maximum value of -uniform distribution.");
352 free(maxPar);
353 maxPar = NULL;
354 }
355 seqRequests++;
356 scanned[iArg].n_items += 1;
357 break;
358 case CLO_POISSON:
359 if (scanned[iArg].n_items < 2)
361 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
363 memset(seqRequest + seqRequests, 0, sizeof(*seqRequest));
364 scanned[iArg].n_items -= 1;
365 memset(seqRequest + seqRequests, 0, sizeof(*seqRequest));
366 seqRequest[seqRequests].randomizationGroup = -1;
367 seqRequest[seqRequests].mean = 1;
369 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
370 "columnName",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
372 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
374 seqRequest[seqRequests].flags |= SEQ_DIRECT_POISSON;
375 if (!(seqRequest[seqRequests].flags & SEQ_OUTPUTNAME) || !(seqRequest[seqRequests].outputName))
376 SDDS_Bomb(
"columnName is not provided for poisson distribution/");
377 if (meanPar) {
380 else if (!
get_double(&seqRequest[seqRequests].mean, meanPar))
381 SDDS_Bomb(
"Invalid value given for mean value of -poisson distribution.");
382 free(meanPar);
383 meanPar = NULL;
384 }
385 seqRequests++;
386 scanned[iArg].n_items += 1;
387 break;
388 case CLO_SAMPLES:
389 if (scanned[iArg].n_items != 2 ||
390 sscanf(scanned[iArg].list[1], "%ld", &samples) != 1 ||
391 samples <= 0)
393 break;
394 case CLO_SEED:
395 if (scanned[iArg].n_items != 2 ||
396 sscanf(scanned[iArg].list[1], "%ld", &randomNumberSeed) != 1)
398 break;
399 case CLO_PIPE:
400 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
402 break;
403 case CLO_VERBOSE:
404 verbose = 1;
405 break;
406 case CLO_OPTIMAL_HALTON:
407 optimalHalton = 1;
408 break;
409 case CLO_THREADS:
410 if (scanned[iArg].n_items != 2 ||
411 sscanf(scanned[iArg].list[1], "%d", &threads) != 1 ||
412 threads < 1)
414 break;
415 default:
416 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
417 exit(EXIT_FAILURE);
418 break;
419 }
420 } else {
421 if (!input)
422 input = scanned[iArg].list[0];
423 else if (!output)
424 output = scanned[iArg].list[0];
425 else
427 }
428 }
429
430 if (!seqRequests)
431 SDDS_Bomb(
"give one or more -columns options");
432 if (samples < 1)
434
435 for (i = 0; i < seqRequests; i++) {
436 if (!(seqRequest[i].flags & (SEQ_DATAFILE | SEQ_DIRECT_GAUSSIAN | SEQ_DIRECT_UNIFORM | SEQ_DIRECT_POISSON)))
437 break;
438 }
439 if (i == seqRequests) {
440
441
442
443
444 if (!input)
445 pipeFlags |= USE_STDIN;
446 if (input && !output) {
447 output = input;
448 input = NULL;
449 pipeFlags |= USE_STDIN;
451 sprintf(msgBuffer, "%s exists already (sddssampledist)", output);
453 }
454 }
455 }
456
458
461
462 if (verbose)
463 fprintf(stderr, "Initialized output file %s\n", output);
464
465
466 for (i = mainInputOpened = 0; i < seqRequests; i++) {
467 if (seqRequest[i].flags & SEQ_DIRECT_GAUSSIAN) {
468 if (seqRequest[i].meanPar || seqRequest[i].sigmaPar) {
469 if (!mainInputOpened) {
473 mainInputOpened = 1;
474 }
475 requireInput = 1;
476 SDDSptr = &SDDSin;
477 if ((seqRequest[i].meanPar &&
479 (seqRequest[i].sigmaPar &&
482 exit(EXIT_FAILURE);
483 }
484 }
487 } else if (seqRequest[i].flags & SEQ_DIRECT_UNIFORM) {
488 if (seqRequest[i].minPar || seqRequest[i].maxPar) {
489 if (!mainInputOpened) {
493 mainInputOpened = 1;
494 }
495 requireInput = 1;
496 SDDSptr = &SDDSin;
497 if ((seqRequest[i].minPar &&
499 (seqRequest[i].maxPar &&
502 exit(EXIT_FAILURE);
503 }
504 }
507 } else if (seqRequest[i].flags & SEQ_DIRECT_POISSON) {
508 if (seqRequest[i].meanPar) {
509 if (!mainInputOpened) {
513 mainInputOpened = 1;
514 }
515 requireInput = 1;
516 SDDSptr = &SDDSin;
519 exit(EXIT_FAILURE);
520 }
521 }
524 } else {
525 if (seqRequest[i].flags & SEQ_RANDOMIZE) {
526 long newGroupID = 0;
527
528 if (seqRequest[i].flags & SEQ_RANDOMGROUP) {
529 newGroupID = seqRequest[i].randomizationGroup;
530 for (j = 0; j < randomizationGroups; j++)
531 if (randomizationData[j].group == newGroupID) {
532 newGroupID = 0;
533 break;
534 }
535 } else {
536 seqRequest[i].randomizationGroup = newGroupID = -(i + 1);
537 }
538 if (newGroupID != 0) {
539 if (!(randomizationData =
SDDS_Realloc(randomizationData,
sizeof(*randomizationData) * (randomizationGroups + 1))))
541 randomizationData[randomizationGroups].group = newGroupID;
542 randomizationData[randomizationGroups].order = NULL;
543 randomizationGroups++;
544 }
545 }
546 if (seqRequest[i].flags & SEQ_DATAFILE) {
549 SDDSptr = &seqRequest[i].SDDSin;
550 } else {
551 if (!mainInputOpened) {
555 mainInputOpened = 1;
556 }
557 requireInput = 1;
558 SDDSptr = &SDDSin;
559 }
561 ((seqRequest[i].flags & SEQ_CDFNAME) &&
563 ((seqRequest[i].flags & SEQ_DFNAME) &&
567 exit(EXIT_FAILURE);
568 }
569 }
570
571 if (seqRequest[i].flags & SEQ_UNITSGIVEN &&
574 }
575
576 if (verbose)
577 fprintf(stderr, "Initialized input files\n");
578
579 if (columnMajorOrder != -1)
580 SDDSout.layout.data_mode.column_major = columnMajorOrder;
581 else
582 SDDSout.layout.data_mode.column_major = 0;
583
586
587 if (randomNumberSeed <= 0) {
588 randomNumberSeed = (long)time((time_t *)NULL);
589 randomNumberSeed = 2 * (randomNumberSeed / 2) + 1;
590#if defined(_WIN32) || defined(__APPLE__)
592#else
594#endif
595 } else
597
598 if (!(sample = calloc(samples, sizeof(*sample))))
600 if (!(dataFilePageStatus = calloc(seqRequests, sizeof(*dataFilePageStatus))))
602 while (1) {
603 if (verbose)
604 fprintf(stderr, "Beginning page loop\n");
606 break;
607 for (i = 0; i < seqRequests; i++)
608 dataFilePageStatus[i] = 1;
609#pragma omp parallel for if (threads > 1 && seqRequests > 1) num_threads(threads) schedule(dynamic)
610 for (i = 0; i < seqRequests; i++) {
611 if (seqRequest[i].flags & SEQ_DATAFILE)
612 dataFilePageStatus[i] =
SDDS_ReadPage(&seqRequest[i].SDDSin);
613 }
614 for (i = 0; i < seqRequests; i++)
615 if ((seqRequest[i].flags & SEQ_DATAFILE) && dataFilePageStatus[i] <= 0)
616 break;
617 if (i != seqRequests)
618 break;
621 if (verbose)
622 fprintf(stderr, "Defining randomization tables\n");
623
624 for (i = 0; i < randomizationGroups; i++) {
625 if (!(randomizationData[i].order =
SDDS_Malloc(
sizeof(*randomizationData[i].order) * samples)))
627 for (j = 0; j < samples; j++)
628 randomizationData[i].order[j] = j;
629 randomizeOrder((
char *)randomizationData[i].order,
sizeof(*randomizationData[i].order), samples, 0,
random_1);
630 }
631 if (verbose)
632 fprintf(stderr, "Beginning loop over sequence requests\n");
633 for (i = 0; i < seqRequests; i++) {
634 if (verbose)
635 fprintf(stderr, "Processing sequence request %ld\n", i);
636 if (seqRequest[i].flags & SEQ_DIRECT_GAUSSIAN) {
637 if ((seqRequest[i].meanPar &&
639 (seqRequest[i].sigmaPar &&
642 for (j = 0; j < samples; j++)
644 } else if (seqRequest[i].flags & SEQ_DIRECT_UNIFORM) {
645 if ((seqRequest[i].minPar &&
647 (seqRequest[i].maxPar &&
650 for (j = 0; j < samples; j++)
651 sample[j] = seqRequest[i].min + (seqRequest[i].max - seqRequest[i].min) *
random_1(1);
652 } else if (seqRequest[i].flags & SEQ_DIRECT_POISSON) {
653 double *pos_x, *pos_cdf, CDF;
654 long pos_points, code;
655 pos_x = pos_cdf = NULL;
656 if ((seqRequest[i].meanPar &&
659 pos_points = CreatePoissonDistributionTable(&pos_x, &pos_cdf, seqRequest[i].mean);
660
661 for (j = 0; j < samples; j++) {
663 sample[j] = (int)(
interp(pos_x, pos_cdf, pos_points, CDF, 0, 1, &code));
664
665 }
666 free(pos_x);
667 free(pos_cdf);
668 } else {
669 if (input && !(seqRequest[i].flags & SEQ_DATAFILE))
670 SDDSptr = &SDDSin;
671 else
672 SDDSptr = &seqRequest[i].SDDSin;
675 (seqRequest[i].flags & SEQ_CDFNAME &&
677 (seqRequest[i].flags & SEQ_DFNAME &&
680 } else {
681 sprintf(msgBuffer, "empty page for file %s\n",
682 (seqRequest[i].flags & SEQ_DATAFILE) ? seqRequest[i].dataFileName : input);
684 }
685 if (verbose)
686 fprintf(stderr, "Checking and converting CDF/DF values\n");
687
688 for (j = 1; j < values; j++) {
689 if (IVValue[j - 1] > IVValue[j]) {
690 sprintf(msgBuffer, "random variate values not monotonically increasing for %s",
691 (seqRequest[i].flags & SEQ_DATAFILE) ? seqRequest[i].dataFileName : input);
693 }
694 if (seqRequest[i].flags & SEQ_DFNAME)
695
696 CDFValue[j] += CDFValue[j - 1];
697 if (CDFValue[j] < CDFValue[j - 1]) {
698 sprintf(msgBuffer, "CDF values decreasing for %s",
699 (seqRequest[i].flags & SEQ_DATAFILE) ? seqRequest[i].dataFileName : input);
701 }
702 }
703 if (verbose)
704 fprintf(stderr, "Normalizing CDF\n");
705
706 if (CDFValue[values - 1] <= 0) {
707 sprintf(msgBuffer, "CDF not valid for %s\n", seqRequest[i].dataFileName);
709 }
710 for (j = 0; j < values; j++)
711 CDFValue[j] /= CDFValue[values - 1];
712 if (seqRequest[i].flags & SEQ_HALTONRADIX) {
713 if (verbose)
714 fprintf(stderr, "Starting halton sequence, offset=%" PRId32 "\n", seqRequest[i].haltonOffset);
715 if (!optimalHalton)
717 else
719 while (seqRequest[i].haltonOffset-- > 0) {
720 if (!optimalHalton)
722 else
724 }
725 }
726 if (verbose)
727 fprintf(stderr, "Generating samples\n");
728 for (j = 0; j < samples; j++) {
729 double CDF;
730 long code;
731 while (1) {
732 if (seqRequest[i].flags & SEQ_HALTONRADIX) {
733 if (!optimalHalton)
735 else
737 } else
739 if (CDF <= CDFValue[values - 1] && CDF >= CDFValue[0])
740 break;
741 }
742 sample[j] = seqRequest[i].factor *
interp(IVValue, CDFValue, values, CDF, 0, 1, &code) + seqRequest[i].offset;
743 }
744 if (seqRequest[i].flags & SEQ_RANDOMIZE) {
745 long k, l;
746 double *sample1;
747 if (verbose)
748 fprintf(stderr, "Randomizing order of values\n");
749 if (!(sample1 = malloc(sizeof(*sample1) * samples)))
751 for (l = 0; l < randomizationGroups; l++)
752 if (randomizationData[l].group == seqRequest[i].randomizationGroup)
753 break;
754 if (l == randomizationGroups)
755 SDDS_Bomb(
"problem with construction of randomization groups!");
756 for (k = 0; k < samples; k++)
757 sample1[k] = sample[randomizationData[l].order[k]];
758 free(sample);
759 sample = sample1;
760 }
761 free(IVValue);
762 free(CDFValue);
763 }
764 if (verbose)
765 fprintf(stderr, "Setting SDDS column values\n");
767 seqRequest[i].outputName ? seqRequest[i].outputName : seqRequest[i].indepName))
769 }
770 if (verbose)
771 fprintf(stderr, "Writing data page\n");
774 if (!requireInput)
775 break;
776 }
777 if (verbose)
778 fprintf(stderr, "Exited read loop\n");
779 free(sample);
780 free(dataFilePageStatus);
783 for (i = 0; i < seqRequests; i++) {
784 if (seqRequest[i].dataFileName)
785 free(seqRequest[i].dataFileName);
786 if (seqRequest[i].indepName)
787 free(seqRequest[i].indepName);
788 if (seqRequest[i].outputName)
789 free(seqRequest[i].outputName);
790 if (seqRequest[i].DFName)
791 free(seqRequest[i].DFName);
792 if (seqRequest[i].CDFName)
793 free(seqRequest[i].CDFName);
794 if (seqRequest[i].units)
795 free(seqRequest[i].units);
796 if (seqRequest[i].meanPar)
797 free(seqRequest[i].meanPar);
798 if (seqRequest[i].sigmaPar)
799 free(seqRequest[i].sigmaPar);
800 if (seqRequest[i].minPar)
801 free(seqRequest[i].minPar);
802 if (seqRequest[i].maxPar)
803 free(seqRequest[i].maxPar);
804 if (seqRequest[i].flags & SEQ_DATAFILE && !
SDDS_Terminate(&(seqRequest[i].SDDSin)))
806 }
807 free(seqRequest);
808 for (i = 0; i < randomizationGroups; i++)
809 free(randomizationData[i].order);
810 if (randomizationData)
811 free(randomizationData);
812
814
815 return EXIT_SUCCESS;
816}
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_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows,...)
Sets the values for a single data column using double-precision floating-point numbers.
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_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
int32_t SDDS_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
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_TransferAllParameterDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
Transfers all parameter definitions from a source dataset to a target dataset.
int32_t SDDS_CheckColumn(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a column exists in the SDDS dataset with the specified name, units, and type.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
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.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric type.
#define SDDS_DOUBLE
Identifier for the double data type.
long bitsSet(unsigned long data)
Counts the number of set bits (1s) in the given data.
int get_double(double *dptr, char *s)
Parses a double value from the given string.
double random_1(long iseed)
Generate a uniform random double in [0,1] using a custom seed initialization.
long randomizeOrder(char *ptr, long size, long length, long iseed, double(*urandom)(long iseed1))
Randomize the order of an array of elements.
double gauss_rn_lim(double mean, double sigma, double limit_in_sigmas, double(*urandom)(long iseed))
Generate a Gaussian-distributed random number with specified mean, sigma, and optional cutoff.
int64_t is_prime(int64_t number)
Determine if a number is prime.
long fexists(const char *filename)
Checks if a file exists.
int32_t startModHaltonSequence(int32_t *radix, double tiny)
Start a modified Halton sequence.
double nextModHaltonSequencePoint(long ID)
Retrieve the next point from the modified Halton sequence.
int32_t startHaltonSequence(int32_t *radix, double value)
Initialize and start a new Halton sequence.
double nextHaltonSequencePoint(long ID)
Get the next point in a Halton sequence.
double interp(double *f, double *x, long n, double xo, long warnings, long order, long *returnCode)
Performs simple linear interpolation of data.
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)
void free_scanargs(SCANNED_ARG **scanned, int argc)
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.
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.