88 {
89 int n_test = 100;
90 double min_temp, max_temp;
91 double bwidth, gap, h, lower, upper;
92 double margin = 0.3;
94 char *input_file = NULL, *output_file = NULL, **column = NULL;
95 long tmpfile_used = 0, columns = 0, no_warnings = 1;
96 unsigned long pipe_flags;
97 long i, i_arg, j;
98 SCANNED_ARG *s_arg;
99 double *column_data = NULL, *pdf = NULL, *cdf = NULL;
100 char buffer_pdf[1024], buffer_cdf[1024], buffer_pdf_units[1024];
101 int64_t rows;
102 int threads = 1;
103
105 argc =
scanargs(&s_arg, argc, argv);
106 pipe_flags = 0;
107
108 if (argc < 2) {
109 fprintf(stderr, "%s", usage);
110 exit(EXIT_FAILURE);
111 }
112
113 for (i_arg = 1; i_arg < argc; i_arg++) {
114 if (s_arg[i_arg].arg_type == OPTION) {
116 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
117 case SET_COLUMN:
118 columns = s_arg[i_arg].n_items - 1;
119 column = realloc(column, sizeof(*column) * columns);
120 for (i = 1; i < s_arg[i_arg].n_items; i++) {
121 column[i - 1] = s_arg[i_arg].list[i];
122 }
123 break;
124 case SET_MARGIN:
125 if (s_arg[i_arg].n_items != 2) {
127 }
128 if (!
get_double(&margin, s_arg[i_arg].list[1])) {
129 SDDS_Bomb(
"Invalid -margin value provided!");
130 }
131 break;
132 case SET_THREADS:
133 if (s_arg[i_arg].n_items != 2 ||
134 sscanf(s_arg[i_arg].list[1], "%d", &threads) != 1 || threads < 1) {
136 }
137 break;
138 case SET_PIPE:
139 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipe_flags)) {
140 fprintf(stderr, "Error (%s): invalid -pipe syntax\n", argv[0]);
141 return EXIT_FAILURE;
142 }
143 break;
144 default:
145 fprintf(stderr, "Unknown option: %s\n", s_arg[i_arg].list[0]);
146 exit(EXIT_FAILURE);
147 }
148 } else {
149 if (!input_file) {
150 input_file = s_arg[i_arg].list[0];
151 } else if (!output_file) {
152 output_file = s_arg[i_arg].list[0];
153 } else {
154 fprintf(stderr, "Error (%s): too many filenames\n", argv[0]);
155 return EXIT_FAILURE;
156 }
157 }
158 }
159
160 processFilenames(
"sddskde", &input_file, &output_file, pipe_flags, no_warnings, &tmpfile_used);
161
162 if (!columns) {
163 fprintf(stderr, "%s", usage);
165 }
166
169 return EXIT_FAILURE;
170 }
171
172 if ((columns = expandColumnPairNames(&sdds_in, &column, NULL, columns, NULL, 0, FIND_NUMERIC_TYPE, 0)) <= 0) {
175 }
176
179 }
180
181 for (i = 0; i < columns; i++) {
182 char *units = NULL;
185 }
186
187 if (units && strlen(units)) {
188 snprintf(buffer_pdf_units, sizeof(buffer_pdf_units), "1/(%s)", units);
189 } else {
190 buffer_pdf_units[0] = '\0';
191 }
192
193 free(units);
194
195 snprintf(buffer_pdf, sizeof(buffer_pdf), "%sPDF", column[i]);
196 snprintf(buffer_cdf, sizeof(buffer_cdf), "%sCDF", column[i]);
197
202 }
203 }
204
207 }
208
209 pdf = malloc(sizeof(*pdf) * n_test);
210 cdf = malloc(sizeof(*cdf) * n_test);
211
216 }
217
218 for (i = 0; i < columns; i++) {
219 snprintf(buffer_pdf, sizeof(buffer_pdf), "%sPDF", column[i]);
220 snprintf(buffer_cdf, sizeof(buffer_cdf), "%sCDF", column[i]);
221
224 }
225
227 gap = max_temp - min_temp;
228 lower = min_temp - gap * margin;
229 upper = max_temp + gap * margin;
230
231 double *x_array = linearspace(lower, upper, n_test);
232 bwidth = bandwidth(column_data, rows);
233 h = GSL_MAX(bwidth, 2e-6);
234
235#pragma omp parallel for if (threads > 1) num_threads(threads)
236 for (j = 0; j < n_test; j++) {
237 pdf[j] = kerneldensityestimate(column_data, x_array[j], rows, h);
238 cdf[j] = pdf[j];
239 }
240
241 for (j = 1; j < n_test; j++) {
242 cdf[j] += cdf[j - 1];
243 }
244
245 for (j = 0; j < n_test; j++) {
246 cdf[j] = cdf[j] / cdf[n_test - 1];
247 }
248
253 }
254
255 free(column_data);
256 column_data = NULL;
257
258 free(x_array);
259 x_array = NULL;
260 }
261 }
262
265 }
266 }
267
268 free(pdf);
269 free(cdf);
270
273 }
274
276 return EXIT_FAILURE;
277 }
278
279 free(column);
280
281 return EXIT_SUCCESS;
282}
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_GetColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified column in 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_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_DefineColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length)
Defines a data column within the SDDS dataset.
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.
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.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_DOUBLE
Identifier for the double data type.
int get_double(double *dptr, char *s)
Parses a double value from the given string.
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
int find_min_max(double *min, double *max, double *list, int64_t n)
Finds the minimum and maximum values in a list of doubles.
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.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
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)