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

Provides functions for writing SDDS layout headers. More...

#include "mdb.h"
#include "match_string.h"
#include "SDDS.h"
#include "SDDS_internal.h"

Go to the source code of this file.

Functions

char * SDDS_BlankToNull (char *string)
 Converts blank strings to NULL.
 
int32_t SDDS_WriteVersion (int32_t version_number, FILE *fp)
 Writes the SDDS protocol version to a standard 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_PrintNamelistField (FILE *fp, char *name, char *value)
 Writes a namelist field 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_WriteDescription (char *text, char *contents, FILE *fp)
 Writes the SDDS description section 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.
 
int32_t SDDS_WriteColumnDefinition (COLUMN_DEFINITION *column_definition, FILE *fp)
 Writes a column definition to a standard file.
 
int32_t SDDS_LZMAWriteColumnDefinition (COLUMN_DEFINITION *column_definition, struct lzmafile *lzmafp)
 Writes a column definition 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_LZMAWriteParameterDefinition (PARAMETER_DEFINITION *parameter_definition, struct lzmafile *lzmafp)
 Writes a parameter definition to an LZMA-compressed file.
 
int32_t SDDS_WriteAssociateDefinition (ASSOCIATE_DEFINITION *associate_definition, FILE *fp)
 Writes an associate definition 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_WriteDataMode (SDDS_LAYOUT *layout, FILE *fp)
 Writes the data mode section 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_WriteArrayDefinition (ARRAY_DEFINITION *array_definition, FILE *fp)
 Writes an array definition to a standard file.
 
int32_t SDDS_LZMAWriteArrayDefinition (ARRAY_DEFINITION *array_definition, struct lzmafile *lzmafp)
 Writes an array definition to an LZMA-compressed file.
 

Detailed Description

Provides functions for writing SDDS layout headers.

This file contains functions that handle writing SDDS (Self Describing Data Sets) layout headers. These functions convert the internal layout structures into the namelist format used for input/output operations.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Authors
M. Borland, C. Saunders, R. Soliday

Definition in file SDDS_write.c.

Function Documentation

◆ SDDS_BlankToNull()

char * SDDS_BlankToNull ( char * string)

Converts blank strings to NULL.

This utility function checks if a given string is NULL or consists solely of whitespace characters. If so, it returns NULL; otherwise, it returns the original string.

Parameters
stringThe input string to check.
Returns
Returns NULL if the string is blank or NULL; otherwise, returns the original string.

Definition at line 37 of file SDDS_write.c.

37 {
38 if (!string || SDDS_StringIsBlank(string))
39 return NULL;
40 return string;
41}
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).

◆ SDDS_LZMAPrintNamelistField()

int32_t SDDS_LZMAPrintNamelistField ( struct lzmafile * lzmafp,
char * name,
char * value )

Writes a namelist field to an LZMA-compressed file.

This function formats and writes a single namelist field to the specified LZMA-compressed file. It handles escaping of double quotes and determines whether to enclose the value in quotes based on its content.

Parameters
lzmafpThe LZMA-compressed file pointer where the namelist field will be written.
nameThe name of the field.
valueThe value of the field.
Returns
Returns 1 on success, 0 if the name is NULL or memory allocation fails.

Definition at line 166 of file SDDS_write.c.

166 {
167 char *buffer = NULL, *bPtr, *vPtr;
168 if (!name)
169 return 0;
170 if (!value || !strlen(name))
171 return 1;
172 if (!strlen(value))
173 lzma_printf(lzmafp, "%s=\"\", ", name);
174 else {
175 if (strchr(value, '"')) {
176 if (!(buffer = SDDS_Malloc(sizeof(*buffer) * 2 * strlen(value))))
177 return 0;
178 vPtr = value;
179 bPtr = buffer;
180 while (*vPtr) {
181 if (*vPtr == '"')
182 *bPtr++ = '\\';
183 *bPtr++ = *vPtr++;
184 }
185 *bPtr = 0;
186 value = buffer;
187 }
188 if (strpbrk(value, " ,*$\t\n\b"))
189 lzma_printf(lzmafp, "%s=\"%s\", ", name, value);
190 else
191 lzma_printf(lzmafp, "%s=%s, ", name, value);
192 if (buffer)
193 free(buffer);
194 }
195 return 1;
196}
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
Definition SDDS_utils.c:639

