34#define PARM_TRANSPOSE 4
44#define PARM_MULTICOLUMNMODE 14
59int multiColumnMode = 0;
71 {
"-2d", 3, PARM_2D,
"2D_array"},
72 {
"-debug", 6, PARM_DEBUG,
"Debug_flag"},
73 {
"-xdim", 5, PARM_XDIM,
"X_Dimensions"},
74 {
"-ydim", 5, PARM_YDIM,
"Y_Dimensions"},
75 {
"-transpose", 10, PARM_TRANSPOSE,
"Transpose"},
76 {
"-ascii", 6, PARM_ASCII,
"Transpose"},
77 {
"-contour", 8, PARM_CONTOUR,
"Contour"},
78 {
"-help", 5, PARM_HELP,
"Help"},
79 {
"-?", 2, PARM_QMARK,
"Help"},
80 {
"-xmin", 5, PARM_XMIN,
"X_Minimum"},
81 {
"-ymin", 5, PARM_YMIN,
"Y_Minimum"},
82 {
"-xmax", 5, PARM_XMAX,
"X_Maximum"},
83 {
"-ymax", 5, PARM_YMAX,
"Y_Maximum"},
84 {
"-multicolumnmode", 16, PARM_MULTICOLUMNMODE,
"MultiColumnMode"},
88int process_cmdline_args(
int argc,
char *argv[],
char *infile,
char *outfile);
89void usage(
char *name);
91int main(
int argc,
char *argv[]) {
93 short *rotimage = NULL;
102 double xInterval = .02;
103 double yInterval = .02;
104 double *indexes = NULL;
105 char **columnNames = NULL;
106 int32_t *data = NULL;
108 process_cmdline_args(argc, argv, infile, outfile);
118 image = (
short *)malloc(
sizeof(
short) * xDim * yDim);
119 rotimage = (
short *)malloc(
sizeof(
short) * xDim * yDim);
122 if ((infilefp = fopen(infile,
"r")) == NULL) {
123 fprintf(stderr,
"%s: error: enable to open input file: %s\n", argv[0], infile);
128 for (x = 0; x < xDim * yDim; x++) {
129 image[x] = getc(infilefp);
130 if (image[x] == EOF) {
131 fprintf(stderr,
"%s: Unexpected EOF at index %d\n", argv[0], x);
138 for (x = 0; x < xDim; x++) {
139 for (y = 0; y < yDim; y++) {
140 rotimage[y * xDim + x] = image[i];
148 sprintf(yDimStr,
"%d", xDim);
149 sprintf(xDimStr,
"%d", yDim);
151 sprintf(xDimStr,
"%d", xDim);
152 sprintf(yDimStr,
"%d", yDim);
157 fprintf(stderr,
"%s: SDDS error: unable to initialize output file %s\n", argv[0], outfile);
158 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
162 fprintf(stderr,
"%s: SDDS error: unable to initialize output file %s\n", argv[0], outfile);
163 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
168 xInterval = (xMax - xMin) / (yDim - 1);
170 yInterval = (yMax - yMin) / (xDim - 1);
173 xInterval = (xMax - xMin) / (xDim - 1);
175 yInterval = (yMax - yMin) / (yDim - 1);
178 if (!multiColumnMode) {
181 fprintf(stderr,
"%s: SDDS error: unable to define paramter 1: variable1Name\n", argv[0]);
182 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
186 fprintf(stderr,
"%s: SDDS error: unable to define parameter 2: variable2Name\n", argv[0]);
187 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
191 fprintf(stderr,
"%s: SDDS error: unable to define parameter 3: xInterval\n", argv[0]);
192 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
196 fprintf(stderr,
"%s: SDDS error: unable to define paramter 4: xMinimum\n", argv[0]);
197 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
201 fprintf(stderr,
"%s: SDDS error: unable to define paramter 5: xDimension\n", argv[0]);
202 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
206 fprintf(stderr,
"%s: SDDS error: unable to define parameter 6: yInterval\n", argv[0]);
207 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
211 fprintf(stderr,
"%s: SDDS error: unable to define paramter 7: yMinimum\n", argv[0]);
212 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
216 fprintf(stderr,
"%s: SDDS error: unable to define paramter 8: yDimension\n", argv[0]);
217 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
225 fprintf(stderr,
"%s: SDDS error: unable to define array %s\n", argv[0],
"Image");
226 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
229 if (!multiColumnMode) {
231 fprintf(stderr,
"%s: SDDS error: unable to define column %s\n", argv[0],
"Image");
232 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
236 fprintf(stderr,
"Problem defining column Index.\n");
246 indexes = malloc(
sizeof(
double) * dim[1]);
247 columnNames = malloc(
sizeof(
char *) * dim[0]);
248 data = malloc(
sizeof(int32_t) * dim[1]);
249 for (i = 0; i < dim[0]; i++) {
250 columnNames[i] = malloc(
sizeof(
char) * 20);
251 sprintf(columnNames[i],
"Line%" PRId32, i);
253 fprintf(stderr,
"Problem defining column %s.\n", columnNames[i]);
261 fprintf(stderr,
"%s: SDDS error: unable to write layout\n", argv[0]);
262 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
265 if (!multiColumnMode) {
266 if (!SDDS_StartTable(&table, xDim * yDim)) {
267 fprintf(stderr,
"%s: SDDS error: unable to start table\n", argv[0]);
268 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
271 if (!SDDS_StartTable(&table, dim[1])) {
272 fprintf(stderr,
"%s: SDDS error: unable to start table\n", argv[0]);
273 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
278 if (!multiColumnMode) {
280 for (x = 0; x < xDim * yDim; x++) {
281 if (!
SDDS_SetRowValues(&table, (SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE), x,
"Image", rotimage[x], NULL)) {
282 fprintf(stderr,
"%s: SDDS error: unable to write row\n", argv[0]);
287 for (x = 0; x < xDim * yDim; x++) {
288 if (!
SDDS_SetRowValues(&table, (SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE), x,
"Image", image[x], NULL)) {
289 fprintf(stderr,
"%s: SDDS error: unable to write row\n", argv[0]);
295 for (i = 0; i < dim[1]; i++)
296 indexes[i] = xMin + xInterval * i;
301 for (i = 0; i < dim[0]; i++) {
302 for (j = 0; j < dim[1]; j++) {
306 data[j] = rotimage[n];
319 if (
SDDS_SetArray(&table,
"ImageArray", SDDS_CONTIGUOUS_DATA, rotimage, dim) == 0) {
320 fprintf(stderr,
"%s: SDDS Error - unable to stuff array\n", argv[0]);
326 if (
SDDS_SetArray(&table,
"ImageArray", SDDS_CONTIGUOUS_DATA, image, dim) == 0) {
327 fprintf(stderr,
"%s: SDDS Error - unable to stuff array\n", argv[0]);
333 if (!SDDS_WriteTable(&table)) {
334 fprintf(stderr,
"%s: SDDS error: unable to write table\n", argv[0]);
335 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
339 fprintf(stderr,
"%s: SDDS error: unable to terminate SDDS\n", argv[0]);
340 SDDS_PrintErrors(stderr, (SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors));
363int process_cmdline_args(
int argc,
char *argv[],
char *infile,
char *outfile) {
375 strcpy(infile, argv[1]);
376 strcpy(outfile, argv[2]);
379 for (i = 3; i < argc && !cmderror; i++) {
380 for (j = 0; !scan_done && !cmderror && ptable[j].parm; j++) {
381 if (strncmp(ptable[j].parm, argv[i], ptable[j].len) == 0) {
382 switch (ptable[j].
id) {
388 if (argv[i][0] ==
'-')
391 if (sscanf(argv[i],
"%d", &debug) < 1)
403 if (argv[i][0] ==
'-')
406 if (sscanf(argv[i],
"%d", &xDim) < 1)
418 if (argv[i][0] ==
'-')
421 if (sscanf(argv[i],
"%d", &yDim) < 1)
433 if (argv[i][0] ==
'-')
436 if (sscanf(argv[i],
"%lf", &xMin) < 1)
447 if (argv[i][0] ==
'-')
450 if (sscanf(argv[i],
"%lf", &xMax) < 1)
463 if (argv[i][0] ==
'-')
466 if (sscanf(argv[i],
"%lf", &yMin) < 1)
477 if (argv[i][0] ==
'-')
480 if (sscanf(argv[i],
"%lf", &yMax) < 1)
494 case PARM_MULTICOLUMNMODE:
504 case PARM_HELP | PARM_QMARK:
546void usage(
char *name) {
547 pr(stderr,
"Image conversion to SDDS utility %s\n", VERSION);
548 pr(stderr,
"-------------------------------------\n");
549 pr(stderr,
"usage: %s <IMAGE infile> <SDDS outfile> [optionlist...]\n", name);
550 pr(stderr,
"[-2d] output SDDS file as 2D array\n");
551 pr(stderr,
"[-ascii] write SDDS file as ascii (default is binary)\n");
552 pr(stderr,
"[-contour] generate SDDS headers for sddscontour tool \n");
553 pr(stderr,
"[-multicolumnmode]\n");
554 pr(stderr,
"[-?] or [-help] print this message\n");
555 pr(stderr,
"[-transpose] transpose image about diagonal\n");
556 pr(stderr,
"[-xdim <value>] X dimension of image (default = %d) \n", XDIMENSION);
557 pr(stderr,
"[-ydim <value>] Y dimension of image (default = %d) \n", YDIMENSION);
558 pr(stderr,
"[-xmin <value>] [-xmax <value>]\n");
559 pr(stderr,
"[-ymin <value>] [-ymax <value>]\n");
560 pr(stderr,
"\npurpose:\tReads the image data from file <infile>.\n");
561 pr(stderr,
"\t\tand write SDDS data to <outfile>.\n");
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_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.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_DOUBLE
Identifier for the double data type.