75 {
76 int n_test = 100;
77 double min_temp, max_temp;
78 double gap, lower, upper;
79 double margin = 0.3;
81 char *input_file = NULL, *output_file = NULL, **column = NULL;
82 long tmpfile_used = 0, columns = 0, no_warnings = 1;
83 unsigned long pipe_flags;
84 long i, i_arg, j;
85 SCANNED_ARG *s_arg;
86 double *column_data = NULL, *pdf = NULL, *cdf = NULL;
87 char buffer_pdf[1024], buffer_cdf[1024], buffer_pdf_units[1024];
88 int64_t rows;
89
92 pipe_flags = 0;
93
94 if (argc < 2) {
95 fprintf(stderr, "%s", usage);
96 exit(EXIT_FAILURE);
97 }
98
99 for (i_arg = 1; i_arg < argc; i_arg++) {
100 if (s_arg[i_arg].arg_type == OPTION) {
102 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
103 case SET_COLUMN:
104 columns = s_arg[i_arg].n_items - 1;
105 column = realloc(column, sizeof(*column) * columns);
106 for (i = 1; i < s_arg[i_arg].n_items; i++) {
107 column[i - 1] = s_arg[i_arg].list[i];
108 }
109 break;
110 case SET_MARGIN:
111 if (s_arg[i_arg].n_items != 2) {
113 }
114 if (!
get_double(&margin, s_arg[i_arg].list[1])) {
115 SDDS_Bomb(
"Invalid -margin value provided!");
116 }
117 break;
118 case SET_PIPE:
119 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipe_flags)) {
120 fprintf(stderr, "Error (%s): invalid -pipe syntax\n", argv[0]);
121 return EXIT_FAILURE;
122 }
123 break;
124 default:
125 fprintf(stderr, "Unknown option: %s\n", s_arg[i_arg].list[0]);
126 exit(EXIT_FAILURE);
127 }
128 } else {
129 if (!input_file) {
130 input_file = s_arg[i_arg].list[0];
131 } else if (!output_file) {
132 output_file = s_arg[i_arg].list[0];
133 } else {
134 fprintf(stderr, "Error (%s): too many filenames\n", argv[0]);
135 return EXIT_FAILURE;
136 }
137 }
138 }
139
140 processFilenames(
"sddskde", &input_file, &output_file, pipe_flags, no_warnings, &tmpfile_used);
141
142 if (!columns) {
143 fprintf(stderr, "%s", usage);
145 }
146
149 return EXIT_FAILURE;
150 }
151
152 if ((columns = expandColumnPairNames(&sdds_in, &column, NULL, columns, NULL, 0, FIND_NUMERIC_TYPE, 0)) <= 0) {
155 }
156
159 }
160
161 for (i = 0; i < columns; i++) {
162 char *units = NULL;
165 }
166
167 if (units && strlen(units)) {
168 snprintf(buffer_pdf_units, sizeof(buffer_pdf_units), "1/(%s)", units);
169 } else {
170 buffer_pdf_units[0] = '\0';
171 }
172
173 free(units);
174
175 snprintf(buffer_pdf, sizeof(buffer_pdf), "%sPDF", column[i]);
176 snprintf(buffer_cdf, sizeof(buffer_cdf), "%sCDF", column[i]);
177
182 }
183 }
184
187 }
188
189 pdf = malloc(sizeof(*pdf) * n_test);
190 cdf = malloc(sizeof(*cdf) * n_test);
191
196 }
197
198 for (i = 0; i < columns; i++) {
199 snprintf(buffer_pdf, sizeof(buffer_pdf), "%sPDF", column[i]);
200 snprintf(buffer_cdf, sizeof(buffer_cdf), "%sCDF", column[i]);
201
204 }
205
207 gap = max_temp - min_temp;
208 lower = min_temp - gap * margin;
209 upper = max_temp + gap * margin;
210
211 double *x_array = linearspace(lower, upper, n_test);
212
213 for (j = 0; j < n_test; j++) {
214 pdf[j] = kerneldensityestimate(column_data, x_array[j], rows);
215 cdf[j] = pdf[j];
216 }
217
218 for (j = 1; j < n_test; j++) {
219 cdf[j] += cdf[j - 1];
220 }
221
222 for (j = 0; j < n_test; j++) {
223 cdf[j] = cdf[j] / cdf[n_test - 1];
224 }
225
230 }
231
232 free(column_data);
233 column_data = NULL;
234
235 free(x_array);
236 x_array = NULL;
237 }
238 }
239
242 }
243 }
244
245 free(pdf);
246 free(cdf);
247
250 }
251
253 return EXIT_FAILURE;
254 }
255
256 free(column);
257
258 return EXIT_SUCCESS;
259}
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)