◆ SDDS_LZMAWriteArrayDefinition()

int32_t SDDS_LZMAWriteArrayDefinition ( ARRAY_DEFINITION * array_definition,
struct lzmafile * lzmafp )

Writes an array definition to an LZMA-compressed file.

This function outputs the definition of a single array in the SDDS layout to an LZMA-compressed file. It includes fields such as name, symbol, units, description, format string, group name, data type, and dimensions. The definition is enclosed within &array and &end tags.

Parameters
array_definitionPointer to the array definition structure.
lzmafpThe LZMA-compressed file pointer where the array definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the array type is invalid.

Definition at line 722 of file SDDS_write.c.

722 {
723 if (!lzmafp || array_definition->type <= 0 || array_definition->type > SDDS_NUM_TYPES)
724 return (0);
725
726 lzma_puts("&array ", lzmafp);
727 SDDS_LZMAPrintNamelistField(lzmafp, "name", array_definition->name);
728 SDDS_LZMAPrintNamelistField(lzmafp, "symbol", SDDS_BlankToNull(array_definition->symbol));
729 SDDS_LZMAPrintNamelistField(lzmafp, "units", SDDS_BlankToNull(array_definition->units));
730 SDDS_LZMAPrintNamelistField(lzmafp, "description", SDDS_BlankToNull(array_definition->description));
731 SDDS_LZMAPrintNamelistField(lzmafp, "format_string", SDDS_BlankToNull(array_definition->format_string));
732 SDDS_LZMAPrintNamelistField(lzmafp, "group_name", SDDS_BlankToNull(array_definition->group_name));
733 SDDS_LZMAPrintNamelistField(lzmafp, "type", SDDS_type_name[array_definition->type - 1]);
734 if (array_definition->dimensions != 1) /* 1 is default */
735 lzma_printf(lzmafp, "dimensions=%" PRId32 ", ", array_definition->dimensions);
736 lzma_puts(" &end\n", lzmafp);
737 return (1);
738}
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
Definition SDDS_data.c:43
int32_t SDDS_LZMAPrintNamelistField(struct lzmafile *lzmafp, char *name, char *value)
Writes a namelist field to an LZMA-compressed file.
Definition SDDS_write.c:166
char * SDDS_BlankToNull(char *string)
Converts blank strings to NULL.
Definition SDDS_write.c:37
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
Definition SDDStypes.h:97

◆ SDDS_LZMAWriteAssociateDefinition()

int32_t SDDS_LZMAWriteAssociateDefinition ( ASSOCIATE_DEFINITION * associate_definition,
struct lzmafile * lzmafp )

Writes an associate definition to an LZMA-compressed file.

This function outputs the definition of an associate in the SDDS layout to an LZMA-compressed file. It includes fields such as name, filename, contents, path, description, and an SDDS flag. The definition is enclosed within &associate and &end tags.

Parameters
associate_definitionPointer to the associate definition structure.
lzmafpThe LZMA-compressed file pointer where the associate definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL.

Definition at line 520 of file SDDS_write.c.

520 {
521 if (!lzmafp)
522 return (0);
523
524 lzma_puts("&associate ", lzmafp);
525 SDDS_LZMAPrintNamelistField(lzmafp, "name", associate_definition->name);
526 SDDS_LZMAPrintNamelistField(lzmafp, "filename", SDDS_BlankToNull(associate_definition->filename));
527 SDDS_LZMAPrintNamelistField(lzmafp, "contents", SDDS_BlankToNull(associate_definition->contents));
528 SDDS_LZMAPrintNamelistField(lzmafp, "path", SDDS_BlankToNull(associate_definition->path));
529 SDDS_LZMAPrintNamelistField(lzmafp, "description", SDDS_BlankToNull(associate_definition->description));
530 lzma_printf(lzmafp, "sdds=%" PRId32, associate_definition->sdds);
531 lzma_puts(" &end\n", lzmafp);
532 return (1);
533}

◆ SDDS_LZMAWriteColumnDefinition()

int32_t SDDS_LZMAWriteColumnDefinition ( COLUMN_DEFINITION * column_definition,
struct lzmafile * lzmafp )

Writes a column definition to an LZMA-compressed file.

