SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
image2sdds.c
Go to the documentation of this file.
1/**
2 * @file image2sdds.c
3 * @brief Converts raw binary image files into SDDS format.
4 *
5 * @details
6 * This program processes raw binary image data and converts it to the SDDS (Self Describing Data Sets) format.
7 * It supports both binary and ASCII outputs and includes features for data transposition, 2D array representation,
8 * contour header generation, and multi-column mode. The SDDS format facilitates the storage and transfer of
9 * scientific data with metadata, making it ideal for analytical and visualization applications.
10 *
11 * @section Usage
12 * ```
13 * image2sdds <IMAGE infile> <SDDS outfile>
14 * [-2d]
15 * [-ascii]
16 * [-contour]
17 * [-multicolumnmode]
18 * [-transpose]
19 * [-xdim <value>]
20 * [-ydim <value>]
21 * [-xmin <value>]
22 * [-xmax <value>]
23 * [-ymin <value>]
24 * [-ymax <value>]
25 * [-debug]
26 * [-help]
27 * ```
28 *
29 * @section Options
30 * | Optional | Description |
31 * |-----------------------------------------|-----------------------------------------------------------|
32 * | `-2d` | Output the SDDS file as a 2D array. |
33 * | `-ascii` | Write the SDDS file in ASCII format (default is binary). |
34 * | `-contour` | Generate SDDS headers for compatibility with sddscontour.|
35 * | `-multicolumnmode` | Enable multi-column mode for SDDS output. |
36 * | `-transpose` | Transpose the image along its diagonal axis. |
37 * | `-xdim` | Set the X dimension of the image (default: 482). |
38 * | `-ydim` | Set the Y dimension of the image (default: 512). |
39 * | `-xmin` | Set the minimum X coordinate value. |
40 * | `-xmax` | Set the maximum X coordinate value. |
41 * | `-ymin` | Set the minimum Y coordinate value. |
42 * | `-ymax` | Set the maximum Y coordinate value. |
43 * | `-debug` | Enable debug mode with the specified level. |
44 * | `-help` | Display usage information. |
45 *
46 * @subsection Incompatibilities
47 * - Only one of the following options may be specified:
48 * - `-2d`
49 * - `-multicolumnmode`
50 *
51 * @copyright
52 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
53 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
54 *
55 * @license
56 * This file is distributed under the terms of the Software License Agreement
57 * found in the file LICENSE included with this distribution.
58 *
59 * @authors
60 * Josh Stein, J. Anderson, R. Soliday
61 */
62
63#include <stdio.h>
64#include <string.h>
65#include <SDDS.h> /* SDDS library header */
66
67#define VERSION "V1.2"
68#define XDIMENSION 482 /* Default beam size in X axis */
69#define YDIMENSION 512 /* Default beam size in Y axis */
70
71/* Parameter defines */
72#define PARM_DEBUG 1
73#define PARM_XDIM 2
74#define PARM_YDIM 3
75#define PARM_TRANSPOSE 4
76#define PARM_ASCII 5
77#define PARM_HELP 6
78#define PARM_QMARK 7
79#define PARM_CONTOUR 8
80#define PARM_2D 9
81#define PARM_XMIN 10
82#define PARM_YMIN 11
83#define PARM_XMAX 12
84#define PARM_YMAX 13
85#define PARM_MULTICOLUMNMODE 14
86
87int asciiOutput = 0; /* Set to 1 for ASCII SDDS output, 0 for binary */
88int array = 0; /* Set to 1 for 2-dimensional array output */
89int contour = 0;
90int xDim = 0;
91int yDim = 0;
92double xMin = 0;
93double yMin = 0;
94double xMax = 1;
95double yMax = 1;
96int useXmax = 0;
97int useYmax = 0;
98int debug = 0;
99int transpose = 0;
100int multiColumnMode = 0;
101
102struct parm_info {
103 char *parm; /* Parameter string */
104 int len; /* Length of the parameter string */
105 int id; /* Parameter identifier */
106 char *desc; /* Description of the parameter */
107};
108
109typedef struct parm_info PARM_INFO;
110
111static PARM_INFO ptable[] = {
112 {"-2d", 3, PARM_2D, "Output SDDS file as 2D array"},
113 {"-debug", 6, PARM_DEBUG, "Enable debug mode"},
114 {"-xdim", 5, PARM_XDIM, "Set X dimension of the image"},
115 {"-ydim", 5, PARM_YDIM, "Set Y dimension of the image"},
116 {"-transpose", 10, PARM_TRANSPOSE, "Transpose the image"},
117 {"-ascii", 6, PARM_ASCII, "Output SDDS file as ASCII"},
118 {"-contour", 8, PARM_CONTOUR, "Generate SDDS headers for sddscontour tool"},
119 {"-help", 5, PARM_HELP, "Display usage information"},
120 {"-?", 2, PARM_QMARK, "Display usage information"},
121 {"-xmin", 5, PARM_XMIN, "Set minimum X value"},
122 {"-ymin", 5, PARM_YMIN, "Set minimum Y value"},
123 {"-xmax", 5, PARM_XMAX, "Set maximum X value"},
124 {"-ymax", 5, PARM_YMAX, "Set maximum Y value"},
125 {"-multicolumnmode", 16, PARM_MULTICOLUMNMODE, "Enable multi-column mode"},
126 {NULL, -1, -1, NULL}};
127
128/* Prototypes */
129int process_cmdline_args(int argc, char *argv[], char *infile, char *outfile);
130void usage(char *name);
131
132int main(int argc, char *argv[]) {
133 short *image = NULL;
134 short *rotimage = NULL;
135 char infile[255];
136 char outfile[255];
137 char xDimStr[10];
138 char yDimStr[10];
139 int32_t dim[2];
140 FILE *infilefp;
141 int x, y, i, n, j;
142 SDDS_TABLE table;
143 double xInterval = 0.02;
144 double yInterval = 0.02;
145 double *indexes = NULL;
146 char **columnNames = NULL;
147 int32_t *data = NULL;
148
149 process_cmdline_args(argc, argv, infile, outfile);
150
151 /* If user didn't specify dimensions, use defaults */
152 if (!xDim) {
153 xDim = XDIMENSION;
154 }
155 if (!yDim) {
156 yDim = YDIMENSION;
157 }
158
159 image = (short *)malloc(sizeof(short) * xDim * yDim);
160 if (!image) {
161 fprintf(stderr, "%s: Error allocating memory for image.\n", argv[0]);
162 exit(EXIT_FAILURE);
163 }
164
165 rotimage = (short *)malloc(sizeof(short) * xDim * yDim);
166 if (!rotimage) {
167 fprintf(stderr, "%s: Error allocating memory for rotated image.\n", argv[0]);
168 exit(EXIT_FAILURE);
169 }
170
171 /* Open input file */
172 if ((infilefp = fopen(infile, "rb")) == NULL) {
173 fprintf(stderr, "%s: Error: unable to open input file: %s\n", argv[0], infile);
174 exit(EXIT_FAILURE);
175 }
176
177 /* Read image into 1-dimensional array */
178 for (x = 0; x < xDim * yDim; x++) {
179 int byte = getc(infilefp);
180 if (byte == EOF) {
181 fprintf(stderr, "%s: Unexpected EOF at index %d\n", argv[0], x);
182 exit(EXIT_FAILURE);
183 }
184 image[x] = (short)byte;
185 }
186 fclose(infilefp);
187
188 /* Use transpose factor here to adjust image */
189 i = 0;
190 for (x = 0; x < xDim; x++) {
191 for (y = 0; y < yDim; y++) {
192 rotimage[y * xDim + x] = image[i];
193 i++;
194 }
195 }
196
197 /* Begin SDDS specifics */
198
199 if (transpose) { /* Reverse dimensions for transposed image */
200 sprintf(yDimStr, "%d", xDim); /* Dimensions of image sent to SDDS */
201 sprintf(xDimStr, "%d", yDim);
202 } else {
203 sprintf(xDimStr, "%d", xDim); /* Dimensions of image sent to SDDS */
204 sprintf(yDimStr, "%d", yDim);
205 }
206
207 if (asciiOutput) {
208 if (!SDDS_InitializeOutput(&table, SDDS_ASCII, 1, "ImageArray", "Converted image data", outfile)) {
209 fprintf(stderr, "%s: SDDS error: unable to initialize output file %s\n", argv[0], outfile);
210 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
211 exit(EXIT_FAILURE);
212 }
213 } else {
214 if (!SDDS_InitializeOutput(&table, SDDS_BINARY, 1, "ImageArray", "Converted image data", outfile)) {
215 fprintf(stderr, "%s: SDDS error: unable to initialize output file %s\n", argv[0], outfile);
216 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
217 exit(EXIT_FAILURE);
218 }
219 }
220
221 if (transpose) {
222 if (useXmax)
223 xInterval = (xMax - xMin) / (yDim - 1);
224 if (useYmax)
225 yInterval = (yMax - yMin) / (xDim - 1);
226 } else {
227 if (useXmax)
228 xInterval = (xMax - xMin) / (xDim - 1);
229 if (useYmax)
230 yInterval = (yMax - yMin) / (yDim - 1);
231 }
232
233 if (contour) {
234 if (!multiColumnMode) {
235 /* Begin setting parameters for use in sddscontour tool */
236 if (SDDS_DefineParameter(&table, "Variable1Name", NULL, NULL, NULL, NULL, SDDS_STRING, "x") == -1) {
237 fprintf(stderr, "%s: SDDS error: unable to define parameter 1: Variable1Name\n", argv[0]);
238 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
239 exit(EXIT_FAILURE);
240 }
241
242 if (SDDS_DefineParameter(&table, "Variable2Name", NULL, NULL, NULL, NULL, SDDS_STRING, "y") == -1) {
243 fprintf(stderr, "%s: SDDS error: unable to define parameter 2: Variable2Name\n", argv[0]);
244 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
245 exit(EXIT_FAILURE);
246 }
247
248 if (SDDS_DefineParameter1(&table, "xInterval", NULL, NULL, NULL, NULL, SDDS_DOUBLE, &xInterval) == -1) {
249 fprintf(stderr, "%s: SDDS error: unable to define parameter 3: xInterval\n", argv[0]);
250 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
251 exit(EXIT_FAILURE);
252 }
253
254 if (SDDS_DefineParameter1(&table, "xMinimum", NULL, NULL, NULL, NULL, SDDS_DOUBLE, &xMin) == -1) {
255 fprintf(stderr, "%s: SDDS error: unable to define parameter 4: xMinimum\n", argv[0]);
256 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
257 exit(EXIT_FAILURE);
258 }
259
260 if (SDDS_DefineParameter(&table, "xDimension", NULL, NULL, NULL, NULL, SDDS_LONG, xDimStr) == -1) {
261 fprintf(stderr, "%s: SDDS error: unable to define parameter 5: xDimension\n", argv[0]);
262 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
263 exit(EXIT_FAILURE);
264 }
265
266 if (SDDS_DefineParameter1(&table, "yInterval", NULL, NULL, NULL, NULL, SDDS_DOUBLE, &yInterval) == -1) {
267 fprintf(stderr, "%s: SDDS error: unable to define parameter 6: yInterval\n", argv[0]);
268 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
269 exit(EXIT_FAILURE);
270 }
271
272 if (SDDS_DefineParameter1(&table, "yMinimum", NULL, NULL, NULL, NULL, SDDS_DOUBLE, &yMin) == -1) {
273 fprintf(stderr, "%s: SDDS error: unable to define parameter 7: yMinimum\n", argv[0]);
274 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
275 exit(EXIT_FAILURE);
276 }
277
278 if (SDDS_DefineParameter(&table, "yDimension", NULL, NULL, NULL, NULL, SDDS_LONG, yDimStr) == -1) {
279 fprintf(stderr, "%s: SDDS error: unable to define parameter 8: yDimension\n", argv[0]);
280 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
281 exit(EXIT_FAILURE);
282 }
283 }
284 }
285 /* Done setting parameters */
286
287 if (array) {
288 if (SDDS_DefineArray(&table, "ImageArray", NULL, NULL, "Intensity", NULL, SDDS_CHARACTER, 0, 2, NULL) == -1) {
289 fprintf(stderr, "%s: SDDS error: unable to define array %s\n", argv[0], "ImageArray");
290 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
291 exit(EXIT_FAILURE);
292 }
293 } else {
294 if (!multiColumnMode) {
295 if (SDDS_DefineColumn(&table, "Image", NULL, NULL, NULL, NULL, SDDS_SHORT, 0) == -1) {
296 fprintf(stderr, "%s: SDDS error: unable to define column %s\n", argv[0], "Image");
297 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
298 exit(EXIT_FAILURE);
299 }
300 } else {
301 if (SDDS_DefineSimpleColumn(&table, "Index", NULL, SDDS_DOUBLE) < 0) {
302 fprintf(stderr, "%s: SDDS error: problem defining column Index.\n", argv[0]);
303 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
304 exit(EXIT_FAILURE);
305 }
306 if (transpose) {
307 dim[0] = xDim;
308 dim[1] = yDim;
309 } else {
310 dim[0] = yDim;
311 dim[1] = xDim;
312 }
313 indexes = malloc(sizeof(double) * dim[1]);
314 if (!indexes) {
315 fprintf(stderr, "%s: Error allocating memory for indexes.\n", argv[0]);
316 exit(EXIT_FAILURE);
317 }
318 columnNames = malloc(sizeof(char *) * dim[0]);
319 if (!columnNames) {
320 fprintf(stderr, "%s: Error allocating memory for column names.\n", argv[0]);
321 exit(EXIT_FAILURE);
322 }
323 data = malloc(sizeof(int32_t) * dim[1]);
324 if (!data) {
325 fprintf(stderr, "%s: Error allocating memory for data.\n", argv[0]);
326 exit(EXIT_FAILURE);
327 }
328 for (i = 0; i < dim[0]; i++) {
329 columnNames[i] = malloc(sizeof(char) * 20);
330 if (!columnNames[i]) {
331 fprintf(stderr, "%s: Error allocating memory for column name %d.\n", argv[0], i);
332 exit(EXIT_FAILURE);
333 }
334 sprintf(columnNames[i], "Line%" PRId32, i);
335 if (SDDS_DefineSimpleColumn(&table, columnNames[i], NULL, SDDS_SHORT) < 0) {
336 fprintf(stderr, "%s: SDDS error: problem defining column %s.\n", argv[0], columnNames[i]);
337 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
338 exit(EXIT_FAILURE);
339 }
340 }
341 }
342 }
343
344 if (!SDDS_WriteLayout(&table)) {
345 fprintf(stderr, "%s: SDDS error: unable to write layout\n", argv[0]);
346 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
347 exit(EXIT_FAILURE);
348 }
349
350 if (!multiColumnMode) {
351 if (!SDDS_StartTable(&table, xDim * yDim)) {
352 fprintf(stderr, "%s: SDDS error: unable to start table\n", argv[0]);
353 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
354 exit(EXIT_FAILURE);
355 }
356 } else {
357 if (!SDDS_StartTable(&table, dim[1])) {
358 fprintf(stderr, "%s: SDDS error: unable to start table\n", argv[0]);
359 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
360 exit(EXIT_FAILURE);
361 }
362 }
363
364 if (!array) {
365 if (!multiColumnMode) {
366 if (transpose) {
367 for (x = 0; x < xDim * yDim; x++) {
368 if (!SDDS_SetRowValues(&table, (SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE), x, "Image", rotimage[x], NULL)) {
369 fprintf(stderr, "%s: SDDS error: unable to write row %d\n", argv[0], x);
370 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
371 exit(EXIT_FAILURE);
372 }
373 }
374 } else {
375 for (x = 0; x < xDim * yDim; x++) {
376 if (!SDDS_SetRowValues(&table, (SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE), x, "Image", image[x], NULL)) {
377 fprintf(stderr, "%s: SDDS error: unable to write row %d\n", argv[0], x);
378 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
379 exit(EXIT_FAILURE);
380 }
381 }
382 }
383 } else {
384 for (i = 0; i < dim[1]; i++)
385 indexes[i] = xMin + xInterval * i;
386 if (!SDDS_SetColumnFromDoubles(&table, SDDS_SET_BY_NAME, indexes, dim[1], "Index")) {
387 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
388 exit(EXIT_FAILURE);
389 }
390 n = 0;
391
392 for (i = 0; i < dim[0]; i++) {
393 for (j = 0; j < dim[1]; j++) {
394 if (transpose) {
395 data[j] = image[n];
396 } else {
397 data[j] = rotimage[n];
398 }
399 n++;
400 }
401
402 if (!SDDS_SetColumnFromLongs(&table, SDDS_SET_BY_NAME, data, dim[1], columnNames[i])) {
403 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
404 exit(EXIT_FAILURE);
405 }
406 }
407 }
408 } else { /* Requesting writing of 2D array */
409 if (transpose) {
410 dim[0] = xDim;
411 dim[1] = yDim;
412 if (SDDS_SetArray(&table, "ImageArray", SDDS_CONTIGUOUS_DATA, rotimage, dim) == 0) {
413 fprintf(stderr, "%s: SDDS Error - unable to set array\n", argv[0]);
414 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
415 exit(EXIT_FAILURE);
416 }
417 } else {
418 dim[0] = yDim;
419 dim[1] = xDim;
420 if (SDDS_SetArray(&table, "ImageArray", SDDS_CONTIGUOUS_DATA, image, dim) == 0) {
421 fprintf(stderr, "%s: SDDS Error - unable to set array\n", argv[0]);
422 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
423 exit(EXIT_FAILURE);
424 }
425 }
426 }
427
428 if (!SDDS_WriteTable(&table)) {
429 fprintf(stderr, "%s: SDDS error: unable to write table\n", argv[0]);
430 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
431 exit(EXIT_FAILURE);
432 }
433
434 if (!SDDS_Terminate(&table)) {
435 fprintf(stderr, "%s: SDDS error: unable to terminate SDDS\n", argv[0]);
436 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
437 exit(EXIT_FAILURE);
438 }
439
440 /* Free allocated memory */
441 if (image)
442 free(image);
443 if (rotimage)
444 free(rotimage);
445 if (indexes)
446 free(indexes);
447 if (data)
448 free(data);
449 if (columnNames) {
450 free(columnNames);
451 }
452
453 return EXIT_SUCCESS;
454}
455
456/*************************************************************************
457 * FUNCTION : process_cmdline_args()
458 * PURPOSE : Get command line arguments and set flags appropriately.
459 * ARGS in : argc, argv - standard unix
460 * ARGS out : infile, outfile - names of input and output files
461 * GLOBAL : nothing
462 * RETURNS : 0 on success, exits on error
463 ************************************************************************/
464int process_cmdline_args(int argc, char *argv[], char *infile, char *outfile) {
465 int i, j;
466 int cmderror = 0;
467 int scan_done = 0;
468
469 *infile = '\0';
470 *outfile = '\0';
471
472 /* Process command line options */
473 if (argc < 3)
474 cmderror++;
475 else {
476 strcpy(infile, argv[1]);
477 strcpy(outfile, argv[2]);
478
479 /* Begin parsing any optional args */
480 for (i = 3; i < argc && !cmderror; i++) {
481 for (j = 0; !scan_done && !cmderror && ptable[j].parm; j++) {
482 if (strncmp(ptable[j].parm, argv[i], ptable[j].len) == 0) {
483 switch (ptable[j].id) {
484
485 case PARM_DEBUG:
486 if (++i >= argc)
487 cmderror++;
488 else {
489 if (argv[i][0] == '-')
490 cmderror++;
491 else {
492 if (sscanf(argv[i], "%d", &debug) < 1)
493 cmderror++;
494 else
495 scan_done = 1;
496 }
497 }
498 break;
499
500 case PARM_XDIM:
501 if (++i >= argc)
502 cmderror++;
503 else {
504 if (argv[i][0] == '-')
505 cmderror++;
506 else {
507 if (sscanf(argv[i], "%d", &xDim) < 1)
508 cmderror++;
509 else
510 scan_done = 1;
511 }
512 }
513 break;
514
515 case PARM_YDIM:
516 if (++i >= argc)
517 cmderror++;
518 else {
519 if (argv[i][0] == '-')
520 cmderror++;
521 else {
522 if (sscanf(argv[i], "%d", &yDim) < 1)
523 cmderror++;
524 else
525 scan_done = 1;
526 }
527 }
528 break;
529
530 case PARM_XMIN:
531 if (++i >= argc)
532 cmderror++;
533 else {
534 if (argv[i][0] == '-')
535 cmderror++;
536 else {
537 if (sscanf(argv[i], "%lf", &xMin) < 1)
538 cmderror++;
539 else
540 scan_done = 1;
541 }
542 }
543 break;
544 case PARM_XMAX:
545 if (++i >= argc)
546 cmderror++;
547 else {
548 if (argv[i][0] == '-')
549 cmderror++;
550 else {
551 if (sscanf(argv[i], "%lf", &xMax) < 1)
552 cmderror++;
553 else {
554 scan_done = 1;
555 useXmax = 1;
556 }
557 }
558 }
559 break;
560 case PARM_YMIN:
561 if (++i >= argc)
562 cmderror++;
563 else {
564 if (argv[i][0] == '-')
565 cmderror++;
566 else {
567 if (sscanf(argv[i], "%lf", &yMin) < 1)
568 cmderror++;
569 else
570 scan_done = 1;
571 }
572 }
573 break;
574 case PARM_YMAX:
575 if (++i >= argc)
576 cmderror++;
577 else {
578 if (argv[i][0] == '-')
579 cmderror++;
580 else {
581 if (sscanf(argv[i], "%lf", &yMax) < 1)
582 cmderror++;
583 else {
584 scan_done = 1;
585 useYmax = 1;
586 }
587 }
588 }
589 break;
590
591 case PARM_TRANSPOSE:
592 transpose++;
593 scan_done = 1;
594 break;
595 case PARM_MULTICOLUMNMODE:
596 multiColumnMode = 1;
597 scan_done = 1;
598 break;
599
600 case PARM_ASCII:
601 asciiOutput++;
602 scan_done = 1;
603 break;
604
605 case PARM_HELP:
606 case PARM_QMARK:
607 usage(argv[0]);
608 exit(EXIT_SUCCESS);
609 break;
610
611 case PARM_CONTOUR:
612 contour++;
613 scan_done = 1;
614 break;
615
616 case PARM_2D:
617 array++;
618 scan_done = 1;
619 break;
620
621 default:
622 cmderror++;
623 break;
624 }
625 }
626 }
627 scan_done = 0;
628 }
629 }
630 if (cmderror) {
631 usage(argv[0]);
632 exit(EXIT_FAILURE);
633 }
634 return 0;
635}
636
637/*************************************************************************
638 * FUNCTION : usage()
639 * PURPOSE : Describes command line options available to client.
640 * ARGS in : char *name - name of executable program
641 * ARGS out : none
642 * GLOBAL : nothing
643 * RETURNS : none
644 ************************************************************************/
645
646#define pr fprintf
647
648void usage(char *name) {
649 pr(stderr, "Image2SDDS Utility %s\n", VERSION);
650 pr(stderr, "=============================\n");
651 pr(stderr, "Usage:\n");
652 pr(stderr, " image2sdds <IMAGE infile> <SDDS outfile>\n");
653 pr(stderr, " [-2d]\n");
654 pr(stderr, " [-ascii]\n");
655 pr(stderr, " [-contour]\n");
656 pr(stderr, " [-multicolumnmode]\n");
657 pr(stderr, " [-transpose]\n");
658 pr(stderr, " [-xdim <value>]\n");
659 pr(stderr, " [-ydim <value>]\n");
660 pr(stderr, " [-xmin <value>]\n");
661 pr(stderr, " [-xmax <value>]\n");
662 pr(stderr, " [-ymin <value>]\n");
663 pr(stderr, " [-ymax <value>]\n");
664 pr(stderr, " [-debug]\n");
665 pr(stderr, " [-help]\n");
666 pr(stderr, "Options:\n");
667 pr(stderr, " -2d Output SDDS file as a 2D array.\n");
668 pr(stderr, " -ascii Write SDDS file as ASCII (default is binary).\n");
669 pr(stderr, " -contour Generate SDDS headers for the sddscontour tool.\n");
670 pr(stderr, " -multicolumnmode Enable multi-column mode.\n");
671 pr(stderr, " -transpose Transpose the image about the diagonal.\n");
672 pr(stderr, " -xdim <value> Set X dimension of the image (default = %d).\n", XDIMENSION);
673 pr(stderr, " -ydim <value> Set Y dimension of the image (default = %d).\n", YDIMENSION);
674 pr(stderr, " -xmin <value> Set minimum X value.\n");
675 pr(stderr, " -xmax <value> Set maximum X value.\n");
676 pr(stderr, " -ymin <value> Set minimum Y value.\n");
677 pr(stderr, " -ymax <value> Set maximum Y value.\n");
678 pr(stderr, " -debug <level> Enable debug mode with the specified level.\n");
679 pr(stderr, " -? or -help Display this usage message.\n\n");
680 pr(stderr, "Purpose:\n");
681 pr(stderr, " Reads image data from <infile> and writes SDDS data to <outfile>.\n");
682 pr(stderr, " Supports various output formats and options for data manipulation.\n");
683}
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_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_SetArray(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t *dimension)
Sets the values of an array variable in the SDDS dataset using specified dimensions.
int32_t SDDS_SetColumnFromLongs(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t *data, int64_t rows,...)
Sets the values for a single data column using long integer numbers.
int32_t SDDS_Terminate(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_DefineParameter1(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, void *fixed_value)
Defines a data parameter with a fixed numerical value.
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_DefineArray(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, int32_t dimensions, const char *group_name)
Defines a data array within the SDDS dataset.
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_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
Definition SDDS_utils.c:432
#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_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37