Main function that processes the SDDS file.
The main function checks the command-line arguments, initializes the SDDS dataset, and iterates over the pages in the SDDS file. For each page, it processes the parameters, columns, and arrays, printing their names and values to the console.
28 {
30 int32_t page;
31 int32_t n_params;
32 int32_t n_columns;
33 int32_t n_arrays;
34 int64_t n_rows;
35 char **parameter_names;
36 char **column_names;
37 char **array_names;
38 int32_t type;
39 void *data;
40
41
42 if (argc != 2) {
43 fprintf(stderr, "Usage: %s filename.sdds\n", argv[0]);
44 exit(1);
45 }
46
47
50 exit(1);
51 }
52
53
57
58 page = 0;
59
61 printf("Page %d\n", page);
62
64
65
66 printf("Parameters:\n");
67 for (int32_t i = 0; i < n_params; i++) {
69 printf(" %s = ", parameter_names[i]);
70 switch (type) {
72 short value;
73
76 continue;
77 }
78 printf("%hd\n", value);
79 break;
80 }
82 unsigned short value;
85 continue;
86 }
87 printf("%hu\n", value);
88 break;
89 }
91 int32_t value;
94 continue;
95 }
96 printf("%" PRId32 "\n", value);
97 break;
98 }
100 uint32_t value;
103 continue;
104 }
105 printf("%" PRIu32 "\n", value);
106 break;
107 }
109 int64_t value;
112 continue;
113 }
114 printf("%" PRId64 "\n", value);
115 break;
116 }
118 uint64_t value;
121 continue;
122 }
123 printf("%" PRIu64 "\n", value);
124 break;
125 }
127 float value;
130 continue;
131 }
132 printf("%15.6e\n", value);
133 break;
134 }
136 double value;
139 continue;
140 }
141 printf("%21.14e\n", value);
142 break;
143 }
145 long double value;
148 continue;
149 }
150 if (LDBL_DIG == 18) {
151 printf("%21.18Le\n", value);
152 } else {
153 printf("%21.14Le\n", value);
154 }
155 break;
156 }
158 char *value;
161 continue;
162 }
163 printf("%s\n", value);
164 free(value);
165 break;
166 }
168 char value;
171 continue;
172 }
173 printf("%c\n", value);
174 break;
175 }
176 default:
177 printf("Unknown type\n");
178 break;
179 }
180 }
181
182
183 printf("Columns (%" PRId64 " rows):\n", n_rows);
184 for (int32_t i = 0; i < n_columns; i++) {
186 printf(" Column: %s\n", column_names[i]);
188 if (data == NULL) {
189 fprintf(stderr, "Error getting column %s\n", column_names[i]);
190 continue;
191 }
192 switch (type) {
194 short *values = (short *)data;
195 for (int64_t row = 0; row < n_rows; row++) {
196 printf(" %hd\n", values[row]);
197 }
198 break;
199 }
201 unsigned short *values = (unsigned short *)data;
202 for (int64_t row = 0; row < n_rows; row++) {
203 printf(" %hu\n", values[row]);
204 }
205 break;
206 }
208 int32_t *values = (int32_t *)data;
209 for (int64_t row = 0; row < n_rows; row++) {
210 printf(" %" PRId32 "\n", values[row]);
211 }
212 break;
213 }
215 uint32_t *values = (uint32_t *)data;
216 for (int64_t row = 0; row < n_rows; row++) {
217 printf(" %" PRIu32 "\n", values[row]);
218 }
219 break;
220 }
222 int64_t *values = (int64_t *)data;
223 for (int64_t row = 0; row < n_rows; row++) {
224 printf(" %" PRId64 "\n", values[row]);
225 }
226 break;
227 }
229 uint64_t *values = (uint64_t *)data;
230 for (int64_t row = 0; row < n_rows; row++) {
231 printf(" %" PRIu64 "\n", values[row]);
232 }
233 break;
234 }
236 float *values = (float *)data;
237 for (int64_t row = 0; row < n_rows; row++) {
238 printf(" %15.6e\n", values[row]);
239 }
240 break;
241 }
243 double *values = (double *)data;
244 for (int64_t row = 0; row < n_rows; row++) {
245 printf(" %21.14e\n", values[row]);
246 }
247 break;
248 }
250 long double *values = (long double *)data;
251 if (LDBL_DIG == 18) {
252 for (int64_t row = 0; row < n_rows; row++) {
253 printf(" %21.18Le\n", values[row]);
254 }
255 } else {
256 for (int64_t row = 0; row < n_rows; row++) {
257 printf(" %21.14Le\n", values[row]);
258 }
259 }
260 break;
261 }
263 char **values = (char **)data;
264 for (int64_t row = 0; row < n_rows; row++) {
265 printf(" %s\n", values[row]);
266 free(values[row]);
267 }
268 break;
269 }
271 char *values = (char *)data;
272 for (int64_t row = 0; row < n_rows; row++) {
273 printf(" %c\n", values[row]);
274 }
275 break;
276 }
277 default:
278 printf("Unknown type\n");
279 break;
280 }
281
283 data = NULL;
284 }
285
286
287 printf("Arrays:\n");
288 for (int32_t i = 0; i < n_arrays; i++) {
291 if (!data) {
292 fprintf(stderr, "Error getting array %s\n", array_names[i]);
293 continue;
294 }
295 printf(" Array: %s (dimensions: ", array_names[i]);
296
298 for (int32_t d = 0; d < array->definition->dimensions; d++) {
299 printf("%d", array->dimension[d]);
300 if (d < array->definition->dimensions - 1)
301 printf(" x ");
302 }
303 printf(")\n");
304
305 switch (type) {
307 short *values = (short *)array->data;
308 for (int32_t idx = 0; idx < array->elements; idx++) {
309 printf(" %hd\n", values[idx]);
310 }
311 break;
312 }
314 unsigned short *values = (unsigned short *)array->data;
315 for (int32_t idx = 0; idx < array->elements; idx++) {
316 printf(" %hu\n", values[idx]);
317 }
318 break;
319 }
321 int32_t *values = (int32_t *)array->data;
322 for (int32_t idx = 0; idx < array->elements; idx++) {
323 printf(" %" PRId32 "\n", values[idx]);
324 }
325 break;
326 }
328 uint32_t *values = (uint32_t *)array->data;
329 for (int32_t idx = 0; idx < array->elements; idx++) {
330 printf(" %" PRIu32 "\n", values[idx]);
331 }
332 break;
333 }
335 int64_t *values = (int64_t *)array->data;
336 for (int32_t idx = 0; idx < array->elements; idx++) {
337 printf(" %" PRId64 "\n", values[idx]);
338 }
339 break;
340 }
342 uint64_t *values = (uint64_t *)array->data;
343 for (int32_t idx = 0; idx < array->elements; idx++) {
344 printf(" %" PRIu64 "\n", values[idx]);
345 }
346 break;
347 }
349 float *values = (float *)array->data;
350 for (int32_t idx = 0; idx < array->elements; idx++) {
351 printf(" %15.6e\n", values[idx]);
352 }
353 break;
354 }
356 double *values = (double *)array->data;
357 for (int32_t idx = 0; idx < array->elements; idx++) {
358 printf(" %21.14e\n", values[idx]);
359 }
360 break;
361 }
363 long double *values = (long double *)array->data;
364 if (LDBL_DIG == 18) {
365 for (int32_t idx = 0; idx < array->elements; idx++) {
366 printf(" %21.18Le\n", values[idx]);
367 }
368 } else {
369 for (int32_t idx = 0; idx < array->elements; idx++) {
370 printf(" %21.14Le\n", values[idx]);
371 }
372 }
373 break;
374 }
376 char **values = (char **)array->data;
377 for (int32_t idx = 0; idx < array->elements; idx++) {
378 printf(" %s\n", values[idx]);
379 }
380 break;
381 }
383 char *values = (char *)array->data;
384 for (int32_t idx = 0; idx < array->elements; idx++) {
385 printf(" %c\n", values[idx]);
386 }
387 break;
388 }
389 default:
390 printf("Unknown type\n");
391 break;
392 }
393
395 }
396 }
397
398
401
402
405
406
409
410
412 return 0;
413}
void SDDS_FreeArray(SDDS_ARRAY *array)
Frees memory allocated for an SDDS array structure.
int32_t SDDS_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters in the SDDS dataset.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
int32_t SDDS_GetArrayType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of an array in the SDDS dataset by its index.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
char ** SDDS_GetArrayNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all arrays in the SDDS dataset.
void SDDS_Free(void *mem)
Free memory previously allocated by SDDS_Malloc.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer 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_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.