82#define CLO_OPTIMAL_HALTON 8
83#define CLO_MAJOR_ORDER 9
86static char *option[CLO_OPTIONS] = {
99char *USAGE1 =
"sddssampledist [<input>] [<output>] [-pipe=[in][,out]]\n\
100-columns=independentVariable=<name>,{cdf=<CDFName> | df=<DFName>}[,output=<name>][,units=<string>][,factor=<value>][,offset=<value>][,datafile=<filename>][,haltonRadix=<primeNumber>[,haltonOffset=<integer>][,randomize[,group=<groupID>]]]\n\
101[-columns=...] [-samples=<integer>] [-seed=<integer>] [-verbose] \n\
102[-gaussian=columnName=<columnName>[,meanValue=<value>|@<parameter_name>][,sigmaValue=<value>|@<parameter_name>][,units=<string>]] \n\
103[-uniform=columnName=<columnName>[,minimumValue=<value>|@<parameter_name>][,maximumValue=<value>|@<parameter_name>][,units=<string>]] \n\
104[-poisson=columnName=<columnName>[,meanValue=<value>|@<parameter_name>][,units=<string>] [-optimalHalton] [-majorOrder=row|column] \n";
105char *USAGE2 =
"-columns Gives the name of the independent variable for the distribution\n\
106 and the name of the cumulative distribution function (CDF) or the\n\
107 distribution function (DF). The CDF is a nondecreasing function normalized\n\
108 to 1. The DF need not be normalized (a histogram is acceptable, for\n\
109 example). The output samples will have the same name as the independent\n\
110 variable unless the output qualifier is given. By default, the data is\n\
111 taken from <input>. If the datafile qualifier is given, the data is \n\
112 taken from the named file. If haltonRadix is given, then the samples\n\
113 are generated using a Halton sequence, rather than random numbers.\n\
114 If Halton sequences are used, one can randomize the values in groups\n\
115 identified by an integer group ID. This prevents strange banding from\n\
116 arising in configuration space. Also, the haltonOffset can be used to\n\
117 skip the first <n> values in the halton sequence, which generates a\n\
118 different but not independent sequence.\n\
119 If factor or offset are given, the output values are transformed \n\
120 according to x -> factor*x+offset.\n\
121-gaussian Sample gaussian distribution with specified mean and width, <columnName> \n\
122 gives the output column. \n\
123 If mean value or sigma is specified by meanValue=@<parameter_name> or \n\
124 sigmaValue=@<parameter_name>, the mean or sigma value will be obtained from \n\
125 input file parameter named by corresponding <parameter_name>.\n\
126 Defaut mean is 0 and default sigma is 1. \n";
127char *USAGE3 =
"-uniform Sample with uniform distribution with specified minimum and maximum value.\n\
128 <columnName> gives the output column. \n\
129 If mimimum or maximum value is specified by minimumValue=@<parameter_name> or \n\
130 maximumValue=@<parameter_name>, the minimum or maximum value will be obtained from \n\
131 input file parameter named by corresponding <parameter_name>.\n\
132 The default minimum/maximum value is 0/1. \n\
133-poisson Sample with poisson distribution with specified mean. <columnName> gives the \n\
134 output column. If the mean value is specified by meanValue=@<parameter_name>, \n\
135 the mean value will be obtained from input file parameter named by <parameter_name>.\n\
136 The default mean is 1.\n\
137-samples Specifies the number of samples to generate.\n\
138-seed Specifies the seed for the random number generator. If not given or non-positive,\n\
139 the generator is seeded from the system clock.\n\
140-optimalHalton if provided, the improved halton sequence will be used for generating random numbers.\n\
141-majorOrder Specifies the output file in row or column major order.\n\
142-verbose Prints information to stderr while working.\n\n\
143Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
145#define SEQ_DATAFILE 0x0001UL
146#define SEQ_INDEPNAME 0x0002UL
147#define SEQ_CDFNAME 0x0004UL
148#define SEQ_DFNAME 0x0008UL
149#define SEQ_OUTPUTNAME 0x0010UL
150#define SEQ_HALTONRADIX 0x0020UL
151#define SEQ_RANDOMIZE 0x0040UL
152#define SEQ_RANDOMGROUP 0x0080UL
153#define SEQ_UNITSGIVEN 0x0100UL
154#define SEQ_HALTONOFFSET 0x0200UL
155#define SEQ_DIRECT_GAUSSIAN 0x0400UL
156#define SEQ_DIRECT_UNIFORM 0x0800UL
157#define SEQ_DIRECT_POISSON 0x1000UL
162 char *dataFileName, *indepName, *CDFName, *DFName, *outputName, *units, *meanPar, *sigmaPar, *minPar, *maxPar;
164 int32_t haltonRadix, randomizationGroup, haltonOffset;
165 double factor, offset, mean, min, max, sigma;
174long CreatePoissonDistributionTable(
double **x,
double **pos_CDF,
double mean);
176int main(
int argc,
char **argv) {
178 char *input, *output, *meanPar, *sigmaPar, *maxPar, *minPar;
179 long i, mainInputOpened, haltonID = 0, requireInput = 0;
180 unsigned long pipeFlags, majorOrderFlag;
181 SCANNED_ARG *scanned;
183 long randomNumberSeed = 0;
185 long samples, seqRequests, randomizationGroups = 0;
187 double *sample, *IVValue, *CDFValue;
188 char msgBuffer[1000];
190 long verbose, optimalHalton = 0;
191 short columnMajorOrder = -1;
194 argc =
scanargs(&scanned, argc, argv);
196 fprintf(stderr,
"%s%s%s\n", USAGE1, USAGE2, USAGE3);
201 output = input = NULL;
203 samples = values = 0;
204 sample = IVValue = CDFValue = NULL;
206 maxPar = minPar = meanPar = sigmaPar = NULL;
208 for (iArg = 1; iArg < argc; iArg++) {
209 if (scanned[iArg].arg_type == OPTION) {
211 switch (
match_string(scanned[iArg].list[0], option, CLO_OPTIONS, 0)) {
212 case CLO_MAJOR_ORDER:
214 scanned[iArg].n_items--;
215 if (scanned[iArg].n_items > 0 &&
216 (!
scanItemList(&majorOrderFlag, scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
217 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
218 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
219 SDDS_Bomb(
"invalid -majorOrder syntax/values");
220 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
221 columnMajorOrder = 1;
222 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
223 columnMajorOrder = 0;
226 if (scanned[iArg].n_items < 3)
228 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
230 scanned[iArg].n_items -= 1;
231 memset(seqRequest + seqRequests, 0,
sizeof(*seqRequest));
233 seqRequest[seqRequests].randomizationGroup = -1;
234 seqRequest[seqRequests].factor = 1;
235 seqRequest[seqRequests].offset = 0;
237 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
238 "datafile",
SDDS_STRING, &seqRequest[seqRequests].dataFileName, 1, SEQ_DATAFILE,
239 "independentvariable",
SDDS_STRING, &seqRequest[seqRequests].indepName, 1, SEQ_INDEPNAME,
240 "cdf",
SDDS_STRING, &seqRequest[seqRequests].CDFName, 1, SEQ_CDFNAME,
241 "df",
SDDS_STRING, &seqRequest[seqRequests].DFName, 1, SEQ_DFNAME,
242 "output",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
243 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN,
244 "haltonradix",
SDDS_LONG, &seqRequest[seqRequests].haltonRadix, 1, SEQ_HALTONRADIX,
245 "haltonoffset",
SDDS_LONG, &seqRequest[seqRequests].haltonOffset, 1, SEQ_HALTONOFFSET,
246 "randomize", -1, NULL, 0, SEQ_RANDOMIZE,
247 "group",
SDDS_LONG, &seqRequest[seqRequests].randomizationGroup, 1, SEQ_RANDOMGROUP,
248 "factor",
SDDS_DOUBLE, &seqRequest[seqRequests].factor, 1, 0,
249 "offset",
SDDS_DOUBLE, &seqRequest[seqRequests].offset, 1, 0, NULL) ||
250 bitsSet(seqRequest[seqRequests].flags & (SEQ_INDEPNAME + SEQ_CDFNAME + SEQ_DFNAME)) != 2)
252 if (seqRequest[seqRequests].flags & SEQ_RANDOMGROUP && seqRequest[seqRequests].randomizationGroup <= 0)
253 SDDS_Bomb(
"use a positive integer for the randomization group ID");
254 if (seqRequest[seqRequests].flags & SEQ_CDFNAME && seqRequest[seqRequests].flags & SEQ_DFNAME)
255 SDDS_Bomb(
"give df or cdf for -columns, not both");
256 if (seqRequest[seqRequests].flags & SEQ_HALTONRADIX && !
is_prime(seqRequest[seqRequests].haltonRadix))
257 SDDS_Bomb(
"halton radix must be a prime number");
259 scanned[iArg].n_items += 1;
262 if (scanned[iArg].n_items < 2)
264 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
266 memset(seqRequest + seqRequests, 0,
sizeof(*seqRequest));
267 scanned[iArg].n_items -= 1;
268 seqRequest[seqRequests].randomizationGroup = -1;
269 seqRequest[seqRequests].mean = 0;
270 seqRequest[seqRequests].sigma = 1;
272 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
273 "columnName",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
276 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
278 seqRequest[seqRequests].flags |= SEQ_DIRECT_GAUSSIAN;
279 if (!(seqRequest[seqRequests].flags & SEQ_OUTPUTNAME) || !(seqRequest[seqRequests].outputName))
280 SDDS_Bomb(
"columnName is not provided for gaussian distribution/");
284 else if (!
get_double(&seqRequest[seqRequests].mean, meanPar))
285 SDDS_Bomb(
"Invalid value given for mean value of -gaussian distribution.");
292 else if (!
get_double(&seqRequest[seqRequests].sigma, sigmaPar))
293 SDDS_Bomb(
"Invalid value given for sigma value of -gaussian distribution.");
298 scanned[iArg].n_items += 1;
301 if (scanned[iArg].n_items < 2)
303 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
305 memset(seqRequest + seqRequests, 0,
sizeof(*seqRequest));
306 scanned[iArg].n_items -= 1;
307 memset(seqRequest + seqRequests, 0,
sizeof(*seqRequest));
308 seqRequest[seqRequests].randomizationGroup = -1;
309 seqRequest[seqRequests].min = 0;
310 seqRequest[seqRequests].max = 1;
312 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
313 "columnName",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
316 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
318 seqRequest[seqRequests].flags |= SEQ_DIRECT_UNIFORM;
319 if (!(seqRequest[seqRequests].flags & SEQ_OUTPUTNAME) ||
320 !(seqRequest[seqRequests].outputName))
321 SDDS_Bomb(
"columnName is not provided for uniform distribution/");
325 else if (!
get_double(&seqRequest[seqRequests].min, minPar))
326 SDDS_Bomb(
"Invalid value given for minimum value of -uniform distribution.");
333 else if (!
get_double(&seqRequest[seqRequests].max, maxPar))
334 SDDS_Bomb(
"Invalid value given for maximum value of -uniform distribution.");
339 scanned[iArg].n_items += 1;
342 if (scanned[iArg].n_items < 2)
344 if (!(seqRequest =
SDDS_Realloc(seqRequest,
sizeof(*seqRequest) * (seqRequests + 1))))
346 memset(seqRequest + seqRequests, 0,
sizeof(*seqRequest));
347 scanned[iArg].n_items -= 1;
348 memset(seqRequest + seqRequests, 0,
sizeof(*seqRequest));
349 seqRequest[seqRequests].randomizationGroup = -1;
350 seqRequest[seqRequests].mean = 1;
352 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
353 "columnName",
SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
355 "units",
SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
357 seqRequest[seqRequests].flags |= SEQ_DIRECT_POISSON;
358 if (!(seqRequest[seqRequests].flags & SEQ_OUTPUTNAME) || !(seqRequest[seqRequests].outputName))
359 SDDS_Bomb(
"columnName is not provided for uniform distribution/");
363 else if (!
get_double(&seqRequest[seqRequests].mean, meanPar))
364 SDDS_Bomb(
"Invalid value given for mean value of -poisson distribution.");
369 scanned[iArg].n_items += 1;
372 if (scanned[iArg].n_items != 2 ||
373 sscanf(scanned[iArg].list[1],
"%ld", &samples) != 1 ||
378 if (scanned[iArg].n_items != 2 ||
379 sscanf(scanned[iArg].list[1],
"%ld", &randomNumberSeed) != 1)
383 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
389 case CLO_OPTIMAL_HALTON:
393 fprintf(stderr,
"error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
399 input = scanned[iArg].list[0];
401 output = scanned[iArg].list[0];
408 SDDS_Bomb(
"give one or more -columns options");
412 for (i = 0; i < seqRequests; i++) {
413 if (!(seqRequest[i].flags & (SEQ_DATAFILE | SEQ_DIRECT_GAUSSIAN | SEQ_DIRECT_UNIFORM | SEQ_DIRECT_POISSON)))
416 if (i == seqRequests) {
422 pipeFlags |= USE_STDIN;
423 if (input && !output) {
426 pipeFlags |= USE_STDIN;
428 sprintf(msgBuffer,
"%s exists already (sddssampledist)", output);
440 fprintf(stderr,
"Initialized output file %s\n", output);
443 for (i = mainInputOpened = 0; i < seqRequests; i++) {
444 if (seqRequest[i].flags & SEQ_DIRECT_GAUSSIAN) {
445 if (seqRequest[i].meanPar || seqRequest[i].sigmaPar) {
446 if (!mainInputOpened) {
454 if ((seqRequest[i].meanPar &&
456 (seqRequest[i].sigmaPar &&
464 }
else if (seqRequest[i].flags & SEQ_DIRECT_UNIFORM) {
465 if (seqRequest[i].minPar || seqRequest[i].maxPar) {
466 if (!mainInputOpened) {
474 if ((seqRequest[i].minPar &&
476 (seqRequest[i].maxPar &&
484 }
else if (seqRequest[i].flags & SEQ_DIRECT_POISSON) {
485 if (seqRequest[i].meanPar) {
486 if (!mainInputOpened) {
502 if (seqRequest[i].flags & SEQ_RANDOMIZE) {
505 if (seqRequest[i].flags & SEQ_RANDOMGROUP) {
506 newGroupID = seqRequest[i].randomizationGroup;
507 for (j = 0; j < randomizationGroups; j++)
508 if (randomizationData[j].group == newGroupID) {
513 seqRequest[i].randomizationGroup = newGroupID = -(i + 1);
515 if (newGroupID != 0) {
516 if (!(randomizationData =
SDDS_Realloc(randomizationData,
sizeof(*randomizationData) * (randomizationGroups + 1))))
518 randomizationData[randomizationGroups].group = newGroupID;
519 randomizationData[randomizationGroups].order = NULL;
520 randomizationGroups++;
523 if (seqRequest[i].flags & SEQ_DATAFILE) {
526 SDDSptr = &seqRequest[i].SDDSin;
528 if (!mainInputOpened) {
538 ((seqRequest[i].flags & SEQ_CDFNAME) &&
540 ((seqRequest[i].flags & SEQ_DFNAME) &&
548 if (seqRequest[i].flags & SEQ_UNITSGIVEN &&
554 fprintf(stderr,
"Initialized input files\n");
556 if (columnMajorOrder != -1)
557 SDDSout.layout.data_mode.column_major = columnMajorOrder;
559 SDDSout.layout.data_mode.column_major = 0;
564 if (randomNumberSeed <= 0) {
565 randomNumberSeed = (long)time((time_t *)NULL);
566 randomNumberSeed = 2 * (randomNumberSeed / 2) + 1;
567#if defined(_WIN32) || defined(darwin)
575 if (!((sample = calloc(
sizeof(*sample), samples))))
579 fprintf(stderr,
"Beginning page loop\n");
582 for (i = 0; i < seqRequests; i++) {
583 if (seqRequest[i].flags & SEQ_DATAFILE &&
SDDS_ReadPage(&seqRequest[i].SDDSin) <= 0)
586 if (i != seqRequests)
591 fprintf(stderr,
"Defining randomization tables\n");
593 for (i = 0; i < randomizationGroups; i++) {
594 if (!(randomizationData[i].order =
SDDS_Malloc(
sizeof(*randomizationData[i].order) * samples)))
596 for (j = 0; j < samples; j++)
597 randomizationData[i].order[j] = j;
598 randomizeOrder((
char *)randomizationData[i].order,
sizeof(*randomizationData[i].order), samples, 0,
random_1);
601 fprintf(stderr,
"Beginning loop over sequence requests\n");
602 for (i = 0; i < seqRequests; i++) {
604 fprintf(stderr,
"Processing sequence request %ld\n", i);
605 if (seqRequest[i].flags & SEQ_DIRECT_GAUSSIAN) {
606 if ((seqRequest[i].meanPar &&
608 (seqRequest[i].sigmaPar &&
611 for (j = 0; j < samples; j++)
613 }
else if (seqRequest[i].flags & SEQ_DIRECT_UNIFORM) {
614 if ((seqRequest[i].minPar &&
616 (seqRequest[i].maxPar &&
619 for (j = 0; j < samples; j++)
620 sample[j] = seqRequest[i].min + (seqRequest[i].max - seqRequest[i].min) *
random_1(1);
621 }
else if (seqRequest[i].flags & SEQ_DIRECT_POISSON) {
622 double *pos_x, *pos_cdf, CDF;
623 long pos_points, code;
624 pos_x = pos_cdf = NULL;
625 if ((seqRequest[i].meanPar &&
628 pos_points = CreatePoissonDistributionTable(&pos_x, &pos_cdf, seqRequest[i].mean);
630 for (j = 0; j < samples; j++) {
632 sample[j] = (int)(
interp(pos_x, pos_cdf, pos_points, CDF, 0, 1, &code));
638 if (input && !(seqRequest[i].flags & SEQ_DATAFILE))
641 SDDSptr = &seqRequest[i].SDDSin;
644 (seqRequest[i].flags & SEQ_CDFNAME &&
646 (seqRequest[i].flags & SEQ_DFNAME &&
650 sprintf(msgBuffer,
"empty page for file %s\n", seqRequest[i].flags & SEQ_DATAFILE ? seqRequest[i].dataFileName : input);
654 fprintf(stderr,
"Checking and converting CDF/DF values\n");
656 for (j = 1; j < values; j++) {
657 if (IVValue[j - 1] > IVValue[j]) {
658 sprintf(msgBuffer,
"random variate values not monotonically increasing for %s", seqRequest[i].flags & SEQ_DATAFILE ? seqRequest[i].dataFileName : input);
661 if (seqRequest[i].flags & SEQ_DFNAME)
663 CDFValue[j] += CDFValue[j - 1];
664 if (CDFValue[j] < CDFValue[j - 1]) {
665 sprintf(msgBuffer,
"CDF values decreasing for %s", seqRequest[i].flags & SEQ_DATAFILE ? seqRequest[i].dataFileName : input);
670 fprintf(stderr,
"Normalizing CDF\n");
672 if (CDFValue[values - 1] <= 0) {
673 sprintf(msgBuffer,
"CDF not valid for %s\n", seqRequest[i].dataFileName);
676 for (j = 0; j < values; j++)
677 CDFValue[j] /= CDFValue[values - 1];
678 if (seqRequest[i].flags & SEQ_HALTONRADIX) {
680 fprintf(stderr,
"Starting halton sequence, offset=%" PRId32
"\n", seqRequest[i].haltonOffset);
685 while (seqRequest[i].haltonOffset-- > 0) {
693 fprintf(stderr,
"Generating samples\n");
694 for (j = 0; j < samples; j++) {
698 if (seqRequest[i].flags & SEQ_HALTONRADIX) {
705 if (CDF <= CDFValue[values - 1] && CDF >= CDFValue[0])
708 sample[j] = seqRequest[i].factor *
interp(IVValue, CDFValue, values, CDF, 0, 1, &code) + seqRequest[i].offset;
710 if (seqRequest[i].flags & SEQ_RANDOMIZE) {
714 fprintf(stderr,
"Randomizing order of values\n");
715 if (!(sample1 = malloc(
sizeof(*sample1) * samples)))
717 for (l = 0; l < randomizationGroups; l++)
718 if (randomizationData[l].group == seqRequest[i].randomizationGroup)
720 if (l == randomizationGroups)
721 SDDS_Bomb(
"problem with construction of randomization groups!");
722 for (k = 0; k < samples; k++)
723 sample1[k] = sample[randomizationData[l].order[k]];
731 fprintf(stderr,
"Setting SDDS column values\n");
733 seqRequest[i].outputName ? seqRequest[i].outputName : seqRequest[i].indepName))
737 fprintf(stderr,
"Writing data page\n");
744 fprintf(stderr,
"Exited read loop\n");
748 for (i = 0; i < seqRequests; i++) {
749 if (seqRequest[i].dataFileName)
750 free(seqRequest[i].dataFileName);
751 if (seqRequest[i].indepName)
752 free(seqRequest[i].indepName);
753 if (seqRequest[i].outputName)
754 free(seqRequest[i].outputName);
755 if (seqRequest[i].DFName)
756 free(seqRequest[i].DFName);
757 if (seqRequest[i].CDFName)
758 free(seqRequest[i].CDFName);
759 if (seqRequest[i].units)
760 free(seqRequest[i].units);
761 if (seqRequest[i].meanPar)
762 free(seqRequest[i].meanPar);
763 if (seqRequest[i].sigmaPar)
764 free(seqRequest[i].sigmaPar);
765 if (seqRequest[i].minPar)
766 free(seqRequest[i].minPar);
767 if (seqRequest[i].maxPar)
768 free(seqRequest[i].maxPar);
769 if (seqRequest[i].flags & SEQ_DATAFILE && !
SDDS_Terminate(&(seqRequest[i].SDDSin)))
773 for (i = 0; i < randomizationGroups; i++)
774 free(randomizationData[i].order);
775 if (randomizationData)
776 free(randomizationData);
783long CreatePoissonDistributionTable(
double **x,
double **pos_CDF,
double mean) {
784 long i, npoints = 20, count = 0;
788 *x = *pos_CDF = NULL;
789 if (!(*x = malloc(
sizeof(**x) * npoints)) ||
790 !(pos = malloc(
sizeof(*pos) * npoints)) ||
791 !(*pos_CDF = malloc(
sizeof(**pos_CDF) * npoints)))
792 SDDS_Bomb(
"memeroy allocation failure.");
795 if (count + 2 >= npoints) {
798 *pos_CDF =
SDDS_Realloc(*pos_CDF,
sizeof(**pos_CDF) * npoints);
805 (*pos_CDF)[count] = pos[i];
808 pos[i] = pos[i - 1] * mean / i;
809 (*pos_CDF)[count] = (*pos_CDF)[count - 1];
810 (*pos_CDF)[count + 1] = (*pos_CDF)[count - 1] + pos[i];
812 if (1.0 - (*pos_CDF)[count + 1] <= 1.0e-15)
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
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.
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.
#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.