This function outputs the definition of a single column in the SDDS layout to an LZMA-compressed file. It includes fields such as name, symbol, units, description, format string, and data type. The definition is enclosed within &column and &end tags.

Parameters
column_definitionPointer to the column definition structure.
lzmafpThe LZMA-compressed file pointer where the column definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the column type is invalid.

Definition at line 356 of file SDDS_write.c.

356 {
357 if (!lzmafp || column_definition->type <= 0 || column_definition->type > SDDS_NUM_TYPES)
358 return (0);
359
360 lzma_puts("&column ", lzmafp);
361 SDDS_LZMAPrintNamelistField(lzmafp, "name", column_definition->name);
362 SDDS_LZMAPrintNamelistField(lzmafp, "symbol", SDDS_BlankToNull(column_definition->symbol));
363 SDDS_LZMAPrintNamelistField(lzmafp, "units", SDDS_BlankToNull(column_definition->units));
364 SDDS_LZMAPrintNamelistField(lzmafp, "description", SDDS_BlankToNull(column_definition->description));
365 SDDS_LZMAPrintNamelistField(lzmafp, "format_string", SDDS_BlankToNull(column_definition->format_string));
366 SDDS_LZMAPrintNamelistField(lzmafp, "type", SDDS_type_name[column_definition->type - 1]);
367 lzma_puts(" &end\n", lzmafp);
368 return (1);
369}

◆ SDDS_LZMAWriteDataMode()

int32_t SDDS_LZMAWriteDataMode ( SDDS_LAYOUT * layout,
struct lzmafile * lzmafp )

Writes the data mode section to an LZMA-compressed file.

This function outputs the data mode settings of the SDDS layout to the specified LZMA-compressed file pointer. It includes settings such as mode, lines per row, row counts, endianess, column-major order, and fixed row counts. The section is enclosed within &data and &end tags.

Parameters
layoutPointer to the SDDS layout structure containing data mode settings.
lzmafpThe LZMA-compressed file pointer where the data mode section will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the data mode is invalid.

Definition at line 614 of file SDDS_write.c.

614 {
615 if (!lzmafp || layout->data_mode.mode < 0 || layout->data_mode.mode > SDDS_NUM_DATA_MODES)
616 return (0);
617
618 lzma_puts("&data ", lzmafp);
619 SDDS_LZMAPrintNamelistField(lzmafp, "mode", SDDS_data_mode[layout->data_mode.mode - 1]);
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, ");
628 else
629 lzma_printf(lzmafp, "endian=little, ");
630 if (layout->data_mode.column_major)
631 lzma_printf(lzmafp, "column_major_order=1, ");
632 }
633 if (layout->data_mode.fixed_row_count)
634 lzma_printf(lzmafp, "fixed_row_count=1, ");
635 }
636 lzma_puts("&end\n", lzmafp);
637 return (1);
638}
char * SDDS_data_mode[SDDS_NUM_DATA_MODES]
Array of supported data modes.
Definition SDDS_data.c:33

◆ SDDS_LZMAWriteDescription()

int32_t SDDS_LZMAWriteDescription ( char * text,
char * contents,
struct lzmafile * lzmafp )

Writes the SDDS description section to an LZMA-compressed file.

This function writes the description section of the SDDS layout, including optional text and contents fields. It encapsulates the data within &description and &end tags in an LZMA-compressed file.

Parameters
textThe descriptive text for the SDDS layout.
contentsThe contents description for the SDDS layout.
lzmafpThe LZMA-compressed file pointer where the description will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL.

Definition at line 280 of file SDDS_write.c.

280 {
281 if (!lzmafp)
282 return 0;
283 if (!text && !contents)
284 return 1;
285 lzma_puts("&description ", lzmafp);
286 SDDS_LZMAPrintNamelistField(lzmafp, "text", text);
287 SDDS_LZMAPrintNamelistField(lzmafp, "contents", contents);
288 lzma_puts("&end\n", lzmafp);
289 return 1;
290}

◆ SDDS_LZMAWriteParameterDefinition()

int32_t SDDS_LZMAWriteParameterDefinition ( PARAMETER_DEFINITION * parameter_definition,
struct lzmafile * lzmafp )

Writes a parameter definition to an LZMA-compressed file.

