SDDSlib
Loading...
Searching...
No Matches
sddssampledist.c
1/*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * This file is distributed subject to a Software License Agreement found
7 * in the file LICENSE that is included with this distribution.
8\*************************************************************************/
9
10/*
11 $Log: not supported by cvs2svn $
12 Revision 1.15 2007/06/21 17:38:12 borland
13 Restored ability to read from a file and write to a pipe.
14 Fixed usage messages for -gaussian, -uniform, and -poisson.
15
16 Revision 1.14 2007/02/12 23:03:59 soliday
17 Updated to work with WIN32
18
19 Revision 1.13 2007/01/03 20:15:36 shang
20 added gaussian, uniform, and poisson distribution
21
22 Revision 1.12 2006/12/14 22:22:00 soliday
23 Updated a bunch of programs because SDDS_SaveLayout is now called by
24 SDDS_WriteLayout and it is no longer required to be called directly.
25 Also the AutoCheckMode is turned off by default now so I removed calls to
26 SDDS_SetAutoCheckMode that would attempt to turn it off. It is now up to
27 the programmer to turn it on in new programs until debugging is completed
28 and then remove the call to SDDS_SetAutoCheckMode.
29
30 Revision 1.11 2006/10/19 17:55:40 soliday
31 Updated to work with linux-x86_64.
32
33 Revision 1.10 2005/11/07 21:48:11 soliday
34 Updated to remove Linux compiler warnings.
35
36 Revision 1.9 2005/11/04 22:46:17 soliday
37 Updated code to be compiled by a 64 bit processor.
38
39 Revision 1.8 2005/03/02 01:40:27 borland
40 Fixed bug in halton sequences (uninitialized values) that resulted in very
41 long run times.
42 Added verbose option.
43
44 Revision 1.7 2003/05/08 18:27:40 borland
45 Added the haltonOffset feature.
46
47 Revision 1.6 2002/08/14 17:12:53 soliday
48 Added Open License
49
50 Revision 1.5 2002/02/10 07:38:01 borland
51 Fixed bug that occurred when there was a single input file.
52
53 Revision 1.4 2002/01/21 01:36:04 borland
54 Fixed bug in randomization when no group was given.
55
56 Revision 1.3 2002/01/21 00:39:09 borland
57 Added units, factor, and offset qualifiers to -columns option.
58
59 Revision 1.2 2002/01/20 23:15:11 borland
60 Added option for individual input files for each -column option.
61 Can use Halton sequences instead of random numbers, with grouping
62 and randomization of order.
63
64 Revision 1.1 2002/01/05 05:17:59 borland
65 First version.
66
67*/
68
69#include "mdb.h"
70#include "scan.h"
71#include "SDDS.h"
72#include <time.h>
73
74#define CLO_PIPE 0
75#define CLO_COLUMNS 1
76#define CLO_SAMPLES 2
77#define CLO_SEED 3
78#define CLO_VERBOSE 4
79#define CLO_GAUSSIAN 5
80#define CLO_UNIFORM 6
81#define CLO_POISSON 7
82#define CLO_OPTIMAL_HALTON 8
83#define CLO_MAJOR_ORDER 9
84#define CLO_OPTIONS 10
85
86static char *option[CLO_OPTIONS] = {
87 "pipe",
88 "columns",
89 "samples",
90 "seed",
91 "verbose",
92 "gaussian",
93 "uniform",
94 "poisson",
95 "optimalHalton",
96 "majorOrder",
97};
98
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";
144
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
158
159typedef struct
160{
161 unsigned long flags;
162 char *dataFileName, *indepName, *CDFName, *DFName, *outputName, *units, *meanPar, *sigmaPar, *minPar, *maxPar;
163 SDDS_DATASET SDDSin;
164 int32_t haltonRadix, randomizationGroup, haltonOffset;
165 double factor, offset, mean, min, max, sigma;
167
168typedef struct
169{
170 long group;
171 long *order;
173
174long CreatePoissonDistributionTable(double **x, double **pos_CDF, double mean);
175
176int main(int argc, char **argv) {
177 int iArg;
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;
182 SDDS_DATASET SDDSin, SDDSout, *SDDSptr;
183 long randomNumberSeed = 0;
184 SEQ_REQUEST *seqRequest;
185 long samples, seqRequests, randomizationGroups = 0;
186 int64_t j, values;
187 double *sample, *IVValue, *CDFValue;
188 char msgBuffer[1000];
189 RANDOMIZED_ORDER *randomizationData = NULL;
190 long verbose, optimalHalton = 0;
191 short columnMajorOrder = -1;
192
194 argc = scanargs(&scanned, argc, argv);
195 if (argc < 2) {
196 fprintf(stderr, "%s%s%s\n", USAGE1, USAGE2, USAGE3);
197 return (1);
198 }
199 seqRequest = NULL;
200 seqRequests = 0;
201 output = input = NULL;
202 pipeFlags = 0;
203 samples = values = 0;
204 sample = IVValue = CDFValue = NULL;
205 verbose = 0;
206 maxPar = minPar = meanPar = sigmaPar = NULL;
207
208 for (iArg = 1; iArg < argc; iArg++) {
209 if (scanned[iArg].arg_type == OPTION) {
210 /* process options here */
211 switch (match_string(scanned[iArg].list[0], option, CLO_OPTIONS, 0)) {
212 case CLO_MAJOR_ORDER:
213 majorOrderFlag = 0;
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;
224 break;
225 case CLO_COLUMNS:
226 if (scanned[iArg].n_items < 3)
227 SDDS_Bomb("invalid -columns syntax");
228 if (!(seqRequest = SDDS_Realloc(seqRequest, sizeof(*seqRequest) * (seqRequests + 1))))
229 SDDS_Bomb("memory allocation failure");
230 scanned[iArg].n_items -= 1;
231 memset(seqRequest + seqRequests, 0, sizeof(*seqRequest));
232 /*remove following pointer initialization because memset already initialize them */
233 seqRequest[seqRequests].randomizationGroup = -1;
234 seqRequest[seqRequests].factor = 1;
235 seqRequest[seqRequests].offset = 0;
236 if (!scanItemList(&seqRequest[seqRequests].flags,
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)
251 SDDS_Bomb("invalid -columns syntax");
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");
258 seqRequests++;
259 scanned[iArg].n_items += 1;
260 break;
261 case CLO_GAUSSIAN:
262 if (scanned[iArg].n_items < 2)
263 SDDS_Bomb("invalid -gaussian syntax");
264 if (!(seqRequest = SDDS_Realloc(seqRequest, sizeof(*seqRequest) * (seqRequests + 1))))
265 SDDS_Bomb("memory allocation failure");
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;
271 if (!scanItemList(&seqRequest[seqRequests].flags,
272 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
273 "columnName", SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
274 "meanValue", SDDS_STRING, &meanPar, 1, 0,
275 "sigmaValue", SDDS_STRING, &sigmaPar, 1, 0,
276 "units", SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
277 SDDS_Bomb("invalid -gaussian syntax");
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/");
281 if (meanPar) {
282 if (wild_match(meanPar, "@*"))
283 SDDS_CopyString(&seqRequest[seqRequests].meanPar, meanPar + 1);
284 else if (!get_double(&seqRequest[seqRequests].mean, meanPar))
285 SDDS_Bomb("Invalid value given for mean value of -gaussian distribution.");
286 free(meanPar);
287 meanPar = NULL;
288 }
289 if (sigmaPar) {
290 if (wild_match(sigmaPar, "@*"))
291 SDDS_CopyString(&seqRequest[seqRequests].sigmaPar, sigmaPar + 1);
292 else if (!get_double(&seqRequest[seqRequests].sigma, sigmaPar))
293 SDDS_Bomb("Invalid value given for sigma value of -gaussian distribution.");
294 free(sigmaPar);
295 sigmaPar = NULL;
296 }
297 seqRequests++;
298 scanned[iArg].n_items += 1;
299 break;
300 case CLO_UNIFORM:
301 if (scanned[iArg].n_items < 2)
302 SDDS_Bomb("invalid -uniform syntax");
303 if (!(seqRequest = SDDS_Realloc(seqRequest, sizeof(*seqRequest) * (seqRequests + 1))))
304 SDDS_Bomb("memory allocation failure");
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;
311 if (!scanItemList(&seqRequest[seqRequests].flags,
312 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
313 "columnName", SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
314 "minimumValue", SDDS_STRING, &minPar, 1, 0,
315 "maximumValue", SDDS_STRING, &maxPar, 1, 0,
316 "units", SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
317 SDDS_Bomb("invalid -uniform syntax");
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/");
322 if (minPar) {
323 if (wild_match(minPar, "@*"))
324 SDDS_CopyString(&seqRequest[seqRequests].minPar, minPar + 1);
325 else if (!get_double(&seqRequest[seqRequests].min, minPar))
326 SDDS_Bomb("Invalid value given for minimum value of -uniform distribution.");
327 free(minPar);
328 minPar = NULL;
329 }
330 if (maxPar) {
331 if (wild_match(maxPar, "@*"))
332 SDDS_CopyString(&seqRequest[seqRequests].maxPar, maxPar + 1);
333 else if (!get_double(&seqRequest[seqRequests].max, maxPar))
334 SDDS_Bomb("Invalid value given for maximum value of -uniform distribution.");
335 free(maxPar);
336 maxPar = NULL;
337 }
338 seqRequests++;
339 scanned[iArg].n_items += 1;
340 break;
341 case CLO_POISSON:
342 if (scanned[iArg].n_items < 2)
343 SDDS_Bomb("invalid -poisson syntax");
344 if (!(seqRequest = SDDS_Realloc(seqRequest, sizeof(*seqRequest) * (seqRequests + 1))))
345 SDDS_Bomb("memory allocation failure");
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;
351 if (!scanItemList(&seqRequest[seqRequests].flags,
352 scanned[iArg].list + 1, &scanned[iArg].n_items, 0,
353 "columnName", SDDS_STRING, &seqRequest[seqRequests].outputName, 1, SEQ_OUTPUTNAME,
354 "meanValue", SDDS_STRING, &meanPar, 1, 0,
355 "units", SDDS_STRING, &seqRequest[seqRequests].units, 1, SEQ_UNITSGIVEN, NULL))
356 SDDS_Bomb("invalid -poisson syntax");
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/");
360 if (meanPar) {
361 if (wild_match(meanPar, "@*"))
362 SDDS_CopyString(&seqRequest[seqRequests].meanPar, meanPar + 1);
363 else if (!get_double(&seqRequest[seqRequests].mean, meanPar))
364 SDDS_Bomb("Invalid value given for mean value of -poisson distribution.");
365 free(meanPar);
366 meanPar = NULL;
367 }
368 seqRequests++;
369 scanned[iArg].n_items += 1;
370 break;
371 case CLO_SAMPLES:
372 if (scanned[iArg].n_items != 2 ||
373 sscanf(scanned[iArg].list[1], "%ld", &samples) != 1 ||
374 samples <= 0)
375 SDDS_Bomb("invalid -samples syntax");
376 break;
377 case CLO_SEED:
378 if (scanned[iArg].n_items != 2 ||
379 sscanf(scanned[iArg].list[1], "%ld", &randomNumberSeed) != 1)
380 SDDS_Bomb("invalid -seed syntax");
381 break;
382 case CLO_PIPE:
383 if (!processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
384 SDDS_Bomb("invalid -pipe syntax");
385 break;
386 case CLO_VERBOSE:
387 verbose = 1;
388 break;
389 case CLO_OPTIMAL_HALTON:
390 optimalHalton = 1;
391 break;
392 default:
393 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
394 exit(1);
395 break;
396 }
397 } else {
398 if (!input)
399 input = scanned[iArg].list[0];
400 else if (!output)
401 output = scanned[iArg].list[0];
402 else
403 SDDS_Bomb("too many filenames seen");
404 }
405 }
406
407 if (!seqRequests)
408 SDDS_Bomb("give one or more -columns options");
409 if (samples < 1)
410 SDDS_Bomb("-samples option not given");
411
412 for (i = 0; i < seqRequests; i++) {
413 if (!(seqRequest[i].flags & (SEQ_DATAFILE | SEQ_DIRECT_GAUSSIAN | SEQ_DIRECT_UNIFORM | SEQ_DIRECT_POISSON)))
414 break;
415 }
416 if (i == seqRequests) {
417 /* all columns options have either their own input files or else use
418 * one of the "direct" distributions. Hence, we don't expect an input
419 * file.
420 */
421 if (!input)
422 pipeFlags |= USE_STDIN; /* not really, but fakes out processFilenames */
423 if (input && !output) {
424 output = input;
425 input = NULL;
426 pipeFlags |= USE_STDIN;
427 if (fexists(output)) {
428 sprintf(msgBuffer, "%s exists already (sddssampledist)", output);
429 SDDS_Bomb(msgBuffer);
430 }
431 }
432 }
433
434 processFilenames("sddssampledist", &input, &output, pipeFlags, 0, NULL);
435
436 if (!SDDS_InitializeOutput(&SDDSout, SDDS_BINARY, 0, NULL, NULL, output))
437 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
438
439 if (verbose)
440 fprintf(stderr, "Initialized output file %s\n", output);
441
442 /* open and check input files */
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) {
447 if (!SDDS_InitializeInput(&SDDSin, input) ||
448 !SDDS_TransferAllParameterDefinitions(&SDDSout, &SDDSin, 0))
449 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
450 mainInputOpened = 1;
451 }
452 requireInput = 1;
453 SDDSptr = &SDDSin;
454 if ((seqRequest[i].meanPar &&
455 SDDS_CheckParameter(SDDSptr, seqRequest[i].meanPar, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) ||
456 (seqRequest[i].sigmaPar &&
457 SDDS_CheckParameter(SDDSptr, seqRequest[i].sigmaPar, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK)) {
458 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
459 exit(1);
460 }
461 }
462 if (!SDDS_DefineSimpleColumn(&SDDSout, seqRequest[i].outputName, NULL, SDDS_DOUBLE))
463 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
464 } else if (seqRequest[i].flags & SEQ_DIRECT_UNIFORM) {
465 if (seqRequest[i].minPar || seqRequest[i].maxPar) {
466 if (!mainInputOpened) {
467 if (!SDDS_InitializeInput(&SDDSin, input) ||
468 !SDDS_TransferAllParameterDefinitions(&SDDSout, &SDDSin, 0))
469 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
470 mainInputOpened = 1;
471 }
472 requireInput = 1;
473 SDDSptr = &SDDSin;
474 if ((seqRequest[i].minPar &&
475 SDDS_CheckParameter(SDDSptr, seqRequest[i].minPar, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) ||
476 (seqRequest[i].maxPar &&
477 SDDS_CheckParameter(SDDSptr, seqRequest[i].maxPar, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK)) {
478 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
479 exit(1);
480 }
481 }
482 if (!SDDS_DefineSimpleColumn(&SDDSout, seqRequest[i].outputName, NULL, SDDS_DOUBLE))
483 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
484 } else if (seqRequest[i].flags & SEQ_DIRECT_POISSON) {
485 if (seqRequest[i].meanPar) {
486 if (!mainInputOpened) {
487 if (!SDDS_InitializeInput(&SDDSin, input) ||
488 !SDDS_TransferAllParameterDefinitions(&SDDSout, &SDDSin, 0))
489 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
490 mainInputOpened = 1;
491 }
492 requireInput = 1;
493 SDDSptr = &SDDSin;
494 if (SDDS_CheckParameter(SDDSptr, seqRequest[i].meanPar, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) {
495 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
496 exit(1);
497 }
498 }
499 if (!SDDS_DefineSimpleColumn(&SDDSout, seqRequest[i].outputName, NULL, SDDS_LONG))
500 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
501 } else {
502 if (seqRequest[i].flags & SEQ_RANDOMIZE) {
503 long newGroupID = 0;
504 /* define randomization groups */
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) {
509 newGroupID = 0;
510 break;
511 }
512 } else {
513 seqRequest[i].randomizationGroup = newGroupID = -(i + 1);
514 }
515 if (newGroupID != 0) {
516 if (!(randomizationData = SDDS_Realloc(randomizationData, sizeof(*randomizationData) * (randomizationGroups + 1))))
517 SDDS_Bomb("memory allocation failure");
518 randomizationData[randomizationGroups].group = newGroupID;
519 randomizationData[randomizationGroups].order = NULL;
520 randomizationGroups++;
521 }
522 }
523 if (seqRequest[i].flags & SEQ_DATAFILE) {
524 if (!SDDS_InitializeInput(&seqRequest[i].SDDSin, seqRequest[i].dataFileName))
525 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
526 SDDSptr = &seqRequest[i].SDDSin;
527 } else {
528 if (!mainInputOpened) {
529 if (!SDDS_InitializeInput(&SDDSin, input) ||
530 !SDDS_TransferAllParameterDefinitions(&SDDSout, &SDDSin, 0))
531 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
532 mainInputOpened = 1;
533 }
534 requireInput = 1;
535 SDDSptr = &SDDSin;
536 }
537 if (SDDS_CheckColumn(SDDSptr, seqRequest[i].indepName, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK ||
538 ((seqRequest[i].flags & SEQ_CDFNAME) &&
539 SDDS_CheckColumn(SDDSptr, seqRequest[i].CDFName, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) ||
540 ((seqRequest[i].flags & SEQ_DFNAME) &&
541 SDDS_CheckColumn(SDDSptr, seqRequest[i].DFName, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) ||
542 !SDDS_TransferColumnDefinition(&SDDSout, SDDSptr, seqRequest[i].indepName, seqRequest[i].outputName)) {
543 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
544 exit(1);
545 }
546 }
547
548 if (seqRequest[i].flags & SEQ_UNITSGIVEN &&
549 !SDDS_ChangeColumnInformation(&SDDSout, "units", seqRequest[i].units, SDDS_SET_BY_NAME, seqRequest[i].outputName))
550 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
551 }
552
553 if (verbose)
554 fprintf(stderr, "Initialized input files\n");
555
556 if (columnMajorOrder != -1)
557 SDDSout.layout.data_mode.column_major = columnMajorOrder;
558 else
559 SDDSout.layout.data_mode.column_major = 0;
560
561 if (!SDDS_WriteLayout(&SDDSout))
562 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
563
564 if (randomNumberSeed <= 0) {
565 randomNumberSeed = (long)time((time_t *)NULL);
566 randomNumberSeed = 2 * (randomNumberSeed / 2) + 1;
567#if defined(_WIN32) || defined(darwin)
568 random_1(-labs(randomNumberSeed));
569#else
570 random_1(-FABS(randomNumberSeed));
571#endif
572 } else
573 random_1(-randomNumberSeed);
574
575 if (!((sample = calloc(sizeof(*sample), samples))))
576 SDDS_Bomb("memory allocation failure");
577 while (1) {
578 if (verbose)
579 fprintf(stderr, "Beginning page loop\n");
580 if (input && SDDS_ReadPage(&SDDSin) <= 0)
581 break;
582 for (i = 0; i < seqRequests; i++) {
583 if (seqRequest[i].flags & SEQ_DATAFILE && SDDS_ReadPage(&seqRequest[i].SDDSin) <= 0)
584 break;
585 }
586 if (i != seqRequests)
587 break;
588 if (!SDDS_StartPage(&SDDSout, samples) || (input && !SDDS_CopyParameters(&SDDSout, &SDDSin)))
589 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
590 if (verbose)
591 fprintf(stderr, "Defining randomization tables\n");
592 /* define randomization tables */
593 for (i = 0; i < randomizationGroups; i++) {
594 if (!(randomizationData[i].order = SDDS_Malloc(sizeof(*randomizationData[i].order) * samples)))
595 SDDS_Bomb("memory allocation failure");
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);
599 }
600 if (verbose)
601 fprintf(stderr, "Beginning loop over sequence requests\n");
602 for (i = 0; i < seqRequests; i++) {
603 if (verbose)
604 fprintf(stderr, "Processing sequence request %ld\n", i);
605 if (seqRequest[i].flags & SEQ_DIRECT_GAUSSIAN) {
606 if ((seqRequest[i].meanPar &&
607 !SDDS_GetParameterAsDouble(&SDDSin, seqRequest[i].meanPar, &seqRequest[i].mean)) ||
608 (seqRequest[i].sigmaPar &&
609 !SDDS_GetParameterAsDouble(&SDDSin, seqRequest[i].sigmaPar, &seqRequest[i].sigma)))
610 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
611 for (j = 0; j < samples; j++)
612 sample[j] = gauss_rn_lim(seqRequest[i].mean, seqRequest[i].sigma, -1, random_1);
613 } else if (seqRequest[i].flags & SEQ_DIRECT_UNIFORM) {
614 if ((seqRequest[i].minPar &&
615 !SDDS_GetParameterAsDouble(&SDDSin, seqRequest[i].minPar, &seqRequest[i].min)) ||
616 (seqRequest[i].maxPar &&
617 !SDDS_GetParameterAsDouble(&SDDSin, seqRequest[i].maxPar, &seqRequest[i].max)))
618 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
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 &&
626 !SDDS_GetParameterAsDouble(&SDDSin, seqRequest[i].meanPar, &seqRequest[i].mean)))
627 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
628 pos_points = CreatePoissonDistributionTable(&pos_x, &pos_cdf, seqRequest[i].mean);
629
630 for (j = 0; j < samples; j++) {
631 CDF = random_1(1);
632 sample[j] = (int)(interp(pos_x, pos_cdf, pos_points, CDF, 0, 1, &code));
633 /* fprintf(stderr, "%d, cdf=%f, sample=%f\n", j, CDF, sample[j]); */
634 }
635 free(pos_x);
636 free(pos_cdf);
637 } else {
638 if (input && !(seqRequest[i].flags & SEQ_DATAFILE))
639 SDDSptr = &SDDSin;
640 else
641 SDDSptr = &seqRequest[i].SDDSin;
642 if ((values = SDDS_CountRowsOfInterest(SDDSptr))) {
643 if (!(IVValue = SDDS_GetColumnInDoubles(SDDSptr, seqRequest[i].indepName)) ||
644 (seqRequest[i].flags & SEQ_CDFNAME &&
645 !(CDFValue = SDDS_GetColumnInDoubles(SDDSptr, seqRequest[i].CDFName))) ||
646 (seqRequest[i].flags & SEQ_DFNAME &&
647 !(CDFValue = SDDS_GetColumnInDoubles(SDDSptr, seqRequest[i].DFName))))
648 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
649 } else {
650 sprintf(msgBuffer, "empty page for file %s\n", seqRequest[i].flags & SEQ_DATAFILE ? seqRequest[i].dataFileName : input);
651 SDDS_Bomb(msgBuffer);
652 }
653 if (verbose)
654 fprintf(stderr, "Checking and converting CDF/DF values\n");
655 /* check/convert CDF/DF values */
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);
659 SDDS_Bomb(msgBuffer);
660 }
661 if (seqRequest[i].flags & SEQ_DFNAME)
662 /* convert DF to CDF */
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);
666 SDDS_Bomb(msgBuffer);
667 }
668 }
669 if (verbose)
670 fprintf(stderr, "Normalizing CDF\n");
671 /* normalize the CDF */
672 if (CDFValue[values - 1] <= 0) {
673 sprintf(msgBuffer, "CDF not valid for %s\n", seqRequest[i].dataFileName);
674 SDDS_Bomb(msgBuffer);
675 }
676 for (j = 0; j < values; j++)
677 CDFValue[j] /= CDFValue[values - 1];
678 if (seqRequest[i].flags & SEQ_HALTONRADIX) {
679 if (verbose)
680 fprintf(stderr, "Starting halton sequence, offset=%" PRId32 "\n", seqRequest[i].haltonOffset);
681 if (!optimalHalton)
682 haltonID = startHaltonSequence(&seqRequest[i].haltonRadix, 0.5);
683 else
684 haltonID = startModHaltonSequence(&seqRequest[i].haltonRadix, 0);
685 while (seqRequest[i].haltonOffset-- > 0) {
686 if (!optimalHalton)
687 nextHaltonSequencePoint(haltonID);
688 else
690 }
691 }
692 if (verbose)
693 fprintf(stderr, "Generating samples\n");
694 for (j = 0; j < samples; j++) {
695 double CDF;
696 long code;
697 while (1) {
698 if (seqRequest[i].flags & SEQ_HALTONRADIX) {
699 if (!optimalHalton)
700 CDF = nextHaltonSequencePoint(haltonID);
701 else
702 CDF = nextModHaltonSequencePoint(haltonID);
703 } else
704 CDF = random_1(1);
705 if (CDF <= CDFValue[values - 1] && CDF >= CDFValue[0])
706 break;
707 }
708 sample[j] = seqRequest[i].factor * interp(IVValue, CDFValue, values, CDF, 0, 1, &code) + seqRequest[i].offset;
709 }
710 if (seqRequest[i].flags & SEQ_RANDOMIZE) {
711 long k, l;
712 double *sample1;
713 if (verbose)
714 fprintf(stderr, "Randomizing order of values\n");
715 if (!(sample1 = malloc(sizeof(*sample1) * samples)))
716 SDDS_Bomb("memory allocation failure");
717 for (l = 0; l < randomizationGroups; l++)
718 if (randomizationData[l].group == seqRequest[i].randomizationGroup)
719 break;
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]];
724 free(sample);
725 sample = sample1;
726 }
727 free(IVValue);
728 free(CDFValue);
729 }
730 if (verbose)
731 fprintf(stderr, "Setting SDDS column values\n");
732 if (!SDDS_SetColumnFromDoubles(&SDDSout, SDDS_SET_BY_NAME, sample, samples,
733 seqRequest[i].outputName ? seqRequest[i].outputName : seqRequest[i].indepName))
734 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
735 }
736 if (verbose)
737 fprintf(stderr, "Writing data page\n");
738 if (!SDDS_WritePage(&SDDSout))
739 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
740 if (!requireInput)
741 break;
742 }
743 if (verbose)
744 fprintf(stderr, "Exited read loop\n");
745 free(sample);
746 if ((input && !SDDS_Terminate(&SDDSin)) || !SDDS_Terminate(&SDDSout))
747 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
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)))
770 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
771 }
772 free(seqRequest);
773 for (i = 0; i < randomizationGroups; i++)
774 free(randomizationData[i].order);
775 if (randomizationData)
776 free(randomizationData);
777
778 free_scanargs(&scanned, argc);
779
780 return (0);
781}
782
783long CreatePoissonDistributionTable(double **x, double **pos_CDF, double mean) {
784 long i, npoints = 20, count = 0;
785 double *pos = NULL;
786 /*SDDS_DATASET pos_out; */
787
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.");
793 i = count = 0;
794 while (1) {
795 if (count + 2 >= npoints) {
796 npoints += 20;
797 *x = SDDS_Realloc(*x, sizeof(**x) * npoints);
798 *pos_CDF = SDDS_Realloc(*pos_CDF, sizeof(**pos_CDF) * npoints);
799 pos = SDDS_Realloc(pos, sizeof(*pos) * npoints);
800 }
801
802 (*x)[count] = i;
803 if (!i) {
804 pos[i] = exp(-mean);
805 (*pos_CDF)[count] = pos[i];
806 count++;
807 } else {
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];
811 (*x)[count + 1] = i;
812 if (1.0 - (*pos_CDF)[count + 1] <= 1.0e-15)
813 break;
814 count += 2;
815 }
816 i++;
817 }
818 /* fprintf(stderr,"lamda=%f\n", mean);
819 if (!SDDS_InitializeOutput(&pos_out, SDDS_BINARY, 0, NULL, NULL, "pos_dist.sdds"))
820 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors);
821 if (!SDDS_DefineSimpleColumn(&pos_out, "Count", NULL, SDDS_DOUBLE) ||
822 !SDDS_DefineSimpleColumn(&pos_out, "P", NULL, SDDS_DOUBLE))
823 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors);
824 if (!SDDS_SaveLayout(&pos_out) || !SDDS_WriteLayout(&pos_out))
825 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors);
826 if (!SDDS_StartPage(&pos_out, count) ||
827 !SDDS_SetColumnFromDoubles(&pos_out, SDDS_SET_BY_NAME, *x, count, "Count") ||
828 !SDDS_SetColumnFromDoubles(&pos_out, SDDS_SET_BY_NAME, *pos_CDF, count, "P"))
829 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors);
830 if (!SDDS_WritePage(&pos_out) || !SDDS_Terminate(&pos_out))
831 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors);
832 */
833 free(pos);
834 return count;
835}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_CopyParameters(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:286
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.
double * SDDS_GetParameterAsDouble(SDDS_DATASET *SDDS_dataset, char *parameter_name, double *memory)
Retrieves the value of a specified parameter as a double from the current data table of an SDDS datas...
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
double * SDDS_GetColumnInDoubles(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves the data of a specified numerical column as an array of doubles, considering only rows mark...
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.
Definition SDDS_info.c:364
int32_t SDDS_InitializeInput(SDDS_DATASET *SDDS_dataset, char *filename)
Definition SDDS_input.c:49
int32_t SDDS_Terminate(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_ReadPage(SDDS_DATASET *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.
Definition SDDS_utils.c:432
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
Definition SDDS_utils.c:639
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
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.
Definition SDDS_utils.c:856
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
#define SDDS_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric type.
Definition SDDStypes.h:157
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
long bitsSet(unsigned long data)
Counts the number of set bits (1s) in the given data.
Definition binary.c:52
int get_double(double *dptr, char *s)
Parses a double value from the given string.
Definition data_scan.c:40
double random_1(long iseed)
Generate a uniform random double in [0,1] using a custom seed initialization.
Definition drand.c:175
long randomizeOrder(char *ptr, long size, long length, long iseed, double(*urandom)(long iseed1))
Randomize the order of an array of elements.
Definition drand.c:465
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.
Definition drand.c:378
int64_t is_prime(int64_t number)
Determine if a number is prime.
Definition factorize.c:26
long fexists(const char *filename)
Checks if a file exists.
Definition fexists.c:27
int32_t startModHaltonSequence(int32_t *radix, double tiny)
Start a modified Halton sequence.
Definition halton.c:508
double nextModHaltonSequencePoint(long ID)
Retrieve the next point from the modified Halton sequence.
Definition halton.c:624
int32_t startHaltonSequence(int32_t *radix, double value)
Initialize and start a new Halton sequence.
Definition halton.c:38
double nextHaltonSequencePoint(long ID)
Get the next point in a Halton sequence.
Definition halton.c:107
double interp(double *f, double *x, long n, double xo, long warnings, long order, long *returnCode)
Performs simple linear interpolation of data.
Definition interp.c:34
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)
Definition scanargs.c:36
long processPipeOption(char **item, long items, unsigned long *flags)
Definition scanargs.c:356
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
Definition scanargs.c:390
void free_scanargs(SCANNED_ARG **scanned, int argc)
Definition scanargs.c:584
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.
Definition wild_match.c:49