SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
sddsquery.c
Go to the documentation of this file.
1/**
2 * @file sddsquery.c
3 * @brief Reads an SDDS file header and summarizes it.
4 *
5 * @details
6 * This program processes SDDS files and summarizes their headers. It provides
7 * lists of arrays, columns, parameters, or associates based on user-specified options.
8 *
9 * @section Usage
10 * ```
11 * sddsquery [<SDDSfilename>] [<SDDSfilename>...]
12 * [-pipe[=input]]
13 * [-sddsOutput[=<filename>]]
14 * [-arraylist]
15 * [-associatelist]
16 * [-columnlist]
17 * [-parameterlist]
18 * [-version]
19 * [-delimiter=<delimiting-string>]
20 * [-appendunits[=bare]]
21 * [-readAll]
22 * ```
23 *
24 * @section Options
25 * | Optional | Description |
26 * |-----------------|---------------------------------------------------------------------------------------|
27 * | `-pipe` | Read input from a pipe. |
28 * | `-sddsOutput` | Write SDDS output to a file. |
29 * | `-arraylist` | List arrays. |
30 * | `-associatelist`| List associates. |
31 * | `-columnlist` | List columns. |
32 * | `-parameterlist`| List parameters. |
33 * | `-version` | Show version information. |
34 * | `-delimiter` | Use <string> as a delimiter. |
35 * | `-appendunits` | Append units to the output. |
36 * | `-readAll` | Read all pages. |
37 *
38 * @subsection Incompatibilities
39 * - Only one of the following may be specified:
40 * - `-arraylist`
41 * - `-associatelist`
42 * - `-columnlist`
43 * - `-parameterlist`
44 * - `-version`
45 *
46 * @copyright
47 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
48 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
49 *
50 * @license
51 * This file is distributed under the terms of the Software License Agreement
52 * found in the file LICENSE included with this distribution.
53 *
54 * @author
55 * M. Borland, C. Saunders, R. Soliday
56 */
57
58#include "mdb.h"
59#include "SDDS.h"
60#include "scan.h"
61
62/* Enumeration for option types */
63enum option_type {
64 SET_COLUMN_LIST,
65 SET_PARAMETER_LIST,
66 SET_ASSOCIATE_LIST,
67 SET_ARRAY_LIST,
68 SET_DELIMITER,
69 SET_APPEND_UNITS,
70 SET_VERSION,
71 SET_PIPE,
72 SET_SDDSOUTPUT,
73 SET_READALL,
74 N_OPTIONS
75};
76
77char *option[N_OPTIONS] = {
78 "columnlist",
79 "parameterlist",
80 "associatelist",
81 "arraylist",
82 "delimiter",
83 "appendunits",
84 "version",
85 "pipe",
86 "sddsoutput",
87 "readall",
88};
89
90char *USAGE =
91 "sddsquery [<SDDSfilename>...]\n"
92 " [-pipe[=input]]\n"
93 " [-sddsOutput[=<filename>]]\n"
94 " [-arraylist]\n"
95 " [-associatelist]\n"
96 " [-columnlist]\n"
97 " [-parameterlist]\n"
98 " [-version]\n"
99 " [-delimiter=<delimiting-string>] \n"
100 " [-appendunits[=bare]] \n"
101 " [-readAll]\n"
102 "Options:\n"
103 " -pipe[=input] Read input from a pipe.\n"
104 " -sddsOutput[=<filename>] Write SDDS output to a file.\n"
105 " -arraylist List arrays.\n"
106 " -associatelist List associates.\n"
107 " -columnlist List columns.\n"
108 " -parameterlist List parameters.\n"
109 " -version Show version information.\n"
110 " -delimiter=<string> Use <string> as a delimiter.\n"
111 " -appendunits[=bare] Append units to the output.\n"
112 " -readAll Read all pages.\n"
113 "\n"
114 "Description:\n"
115 " sddsquery accesses a series of SDDS files and summarizes the file header for each. "
116 "It also provides lists of arrays, columns, parameters, or associates.\n"
117 "\n"
118 "Program by Michael Borland. (" __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n";
119
120long InitializeSDDSHeaderOutput(SDDS_DATASET *outSet, char *filename);
121long MakeSDDSHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, long listRequest, char *inputFile);
122long MakeColumnHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, char *inputFile);
123long MakeParameterHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, char *inputFile);
124long MakeArrayHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, char *inputFile);
125
126int main(int argc, char **argv) {
127 SDDS_DATASET SDDS_dataset, SDDSout;
128 SDDS_LAYOUT *layout;
129 COLUMN_DEFINITION *coldef;
130 PARAMETER_DEFINITION *pardef;
131 ARRAY_DEFINITION *arraydef;
132 long list_request;
133 char s[SDDS_MAXLINE];
134 char **filename, *ptr, *sddsOutputFile;
135 long i, i_arg, filenames, file, append_units, sddsOutput;
136 SCANNED_ARG *s_arg;
137 char *text, *contents, *delimiter, *unitsTemplate;
138 FILE *fp;
139 unsigned long pipeFlags;
140 long readAll;
141
142 list_request = -1;
143 filename = NULL;
144 sddsOutput = 0;
145 filenames = append_units = 0;
146 delimiter = sddsOutputFile = unitsTemplate = NULL;
147 pipeFlags = 0;
148 readAll = 0;
149
151 argc = scanargs(&s_arg, argc, argv);
152
153 for (i_arg = 1; i_arg < argc; i_arg++) {
154 if (s_arg[i_arg].arg_type == OPTION) {
155 delete_chars(s_arg[i_arg].list[0], "_");
156 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
157 case SET_COLUMN_LIST:
158 list_request = SET_COLUMN_LIST;
159 break;
160 case SET_PARAMETER_LIST:
161 list_request = SET_PARAMETER_LIST;
162 break;
163 case SET_ASSOCIATE_LIST:
164 list_request = SET_ASSOCIATE_LIST;
165 break;
166 case SET_ARRAY_LIST:
167 list_request = SET_ARRAY_LIST;
168 break;
169 case SET_VERSION:
170 list_request = SET_VERSION;
171 break;
172 case SET_DELIMITER:
173 if (s_arg[i_arg].n_items < 2)
174 SDDS_Bomb("invalid -delimiter syntax");
175 delimiter = s_arg[i_arg].list[1];
176 break;
177 case SET_APPEND_UNITS:
178 append_units = 1;
179 if (s_arg[i_arg].n_items == 2) {
180 if (strncmp(s_arg[i_arg].list[1], "bare", strlen(s_arg[i_arg].list[1])) == 0)
181 unitsTemplate = " %s";
182 else
183 SDDS_Bomb("invalid -appendUnits syntax");
184 } else if (s_arg[i_arg].n_items > 2)
185 SDDS_Bomb("invalid -appendUnits syntax");
186 else
187 unitsTemplate = " (%s)";
188 break;
189 case SET_PIPE:
190 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
191 SDDS_Bomb("invalid -pipe syntax");
192 break;
193 case SET_SDDSOUTPUT:
194 sddsOutput = 1;
195 sddsOutputFile = NULL;
196 if ((s_arg[i_arg].n_items != 1 && s_arg[i_arg].n_items != 2) ||
197 (s_arg[i_arg].n_items == 2 && SDDS_StringIsBlank(sddsOutputFile = s_arg[i_arg].list[1])))
198 SDDS_Bomb("invalid -sddsOutput syntax");
199 break;
200 case SET_READALL:
201 readAll = 1;
202 break;
203 default:
204 bomb("unknown switch", USAGE);
205 break;
206 }
207 } else {
208 filename = trealloc(filename, sizeof(*filename) * (filenames + 1));
209 filename[filenames++] = s_arg[i_arg].list[0];
210 }
211 }
212
213 if (!filenames && !(pipeFlags & USE_STDIN))
214 bomb(NULL, USAGE);
215 if (pipeFlags & USE_STDIN) {
216 char **filename1;
217 filename1 = tmalloc(sizeof(*filename1) * (filenames + 1));
218 filename1[0] = NULL;
219 for (file = 0; file < filenames; file++)
220 filename1[file + 1] = filename[file];
221 if (filename)
222 free(filename);
223 filename = filename1;
224 filenames++;
225 }
226#ifdef DEBUG
227 fprintf(stderr, "files: ");
228 for (file = 0; file < filenames; file++)
229 fprintf(stderr, "%s ", filename[file] ? filename[file] : "NULL");
230 fprintf(stderr, "\n");
231#endif
232
233 if (sddsOutput && !InitializeSDDSHeaderOutput(&SDDSout, sddsOutputFile)) {
234 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
235 exit(EXIT_FAILURE);
236 }
237
238 for (file = 0; file < filenames; file++) {
239#ifdef DEBUG
240 fprintf(stderr, "working on file %ld\n", file);
241#endif
242 if (list_request != SET_VERSION && !SDDS_InitializeInput(&SDDS_dataset, filename[file])) {
243 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
244 exit(EXIT_FAILURE);
245 }
246#ifdef DEBUG
247 fprintf(stderr, "file initialized\n");
248#endif
249 if (sddsOutput) {
250#ifdef DEBUG
251 fprintf(stderr, "Making SDDS header summary\n");
252#endif
253 if (!MakeSDDSHeaderSummary(&SDDSout, &SDDS_dataset, list_request, filename[file])) {
254 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
255 exit(EXIT_FAILURE);
256 }
257#ifdef SOLARIS
258 if (!SDDS_Terminate(&SDDS_dataset)) {
259 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
260 exit(EXIT_FAILURE);
261 }
262#endif
263 continue;
264 }
265 layout = &SDDS_dataset.layout;
266 if (list_request >= 0) {
267 switch (list_request) {
268 case SET_COLUMN_LIST:
269#ifdef DEBUG
270 fprintf(stderr, "printing column info\n");
271#endif
272 for (i = 0; i < layout->n_columns; i++) {
273 fputs(layout->column_definition[i].name, stdout);
274 if (append_units && layout->column_definition[i].units &&
275 !SDDS_StringIsBlank(layout->column_definition[i].units))
276 fprintf(stdout, unitsTemplate, layout->column_definition[i].units);
277 fputs(delimiter ? delimiter : "\n", stdout);
278 }
279 break;
280 case SET_PARAMETER_LIST:
281#ifdef DEBUG
282 fprintf(stderr, "printing parameter info\n");
283#endif
284 for (i = 0; i < layout->n_parameters; i++) {
285 fputs(layout->parameter_definition[i].name, stdout);
286 if (append_units && layout->parameter_definition[i].units &&
287 !SDDS_StringIsBlank(layout->parameter_definition[i].units))
288 fprintf(stdout, unitsTemplate, layout->parameter_definition[i].units);
289 fputs(delimiter ? delimiter : "\n", stdout);
290 }
291 break;
292 case SET_ASSOCIATE_LIST:
293#ifdef DEBUG
294 fprintf(stderr, "printing associate info\n");
295#endif
296 for (i = 0; i < layout->n_associates; i++) {
297 fputs(layout->associate_definition[i].filename, stdout);
298 fputs(delimiter ? delimiter : "\n", stdout);
299 }
300 break;
301 case SET_ARRAY_LIST:
302#ifdef DEBUG
303 fprintf(stderr, "printing array info\n");
304#endif
305 for (i = 0; i < layout->n_arrays; i++) {
306 fputs(layout->array_definition[i].name, stdout);
307 if (append_units && layout->array_definition[i].units &&
308 !SDDS_StringIsBlank(layout->array_definition[i].units))
309 fprintf(stdout, unitsTemplate, layout->array_definition[i].units);
310 fputs(delimiter ? delimiter : "\n", stdout);
311 }
312 break;
313 case SET_VERSION:
314#ifdef DEBUG
315 fprintf(stderr, "printing version info\n");
316#endif
317 s[0] = 0;
318 if (!(fp = fopen(filename[file], "r")) || !fgets(s, SDDS_MAXLINE, fp)) {
319 puts("-1");
320 exit(EXIT_FAILURE);
321 }
322 if (strncmp(s, "SDDS", 4) != 0)
323 puts("0");
324 else {
325 if (!(ptr = strchr(s, '\n')))
326 puts("0");
327 else {
328 *ptr = 0;
329 puts(s + 4);
330 }
331 }
332 fclose(fp);
333 break;
334 default:
335 SDDS_Bomb("something impossible happened!");
336 break;
337 }
338 if (readAll) {
339 while (SDDS_ReadPageSparse(&SDDS_dataset, 0, 1000, 0, 0) > 0)
340 ;
341 }
342#ifdef SOLARIS
343 if (list_request != SET_VERSION && !SDDS_Terminate(&SDDS_dataset)) {
344 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
345 exit(EXIT_FAILURE);
346 }
347#endif
348 exit(EXIT_SUCCESS);
349 }
350
351 fprintf(stdout, "\nfile %s is in SDDS protocol version %" PRId32 "\n",
352 filename[file] ? filename[file] : "stdin", layout->version);
353 if (!SDDS_GetDescription(&SDDS_dataset, &text, &contents))
354 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
355 if (text)
356 fprintf(stdout, "description: %s\n", text);
357 if (contents)
358 fprintf(stdout, "contents: %s\n", contents);
359 if (layout->data_mode.mode == SDDS_ASCII) {
360 fprintf(stdout, "\ndata is ASCII with %" PRId32 " lines per row and %" PRId32 " additional header lines expected.\n",
361 layout->data_mode.lines_per_row, layout->data_mode.additional_header_lines);
362 fprintf(stdout, "row counts: %s\n", layout->data_mode.no_row_counts ? "no" : "yes");
363 } else {
364 if (!SDDS_dataset.layout.byteOrderDeclared)
365 fprintf(stdout, "data is binary (no byte order declared)\n");
366 else if (SDDS_IsBigEndianMachine()) {
367 if (SDDS_dataset.swapByteOrder)
368 fprintf(stdout, "data is little-endian binary\n");
369 else
370 fprintf(stdout, "data is big-endian binary\n");
371 } else {
372 if (SDDS_dataset.swapByteOrder)
373 fprintf(stdout, "data is big-endian binary\n");
374 else
375 fprintf(stdout, "data is little-endian binary\n");
376 }
377 }
378
379 if (layout->n_columns) {
380 fprintf(stdout, "\n%" PRId32 " columns of data:\n", layout->n_columns);
381 fprintf(stdout, "NAME UNITS SYMBOL FORMAT TYPE FIELD DESCRIPTION\n");
382 fprintf(stdout, " LENGTH\n");
383 for (i = 0; i < layout->n_columns; i++) {
384 coldef = layout->column_definition + i;
385 fprintf(stdout, "%-15s %-15s %-15s %-15s %-7s %-7" PRId32 " %s\n",
386 coldef->name ? coldef->name : "NULL",
387 coldef->units ? coldef->units : "NULL",
388 coldef->symbol ? coldef->symbol : "NULL",
389 coldef->format_string ? coldef->format_string : "NULL",
390 SDDS_type_name[coldef->type - 1] ? SDDS_type_name[coldef->type - 1] : "NULL",
391 coldef->field_length, coldef->description ? coldef->description : "NULL");
392 }
393 }
394
395 if (layout->n_parameters) {
396 fprintf(stdout, "\n%" PRId32 " parameters:\n", layout->n_parameters);
397 fprintf(stdout, "NAME UNITS SYMBOL TYPE DESCRIPTION\n");
398 for (i = 0; i < layout->n_parameters; i++) {
399 pardef = layout->parameter_definition + i;
400 fprintf(stdout, "%-19s %-19s %-19s %-19s %s\n",
401 pardef->name ? pardef->name : "NULL",
402 pardef->units ? pardef->units : "NULL",
403 pardef->symbol ? pardef->symbol : "NULL",
404 SDDS_type_name[pardef->type - 1] ? SDDS_type_name[pardef->type - 1] : "NULL",
405 pardef->description ? pardef->description : "NULL");
406 }
407 }
408
409 if (layout->n_arrays) {
410 fprintf(stdout, "\n%" PRId32 " arrays of data:\n", layout->n_arrays);
411 fprintf(stdout, "NAME UNITS SYMBOL FORMAT TYPE FIELD GROUP DESCRIPTION\n");
412 fprintf(stdout, " LENGTH NAME\n");
413 for (i = 0; i < layout->n_arrays; i++) {
414 arraydef = layout->array_definition + i;
415 fprintf(stdout, "%-15s %-15s %-15s %-7s %-8s*^%-5" PRId32 " %-7" PRId32 " %-15s %s\n",
416 arraydef->name ? arraydef->name : "NULL",
417 arraydef->units ? arraydef->units : "NULL",
418 arraydef->symbol ? arraydef->symbol : "NULL",
419 arraydef->format_string ? arraydef->format_string : "NULL",
420 SDDS_type_name[arraydef->type - 1],
421 arraydef->dimensions,
422 arraydef->field_length,
423 arraydef->group_name ? arraydef->group_name : "NULL",
424 arraydef->description ? arraydef->description : "NULL");
425 }
426 }
427
428 if (layout->n_associates) {
429 fprintf(stdout, "\n%" PRId32 " associates:\n", layout->n_associates);
430 fprintf(stdout, "SDDS FILENAME PATH CONTENTS DESCRIPTION\n");
431 for (i = 0; i < layout->n_associates; i++)
432 fprintf(stdout, "%-5s %-19s %-29s %-19s %s\n",
433 layout->associate_definition[i].sdds ? "yes" : "no",
434 layout->associate_definition[i].filename ? layout->associate_definition[i].filename : "NULL",
435 layout->associate_definition[i].path ? layout->associate_definition[i].path : "NULL",
436 layout->associate_definition[i].contents ? layout->associate_definition[i].contents : "NULL",
437 layout->associate_definition[i].description ? layout->associate_definition[i].description : "NULL");
438 }
439 fflush(stdout);
440 if (readAll) {
441 while (SDDS_ReadPageSparse(&SDDS_dataset, 0, 1000, 0, 0) > 0)
442 ;
443 }
444 if (!SDDS_Terminate(&SDDS_dataset)) {
445 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
446 exit(EXIT_FAILURE);
447 }
448 }
449 if (sddsOutput && !SDDS_Terminate(&SDDSout)) {
450 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
451 exit(EXIT_FAILURE);
452 }
453 return EXIT_SUCCESS;
454}
455
456static long indexName, indexUnits, indexSymbol, indexFormat, indexType, indexDescription, indexGroup;
457
458long InitializeSDDSHeaderOutput(SDDS_DATASET *outSet, char *filename) {
459 if (!SDDS_InitializeOutput(outSet, SDDS_BINARY, 0, NULL, NULL, filename))
460 return 0;
461 if (0 > (indexName = SDDS_DefineColumn(outSet, "Name", NULL, NULL, NULL, NULL, SDDS_STRING, 0)) ||
462 0 > (indexUnits = SDDS_DefineColumn(outSet, "Units", NULL, NULL, NULL, NULL, SDDS_STRING, 0)) ||
463 0 > (indexSymbol = SDDS_DefineColumn(outSet, "Symbol", NULL, NULL, NULL, NULL, SDDS_STRING, 0)) ||
464 0 > (indexFormat = SDDS_DefineColumn(outSet, "Format", NULL, NULL, NULL, NULL, SDDS_STRING, 0)) ||
465 0 > (indexType = SDDS_DefineColumn(outSet, "Type", NULL, NULL, NULL, NULL, SDDS_STRING, 0)) ||
466 0 > (indexDescription = SDDS_DefineColumn(outSet, "Description", NULL, NULL, NULL, NULL, SDDS_STRING, 0)) ||
467 0 > (indexGroup = SDDS_DefineColumn(outSet, "Group", NULL, NULL, NULL, NULL, SDDS_STRING, 0)))
468 return 0;
469 if (0 > SDDS_DefineParameter(outSet, "Class", NULL, NULL, NULL, NULL, SDDS_STRING, 0) ||
470 0 > SDDS_DefineParameter(outSet, "Filename", NULL, NULL, NULL, NULL, SDDS_STRING, 0))
471 return 0;
472 if (!SDDS_WriteLayout(outSet))
473 return 0;
474 return 1;
475}
476
477long MakeSDDSHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, long listRequest, char *inputFile) {
478 switch (listRequest) {
479 case SET_COLUMN_LIST:
480 if (!MakeColumnHeaderSummary(outSet, inSet, inputFile))
481 return 0;
482 break;
483 case SET_PARAMETER_LIST:
484 if (!MakeParameterHeaderSummary(outSet, inSet, inputFile))
485 return 0;
486 break;
487 case SET_ARRAY_LIST:
488 if (!MakeArrayHeaderSummary(outSet, inSet, inputFile))
489 return 0;
490 break;
491 default:
492 if (!MakeColumnHeaderSummary(outSet, inSet, inputFile) ||
493 !MakeParameterHeaderSummary(outSet, inSet, inputFile) ||
494 !MakeArrayHeaderSummary(outSet, inSet, inputFile))
495 return 0;
496 break;
497 }
498 return 1;
499}
500
501long MakeColumnHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, char *inputFile) {
502 SDDS_LAYOUT *layout;
503 COLUMN_DEFINITION *coldef;
504 long i;
505
506 layout = &inSet->layout;
507 if (!layout->n_columns)
508 return 1;
509 if (!SDDS_StartPage(outSet, layout->n_columns))
510 return 0;
511 for (i = 0; i < layout->n_columns; i++) {
512 coldef = layout->column_definition + i;
513 if (!SDDS_SetRowValues(outSet, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i,
514 indexName, coldef->name,
515 indexUnits, coldef->units,
516 indexSymbol, coldef->symbol,
517 indexFormat, coldef->format_string,
518 indexType, SDDS_type_name[coldef->type - 1],
519 indexDescription, coldef->description,
520 indexGroup, NULL, -1))
521 return 0;
522 }
523 if (!SDDS_SetParameters(outSet, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
524 "Class", "column",
525 "Filename", inputFile,
526 NULL))
527 return 0;
528 if (!SDDS_WritePage(outSet))
529 return 0;
530 return 1;
531}
532
533long MakeParameterHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, char *inputFile) {
534 SDDS_LAYOUT *layout;
535 PARAMETER_DEFINITION *pardef;
536 long i;
537
538 layout = &inSet->layout;
539 if (!layout->n_parameters)
540 return 1;
541 if (!SDDS_StartPage(outSet, layout->n_parameters))
542 return 0;
543 for (i = 0; i < layout->n_parameters; i++) {
544 pardef = layout->parameter_definition + i;
545 if (!SDDS_SetRowValues(outSet, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i,
546 indexName, pardef->name,
547 indexUnits, pardef->units,
548 indexSymbol, pardef->symbol,
549 indexFormat, pardef->format_string,
550 indexType, SDDS_type_name[pardef->type - 1],
551 indexDescription, pardef->description,
552 indexGroup, NULL, -1))
553 return 0;
554 }
555 if (!SDDS_SetParameters(outSet, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
556 "Class", "parameter",
557 "Filename", inputFile,
558 NULL))
559 return 0;
560 if (!SDDS_WritePage(outSet))
561 return 0;
562 return 1;
563}
564
565long MakeArrayHeaderSummary(SDDS_DATASET *outSet, SDDS_DATASET *inSet, char *inputFile) {
566 SDDS_LAYOUT *layout;
567 ARRAY_DEFINITION *arrdef;
568 long i;
569
570 layout = &inSet->layout;
571 if (!layout->n_arrays)
572 return 1;
573 if (!SDDS_StartPage(outSet, layout->n_arrays))
574 return 0;
575 for (i = 0; i < layout->n_arrays; i++) {
576 arrdef = layout->array_definition + i;
577 if (!SDDS_SetRowValues(outSet, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, i,
578 indexName, arrdef->name,
579 indexUnits, arrdef->units,
580 indexSymbol, arrdef->symbol,
581 indexFormat, arrdef->format_string,
582 indexType, SDDS_type_name[arrdef->type - 1],
583 indexDescription, arrdef->description,
584 indexGroup, arrdef->group_name,
585 -1))
586 return 0;
587 }
588 if (!SDDS_SetParameters(outSet, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
589 "Class", "array",
590 "Filename", inputFile,
591 NULL))
592 return 0;
593 if (!SDDS_WritePage(outSet))
594 return 0;
595 return 1;
596}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
Definition SDDS_data.c:43
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,...)
int32_t SDDS_GetDescription(SDDS_DATASET *SDDS_dataset, char **text, char **contents)
Retrieves the text and contents descriptions from an SDDS dataset.
int32_t SDDS_ReadPageSparse(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
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_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_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
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
Definition bomb.c:26
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