This function outputs the definition of a single parameter in the SDDS layout to an LZMA-compressed file. It includes fields such as name, symbol, units, description, format string, data type, and fixed value. The definition is enclosed within &parameter and &end tags.

Parameters
parameter_definitionPointer to the parameter definition structure.
lzmafpThe LZMA-compressed file pointer where the parameter definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the parameter type is invalid.

Definition at line 438 of file SDDS_write.c.

438 {
439 if (!lzmafp || parameter_definition->type <= 0 || parameter_definition->type > SDDS_NUM_TYPES)
440 return (0);
441 lzma_puts("&parameter ", lzmafp);
442 SDDS_LZMAPrintNamelistField(lzmafp, "name", parameter_definition->name);
443 SDDS_LZMAPrintNamelistField(lzmafp, "symbol", SDDS_BlankToNull(parameter_definition->symbol));
444 SDDS_LZMAPrintNamelistField(lzmafp, "units", SDDS_BlankToNull(parameter_definition->units));
445 SDDS_LZMAPrintNamelistField(lzmafp, "description", SDDS_BlankToNull(parameter_definition->description));
446 SDDS_LZMAPrintNamelistField(lzmafp, "format_string", SDDS_BlankToNull(parameter_definition->format_string));
447 SDDS_LZMAPrintNamelistField(lzmafp, "type", SDDS_type_name[parameter_definition->type - 1]);
448 SDDS_LZMAPrintNamelistField(lzmafp, "fixed_value", parameter_definition->fixed_value);
449 lzma_puts("&end\n", lzmafp);
450 return (1);
451}

◆ SDDS_LZMAWriteVersion()

int32_t SDDS_LZMAWriteVersion ( int32_t version_number,
struct lzmafile * lzmafp )

Writes the SDDS protocol version to an LZMA-compressed file.

This function outputs the SDDS protocol version string to the provided LZMA-compressed file pointer. Maintaining the protocol version is essential for ensuring the integrity of the SDDS file format.

Parameters
version_numberThe SDDS protocol version number to write.
lzmafpThe LZMA-compressed file pointer where the version string will be written.
Returns
Returns 1 on successful write, 0 if the file pointer is NULL.

Definition at line 77 of file SDDS_write.c.

77 {
78 if (!lzmafp)
79 return (0);
80 lzma_printf(lzmafp, "SDDS%" PRId32 "\n", version_number);
81 return (1);
82}

◆ SDDS_PrintNamelistField()

int32_t SDDS_PrintNamelistField ( FILE * fp,
char * name,
char * value )

Writes a namelist field to a standard file.

This function formats and writes a single namelist field to the specified file. It handles escaping of double quotes and determines whether to enclose the value in quotes based on its content.

Parameters
fpThe file pointer where the namelist field will be written.
nameThe name of the field.
valueThe value of the field.
Returns
Returns 1 on success, 0 if the name is NULL or memory allocation fails.

Definition at line 122 of file SDDS_write.c.

122 {
123 char *buffer = NULL, *bPtr, *vPtr;
124 if (!name)
125 return 0;
126 if (!value || !strlen(name))
127 return 1;
128 if (!strlen(value))
129 fprintf(fp, "%s=\"\", ", name);
130 else {
131 if (strchr(value, '"')) {
132 if (!(buffer = SDDS_Malloc(sizeof(*buffer) * 2 * strlen(value))))
133 return 0;
134 vPtr = value;
135 bPtr = buffer;
136 while (*vPtr) {
137 if (*vPtr == '"')
138 *bPtr++ = '\\';
139 *bPtr++ = *vPtr++;
140 }
141 *bPtr = 0;
142 value = buffer;
143 }
144 if (strpbrk(value, " ,*$\t\n\b"))
145 fprintf(fp, "%s=\"%s\", ", name, value);
146 else
147 fprintf(fp, "%s=%s, ", name, value);
148 if (buffer)
149 free(buffer);
150 }
151 return 1;
152}

◆ SDDS_WriteArrayDefinition()

int32_t SDDS_WriteArrayDefinition ( ARRAY_DEFINITION * array_definition,
FILE * fp )

Writes an array definition to a standard file.

This function outputs the definition of a single array in the SDDS layout. It includes fields such as name, symbol, units, description, format string, group name, data type, and dimensions. The definition is enclosed within &array and &end tags.

