SDDSlib
Loading...
Searching...
No Matches
sdds2dinterpolate.c
Go to the documentation of this file.
1/**
2 * @file sdds2dinterpolate.c
3 * @brief Interpolates scalar 2D data at specified points using Natural Neighbours or Cubic Spline Approximation.
4 *
5 * This program reads 2D scalar data from an SDDS file, performs interpolation at specified output points,
6 * and writes the interpolated data to an output SDDS file. Various options are available to control
7 * the interpolation process, scaling, output grid, and other parameters.
8 *
9 * @section Usage
10 * ```
11 * sdds2dinterpolate <input> <output> [options]
12 * ```
13 *
14 * @section Options
15 * -pipe=[input][,output]
16 * -independentColumn=xcolumn=<string>,ycolumn=<string>[,errorColumn=<string>]
17 * -dependentColumn=<list of z column names separated by comma>
18 * -scale=circle|square
19 * -outDimension=xdimension=<nx>,ydimension=<ny>
20 * -range=xminimum=<value>,xmaximum=<value>,yminimum=<value>,ymaximum=<value>
21 * -zoom=<value>
22 * -dimensionThin=xdimension=<nx>,ydimension=<ny>
23 * -clusterThin=<value>
24 * -preprocess
25 * -algorithm=<string>,linear|sibson|nonsibson[,average=<value>][,sensitivity=<value>]
26 * -weight=<value>
27 * -vertex=<id>
28 * -npoints=<integer>
29 * -verbose
30 * -merge
31 * -file=<output points file>[,<xName>,<yName>]
32 * -majorOrder=row|column
33 *
34 * @note
35 * Converted from `nnbathy.c` by Hairong Shang (April 2007) for interpolating scalar 2D data in specified points
36 * using Natural Neighbours interpolation. The interpolated values are written to an SDDS file.
37 *
38 * @copyright
39 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
40 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
41 *
42 * @license
43 * This file is distributed under the terms of the Software License Agreement
44 * found in the file LICENSE included with this distribution.
45 *
46 * @author H. Shang, R. Soliday, L. Emery, M. Borland
47 */
48
49#include "SDDS.h"
50#include "mdb.h"
51#include "scan.h"
52#include "nn_2d_interpolate.h"
53#include "csa.h"
54
55/* Enumeration for option types */
56enum option_type {
57 CLO_PIPE,
58 CLO_INDEPENDENT_COLUMN,
59 CLO_DEPENDENT_COLUMN,
60 CLO_SCALE,
61 CLO_OUT_DIMENSION,
62 CLO_RANGE,
63 CLO_ZOOM,
64 CLO_DIMENSION_THIN,
65 CLO_CLUSTER_THIN,
66 CLO_PREPROCESS,
67 CLO_ALGORITHM,
68 CLO_WEIGHT,
69 CLO_VERTEX,
70 CLO_NPOINTS,
71 CLO_VERBOSE,
72 CLO_MERGE,
73 CLO_FILE,
74 CLO_MAJOR_ORDER,
75 N_OPTIONS
76};
77
78char *option[N_OPTIONS] = {
79 "pipe", "independentColumn", "dependentColumn", "scale",
80 "outDimension", "range", "zoom", "dimensionThin", "clusterThin",
81 "preprocess", "algorithm", "weight", "vertex", "npoints", "verbose", "merge", "file", "majorOrder"};
82
83static const char *USAGE =
84 "Usage: sdds2dinterpolate <input> <output> [options]\n"
85 "\n"
86 "Options:\n"
87 " -pipe=[input][,output]\n"
88 " -independentColumn=xcolumn=<string>,ycolumn=<string>[,errorColumn=<string>]\n"
89 " -dependentColumn=<list of z column names separated by comma>\n"
90 " -scale=circle|square\n"
91 " -outDimension=xdimension=<nx>,ydimension=<ny>\n"
92 " -range=xminimum=<value>,xmaximum=<value>,yminimum=<value>,ymaximum=<value>\n"
93 " -zoom=<value>\n"
94 " -dimensionThin=xdimension=<nx>,ydimension=<ny>\n"
95 " -clusterThin=<value>\n"
96 " -preprocess\n"
97 " -algorithm=<string>,linear|sibson|nonsibson[,average=<value>][,sensitivity=<value>]\n"
98 " -weight=<value>\n"
99 " -vertex=<id>\n"
100 " -npoints=<integer>\n"
101 " -verbose\n"
102 " -merge\n"
103 " -file=<output points file>[,<xName>,<yName>]\n"
104 " -majorOrder=row|column\n"
105 "\n"
106 "Detailed option descriptions are as follows:\n"
107 " -independentColumn: Specifies the independent columns for X, Y, and optional error.\n"
108 " -dependentColumn: Specifies the dependent Z columns to interpolate.\n"
109 " -scale: Choose between 'circle' or 'square' scaling methods.\n"
110 " -outDimension: Define the output grid dimensions in X and Y.\n"
111 " -range: Set the minimum and maximum values for X and Y in the output grid.\n"
112 " -zoom: Zoom in or out on the output grid.\n"
113 " -dimensionThin: Thin input data by averaging within specified grid dimensions.\n"
114 " -clusterThin: Thin input data by clustering points based on a maximum distance.\n"
115 " -preprocess: Output data without performing interpolation.\n"
116 " -algorithm: Select the interpolation algorithm and its parameters.\n"
117 " -weight: Set the minimal allowed weight for a vertex.\n"
118 " -vertex: Enable verbose output for a specific vertex.\n"
119 " -npoints: Define the number of output points.\n"
120 " -verbose: Enable verbose output during processing.\n"
121 " -merge: Merge data from all input pages before interpolation.\n"
122 " -file: Specify an SDDS file with output points.\n"
123 " -majorOrder: Set the output file's data order to 'row' or 'column'.\n"
124 "Program by Hairong Shang. " __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION "\n";
125
126/* Struct for output points */
127typedef struct
128{
129 double xmin, xmax, ymin, ymax, dx, dy;
130 int nx, ny, nout;
131 point *pout;
132} OUT_POINT;
133
134#define ALGORITHMS 2
135#define LINEAR_NN 0x0001UL
136#define SIBSON_NN 0x0002UL
137#define NONSIBSON_NN 0x0004UL
138
139char *algorithm_option[ALGORITHMS] = {"nn", "csa"};
140
141#define SCALE_OPTIONS 2
142char *scale_option[SCALE_OPTIONS] = {"circle", "square"};
143
144/* Function prototypes */
145void ReadInputFile(char *inputFile, char *xCol, char *yCol, char **zColMatch, long zColMatches, char ***zCol, int32_t *zCols,
146 char *stdCol, long *pages, long **rows, double ***x, double ***y, double ****z, double ***std, SDDS_DATASET *SDDS_in);
147void SetupOutputFile(SDDS_DATASET *SDDS_out, SDDS_DATASET *SDDS_in, char *outputFile, char *xCol, char *yCol,
148 char *xName, char *yName, char **zCol, long zCols, short columnMajorOrder);
149void WriteOutputPage(SDDS_DATASET *SDDS_out, char *xCol, char *yCol, char *zCol, specs *spec, int nout, point *pout, long writepage);
150void ReadPointFile(char *pointsFile, char *xCol, char *yCol, long *point_pages, OUT_POINT **out_point);
151int interpolate_output_points(int nin, point **pin, double *std, char *xCol, char *yCol, char *xName, char *yName,
152 char **zCol, long zCols, specs *spec, long pages, OUT_POINT *out_point, SDDS_DATASET *SDDS_out);
153
154static char *INFINITY_OPTION[1] = {"infinity"};
155
156int main(int argc, char *argv[]) {
157 SDDS_DATASET SDDS_out, SDDS_in;
158 char *inputFile, *outputFile, *xCol = "x", *yCol = "y", **zCol = NULL, *stdCol = "StdError", *pointsFile = NULL, **zColMatch = NULL;
159 char *pointsFileXName = NULL, *pointsFileYName = NULL;
160 long i, j, i_arg, k, scale, *rows, pages, merge = 0, point_pages = 0, writepage = 0, zColMatches = 0;
161 int32_t zCols = 1;
162 unsigned long dummyFlags = 0, pipeFlags = 0, majorOrderFlag;
163 SCANNED_ARG *s_arg;
164 double **x = NULL, **y = NULL, ***z = NULL, xmin = 0, xmax = 0, ymin = 0, ymax = 0, **std = NULL, *std_all = NULL;
165 specs *spec = specs_create();
166 int nin = 0;
167 point **pin = NULL;
168 int nout = 0;
169 point *pout = NULL;
170 OUT_POINT *out_point = NULL;
171 short columnMajorOrder = -1;
172
173 /* Turn off the extrapolation by default */
174 spec->wmin = 0;
175 inputFile = outputFile = NULL;
177 argc = scanargs(&s_arg, argc, argv);
178 if (argc < 2) {
179 fprintf(stderr, "%s", USAGE);
180 return EXIT_FAILURE;
181 }
182
183 for (i_arg = 1; i_arg < argc; i_arg++) {
184 if (s_arg[i_arg].arg_type == OPTION) {
185 delete_chars(s_arg[i_arg].list[0], "_");
186 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
187 case CLO_MAJOR_ORDER:
188 majorOrderFlag = 0;
189 s_arg[i_arg].n_items -= 1;
190 if (s_arg[i_arg].n_items > 0 &&
191 (!scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
192 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
193 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL))) {
194 SDDS_Bomb("Invalid -majorOrder syntax/values");
195 }
196 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
197 columnMajorOrder = 1;
198 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
199 columnMajorOrder = 0;
200 break;
201 case CLO_FILE:
202 if (s_arg[i_arg].n_items != 2 && s_arg[i_arg].n_items != 4)
203 SDDS_Bomb("Invalid -file syntax.");
204 pointsFile = s_arg[i_arg].list[1];
205 if (s_arg[i_arg].n_items == 4) {
206 pointsFileXName = s_arg[i_arg].list[2];
207 pointsFileYName = s_arg[i_arg].list[3];
208 }
209 break;
210 case CLO_PIPE:
211 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
212 SDDS_Bomb("Invalid -pipe syntax");
213 break;
214 case CLO_INDEPENDENT_COLUMN:
215 if (s_arg[i_arg].n_items < 3)
216 SDDS_Bomb("Invalid -independentColumn syntax.");
217 s_arg[i_arg].n_items--;
218 if (!scanItemList(&dummyFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
219 "xcolumn", SDDS_STRING, &xCol, 1, 0,
220 "ycolumn", SDDS_STRING, &yCol, 1, 0,
221 "errorcolumn", SDDS_STRING, &stdCol, 1, 0, NULL))
222 SDDS_Bomb("Invalid -independentColumn syntax");
223 s_arg[i_arg].n_items++;
224 break;
225 case CLO_DEPENDENT_COLUMN:
226 if (s_arg[i_arg].n_items < 2)
227 SDDS_Bomb("Invalid -dependentColumn syntax.");
228 zColMatches = s_arg[i_arg].n_items - 1;
229 zColMatch = tmalloc(sizeof(*zColMatch) * zColMatches);
230 for (i = 0; i < zColMatches; i++)
231 zColMatch[i] = s_arg[i_arg].list[i + 1];
232 break;
233 case CLO_SCALE:
234 if (s_arg[i_arg].n_items != 2)
235 SDDS_Bomb("Invalid -scale syntax.");
236 if ((scale = match_string(s_arg[i_arg].list[1], scale_option, SCALE_OPTIONS, 0)) == -1) {
237 fprintf(stderr, "Invalid scale option - %s provided.\n", s_arg[i_arg].list[1]);
238 exit(EXIT_FAILURE);
239 }
240 spec->square = !scale;
241 spec->invariant = scale;
242 break;
243 case CLO_OUT_DIMENSION:
244 if (s_arg[i_arg].n_items != 3)
245 SDDS_Bomb("Invalid -outDimension syntax.");
246 s_arg[i_arg].n_items--;
247 if (!scanItemList(&dummyFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
248 "xdimension", SDDS_LONG, &spec->nx, 1, 0,
249 "ydimension", SDDS_LONG, &spec->ny, 1, 0, NULL))
250 SDDS_Bomb("Invalid -outDimension syntax");
251 s_arg[i_arg].n_items++;
252 if (spec->nx <= 0 || spec->nx > NMAX || spec->ny <= 0 || spec->ny > NMAX)
253 SDDS_Bomb("Invalid size for output grid.");
254 spec->generate_points = 1;
255 break;
256 case CLO_RANGE:
257 if (s_arg[i_arg].n_items < 2)
258 SDDS_Bomb("Invalid -range syntax.");
259 s_arg[i_arg].n_items--;
260 if (!scanItemList(&dummyFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
261 "xminimum", SDDS_DOUBLE, &spec->xmin, 1, 0,
262 "xmaximum", SDDS_DOUBLE, &spec->xmax, 1, 0,
263 "yminimum", SDDS_DOUBLE, &spec->ymin, 1, 0,
264 "ymaximum", SDDS_DOUBLE, &spec->ymax, 1, 0, NULL))
265 SDDS_Bomb("Invalid -range syntax");
266 s_arg[i_arg].n_items++;
267 if (spec->xmin > spec->xmax || spec->ymin > spec->ymax ||
268 isnan(spec->xmin) || isnan(spec->xmax) || isnan(spec->ymin) || isnan(spec->ymax))
269 SDDS_Bomb("Invalid -range provided.");
270 spec->range = 1;
271 break;
272 case CLO_ZOOM:
273 if (s_arg[i_arg].n_items != 2)
274 SDDS_Bomb("Invalid -zoom syntax.");
275 if (!get_double(&spec->zoom, s_arg[i_arg].list[1]))
276 SDDS_Bomb("Invalid -zoom value provided.");
277 break;
278 case CLO_DIMENSION_THIN:
279 if (s_arg[i_arg].n_items != 3)
280 SDDS_Bomb("Invalid -dimensionThin syntax.");
281 s_arg[i_arg].n_items--;
282 if (!scanItemList(&dummyFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
283 "xdimension", SDDS_LONG, &spec->nxd, 1, 0,
284 "ydimension", SDDS_LONG, &spec->nyd, 1, 0, NULL))
285 SDDS_Bomb("Invalid -dimensionThin syntax");
286 s_arg[i_arg].n_items++;
287 spec->thin = 1;
288 break;
289 case CLO_CLUSTER_THIN:
290 if (s_arg[i_arg].n_items != 2)
291 SDDS_Bomb("Invalid -clusterThin syntax.");
292 if (!get_double(&spec->rmax, s_arg[i_arg].list[1]))
293 SDDS_Bomb("Invalid -clusterThin value provided.");
294 spec->thin = 2;
295 break;
296 case CLO_PREPROCESS:
297 spec->nointerp = 1;
298 break;
299 case CLO_ALGORITHM:
300 if (s_arg[i_arg].n_items < 2)
301 SDDS_Bomb("Invalid -algorithm syntax!");
302 if ((spec->method = match_string(s_arg[i_arg].list[1], algorithm_option, ALGORITHMS, 0)) == -1) {
303 fprintf(stderr, "Invalid algorithm - %s provided, has to be nn or csa.\n", s_arg[i_arg].list[1]);
304 exit(EXIT_FAILURE);
305 }
306 dummyFlags = 0;
307 s_arg[i_arg].n_items -= 2;
308 if (!scanItemList(&dummyFlags, s_arg[i_arg].list + 2, &s_arg[i_arg].n_items, 0,
309 "linear", -1, NULL, 0, LINEAR_NN,
310 "sibson", -1, NULL, 0, SIBSON_NN,
311 "nonSibson", -1, NULL, 0, NONSIBSON_NN,
312 "average", SDDS_LONG, &spec->nppc, 1, 0,
313 "sensitivity", SDDS_DOUBLE, &spec->k, 1, 0, NULL))
314 SDDS_Bomb("Invalid -algorithm syntax!");
315 spec->linear = 0;
316 if (!dummyFlags || dummyFlags & LINEAR_NN) {
317 spec->linear = 1;
318 } else if (dummyFlags & SIBSON_NN) {
319 nn_rule = SIBSON;
320 } else if (dummyFlags & NONSIBSON_NN) {
321 nn_rule = NON_SIBSONIAN;
322 }
323 s_arg[i_arg].n_items += 2;
324 break;
325 case CLO_WEIGHT:
326 if (s_arg[i_arg].n_items != 2)
327 SDDS_Bomb("Invalid -weight syntax.");
328 if (match_string(s_arg[i_arg].list[1], INFINITY_OPTION, 1, 0) == 0)
329 spec->wmin = -DBL_MAX;
330 else {
331 if (!get_double(&spec->wmin, s_arg[i_arg].list[1]))
332 SDDS_Bomb("Invalid weight value provided.");
333 }
334 break;
335 case CLO_VERTEX:
336 if (s_arg[i_arg].n_items != 2)
337 SDDS_Bomb("Invalid -vertex syntax.");
338 if (!get_int(&nn_test_vertice, s_arg[i_arg].list[1]))
339 SDDS_Bomb("Invalid vertex value provided.");
340 nn_verbose = 1;
341 break;
342 case CLO_NPOINTS:
343 if (s_arg[i_arg].n_items != 2)
344 SDDS_Bomb("Invalid -npoints syntax.");
345 if (!get_int(&spec->npoints, s_arg[i_arg].list[1]))
346 SDDS_Bomb("Invalid npoints value provided.");
347 break;
348 case CLO_VERBOSE:
349 nn_verbose = 2;
350 break;
351 case CLO_MERGE:
352 merge = 1;
353 break;
354 default:
355 fprintf(stderr, "Unknown option - %s provided.\n", s_arg[i_arg].list[0]);
356 exit(EXIT_FAILURE);
357 break;
358 }
359 } else {
360 if (!inputFile)
361 inputFile = s_arg[i_arg].list[0];
362 else if (!outputFile)
363 outputFile = s_arg[i_arg].list[0];
364 else
365 SDDS_Bomb("Too many files given!");
366 }
367 }
368
369 processFilenames("sdds2dinterpolate", &inputFile, &outputFile, pipeFlags, 0, NULL);
370 if (!spec->generate_points && !spec->nointerp && !pointsFile) {
371 fprintf(stderr, "No output grid specified.\n");
372 exit(EXIT_FAILURE);
373 }
374 if (spec->thin) {
375 if (spec->nxd == -1)
376 spec->nxd = spec->nx;
377 if (spec->nyd == -1)
378 spec->nyd = spec->ny;
379 if (spec->nxd <= 0 || spec->nyd <= 0) {
380 fprintf(stderr, "Invalid grid size for thinning.\n");
381 exit(EXIT_FAILURE);
382 }
383 }
384 if (spec->npoints == 1) {
385 if (spec->nx <= 0)
386 spec->npoints = 0;
387 else
388 spec->npoints = spec->nx * spec->ny;
389 }
390 ReadInputFile(inputFile, xCol, yCol, zColMatch, zColMatches, &zCol, &zCols, stdCol, &pages, &rows, &x, &y, &z, &std, &SDDS_in);
391 if (!spec->nointerp)
392 SetupOutputFile(&SDDS_out, &SDDS_in, outputFile, xCol, yCol, pointsFileXName, pointsFileYName,
393 zCol, zCols, columnMajorOrder);
394 if (!SDDS_Terminate(&SDDS_in))
395 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
396 if (pointsFile)
397 ReadPointFile(pointsFile, pointsFileXName ? pointsFileXName : xCol, pointsFileYName ? pointsFileYName : yCol,
398 &point_pages, &out_point);
399 pin = tmalloc(sizeof(*pin) * zCols);
400 if (merge) {
401 for (i = 0; i < pages; i++) {
402 if (!i) {
403 xmin = xmax = x[0][0];
404 ymin = ymax = y[0][0];
405 }
406 for (k = 0; k < zCols; k++)
407 pin[k] = SDDS_Realloc(pin[k], sizeof(**pin) * (nin + rows[i]));
408 if (std)
409 std_all = SDDS_Realloc(std_all, sizeof(*std_all) * (nin + rows[i]));
410 for (j = 0; j < rows[i]; j++) {
411 if (x[i][j] < xmin)
412 xmin = x[i][j];
413 else if (x[i][j] > xmax)
414 xmax = x[i][j];
415 if (y[i][j] < ymin)
416 ymin = y[i][j];
417 else if (y[i][j] > ymax)
418 ymax = y[i][j];
419 for (k = 0; k < zCols; k++) {
420 pin[k][nin + j].x = x[i][j];
421 pin[k][nin + j].y = y[i][j];
422 pin[k][nin + j].z = z[k][i][j];
423 }
424 if (std)
425 std_all[nin + j] = std[i][j];
426 }
427 nin += rows[i];
428 free(x[i]);
429 free(y[i]);
430 for (k = 0; k < zCols; k++) {
431 free(z[k][i]);
432 z[k][i] = NULL;
433 }
434 if (std && std[i]) {
435 free(std[i]);
436 std[i] = NULL;
437 }
438 x[i] = y[i] = NULL;
439 }
440 free(x);
441 free(y);
442 x = y = NULL;
443 for (k = 0; k < zCols; k++) {
444 free(z[k]);
445 z[k] = NULL;
446 }
447 free(z);
448 z = NULL;
449 if (std)
450 free(std);
451 std = NULL;
452 if (!spec->range) {
453 spec->xmin = xmin;
454 spec->ymin = ymin;
455 spec->xmax = xmax;
456 spec->ymax = ymax;
457 }
458 if (pointsFile) {
459 if (!interpolate_output_points(nin, pin, std_all, xCol, yCol, pointsFileXName, pointsFileYName,
460 zCol, zCols, spec, pages, out_point, &SDDS_out))
461 exit(EXIT_FAILURE);
462 writepage = 1;
463 } else {
464 for (k = 0; k < zCols; k++) {
465 if (spec->method == NN) {
466 do_nn_2d_interpolate(spec, &nin, &pin[k], &nout, &pout);
467 } else if (spec->method == CSA) {
468 do_csa_2d_interpolate(spec, nin, pin[k], &nout, &pout, std_all);
469 }
470 if (!spec->nointerp) {
471 if (!writepage) {
472 WriteOutputPage(&SDDS_out, pointsFileXName ? pointsFileXName : xCol,
473 pointsFileYName ? pointsFileYName : yCol,
474 zCol[k], spec, nout, pout, 0);
475 writepage = 1;
476 } else {
477 for (i = 0; i < nout; i++) {
478 if (!SDDS_SetRowValues(&SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, i,
479 zCol[k], pout[i].z, NULL))
480 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
481 }
482 }
483 }
484 }
485 if (writepage && !SDDS_WritePage(&SDDS_out))
486 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
487 }
488 } else {
489 for (i = 0; i < pages; i++) {
490 xmin = xmax = x[i][0];
491 ymin = ymax = y[i][0];
492 nin = rows[i];
493 for (j = 0; j < nin; j++) {
494 if (x[i][j] < xmin)
495 xmin = x[i][j];
496 else if (x[i][j] > xmax)
497 xmax = x[i][j];
498 if (y[i][j] < ymin)
499 ymin = y[i][j];
500 else if (y[i][j] > ymax)
501 ymax = y[i][j];
502 }
503 if (!spec->range) {
504 spec->xmin = xmin;
505 spec->ymin = ymin;
506 spec->xmax = xmax;
507 spec->ymax = ymax;
508 }
509 for (k = 0; k < zCols; k++) {
510 pin[k] = malloc(sizeof(**pin) * nin);
511 for (j = 0; j < rows[i]; j++) {
512 pin[k][j].x = x[i][j];
513 pin[k][j].y = y[i][j];
514 pin[k][j].z = z[k][i][j];
515 }
516 free(z[k][i]);
517 }
518 free(x[i]);
519 free(y[i]);
520 x[i] = y[i] = NULL;
521 if (std && std[i])
522 std_all = std[i];
523 else
524 std_all = NULL;
525 if (pointsFile) {
526 if (!interpolate_output_points(nin, pin, std_all, xCol, yCol, pointsFileXName, pointsFileYName,
527 zCol, zCols, spec, point_pages, out_point, &SDDS_out))
528 exit(EXIT_FAILURE);
529 writepage = 1;
530 } else {
531 for (k = 0; k < zCols; k++) {
532 if (spec->method == NN) {
533 do_nn_2d_interpolate(spec, &nin, &pin[k], &nout, &pout);
534 } else if (spec->method == CSA) {
535 do_csa_2d_interpolate(spec, nin, pin[k], &nout, &pout, std_all);
536 }
537 if (!spec->nointerp) {
538 if (!writepage) {
539 WriteOutputPage(&SDDS_out, pointsFileXName ? pointsFileXName : xCol,
540 pointsFileYName ? pointsFileYName : yCol,
541 zCol[k], spec, nout, pout, 0);
542 writepage = 1;
543 } else {
544 for (j = 0; j < nout; j++) {
545 if (!SDDS_SetRowValues(&SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, j,
546 zCol[k], pout[j].z, NULL))
547 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
548 }
549 }
550 }
551 }
552 if (std && std[i]) {
553 free(std[i]);
554 std[i] = NULL;
555 }
556 if (writepage && !SDDS_WritePage(&SDDS_out))
557 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
558 }
559 }
560 free(x);
561 free(y);
562 for (k = 0; k < zCols; k++)
563 free(z[k]);
564 free(z);
565 x = y = NULL;
566 }
567 if (std)
568 free(std);
569 for (k = 0; k < zCols; k++)
570 free(pin[k]);
571 free(pin);
572 if (writepage && !SDDS_Terminate(&SDDS_out))
573 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
574 if (point_pages && out_point) {
575 for (i = 0; i < point_pages; i++) {
576 free(out_point[i].pout);
577 }
578 free(out_point);
579 }
580 if (pout)
581 free(pout);
582 free(spec);
583 free(rows);
584 for (i = 0; i < zCols; i++)
585 free(zCol[i]);
586 free(zCol);
587 free_scanargs(&s_arg, argc);
588 return EXIT_SUCCESS;
589}
590
591void ReadInputFile(char *inputFile, char *xCol, char *yCol, char **zColMatch, long zColMatches, char ***zCol, int32_t *zCols,
592 char *stdCol, long *pages, long **rows, double ***x, double ***y, double ****z, double ***std, SDDS_DATASET *SDDS_in) {
593 int64_t rows1 = 0;
594 long i, pages0 = 0, std_exist = 0;
595
596 if (!SDDS_InitializeInput(SDDS_in, inputFile))
597 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
598 if (!zColMatches) {
599 *zCol = tmalloc(sizeof(**zCol));
600 SDDS_CopyString(zCol[0], "z");
601 *zCols = 1;
602 } else {
603 *zCol = getMatchingSDDSNames(SDDS_in, zColMatch, zColMatches, zCols, SDDS_MATCH_COLUMN);
604 free(zColMatch);
605 if (!(*zCols)) {
606 fprintf(stderr, "No dependent columns found in input file.\n");
607 exit(EXIT_FAILURE);
608 }
609 }
610 *z = tmalloc(sizeof(**z) * (*zCols));
611 *rows = NULL;
612 if (SDDS_CheckColumn(SDDS_in, xCol, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) {
613 fprintf(stderr, "X column - %s does not exist!\n", xCol);
614 exit(EXIT_FAILURE);
615 }
616 if (SDDS_CheckColumn(SDDS_in, yCol, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) {
617 fprintf(stderr, "Y column - %s does not exist!\n", yCol);
618 exit(EXIT_FAILURE);
619 }
620 for (i = 0; i < *zCols; i++) {
621 if (SDDS_CheckColumn(SDDS_in, (*zCol)[i], NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) {
622 fprintf(stderr, "Z column - %s does not exist!\n", (*zCol)[i]);
623 exit(EXIT_FAILURE);
624 }
625 }
626 if (SDDS_CheckColumn(SDDS_in, stdCol, NULL, SDDS_ANY_NUMERIC_TYPE, NULL) == SDDS_CHECK_OK)
627 std_exist = 1;
628
629 while (SDDS_ReadPage(SDDS_in) > 0) {
630 rows1 = SDDS_CountRowsOfInterest(SDDS_in);
631 if (!rows1)
632 continue;
633 if (rows1 > INT32_MAX) {
634 fprintf(stderr, "Too many input rows for 2D interpolate library routines.\n");
635 exit(EXIT_FAILURE);
636 }
637 *rows = SDDS_Realloc(*rows, sizeof(**rows) * (pages0 + 1));
638 (*rows)[pages0] = rows1;
639 if (!(*x = SDDS_Realloc(*x, sizeof(**x) * (pages0 + 1))) ||
640 !(*y = SDDS_Realloc(*y, sizeof(**y) * (pages0 + 1)))) {
641 fprintf(stderr, "Memory allocation error for X and Y data.\n");
642 exit(EXIT_FAILURE);
643 }
644 for (i = 0; i < *zCols; i++) {
645 if (!((*z)[i] = SDDS_Realloc((*z)[i], sizeof(***z) * (pages0 + 1)))) {
646 fprintf(stderr, "Memory allocation error for Z data.\n");
647 exit(EXIT_FAILURE);
648 }
649 }
650 if (std_exist) {
651 if (!(*std = SDDS_Realloc(*std, sizeof(**std) * (pages0 + 1)))) {
652 fprintf(stderr, "Memory allocation error for standard error.\n");
653 exit(EXIT_FAILURE);
654 }
655 (*std)[pages0] = NULL;
656 }
657
658 (*x)[pages0] = (*y)[pages0] = NULL;
659 if (!((*x)[pages0] = (double *)SDDS_GetColumnInDoubles(SDDS_in, xCol)) ||
660 !((*y)[pages0] = (double *)SDDS_GetColumnInDoubles(SDDS_in, yCol)))
661 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
662 for (i = 0; i < *zCols; i++) {
663 (*z)[i][pages0] = NULL;
664 if (!((*z)[i][pages0] = (double *)SDDS_GetColumnInDoubles(SDDS_in, (*zCol)[i])))
665 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
666 }
667 if (std_exist && !((*std)[pages0] = (double *)SDDS_GetColumnInDoubles(SDDS_in, stdCol)))
668 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
669 pages0++;
670 }
671
672 if (!pages0) {
673 fprintf(stderr, "No data found in the input file.\n");
674 exit(EXIT_FAILURE);
675 }
676 *pages = pages0;
677 return;
678}
679
680void SetupOutputFile(SDDS_DATASET *SDDS_out, SDDS_DATASET *SDDS_in, char *outputFile, char *xCol, char *yCol,
681 char *xName, char *yName, char **zCol, long zCols, short columnMajorOrder) {
682 char tmpstr[256], *xUnits = NULL, *yUnits = NULL;
683 long i;
684
685 if (!SDDS_InitializeOutput(SDDS_out, SDDS_BINARY, 1, NULL, NULL, outputFile))
686 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
687 if (!SDDS_DefineSimpleParameter(SDDS_out, "Variable1Name", NULL, SDDS_STRING) ||
688 !SDDS_DefineSimpleParameter(SDDS_out, "Variable2Name", NULL, SDDS_STRING) ||
689 !SDDS_TransferColumnDefinition(SDDS_out, SDDS_in, xCol, xName) ||
690 !SDDS_TransferColumnDefinition(SDDS_out, SDDS_in, yCol, yName))
691 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
692 if (columnMajorOrder != -1)
693 SDDS_out->layout.data_mode.column_major = columnMajorOrder;
694 else
695 SDDS_out->layout.data_mode.column_major = SDDS_in->layout.data_mode.column_major;
696 for (i = 0; i < zCols; i++) {
697 if (!SDDS_TransferColumnDefinition(SDDS_out, SDDS_in, zCol[i], NULL))
698 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
699 }
700 if (SDDS_GetColumnInformation(SDDS_in, "units", &xUnits, SDDS_GET_BY_NAME, xCol) != SDDS_STRING ||
701 SDDS_GetColumnInformation(SDDS_in, "units", &yUnits, SDDS_GET_BY_NAME, yCol) != SDDS_STRING)
702 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
703 sprintf(tmpstr, "%sDimension", xName ? xName : xCol);
704 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, NULL, SDDS_LONG))
705 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
706 sprintf(tmpstr, "%sDimension", yName ? yName : yCol);
707 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, NULL, SDDS_LONG))
708 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
709 sprintf(tmpstr, "%sInterval", xName ? xName : xCol);
710 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, xUnits, SDDS_DOUBLE))
711 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
712 sprintf(tmpstr, "%sInterval", yName ? yName : yCol);
713 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, yUnits, SDDS_DOUBLE))
714 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
715 sprintf(tmpstr, "%sMinimum", xName ? xName : xCol);
716 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, xUnits, SDDS_DOUBLE))
717 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
718 sprintf(tmpstr, "%sMinimum", yName ? yName : yCol);
719 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, yUnits, SDDS_DOUBLE))
720 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
721 sprintf(tmpstr, "%sMaximum", xName ? xName : xCol);
722 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, xUnits, SDDS_DOUBLE))
723 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
724 sprintf(tmpstr, "%sMaximum", yName ? yName : yCol);
725 if (!SDDS_DefineSimpleParameter(SDDS_out, tmpstr, yUnits, SDDS_DOUBLE))
726 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
727 if (!SDDS_WriteLayout(SDDS_out))
728 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
729 if (xUnits)
730 free(xUnits);
731 if (yUnits)
732 free(yUnits);
733}
734
735void WriteOutputPage(SDDS_DATASET *SDDS_out, char *xCol, char *yCol, char *zCol, specs *spec, int nout, point *pout, long writepage) {
736 char tmpstr[256];
737 int i;
738
739 if (!SDDS_StartPage(SDDS_out, nout))
740 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
741 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
742 "Variable1Name", xCol,
743 "Variable2Name", yCol, NULL))
744 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
745 sprintf(tmpstr, "%sDimension", xCol);
746 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->nx, NULL))
747 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
748 sprintf(tmpstr, "%sDimension", yCol);
749 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->ny, NULL))
750 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
751 sprintf(tmpstr, "%sInterval", xCol);
752 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->dx, NULL))
753 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
754 sprintf(tmpstr, "%sInterval", yCol);
755 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->dy, NULL))
756 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
757 sprintf(tmpstr, "%sMinimum", xCol);
758 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->xmin, NULL))
759 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
760 sprintf(tmpstr, "%sMinimum", yCol);
761 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->ymin, NULL))
762 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
763 sprintf(tmpstr, "%sMaximum", xCol);
764 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->xmax, NULL))
765 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
766 sprintf(tmpstr, "%sMaximum", yCol);
767 if (!SDDS_SetParameters(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, tmpstr, spec->ymax, NULL))
768 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
769 for (i = 0; i < nout; i++) {
770 if (!SDDS_SetRowValues(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, i,
771 xCol, pout[i].x,
772 yCol, pout[i].y,
773 zCol, pout[i].z, NULL))
774 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
775 }
776 if (writepage && !SDDS_WritePage(SDDS_out))
777 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
778}
779
780void ReadPointFile(char *inputFile, char *xCol, char *yCol, long *pages, OUT_POINT **out_point) {
781 SDDS_DATASET SDDS_in;
782 int64_t rows1 = 0;
783 long pages0 = 0;
784 double *x, *y, xmin, xmax, firstx, firsty, ymin, ymax;
785 int nx, ny, i;
786
787 if (!SDDS_InitializeInput(&SDDS_in, inputFile))
788 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
789 if (SDDS_CheckColumn(&SDDS_in, xCol, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) {
790 fprintf(stderr, "X column - %s does not exist!\n", xCol);
791 exit(EXIT_FAILURE);
792 }
793 if (SDDS_CheckColumn(&SDDS_in, yCol, NULL, SDDS_ANY_NUMERIC_TYPE, stderr) != SDDS_CHECK_OK) {
794 fprintf(stderr, "Y column - %s does not exist!\n", yCol);
795 exit(EXIT_FAILURE);
796 }
797 while (SDDS_ReadPage(&SDDS_in) > 0) {
798 rows1 = SDDS_CountRowsOfInterest(&SDDS_in);
799 if (!rows1)
800 continue;
801 if (rows1 > INT32_MAX) {
802 fprintf(stderr, "Too many input rows for 2D interpolate library routines.\n");
803 exit(EXIT_FAILURE);
804 }
805 *out_point = SDDS_Realloc(*out_point, sizeof(**out_point) * (pages0 + 1));
806 x = y = NULL;
807 (*out_point)[pages0].pout = malloc(sizeof(point) * rows1);
808 (*out_point)[pages0].nout = rows1;
809 if (!(x = (double *)SDDS_GetColumnInDoubles(&SDDS_in, xCol)) ||
810 !(y = (double *)SDDS_GetColumnInDoubles(&SDDS_in, yCol)))
811 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
812 xmin = xmax = firstx = x[0];
813 ymin = ymax = firsty = y[0];
814 nx = ny = 0;
815
816 for (i = 0; i < rows1; i++) {
817 (*out_point)[pages0].pout[i].x = x[i];
818 (*out_point)[pages0].pout[i].y = y[i];
819 if (x[i] < xmin)
820 xmin = x[i];
821 else if (x[i] > xmax)
822 xmax = x[i];
823 if (x[i] == firstx)
824 ny++;
825 if (y[i] < ymin)
826 ymin = y[i];
827 else if (y[i] > ymax)
828 ymax = y[i];
829 if (y[i] == firsty)
830 nx++;
831 }
832 free(x);
833 free(y);
834 (*out_point)[pages0].xmin = xmin;
835 (*out_point)[pages0].xmax = xmax;
836 (*out_point)[pages0].ymin = ymin;
837 (*out_point)[pages0].ymax = ymax;
838 (*out_point)[pages0].nx = nx;
839 (*out_point)[pages0].ny = ny;
840 if (nx > 1)
841 (*out_point)[pages0].dx = (xmax - xmin) / (nx - 1);
842 else
843 (*out_point)[pages0].dx = 0;
844 if (ny > 1)
845 (*out_point)[pages0].dy = (ymax - ymin) / (ny - 1);
846 else
847 (*out_point)[pages0].dy = 0;
848 pages0++;
849 }
850 if (!SDDS_Terminate(&SDDS_in))
851 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
852 if (!pages0) {
853 fprintf(stderr, "No data found in the points file.\n");
854 exit(EXIT_FAILURE);
855 }
856 *pages = pages0;
857 return;
858}
859
860int interpolate_output_points(int nin, point **pin, double *std, char *xCol, char *yCol, char *xName, char *yName,
861 char **zCol, long zCols, specs *spec, long pages, OUT_POINT *out_point, SDDS_DATASET *SDDS_out) {
862 int nout, page, k, writepage = 0, i;
863 point *pout = NULL;
864
865 for (page = 0; page < pages; page++) {
866 nout = out_point[page].nout;
867 pout = out_point[page].pout;
868 spec->nx = out_point[page].nx;
869 spec->ny = out_point[page].ny;
870 spec->xmin = out_point[page].xmin;
871 spec->xmax = out_point[page].xmax;
872 spec->dx = out_point[page].dx;
873 spec->ymin = out_point[page].ymin;
874 spec->ymax = out_point[page].ymax;
875 spec->dy = out_point[page].dy;
876 for (k = 0; k < zCols; k++) {
877 if (spec->method == NN) {
878 do_nn_2d_interpolate(spec, &nin, &pin[k], &nout, &pout);
879 } else {
880 do_csa_2d_interpolate(spec, nin, pin[k], &nout, &pout, std);
881 }
882 if (!spec->nointerp) {
883 if (!writepage) {
884 WriteOutputPage(SDDS_out, xName ? xName : xCol, yName ? yName : yCol, zCol[k], spec, nout, pout, 0);
885 writepage = 1;
886 } else {
887 for (i = 0; i < nout; i++) {
888 if (!SDDS_SetRowValues(SDDS_out, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE, i,
889 zCol[k], pout[i].z, NULL))
890 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
891 }
892 }
893 }
894 }
895 }
896 if (writepage && !SDDS_WritePage(SDDS_out))
897 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
898 return 1;
899}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
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_GetColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified column in the SDDS dataset.
Definition SDDS_info.c:41
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_DefineSimpleParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data parameter 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.
char ** getMatchingSDDSNames(SDDS_DATASET *dataset, char **matchName, int32_t matches, int32_t *names, short type)
Retrieves an array of matching SDDS entity names based on specified criteria.
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_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_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
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
int get_double(double *dptr, char *s)
Parses a double value from the given string.
Definition data_scan.c:40
int get_int(int *iptr, char *s)
Parses an integer value from the given string.
Definition data_scan.c:380
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
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.