SDDSlib
Loading...
Searching...
No Matches
sdds2stream.c File Reference

Utility for streaming SDDS data values. More...

#include "mdb.h"
#include "SDDS.h"
#include "scan.h"

Go to the source code of this file.

Macros

#define SET_COLUMNS   0
 
#define SET_PARAMETERS   1
 
#define SET_TABLE   2
 
#define SET_DELIMITER   3
 
#define SET_FILENAMES   4
 
#define SET_ROWS   5
 
#define SET_NOQUOTES   6
 
#define SET_PIPE   7
 
#define SET_PAGE   8
 
#define SET_ARRAYS   9
 
#define SET_IGNOREFORMATS   10
 
#define SET_DESCRIPTION   11
 
#define SET_SHOW_PAGES   12
 
#define N_OPTIONS   13
 

Functions

long SDDS_SprintTypedValue2 (char *s, char *format, char *buffer, unsigned long mode)
 
int main (int argc, char **argv)
 

Variables

char * option [N_OPTIONS]
 
char * USAGE
 

Detailed Description

Utility for streaming SDDS data values.

This program reads an SDDS data set and outputs selected column or parameter values in a delimited format. Users can specify the columns, parameters, or arrays to stream, as well as other options like page filtering, row counting, and delimiter customization.

@features

  • Stream data values from specified columns, parameters, or arrays.
  • Output is formatted as delimited text, with customizable delimiters.
  • Handles multiple input files and multiple data pages.
  • Includes options for filtering by page or rows.

@usage

sdds2stream [-pipe] [<SDDSinput>...]
[-columns=<column-name>[,...]]
[-parameters=<parameter-name>[,...]]
[-arrays=<array-name>[,...]]
[-page=<pageNumber>] [-delimiter=<delimiting-string>]
[-filenames] [-rows[=bare][,total][,scientific]]
[-npages=<bare>] [-noquotes]
[-ignoreFormats] [-description]

Examples:

sdds2stream -columns=x,y input.sdds
sdds2stream -columns=x,y -delimiter=\\, input.sdds > output.csv
License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file sdds2stream.c.

Macro Definition Documentation

◆ N_OPTIONS

#define N_OPTIONS   13

Definition at line 63 of file sdds2stream.c.

◆ SET_ARRAYS

#define SET_ARRAYS   9

Definition at line 59 of file sdds2stream.c.

◆ SET_COLUMNS

#define SET_COLUMNS   0

Definition at line 49 of file sdds2stream.c.

◆ SET_DELIMITER

#define SET_DELIMITER   3

Definition at line 53 of file sdds2stream.c.

◆ SET_DESCRIPTION

#define SET_DESCRIPTION   11

Definition at line 61 of file sdds2stream.c.

◆ SET_FILENAMES

#define SET_FILENAMES   4

Definition at line 54 of file sdds2stream.c.

◆ SET_IGNOREFORMATS

#define SET_IGNOREFORMATS   10

Definition at line 60 of file sdds2stream.c.

◆ SET_NOQUOTES

#define SET_NOQUOTES   6

Definition at line 56 of file sdds2stream.c.

◆ SET_PAGE

#define SET_PAGE   8

Definition at line 58 of file sdds2stream.c.

◆ SET_PARAMETERS

#define SET_PARAMETERS   1

Definition at line 50 of file sdds2stream.c.

◆ SET_PIPE

#define SET_PIPE   7

Definition at line 57 of file sdds2stream.c.

◆ SET_ROWS

#define SET_ROWS   5

Definition at line 55 of file sdds2stream.c.

◆ SET_SHOW_PAGES

#define SET_SHOW_PAGES   12

Definition at line 62 of file sdds2stream.c.

◆ SET_TABLE

#define SET_TABLE   2

Definition at line 52 of file sdds2stream.c.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 101 of file sdds2stream.c.