Parameters
array_definitionPointer to the array definition structure.
fpThe file pointer where the array definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the array type is invalid.

Definition at line 692 of file SDDS_write.c.

692 {
693 if (!fp || array_definition->type <= 0 || array_definition->type > SDDS_NUM_TYPES)
694 return (0);
695
696 fputs("&array ", fp);
697 SDDS_PrintNamelistField(fp, "name", array_definition->name);
698 SDDS_PrintNamelistField(fp, "symbol", SDDS_BlankToNull(array_definition->symbol));
699 SDDS_PrintNamelistField(fp, "units", SDDS_BlankToNull(array_definition->units));
700 SDDS_PrintNamelistField(fp, "description", SDDS_BlankToNull(array_definition->description));
701 SDDS_PrintNamelistField(fp, "format_string", SDDS_BlankToNull(array_definition->format_string));
702 SDDS_PrintNamelistField(fp, "group_name", SDDS_BlankToNull(array_definition->group_name));
703 SDDS_PrintNamelistField(fp, "type", SDDS_type_name[array_definition->type - 1]);
704 if (array_definition->dimensions != 1) /* 1 is default */
705 fprintf(fp, "dimensions=%" PRId32 ", ", array_definition->dimensions);
706 fputs(" &end\n", fp);
707 return (1);
708}
int32_t SDDS_PrintNamelistField(FILE *fp, char *name, char *value)
Writes a namelist field to a standard file.
Definition SDDS_write.c:122

◆ SDDS_WriteAssociateDefinition()

int32_t SDDS_WriteAssociateDefinition ( ASSOCIATE_DEFINITION * associate_definition,
FILE * fp )

Writes an associate definition to a standard file.

This function outputs the definition of an associate in the SDDS layout. It includes fields such as name, filename, contents, path, description, and an SDDS flag. The definition is enclosed within &associate and &end tags.

Parameters
associate_definitionPointer to the associate definition structure.
fpThe file pointer where the associate definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL.

Definition at line 493 of file SDDS_write.c.

493 {
494 if (!fp)
495 return (0);
496
497 fputs("&associate ", fp);
498 SDDS_PrintNamelistField(fp, "name", associate_definition->name);
499 SDDS_PrintNamelistField(fp, "filename", SDDS_BlankToNull(associate_definition->filename));
500 SDDS_PrintNamelistField(fp, "contents", SDDS_BlankToNull(associate_definition->contents));
501 SDDS_PrintNamelistField(fp, "path", SDDS_BlankToNull(associate_definition->path));
502 SDDS_PrintNamelistField(fp, "description", SDDS_BlankToNull(associate_definition->description));
503 fprintf(fp, "sdds=%" PRId32, associate_definition->sdds);
504 fputs(" &end\n", fp);
505 return (1);
506}

◆ SDDS_WriteColumnDefinition()

int32_t SDDS_WriteColumnDefinition ( COLUMN_DEFINITION * column_definition,
FILE * fp )

Writes a column definition to a standard file.

This function outputs the definition of a single column in the SDDS layout. It includes fields such as name, symbol, units, description, format string, and data type. The definition is enclosed within &column and &end tags.

Parameters
column_definitionPointer to the column definition structure.
fpThe file pointer where the column definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the column type is invalid.

Definition at line 329 of file SDDS_write.c.

329 {
330 if (!fp || column_definition->type <= 0 || column_definition->type > SDDS_NUM_TYPES)
331 return (0);
332
333 fputs("&column ", fp);
334 SDDS_PrintNamelistField(fp, "name", column_definition->name);
335 SDDS_PrintNamelistField(fp, "symbol", SDDS_BlankToNull(column_definition->symbol));
336 SDDS_PrintNamelistField(fp, "units", SDDS_BlankToNull(column_definition->units));
337 SDDS_PrintNamelistField(fp, "description", SDDS_BlankToNull(column_definition->description));
338 SDDS_PrintNamelistField(fp, "format_string", SDDS_BlankToNull(column_definition->format_string));
339 SDDS_PrintNamelistField(fp, "type", SDDS_type_name[column_definition->type - 1]);
340 fputs(" &end\n", fp);
341 return (1);
342}

◆ SDDS_WriteDataMode()

int32_t SDDS_WriteDataMode ( SDDS_LAYOUT * layout,
FILE * fp )

