24#include "match_string.h"
62 fprintf(fp,
"SDDS%" PRId32
"\n", version_number);
80 lzma_printf(lzmafp,
"SDDS%" PRId32
"\n", version_number);
96int32_t SDDS_GZipWriteVersion(int32_t version_number, gzFile gzfp) {
99 gzprintf(gzfp,
"SDDS%" PRId32
"\n", version_number);
123 char *buffer = NULL, *bPtr, *vPtr;
126 if (!value || !strlen(name))
129 fprintf(fp,
"%s=\"\", ", name);
131 if (strchr(value,
'"')) {
132 if (!(buffer =
SDDS_Malloc(
sizeof(*buffer) * 2 * strlen(value))))
144 if (strpbrk(value,
" ,*$\t\n\b"))
145 fprintf(fp,
"%s=\"%s\", ", name, value);
147 fprintf(fp,
"%s=%s, ", name, value);
167 char *buffer = NULL, *bPtr, *vPtr;
170 if (!value || !strlen(name))
173 lzma_printf(lzmafp,
"%s=\"\", ", name);
175 if (strchr(value,
'"')) {
176 if (!(buffer =
SDDS_Malloc(
sizeof(*buffer) * 2 * strlen(value))))
188 if (strpbrk(value,
" ,*$\t\n\b"))
189 lzma_printf(lzmafp,
"%s=\"%s\", ", name, value);
191 lzma_printf(lzmafp,
"%s=%s, ", name, value);
211int32_t SDDS_GZipPrintNamelistField(gzFile gzfp,
char *name,
char *value) {
212 char *buffer = NULL, *bPtr, *vPtr;
215 if (!value || !strlen(name))
218 gzprintf(gzfp,
"%s=\"\", ", name);
220 if (strchr(value,
'"')) {
221 if (!(buffer =
SDDS_Malloc(
sizeof(*buffer) * 2 * strlen(value))))
233 if (strpbrk(value,
" ,*$\t\n\b"))
234 gzprintf(gzfp,
"%s=\"%s\", ", name, value);
236 gzprintf(gzfp,
"%s=%s, ", name, value);
259 if (!text && !contents)
261 fputs(
"&description ", fp);
283 if (!text && !contents)
285 lzma_puts(
"&description ", lzmafp);
288 lzma_puts(
"&end\n", lzmafp);
305int32_t SDDS_GZipWriteDescription(
char *text,
char *contents, gzFile gzfp) {
308 if (!text && !contents)
310 gzputs(gzfp,
"&description ");
311 SDDS_GZipPrintNamelistField(gzfp,
"text", text);
312 SDDS_GZipPrintNamelistField(gzfp,
"contents", contents);
313 gzputs(gzfp,
"&end\n");
330 if (!fp || column_definition->type <= 0 || column_definition->type >
SDDS_NUM_TYPES)
333 fputs(
"&column ", fp);
340 fputs(
" &end\n", fp);
357 if (!lzmafp || column_definition->type <= 0 || column_definition->type >
SDDS_NUM_TYPES)
360 lzma_puts(
"&column ", lzmafp);
367 lzma_puts(
" &end\n", lzmafp);
384int32_t SDDS_GZipWriteColumnDefinition(
COLUMN_DEFINITION *column_definition, gzFile gzfp) {
385 if (!gzfp || column_definition->type <= 0 || column_definition->type >
SDDS_NUM_TYPES)
388 gzputs(gzfp,
"&column ");
389 SDDS_GZipPrintNamelistField(gzfp,
"name", column_definition->name);
390 SDDS_GZipPrintNamelistField(gzfp,
"symbol",
SDDS_BlankToNull(column_definition->symbol));
391 SDDS_GZipPrintNamelistField(gzfp,
"units",
SDDS_BlankToNull(column_definition->units));
392 SDDS_GZipPrintNamelistField(gzfp,
"description",
SDDS_BlankToNull(column_definition->description));
393 SDDS_GZipPrintNamelistField(gzfp,
"format_string",
SDDS_BlankToNull(column_definition->format_string));
394 SDDS_GZipPrintNamelistField(gzfp,
"type",
SDDS_type_name[column_definition->type - 1]);
395 gzputs(gzfp,
" &end\n");
412 if (!fp || parameter_definition->type <= 0 || parameter_definition->type >
SDDS_NUM_TYPES)
414 fputs(
"¶meter ", fp);
439 if (!lzmafp || parameter_definition->type <= 0 || parameter_definition->type >
SDDS_NUM_TYPES)
441 lzma_puts(
"¶meter ", lzmafp);
449 lzma_puts(
"&end\n", lzmafp);
466int32_t SDDS_GZipWriteParameterDefinition(
PARAMETER_DEFINITION *parameter_definition, gzFile gzfp) {
467 if (!gzfp || parameter_definition->type <= 0 || parameter_definition->type >
SDDS_NUM_TYPES)
469 gzputs(gzfp,
"¶meter ");
470 SDDS_GZipPrintNamelistField(gzfp,
"name", parameter_definition->name);
471 SDDS_GZipPrintNamelistField(gzfp,
"symbol",
SDDS_BlankToNull(parameter_definition->symbol));
472 SDDS_GZipPrintNamelistField(gzfp,
"units",
SDDS_BlankToNull(parameter_definition->units));
473 SDDS_GZipPrintNamelistField(gzfp,
"description",
SDDS_BlankToNull(parameter_definition->description));
474 SDDS_GZipPrintNamelistField(gzfp,
"format_string",
SDDS_BlankToNull(parameter_definition->format_string));
475 SDDS_GZipPrintNamelistField(gzfp,
"type",
SDDS_type_name[parameter_definition->type - 1]);
476 SDDS_GZipPrintNamelistField(gzfp,
"fixed_value", parameter_definition->fixed_value);
477 gzputs(gzfp,
"&end\n");
497 fputs(
"&associate ", fp);
503 fprintf(fp,
"sdds=%" PRId32, associate_definition->sdds);
504 fputs(
" &end\n", fp);
524 lzma_puts(
"&associate ", lzmafp);
530 lzma_printf(lzmafp,
"sdds=%" PRId32, associate_definition->sdds);
531 lzma_puts(
" &end\n", lzmafp);
548int32_t SDDS_GZipWriteAssociateDefinition(
ASSOCIATE_DEFINITION *associate_definition, gzFile gzfp) {
552 gzputs(gzfp,
"&associate ");
553 SDDS_GZipPrintNamelistField(gzfp,
"name", associate_definition->name);
554 SDDS_GZipPrintNamelistField(gzfp,
"filename",
SDDS_BlankToNull(associate_definition->filename));
555 SDDS_GZipPrintNamelistField(gzfp,
"contents",
SDDS_BlankToNull(associate_definition->contents));
556 SDDS_GZipPrintNamelistField(gzfp,
"path",
SDDS_BlankToNull(associate_definition->path));
557 SDDS_GZipPrintNamelistField(gzfp,
"description",
SDDS_BlankToNull(associate_definition->description));
558 gzprintf(gzfp,
"sdds=%" PRId32, associate_definition->sdds);
559 gzputs(gzfp,
" &end\n");
577 if (!fp || layout->data_mode.mode < 0 || layout->data_mode.mode > SDDS_NUM_DATA_MODES)
582 if (layout->data_mode.lines_per_row > 1)
583 fprintf(fp,
"lines_per_row=%" PRId32
", ", layout->data_mode.lines_per_row);
584 if (layout->data_mode.no_row_counts)
585 fprintf(fp,
"no_row_counts=1, ");
586 if (layout->version >= 3) {
587 if (layout->data_mode.mode == SDDS_BINARY) {
588 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
589 fprintf(fp,
"endian=big, ");
591 fprintf(fp,
"endian=little, ");
592 if (layout->data_mode.column_major)
593 fprintf(fp,
"column_major_order=1, ");
595 if (layout->data_mode.fixed_row_count)
596 fprintf(fp,
"fixed_row_count=1, ");
615 if (!lzmafp || layout->data_mode.mode < 0 || layout->data_mode.mode > SDDS_NUM_DATA_MODES)
618 lzma_puts(
"&data ", lzmafp);
620 if (layout->data_mode.lines_per_row > 1)
621 lzma_printf(lzmafp,
"lines_per_row=%" PRId32
", ", layout->data_mode.lines_per_row);
622 if (layout->data_mode.no_row_counts)
623 lzma_printf(lzmafp,
"no_row_counts=1, ");
624 if (layout->version >= 3) {
625 if (layout->data_mode.mode == SDDS_BINARY) {
626 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
627 lzma_printf(lzmafp,
"endian=big, ");
629 lzma_printf(lzmafp,
"endian=little, ");
630 if (layout->data_mode.column_major)
631 lzma_printf(lzmafp,
"column_major_order=1, ");
633 if (layout->data_mode.fixed_row_count)
634 lzma_printf(lzmafp,
"fixed_row_count=1, ");
636 lzma_puts(
"&end\n", lzmafp);
653int32_t SDDS_GZipWriteDataMode(
SDDS_LAYOUT *layout, gzFile gzfp) {
654 if (!gzfp || layout->data_mode.mode < 0 || layout->data_mode.mode > SDDS_NUM_DATA_MODES)
657 gzputs(gzfp,
"&data ");
658 SDDS_GZipPrintNamelistField(gzfp,
"mode",
SDDS_data_mode[layout->data_mode.mode - 1]);
659 if (layout->data_mode.lines_per_row > 1)
660 gzprintf(gzfp,
"lines_per_row=%" PRId32
", ", layout->data_mode.lines_per_row);
661 if (layout->data_mode.no_row_counts)
662 gzprintf(gzfp,
"no_row_counts=1, ");
663 if (layout->version >= 3) {
664 if (layout->data_mode.mode == SDDS_BINARY) {
665 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
666 gzprintf(gzfp,
"endian=big, ");
668 gzprintf(gzfp,
"endian=little, ");
669 if (layout->data_mode.column_major)
670 gzprintf(gzfp,
"column_major_order=1, ");
672 if (layout->data_mode.fixed_row_count)
673 gzprintf(gzfp,
"fixed_row_count=1, ");
675 gzputs(gzfp,
"&end\n");
693 if (!fp || array_definition->type <= 0 || array_definition->type >
SDDS_NUM_TYPES)
696 fputs(
"&array ", fp);
704 if (array_definition->dimensions != 1)
705 fprintf(fp,
"dimensions=%" PRId32
", ", array_definition->dimensions);
706 fputs(
" &end\n", fp);
723 if (!lzmafp || array_definition->type <= 0 || array_definition->type >
SDDS_NUM_TYPES)
726 lzma_puts(
"&array ", lzmafp);
734 if (array_definition->dimensions != 1)
735 lzma_printf(lzmafp,
"dimensions=%" PRId32
", ", array_definition->dimensions);
736 lzma_puts(
" &end\n", lzmafp);
753int32_t SDDS_GZipWriteArrayDefinition(
ARRAY_DEFINITION *array_definition, gzFile gzfp) {
754 if (!gzfp || array_definition->type <= 0 || array_definition->type >
SDDS_NUM_TYPES)
757 gzputs(gzfp,
"&array ");
758 SDDS_GZipPrintNamelistField(gzfp,
"name", array_definition->name);
759 SDDS_GZipPrintNamelistField(gzfp,
"symbol",
SDDS_BlankToNull(array_definition->symbol));
760 SDDS_GZipPrintNamelistField(gzfp,
"units",
SDDS_BlankToNull(array_definition->units));
761 SDDS_GZipPrintNamelistField(gzfp,
"description",
SDDS_BlankToNull(array_definition->description));
762 SDDS_GZipPrintNamelistField(gzfp,
"format_string",
SDDS_BlankToNull(array_definition->format_string));
763 SDDS_GZipPrintNamelistField(gzfp,
"group_name",
SDDS_BlankToNull(array_definition->group_name));
764 SDDS_GZipPrintNamelistField(gzfp,
"type",
SDDS_type_name[array_definition->type - 1]);
765 if (array_definition->dimensions != 1)
766 gzprintf(gzfp,
"dimensions=%" PRId32
", ", array_definition->dimensions);
767 gzputs(gzfp,
" &end\n");
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
char * SDDS_data_mode[SDDS_NUM_DATA_MODES]
Array of supported data modes.
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
Internal definitions and function declarations for SDDS with LZMA support.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_WriteAssociateDefinition(ASSOCIATE_DEFINITION *associate_definition, FILE *fp)
Writes an associate definition to a standard file.
int32_t SDDS_LZMAPrintNamelistField(struct lzmafile *lzmafp, char *name, char *value)
Writes a namelist field to an LZMA-compressed file.
int32_t SDDS_WriteColumnDefinition(COLUMN_DEFINITION *column_definition, FILE *fp)
Writes a column definition to a standard file.
int32_t SDDS_LZMAWriteDescription(char *text, char *contents, struct lzmafile *lzmafp)
Writes the SDDS description section to an LZMA-compressed file.
char * SDDS_BlankToNull(char *string)
Converts blank strings to NULL.
int32_t SDDS_LZMAWriteColumnDefinition(COLUMN_DEFINITION *column_definition, struct lzmafile *lzmafp)
Writes a column definition to an LZMA-compressed file.
int32_t SDDS_LZMAWriteVersion(int32_t version_number, struct lzmafile *lzmafp)
Writes the SDDS protocol version to an LZMA-compressed file.
int32_t SDDS_LZMAWriteArrayDefinition(ARRAY_DEFINITION *array_definition, struct lzmafile *lzmafp)
Writes an array definition to an LZMA-compressed file.
int32_t SDDS_PrintNamelistField(FILE *fp, char *name, char *value)
Writes a namelist field to a standard file.
int32_t SDDS_LZMAWriteParameterDefinition(PARAMETER_DEFINITION *parameter_definition, struct lzmafile *lzmafp)
Writes a parameter definition to an LZMA-compressed file.
int32_t SDDS_WriteDescription(char *text, char *contents, FILE *fp)
Writes the SDDS description section to a standard file.
int32_t SDDS_LZMAWriteAssociateDefinition(ASSOCIATE_DEFINITION *associate_definition, struct lzmafile *lzmafp)
Writes an associate definition to an LZMA-compressed file.
int32_t SDDS_WriteVersion(int32_t version_number, FILE *fp)
Writes the SDDS protocol version to a standard file.
int32_t SDDS_LZMAWriteDataMode(SDDS_LAYOUT *layout, struct lzmafile *lzmafp)
Writes the data mode section to an LZMA-compressed file.
int32_t SDDS_WriteParameterDefinition(PARAMETER_DEFINITION *parameter_definition, FILE *fp)
Writes a parameter definition to a standard file.
int32_t SDDS_WriteArrayDefinition(ARRAY_DEFINITION *array_definition, FILE *fp)
Writes an array definition to a standard file.
int32_t SDDS_WriteDataMode(SDDS_LAYOUT *layout, FILE *fp)
Writes the data mode section to a standard file.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.