101 {
102 SDDS_DATASET SDDS_dataset;
103 long i, k, i_arg, retval, description;
104 int64_t j, rows;
105 SCANNED_ARG *s_arg;
106 char **input;
107 char **column_name, **parameter_name, **array_name;
108 char **parameterFormat, **columnFormat, **arrayFormat;
109 long column_names, parameter_names, array_names, page_number, *type, inputs;
110 char *delimiter;
111 void **data;
112 char *buffer;
113 long filenames, print_rows, print_pages, noQuotes, pipe, ignoreFormats;
114 static char printBuffer[SDDS_MAXLINE * 16];
115 long n_rows_bare, n_rows_total, n_pages, n_pages_bare, n_rows_scinotation;
116 int64_t n_rows;
117
119 argc = scanargs(&s_arg, argc, argv);
120 if (argc < 3)
121 bomb(NULL, USAGE);
122
123 type = NULL;
124 data = NULL;
125 buffer = tmalloc(sizeof(char) * 16); /* large enough for any data type */
126 delimiter = NULL;
127 input = parameter_name = column_name = array_name = NULL;
128 parameterFormat = columnFormat = arrayFormat = NULL;
129 inputs = parameter_names = column_names = array_names = 0;
130 page_number = filenames = ignoreFormats = 0;
131 n_rows = n_rows_bare = n_rows_total = n_pages = n_pages_bare = 0;
132 print_rows = print_pages = noQuotes = pipe = description = 0;
133 n_rows_scinotation = 0;
134
135 /* Parse command-line arguments */
136 for (i_arg = 1; i_arg < argc; i_arg++) {
137 if (s_arg[i_arg].arg_type == OPTION) {
138 int optIndex = match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0);
139 switch (optIndex) {
140 case SET_COLUMNS:
141 if (s_arg[i_arg].n_items < 2)
142 SDDS_Bomb("invalid -columns syntax");
143 if (column_names)
144 SDDS_Bomb("invalid syntax: specify -columns once only");
145 column_name = tmalloc(sizeof(*column_name) * (s_arg[i_arg].n_items - 1));
146 for (i = 1; i < s_arg[i_arg].n_items; i++)
147 column_name[i - 1] = s_arg[i_arg].list[i];
148 column_names = s_arg[i_arg].n_items - 1;
149 break;
150
151 case SET_PARAMETERS:
152 if (s_arg[i_arg].n_items < 2)
153 SDDS_Bomb("invalid -parameters syntax");
154 if (parameter_names)
155 SDDS_Bomb("invalid syntax: specify -parameters once only");
156 parameter_name = tmalloc(sizeof(*parameter_name) * (s_arg[i_arg].n_items - 1));
157 for (i = 1; i < s_arg[i_arg].n_items; i++)
158 parameter_name[i - 1] = s_arg[i_arg].list[i];
159 parameter_names = s_arg[i_arg].n_items - 1;
160 break;
161
162 case SET_ARRAYS:
163 if (s_arg[i_arg].n_items < 2)
164 SDDS_Bomb("invalid -arrays syntax");
165 if (array_names)
166 SDDS_Bomb("invalid syntax: specify -arrays once only");
167 array_name = tmalloc(sizeof(*array_name) * (s_arg[i_arg].n_items - 1));
168 for (i = 1; i < s_arg[i_arg].n_items; i++)
169 array_name[i - 1] = s_arg[i_arg].list[i];
170 array_names = s_arg[i_arg].n_items - 1;
171 break;
172
173 case SET_TABLE:
174 case SET_PAGE:
175 if (s_arg[i_arg].n_items < 2 || s_arg[i_arg].n_items > 2)
176 SDDS_Bomb("invalid -page syntax");
177 if (page_number != 0)
178 SDDS_Bomb("invalid syntax: specify -page once only");
179 if (sscanf(s_arg[i_arg].list[1], "%ld", &page_number) != 1 || page_number <= 0)
180 SDDS_Bomb("invalid -page syntax or value");
181 break;
182
183 case SET_DELIMITER:
184 if (s_arg[i_arg].n_items < 2)
185 SDDS_Bomb("invalid -delimiter syntax");
186 delimiter = s_arg[i_arg].list[1];
187 break;
188
189 case SET_FILENAMES:
190 filenames = 1;
191 break;
192
193 case SET_ROWS:
194 if (s_arg[i_arg].n_items > 4)
195 SDDS_Bomb("invalid -rows syntax");
196 else {
197 char *rowsOutputMode[3] = {"bare", "total", "scientific"};
198 for (i = 1; i < s_arg[i_arg].n_items; i++) {
199 int rm = match_string(s_arg[i_arg].list[i],
200 rowsOutputMode, 3, 0);
201 if (rm == 0)
202 n_rows_bare = 1;
203 else if (rm == 1)
204 n_rows_total = 1;
205 else if (rm == 2)
206 n_rows_scinotation = 1;
207 else
208 SDDS_Bomb("unknown output mode for -rows option");
209 }
210 }
211 print_rows = 1;
212 break;
213
214 case SET_SHOW_PAGES:
215 if (s_arg[i_arg].n_items > 2)
216 SDDS_Bomb("invalid -pages syntax");
217 else {
218 char *pagesOutputMode[1] = {"bare"};
219 for (i = 1; i < s_arg[i_arg].n_items; i++) {
220 if (strcmp(s_arg[i_arg].list[i], "") != 0) {
221 int pm = match_string(s_arg[i_arg].list[i],
222 pagesOutputMode, 1, 0);
223 if (pm == 0)
224 n_pages_bare = 1;
225 else
226 SDDS_Bomb("unknown output mode for -npages option");
227 } else
228 SDDS_Bomb("unknown output mode for -npages option");
229 }
230 }
231 print_pages = 1;
232 break;
233
234 case SET_NOQUOTES:
235 noQuotes = 1;
236 break;
237
238 case SET_PIPE:
239 pipe = 1;
240 break;
241
242 case SET_IGNOREFORMATS:
243 ignoreFormats = 1;
244 break;
245
246 case SET_DESCRIPTION:
247 description = 1;
248 break;
249
250 default:
251 fprintf(stderr, "error: unknown switch: %s\n",
252 s_arg[i_arg].list[0]);
253 exit(1);
254 break;
255 }
256 } else {
257 input = trealloc(input, sizeof(*input) * (inputs + 1));
258 input[inputs++] = s_arg[i_arg].list[0];
259 }
260 }
261
262 if (!inputs) {
263 if (!pipe)
264 SDDS_Bomb("too few filenames");
265 inputs = 1;
266 input = trealloc(input, sizeof(*input) * (inputs + 1));
267 input[0] = NULL;
268 }
269
270 if (!column_names && !parameter_names && !array_names && !print_rows && !description && !print_pages)
271 SDDS_Bomb("you must specify one of -columns, -parameters, "
272 "-arrays, -rows or -description");
273
274 if (!delimiter) {
275 if (column_names || array_names)
276 cp_str(&delimiter, " ");
277 else
278 cp_str(&delimiter, "\n");
279 }
280
281 SDDS_SetTerminateMode(TERMINATE_DONT_FREE_TABLE_STRINGS + TERMINATE_DONT_FREE_ARRAY_STRINGS);
282
283 /* Process each input file */
284 for (k = 0; k < inputs; k++) {
285 if (!SDDS_InitializeInput(&SDDS_dataset, input[k])) {
286 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
287 exit(1);
288 }
289 n_pages = 0;
290
291 /* Setup columns, parameters, or arrays */
292 if (column_names) {
293 if (k == 0) {
294 type = tmalloc(sizeof(*type) * column_names);
295 data = tmalloc(sizeof(*data) * column_names);
296 columnFormat = tmalloc(sizeof(*columnFormat) * column_names);
297 }
298 for (i = 0; i < column_names; i++) {
299 j = SDDS_GetColumnIndex(&SDDS_dataset, column_name[i]);
300 if (j < 0) {
301 fprintf(stderr, "error: column %s does not exist\n",
302 column_name[i]);
303 exit(1);
304 }
305 type[i] = SDDS_GetColumnType(&SDDS_dataset, j);
306 if (type[i] <= 0 || !SDDS_GetColumnInformation(&SDDS_dataset,
307 "format_string",
308 columnFormat + i,
309 SDDS_GET_BY_INDEX, j)) {
310 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
311 exit(1);
312 }
313 }
314 } else if (array_names) {
315 if (k == 0) {
316 type = tmalloc(sizeof(*type) * array_names);
317 data = tmalloc(sizeof(*data) * array_names);
318 arrayFormat = tmalloc(sizeof(*arrayFormat) * array_names);
319 }
320
321 for (i = 0; i < array_names; i++) {
322 j = SDDS_GetArrayIndex(&SDDS_dataset, array_name[i]);
323 if (j < 0) {
324 fprintf(stderr, "error: array %s does not exist\n",
325 array_name[i]);
326 exit(1);
327 }
328 type[i] = SDDS_GetArrayType(&SDDS_dataset, j);
329 if (type[i] <= 0 || !SDDS_GetArrayInformation(&SDDS_dataset, "format_string",
330 arrayFormat + i,
331 SDDS_BY_INDEX, j)) {
332 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
333 exit(1);
334 }
335 }
336 } else if (parameter_names) {
337 if (k == 0) {
338 type = tmalloc(sizeof(*type) * parameter_names);
339 parameterFormat = tmalloc(sizeof(*parameterFormat) * parameter_names);
340 }
341 for (i = 0; i < parameter_names; i++) {
342 j = SDDS_GetParameterIndex(&SDDS_dataset, parameter_name[i]);
343 if (j < 0) {
344 fprintf(stderr, "error: parameter %s does not exist\n",
345 parameter_name[i]);
346 exit(1);
347 }
348 type[i] = SDDS_GetParameterType(&SDDS_dataset, j);
349 if (type[i] <= 0 || !SDDS_GetParameterInformation(&SDDS_dataset,
350 "format_string",
351 parameterFormat + i,
352 SDDS_BY_INDEX, j)) {
353 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
354 exit(1);
355 }
356 }
357 }
358
359 /* Print description if requested */
360 if (description) {
361 if (!SDDS_SprintTypedValue2(SDDS_dataset.layout.description, NULL,
362 printBuffer,
363 noQuotes ? SDDS_PRINT_NOQUOTES : 0)) {
364 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
365 exit(1);
366 }
367
368 fputs(printBuffer, stdout);
369 fprintf(stdout, "%s", delimiter);
370
371 if (!SDDS_SprintTypedValue2(SDDS_dataset.layout.contents, NULL,
372 printBuffer,
373 noQuotes ? SDDS_PRINT_NOQUOTES : 0)) {
374 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
375 exit(1);
376 }
377 fputs(printBuffer, stdout);
378 fprintf(stdout, "%s", delimiter);
379
380 if (!strchr(delimiter, '\n'))
381 fputc('\n', stdout);
382 }
383
384 retval = -1;
385 while (retval != page_number && (retval = SDDS_ReadPage(&SDDS_dataset)) > 0) {
386 if (page_number && retval != page_number)
387 continue;
388
389 if (print_rows) {
390 uint64_t counti = SDDS_CountRowsOfInterest(&SDDS_dataset);
391 if (n_rows_total && !page_number) {
392 n_rows += counti;
393 } else {
394 if (!n_rows_scinotation || counti == 0) {
395 if (n_rows_bare)
396 fprintf(stdout, "%" PRId64 "\n", (int64_t)counti);
397 else
398 fprintf(stdout, "%" PRId64 " rows\n", (int64_t)counti);
399 } else {
400 char format[20];
401 double count = counti;
402 snprintf(format, 20, "%%.%ldle%s",
403 (long)(log10(count)),
404 n_rows_bare ? "" : " rows");
405 fprintf(stdout, format, count);
406 fputc('\n', stdout);
407 }
408 }
409 }
410
411 if (column_names) {
412 rows = SDDS_CountRowsOfInterest(&SDDS_dataset);
413 if (rows < 0) {
414 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
415 exit(1);
416 }
417 if (rows) {
418 if (filenames) {
419 fprintf(stdout, "%s%s", input[k], delimiter);
420 if (!strchr(delimiter, '\n'))
421 fputc('\n', stdout);
422 }
423 for (i = 0; i < column_names; i++) {
424 data[i] = SDDS_GetInternalColumn(&SDDS_dataset,
425 column_name[i]);
426 if (!data[i]) {
427 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
428 exit(1);
429 }
430 }
431 for (j = 0; j < rows; j++) {
432 for (i = 0; i < column_names; i++) {
433 if (!SDDS_SprintTypedValue(data[i], j, type[i],
434 ignoreFormats ? NULL : columnFormat[i],
435 printBuffer,
436 noQuotes ? SDDS_PRINT_NOQUOTES : 0)) {
437 SDDS_PrintErrors(stderr,
438 SDDS_VERBOSE_PrintErrors);
439 exit(1);
440 }
441 fputs(printBuffer, stdout);
442 if (i != column_names - 1)
443 fprintf(stdout, "%s", delimiter);
444 }
445 fputc('\n', stdout);
446 }
447 }
448 } else if (array_names) {
449 SDDS_ARRAY *array;
450 if (filenames) {
451 fprintf(stdout, "%s%s", input[k], delimiter);
452 if (!strchr(delimiter, '\n'))
453 fputc('\n', stdout);
454 }
455 for (i = 0; i < array_names; i++) {
456 array = SDDS_GetArray(&SDDS_dataset, array_name[i], NULL);
457 if (!array) {
458 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
459 exit(1);
460 }
461 for (j = 0; j < array->elements; j++) {
462 if (!SDDS_SprintTypedValue(array->data, j, type[i],
463 ignoreFormats ? NULL : arrayFormat[i],
464 printBuffer,
465 noQuotes ? SDDS_PRINT_NOQUOTES : 0)) {
466 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
467 exit(1);
468 }
469 fputs(printBuffer, stdout);
470 fprintf(stdout, "%s", delimiter);
471 }
472 }
473 if (!strchr(delimiter, '\n'))
474 fputc('\n', stdout);
475 } else if (parameter_names) {
476 if (filenames)
477 fprintf(stdout, "%s%s", input[k], delimiter);
478 for (i = 0; i < parameter_names; i++) {
479 if (!SDDS_GetParameter(&SDDS_dataset, parameter_name[i],
480 buffer)) {
481 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
482 exit(1);
483 }
484 if (!SDDS_SprintTypedValue(buffer, 0, type[i],
485 ignoreFormats ? NULL : parameterFormat[i],
486 printBuffer,
487 noQuotes ? SDDS_PRINT_NOQUOTES : 0)) {
488 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
489 exit(1);
490 }
491 fputs(printBuffer, stdout);
492 fprintf(stdout, "%s", delimiter);
493 }
494 if (!strchr(delimiter, '\n'))
495 fputc('\n', stdout);
496 }
497
498 n_pages++;
499 }
500
501 if (retval == 0) {
502 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
503 exit(1);
504 } else {
505 if (print_rows && (n_rows_total || (retval == -1 && n_pages == 0)) && !page_number) {
506 if (!n_rows_scinotation || n_rows == 0) {
507 if (n_rows_bare)
508 fprintf(stdout, "%" PRId64 "\n", n_rows);
509 else
510 fprintf(stdout, "%" PRId64 " rows\n", n_rows);
511 } else {
512 char format[20];
513 double count = n_rows;
514 snprintf(format, 20, "%%.%ldle%s",
515 (long)(log10(count)),
516 n_rows_bare ? "" : " rows");
517 fprintf(stdout, format, count);
518 fputc('\n', stdout);
519 }
520 }
521 if (print_pages) {
522 if (n_pages_bare)
523 fprintf(stdout, "%ld\n", n_pages);
524 else
525 fprintf(stdout, "%ld pages\n", n_pages);
526 }
527 }
528 if (!SDDS_Terminate(&SDDS_dataset)) {
529 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
530 exit(1);
531 }
532 }
533 return 0;
534}
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
SDDS_ARRAY * SDDS_GetArray(SDDS_DATASET *SDDS_dataset, char *array_name, SDDS_ARRAY *memory)
Retrieves an array from the current data table of an SDDS dataset.
void * SDDS_GetInternalColumn(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves an internal pointer to the data of a specified column, including all rows.
void * SDDS_GetParameter(SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
Retrieves the value of a specified parameter from the current data table of a data set.
int32_t SDDS_GetArrayInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified array in the SDDS dataset.
Definition SDDS_info.c:192
int32_t SDDS_GetParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified parameter in the SDDS dataset.
Definition SDDS_info.c:117
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
void SDDS_SetTerminateMode(uint32_t mode)
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_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_SprintTypedValue(void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode)
Formats a data value of a specified type into a string buffer using an optional printf format string.
Definition SDDS_utils.c:151
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column 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.
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_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
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 * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
Definition cp_str.c:28
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

◆ SDDS_SprintTypedValue2()

long SDDS_SprintTypedValue2 ( char * s,
char * format,
char * buffer,
unsigned long mode )

Definition at line 536 of file sdds2stream.c.

536 {
537 char buffer2[SDDS_PRINT_BUFLEN];
538 short printed;
539
540 if (!s)
541 s = "";
542
543 if (!buffer) {
544 SDDS_SetError("Unable to print value--buffer pointer is NULL "
545 "(SDDS_SprintTypedValue2)");
546 return 0;
547 }
548 if ((long)strlen(s) > SDDS_PRINT_BUFLEN - 3) {
549 SDDS_SetError("Buffer size overflow (SDDS_SprintTypedValue2)");
550 return 0;
551 }
552
553 if (!(mode & SDDS_PRINT_NOQUOTES)) {
554 printed = 0;
555 if (!s || SDDS_StringIsBlank(s))
556 sprintf(buffer, "\"\"");
557 else if (strchr(s, '"')) {
558 strcpy(buffer2, s);
559 SDDS_EscapeQuotes(buffer2, '"');
560 if (SDDS_HasWhitespace(buffer2))
561 sprintf(buffer, "\"%s\"", buffer2);
562 else
563 strcpy(buffer, buffer2);
564 } else if (SDDS_HasWhitespace(s))
565 sprintf(buffer, "\"%s\"", s);
566 else {
567 sprintf(buffer, format ? format : "%s", s);
568 printed = 1;
569 }
570 if (!printed) {
571 sprintf(buffer2, format ? format : "%s", buffer);
572 strcpy(buffer, buffer2);
573 }
574 } else {
575 sprintf(buffer, format ? format : "%s", s);
576 }
577 return 1;
578}
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
void SDDS_EscapeQuotes(char *s, char quote_char)
Escapes quote characters within a string by inserting backslashes.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_HasWhitespace(char *string)
Checks if a string contains any whitespace characters.

Variable Documentation

◆ option

char* option[N_OPTIONS]
Initial value:
=
{
"columns",
"parameters",
"table",
"delimiter",
"filenames",
"rows",
"noquotes",
"pipe",
"page",
"arrays",
"ignoreformats",
"description",
"npages",
}

Definition at line 65 of file sdds2stream.c.

66 {
67 "columns",
68 "parameters",
69 "table",
70 "delimiter",
71 "filenames",
72 "rows",
73 "noquotes",
74 "pipe",
75 "page",
76 "arrays",
77 "ignoreformats",
78 "description",
79 "npages",
80 };

◆ USAGE

char* USAGE
Initial value:
= "sdds2stream [-pipe] [<SDDSinput>...]\n"
" [-columns=<column-name>[,...]]\n"
" [-parameters=<parameter-name>[,...]]\n"
" [-arrays=<array-name>[,...]]]\n"
" [-page=<pageNumber>] [-delimiter=<delimiting-string>]\n"
" [-filenames] [-rows[=bare][,total][,scientific]]\n"
" [-npages=<bare>] [-noquotes]\n"
" [-ignoreFormats] [-description]\n\n"
"sdds2stream provides stream output to the standard output of data values from "
"a group of columns or parameters. Each line of the output contains a different "
"row of the tabular data or a different parameter. Values from different columns "
"are separated by the delimiter string, which by default is a single space. "
"If -page is not employed, all data pages are output sequentially. "
"If multiple filenames are given, the files are processed sequentially in the "
"order given.\n\n"
"Program by Michael Borland. (" __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n"

Definition at line 82 of file sdds2stream.c.