Writes the data mode section to a standard file.

This function outputs the data mode settings of the SDDS layout to the specified file pointer. It includes settings such as mode, lines per row, row counts, endianess, column-major order, and fixed row counts. The section is enclosed within &data and &end tags.

Parameters
layoutPointer to the SDDS layout structure containing data mode settings.
fpThe file pointer where the data mode section will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the data mode is invalid.

Definition at line 576 of file SDDS_write.c.

576 {
577 if (!fp || layout->data_mode.mode < 0 || layout->data_mode.mode > SDDS_NUM_DATA_MODES)
578 return (0);
579
580 fputs("&data ", fp);
581 SDDS_PrintNamelistField(fp, "mode", SDDS_data_mode[layout->data_mode.mode - 1]);
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, ");
590 else
591 fprintf(fp, "endian=little, ");
592 if (layout->data_mode.column_major)
593 fprintf(fp, "column_major_order=1, ");
594 }
595 if (layout->data_mode.fixed_row_count)
596 fprintf(fp, "fixed_row_count=1, ");
597 }
598 fputs("&end\n", fp);
599 return (1);
600}

◆ SDDS_WriteDescription()

int32_t SDDS_WriteDescription ( char * text,
char * contents,
FILE * fp )

Writes the SDDS description section to a standard file.

This function writes the description section of the SDDS layout, including optional text and contents fields. It encapsulates the data within &description and &end tags.

Parameters
textThe descriptive text for the SDDS layout.
contentsThe contents description for the SDDS layout.
fpThe file pointer where the description will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL.

Definition at line 256 of file SDDS_write.c.

256 {
257 if (!fp)
258 return 0;
259 if (!text && !contents)
260 return 1;
261 fputs("&description ", fp);
262 SDDS_PrintNamelistField(fp, "text", text);
263 SDDS_PrintNamelistField(fp, "contents", contents);
264 fputs("&end\n", fp);
265 return 1;
266}

◆ SDDS_WriteParameterDefinition()

int32_t SDDS_WriteParameterDefinition ( PARAMETER_DEFINITION * parameter_definition,
FILE * fp )

Writes a parameter definition to a standard file.

This function outputs the definition of a single parameter in the SDDS layout. It includes fields such as name, symbol, units, description, format string, data type, and fixed value. The definition is enclosed within &parameter and &end tags.

Parameters
parameter_definitionPointer to the parameter definition structure.
fpThe file pointer where the parameter definition will be written.
Returns
Returns 1 on success, 0 if the file pointer is NULL or the parameter type is invalid.

Definition at line 411 of file SDDS_write.c.

411 {
412 if (!fp || parameter_definition->type <= 0 || parameter_definition->type > SDDS_NUM_TYPES)
413 return (0);
414 fputs("&parameter ", fp);
415 SDDS_PrintNamelistField(fp, "name", parameter_definition->name);
416 SDDS_PrintNamelistField(fp, "symbol", SDDS_BlankToNull(parameter_definition->symbol));
417 SDDS_PrintNamelistField(fp, "units", SDDS_BlankToNull(parameter_definition->units));
418 SDDS_PrintNamelistField(fp, "description", SDDS_BlankToNull(parameter_definition->description));
419 SDDS_PrintNamelistField(fp, "format_string", SDDS_BlankToNull(parameter_definition->format_string));
420 SDDS_PrintNamelistField(fp, "type", SDDS_type_name[parameter_definition->type - 1]);
421 SDDS_PrintNamelistField(fp, "fixed_value", parameter_definition->fixed_value);
422 fputs("&end\n", fp);
423 return (1);
424}

◆ SDDS_WriteVersion()

int32_t SDDS_WriteVersion ( int32_t version_number,
FILE * fp )

Writes the SDDS protocol version to a standard file.

This function outputs the SDDS protocol version string to the provided file pointer. It is crucial that the protocol version remains unchanged to ensure compatibility.

Parameters
version_numberThe SDDS protocol version number to write.
fpThe file pointer where the version string will be written.
Returns
Returns 1 on successful write, 0 if the file pointer is NULL.

Definition at line 59 of file SDDS_write.c.

59 {
60 if (!fp)
61 return (0);
62 fprintf(fp, "SDDS%" PRId32 "\n", version_number);
63 return (1);
64}