SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
SDDS_internal.h File Reference

Detailed Description

Internal definitions and function declarations for SDDS with LZMA support.

This header file contains internal macros, structures, and function prototypes used by the SDDS (Self Describing Data Sets) library to handle LZMA-compressed files. It includes definitions for the lzmafile structure, buffer sizes, and various binary and ASCII I/O routines tailored for SDDS datasets.

The file ensures that internal components are only included once using include guards and conditionally includes the LZMA library when necessary.

Key Components:

  • Structures:
    • lzmafile: Represents an LZMA-compressed file with associated stream and buffer.
  • Function Prototypes:
    • lzma_open, lzma_close, lzma_read, lzma_write: Basic file operations for LZMA files.
    • SDDS_WriteBinaryArrays, SDDS_ReadBinaryArrays, etc.: SDDS-specific binary I/O functions.
    • SDDS_WriteAsciiArrays, SDDS_ReadAsciiArrays, etc.: SDDS-specific ASCII I/O functions.
    • Additional utility and processing functions for handling SDDS datasets.
  • Macros:
    • LZMA_BUF_SIZE: Defines the buffer size for LZMA operations.
    • TABLE_LENGTH_INCREMENT: Specifies the increment size for table allocations.
    • Command definitions for various SDDS operations.

Dependencies:

  • Requires the LZMA library (lzma.h) for compression support.
  • Conditionally includes zLib support if defined.

Usage:

This file is intended for internal use within the SDDS library and should not be included directly by external applications. It provides the necessary infrastructure to manage compressed data streams and perform efficient I/O operations on SDDS datasets.

Note
Ensure that the LZMA and zLib libraries are properly linked when compiling components that include this header.
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, H. Shang

Definition in file SDDS_internal.h.

#include "SDDS.h"
#include <lzma.h>

Go to the source code of this file.

Functions

void * lzma_open (const char *path, const char *mode)
 
int lzma_close (struct lzmafile *file)
 
long lzma_read (struct lzmafile *file, void *buf, size_t count)
 
long lzma_write (struct lzmafile *file, const void *buf, size_t count)
 
int lzma_printf (struct lzmafile *file, const char *format,...)
 
int lzma_puts (const char *s, struct lzmafile *file)
 
int lzma_putc (int c, struct lzmafile *file)
 
char * lzma_gets (char *s, int size, struct lzmafile *file)
 
int lzma_eof (struct lzmafile *file)
 
long lzma_tell (struct lzmafile *file)
 
int lzma_seek (struct lzmafile *file, long offset, int whence)
 
void * UnpackLZMAOpen (char *filename)
 
char * fgetsLZMASkipComments (SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, struct lzmafile *lzmafp, char skip_char)
 Reads a line from a LZMA-compressed file while skipping comment lines.
 
char * fgetsLZMASkipCommentsResize (SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, struct lzmafile *lzmafp, char skip_char)
 Reads a line from a LZMA-compressed file with dynamic buffer resizing while skipping comment lines.
 
int32_t SDDS_LZMAWriteBinaryString (char *string, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
 Writes a binary string to a file with LZMA compression.
 
char * SDDS_ReadNonNativeLZMABinaryString (struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
 Reads a non-native endian binary string from an LZMA-compressed file.
 
int32_t SDDS_LZMAWriteNonNativeBinaryString (char *string, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
 Writes a non-native endian binary string to an LZMA-compressed file.
 
int32_t SDDS_WriteBinaryArrays (SDDS_DATASET *SDDS_dataset)
 Writes the binary arrays of the SDDS dataset to a file.
 
int32_t SDDS_WriteBinaryColumns (SDDS_DATASET *SDDS_dataset)
 Writes the binary columns of an SDDS dataset to the associated file.
 
int32_t SDDS_WriteNonNativeBinaryColumns (SDDS_DATASET *SDDS_dataset)
 Writes non-native endian binary columns of an SDDS dataset to the associated file.
 
int32_t SDDS_WriteBinaryParameters (SDDS_DATASET *SDDS_dataset)
 Writes the binary parameters of the SDDS dataset.
 
int32_t SDDS_WriteBinaryPage (SDDS_DATASET *SDDS_dataset)
 
int32_t SDDS_WriteBinaryRow (SDDS_DATASET *SDDS_dataset, int64_t row)
 Writes a single binary row of an SDDS dataset to the associated file.
 
int32_t SDDS_UpdateBinaryPage (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 Updates the binary page of an SDDS dataset.
 
int32_t SDDS_UpdateNonNativeBinaryPage (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 Updates a non-native endian binary page in an SDDS dataset.
 
int32_t SDDS_fseek (FILE *fp, int64_t offset, int32_t dir)
 Sets the file position indicator for a given file stream with retry logic.
 
char * SDDS_ReadBinaryString (FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
 Reads a binary string from a file with buffering.
 
int32_t SDDS_ReadBinaryArrays (SDDS_DATASET *SDDS_dataset)
 Reads binary arrays from an SDDS dataset.
 
int32_t SDDS_ReadBinaryColumns (SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset)
 Reads the binary columns from an SDDS dataset.
 
int32_t SDDS_ReadNonNativeBinaryColumns (SDDS_DATASET *SDDS_dataset)
 Reads the non-native endian binary columns from an SDDS dataset.
 
int32_t SDDS_ReadBinaryParameters (SDDS_DATASET *SDDS_dataset)
 Reads binary parameters from the specified SDDS dataset.
 
int32_t SDDS_ReadBinaryPage (SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
 Reads a binary page from an SDDS dataset.
 
int32_t SDDS_ReadBinaryPageLastRows (SDDS_DATASET *SDDS_dataset, int64_t last_rows)
 Reads the last specified number of rows from a binary page of an SDDS dataset.
 
int32_t SDDS_ReadBinaryPageDetailed (SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows, int32_t sparse_statistics)
 Reads a binary page from an SDDS dataset with detailed options.
 
int32_t SDDS_ReadBinaryRow (SDDS_DATASET *SDDS_dataset, int64_t row, int32_t skip)
 Reads a binary row from the specified SDDS dataset.
 
int32_t SDDS_ReadNonNativePageLastRows (SDDS_DATASET *SDDS_dataset, int64_t last_rows)
 Reads the last few rows from a non-native endian page in an SDDS dataset.
 
int32_t SDDS_ReadNonNativeBinaryPageDetailed (SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows)
 Reads a detailed non-native endian binary page from an SDDS dataset.
 
int32_t SDDS_ReadNonNativePageDetailed (SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows)
 Reads a detailed non-native endian page from an SDDS dataset.
 
int32_t SDDS_ReadNonNativeBinaryPageLastRows (SDDS_DATASET *SDDS_dataset, int64_t last_rows)
 Reads the last few rows from a non-native endian binary page in an SDDS dataset.
 
int32_t SDDS_GetTerminateMode (void)
 
int32_t SDDS_AllocateColumnFlags (SDDS_DATASET *SDDS_target)
 
int32_t SDDS_WriteAsciiArrays (SDDS_DATASET *SDDS_dataset, FILE *fp)
 Writes the arrays of an SDDS dataset in ASCII format to a file.
 
int32_t SDDS_WriteAsciiParameters (SDDS_DATASET *SDDS_dataset, FILE *fp)
 Writes the parameter data of an SDDS dataset in ASCII format to a file.
 
void SDDS_AppendParameterComment (PARAMETER_DEFINITION *definition, char *text, char *string)
 
int32_t SDDS_WriteAsciiRow (SDDS_DATASET *SDDS_dataset, int64_t row, FILE *fp)
 Writes a single row of data in ASCII format to a file.
 
int32_t SDDS_WriteAsciiPage (SDDS_DATASET *SDDS_dataset)
 Writes a page of data in ASCII format to the SDDS dataset.
 
int32_t SDDS_ReadAsciiArrays (SDDS_DATASET *SDDS_dataset)
 Reads the arrays from an ASCII file into the SDDS dataset.
 
int32_t SDDS_ReadAsciiParameters (SDDS_DATASET *SDDS_dataset)
 Reads the parameters from an ASCII file into the SDDS dataset.
 
int32_t SDDS_AsciiDataExpected (SDDS_DATASET *SDDS_dataset)
 Checks whether the SDDS dataset expects ASCII data input.
 
int32_t SDDS_ReadAsciiPageLastRows (SDDS_DATASET *SDDS_dataset, int64_t last_rows)
 Reads the last specified number of rows from an ASCII page of an SDDS dataset.
 
int32_t SDDS_ReadAsciiPageDetailed (SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows, int32_t sparse_statistics)
 Reads a detailed page of data from an ASCII file into an SDDS dataset with optional sparsity and statistics.
 
int32_t SDDS_LZMAWriteAsciiParameters (SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
 Writes the parameter data of an SDDS dataset in ASCII format to an LZMA compressed file.
 
int32_t SDDS_LZMAWriteAsciiArrays (SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
 Writes the arrays of an SDDS dataset in ASCII format to an LZMA compressed file.
 
int32_t SDDS_LZMAWriteAsciiRow (SDDS_DATASET *SDDS_dataset, int64_t row, struct lzmafile *lzmafp)
 Writes a single row of data in ASCII format to an LZMA compressed file.
 
int32_t SDDS_CopyColumn (SDDS_DATASET *SDDS_dataset, int32_t target, int32_t source)
 Copies data from a source column to a target column within an SDDS dataset.
 
int32_t SDDS_CopyParameter (SDDS_DATASET *SDDS_dataset, int32_t target, int32_t source)
 Copies a parameter from a source index to a target index within an SDDS dataset.
 
int32_t SDDS_TransferRow (SDDS_DATASET *SDDS_dataset, int64_t target, int64_t source)
 Transfers data from a source row to a target row within an SDDS dataset.
 
int64_t SDDS_GetSelectedRowIndex (SDDS_DATASET *SDDS_dataset, int64_t srow_index)
 Retrieves the actual row index corresponding to a selected row position within the current data table.
 
int32_t SDDS_CheckTable (SDDS_DATASET *SDDS_dataset, const char *caller)
 
int32_t SDDS_AdvanceCounter (int32_t *counter, int32_t *max_count, int32_t n_indices)
 Advances a multi-dimensional counter based on maximum counts for each dimension.
 
void SDDS_FreePointerArray (void **data, int32_t dimensions, int32_t *dimension)
 Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.
 
int32_t SDDS_WriteVersion (int32_t version_number, FILE *fp)
 Writes the SDDS protocol version to a standard file.
 
int32_t SDDS_WriteDescription (char *description, char *contents, FILE *fp)
 Writes the SDDS description section to a standard file.
 
int32_t SDDS_WriteColumnDefinition (COLUMN_DEFINITION *column, FILE *fp)
 Writes a column definition to a standard file.
 
int32_t SDDS_WriteParameterDefinition (PARAMETER_DEFINITION *parameter, FILE *fp)
 Writes a parameter definition to a standard file.
 
int32_t SDDS_WriteAssociateDefinition (ASSOCIATE_DEFINITION *associate, FILE *fp)
 Writes an associate 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.
 
int32_t SDDS_LZMAWriteVersion (int32_t version_number, struct lzmafile *lzmafp)
 Writes the SDDS protocol version to an LZMA-compressed file.
 
int32_t SDDS_LZMAWriteDescription (char *description, char *contents, struct lzmafile *lzmafp)
 Writes the SDDS description section to an LZMA-compressed file.
 
int32_t SDDS_LZMAWriteColumnDefinition (COLUMN_DEFINITION *column, struct lzmafile *lzmafp)
 Writes a column definition to an LZMA-compressed file.
 
int32_t SDDS_LZMAWriteParameterDefinition (PARAMETER_DEFINITION *parameter, struct lzmafile *lzmafp)
 Writes a parameter definition to an LZMA-compressed file.
 
int32_t SDDS_LZMAWriteAssociateDefinition (ASSOCIATE_DEFINITION *associate, struct lzmafile *lzmafp)
 Writes an associate definition 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_LZMAWriteDataMode (SDDS_LAYOUT *layout, struct lzmafile *lzmafp)
 Writes the data mode section to an LZMA-compressed file.
 
int32_t SDDS_ProcessDescription (SDDS_DATASET *SDDS_dataset, char *s)
 Process the description section of the SDDS dataset.
 
int32_t SDDS_ProcessColumnDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Process the column definition section of the SDDS dataset.
 
int32_t SDDS_ProcessParameterDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Process the parameter definition section of the SDDS dataset.
 
int32_t SDDS_ProcessArrayDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Process the array definition section of the SDDS dataset.
 
FILE * SDDS_ProcessIncludeCommand (SDDS_DATASET *SDDS_dataset, char *s)
 Process the include command within the SDDS dataset.
 
int32_t SDDS_ProcessAssociateDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Process the associate definition section of the SDDS dataset.
 
int32_t SDDS_ProcessDataMode (SDDS_DATASET *SDDS_dataset, char *s)
 Process the data mode section of the SDDS dataset.
 
int32_t SDDS1_ProcessDescription (SDDS_DATASET *SDDS_dataset, char *s)
 Process the description section for SDDS protocol version 1.
 
int32_t SDDS1_ProcessColumnDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Processes and defines a column within an SDDS dataset.
 
int32_t SDDS1_ProcessParameterDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Processes and defines a parameter within an SDDS dataset.
 
int32_t SDDS1_ProcessArrayDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Processes and defines an array within an SDDS dataset.
 
FILE * SDDS1_ProcessIncludeCommand (SDDS_DATASET *SDDS_dataset, char *s)
 Processes an include command by opening the specified file.
 
int32_t SDDS1_ProcessAssociateDefinition (SDDS_DATASET *SDDS_dataset, char *s)
 Processes and defines an associate within an SDDS dataset.
 
int32_t SDDS1_ProcessDataMode (SDDS_DATASET *SDDS_dataset, char *s)
 Processes and sets the data mode for an SDDS dataset.
 
int32_t SDDS_ReadLayout (SDDS_DATASET *SDDS_dataset, FILE *fp)
 
int32_t SDDS_LZMAReadLayout (SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
 
int32_t SDDS_UpdateAsciiPage (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 Updates the current ASCII page of an SDDS dataset with new data.
 
uint32_t SDDS_GetSpecialCommentsModes (SDDS_DATASET *SDDS_dataset)
 Retrieves the current special comments modes set in the SDDS dataset.
 
void SDDS_ResetSpecialCommentsModes (SDDS_DATASET *SDDS_dataset)
 Resets the special comments modes in the SDDS dataset.
 
void SDDS_ParseSpecialComments (SDDS_DATASET *SDDS_dataset, char *s)
 Parses and processes special comment commands within the SDDS dataset.
 
void SDDS_FreeTableStrings (SDDS_DATASET *SDDS_dataset)
 

Function Documentation

◆ fgetsLZMASkipComments()

char * fgetsLZMASkipComments ( SDDS_DATASET * SDDS_dataset,
char * s,
int32_t slen,
struct lzmafile * lzmafp,
char skip_char )

Reads a line from a LZMA-compressed file while skipping comment lines.

This function reads lines from the specified LZMA-compressed file stream, ignoring lines that begin with the specified skip_char. It also processes special comment lines that start with !# by parsing them using SDDS_ParseSpecialComments.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure, used for processing comments.
[out]sPointer to a character array where the read line will be stored.
[in]slenThe maximum number of characters to read into s.
[in]lzmafpPointer to the lzmafile structure representing the LZMA-compressed file stream.
[in]skip_charCharacter indicating the start of a comment line. Lines beginning with this character will be skipped.
Returns
On success, returns the pointer s containing the read line. If the end of the file is reached or an error occurs, returns NULL.
Note
The function modifies the buffer s by removing comments as determined by SDDS_CutOutComments.
See also
SDDS_CutOutComments
SDDS_ParseSpecialComments
lzma_gets

Definition at line 1594 of file SDDS_utils.c.

1594 {
1595 while (lzma_gets(s, slen, lzmafp)) {
1596 if (s[0] != skip_char) {
1597 SDDS_CutOutComments(SDDS_dataset, s, skip_char);
1598 return (s);
1599 } else if (s[1] == '#') {
1600 SDDS_ParseSpecialComments(SDDS_dataset, s + 2);
1601 }
1602 }
1603 return (NULL);
1604}
void SDDS_CutOutComments(SDDS_DATASET *SDDS_dataset, char *s, char cc)
Removes comments from a string based on a specified comment character.
void SDDS_ParseSpecialComments(SDDS_DATASET *SDDS_dataset, char *s)
Parses and processes special comment commands within the SDDS dataset.

◆ fgetsLZMASkipCommentsResize()

char * fgetsLZMASkipCommentsResize ( SDDS_DATASET * SDDS_dataset,
char ** s,
int32_t * slen,
struct lzmafile * lzmafp,
char skip_char )

Reads a line from a LZMA-compressed file with dynamic buffer resizing while skipping comment lines.

This function reads lines from the specified LZMA-compressed file stream, ignoring lines that begin with the specified skip_char. If a line exceeds the current buffer size, the buffer is dynamically resized to accommodate the entire line. It also processes special comment lines that start with !# by parsing them using SDDS_ParseSpecialComments.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure, used for processing comments.
[in,out]sPointer to a pointer to a character array where the read line will be stored. This buffer may be resized if necessary.
[in,out]slenPointer to an int32_t variable specifying the current size of the buffer *s. This value may be updated if the buffer is resized.
[in]lzmafpPointer to the lzmafile structure representing the LZMA-compressed file stream.
[in]skip_charCharacter indicating the start of a comment line. Lines beginning with this character will be skipped.
Returns
On success, returns the pointer *s containing the read line. If the end of the file is reached or an error occurs, returns NULL.
Note
The caller is responsible for managing the memory of the buffer *s, including freeing it when no longer needed.
See also
SDDS_CutOutComments
SDDS_ParseSpecialComments
SDDS_Realloc
lzma_gets

Definition at line 1626 of file SDDS_utils.c.

1626 {
1627 int32_t spaceLeft, length, newLine;
1628 char *sInsert, *fgetsReturn;
1629
1630 sInsert = *s;
1631 spaceLeft = *slen;
1632 newLine = 1;
1633 while ((fgetsReturn = lzma_gets(sInsert, spaceLeft, lzmafp))) {
1634 if (newLine && sInsert[0] == '!')
1635 continue;
1636 SDDS_CutOutComments(SDDS_dataset, sInsert, skip_char);
1637 length = strlen(sInsert);
1638 if (sInsert[length - 1] != '\n' && !lzma_eof(lzmafp)) {
1639 /* buffer wasn't long enough to get the whole line. Resize and add more data. */
1640 spaceLeft = *slen;
1641 *slen = *slen * 2;
1642 *s = SDDS_Realloc(*s, sizeof(**s) * *slen);
1643 sInsert = *s + strlen(*s);
1644 newLine = 0;
1645 } else
1646 break;
1647 }
1648 if (!fgetsReturn)
1649 return NULL;
1650 return (*s);
1651}
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:743

◆ lzma_close()

int lzma_close ( struct lzmafile * file)

Definition at line 136 of file SDDS_lzma.c.

136 {
137 int ret, outsize;
138 unsigned char buf[BUF_SIZE]; /* buffer used when flushing remaining
139 output data in write mode */
140 if (!file)
141 return -1;
142 if (file->mode == 'w') {
143 /* flush LZMA output buffer */
144 for (;;) {
145 file->str.next_out = buf;
146 file->str.avail_out = BUF_SIZE;
147 ret = lzma_code(&file->str, LZMA_FINISH);
148 if (ret != LZMA_STREAM_END && ret != LZMA_OK) {
149 fprintf(stderr, "lzma_close error: encoding failed: %d\n", ret);
150 lzma_end(&file->str);
151 fclose(file->fp);
152 free(file);
153 return EOF;
154 }
155 outsize = BUF_SIZE - file->str.avail_out;
156 if (fwrite(buf, 1, outsize, file->fp) != outsize) {
157 lzma_end(&file->str);
158 fclose(file->fp);
159 free(file);
160 return EOF;
161 }
162 if (ret == LZMA_STREAM_END)
163 break;
164 }
165 }
166 lzma_end(&file->str);
167 ret = fclose(file->fp);
168 free(file);
169 return ret;
170}

◆ lzma_eof()

int lzma_eof ( struct lzmafile * file)

Definition at line 415 of file SDDS_lzma.c.

415 {
416 lzma_stream *lstr;
417 lstr = &file->str;
418 if (lstr->avail_in == 0) {
419 return feof(file->fp);
420 } else {
421 return 0;
422 }
423}

◆ lzma_gets()

char * lzma_gets ( char * s,
int size,
struct lzmafile * file )

Definition at line 217 of file SDDS_lzma.c.

217 {
218 int ret;
219 int i = 0;
220 lzma_stream *lstr;
221 if (file->mode != 'r')
222 return NULL;
223 if (s == NULL || size < 1)
224 return NULL;
225 s[0] = '\0';
226 lstr = &file->str;
227 lstr->next_out = (void *)s;
228
229 /* decompress until newline or EOF or output buffer is full */
230 while (1) {
231 if (lstr->avail_in == 0) {
232 /* refill input buffer */
233 ret = fread(file->rdbuf, 1, BUF_SIZE, file->fp);
234 if (ret == 0) {
235 break; /* EOF */
236 }
237 lstr->next_in = file->rdbuf; /* buffer containing lzma data just read */
238 lstr->avail_in = ret; /* number of bytes read */
239 }
240 if (i + 1 == size) {
241 s[i] = '\0';
242 break;
243 }
244 lstr->avail_out = 1;
245 ret = lzma_code(lstr, LZMA_RUN);
246 /* this fills up lstr->next_out and decreases lstr->avail_out */
247 /* it also emptys lstr->next_in and decreases lstr->avail_in */
248 if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
249 fprintf(stderr, "lzma_gets error: decoding failed: %d\n", ret);
250 return NULL;
251 }
252 if (ret == LZMA_STREAM_END) { /* EOF */
253 s[i + 1] = '\0';
254 break;
255 }
256 if (s[i] == 10) { /* 10 is the value for \n */
257 if (i > 0) { /* we sometimes get \10\10 */
258 if ((i == 1) && (s[0] == 32)) {
259 /* when uncompressing the lzma stream we some times end
260 up with \10\32\10 instead of a simple \10 */
261 } else {
262 s[i + 1] = '\0';
263 break;
264 }
265 }
266 }
267 i++;
268 }
269 return s;
270}

◆ lzma_open()

void * lzma_open ( const char * path,
const char * mode )

Definition at line 99 of file SDDS_lzma.c.

99 {
100 int ret;
101
102 /* initialize LZMA stream */
103 struct lzmafile *lf = malloc(sizeof(struct lzmafile));
104 if (!lf)
105 return NULL;
106 lf->fp = fopen(path, mode);
107 if (!lf->fp) {
108 free(lf);
109 return NULL;
110 }
111 lf->str = lzma_stream_init;
112 lf->mode = mode[0];
113 if (mode[0] == 'r') {
114#if LZMA_VERSION <= UINT32_C(49990030)
115 ret = lzma_auto_decoder(&lf->str, NULL, NULL);
116#else
117 ret = lzma_auto_decoder(&lf->str, -1, 0);
118#endif
119 lf->str.avail_in = 0;
120 } else {
121 ret = LZMA_EASY_ENCODER(&lf->str, SDDS_GetLockedLZMACompressionLevel());
122 }
123 if (ret != LZMA_OK) {
124 fprintf(stderr, "lzma_open error: %d\n", ret);
125 lzma_end(&lf->str);
126 fclose(lf->fp);
127 free(lf);
128 return NULL;
129 }
130 return (void *)lf;
131}

◆ lzma_printf()

int lzma_printf ( struct lzmafile * file,
const char * format,
... )

Definition at line 392 of file SDDS_lzma.c.

392 {
393 size_t size = 32768;
394 int len;
395 unsigned char in[32768];
396 va_list va;
397 va_start(va, format);
398
399 in[size - 1] = 0;
400 (void)vsnprintf((char *)in, size, format, va);
401 va_end(va);
402 len = strlen((char *)in);
403
404 /* check that printf() results fit in buffer */
405 if (len <= 0 || len >= (int)size || in[size - 1] != 0) {
406 fprintf(stderr, "lzma_printf error: the printf results do not fit in the buffer\n");
407 return -1;
408 }
409 in[len] = '\0';
410 len = lzma_write(file, in, len);
411
412 return len;
413}

◆ lzma_putc()

int lzma_putc ( int c,
struct lzmafile * file )

Definition at line 356 of file SDDS_lzma.c.

356 {
357 int ret;
358 lzma_stream *lstr = &file->str;
359
360 unsigned char bufout[1]; /* compressed output buffer */
361 char buf[1];
362
363 if (file->mode != 'w') {
364 fprintf(stderr, "lzma_putc error: file was not opened for writting\n");
365 return EOF;
366 }
367 buf[0] = c;
368
369 lstr->next_in = (void *)buf;
370 lstr->avail_in = 1;
371 while (lstr->avail_in) {
372 lstr->next_out = bufout;
373 lstr->avail_out = 1;
374 ret = lzma_code(lstr, LZMA_RUN);
375 if (ret != LZMA_OK) {
376 fprintf(stderr, "lzma_putc error: encoding failed: %d\n", ret);
377 return EOF;
378 }
379 ret = fwrite(bufout, 1, 1 - lstr->avail_out, file->fp);
380 if (ret != 1 - lstr->avail_out) {
381 fprintf(stderr, "lzma_putc error\n");
382 return EOF;
383 }
384 }
385 return (unsigned char)c;
386}

◆ lzma_puts()

int lzma_puts ( const char * s,
struct lzmafile * file )

Definition at line 311 of file SDDS_lzma.c.

311 {
312 int ret;
313 lzma_stream *lstr = &file->str;
314 int count;
315 unsigned char *bufout; /* compressed output buffer */
316 char *buf;
317
318 if (file->mode != 'w') {
319 fprintf(stderr, "lzma_puts error: file was not opened for writting\n");
320 return EOF;
321 }
322 count = strlen(s);
323 bufout = malloc(sizeof(unsigned char) * count);
324 buf = malloc(sizeof(char) * count);
325 //strncpy(buf, s, count);
326 memcpy(buf, s, count);
327
328 lstr->next_in = (void *)buf;
329 lstr->avail_in = count;
330 while (lstr->avail_in) {
331 lstr->next_out = bufout;
332 lstr->avail_out = count;
333 ret = lzma_code(lstr, LZMA_RUN);
334 if (ret != LZMA_OK) {
335 fprintf(stderr, "lzma_puts error: encoding failed: %d\n", ret);
336 free(bufout);
337 free(buf);
338 return EOF;
339 }
340 ret = fwrite(bufout, 1, count - lstr->avail_out, file->fp);
341 if (ret != count - lstr->avail_out) {
342 fprintf(stderr, "lzma_puts error\n");
343 free(bufout);
344 free(buf);
345 return EOF;
346 }
347 }
348 free(bufout);
349 free(buf);
350 return count;
351}

◆ lzma_read()

long lzma_read ( struct lzmafile * file,
void * buf,
size_t count )

Definition at line 176 of file SDDS_lzma.c.

176 {
177 int ret;
178 lzma_stream *lstr;
179 if (file->mode != 'r')
180 return -1;
181
182 lstr = &file->str;
183 lstr->next_out = buf;
184 lstr->avail_out = count;
185
186 /* decompress until EOF or output buffer is full */
187 while (lstr->avail_out) {
188 if (lstr->avail_in == 0) {
189 /* refill input buffer */
190 ret = fread(file->rdbuf, 1, BUF_SIZE, file->fp);
191 if (ret == 0) {
192 break; /* EOF */
193 }
194 lstr->next_in = file->rdbuf; /* buffer containing lzma data just read */
195 lstr->avail_in = ret; /* number of bytes read */
196 }
197 ret = lzma_code(lstr, LZMA_RUN);
198 /* this fills up lstr->next_out and decreases lstr->avail_out */
199 /* it also emptys lstr->next_in and decreases lstr->avail_in */
200 if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
201 fprintf(stderr, "lzma_read error: decoding failed: %d\n", ret);
202 return -1;
203 }
204 if (ret == LZMA_STREAM_END) {
205 break; /* EOF */
206 }
207 }
208 return count - lstr->avail_out; /* length of buf that has valid data */
209}

◆ lzma_seek()

int lzma_seek ( struct lzmafile * file,
long offset,
int whence )

Definition at line 434 of file SDDS_lzma.c.

434 {
435 return fseek(file->fp, offset, whence);
436}

◆ lzma_tell()

long lzma_tell ( struct lzmafile * file)

Definition at line 430 of file SDDS_lzma.c.

430 {
431 return ftell(file->fp);
432}

◆ lzma_write()

long lzma_write ( struct lzmafile * file,
const void * buf,
size_t count )

Definition at line 275 of file SDDS_lzma.c.

275 {
276 int ret;
277 lzma_stream *lstr = &file->str;
278 unsigned char *bufout; /* compressed output buffer */
279 bufout = malloc(sizeof(char) * count);
280
281 if (file->mode != 'w') {
282 fprintf(stderr, "lzma_write error: file was not opened for writting\n");
283 free(bufout);
284 return -1;
285 }
286 lstr->next_in = buf;
287 lstr->avail_in = count;
288 while (lstr->avail_in) {
289 lstr->next_out = bufout;
290 lstr->avail_out = count;
291 ret = lzma_code(lstr, LZMA_RUN);
292 if (ret != LZMA_OK) {
293 fprintf(stderr, "lzma_write error: encoding failed: %d\n", ret);
294 free(bufout);
295 return -1;
296 }
297 ret = fwrite(bufout, 1, count - lstr->avail_out, file->fp);
298 if (ret != count - lstr->avail_out) {
299 fprintf(stderr, "lzma_write error\n");
300 free(bufout);
301 return -1;
302 }
303 }
304 free(bufout);
305 return count;
306}

◆ SDDS1_ProcessArrayDefinition()

int32_t SDDS1_ProcessArrayDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Processes and defines an array within an SDDS dataset.

This function parses an array definition string, extracts the necessary array information, and defines the array in the given SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS dataset where the array will be defined.
sString containing the array definition in namelist format.
Returns
  • Returns 1 on successful processing and definition of the array.
  • Returns 0 if an error occurs during parsing or definition.

Definition at line 916 of file SDDS_process.c.

916 {
917 ARRAY_DEFINITION arrayDef;
918 int32_t code;
919
920 arrayDef.name = arrayDef.symbol = arrayDef.units = arrayDef.description = arrayDef.format_string = arrayDef.group_name = NULL;
921 arrayDef.type = -1;
922 arrayDef.field_length = 0;
923 arrayDef.dimensions = 1;
924
925 if (!SDDS_ParseNamelist((void *)&arrayDef, SDDS_ArrayFieldInformation, SDDS_ARRAY_FIELDS, s)) {
926 SDDS_SetError("Problem parsing array namelist");
927 return 0;
928 }
929 code = SDDS_DefineArray(SDDS_dataset, arrayDef.name, arrayDef.symbol, arrayDef.units, arrayDef.description, arrayDef.format_string, arrayDef.type, arrayDef.field_length, arrayDef.dimensions, arrayDef.group_name);
930 if (arrayDef.name)
931 free(arrayDef.name);
932 if (arrayDef.symbol)
933 free(arrayDef.symbol);
934 if (arrayDef.units)
935 free(arrayDef.units);
936 if (arrayDef.description)
937 free(arrayDef.description);
938 if (arrayDef.format_string)
939 free(arrayDef.format_string);
940 if (arrayDef.group_name)
941 free(arrayDef.group_name);
942
943 if (code < 0) {
944 SDDS_SetError("Unable to process array definition--call to define array failed (SDDS1_ProcessArrayDefinition)");
945 return (0);
946 }
947 return (1);
948}
SDDS_FIELD_INFORMATION SDDS_ArrayFieldInformation[SDDS_ARRAY_FIELDS]
Field information for array definitions.
Definition SDDS_data.c:175
int32_t SDDS_DefineArray(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, int32_t dimensions, const char *group_name)
Defines a data array within the SDDS dataset.
int32_t SDDS_ParseNamelist(void *data, SDDS_FIELD_INFORMATION *fieldInfo, int32_t fieldInfos, char *s)
Parse a namelist string and populate the corresponding data structure.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:421

◆ SDDS1_ProcessAssociateDefinition()

int32_t SDDS1_ProcessAssociateDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Processes and defines an associate within an SDDS dataset.

This function parses an associate definition string, extracts the necessary associate information, and defines the associate in the given SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS dataset where the associate will be defined.
sString containing the associate definition in namelist format.
Returns
  • Returns 1 on successful processing and definition of the associate.
  • Returns 0 if an error occurs during parsing or definition.

Definition at line 847 of file SDDS_process.c.

847 {
848 ASSOCIATE_DEFINITION assocDef;
849 int32_t code;
850
851 assocDef.name = assocDef.filename = assocDef.path = assocDef.description = assocDef.contents = NULL;
852 assocDef.sdds = 0;
853 if (!SDDS_ParseNamelist((void *)&assocDef, SDDS_AssociateFieldInformation, SDDS_ASSOCIATE_FIELDS, s)) {
854 SDDS_SetError("Problem parsing associate namelist");
855 return 0;
856 }
857
858 code = SDDS_DefineAssociate(SDDS_dataset, assocDef.name, assocDef.filename, assocDef.path, assocDef.description, assocDef.contents, assocDef.sdds);
859 if (code < 0) {
860 SDDS_SetError("Unable to process associate definition--call to define associate failed (SDDS1_ProcessAssociateDefinition)");
861 return (0);
862 }
863 return (1);
864}
SDDS_FIELD_INFORMATION SDDS_AssociateFieldInformation[SDDS_ASSOCIATE_FIELDS]
Field information for associate definitions.
Definition SDDS_data.c:225
int32_t SDDS_DefineAssociate(SDDS_DATASET *SDDS_dataset, const char *name, const char *filename, const char *path, const char *description, const char *contents, int32_t sdds)
Defines an associate for the SDDS dataset.

◆ SDDS1_ProcessColumnDefinition()

int32_t SDDS1_ProcessColumnDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Processes and defines a column within an SDDS dataset.

This function parses a column definition string, extracts the necessary column information, and defines the column in the given SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS dataset where the column will be defined.
sString containing the column definition in namelist format.
Returns
  • Returns 1 on successful processing and definition of the column.
  • Returns 0 if an error occurs during parsing or definition.

Definition at line 730 of file SDDS_process.c.

730 {
731 COLUMN_DEFINITION colDef;
732 int32_t code;
733
734 colDef.name = colDef.symbol = colDef.units = colDef.description = colDef.format_string = NULL;
735 colDef.type = -1;
736 colDef.field_length = 0;
737
738 if (!SDDS_ParseNamelist((void *)&colDef, SDDS_ColumnFieldInformation, SDDS_COLUMN_FIELDS, s)) {
739 SDDS_SetError("Problem parsing column namelist");
740 return 0;
741 }
742 code = SDDS_DefineColumn(SDDS_dataset, colDef.name, colDef.symbol, colDef.units, colDef.description, colDef.format_string, colDef.type, colDef.field_length);
743 if (colDef.name)
744 free(colDef.name);
745 if (colDef.symbol)
746 free(colDef.symbol);
747 if (colDef.units)
748 free(colDef.units);
749 if (colDef.description)
750 free(colDef.description);
751 if (colDef.format_string)
752 free(colDef.format_string);
753
754 if (code < 0) {
755 SDDS_SetError("Unable to process column definition--call to define column failed (SDDS1_ProcessColumnDefinition)");
756 return (0);
757 }
758 return (1);
759}
SDDS_FIELD_INFORMATION SDDS_ColumnFieldInformation[SDDS_COLUMN_FIELDS]
Field information for column definitions.
Definition SDDS_data.c:193
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.

◆ SDDS1_ProcessDataMode()

int32_t SDDS1_ProcessDataMode ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Processes and sets the data mode for an SDDS dataset.

This function parses a data mode definition string, extracts the necessary data mode information, and sets the data mode in the given SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS dataset where the data mode will be set.
sString containing the data mode definition in namelist format.
Returns
  • Returns 1 on successful processing and setting of the data mode.
  • Returns 0 if an error occurs during parsing or if mandatory fields are missing.

Definition at line 879 of file SDDS_process.c.

879 {
880 DATA_MODE *dataMode;
881 dataMode = &(SDDS_dataset->layout.data_mode);
882 dataMode->mode = 0;
883 dataMode->endian = 0;
884 dataMode->lines_per_row = 1;
885 dataMode->no_row_counts = dataMode->additional_header_lines = 0;
886 dataMode->fixed_row_count = 0;
887 dataMode->column_major = 0;
888 if (!SDDS_ParseNamelist((void *)dataMode, SDDS_DataFieldInformation, SDDS_DATA_FIELDS, s)) {
889 SDDS_SetError("Problem parsing data namelist");
890 return 0;
891 }
892 if (dataMode->mode == 0) {
893 SDDS_SetError("Problem with data namelist: mode not given.");
894 return 0;
895 }
896 if (dataMode->mode == SDDS_ASCII && dataMode->lines_per_row < 0) {
897 SDDS_SetError("Unable to process data mode--lines_per_row is invalid (SDDS1_ProcessDataMode)");
898 return (0);
899 }
900 return 1;
901}
SDDS_FIELD_INFORMATION SDDS_DataFieldInformation[SDDS_DATA_FIELDS]
Field information for data mode settings.
Definition SDDS_data.c:159

◆ SDDS1_ProcessDescription()

int32_t SDDS1_ProcessDescription ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the description section for SDDS protocol version 1.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the description string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 703 of file SDDS_process.c.

703 {
704 SDDS_dataset->layout.description = NULL;
705 SDDS_dataset->layout.contents = NULL;
706
707 if (!SDDS_ParseNamelist((void *)&SDDS_dataset->layout, SDDS_DescriptionFieldInformation, SDDS_DESCRIPTION_FIELDS, s)) {
708 SDDS_SetError("Problem parsing description namelist");
709 return 0;
710 }
711#if DEBUG
712 fprintf(stderr, "Description scanned: description=>%s<, contents = >%s<\n", SDDS_dataset->layout.description, SDDS_dataset->layout.contents);
713#endif
714 return 1;
715}
SDDS_FIELD_INFORMATION SDDS_DescriptionFieldInformation[SDDS_DESCRIPTION_FIELDS]
Field information for SDDS layout descriptions.
Definition SDDS_data.c:107

◆ SDDS1_ProcessIncludeCommand()

FILE * SDDS1_ProcessIncludeCommand ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Processes an include command by opening the specified file.

This function parses an include command string to extract the filename, then attempts to open the file for reading. It returns a file pointer if successful.

Parameters
SDDS_datasetPointer to the SDDS dataset (unused in current implementation).
sString containing the include command in namelist format.
Returns
  • Returns a pointer to the opened FILE on success.
  • Returns NULL if parsing fails or the file cannot be opened.

Definition at line 818 of file SDDS_process.c.

818 {
819 FILE *fp;
820 char *filename;
821
822 filename = NULL;
823 if (!SDDS_ParseNamelist((void *)&filename, SDDS_IncludeFieldInformation, SDDS_INCLUDE_FIELDS, s)) {
824 SDDS_SetError("Problem parsing include namelist");
825 return 0;
826 }
827 if (!filename || !(fp = fopen(filename, "r"))) {
828 SDDS_SetError("Unable to process include command--invalid/nonexistent file (SDDS1_ProcessIncludeCommand)");
829 return (NULL);
830 }
831 return (fp);
832}
SDDS_FIELD_INFORMATION SDDS_IncludeFieldInformation[SDDS_INCLUDE_FIELDS]
Field information for include directives.
Definition SDDS_data.c:240

◆ SDDS1_ProcessParameterDefinition()

int32_t SDDS1_ProcessParameterDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Processes and defines a parameter within an SDDS dataset.

This function parses a parameter definition string, extracts the necessary parameter information, and defines the parameter in the given SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS dataset where the parameter will be defined.
sString containing the parameter definition in namelist format.
Returns
  • Returns 1 on successful processing and definition of the parameter.
  • Returns 0 if an error occurs during parsing or definition.

Definition at line 774 of file SDDS_process.c.

774 {
775 PARAMETER_DEFINITION paramDef;
776 int32_t code;
777
778 paramDef.name = paramDef.symbol = paramDef.units = paramDef.description = paramDef.format_string = paramDef.fixed_value = NULL;
779 paramDef.type = -1;
780
781 if (!SDDS_ParseNamelist((void *)&paramDef, SDDS_ParameterFieldInformation, SDDS_PARAMETER_FIELDS, s)) {
782 SDDS_SetError("Problem parsing parameter namelist");
783 return 0;
784 }
785 code = SDDS_DefineParameter(SDDS_dataset, paramDef.name, paramDef.symbol, paramDef.units, paramDef.description, paramDef.format_string, paramDef.type, paramDef.fixed_value);
786 if (paramDef.name)
787 free(paramDef.name);
788 if (paramDef.symbol)
789 free(paramDef.symbol);
790 if (paramDef.units)
791 free(paramDef.units);
792 if (paramDef.description)
793 free(paramDef.description);
794 if (paramDef.format_string)
795 free(paramDef.format_string);
796
797 if (code < 0) {
798 SDDS_SetError("Unable to process parameter definition--call to define parameter failed (SDDS1_ProcessParameterDefinition)");
799 return (0);
800 }
801 return (1);
802}
SDDS_FIELD_INFORMATION SDDS_ParameterFieldInformation[SDDS_PARAMETER_FIELDS]
Field information for parameter definitions.
Definition SDDS_data.c:209
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.

◆ SDDS_AdvanceCounter()

int32_t SDDS_AdvanceCounter ( int32_t * counter,
int32_t * max_count,
int32_t n_indices )
extern

Advances a multi-dimensional counter based on maximum counts for each dimension.

This helper function increments a multi-dimensional counter array, handling carry-over for each dimension. It is typically used for iterating over multi-dimensional arrays in a nested loop fashion.

Parameters
counterPointer to an array of integers representing the current count in each dimension.
max_countPointer to an array of integers representing the maximum count for each dimension.
n_indicesThe number of dimensions (indices) in the counter and max_count arrays.
Returns
Returns the index of the dimension that was incremented. If all dimensions have been fully iterated over, returns -1 to indicate completion.
See also
SDDS_SetArrayVararg, SDDS_SetArray, SDDS_AdvanceCounter

Definition at line 1497 of file SDDS_dataprep.c.

1497 {
1498 int32_t i;
1499
1500 for (i = n_indices - 1; i >= 0; i--)
1501 if (counter[i] != (max_count[i] - 1))
1502 break;
1503 if (i == -1)
1504 return (-1);
1505
1506 for (i = n_indices - 1; i >= 0; i--) {
1507 if (counter[i] < (max_count[i] - 1)) {
1508 counter[i]++;
1509 break;
1510 } else {
1511 counter[i] = 0;
1512 }
1513 }
1514 return (i);
1515}

◆ SDDS_AllocateColumnFlags()

int32_t SDDS_AllocateColumnFlags ( SDDS_DATASET * SDDS_target)
extern

Allocates memory for column flags and column order arrays in the specified SDDS dataset.

This function allocates memory for the column_flag and column_order arrays based on the number of columns defined in the dataset's layout. It initializes column_flag to 1 and column_order to 0 and 1 respectively.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure where column flags will be allocated.
Returns
Returns 1 on successful allocation and initialization. On failure, returns 0 and records an error message.
See also
SDDS_Malloc, SDDS_SetMemory, SDDS_SetError

Definition at line 42 of file SDDS_dataprep.c.

42 {
43 if (SDDS_target->layout.n_columns &&
44 ((!(SDDS_target->column_flag = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_target->layout.n_columns)) ||
45 !(SDDS_target->column_order = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_target->layout.n_columns))) ||
46 (!SDDS_SetMemory(SDDS_target->column_flag, SDDS_target->layout.n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
47 !SDDS_SetMemory(SDDS_target->column_order, SDDS_target->layout.n_columns, SDDS_LONG, (int32_t)0, (int32_t)1)))) {
48 SDDS_SetError("Unable to allocate column flags--memory allocation failure (SDDS_AllocateColumnFlags)");
49 return 0;
50 }
51 return 1;
52}
int32_t SDDS_SetMemory(void *mem, int64_t n_elements, int32_t data_type,...)
Initializes a memory block with a sequence of values based on a specified data type.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
Definition SDDS_utils.c:705
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61

◆ SDDS_AsciiDataExpected()

int32_t SDDS_AsciiDataExpected ( SDDS_DATASET * SDDS_dataset)
extern

Checks whether the SDDS dataset expects ASCII data input.

This function determines if the provided SDDS dataset is expecting ASCII data. The dataset expects ASCII data if it has columns, arrays, or parameters without fixed values. If the dataset only contains parameters with fixed values and no columns or arrays, it does not expect ASCII data.

Parameters
SDDS_datasetPointer to the SDDS dataset to check.
Returns
Returns 1 if ASCII data is expected, or 0 if ASCII data is not expected.

Definition at line 2140 of file SDDS_ascii.c.

2140 {
2141 int32_t i;
2142 if (SDDS_dataset->layout.n_columns || SDDS_dataset->layout.n_arrays)
2143 return (1);
2144 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
2145 if (!SDDS_dataset->layout.parameter_definition[i].fixed_value)
2146 return (1);
2147 return (0);
2148}

◆ SDDS_CopyColumn()

int32_t SDDS_CopyColumn ( SDDS_DATASET * SDDS_dataset,
int32_t target,
int32_t source )
extern

Copies data from a source column to a target column within an SDDS dataset.

This function duplicates the data from the specified source column to the target column in the provided SDDS dataset. It handles both string and non-string data types appropriately, ensuring that memory is managed correctly for string entries.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
targetThe index of the target column where data will be copied to.
sourceThe index of the source column from which data will be copied.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the column copy was successful.
0Indicates that an error occurred (e.g., invalid dataset, out-of-range indices, memory allocation failure, string copy failure).
Note
  • Both target and source must be valid column indices within the dataset.
  • The function does not handle the allocation of new columns; it assumes that the target column already exists.
See also
SDDS_DeleteColumn, SDDS_DeleteUnsetColumns, SDDS_TransferRow

Definition at line 3929 of file SDDS_extract.c.

3929 {
3930 COLUMN_DEFINITION *cd_target, *cd_source;
3931 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_CopyColumn"))
3932 return (0);
3933 if (target < 0 || source < 0 || target >= SDDS_dataset->layout.n_columns || source >= SDDS_dataset->layout.n_columns) {
3934 SDDS_SetError("Unable to copy column--target or source index out of range (SDDS_CopyColumn");
3935 return (0);
3936 }
3937 cd_target = SDDS_dataset->layout.column_definition + target;
3938 cd_source = SDDS_dataset->layout.column_definition + source;
3939 SDDS_dataset->column_flag[target] = SDDS_dataset->column_flag[source];
3940 if (SDDS_dataset->n_rows_allocated) {
3941 if (cd_target->type != cd_source->type) {
3942 if (!(SDDS_dataset->data[target] = SDDS_Realloc(SDDS_dataset->data[target], SDDS_type_size[cd_source->type - 1] * SDDS_dataset->n_rows_allocated))) {
3943 SDDS_SetError("Unable to copy column--memory allocation failure (SDDS_CopyColumn)");
3944 return (0);
3945 }
3946 }
3947 if (cd_source->type != SDDS_STRING)
3948 memcpy(SDDS_dataset->data[target], SDDS_dataset->data[source], SDDS_type_size[cd_source->type - 1] * SDDS_dataset->n_rows);
3949 else if (!SDDS_CopyStringArray(SDDS_dataset->data[target], SDDS_dataset->data[source], SDDS_dataset->n_rows)) {
3950 SDDS_SetError("Unable to copy column--string copy failure (SDDS_CopyColumn)");
3951 return (0);
3952 }
3953 }
3954 memcpy((char *)cd_target, (char *)cd_source, sizeof(*cd_target));
3955 return (1);
3956}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:618
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85

◆ SDDS_CopyParameter()

int32_t SDDS_CopyParameter ( SDDS_DATASET * SDDS_dataset,
int32_t target,
int32_t source )
extern

Copies a parameter from a source index to a target index within an SDDS dataset.

This function duplicates the parameter data from the source index to the target index in the provided SDDS dataset. It handles both string and non-string data types appropriately, ensuring that memory is managed correctly for string entries.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
targetThe index of the target parameter where data will be copied to.
sourceThe index of the source parameter from which data will be copied.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the parameter copy was successful.
0Indicates that an error occurred (e.g., invalid dataset, out-of-range indices, memory allocation failure, string copy failure).
Note
  • Both target and source must be valid parameter indices within the dataset.
  • The function assumes that the target parameter already exists and is intended to be overwritten.
See also
SDDS_DeleteParameter, SDDS_CopyArray

Definition at line 4018 of file SDDS_extract.c.

4018 {
4019 PARAMETER_DEFINITION *cd_target, *cd_source;
4020 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_CopyParameter"))
4021 return (0);
4022 if (target < 0 || source < 0 || target >= SDDS_dataset->layout.n_parameters || source >= SDDS_dataset->layout.n_parameters) {
4023 SDDS_SetError("Unable to copy parameter--target or source index out of range (SDDS_CopyParameter");
4024 return (0);
4025 }
4026 cd_target = SDDS_dataset->layout.parameter_definition + target;
4027 cd_source = SDDS_dataset->layout.parameter_definition + source;
4028 if (SDDS_dataset->parameter) {
4029 if (cd_target->type != cd_source->type) {
4030 if (!(SDDS_dataset->parameter[target] = SDDS_Realloc(SDDS_dataset->data[target], SDDS_type_size[cd_source->type - 1]))) {
4031 SDDS_SetError("Unable to copy parameter--memory allocation failure (SDDS_CopyParameter)");
4032 return (0);
4033 }
4034 }
4035 if (cd_source->type != SDDS_STRING)
4036 memcpy(SDDS_dataset->parameter[target], SDDS_dataset->parameter[source], SDDS_type_size[cd_source->type - 1]);
4037 else if (!SDDS_CopyStringArray(SDDS_dataset->parameter[target], SDDS_dataset->parameter[source], 1)) {
4038 SDDS_SetError("Unable to copy parameter--string copy failure (SDDS_CopyParameter)");
4039 return (0);
4040 }
4041 }
4042 memcpy((char *)cd_target, (char *)cd_source, sizeof(*cd_target));
4043 return (1);
4044}

◆ SDDS_FreePointerArray()

void SDDS_FreePointerArray ( void ** data,
int32_t dimensions,
int32_t * dimension )
extern

Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.

This function recursively deallocates a multi-dimensional pointer array that was previously created using SDDS_MakePointerArray or SDDS_MakePointerArrayRecursively. It ensures that all pointer layers are properly freed to prevent memory leaks.

Parameters
[in]dataPointer to the multi-dimensional pointer array to be freed.
[in]dimensionsThe number of dimensions in the pointer array.
[in]dimensionAn array specifying the size of each dimension.
Note
  • The function assumes that the pointer array was created using SDDS library functions.
  • It does not free the actual data block pointed to by the pointer array.
See also
SDDS_MakePointerArrayRecursively
free

Definition at line 3087 of file SDDS_utils.c.

3091{
3092 if (!data || !dimension || !dimensions)
3093 return;
3094 if (dimensions > 1) {
3095 SDDS_FreePointerArray((void **)(data[0]), dimensions - 1, dimension + 1);
3096 free(data);
3097 }
3098}
void SDDS_FreePointerArray(void **data, int32_t dimensions, int32_t *dimension)
Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.

◆ SDDS_FreeTableStrings()

void SDDS_FreeTableStrings ( SDDS_DATASET * SDDS_dataset)

Frees the strings in the current table of the SDDS dataset.

This function frees any strings stored in the data columns of the current table. It does not free strings from parameters or arrays.

Parameters
SDDS_datasetThe SDDS dataset to free table strings from.

Definition at line 1448 of file SDDS_input.c.

1448 {
1449 int64_t i, j;
1450 char **ptr;
1451 /* free stored strings */
1452 if (!SDDS_dataset)
1453 return;
1454 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
1455 if (SDDS_dataset->layout.column_definition[i].type == SDDS_STRING) {
1456 ptr = (char **)SDDS_dataset->data[i];
1457 for (j = 0; j < SDDS_dataset->n_rows; j++, ptr++)
1458 if (*ptr) {
1459 free(*ptr);
1460 *ptr = NULL;
1461 }
1462 }
1463}

◆ SDDS_fseek()

int32_t SDDS_fseek ( FILE * fp,
int64_t offset,
int32_t dir )
extern

Sets the file position indicator for a given file stream with retry logic.

Attempts to set the file position indicator for the specified file stream (fp) to a new position defined by offset and dir. The function retries the fseek operation up to FSEEK_TRIES times in case of transient failures, implementing a delay between attempts.

Parameters
fpPointer to the FILE stream whose position indicator is to be set.
offsetNumber of bytes to offset from the position specified by dir.
dirPositioning directive, which can be one of:
  • SEEK_SET to set the position relative to the beginning of the file,
  • SEEK_CUR to set the position relative to the current position,
  • SEEK_END to set the position relative to the end of the file.
Returns
  • Returns 0 if the operation is successful.
  • Returns -1 if all retry attempts fail to set the file position.

The function attempts to set the file position using fseek. If fseek fails, it sleeps for 1 second (or 1 second using nanosleep on vxWorks systems) before retrying. After FSEEK_TRIES unsuccessful attempts, it reports a warning and returns -1.

Note
  • The function is designed to handle temporary file access issues by retrying the fseek operation.
  • It is not suitable for non-recoverable fseek errors, which will cause it to fail after retries.

Definition at line 1279 of file SDDS_binary.c.

1279 {
1280 int32_t try;
1281#if defined(vxWorks)
1282 struct timespec rqtp;
1283 rqtp.tv_sec = 1;
1284 rqtp.tv_nsec = 0;
1285#endif
1286 for (try = 0; try < FSEEK_TRIES; try++) {
1287 if (fseek(fp, offset, dir) == -1) {
1288#if defined(vxWorks)
1289 nanosleep(&rqtp, NULL);
1290#else
1291 sleep(1);
1292#endif
1293 } else
1294 break;
1295 }
1296 if (try == 0)
1297 return 0;
1298 if (try == FSEEK_TRIES) {
1299 fputs("warning: fseek problems--unable to recover\n", stderr);
1300 return -1;
1301 }
1302 fputs("warning: fseek problems--recovered\n", stderr);
1303 return 0;
1304}

◆ SDDS_GetSelectedRowIndex()

int64_t SDDS_GetSelectedRowIndex ( SDDS_DATASET * SDDS_dataset,
int64_t srow_index )
extern

Retrieves the actual row index corresponding to a selected row position within the current data table.

This function maps a selected row index (i.e., the position among rows marked as "of interest") to its corresponding actual row index within the dataset's data table.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
srow_indexZero-based index representing the position of the selected row among all rows marked as "of interest".
Returns
  • Non-negative integer representing the actual row index within the dataset's data table.
  • -1 if an error occurs (e.g., invalid dataset, tabular data not present, srow_index out of range).
Warning
  • Ensure that srow_index is within the valid range [0, SDDS_CountRowsOfInterest(SDDS_dataset) - 1] to avoid out-of-range errors.
Note
  • This function is useful when iterating over selected rows and needing to access their actual positions within the dataset.
See also

Definition at line 1702 of file SDDS_extract.c.

1702 {
1703 int64_t i, j;
1704 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetSelectedRowIndex"))
1705 return (-1);
1706 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_GetSelectedRowIndex"))
1707 return (-1);
1708 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1709 if (SDDS_dataset->row_flag[i] && j++ == srow_index)
1710 break;
1711 }
1712 if (i == SDDS_dataset->n_rows)
1713 return (-1);
1714 return (i);
1715}
int32_t SDDS_CheckTabularData(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the consistency of tabular data within an SDDS dataset.
Definition SDDS_utils.c:643

◆ SDDS_GetSpecialCommentsModes()

uint32_t SDDS_GetSpecialCommentsModes ( SDDS_DATASET * SDDS_dataset)

Retrieves the current special comments modes set in the SDDS dataset.

This function returns the current set of special comment flags that have been parsed and set within the dataset. These flags indicate the presence of specific configurations such as endianness and fixed row counts.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Returns
  • A uint32_t value representing the combined set of special comment flags.
  • 0 if no special comments have been set.
Note
  • Special comment flags are typically set by parsing comment strings using functions like SDDS_ParseSpecialComments.
Warning
  • Ensure that the dataset is properly initialized before calling this function.
See also
SDDS_ParseSpecialComments, SDDS_ResetSpecialCommentsModes

Definition at line 5292 of file SDDS_utils.c.

5292 {
5293 return SDDS_dataset->layout.commentFlags;
5294}

◆ SDDS_GetTerminateMode()

int32_t SDDS_GetTerminateMode ( void )
extern

Definition at line 1346 of file SDDS_input.c.

1346 {
1347 int32_t mode;
1348 mdb_thread_lock(&terminateModeLock);
1349 mode = terminateMode;
1350 mdb_thread_unlock(&terminateModeLock);
1351 return mode;
1352}
static MDB_THREAD_LOCK terminateModeLock
Global variable to set the terminate mode for the SDDS dataset.

◆ SDDS_LZMAReadLayout()

int32_t SDDS_LZMAReadLayout ( SDDS_DATASET * SDDS_dataset,
struct lzmafile * lzmafp )
extern

Reads the header layout of an SDDS dataset from a file with LZMA compression.

Parameters
SDDS_datasetThe SDDS dataset structure to store the layout information.
lzmafpThe LZMA file pointer to the SDDS file.
Returns
Returns 1 on success, 0 on failure.

Definition at line 681 of file SDDS_input.c.

681 {
682 char buffer[SDDS_MAXLINE];
683 char *groupName, *ptr;
684 FILE *fp1;
685 int32_t retval, bigEndianMachine;
686 uint32_t commentFlags;
687
688 if (!lzmafp) {
689 SDDS_SetError("Unable to read layout--NULL file pointer (SDDS_LZMAReadLayout)");
690 return (0);
691 }
692 if (SDDS_dataset->layout.depth == 0) {
693 if (SDDS_dataset->layout.disconnected) {
694 SDDS_SetError("Can't read layout--file is disconnected (SDDS_LZMAReadLayout)");
695 return 0;
696 }
697 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_LZMAReadLayout")) {
698 lzma_close(lzmafp);
699 return (0);
700 }
701 SDDS_dataset->layout.layout_written = 1; /* it is already in the file */
702 if (!lzma_gets(SDDS_dataset->layout.s, SDDS_MAXLINE, lzmafp)) {
703 lzma_close(lzmafp);
704 SDDS_SetError("Unable to read layout--no header lines found (SDDS_LZMAReadLayout)");
705 return (0);
706 }
707 if (strncmp(SDDS_dataset->layout.s, "SDDS", 4) != 0) {
708 lzma_close(lzmafp);
709 SDDS_SetError("Unable to read layout--no header lines found (SDDS_LZMAReadLayout)");
710 return (0);
711 }
712 if (sscanf(SDDS_dataset->layout.s + 4, "%" SCNd32, &SDDS_dataset->layout.version) != 1) {
713 lzma_close(lzmafp);
714 SDDS_SetError("Unable to read layout--no version number on first line (SDDS_LZMAReadLayout)");
715 return (0);
716 }
717 SDDS_ResetSpecialCommentsModes(SDDS_dataset);
718 SDDS_dataset->layout.data_command_seen = 0;
719 }
720 while (SDDS_GetLZMANamelist(SDDS_dataset, SDDS_dataset->layout.s, SDDS_MAXLINE, lzmafp)) {
721#if DEBUG
722 strcpy(buffer, SDDS_dataset->layout.s);
723#endif
724 groupName = SDDS_dataset->layout.s + 1;
725 if (!(ptr = strpbrk(SDDS_dataset->layout.s, " \t"))) {
726 SDDS_SetError("Unable to read layout---no groupname in namelist (SDDS_LZMAReadLayout)");
727 return 0;
728 }
729 *ptr = 0;
730 switch (match_string(groupName, SDDS_command, SDDS_NUM_COMMANDS, EXACT_MATCH)) {
731 case SDDS_DESCRIPTION_COMMAND:
732 if (!SDDS_ProcessDescription(SDDS_dataset, ptr + 1)) {
733 lzma_close(lzmafp);
734 SDDS_SetError("Unable to process description (SDDS_LZMAReadLayout)");
735 return (0);
736 }
737 break;
738 case SDDS_COLUMN_COMMAND:
739 if (!SDDS_ProcessColumnDefinition(SDDS_dataset, ptr + 1)) {
740 lzma_close(lzmafp);
741 SDDS_SetError("Unable to process column definition (SDDS_LZMAReadLayout)");
742 return (0);
743 }
744 break;
745 case SDDS_PARAMETER_COMMAND:
746 if (!SDDS_ProcessParameterDefinition(SDDS_dataset, ptr + 1)) {
747 lzma_close(lzmafp);
748 SDDS_SetError("Unable to process parameter definition (SDDS_LZMAReadLayout)");
749 return (0);
750 }
751 break;
752 case SDDS_ASSOCIATE_COMMAND:
753#if RW_ASSOCIATES != 0
754 if (!SDDS_ProcessAssociateDefinition(SDDS_dataset, ptr + 1)) {
755 lzma_close(lzmafp);
756 SDDS_SetError("Unable to process associate definition (SDDS_LZMAReadLayout)");
757 return (0);
758 }
759#endif
760 break;
761 case SDDS_DATA_COMMAND:
762 if (!SDDS_ProcessDataMode(SDDS_dataset, ptr + 1)) {
763 lzma_close(lzmafp);
764 SDDS_SetError("Unable to process data mode (SDDS_LZMAReadLayout)");
765 return (0);
766 }
767 if (SDDS_dataset->layout.data_command_seen) {
768 /* should never happen */
769 lzma_close(lzmafp);
770 SDDS_SetError("Unable to read layout--multiple data commands (SDDS_LZMAReadLayout)");
771 return (0);
772 }
773 if (!SDDS_SaveLayout(SDDS_dataset)) {
774 SDDS_SetError("Unable to read layout--couldn't save layout (SDDS_LZMAReadLayout)");
775 return (0);
776 }
777 SDDS_dataset->layout.data_command_seen = 1;
778 commentFlags = SDDS_GetSpecialCommentsModes(SDDS_dataset);
779 if ((commentFlags & SDDS_BIGENDIAN_SEEN) && (commentFlags & SDDS_LITTLEENDIAN_SEEN)) {
780 SDDS_SetError("Unable to read data as it says it is both big and little endian (SDDS_LZMAReadLayout)");
781 return (0);
782 }
783 bigEndianMachine = SDDS_IsBigEndianMachine();
784 SDDS_dataset->swapByteOrder = SDDS_dataset->layout.byteOrderDeclared = 0;
785 SDDS_dataset->autoRecover = 0;
786 if ((commentFlags & SDDS_BIGENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_BIGENDIAN)) {
787 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN_SEEN;
788 if (!bigEndianMachine)
789 SDDS_dataset->swapByteOrder = 1;
790 }
791 if ((commentFlags & SDDS_LITTLEENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_LITTLEENDIAN)) {
792 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN_SEEN;
793 if (bigEndianMachine)
794 SDDS_dataset->swapByteOrder = 1;
795 }
796 if ((commentFlags & SDDS_FIXED_ROWCOUNT_SEEN) || (SDDS_dataset->layout.data_mode.fixed_row_count))
797 if (!SDDS_SetAutoReadRecovery(SDDS_dataset, SDDS_AUTOREADRECOVER))
798 return (0);
799 return (1);
800 case SDDS_INCLUDE_COMMAND:
801 if (!(fp1 = SDDS_ProcessIncludeCommand(SDDS_dataset, ptr + 1))) {
802 lzma_close(lzmafp);
803 SDDS_SetError("Unable to process include command (SDDS_LZMAReadLayout)");
804 return (0);
805 }
806 SDDS_dataset->layout.depth += 1;
807 retval = SDDS_ReadLayout(SDDS_dataset, fp1);
808 SDDS_dataset->layout.depth -= 1;
809 fclose(fp1);
810 if (retval == 0) {
811 return (0);
812 }
813 if (SDDS_dataset->layout.data_command_seen) {
814 return (1);
815 }
816 break;
817 case SDDS_ARRAY_COMMAND:
818 if (!SDDS_ProcessArrayDefinition(SDDS_dataset, ptr + 1)) {
819 lzma_close(lzmafp);
820 SDDS_SetError("Unable to process array definition (SDDS_LZMAReadLayout)");
821 return (0);
822 }
823 break;
824 default:
825 lzma_close(lzmafp);
826 sprintf(buffer, "Unknown layout entry %s given (SDDS_LZMAReadLayout)", groupName);
827 SDDS_SetError(buffer);
828 return (0);
829 }
830 }
831 /* on recursive calls, it's okay to hit EOF */
832 if ((lzma_eof(lzmafp) && SDDS_dataset->layout.depth != 0) || SDDS_dataset->layout.data_command_seen)
833 return (1);
834 return (0);
835}
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
Definition SDDS_copy.c:615
char * SDDS_command[SDDS_NUM_COMMANDS]
Array of supported SDDS command names.
Definition SDDS_data.c:81
int32_t SDDS_SetAutoReadRecovery(SDDS_DATASET *SDDS_dataset, uint32_t mode)
int32_t SDDS_ReadLayout(SDDS_DATASET *SDDS_dataset, FILE *fp)
Definition SDDS_input.c:518
int32_t SDDS_GetLZMANamelist(SDDS_DATASET *SDDS_dataset, char *buffer, int32_t buflen, struct lzmafile *lzmafp)
Reads a namelist from an LZMA-compressed file into a buffer.
Definition SDDS_input.c:345
int32_t SDDS_ProcessArrayDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the array definition section of the SDDS dataset.
int32_t SDDS_ProcessParameterDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the parameter definition section of the SDDS dataset.
int32_t SDDS_ProcessAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the associate definition section of the SDDS dataset.
FILE * SDDS_ProcessIncludeCommand(SDDS_DATASET *SDDS_dataset, char *s)
Process the include command within the SDDS dataset.
int32_t SDDS_ProcessDataMode(SDDS_DATASET *SDDS_dataset, char *s)
Process the data mode section of the SDDS dataset.
uint32_t SDDS_GetSpecialCommentsModes(SDDS_DATASET *SDDS_dataset)
Retrieves the current special comments modes set in the SDDS dataset.
int32_t SDDS_ProcessDescription(SDDS_DATASET *SDDS_dataset, char *s)
Process the description section of the SDDS dataset.
void SDDS_ResetSpecialCommentsModes(SDDS_DATASET *SDDS_dataset)
Resets the special comments modes in the SDDS dataset.
int32_t SDDS_ProcessColumnDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the column definition section of the SDDS dataset.
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.
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.

◆ SDDS_LZMAWriteArrayDefinition()

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

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_LZMAWriteAsciiArrays()

int32_t SDDS_LZMAWriteAsciiArrays ( SDDS_DATASET * SDDS_dataset,
struct lzmafile * lzmafp )
extern

Writes the arrays of an SDDS dataset in ASCII format to an LZMA compressed file.

This function writes all arrays contained in the provided SDDS dataset to the specified LZMA compressed file in ASCII format. For each array, it writes the dimensions, a description line, and the array elements formatted according to their data type.

Parameters
SDDS_datasetPointer to the SDDS dataset containing the arrays to be written.
lzmafpPointer to the LZMA file stream where the array data will be written.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
The function checks the dataset for consistency before writing. It uses SDDS_LZMAWriteTypedValue() to write each array element according to its data type. Each array element is written, with up to 6 elements per line.

Definition at line 680 of file SDDS_ascii.c.

680 {
681 int32_t i, j;
682 SDDS_LAYOUT *layout;
683 /* char *predefined_format; */
684 ARRAY_DEFINITION *array_definition;
685 SDDS_ARRAY *array;
686
687 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_LZMAWriteAsciiArrays"))
688 return (0);
689 layout = &SDDS_dataset->layout;
690 for (j = 0; j < layout->n_arrays; j++) {
691 array_definition = layout->array_definition + j;
692 array = &SDDS_dataset->array[j];
693 for (i = 0; i < array_definition->dimensions; i++)
694 lzma_printf(lzmafp, "%" PRId32 " ", array->dimension[i]);
695 lzma_printf(lzmafp, " ! %" PRId32 "-dimensional array %s:\n", array_definition->dimensions, array_definition->name);
696 for (i = 0; i < array->elements;) {
697 if (!SDDS_LZMAWriteTypedValue(array->data, i, array_definition->type, NULL, lzmafp)) {
698 SDDS_SetError("Unable to write array--couldn't write ASCII data (SDDS_LZMAWriteAsciiArrays)");
699 return (0);
700 }
701 i++;
702 if (i % 6 == 0 || i == array->elements)
703 lzma_putc('\n', lzmafp);
704 else
705 lzma_putc(' ', lzmafp);
706 }
707 }
708 return (1);
709}
int32_t SDDS_LZMAWriteTypedValue(void *data, int64_t index, int32_t type, char *format, struct lzmafile *lzmafp)
Writes a typed value to an LZMA compressed ASCII file stream.
Definition SDDS_ascii.c:180

◆ SDDS_LZMAWriteAsciiParameters()

int32_t SDDS_LZMAWriteAsciiParameters ( SDDS_DATASET * SDDS_dataset,
struct lzmafile * lzmafp )
extern

Writes the parameter data of an SDDS dataset in ASCII format to an LZMA compressed file.

This function writes all parameters of the provided SDDS dataset to the specified LZMA compressed file in ASCII format. Only parameters that do not have fixed values are written. Each parameter value is written on a new line.

Parameters
SDDS_datasetPointer to the SDDS dataset containing the parameter data.
lzmafpPointer to the LZMA file stream where the ASCII data will be written.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
The function checks the dataset for consistency before writing. It uses SDDS_LZMAWriteTypedValue() to write each parameter value according to its data type.

Definition at line 565 of file SDDS_ascii.c.

565 {
566 int32_t i;
567 SDDS_LAYOUT *layout;
568 /* char *predefined_format; */
569
570 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_LZMAWriteAsciiParameters"))
571 return (0);
572 layout = &SDDS_dataset->layout;
573 for (i = 0; i < layout->n_parameters; i++) {
574 if (layout->parameter_definition[i].fixed_value)
575 continue;
576 if (!SDDS_LZMAWriteTypedValue(SDDS_dataset->parameter[i], 0, layout->parameter_definition[i].type, NULL, lzmafp)) {
577 SDDS_SetError("Unable to write ascii parameters (SDDS_LZMAWriteAsciiParameters)");
578 return 0;
579 }
580 lzma_putc('\n', lzmafp);
581 }
582 return (1);
583}

◆ SDDS_LZMAWriteAsciiRow()

int32_t SDDS_LZMAWriteAsciiRow ( SDDS_DATASET * SDDS_dataset,
int64_t row,
struct lzmafile * lzmafp )
extern

Writes a single row of data in ASCII format to an LZMA compressed file.

This function writes the specified row from the SDDS dataset to the provided LZMA compressed file in ASCII format. The data is formatted according to the data types of the columns. Supports multi-line rows as specified by the data mode settings in the dataset layout.

Parameters
SDDS_datasetPointer to the SDDS dataset containing the data.
rowZero-based index of the row to write.
lzmafpPointer to the LZMA file stream where the row data will be written.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
The function checks the dataset for consistency before writing. It uses SDDS_LZMAWriteTypedValue() to write each column value according to its data type. The number of values per line is determined by the lines_per_row setting in the dataset layout.

Definition at line 826 of file SDDS_ascii.c.

826 {
827 int32_t newline_needed;
828 int64_t i, n_per_line, line;
829 /* int32_t embedded_quotes_present; */
830 SDDS_LAYOUT *layout;
831 /* char *predefined_format, *s; */
832
833 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_LZMAWriteAsciiRow"))
834 return (0);
835 layout = &SDDS_dataset->layout;
836 if (SDDS_dataset->layout.data_mode.lines_per_row <= 0)
837 SDDS_dataset->layout.data_mode.lines_per_row = 1;
838 n_per_line = SDDS_dataset->layout.n_columns / SDDS_dataset->layout.data_mode.lines_per_row;
839 line = 1;
840 newline_needed = 0;
841 for (i = 0; i < layout->n_columns; i++) {
842 if (!SDDS_LZMAWriteTypedValue(SDDS_dataset->data[i], row, layout->column_definition[i].type, NULL, lzmafp)) {
843 SDDS_SetError("Unable to write ascii row (SDDS_LZMAWriteAsciiRow)");
844 return 0;
845 }
846 if ((i + 1) % n_per_line == 0 && line != SDDS_dataset->layout.data_mode.lines_per_row) {
847 newline_needed = 0;
848 lzma_putc('\n', lzmafp);
849 line++;
850 } else {
851 lzma_putc(' ', lzmafp);
852 newline_needed = 1;
853 }
854 }
855 if (newline_needed)
856 lzma_putc('\n', lzmafp);
857 return (1);
858}

◆ SDDS_LZMAWriteAssociateDefinition()

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

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_LZMAWriteBinaryString()

int32_t SDDS_LZMAWriteBinaryString ( char * string,
struct lzmafile * lzmafp,
SDDS_FILEBUFFER * fBuffer )

Writes a binary string to a file with LZMA compression.

This function writes a binary string to the specified LZMA-compressed file by first writing the length of the string followed by the string's content. If the input string is NULL, an empty string is written instead. The writing operation utilizes LZMA buffered write functions to ensure data is compressed appropriately.

Parameters
[in]stringThe null-terminated string to be written. If NULL, an empty string is written.
[in]lzmafpThe LZMA file pointer to write to. Must be a valid, open LZMA-compressed file in write mode.
[in,out]fBufferPointer to the file buffer used for buffered writing operations.
Returns
int32_t Returns 1 on success, 0 on failure.
Return values
1Operation was successful.
0An error occurred during writing.

Definition at line 2674 of file SDDS_binary.c.

2674 {
2675 int32_t length;
2676 static const char dummy_string[] = "";
2677 if (!string)
2678 string = (char *)dummy_string;
2679 length = strlen(string);
2680 if (!SDDS_LZMABufferedWrite(&length, sizeof(length), lzmafp, fBuffer)) {
2681 SDDS_SetError("Unable to write string--error writing length");
2682 return (0);
2683 }
2684 if (length && !SDDS_LZMABufferedWrite(string, sizeof(*string) * length, lzmafp, fBuffer)) {
2685 SDDS_SetError("Unable to write string--error writing contents");
2686 return (0);
2687 }
2688 return (1);
2689}
int32_t SDDS_LZMABufferedWrite(void *target, int64_t targetSize, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)

◆ SDDS_LZMAWriteColumnDefinition()

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

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 )
extern

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 )
extern

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_LZMAWriteNonNativeBinaryString()

int32_t SDDS_LZMAWriteNonNativeBinaryString ( char * string,
struct lzmafile * lzmafp,
SDDS_FILEBUFFER * fBuffer )

Writes a non-native endian binary string to an LZMA-compressed file.

This function writes a binary string to the specified LZMA-compressed file pointer, handling non-native endianness. It first writes the length of the string as a 32-bit integer with byte order swapped. If the string is not to be skipped, it then writes the string data itself followed by a null terminator. If the input string is NULL, an empty string is written instead.

Parameters
[in]stringThe string to write. If NULL, an empty string is written.
[in]lzmafpPointer to the LZMAFILE where the string will be written.
[in]fBufferPointer to the SDDS_FILEBUFFER structure used for buffered writing.
Returns
int32_t Returns 1 on successful writing of the string, or 0 if an error occurred.
Return values
1The string was successfully written and byte-swapped.
0An error occurred during the write operation, such as I/O failures or memory allocation issues.
Note
The caller is responsible for ensuring that the LZMAFILE pointer lzmafp is valid and open for writing. This function does not perform memory allocation for the string; it assumes that the string is already allocated and managed appropriately.

Definition at line 5763 of file SDDS_binary.c.

5763 {
5764 int32_t length;
5765 static const char dummy_string[] = "";
5766 if (!string)
5767 string = (char *)dummy_string;
5768 length = strlen(string);
5769 SDDS_SwapLong(&length);
5770 if (!SDDS_LZMABufferedWrite(&length, sizeof(length), lzmafp, fBuffer)) {
5771 SDDS_SetError("Unable to write string--error writing length");
5772 return (0);
5773 }
5774 SDDS_SwapLong(&length);
5775 if (length && !SDDS_LZMABufferedWrite(string, sizeof(*string) * length, lzmafp, fBuffer)) {
5776 SDDS_SetError("Unable to write string--error writing contents");
5777 return (0);
5778 }
5779 return (1);
5780}
void SDDS_SwapLong(int32_t *data)
Swaps the endianness of a 32-bit integer.

◆ SDDS_LZMAWriteParameterDefinition()

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

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 )
extern

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_ParseSpecialComments()

void SDDS_ParseSpecialComments ( SDDS_DATASET * SDDS_dataset,
char * s )

Parses and processes special comment commands within the SDDS dataset.

This function interprets special commands embedded within comment strings of the SDDS dataset. Supported special commands include:

  • big-endian
  • little-endian
  • fixed-rowcount

Each recognized command updates the commentFlags field within the dataset's layout to reflect the presence of these special configurations.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset. The commentFlags field will be updated based on the parsed commands.
[in]sPointer to the null-terminated string containing special comment commands to be parsed.
Note
  • This function is intended to be used internally by the SDDS library to handle special configurations specified in comments.
  • Only the predefined special commands are recognized and processed.
Warning
  • Unrecognized commands within the comment string are ignored.
  • Ensure that the input string s is properly formatted and null-terminated to prevent undefined behavior.
See also
SDDS_GetSpecialCommentsModes, SDDS_ResetSpecialCommentsModes

Definition at line 5342 of file SDDS_utils.c.

5342 {
5343 char buffer[SDDS_MAXLINE];
5344 int32_t i;
5345 if (SDDS_dataset == NULL)
5346 return;
5347 while (SDDS_GetToken(s, buffer, SDDS_MAXLINE) > 0) {
5348 for (i = 0; i < COMMENT_COMMANDS; i++) {
5349 if (strcmp(buffer, commentCommandName[i]) == 0) {
5350 SDDS_dataset->layout.commentFlags |= commentCommandFlag[i];
5351 break;
5352 }
5353 }
5354 }
5355}
int32_t SDDS_GetToken(char *s, char *buffer, int32_t buflen)
Extracts the next token from a string, handling quoted substrings and escape characters.

◆ SDDS_ProcessArrayDefinition()

int32_t SDDS_ProcessArrayDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the array definition section of the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the array definition string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 243 of file SDDS_process.c.

243 {
244 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessArrayDefinition"))
245 return (0);
246 if (!s) {
247 SDDS_SetError("Unable to process array definition--namelist text pointer NULL (SDDS_ProcessArrayDefinition)");
248 return (0);
249 }
250 switch (SDDS_dataset->layout.version) {
251 case 1:
252 return (SDDS1_ProcessArrayDefinition(SDDS_dataset, s));
253 case 2:
254 return (SDDS1_ProcessArrayDefinition(SDDS_dataset, s));
255 case 3:
256 return (SDDS1_ProcessArrayDefinition(SDDS_dataset, s));
257 case 4:
258 return (SDDS1_ProcessArrayDefinition(SDDS_dataset, s));
259 case 5:
260 return (SDDS1_ProcessArrayDefinition(SDDS_dataset, s));
261 default:
262 SDDS_SetError("Unable to process array definition--protocol version number is invalid (SDDS_ProcessArrayDefinition)");
263 return (0);
264 }
265}
int32_t SDDS1_ProcessArrayDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines an array within an SDDS dataset.

◆ SDDS_ProcessAssociateDefinition()

int32_t SDDS_ProcessAssociateDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the associate definition section of the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the associate definition string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 181 of file SDDS_process.c.

181 {
182 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessAssociateDefinition"))
183 return (0);
184 if (!s) {
185 SDDS_SetError("Unable to process associate definition--namelist text pointer NULL (SDDS_ProcessAssociateDefinition)");
186 return (0);
187 }
188 switch (SDDS_dataset->layout.version) {
189 case 1:
190 return (SDDS1_ProcessAssociateDefinition(SDDS_dataset, s));
191 case 2:
192 return (SDDS1_ProcessAssociateDefinition(SDDS_dataset, s));
193 case 3:
194 return (SDDS1_ProcessAssociateDefinition(SDDS_dataset, s));
195 case 4:
196 return (SDDS1_ProcessAssociateDefinition(SDDS_dataset, s));
197 case 5:
198 return (SDDS1_ProcessAssociateDefinition(SDDS_dataset, s));
199 default:
200 SDDS_SetError("Unable to process associate definition--protocol version number is invalid (SDDS_ProcessAssociateDefinition)");
201 return (0);
202 }
203}
int32_t SDDS1_ProcessAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines an associate within an SDDS dataset.

◆ SDDS_ProcessColumnDefinition()

int32_t SDDS_ProcessColumnDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the column definition section of the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the column definition string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 88 of file SDDS_process.c.

88 {
89 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS1_ProcessColumnDefinition"))
90 return (0);
91 if (!s) {
92 SDDS_SetError("Unable to process column definition--namelist text pointer NULL (SDDS1_ProcessColumnDefinition)");
93 return (0);
94 }
95 switch (SDDS_dataset->layout.version) {
96 case 1:
97 return (SDDS1_ProcessColumnDefinition(SDDS_dataset, s));
98 case 2:
99 return (SDDS1_ProcessColumnDefinition(SDDS_dataset, s));
100 case 3:
101 return (SDDS1_ProcessColumnDefinition(SDDS_dataset, s));
102 case 4:
103 return (SDDS1_ProcessColumnDefinition(SDDS_dataset, s));
104 case 5:
105 return (SDDS1_ProcessColumnDefinition(SDDS_dataset, s));
106 default:
107 SDDS_SetError("Unable to process column definition--protocol version number is invalid (SDDS_ProcessColumnDefinition)");
108 return (0);
109 }
110}
int32_t SDDS1_ProcessColumnDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines a column within an SDDS dataset.

◆ SDDS_ProcessDataMode()

int32_t SDDS_ProcessDataMode ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the data mode section of the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the data mode string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 212 of file SDDS_process.c.

212 {
213 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessDataMode"))
214 return (0);
215 if (!s) {
216 SDDS_SetError("Unable to process data mode--namelist text pointer is NULL (SDDS_ProcessDataMode)");
217 return (0);
218 }
219 switch (SDDS_dataset->layout.version) {
220 case 1:
221 return (SDDS1_ProcessDataMode(SDDS_dataset, s));
222 case 2:
223 return (SDDS1_ProcessDataMode(SDDS_dataset, s));
224 case 3:
225 return (SDDS1_ProcessDataMode(SDDS_dataset, s));
226 case 4:
227 return (SDDS1_ProcessDataMode(SDDS_dataset, s));
228 case 5:
229 return (SDDS1_ProcessDataMode(SDDS_dataset, s));
230 default:
231 SDDS_SetError("Unable to process data mode--protocol version number is invalid (SDDS_ProcessDataMode)");
232 return (0);
233 }
234}
int32_t SDDS1_ProcessDataMode(SDDS_DATASET *SDDS_dataset, char *s)
Processes and sets the data mode for an SDDS dataset.

◆ SDDS_ProcessDescription()

int32_t SDDS_ProcessDescription ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the description section of the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the description string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 57 of file SDDS_process.c.

57 {
58 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessDescription"))
59 return (0);
60 if (!s) {
61 SDDS_SetError("Unable to process description--namelist text pointer is NULL (SDDS_ProcessDescription)");
62 return (0);
63 }
64 switch (SDDS_dataset->layout.version) {
65 case 1:
66 return (SDDS1_ProcessDescription(SDDS_dataset, s));
67 case 2:
68 return (SDDS1_ProcessDescription(SDDS_dataset, s));
69 case 3:
70 return (SDDS1_ProcessDescription(SDDS_dataset, s));
71 case 4:
72 return (SDDS1_ProcessDescription(SDDS_dataset, s));
73 case 5:
74 return (SDDS1_ProcessDescription(SDDS_dataset, s));
75 default:
76 SDDS_SetError("Unable to process description--protocol version number is invalid (SDDS_ProcessDescription)");
77 return (0);
78 }
79}
int32_t SDDS1_ProcessDescription(SDDS_DATASET *SDDS_dataset, char *s)
Process the description section for SDDS protocol version 1.

◆ SDDS_ProcessIncludeCommand()

FILE * SDDS_ProcessIncludeCommand ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the include command within the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the include command string.
Returns
Returns a FILE pointer on success, NULL on failure.

Definition at line 150 of file SDDS_process.c.

150 {
151 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessIncludeCommand"))
152 return (NULL);
153 if (!s) {
154 SDDS_SetError("Unable to process parameter definition--namelist text pointer NULL (SDDS_ProcessIncludeCommand)");
155 return (NULL);
156 }
157 switch (SDDS_dataset->layout.version) {
158 case 1:
159 return (SDDS1_ProcessIncludeCommand(SDDS_dataset, s));
160 case 2:
161 return (SDDS1_ProcessIncludeCommand(SDDS_dataset, s));
162 case 3:
163 return (SDDS1_ProcessIncludeCommand(SDDS_dataset, s));
164 case 4:
165 return (SDDS1_ProcessIncludeCommand(SDDS_dataset, s));
166 case 5:
167 return (SDDS1_ProcessIncludeCommand(SDDS_dataset, s));
168 default:
169 SDDS_SetError("Unable to process parameter definition--protocol version number is invalid (SDDS_ProcessIncludeCommand)");
170 return (0);
171 }
172}
FILE * SDDS1_ProcessIncludeCommand(SDDS_DATASET *SDDS_dataset, char *s)
Processes an include command by opening the specified file.

◆ SDDS_ProcessParameterDefinition()

int32_t SDDS_ProcessParameterDefinition ( SDDS_DATASET * SDDS_dataset,
char * s )
extern

Process the parameter definition section of the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
sPointer to the parameter definition string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 119 of file SDDS_process.c.

119 {
120 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessParameterDefinition"))
121 return (0);
122 if (!s) {
123 SDDS_SetError("Unable to process parameter definition--namelist text pointer NULL (SDDS_ProcessParameterDefinition)");
124 return (0);
125 }
126 switch (SDDS_dataset->layout.version) {
127 case 1:
128 return (SDDS1_ProcessParameterDefinition(SDDS_dataset, s));
129 case 2:
130 return (SDDS1_ProcessParameterDefinition(SDDS_dataset, s));
131 case 3:
132 return (SDDS1_ProcessParameterDefinition(SDDS_dataset, s));
133 case 4:
134 return (SDDS1_ProcessParameterDefinition(SDDS_dataset, s));
135 case 5:
136 return (SDDS1_ProcessParameterDefinition(SDDS_dataset, s));
137 default:
138 SDDS_SetError("Unable to process parameter definition--protocol version number is invalid (SDDS_ProcessParameterDefinition)");
139 return (0);
140 }
141}
int32_t SDDS1_ProcessParameterDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines a parameter within an SDDS dataset.

◆ SDDS_ReadAsciiArrays()

int32_t SDDS_ReadAsciiArrays ( SDDS_DATASET * SDDS_dataset)
extern

Reads the arrays from an ASCII file into the SDDS dataset.

This function reads array data from an ASCII file and stores it in the provided SDDS dataset. It supports reading from regular files, as well as GZIP and LZMA compressed files if enabled.

Parameters
SDDS_datasetPointer to the SDDS dataset where the arrays will be stored.
Returns
Returns 1 on success, 0 on error, or -1 if end-of-file is reached before any arrays are read.
Note
The function checks the dataset for consistency before reading. It reads array dimensions and elements, handling multi-dimensional arrays appropriately. The array elements are scanned and stored according to their data types.

Definition at line 1047 of file SDDS_ascii.c.

1047 {
1048 int32_t i, j, length;
1049 SDDS_LAYOUT *layout;
1050 char *buffer = NULL;
1051 int32_t bufferSize = 0;
1052 char *bigBuffer = NULL;
1053 int32_t bigBufferSize = 0;
1054 char *bigBufferCopy;
1055 int32_t bigBufferCopySize;
1056 /* ARRAY_DEFINITION *array_definition; */
1057 SDDS_ARRAY *array;
1058#if defined(zLib)
1059 gzFile gzfp = NULL;
1060#endif
1061 FILE *fp = NULL;
1062 struct lzmafile *lzmafp = NULL;
1063
1064 layout = &SDDS_dataset->layout;
1065#if defined(zLib)
1066 if (SDDS_dataset->layout.gzipFile) {
1067 gzfp = layout->gzfp;
1068 } else {
1069#endif
1070 if (SDDS_dataset->layout.lzmaFile) {
1071 lzmafp = layout->lzmafp;
1072 } else {
1073 fp = layout->fp;
1074 }
1075#if defined(zLib)
1076 }
1077#endif
1078 if (layout->n_arrays > 0) {
1079 if (!(bigBuffer = SDDS_Malloc(sizeof(*bigBuffer) * (bigBufferSize = INITIAL_BIG_BUFFER_SIZE)))) {
1080 SDDS_SetError("Unable to read parameters--buffer allocation failure (SDDS_ReadAsciiArrays)");
1081 return (0);
1082 }
1083 }
1084 for (i = 0; i < layout->n_arrays; i++) {
1085#if defined(zLib)
1086 if (SDDS_dataset->layout.gzipFile) {
1087 if (!fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp, '!') || SDDS_StringIsBlank(bigBuffer)) {
1088 if (i == 0)
1089 return (-1);
1090 SDDS_SetError("Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1091 return (0);
1092 }
1093 } else {
1094#endif
1095 if (SDDS_dataset->layout.lzmaFile) {
1096 if (!fgetsLZMASkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, lzmafp, '!') || SDDS_StringIsBlank(bigBuffer)) {
1097 if (i == 0)
1098 return (-1);
1099 SDDS_SetError("Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1100 return (0);
1101 }
1102 } else {
1103 if (!fgetsSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, fp, '!') || SDDS_StringIsBlank(bigBuffer)) {
1104 if (i == 0)
1105 return (-1);
1106 SDDS_SetError("Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1107 return (0);
1108 }
1109 }
1110#if defined(zLib)
1111 }
1112#endif
1113 if (!(array = SDDS_dataset->array + i)) {
1114 SDDS_SetError("Unable to read array--pointer to structure storage area is NULL (SDDS_ReadAsciiArrays)");
1115 return (0);
1116 }
1117 if (array->definition && !SDDS_FreeArrayDefinition(array->definition)) {
1118 SDDS_SetError("Unable to get array--array definition corrupted (SDDS_ReadAsciiArrays)");
1119 return (0);
1120 }
1121 if (!SDDS_CopyArrayDefinition(&array->definition, layout->array_definition + i)) {
1122 SDDS_SetError("Unable to read array--definition copy failed (SDDS_ReadAsciiArrays)");
1123 return (0);
1124 }
1125 /*if (array->dimension) free(array->dimension); */
1126 if (!(array->dimension = SDDS_Realloc(array->dimension, sizeof(*array->dimension) * array->definition->dimensions))) {
1127 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadAsciiArrays)");
1128 return (0);
1129 }
1130 array->elements = 1;
1131 if ((length = strlen(bigBuffer)) >= bufferSize) {
1132 if (!(buffer = SDDS_Realloc(buffer, sizeof(*buffer) * (bufferSize = 2 * length)))) {
1133 SDDS_SetError("Unable to scan data--allocation failure (SDDS_ReadAsciiArrays");
1134 return (0);
1135 }
1136 }
1137 for (j = 0; j < array->definition->dimensions; j++) {
1138 if (SDDS_GetToken(bigBuffer, buffer, SDDS_MAXLINE) <= 0 || sscanf(buffer, "%" SCNd32, array->dimension + j) != 1 || array->dimension[j] < 0) {
1139 SDDS_SetError("Unable to read array--dimensions missing or negative (SDDS_ReadAsciiArrays)");
1140 return (0);
1141 }
1142 array->elements *= array->dimension[j];
1143 }
1144 if (!array->elements)
1145 continue;
1146 if (array->data)
1147 free(array->data);
1148 array->data = array->pointer = NULL;
1149 if (!(array->data = SDDS_Realloc(array->data, array->elements * SDDS_type_size[array->definition->type - 1]))) {
1150 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadAsciiArrays)");
1151 return (0);
1152 }
1153 SDDS_ZeroMemory(array->data, array->elements * SDDS_type_size[array->definition->type - 1]);
1154 j = 0;
1155 bigBuffer[0] = 0;
1156 do {
1157 if (SDDS_StringIsBlank(bigBuffer)) {
1158 bigBuffer[0] = 0;
1159#if defined(zLib)
1160 if (SDDS_dataset->layout.gzipFile) {
1161 if (!fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp, '!') || SDDS_StringIsBlank(bigBuffer)) {
1162 SDDS_SetError("Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1163 return (0);
1164 }
1165 } else {
1166#endif
1167 if (SDDS_dataset->layout.lzmaFile) {
1168 if (!fgetsLZMASkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, lzmafp, '!') || SDDS_StringIsBlank(bigBuffer)) {
1169 SDDS_SetError("Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1170 return (0);
1171 }
1172 } else {
1173 if (!fgetsSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, fp, '!') || SDDS_StringIsBlank(bigBuffer)) {
1174 SDDS_SetError("Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1175 return (0);
1176 }
1177 }
1178#if defined(zLib)
1179 }
1180#endif
1181 }
1182 /* copy the bigBuffer because SDDS_ScanData2 will change the bigBufferCopy pointer that SDDS_ScanData
1183 cannot do becuase bigBuffer is a static variable. This change was implemented to greatly improve
1184 the speed of reading a very large line of array elements. The previous version just did a lot of
1185 strcpy commands to these huge lines which was really slow. */
1186 bigBufferCopy = bigBuffer;
1187 bigBufferCopySize = strlen(bigBufferCopy);
1188 do {
1189 if (!SDDS_ScanData2(bigBufferCopy, &bigBufferCopy, &bigBufferCopySize, array->definition->type, array->definition->field_length, array->data, j, 0)) {
1190 SDDS_SetError("Unable to read array--error scanning data element (SDDS_ReadAsciiArrays)");
1191 return (0);
1192 }
1193 } while (++j < array->elements && !SDDS_StringIsBlank(bigBufferCopy));
1194 bigBuffer[0] = 0;
1195 } while (j < array->elements);
1196 }
1197 if (buffer)
1198 free(buffer);
1199 if (bigBuffer)
1200 free(bigBuffer);
1201 return (1);
1202}
int32_t SDDS_ScanData2(char *string, char **pstring, int32_t *strlength, int32_t type, int32_t field_length, void *data, int64_t index, int32_t is_parameter)
Scans a string and saves the parsed value into a data pointer, optimized for long strings.
char * fgetsLZMASkipCommentsResize(SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, struct lzmafile *lzmafp, char skip_char)
Reads a line from a LZMA-compressed file with dynamic buffer resizing while skipping comment lines.
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
ARRAY_DEFINITION * SDDS_CopyArrayDefinition(ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
Creates a copy of an array definition.
char * fgetsSkipCommentsResize(SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, FILE *fp, char skip_char)
Reads a line from a file with dynamic buffer resizing while skipping comment lines.

◆ SDDS_ReadAsciiPageDetailed()

int32_t SDDS_ReadAsciiPageDetailed ( SDDS_DATASET * SDDS_dataset,
int64_t sparse_interval,
int64_t sparse_offset,
int64_t last_rows,
int32_t sparse_statistics )
extern

Reads a detailed page of data from an ASCII file into an SDDS dataset with optional sparsity and statistics.

This function reads a page of data from an ASCII SDDS file into the provided dataset, supporting various options for data sparsity and statistical processing. It allows specifying a sparse interval and offset to read every nth row starting from a specific offset, as well as reading only the last specified number of rows. Additionally, it can compute statistical measures over the sparse data, such as average, median, minimum, or maximum.

Parameters
SDDS_datasetPointer to the SDDS dataset where the data will be stored.
sparse_intervalInterval for sparsity; reads every nth row if greater than 1. Use 1 to read every row.
sparse_offsetOffset from the first row to start reading. Rows before this offset are skipped.
last_rowsNumber of last rows to read. If greater than 0, only the last last_rows rows are read, overriding sparse_interval and sparse_offset. Use 0 to read all rows according to sparse_interval and sparse_offset.
sparse_statisticsStatistical operation to perform over the sparse data:
  • 0: None (no statistical operation)
  • 1: Average
  • 2: Median
  • 3: Minimum
  • 4: Maximum
Returns
Returns the page number on success, -1 if end-of-file is reached before any data is read, 0 on error.
Note
This function handles reading from regular files, as well as GZIP and LZMA compressed files if enabled. It updates the internal state of the dataset, including the page number and number of rows read. If last_rows is specified and greater than 0, it overrides sparse_interval and sparse_offset. In case of errors during reading, the function attempts to recover if autoRecover is enabled in the dataset.

Definition at line 1273 of file SDDS_ascii.c.

1273 {
1274 SDDS_LAYOUT *layout;
1275 int32_t no_row_counts, end_of_data, retval, lineCount;
1276 int64_t n_rows, i, j, k, rows_to_store;
1277 /* int32_t page_number; */
1278 char s[SDDS_MAXLINE];
1279 char *dataRead, *bigBufferCopy;
1280 int32_t bigBufferCopySize;
1281 char *bigBuffer = NULL;
1282 int32_t bigBufferSize = 0;
1283 /* char *ptr; */
1284#if defined(zLib)
1285 gzFile gzfp = NULL;
1286#endif
1287 FILE *fp = NULL;
1288 void **statData=NULL;
1289 double statResult;
1290 struct lzmafile *lzmafp = NULL;
1291 /* double value; */
1292
1293 if (SDDS_dataset->autoRecovered)
1294 return -1;
1295
1296 SDDS_SetReadRecoveryMode(SDDS_dataset, 0);
1297
1298#if defined(zLib)
1299 if (SDDS_dataset->layout.gzipFile) {
1300 gzfp = SDDS_dataset->layout.gzfp;
1301 } else {
1302#endif
1303 if (SDDS_dataset->layout.lzmaFile) {
1304 lzmafp = SDDS_dataset->layout.lzmafp;
1305 } else {
1306 fp = SDDS_dataset->layout.fp;
1307 }
1308#if defined(zLib)
1309 }
1310#endif
1311 if (SDDS_dataset->page_number == -1)
1312 /* end of file already hit */
1313 return -1;
1314#if defined(zLib)
1315 if (SDDS_dataset->layout.gzipFile) {
1316 if (gzeof(gzfp) && SDDS_dataset->page_number > 0)
1317 /* end of file and not first page about to be read */
1318 return SDDS_dataset->page_number = -1;
1319 } else {
1320#endif
1321 if (SDDS_dataset->layout.lzmaFile) {
1322 if (lzma_eof(lzmafp) && SDDS_dataset->page_number > 0)
1323 /* end of file and not first page about to be read */
1324 return SDDS_dataset->page_number = -1;
1325 } else {
1326 if (feof(fp) && SDDS_dataset->page_number > 0)
1327 /* end of file and not first page about to be read */
1328 return SDDS_dataset->page_number = -1;
1329 }
1330#if defined(zLib)
1331 }
1332#endif
1333 if (!SDDS_AsciiDataExpected(SDDS_dataset) && SDDS_dataset->page_number != 0)
1334 /* if no columns or arrays and only fixed value parameters, then only one "page" allowed */
1335 return (SDDS_dataset->page_number = -1);
1336
1337#if defined(zLib)
1338 if (SDDS_dataset->layout.gzipFile) {
1339 if (SDDS_dataset->page_number == 0)
1340 for (i = 0; i < SDDS_dataset->layout.data_mode.additional_header_lines; i++) {
1341 if (!fgetsGZipSkipComments(SDDS_dataset, s, SDDS_MAXLINE, gzfp, '!'))
1342 return (SDDS_dataset->page_number = -1); /* indicates end of data */
1343 }
1344 } else {
1345#endif
1346 if (SDDS_dataset->layout.lzmaFile) {
1347 if (SDDS_dataset->page_number == 0)
1348 for (i = 0; i < SDDS_dataset->layout.data_mode.additional_header_lines; i++) {
1349 if (!fgetsLZMASkipComments(SDDS_dataset, s, SDDS_MAXLINE, lzmafp, '!'))
1350 return (SDDS_dataset->page_number = -1); /* indicates end of data */
1351 }
1352 } else {
1353 if (SDDS_dataset->page_number == 0)
1354 for (i = 0; i < SDDS_dataset->layout.data_mode.additional_header_lines; i++) {
1355 if (!fgetsSkipComments(SDDS_dataset, s, SDDS_MAXLINE, fp, '!'))
1356 return (SDDS_dataset->page_number = -1); /* indicates end of data */
1357 }
1358 }
1359#if defined(zLib)
1360 }
1361#endif
1362
1363 /* the next call increments the page number */
1364 if (!SDDS_StartPage(SDDS_dataset, 0)) {
1365 SDDS_SetError("Unable to read page--couldn't start page (SDDS_ReadAsciiPage)");
1366 return (0);
1367 }
1368
1369 layout = &SDDS_dataset->layout;
1370
1371 if ((retval = SDDS_ReadAsciiParameters(SDDS_dataset)) < 1) {
1372 if (retval)
1373 return (SDDS_dataset->page_number = retval);
1374 SDDS_SetError("Unable to read page--couldn't read parameters (SDDS_ReadAsciiPage)");
1375 return (0);
1376 }
1377 if ((retval = SDDS_ReadAsciiArrays(SDDS_dataset)) < 1) {
1378 if (retval)
1379 return (SDDS_dataset->page_number = retval);
1380 SDDS_SetError("Unable to read page--couldn't read arrays (SDDS_ReadAsciiPage)");
1381 return (0);
1382 }
1383
1384 if (last_rows < 0)
1385 last_rows = 0;
1386 if (sparse_interval <= 0)
1387 sparse_interval = 1;
1388 if (sparse_offset < 0)
1389 sparse_offset = 0;
1390
1391 SDDS_dataset->rowcount_offset = -1;
1392 if (layout->n_columns) {
1393 if (!(bigBuffer = SDDS_Malloc(sizeof(*bigBuffer) * (bigBufferSize = INITIAL_BIG_BUFFER_SIZE)))) {
1394 SDDS_SetError("Unable to read parameters--buffer allocation failure (SDDS_ReadAsciiPage)");
1395 return (0);
1396 }
1397
1398 n_rows = 0;
1399 no_row_counts = 0;
1400 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
1401 /* read the number of rows */
1402#if defined(zLib)
1403 if (SDDS_dataset->layout.gzipFile) {
1404 if (!fgetsGZipSkipComments(SDDS_dataset, s, SDDS_MAXLINE, gzfp, '!')) {
1405 if (bigBuffer)
1406 free(bigBuffer);
1407 return (SDDS_dataset->page_number = -1); /* indicates end of data */
1408 }
1409 } else {
1410#endif
1411 if (SDDS_dataset->layout.lzmaFile) {
1412 if (!fgetsLZMASkipComments(SDDS_dataset, s, SDDS_MAXLINE, lzmafp, '!')) {
1413 if (bigBuffer)
1414 free(bigBuffer);
1415 return (SDDS_dataset->page_number = -1); /* indicates end of data */
1416 }
1417 } else {
1418 do {
1419 SDDS_dataset->rowcount_offset = ftell(fp);
1420 if (!fgets(s, SDDS_MAXLINE, fp)) {
1421 if (bigBuffer)
1422 free(bigBuffer);
1423 return (SDDS_dataset->page_number = -1); /* indicates end of data */
1424 }
1425 } while (s[0] == '!');
1426 }
1427#if defined(zLib)
1428 }
1429#endif
1430 if (sscanf(s, "%" SCNd64, &n_rows) != 1 || n_rows < 0) {
1431 SDDS_SetError("Unable to read page--file has no (valid) number-of-rows entry (SDDS_ReadAsciiPage)");
1432 return (0);
1433 }
1434 if (n_rows > SDDS_GetRowLimit()) {
1435 /* number of rows is "unreasonably" large---treat like end-of-file */
1436 if (bigBuffer)
1437 free(bigBuffer);
1438 return (SDDS_dataset->page_number = -1);
1439 }
1440 if (last_rows) {
1441 sparse_interval = 1;
1442 sparse_offset = n_rows - last_rows;
1443 if (sparse_offset < 0)
1444 sparse_offset = 0;
1445 }
1446 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
1447 } else {
1448 // fix last_rows when no row count is available
1449 no_row_counts = 1;
1450 n_rows = TABLE_LENGTH_INCREMENT;
1451 rows_to_store = n_rows;
1452 }
1453
1454 if (rows_to_store >= SDDS_dataset->n_rows_allocated) {
1455 /* lengthen the page */
1456 if (!SDDS_LengthenTable(SDDS_dataset, rows_to_store - SDDS_dataset->n_rows_allocated)) {
1457 SDDS_SetError("Unable to read page--couldn't lengthen data page (SDDS_ReadAsciiPage)");
1458 return (0);
1459 }
1460 }
1461
1462 /* read the page values */
1463 j = end_of_data = k = 0;
1464 s[0] = 0;
1465 if (!no_row_counts && n_rows == 0) {
1466 SDDS_dataset->n_rows = 0;
1467 if (bigBuffer)
1468 free(bigBuffer);
1469 return (SDDS_dataset->page_number);
1470 }
1471 bigBuffer[0] = 0;
1472 bigBufferCopy = bigBuffer;
1473 do {
1474 if (j >= SDDS_dataset->n_rows_allocated) {
1475 /* lengthen the page */
1476 if (!SDDS_LengthenTable(SDDS_dataset, TABLE_LENGTH_INCREMENT)) {
1477 SDDS_SetError("Unable to read page--couldn't lengthen data page (SDDS_ReadAsciiPage)");
1478 return (0);
1479 }
1480 }
1481 lineCount = 0;
1482 dataRead = NULL;
1483 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
1484 if (k == 0) {
1485 if (sparse_statistics != 0) {
1486 // Allocate buffer space for statistical sparsing
1487 if (i == 0) {
1488 statData = (void**)malloc(SDDS_dataset->layout.n_columns * sizeof(void*));
1489 }
1490 if (SDDS_FLOATING_TYPE(layout->column_definition[i].type)) {
1491 // Not ideal for SDDS_LONGDOUBLE but we may never run across this error
1492 statData[i] = (double*)calloc(sparse_interval, sizeof(double));
1493 }
1494 }
1495 }
1496
1497 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
1498 continue;
1499 if (SDDS_StringIsBlank(bigBufferCopy)) {
1500 bigBuffer[0] = 0;
1501 bigBufferCopy = bigBuffer;
1502 dataRead = NULL;
1503#if defined(zLib)
1504 if (SDDS_dataset->layout.gzipFile) {
1505 if (!(dataRead = fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp, '!')) || SDDS_StringIsBlank(bigBuffer)) {
1506 SDDS_dataset->n_rows = j;
1507 if (no_row_counts) {
1508 /* legitmate end of data set */
1509 end_of_data = 1;
1510 break;
1511 }
1512 /* error, but may be recoverable */
1513 gzseek(gzfp, 0L, SEEK_END);
1514 if (SDDS_dataset->autoRecover) {
1515 SDDS_dataset->autoRecovered = 1;
1517 if (bigBuffer)
1518 free(bigBuffer);
1519 return (SDDS_dataset->page_number);
1520 }
1521 SDDS_SetError("Unable to read page (SDDS_ReadAsciiPage)");
1522 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
1523 return (0);
1524 }
1525 } else {
1526#endif
1527 if (SDDS_dataset->layout.lzmaFile) {
1528 if (!(dataRead = fgetsLZMASkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, lzmafp, '!')) || SDDS_StringIsBlank(bigBuffer)) {
1529 SDDS_dataset->n_rows = j;
1530 if (no_row_counts) {
1531 /* legitmate end of data set */
1532 end_of_data = 1;
1533 break;
1534 }
1535 /* error, but may be recoverable */
1536 lzma_seek(lzmafp, 0L, SEEK_END);
1537 if (SDDS_dataset->autoRecover) {
1538 SDDS_dataset->autoRecovered = 1;
1540 if (bigBuffer)
1541 free(bigBuffer);
1542 return (SDDS_dataset->page_number);
1543 }
1544 SDDS_SetError("Unable to read page (SDDS_ReadAsciiPage)");
1545 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
1546 return (0);
1547 }
1548 } else {
1549 if (!(dataRead = fgetsSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, fp, '!')) || SDDS_StringIsBlank(bigBuffer)) {
1550 SDDS_dataset->n_rows = j;
1551 if (no_row_counts) {
1552 /* legitmate end of data set */
1553 end_of_data = 1;
1554 break;
1555 }
1556 /* error, but may be recoverable */
1557 fseek(fp, 0L, SEEK_END);
1558 if (SDDS_dataset->autoRecover) {
1559 SDDS_dataset->autoRecovered = 1;
1561 if (bigBuffer)
1562 free(bigBuffer);
1563 return (SDDS_dataset->page_number);
1564 }
1565 SDDS_SetError("Unable to read page (SDDS_ReadAsciiPage)");
1566 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
1567 return (0);
1568 }
1569 }
1570#if defined(zLib)
1571 }
1572#endif
1573 lineCount++;
1574 bigBufferCopy = bigBuffer;
1575 bigBufferCopySize = strlen(bigBufferCopy);
1576 }
1577 if (!SDDS_ScanData2(bigBufferCopy, &bigBufferCopy, &bigBufferCopySize, layout->column_definition[i].type, layout->column_definition[i].field_length, SDDS_dataset->data[i], j, 0)) {
1578 /* error, but may be recoverable */
1579 SDDS_dataset->n_rows = j;
1580#if defined(zLib)
1581 if (SDDS_dataset->layout.gzipFile) {
1582 gzseek(gzfp, 0L, SEEK_END);
1583 } else {
1584#endif
1585 if (SDDS_dataset->layout.lzmaFile) {
1586 lzma_seek(lzmafp, 0L, SEEK_END);
1587 } else {
1588 fseek(fp, 0L, SEEK_END);
1589 }
1590#if defined(zLib)
1591 }
1592#endif
1593 if (SDDS_dataset->autoRecover) {
1594 SDDS_dataset->autoRecovered = 1;
1596 if (bigBuffer)
1597 free(bigBuffer);
1598 return (SDDS_dataset->page_number);
1599 }
1600 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
1601 SDDS_SetError("Unable to read page--scanning error (SDDS_ReadAsciiPage)");
1602 return (0);
1603 }
1604 if (sparse_statistics != 0) {
1605 switch (layout->column_definition[i].type) {
1606 case SDDS_FLOAT:
1607 ((double*)statData[i])[k % sparse_interval] = (double)(((float*)SDDS_dataset->data[i])[j]);
1608 break;
1609 case SDDS_DOUBLE:
1610 ((double*)statData[i])[k % sparse_interval] = ((double*)SDDS_dataset->data[i])[j];
1611 break;
1612 case SDDS_LONGDOUBLE:
1613 ((double*)statData[i])[k % sparse_interval] = (double)(((long double*)SDDS_dataset->data[i])[j]);
1614 break;
1615 }
1616 if (SDDS_FLOATING_TYPE(layout->column_definition[i].type)) {
1617 if (sparse_statistics == 1) {
1618 // Sparse and get average statistics
1619 compute_average(&statResult, (double*)statData[i], (k % sparse_interval) + 1);
1620 } else if (sparse_statistics == 2) {
1621 // Sparse and get median statistics
1622 compute_median(&statResult, (double*)statData[i], (k % sparse_interval) + 1);
1623 } else if (sparse_statistics == 3) {
1624 // Sparse and get minimum statistics
1625 statResult = min_in_array((double*)statData[i], (k % sparse_interval) + 1);
1626 } else if (sparse_statistics == 4) {
1627 // Sparse and get maximum statistics
1628 statResult = max_in_array((double*)statData[i], (k % sparse_interval) + 1);
1629 }
1630 }
1631 switch (layout->column_definition[i].type) {
1632 case SDDS_FLOAT:
1633 ((float*)SDDS_dataset->data[i])[j] = statResult;
1634 break;
1635 case SDDS_DOUBLE:
1636 ((double*)SDDS_dataset->data[i])[j] = statResult;
1637 break;
1638 case SDDS_LONGDOUBLE:
1639 ((long double*)SDDS_dataset->data[i])[j] = statResult;
1640 break;
1641 }
1642 }
1643
1644#if defined(DEBUG)
1645 fprintf(stderr, "line remaining = %s\n", bigBuffer);
1646#endif
1647 }
1648 if (end_of_data)
1649 /* ran out of data for no_row_counts=1 */
1650 break;
1651 if (layout->data_mode.lines_per_row != 0 && lineCount != layout->data_mode.lines_per_row) {
1652 sprintf(s, "Unable to read page--line layout error at line %" PRId64 " of page %" PRId32 " (SDDS_ReadAsciiPage)", j + 1, SDDS_dataset->page_number);
1653 SDDS_SetError(s);
1654 /* data ends prematurely, which is an error that may be recoverable */
1655#if defined(zLib)
1656 if (SDDS_dataset->layout.gzipFile) {
1657 gzseek(gzfp, 0L, SEEK_END);
1658 } else {
1659#endif
1660 if (SDDS_dataset->layout.lzmaFile) {
1661 lzma_seek(lzmafp, 0L, SEEK_END);
1662 } else {
1663 fseek(fp, 0L, SEEK_END);
1664 }
1665#if defined(zLib)
1666 }
1667#endif
1668 if (SDDS_dataset->autoRecover) {
1669 SDDS_dataset->autoRecovered = 1;
1671 if (bigBuffer)
1672 free(bigBuffer);
1673 return (SDDS_dataset->page_number);
1674 }
1675 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
1676 SDDS_dataset->n_rows = j;
1677 return (0);
1678 }
1679 if (layout->data_mode.lines_per_row != 0) {
1680 bigBuffer[0] = 0;
1681 bigBufferCopy = bigBuffer;
1682 }
1683 if (--sparse_offset < 0 &&
1684 (((sparse_statistics == 0) && (k % sparse_interval == 0)) || ((sparse_statistics != 0) && (k % sparse_interval == sparse_interval - 1))))
1685 j++;
1686 k++;
1687 } while (k < n_rows || no_row_counts);
1688
1689 if (sparse_statistics != 0) {
1690 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
1691 if (SDDS_FLOATING_TYPE(layout->column_definition[i].type)) {
1692 free(statData[i]);
1693 }
1694 }
1695 free(statData);
1696 }
1697
1698 if (end_of_data && !(SDDS_dataset->page_number == 1) && j == 0 && !dataRead) {
1699 /* For end of data in no_row_counts=1 mode for any page other than the first,
1700 * an end-of-file is not a valid way to end an empty page (only an incomplete line is)
1701 */
1702 if (bigBuffer)
1703 free(bigBuffer);
1704 return SDDS_dataset->page_number = -1;
1705 }
1706 SDDS_dataset->n_rows = j;
1707 }
1708 if (bigBuffer)
1709 free(bigBuffer);
1710
1711 return (SDDS_dataset->page_number);
1712}
int32_t SDDS_AsciiDataExpected(SDDS_DATASET *SDDS_dataset)
Checks whether the SDDS dataset expects ASCII data input.
int32_t SDDS_ReadAsciiArrays(SDDS_DATASET *SDDS_dataset)
Reads the arrays from an ASCII file into the SDDS dataset.
int32_t SDDS_ReadAsciiParameters(SDDS_DATASET *SDDS_dataset)
Reads the parameters from an ASCII file into the SDDS dataset.
Definition SDDS_ascii.c:927
void SDDS_SetReadRecoveryMode(SDDS_DATASET *SDDS_dataset, int32_t mode)
Sets the read recovery mode for an SDDS dataset.
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int64_t SDDS_GetRowLimit()
char * fgetsLZMASkipComments(SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, struct lzmafile *lzmafp, char skip_char)
Reads a line from a LZMA-compressed file while skipping comment lines.
char * fgetsSkipComments(SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, FILE *fp, char skip_char)
Reads a line from a file while skipping comment lines.
void SDDS_ClearErrors()
Clears all recorded error messages from the SDDS error stack.
Definition SDDS_utils.c:354
#define SDDS_FLOAT
Identifier for the float data type.
Definition SDDStypes.h:43
#define SDDS_FLOATING_TYPE(type)
Checks if the given type identifier corresponds to a floating-point type.
Definition SDDStypes.h:124
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
Definition SDDStypes.h:31
double max_in_array(double *array, long n)
Finds the maximum value in an array of doubles.
Definition findMinMax.c:318
double min_in_array(double *array, long n)
Finds the minimum value in an array of doubles.
Definition findMinMax.c:336
long compute_average(double *value, double *data, int64_t n)
Computes the average of an array of doubles.
Definition median.c:152
long compute_median(double *value, double *x, long n)
Computes the median of an array of doubles.
Definition median.c:29

◆ SDDS_ReadAsciiPageLastRows()

int32_t SDDS_ReadAsciiPageLastRows ( SDDS_DATASET * SDDS_dataset,
int64_t last_rows )
extern

Reads the last specified number of rows from an ASCII page of an SDDS dataset.

This function reads only the last specified number of rows from the next ASCII page in the SDDS dataset.

Parameters
SDDS_datasetPointer to the SDDS dataset where the data will be stored.
last_rowsNumber of rows to read from the end of the page.
Returns
Returns the page number on success, -1 if end-of-file is reached, or 0 on error.
Note
The function utilizes SDDS_ReadAsciiPageDetailed() to perform the actual reading.

Definition at line 1241 of file SDDS_ascii.c.

1241 {
1242 return SDDS_ReadAsciiPageDetailed(SDDS_dataset, 1, 0, last_rows, 0);
1243}
int32_t SDDS_ReadAsciiPageDetailed(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows, int32_t sparse_statistics)
Reads a detailed page of data from an ASCII file into an SDDS dataset with optional sparsity and stat...

◆ SDDS_ReadAsciiParameters()

int32_t SDDS_ReadAsciiParameters ( SDDS_DATASET * SDDS_dataset)
extern

Reads the parameters from an ASCII file into the SDDS dataset.

This function reads parameter data from an ASCII file and stores it in the provided SDDS dataset. It supports reading from regular files, as well as GZIP and LZMA compressed files if enabled.

Parameters
SDDS_datasetPointer to the SDDS dataset where the parameters will be stored.
Returns
Returns 1 on success, 0 on error, or -1 if end-of-file is reached before any parameters are read.
Note
The function checks the dataset for consistency before reading. It handles fixed-value parameters appropriately. The function reads each parameter line by line, skipping comments, and stores the values after scanning them according to their data type.

Definition at line 927 of file SDDS_ascii.c.

927 {
928 int32_t i, first_read;
929 SDDS_LAYOUT *layout;
930#if defined(zLib)
931 gzFile gzfp;
932#endif
933 FILE *fp;
934 struct lzmafile *lzmafp;
935 char *bigBuffer = NULL;
936 int32_t bigBufferSize = 0;
937
938 layout = &SDDS_dataset->layout;
939 first_read = 1;
940 if (layout->n_parameters > 0) {
941 if (!(bigBuffer = SDDS_Malloc(sizeof(*bigBuffer) * (bigBufferSize = INITIAL_BIG_BUFFER_SIZE)))) {
942 SDDS_SetError("Unable to read parameters--buffer allocation failure (SDDS_ReadAsciiParameters)");
943 return (0);
944 }
945 }
946#if defined(zLib)
947 if (SDDS_dataset->layout.gzipFile) {
948 gzfp = layout->gzfp;
949 for (i = 0; i < layout->n_parameters; i++) {
950 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
951 continue;
952 bigBuffer[0] = 0;
953 if (!layout->parameter_definition[i].fixed_value) {
954 if (!fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp, '!')) {
955 if (first_read) {
956 if (bigBuffer)
957 free(bigBuffer);
958 return (-1);
959 }
960 SDDS_SetError("Unable to read parameters--data ends prematurely (SDDS_ReadAsciiParameters)");
961 return (0);
962 }
963 first_read = 0;
964 bigBuffer[strlen(bigBuffer) - 1] = 0;
965 } else
966 strcpy(bigBuffer, layout->parameter_definition[i].fixed_value);
967 if (!SDDS_ScanData(bigBuffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
968 SDDS_SetError("Unable to read page--parameter scanning error (SDDS_ReadAsciiParameters)");
969 return (0);
970 }
971 }
972 } else {
973#endif
974 if (SDDS_dataset->layout.lzmaFile) {
975 lzmafp = layout->lzmafp;
976 for (i = 0; i < layout->n_parameters; i++) {
977 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
978 continue;
979 bigBuffer[0] = 0;
980 if (!layout->parameter_definition[i].fixed_value) {
981 if (!fgetsLZMASkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, lzmafp, '!')) {
982 if (first_read) {
983 if (bigBuffer)
984 free(bigBuffer);
985 return (-1);
986 }
987 SDDS_SetError("Unable to read parameters--data ends prematurely (SDDS_ReadAsciiParameters)");
988 return (0);
989 }
990 first_read = 0;
991 bigBuffer[strlen(bigBuffer) - 1] = 0;
992 } else
993 strcpy(bigBuffer, layout->parameter_definition[i].fixed_value);
994 if (!SDDS_ScanData(bigBuffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
995 SDDS_SetError("Unable to read page--parameter scanning error (SDDS_ReadAsciiParameters)");
996 return (0);
997 }
998 }
999 } else {
1000 fp = layout->fp;
1001 for (i = 0; i < layout->n_parameters; i++) {
1002 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
1003 continue;
1004 bigBuffer[0] = 0;
1005 if (!layout->parameter_definition[i].fixed_value) {
1006 if (!fgetsSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, fp, '!')) {
1007 if (first_read) {
1008 if (bigBuffer)
1009 free(bigBuffer);
1010 return (-1);
1011 }
1012 SDDS_SetError("Unable to read parameters--data ends prematurely (SDDS_ReadAsciiParameters)");
1013 return (0);
1014 }
1015 first_read = 0;
1016 bigBuffer[strlen(bigBuffer) - 1] = 0;
1017 } else
1018 strcpy(bigBuffer, layout->parameter_definition[i].fixed_value);
1019 if (!SDDS_ScanData(bigBuffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
1020 SDDS_SetError("Unable to read page--parameter scanning error (SDDS_ReadAsciiParameters)");
1021 return (0);
1022 }
1023 }
1024 }
1025#if defined(zLib)
1026 }
1027#endif
1028 if (bigBuffer)
1029 free(bigBuffer);
1030 return (1);
1031}
int32_t SDDS_ScanData(char *string, int32_t type, int32_t field_length, void *data, int64_t index, int32_t is_parameter)
Scans a string and saves the parsed value into a data pointer according to the specified data type.

◆ SDDS_ReadBinaryArrays()

int32_t SDDS_ReadBinaryArrays ( SDDS_DATASET * SDDS_dataset)
extern

Reads binary arrays from an SDDS dataset.

This function iterates through all array definitions within the specified SDDS dataset and reads their binary data from the underlying file. It handles various compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files. For each array, the function reads its definition, dimensions, and data elements, allocating and managing memory as necessary. String arrays are handled by reading each string individually, while other data types are read in bulk.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
Returns
int32_t Returns 1 on successful reading of all arrays, or 0 if an error occurred.
Return values
1All arrays were successfully read and stored.
0An error occurred during the read operation, such as I/O failures, memory allocation issues, or corrupted array definitions.
Note
The caller is responsible for ensuring that the SDDS_dataset structure is properly initialized and that memory allocations for arrays are managed appropriately to prevent memory leaks.

Definition at line 3184 of file SDDS_binary.c.

3184 {
3185 int32_t i, j;
3186 SDDS_LAYOUT *layout;
3187 /* char *predefined_format; */
3188 /* static char buffer[SDDS_MAXLINE]; */
3189#if defined(zLib)
3190 gzFile gzfp = NULL;
3191#endif
3192 FILE *fp = NULL;
3193 struct lzmafile *lzmafp = NULL;
3194 SDDS_ARRAY *array;
3195 SDDS_FILEBUFFER *fBuffer;
3196
3197 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryArrays"))
3198 return (0);
3199 layout = &SDDS_dataset->layout;
3200 if (!layout->n_arrays)
3201 return (1);
3202#if defined(zLib)
3203 if (SDDS_dataset->layout.gzipFile) {
3204 gzfp = layout->gzfp;
3205 } else {
3206#endif
3207 if (SDDS_dataset->layout.lzmaFile) {
3208 lzmafp = layout->lzmafp;
3209 } else {
3210 fp = layout->fp;
3211 }
3212#if defined(zLib)
3213 }
3214#endif
3215 fBuffer = &SDDS_dataset->fBuffer;
3216 if (!SDDS_dataset->array) {
3217 SDDS_SetError("Unable to read array--pointer to structure storage area is NULL (SDDS_ReadBinaryArrays)");
3218 return (0);
3219 }
3220 for (i = 0; i < layout->n_arrays; i++) {
3221 array = SDDS_dataset->array + i;
3222 if (array->definition && !SDDS_FreeArrayDefinition(array->definition)) {
3223 SDDS_SetError("Unable to get array--array definition corrupted (SDDS_ReadBinaryArrays)");
3224 return (0);
3225 }
3226 if (!SDDS_CopyArrayDefinition(&array->definition, layout->array_definition + i)) {
3227 SDDS_SetError("Unable to read array--definition copy failed (SDDS_ReadBinaryArrays)");
3228 return (0);
3229 }
3230 /*if (array->dimension) free(array->dimension); */
3231 if (!(array->dimension = SDDS_Realloc(array->dimension, sizeof(*array->dimension) * array->definition->dimensions))) {
3232 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3233 return (0);
3234 }
3235#if defined(zLib)
3236 if (SDDS_dataset->layout.gzipFile) {
3237 if (!SDDS_GZipBufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, gzfp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3238 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3239 return (0);
3240 }
3241 } else {
3242#endif
3243 if (SDDS_dataset->layout.lzmaFile) {
3244 if (!SDDS_LZMABufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, lzmafp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3245 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3246 return (0);
3247 }
3248 } else {
3249 if (!SDDS_BufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, fp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3250 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3251 return (0);
3252 }
3253 }
3254#if defined(zLib)
3255 }
3256#endif
3257 array->elements = 1;
3258 for (j = 0; j < array->definition->dimensions; j++)
3259 array->elements *= array->dimension[j];
3260 if (array->data)
3261 free(array->data);
3262 array->data = array->pointer = NULL;
3263 if (array->elements == 0)
3264 continue;
3265 if (array->elements < 0) {
3266 SDDS_SetError("Unable to read array--number of elements is negative (SDDS_ReadBinaryArrays)");
3267 return (0);
3268 }
3269 if (!(array->data = SDDS_Realloc(array->data, array->elements * SDDS_type_size[array->definition->type - 1]))) {
3270 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3271 return (0);
3272 }
3273 if (array->definition->type == SDDS_STRING) {
3274#if defined(zLib)
3275 if (SDDS_dataset->layout.gzipFile) {
3276 for (j = 0; j < array->elements; j++) {
3277 if (!(((char **)(array->data))[j] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3278 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3279 return (0);
3280 }
3281 }
3282 } else {
3283#endif
3284 if (SDDS_dataset->layout.lzmaFile) {
3285 for (j = 0; j < array->elements; j++) {
3286 if (!(((char **)(array->data))[j] = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
3287 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3288 return (0);
3289 }
3290 }
3291 } else {
3292 for (j = 0; j < array->elements; j++) {
3293 if (!(((char **)(array->data))[j] = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
3294 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3295 return (0);
3296 }
3297 }
3298 }
3299#if defined(zLib)
3300 }
3301#endif
3302 } else {
3303#if defined(zLib)
3304 if (SDDS_dataset->layout.gzipFile) {
3305 if (!SDDS_GZipBufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, gzfp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3306 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3307 return (0);
3308 }
3309 } else {
3310#endif
3311 if (SDDS_dataset->layout.lzmaFile) {
3312 if (!SDDS_LZMABufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, lzmafp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3313 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3314 return (0);
3315 }
3316 } else {
3317 if (!SDDS_BufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, fp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3318 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3319 return (0);
3320 }
3321 }
3322#if defined(zLib)
3323 }
3324#endif
3325 }
3326 }
3327 return (1);
3328}
int32_t SDDS_LZMABufferedRead(void *target, int64_t targetSize, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder)
char * SDDS_ReadBinaryString(FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a binary string from a file with buffering.
int32_t SDDS_BufferedRead(void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder)
char * SDDS_ReadLZMABinaryString(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a binary string from an LZMA-compressed file with buffering.

◆ SDDS_ReadBinaryColumns()

int32_t SDDS_ReadBinaryColumns ( SDDS_DATASET * SDDS_dataset,
int64_t sparse_interval,
int64_t sparse_offset )
extern

Reads the binary columns from an SDDS dataset.

This function iterates through all column definitions within the specified SDDS dataset and reads their binary data from the underlying file. It handles various compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files. For each column, the function reads data for each row, managing memory allocation for string columns as necessary. Non-string data types are read in bulk for each column.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
Returns
int32_t Returns 1 on successful reading of all columns, or 0 if an error occurred.
Return values
1All columns were successfully read and stored.
0An error occurred during the read operation, such as I/O failures, memory allocation issues, or corrupted column definitions.
Note
The caller is responsible for ensuring that the SDDS_dataset structure is properly initialized and that memory allocations for columns are managed appropriately to prevent memory leaks.

Definition at line 3349 of file SDDS_binary.c.

3349 {
3350 int64_t i, j, k, row;
3351 SDDS_LAYOUT *layout;
3352 /* char *predefined_format; */
3353 /* static char buffer[SDDS_MAXLINE]; */
3354#if defined(zLib)
3355 gzFile gzfp = NULL;
3356#endif
3357 FILE *fp = NULL;
3358 struct lzmafile *lzmafp = NULL;
3359 SDDS_FILEBUFFER *fBuffer;
3360
3361 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryColumns"))
3362 return (0);
3363 layout = &SDDS_dataset->layout;
3364 if (!layout->n_columns || !SDDS_dataset->n_rows)
3365 return (1);
3366#if defined(zLib)
3367 if (SDDS_dataset->layout.gzipFile) {
3368 gzfp = layout->gzfp;
3369 } else {
3370#endif
3371 if (SDDS_dataset->layout.lzmaFile) {
3372 lzmafp = layout->lzmafp;
3373 } else {
3374 fp = layout->fp;
3375 }
3376#if defined(zLib)
3377 }
3378#endif
3379 fBuffer = &SDDS_dataset->fBuffer;
3380
3381 for (i = 0; i < layout->n_columns; i++) {
3382 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3383 continue;
3384 if (layout->column_definition[i].type == SDDS_STRING) {
3385#if defined(zLib)
3386 if (SDDS_dataset->layout.gzipFile) {
3387 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3388 if (((char ***)SDDS_dataset->data)[i][row])
3389 free((((char ***)SDDS_dataset->data)[i][row]));
3390 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3391 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadBinaryColumns)");
3392 return (0);
3393 }
3394 }
3395 } else {
3396#endif
3397 if (SDDS_dataset->layout.lzmaFile) {
3398 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3399 if (((char ***)SDDS_dataset->data)[i][row])
3400 free((((char ***)SDDS_dataset->data)[i][row]));
3401 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
3402 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3403 return (0);
3404 }
3405 }
3406 } else {
3407 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3408 if (((char ***)SDDS_dataset->data)[i][row])
3409 free((((char ***)SDDS_dataset->data)[i][row]));
3410 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
3411 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3412 return (0);
3413 }
3414 }
3415 }
3416#if defined(zLib)
3417 }
3418#endif
3419 } else {
3420#if defined(zLib)
3421 if (SDDS_dataset->layout.gzipFile) {
3422 if (!SDDS_GZipBufferedRead(SDDS_dataset->data[i], SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, gzfp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3423 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3424 return (0);
3425 }
3426 } else {
3427#endif
3428 if (SDDS_dataset->layout.lzmaFile) {
3429 if (!SDDS_LZMABufferedRead(SDDS_dataset->data[i], SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, lzmafp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3430 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3431 return (0);
3432 }
3433 } else {
3434 if (!SDDS_BufferedRead(SDDS_dataset->data[i], SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, fp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3435 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3436 return (0);
3437 }
3438 }
3439#if defined(zLib)
3440 }
3441#endif
3442 }
3443 }
3444
3445 if (sparse_interval == 1 && sparse_offset == 0) {
3446 return(1);
3447 }
3448
3449 j = SDDS_dataset->n_rows;
3450 for (i = 0; i < layout->n_columns; i++) {
3451 j = k = 0;
3452 switch (layout->column_definition[i].type) {
3453 case SDDS_SHORT:
3454 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3455 if (k % sparse_interval == 0) {
3456 ((short*)SDDS_dataset->data[i])[j] = ((short*)SDDS_dataset->data[i])[row];
3457 j++;
3458 }
3459 k++;
3460 }
3461 break;
3462 case SDDS_USHORT:
3463 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3464 if (k % sparse_interval == 0) {
3465 ((unsigned short*)SDDS_dataset->data[i])[j] = ((unsigned short*)SDDS_dataset->data[i])[row];
3466 j++;
3467 }
3468 k++;
3469 }
3470 break;
3471 case SDDS_LONG:
3472 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3473 if (k % sparse_interval == 0) {
3474 ((int32_t*)SDDS_dataset->data[i])[j] = ((int32_t*)SDDS_dataset->data[i])[row];
3475 j++;
3476 }
3477 k++;
3478 }
3479 break;
3480 case SDDS_ULONG:
3481 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3482 if (k % sparse_interval == 0) {
3483 ((uint32_t*)SDDS_dataset->data[i])[j] = ((uint32_t*)SDDS_dataset->data[i])[row];
3484 j++;
3485 }
3486 k++;
3487 }
3488 break;
3489 case SDDS_LONG64:
3490 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3491 if (k % sparse_interval == 0) {
3492 ((int64_t*)SDDS_dataset->data[i])[j] = ((int64_t*)SDDS_dataset->data[i])[row];
3493 j++;
3494 }
3495 k++;
3496 }
3497 break;
3498 case SDDS_ULONG64:
3499 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3500 if (k % sparse_interval == 0) {
3501 ((uint64_t*)SDDS_dataset->data[i])[j] = ((uint64_t*)SDDS_dataset->data[i])[row];
3502 j++;
3503 }
3504 k++;
3505 }
3506 break;
3507 case SDDS_FLOAT:
3508 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3509 if (k % sparse_interval == 0) {
3510 ((float*)SDDS_dataset->data[i])[j] = ((float*)SDDS_dataset->data[i])[row];
3511 j++;
3512 }
3513 k++;
3514 }
3515 break;
3516 case SDDS_DOUBLE:
3517 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3518 if (k % sparse_interval == 0) {
3519 ((double*)SDDS_dataset->data[i])[j] = ((double*)SDDS_dataset->data[i])[row];
3520 j++;
3521 }
3522 k++;
3523 }
3524 break;
3525 case SDDS_LONGDOUBLE:
3526 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3527 if (k % sparse_interval == 0) {
3528 ((long double*)SDDS_dataset->data[i])[j] = ((long double*)SDDS_dataset->data[i])[row];
3529 j++;
3530 }
3531 k++;
3532 }
3533 break;
3534 case SDDS_STRING:
3535 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3536 if (k % sparse_interval == 0) {
3537 ((char**)SDDS_dataset->data[i])[j] = ((char**)SDDS_dataset->data[i])[row];
3538 j++;
3539 }
3540 k++;
3541 }
3542 for (k=j; k<SDDS_dataset->n_rows; k++) {
3543 if (((char ***)SDDS_dataset->data)[i][k]) {
3544 free((((char ***)SDDS_dataset->data)[i][k]));
3545 ((char ***)SDDS_dataset->data)[i][k] = NULL;
3546 }
3547 }
3548
3549 break;
3550 case SDDS_CHARACTER:
3551 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3552 if (k % sparse_interval == 0) {
3553 ((char*)SDDS_dataset->data[i])[j] = ((char*)SDDS_dataset->data[i])[row];
3554 j++;
3555 }
3556 k++;
3557 }
3558 break;
3559 default:
3560 break;
3561 }
3562 }
3563
3564 SDDS_dataset->n_rows = j;
3565
3566 return (1);
3567}
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
Definition SDDStypes.h:67
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
Definition SDDStypes.h:55
#define SDDS_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
Definition SDDStypes.h:79
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49

◆ SDDS_ReadBinaryPage()

int32_t SDDS_ReadBinaryPage ( SDDS_DATASET * SDDS_dataset,
int64_t sparse_interval,
int64_t sparse_offset,
int32_t sparse_statistics )
extern

Reads a binary page from an SDDS dataset.

This function reads a binary page from the specified SDDS dataset. It allows for sparse reading by specifying the sparse_interval and sparse_offset parameters, enabling the reading of data at specified intervals or starting from a specific offset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
sparse_intervalInterval at which to read rows. A value greater than 1 enables sparse reading.
sparse_offsetNumber of initial rows to skip before starting to read data.
sparse_statisticsFlag indicating whether to compute statistics during sparse reading:
  • 0: No statistics.
  • 1: Compute average.
  • 2: Compute median.
  • 3: Compute minimum.
  • 4: Compute maximum.
Returns
  • Returns the page number on successful read.
  • Returns -1 if the end-of-file is reached.
  • Returns 0 on error.

The function internally calls SDDS_ReadBinaryPageDetailed with the provided parameters to perform the actual reading. It handles various scenarios, including non-native byte orders and different data layouts (row-major or column-major).

Note
  • This function is typically called to read data pages in bulk, allowing for efficient data access by skipping unnecessary rows.
  • Sparse statistics can be used to reduce the amount of data by computing aggregated values.
  • The function assumes that the dataset has been properly initialized and that the file pointers are correctly set up.

Definition at line 2141 of file SDDS_binary.c.

2141 {
2142 return SDDS_ReadBinaryPageDetailed(SDDS_dataset, sparse_interval, sparse_offset, 0, sparse_statistics);
2143}
int32_t SDDS_ReadBinaryPageDetailed(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows, int32_t sparse_statistics)
Reads a binary page from an SDDS dataset with detailed options.

◆ SDDS_ReadBinaryPageDetailed()

int32_t SDDS_ReadBinaryPageDetailed ( SDDS_DATASET * SDDS_dataset,
int64_t sparse_interval,
int64_t sparse_offset,
int64_t last_rows,
int32_t sparse_statistics )
extern

Reads a binary page from an SDDS dataset with detailed options.

This function reads a binary page from the specified SDDS dataset, providing detailed control over the reading process. It supports sparse reading, reading a specific number of rows from the end, and computing statistics on the data.

Typically, this function is not called directly. Instead, it is invoked through higher-level functions such as SDDS_ReadBinaryPage or SDDS_ReadBinaryPageLastRows, which provide simplified interfaces for common reading scenarios.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
sparse_intervalInterval at which to read rows. A value greater than 1 enables sparse reading.
sparse_offsetNumber of initial rows to skip before starting to read data.
last_rowsThe number of rows to read from the end of the dataset. If 0, all rows are read.
sparse_statisticsFlag indicating whether to compute statistics during sparse reading:
  • 0: No statistics.
  • 1: Compute average.
  • 2: Compute median.
  • 3: Compute minimum.
  • 4: Compute maximum.
Returns
  • Returns the page number on successful read.
  • Returns -1 if the end-of-file is reached.
  • Returns 0 on error.

The function performs the following steps:

  • Checks if the dataset has been auto-recovered; if so, it returns -1.
  • Determines if the dataset uses native or non-native byte order and delegates to SDDS_ReadNonNativePageDetailed if necessary.
  • Initializes file pointers based on the compression format (standard, gzip, LZMA).
  • Allocates and initializes the buffer for reading if not already allocated.
  • Reads the number of rows from the binary file, handling both 32-bit and 64-bit row counts.
  • Validates the row count and ensures it does not exceed predefined limits.
  • Adjusts for column-major layouts by calling SDDS_ReadBinaryColumns if necessary.
  • Handles sparse reading by skipping rows based on sparse_interval and sparse_offset.
  • If sparse_statistics is enabled, computes the specified statistics (average, median, min, max) on floating-point data.
  • Handles errors by setting appropriate error messages and managing recovery modes.
Note
  • This function provides extensive control over the reading process, allowing for optimized data access.
  • Ensure that all parameters are set correctly to avoid unintended data skips or miscomputations.
  • The function assumes that the dataset has been properly initialized and that the file pointers are correctly set up.
  • Compression support (zLib for gzip, LZMA libraries) must be enabled during compilation for handling compressed files.

Definition at line 2223 of file SDDS_binary.c.

2223 {
2224 int32_t n_rows32;
2225 int64_t n_rows, i, j, k, alloc_rows, rows_to_store, mod;
2226
2227 /* int32_t page_number, i; */
2228#if defined(zLib)
2229 gzFile gzfp = NULL;
2230#endif
2231 FILE *fp = NULL;
2232 struct lzmafile *lzmafp = NULL;
2233 SDDS_FILEBUFFER *fBuffer;
2234 void **statData=NULL;
2235 double statResult;
2236
2237 if (SDDS_dataset->autoRecovered)
2238 return -1;
2239 if (SDDS_dataset->swapByteOrder) {
2240 return SDDS_ReadNonNativePageDetailed(SDDS_dataset, 0, sparse_interval, sparse_offset, last_rows);
2241 }
2242
2243 /* static char s[SDDS_MAXLINE]; */
2244 n_rows = 0;
2245 SDDS_SetReadRecoveryMode(SDDS_dataset, 0);
2246#if defined(zLib)
2247 if (SDDS_dataset->layout.gzipFile) {
2248 gzfp = SDDS_dataset->layout.gzfp;
2249 } else {
2250#endif
2251 if (SDDS_dataset->layout.lzmaFile) {
2252 lzmafp = SDDS_dataset->layout.lzmafp;
2253 } else {
2254 fp = SDDS_dataset->layout.fp;
2255 }
2256#if defined(zLib)
2257 }
2258#endif
2259 fBuffer = &SDDS_dataset->fBuffer;
2260 if (!fBuffer->buffer) {
2261 int32_t bufferSize = SDDS_GetLockedDefaultIOBufferSize();
2262 if (bufferSize == 0 && (SDDS_dataset->layout.popenUsed || !SDDS_dataset->layout.filename) && (sparse_interval > 1 || sparse_offset > 0 || last_rows > 0)) {
2263 SDDS_SetError("The IO buffer size is 0 for data being read from a pipe with sparsing. This is not supported.");
2264 return 0;
2265 }
2266 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * (bufferSize + 1)))) {
2267 SDDS_SetError("Unable to do buffered read--allocation failure");
2268 return 0;
2269 }
2270 fBuffer->bufferSize = bufferSize;
2271 fBuffer->bytesLeft = 0;
2272 }
2273 SDDS_dataset->rowcount_offset = -1;
2274#if defined(zLib)
2275 if (SDDS_dataset->layout.gzipFile) {
2276 if (!SDDS_GZipBufferedRead(&n_rows32, sizeof(n_rows32), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2277 if (gzeof(gzfp))
2278 return (SDDS_dataset->page_number = -1);
2279 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2280 return (0);
2281 }
2282 if (n_rows32 == INT32_MIN) {
2283 if (!SDDS_GZipBufferedRead(&n_rows, sizeof(n_rows), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
2284 if (gzeof(gzfp))
2285 return (SDDS_dataset->page_number = -1);
2286 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2287 return (0);
2288 }
2289 } else {
2290 n_rows = n_rows32;
2291 }
2292 } else {
2293#endif
2294 /* This value will only be valid if read buffering is turned off, which is done for
2295 * certain append operations! Should really modify SDDS_BufferedRead and SDDS_BufferedWrite
2296 * to provide ftell capability.
2297 */
2298 if (SDDS_dataset->layout.lzmaFile) {
2299 if (!SDDS_LZMABufferedRead(&n_rows32, sizeof(n_rows32), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2300 if (lzma_eof(lzmafp))
2301 return (SDDS_dataset->page_number = -1);
2302 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2303 return (0);
2304 }
2305 if (n_rows32 == INT32_MIN) {
2306 if (!SDDS_LZMABufferedRead(&n_rows, sizeof(n_rows), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
2307 if (lzma_eof(lzmafp))
2308 return (SDDS_dataset->page_number = -1);
2309 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2310 return (0);
2311 }
2312 } else {
2313 n_rows = n_rows32;
2314 }
2315 } else {
2316 SDDS_dataset->rowcount_offset = ftell(fp);
2317 if (!SDDS_BufferedRead(&n_rows32, sizeof(n_rows32), fp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2318 if (feof(fp))
2319 return (SDDS_dataset->page_number = -1);
2320 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2321 return (0);
2322 }
2323 if (n_rows32 == INT32_MIN) {
2324 if (!SDDS_BufferedRead(&n_rows, sizeof(n_rows), fp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
2325 if (feof(fp))
2326 return (SDDS_dataset->page_number = -1);
2327 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2328 return (0);
2329 }
2330 } else {
2331 n_rows = n_rows32;
2332 }
2333 }
2334#if defined(zLib)
2335 }
2336#endif
2337
2338#if defined(DEBUG)
2339 fprintf(stderr, "Expect %" PRId64 " rows of data\n", n_rows);
2340#endif
2341 if (n_rows < 0) {
2342 SDDS_SetError("Unable to read page--negative number of rows (SDDS_ReadBinaryPageDetailed)");
2343 return (0);
2344 }
2345 if (SDDS_dataset->layout.byteOrderDeclared == 0) {
2346 if (n_rows > 10000000) {
2347 SDDS_SetError("Unable to read page--endian byte order not declared and suspected to be non-native. (SDDS_ReadBinaryPageDetailed)");
2348 return (0);
2349 }
2350 }
2351 if (n_rows > SDDS_GetRowLimit()) {
2352 /* the number of rows is "unreasonably" large---treat like end-of-file */
2353 return (SDDS_dataset->page_number = -1);
2354 }
2355 if (last_rows < 0)
2356 last_rows = 0;
2357 /* Fix this limitation later */
2358
2359 if (last_rows) {
2360 sparse_interval = 1;
2361 sparse_offset = n_rows - last_rows;
2362 }
2363 if (sparse_interval <= 0)
2364 sparse_interval = 1;
2365 if (sparse_offset < 0)
2366 sparse_offset = 0;
2367
2368 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
2369 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
2370
2371 if (!SDDS_StartPage(SDDS_dataset, 0) || !SDDS_LengthenTable(SDDS_dataset, alloc_rows)) {
2372 SDDS_SetError("Unable to read page--couldn't start page (SDDS_ReadBinaryPageDetailed)");
2373 return (0);
2374 }
2375
2376 /* read the parameter values */
2377 if (!SDDS_ReadBinaryParameters(SDDS_dataset)) {
2378 SDDS_SetError("Unable to read page--parameter reading error (SDDS_ReadBinaryPageDetailed)");
2379 return (0);
2380 }
2381
2382 /* read the array values */
2383 if (!SDDS_ReadBinaryArrays(SDDS_dataset)) {
2384 SDDS_SetError("Unable to read page--array reading error (SDDS_ReadBinaryPageDetailed)");
2385 return (0);
2386 }
2387 if (SDDS_dataset->layout.data_mode.column_major) {
2388 SDDS_dataset->n_rows = n_rows;
2389 if (sparse_statistics == 0) {
2390 if (!SDDS_ReadBinaryColumns(SDDS_dataset, sparse_interval, sparse_offset)) {
2391 SDDS_SetError("Unable to read page--column reading error (SDDS_ReadBinaryPageDetailed)");
2392 return (0);
2393 }
2394 return (SDDS_dataset->page_number);
2395 } else {
2396 /* allocate space for full columns if needed */
2397 if (SDDS_dataset->n_rows_allocated < n_rows) {
2398 if (!SDDS_LengthenTable(SDDS_dataset, n_rows - SDDS_dataset->n_rows_allocated)) {
2399 SDDS_SetError("Unable to read page--couldn't start page (SDDS_ReadBinaryPageDetailed)");
2400 return (0);
2401 }
2402 }
2403 if (!SDDS_ReadBinaryColumns(SDDS_dataset, 1, 0)) {
2404 SDDS_SetError("Unable to read page--column reading error (SDDS_ReadBinaryPageDetailed)");
2405 return (0);
2406 }
2407 statData = (void**)malloc(SDDS_dataset->layout.n_columns * sizeof(void*));
2408 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2409 statData[i] = NULL;
2410 if (SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type))
2411 statData[i] = (double*)calloc(sparse_interval, sizeof(double));
2412 }
2413 n_rows -= sparse_offset;
2414 for (j = k = 0; j < n_rows; j++) {
2415 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2416 switch (SDDS_dataset->layout.column_definition[i].type) {
2417 case SDDS_FLOAT:
2418 if (statData[i])
2419 ((double*)statData[i])[j % sparse_interval] = (double)(((float*)SDDS_dataset->data[i])[j + sparse_offset]);
2420 break;
2421 case SDDS_DOUBLE:
2422 if (statData[i])
2423 ((double*)statData[i])[j % sparse_interval] = ((double*)SDDS_dataset->data[i])[j + sparse_offset];
2424 break;
2425 case SDDS_LONGDOUBLE:
2426 if (statData[i])
2427 ((double*)statData[i])[j % sparse_interval] = (double)(((long double*)SDDS_dataset->data[i])[j + sparse_offset]);
2428 break;
2429 case SDDS_STRING:
2430 if (((char ***)SDDS_dataset->data)[i][k])
2431 free(((char ***)SDDS_dataset->data)[i][k]);
2432 ((char ***)SDDS_dataset->data)[i][k] = ((char ***)SDDS_dataset->data)[i][j + sparse_offset];
2433 ((char ***)SDDS_dataset->data)[i][j + sparse_offset] = NULL;
2434 break;
2435 case SDDS_SHORT:
2436 ((short*)SDDS_dataset->data[i])[k] = ((short*)SDDS_dataset->data[i])[j + sparse_offset];
2437 break;
2438 case SDDS_USHORT:
2439 ((unsigned short*)SDDS_dataset->data[i])[k] = ((unsigned short*)SDDS_dataset->data[i])[j + sparse_offset];
2440 break;
2441 case SDDS_LONG:
2442 ((int32_t*)SDDS_dataset->data[i])[k] = ((int32_t*)SDDS_dataset->data[i])[j + sparse_offset];
2443 break;
2444 case SDDS_ULONG:
2445 ((uint32_t*)SDDS_dataset->data[i])[k] = ((uint32_t*)SDDS_dataset->data[i])[j + sparse_offset];
2446 break;
2447 case SDDS_LONG64:
2448 ((int64_t*)SDDS_dataset->data[i])[k] = ((int64_t*)SDDS_dataset->data[i])[j + sparse_offset];
2449 break;
2450 case SDDS_ULONG64:
2451 ((uint64_t*)SDDS_dataset->data[i])[k] = ((uint64_t*)SDDS_dataset->data[i])[j + sparse_offset];
2452 break;
2453 case SDDS_CHARACTER:
2454 ((char*)SDDS_dataset->data[i])[k] = ((char*)SDDS_dataset->data[i])[j + sparse_offset];
2455 break;
2456 default:
2457 break;
2458 }
2459 if (statData[i]) {
2460 if (sparse_statistics == 1)
2461 compute_average(&statResult, (double*)statData[i], (j % sparse_interval) + 1);
2462 else if (sparse_statistics == 2)
2463 compute_median(&statResult, (double*)statData[i], (j % sparse_interval) + 1);
2464 else if (sparse_statistics == 3)
2465 statResult = min_in_array((double*)statData[i], (j % sparse_interval) + 1);
2466 else if (sparse_statistics == 4)
2467 statResult = max_in_array((double*)statData[i], (j % sparse_interval) + 1);
2468 switch (SDDS_dataset->layout.column_definition[i].type) {
2469 case SDDS_FLOAT:
2470 ((float*)SDDS_dataset->data[i])[k] = statResult;
2471 break;
2472 case SDDS_DOUBLE:
2473 ((double*)SDDS_dataset->data[i])[k] = statResult;
2474 break;
2475 case SDDS_LONGDOUBLE:
2476 ((long double*)SDDS_dataset->data[i])[k] = statResult;
2477 break;
2478 }
2479 }
2480 }
2481 if (j % sparse_interval == sparse_interval - 1)
2482 k++;
2483 }
2484 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2485 if (SDDS_dataset->layout.column_definition[i].type == SDDS_STRING) {
2486 int64_t r;
2487 for (r = k; r < SDDS_dataset->n_rows; r++) {
2488 if (((char ***)SDDS_dataset->data)[i][r]) {
2489 free(((char ***)SDDS_dataset->data)[i][r]);
2490 ((char ***)SDDS_dataset->data)[i][r] = NULL;
2491 }
2492 }
2493 }
2494 if (statData[i])
2495 free(statData[i]);
2496 }
2497 free(statData);
2498 SDDS_dataset->n_rows = k;
2499 return (SDDS_dataset->page_number);
2500 }
2501 }
2502 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
2503 for (j = 0; j < n_rows; j++) {
2504 if (!SDDS_ReadBinaryRow(SDDS_dataset, j, 0)) {
2505 SDDS_dataset->n_rows = j;
2506 if (SDDS_dataset->autoRecover) {
2507#if defined(DEBUG)
2508 fprintf(stderr, "Doing auto-read recovery\n");
2509#endif
2510 SDDS_dataset->autoRecovered = 1;
2512 return (SDDS_dataset->page_number);
2513 }
2514 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2515 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2516 return (0);
2517 }
2518 }
2519 SDDS_dataset->n_rows = j;
2520 return (SDDS_dataset->page_number);
2521 } else {
2522 for (j = 0; j < sparse_offset; j++) {
2523 if (!SDDS_ReadBinaryRow(SDDS_dataset, 0, 1)) {
2524 SDDS_dataset->n_rows = 0;
2525 if (SDDS_dataset->autoRecover) {
2526 SDDS_dataset->autoRecovered = 1;
2528 return (SDDS_dataset->page_number);
2529 }
2530 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2531 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2532 return (0);
2533 }
2534 }
2535 n_rows -= sparse_offset;
2536 if (sparse_statistics != 0) {
2537 // Allocate buffer space for statistical sparsing
2538 statData = (void**)malloc(SDDS_dataset->layout.n_columns * sizeof(void*));
2539 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2540 if (SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type)) {
2541 // Not ideal for SDDS_LONGDOUBLE but we may never run across this error
2542 statData[i] = (double*)calloc(sparse_interval, sizeof(double));
2543 }
2544 }
2545 for (j = k = 0; j < n_rows; j++) {
2546 if (!SDDS_ReadBinaryRow(SDDS_dataset, k, 0)) {
2547 SDDS_dataset->n_rows = k;
2548 if (SDDS_dataset->autoRecover) {
2549 SDDS_dataset->autoRecovered = 1;
2551 return (SDDS_dataset->page_number);
2552 }
2553 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2554 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2555 return (0);
2556 }
2557 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2558 switch (SDDS_dataset->layout.column_definition[i].type) {
2559 case SDDS_FLOAT:
2560 ((double*)statData[i])[j % sparse_interval] = (double)(((float*)SDDS_dataset->data[i])[k]);
2561 break;
2562 case SDDS_DOUBLE:
2563 ((double*)statData[i])[j % sparse_interval] = ((double*)SDDS_dataset->data[i])[k];
2564 break;
2565 case SDDS_LONGDOUBLE:
2566 ((double*)statData[i])[j % sparse_interval] = (double)(((long double*)SDDS_dataset->data[i])[k]);
2567 break;
2568 }
2569 if (SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type)) {
2570 if (sparse_statistics == 1) {
2571 // Sparse and get average statistics
2572 compute_average(&statResult, (double*)statData[i], (j % sparse_interval) + 1);
2573 } else if (sparse_statistics == 2) {
2574 // Sparse and get median statistics
2575 compute_median(&statResult, (double*)statData[i], (j % sparse_interval) + 1);
2576 } else if (sparse_statistics == 3) {
2577 // Sparse and get minimum statistics
2578 statResult = min_in_array((double*)statData[i], (j % sparse_interval) + 1);
2579 } else if (sparse_statistics == 4) {
2580 // Sparse and get maximum statistics
2581 statResult = max_in_array((double*)statData[i], (j % sparse_interval) + 1);
2582 }
2583 }
2584 switch (SDDS_dataset->layout.column_definition[i].type) {
2585 case SDDS_FLOAT:
2586 ((float*)SDDS_dataset->data[i])[k] = statResult;
2587 break;
2588 case SDDS_DOUBLE:
2589 ((double*)SDDS_dataset->data[i])[k] = statResult;
2590 break;
2591 case SDDS_LONGDOUBLE:
2592 ((long double*)SDDS_dataset->data[i])[k] = statResult;
2593 break;
2594 }
2595 }
2596 if (j % sparse_interval == sparse_interval - 1) {
2597 k++;
2598 }
2599 }
2600 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2601 if (SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type)) {
2602 free(statData[i]);
2603 }
2604 }
2605 free(statData);
2606 } else {
2607 for (j = k = 0; j < n_rows; j++) {
2608 if (!SDDS_ReadBinaryRow(SDDS_dataset, k, mod = j % sparse_interval)) {
2609 SDDS_dataset->n_rows = k;
2610 if (SDDS_dataset->autoRecover) {
2611 SDDS_dataset->autoRecovered = 1;
2613 return (SDDS_dataset->page_number);
2614 }
2615 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2616 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2617 return (0);
2618 }
2619 k += mod ? 0 : 1;
2620 }
2621 }
2622 SDDS_dataset->n_rows = k;
2623 return (SDDS_dataset->page_number);
2624 }
2625}
int32_t SDDS_ReadBinaryColumns(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset)
Reads the binary columns from an SDDS dataset.
int32_t SDDS_ReadBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row, int32_t skip)
Reads a binary row from the specified SDDS dataset.
int32_t SDDS_ReadNonNativePageDetailed(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows)
Reads a detailed non-native endian page from an SDDS dataset.
int32_t SDDS_ReadBinaryArrays(SDDS_DATASET *SDDS_dataset)
Reads binary arrays from an SDDS dataset.
int32_t SDDS_ReadBinaryParameters(SDDS_DATASET *SDDS_dataset)
Reads binary parameters from the specified SDDS dataset.

◆ SDDS_ReadBinaryPageLastRows()

int32_t SDDS_ReadBinaryPageLastRows ( SDDS_DATASET * SDDS_dataset,
int64_t last_rows )
extern

Reads the last specified number of rows from a binary page of an SDDS dataset.

This function reads the last last_rows rows from the binary page of the specified SDDS dataset. It is useful for retrieving recent data entries without processing the entire dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
last_rowsThe number of rows to read from the end of the dataset.
Returns
  • Returns the page number on successful read.
  • Returns -1 if the end-of-file is reached.
  • Returns 0 on error.

The function internally calls SDDS_ReadBinaryPageDetailed with sparse_interval set to 1, sparse_offset set to 0, and last_rows as specified. This configuration ensures that only the last last_rows rows are read from the dataset.

Note
  • This function is particularly useful for applications that need to display or process the most recent data entries.
  • Ensure that last_rows does not exceed the total number of rows in the dataset to avoid errors.
  • The function assumes that the dataset has been properly initialized and that the file pointers are correctly set up.

Definition at line 2171 of file SDDS_binary.c.

2171 {
2172 return SDDS_ReadBinaryPageDetailed(SDDS_dataset, 1, 0, last_rows, 0);
2173}

◆ SDDS_ReadBinaryParameters()

int32_t SDDS_ReadBinaryParameters ( SDDS_DATASET * SDDS_dataset)
extern

Reads binary parameters from the specified SDDS dataset.

This function iterates through all the parameters defined in the SDDS dataset layout and reads their values from the underlying file. It handles different data types, including strings, and manages memory allocation for string parameters. Depending on the dataset's compression settings (uncompressed, LZMA, or GZIP), it uses the appropriate reading functions to retrieve the parameter values.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
Returns
int32_t Returns 1 on successfully reading all binary parameters, or 0 if an error occurred.
Return values
1All parameters were successfully read and stored.
0An error occurred during the read operation, such as I/O errors, data type mismatches, or memory allocation failures.
Note
Parameters with the 'fixed_value' attribute are handled by scanning the fixed value string instead of reading from the file. String parameters are dynamically allocated and should be freed by the caller when no longer needed.

Definition at line 3072 of file SDDS_binary.c.

3072 {
3073 int32_t i;
3074 SDDS_LAYOUT *layout;
3075 /* char *predefined_format; */
3076 char buffer[SDDS_MAXLINE];
3077#if defined(zLib)
3078 gzFile gzfp = NULL;
3079#endif
3080 FILE *fp = NULL;
3081 struct lzmafile *lzmafp = NULL;
3082 SDDS_FILEBUFFER *fBuffer;
3083
3084 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryParameters"))
3085 return (0);
3086 layout = &SDDS_dataset->layout;
3087 if (!layout->n_parameters)
3088 return (1);
3089#if defined(zLib)
3090 if (SDDS_dataset->layout.gzipFile) {
3091 gzfp = layout->gzfp;
3092 } else {
3093#endif
3094 if (SDDS_dataset->layout.lzmaFile) {
3095 lzmafp = layout->lzmafp;
3096 } else {
3097 fp = layout->fp;
3098 }
3099#if defined(zLib)
3100 }
3101#endif
3102 fBuffer = &SDDS_dataset->fBuffer;
3103 for (i = 0; i < layout->n_parameters; i++) {
3104 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3105 continue;
3106 if (layout->parameter_definition[i].fixed_value) {
3107 strcpy(buffer, layout->parameter_definition[i].fixed_value);
3108 if (!SDDS_ScanData(buffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
3109 SDDS_SetError("Unable to read page--parameter scanning error (SDDS_ReadBinaryParameters)");
3110 return (0);
3111 }
3112 } else if (layout->parameter_definition[i].type == SDDS_STRING) {
3113 if (*(char **)SDDS_dataset->parameter[i])
3114 free(*(char **)SDDS_dataset->parameter[i]);
3115#if defined(zLib)
3116 if (SDDS_dataset->layout.gzipFile) {
3117 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3118 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
3119 return (0);
3120 }
3121 } else {
3122#endif
3123 if (SDDS_dataset->layout.lzmaFile) {
3124 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
3125 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
3126 return (0);
3127 }
3128 } else {
3129 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
3130 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
3131 return (0);
3132 }
3133 }
3134#if defined(zLib)
3135 }
3136#endif
3137 } else {
3138#if defined(zLib)
3139 if (SDDS_dataset->layout.gzipFile) {
3140 if (!SDDS_GZipBufferedRead(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3141 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3142 return (0);
3143 }
3144 } else {
3145#endif
3146 if (SDDS_dataset->layout.lzmaFile) {
3147 if (!SDDS_LZMABufferedRead(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], lzmafp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3148 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3149 return (0);
3150 }
3151 } else {
3152 if (!SDDS_BufferedRead(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], fp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3153 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3154 return (0);
3155 }
3156 }
3157#if defined(zLib)
3158 }
3159#endif
3160 }
3161 }
3162 return (1);
3163}

◆ SDDS_ReadBinaryRow()

int32_t SDDS_ReadBinaryRow ( SDDS_DATASET * SDDS_dataset,
int64_t row,
int32_t skip )
extern

Reads a binary row from the specified SDDS dataset.

This function reads a single row of data from the given SDDS dataset. Depending on the dataset's configuration, it handles uncompressed, LZMA-compressed, or GZIP-compressed files. For each column in the dataset, the function reads the appropriate data type. If a column is of type string, it reads the string using the corresponding string reading function. If the 'skip' parameter is set, the function skips reading the data without storing it.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]rowThe row number to read. Must be within the allocated range of rows in the dataset.
[in]skipIf non-zero, the function skips reading the data for each column without storing it.
Returns
int32_t Returns 1 on successful reading of the row, or 0 if an error occurred.
Return values
1The row was successfully read and stored (or skipped).
0An error occurred during reading, such as I/O errors or memory allocation failures.
Note
This function may modify the dataset's data structures by allocating memory for string columns. Ensure that the dataset is properly initialized and that memory is managed appropriately.

Definition at line 2836 of file SDDS_binary.c.

2836 {
2837 int64_t i, type, size;
2838 SDDS_LAYOUT *layout;
2839#if defined(zLib)
2840 gzFile gzfp;
2841#endif
2842 FILE *fp;
2843 struct lzmafile *lzmafp;
2844 SDDS_FILEBUFFER *fBuffer;
2845
2846 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryRow"))
2847 return (0);
2848 layout = &SDDS_dataset->layout;
2849 fBuffer = &SDDS_dataset->fBuffer;
2850
2851#if defined(zLib)
2852 if (SDDS_dataset->layout.gzipFile) {
2853 gzfp = layout->gzfp;
2854 for (i = 0; i < layout->n_columns; i++) {
2855 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2856 continue;
2857 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2858 if (!skip) {
2859 if (((char ***)SDDS_dataset->data)[i][row])
2860 free((((char ***)SDDS_dataset->data)[i][row]));
2861 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
2862 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2863 return (0);
2864 }
2865 } else {
2866 if (!SDDS_ReadGZipBinaryString(gzfp, fBuffer, 1)) {
2867 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2868 return 0;
2869 }
2870 }
2871 } else {
2872 size = SDDS_type_size[type - 1];
2873 if (!SDDS_GZipBufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2874 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2875 return (0);
2876 }
2877 }
2878 }
2879 } else {
2880#endif
2881 if (SDDS_dataset->layout.lzmaFile) {
2882 lzmafp = layout->lzmafp;
2883 for (i = 0; i < layout->n_columns; i++) {
2884 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2885 continue;
2886 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2887 if (!skip) {
2888 if (((char ***)SDDS_dataset->data)[i][row])
2889 free((((char ***)SDDS_dataset->data)[i][row]));
2890 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
2891 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2892 return (0);
2893 }
2894 } else {
2895 if (!SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 1)) {
2896 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2897 return 0;
2898 }
2899 }
2900 } else {
2901 size = SDDS_type_size[type - 1];
2902 if (!SDDS_LZMABufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2903 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2904 return (0);
2905 }
2906 }
2907 }
2908 } else {
2909 fp = layout->fp;
2910 for (i = 0; i < layout->n_columns; i++) {
2911 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2912 continue;
2913 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2914 if (!skip) {
2915 if (((char ***)SDDS_dataset->data)[i][row])
2916 free((((char ***)SDDS_dataset->data)[i][row]));
2917 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
2918 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2919 return (0);
2920 }
2921 } else {
2922 if (!SDDS_ReadBinaryString(fp, fBuffer, 1)) {
2923 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2924 return 0;
2925 }
2926 }
2927 } else {
2928 size = SDDS_type_size[type - 1];
2929 if (!SDDS_BufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2930 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2931 return (0);
2932 }
2933 }
2934 }
2935 }
2936#if defined(zLib)
2937 }
2938#endif
2939 return (1);
2940}

◆ SDDS_ReadBinaryString()

char * SDDS_ReadBinaryString ( FILE * fp,
SDDS_FILEBUFFER * fBuffer,
int32_t skip )
extern

Reads a binary string from a file with buffering.

This function reads a binary string from the specified file by first reading the length of the string and then reading the string content based on the length. If the 'skip' parameter is set, the string data is skipped over instead of being stored. The function allocates memory for the string, which should be freed by the caller when no longer needed.

Parameters
[in]fpThe file pointer to read from. Must be an open file in binary read mode.
[in,out]fBufferPointer to the file buffer used for buffered reading operations.
[in]skipIf non-zero, the string data is skipped without being stored.
Returns
char* Returns a pointer to the read null-terminated string on success, or NULL if an error occurred.
Return values
NULLAn error occurred during reading or memory allocation.
Non-NULLPointer to the read string.

Definition at line 2741 of file SDDS_binary.c.

2741 {
2742 int32_t length;
2743 char *string;
2744
2745 if (!SDDS_BufferedRead(&length, sizeof(length), fp, fBuffer, SDDS_LONG, 0) || length < 0)
2746 return (0);
2747 if (!(string = SDDS_Malloc(sizeof(*string) * (length + 1))))
2748 return (NULL);
2749 if (length && !SDDS_BufferedRead(skip ? NULL : string, sizeof(*string) * length, fp, fBuffer, SDDS_STRING, 0))
2750 return (NULL);
2751 string[length] = 0;
2752 return (string);
2753}

◆ SDDS_ReadLayout()

int32_t SDDS_ReadLayout ( SDDS_DATASET * SDDS_dataset,
FILE * fp )
extern

Reads the header layout of an SDDS dataset from a file.

Parameters
SDDS_datasetThe SDDS dataset structure to store the layout information.
fpThe file pointer to the SDDS file.
Returns
Returns 1 on success, 0 on failure.

Definition at line 518 of file SDDS_input.c.

518 {
519 char buffer[SDDS_MAXLINE];
520 char *groupName, *ptr;
521 FILE *fp1;
522 int32_t retval, bigEndianMachine;
523 uint32_t commentFlags;
524
525 if (!fp) {
526 SDDS_SetError("Unable to read layout--NULL file pointer (SDDS_ReadLayout)");
527 return (0);
528 }
529 if (SDDS_dataset->layout.depth == 0) {
530 if (SDDS_dataset->layout.disconnected) {
531 SDDS_SetError("Can't read layout--file is disconnected (SDDS_ReadLayout)");
532 return 0;
533 }
534 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadLayout")) {
535 fclose(fp);
536 return (0);
537 }
538 SDDS_dataset->layout.layout_written = 1; /* it is already in the file */
539 if (!fgets(SDDS_dataset->layout.s, SDDS_MAXLINE, fp)) {
540 fclose(fp);
541 SDDS_SetError("Unable to read layout--no header lines found (SDDS_ReadLayout)");
542 return (0);
543 }
544 if (strncmp(SDDS_dataset->layout.s, "SDDS", 4) != 0) {
545 fclose(fp);
546 SDDS_SetError("Unable to read layout--no header lines found (SDDS_ReadLayout)");
547 return (0);
548 }
549 if (sscanf(SDDS_dataset->layout.s + 4, "%" SCNd32, &SDDS_dataset->layout.version) != 1) {
550 fclose(fp);
551 SDDS_SetError("Unable to read layout--no version number on first line (SDDS_ReadLayout)");
552 return (0);
553 }
554 SDDS_ResetSpecialCommentsModes(SDDS_dataset);
555 SDDS_dataset->layout.data_command_seen = 0;
556 }
557 while (SDDS_GetNamelist(SDDS_dataset, SDDS_dataset->layout.s, SDDS_MAXLINE, fp)) {
558#if DEBUG
559 strcpy(buffer, SDDS_dataset->layout.s);
560#endif
561 groupName = SDDS_dataset->layout.s + 1;
562 if (!(ptr = strpbrk(SDDS_dataset->layout.s, " \t"))) {
563 SDDS_SetError("Unable to read layout---no groupname in namelist (SDDS_ReadLayout)");
564 return 0;
565 }
566 *ptr = 0;
567 switch (match_string(groupName, SDDS_command, SDDS_NUM_COMMANDS, EXACT_MATCH)) {
568 case SDDS_DESCRIPTION_COMMAND:
569 if (!SDDS_ProcessDescription(SDDS_dataset, ptr + 1)) {
570 fclose(fp);
571 SDDS_SetError("Unable to process description (SDDS_ReadLayout)");
572 return (0);
573 }
574 break;
575 case SDDS_COLUMN_COMMAND:
576 if (!SDDS_ProcessColumnDefinition(SDDS_dataset, ptr + 1)) {
577 fclose(fp);
578 SDDS_SetError("Unable to process column definition (SDDS_ReadLayout)");
579 return (0);
580 }
581 break;
582 case SDDS_PARAMETER_COMMAND:
583 if (!SDDS_ProcessParameterDefinition(SDDS_dataset, ptr + 1)) {
584 fclose(fp);
585 SDDS_SetError("Unable to process parameter definition (SDDS_ReadLayout)");
586 return (0);
587 }
588 break;
589 case SDDS_ASSOCIATE_COMMAND:
590#if RW_ASSOCIATES != 0
591 if (!SDDS_ProcessAssociateDefinition(SDDS_dataset, ptr + 1)) {
592 fclose(fp);
593 SDDS_SetError("Unable to process associate definition (SDDS_ReadLayout)");
594 return (0);
595 }
596#endif
597 break;
598 case SDDS_DATA_COMMAND:
599 if (!SDDS_ProcessDataMode(SDDS_dataset, ptr + 1)) {
600 fclose(fp);
601 SDDS_SetError("Unable to process data mode (SDDS_ReadLayout)");
602 return (0);
603 }
604 if (SDDS_dataset->layout.data_command_seen) {
605 /* should never happen */
606 fclose(fp);
607 SDDS_SetError("Unable to read layout--multiple data commands (SDDS_ReadLayout)");
608 return (0);
609 }
610 if (!SDDS_SaveLayout(SDDS_dataset)) {
611 SDDS_SetError("Unable to read layout--couldn't save layout (SDDS_ReadLayout)");
612 return (0);
613 }
614 SDDS_dataset->layout.data_command_seen = 1;
615 commentFlags = SDDS_GetSpecialCommentsModes(SDDS_dataset);
616 if ((commentFlags & SDDS_BIGENDIAN_SEEN) && (commentFlags & SDDS_LITTLEENDIAN_SEEN)) {
617 SDDS_SetError("Unable to read data as it says it is both big and little endian (SDDS_ReadLayout)");
618 return (0);
619 }
620 bigEndianMachine = SDDS_IsBigEndianMachine();
621 SDDS_dataset->swapByteOrder = SDDS_dataset->layout.byteOrderDeclared = 0;
622 SDDS_dataset->autoRecover = 0;
623 if ((commentFlags & SDDS_BIGENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_BIGENDIAN)) {
624 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN_SEEN;
625 if (!bigEndianMachine)
626 SDDS_dataset->swapByteOrder = 1;
627 }
628 if ((commentFlags & SDDS_LITTLEENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_LITTLEENDIAN)) {
629 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN_SEEN;
630 if (bigEndianMachine)
631 SDDS_dataset->swapByteOrder = 1;
632 }
633 if ((commentFlags & SDDS_FIXED_ROWCOUNT_SEEN) || (SDDS_dataset->layout.data_mode.fixed_row_count))
634 if (!SDDS_SetAutoReadRecovery(SDDS_dataset, SDDS_AUTOREADRECOVER))
635 return (0);
636 return (1);
637 case SDDS_INCLUDE_COMMAND:
638 if (!(fp1 = SDDS_ProcessIncludeCommand(SDDS_dataset, ptr + 1))) {
639 fclose(fp);
640 SDDS_SetError("Unable to process include command (SDDS_ReadLayout)");
641 return (0);
642 }
643 SDDS_dataset->layout.depth += 1;
644 retval = SDDS_ReadLayout(SDDS_dataset, fp1);
645 SDDS_dataset->layout.depth -= 1;
646 fclose(fp1);
647 if (retval == 0) {
648 return (0);
649 }
650 if (SDDS_dataset->layout.data_command_seen) {
651 return (1);
652 }
653 break;
654 case SDDS_ARRAY_COMMAND:
655 if (!SDDS_ProcessArrayDefinition(SDDS_dataset, ptr + 1)) {
656 fclose(fp);
657 SDDS_SetError("Unable to process array definition (SDDS_ReadLayout)");
658 return (0);
659 }
660 break;
661 default:
662 fclose(fp);
663 sprintf(buffer, "Unknown layout entry %s given (SDDS_ReadLayout)", groupName);
664 SDDS_SetError(buffer);
665 return (0);
666 }
667 }
668 /* on recursive calls, it's okay to hit EOF */
669 if ((feof(fp) && SDDS_dataset->layout.depth != 0) || SDDS_dataset->layout.data_command_seen)
670 return (1);
671 return (0);
672}
int32_t SDDS_GetNamelist(SDDS_DATASET *SDDS_dataset, char *buffer, int32_t buflen, FILE *fp)
Reads a namelist from a file into a buffer.
Definition SDDS_input.c:249

◆ SDDS_ReadNonNativeBinaryColumns()

int32_t SDDS_ReadNonNativeBinaryColumns ( SDDS_DATASET * SDDS_dataset)
extern

Reads the non-native endian binary columns from an SDDS dataset.

This function is similar to SDDS_ReadBinaryColumns but specifically handles columns with non-native endianness. It iterates through all column definitions within the specified SDDS dataset and reads their binary data from the underlying file, ensuring that the byte order is correctly swapped to match the system's native endianness. The function supports various compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
Returns
int32_t Returns 1 on successful reading and byte-swapping of all columns, or 0 if an error occurred.
Return values
1All non-native endian columns were successfully read and byte-swapped.
0An error occurred during the read or byte-swapping operation, such as I/O failures, memory allocation issues, or corrupted column definitions.
Note
This function assumes that the dataset's byte order has been declared and that the underlying file's byte order differs from the system's native byte order. Proper initialization and configuration of the SDDS_dataset structure are required before calling this function.

Definition at line 3590 of file SDDS_binary.c.

3590 {
3591 int64_t i, row;
3592 SDDS_LAYOUT *layout;
3593 /* char *predefined_format; */
3594 /* static char buffer[SDDS_MAXLINE]; */
3595#if defined(zLib)
3596 gzFile gzfp = NULL;
3597#endif
3598 FILE *fp = NULL;
3599 struct lzmafile *lzmafp = NULL;
3600 SDDS_FILEBUFFER *fBuffer;
3601
3602 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativeBinaryColumns"))
3603 return (0);
3604 layout = &SDDS_dataset->layout;
3605 if (!layout->n_columns || !SDDS_dataset->n_rows)
3606 return (1);
3607#if defined(zLib)
3608 if (SDDS_dataset->layout.gzipFile) {
3609 gzfp = layout->gzfp;
3610 } else {
3611#endif
3612 if (SDDS_dataset->layout.lzmaFile) {
3613 lzmafp = layout->lzmafp;
3614 } else {
3615 fp = layout->fp;
3616 }
3617#if defined(zLib)
3618 }
3619#endif
3620 fBuffer = &SDDS_dataset->fBuffer;
3621
3622 for (i = 0; i < layout->n_columns; i++) {
3623 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3624 continue;
3625 if (layout->column_definition[i].type == SDDS_STRING) {
3626#if defined(zLib)
3627 if (SDDS_dataset->layout.gzipFile) {
3628 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3629 if (((char ***)SDDS_dataset->data)[i][row])
3630 free((((char ***)SDDS_dataset->data)[i][row]));
3631 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
3632 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumns)");
3633 return (0);
3634 }
3635 }
3636 } else {
3637#endif
3638 if (SDDS_dataset->layout.lzmaFile) {
3639 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3640 if (((char ***)SDDS_dataset->data)[i][row])
3641 free((((char ***)SDDS_dataset->data)[i][row]));
3642 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeLZMABinaryString(lzmafp, fBuffer, 0))) {
3643 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3644 return (0);
3645 }
3646 }
3647 } else {
3648 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3649 if (((char ***)SDDS_dataset->data)[i][row])
3650 free((((char ***)SDDS_dataset->data)[i][row]));
3651 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeBinaryString(fp, fBuffer, 0))) {
3652 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3653 return (0);
3654 }
3655 }
3656 }
3657#if defined(zLib)
3658 }
3659#endif
3660 } else {
3661#if defined(zLib)
3662 if (SDDS_dataset->layout.gzipFile) {
3663 if (!SDDS_GZipBufferedRead(SDDS_dataset->data[i], SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, gzfp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3664 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3665 return (0);
3666 }
3667 } else {
3668#endif
3669 if (SDDS_dataset->layout.lzmaFile) {
3670 if (!SDDS_LZMABufferedRead(SDDS_dataset->data[i], SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, lzmafp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3671 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3672 return (0);
3673 }
3674 } else {
3675 if (!SDDS_BufferedRead(SDDS_dataset->data[i], SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, fp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3676 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3677 return (0);
3678 }
3679 }
3680#if defined(zLib)
3681 }
3682#endif
3683 }
3684 }
3685 return (1);
3686}
char * SDDS_ReadNonNativeLZMABinaryString(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a non-native endian binary string from an LZMA-compressed file.
char * SDDS_ReadNonNativeBinaryString(FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a non-native endian binary string from a file.

◆ SDDS_ReadNonNativeBinaryPageDetailed()

int32_t SDDS_ReadNonNativeBinaryPageDetailed ( SDDS_DATASET * SDDS_dataset,
int64_t sparse_interval,
int64_t sparse_offset,
int64_t last_rows )
extern

Reads a detailed non-native endian binary page from an SDDS dataset.

This function reads a binary page from the specified SDDS dataset, handling data with non-native endianness. It supports both sparse reading and reading of the last few rows based on the provided parameters. The function performs necessary byte order conversions to ensure correct data interpretation on the host system.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]sparse_intervalInterval between rows to be read for sparsity.
[in]sparse_offsetOffset to start reading rows for sparsity.
[in]last_rowsNumber of last rows to read from the dataset.
Returns
int32_t Returns the page number on success, or 0 on failure.
Return values
>0Page number successfully read.
0An error occurred during the read operation, such as I/O failures, data corruption, or unsupported data modes.
Note
This function handles various compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files. It manages memory allocation for parameters, arrays, and columns, ensuring that data is correctly stored and byte-swapped as necessary. The function also updates the dataset's row count and handles auto-recovery in case of errors.

Definition at line 4361 of file SDDS_binary.c.

4361 {
4362 int32_t n_rows32 = 0;
4363 int64_t n_rows, j, k, alloc_rows, rows_to_store, mod;
4364 /* int32_t page_number, i; */
4365#if defined(zLib)
4366 gzFile gzfp = NULL;
4367#endif
4368 FILE *fp = NULL;
4369 struct lzmafile *lzmafp = NULL;
4370 SDDS_FILEBUFFER *fBuffer;
4371
4372 /* static char s[SDDS_MAXLINE]; */
4373 n_rows = 0;
4374 SDDS_SetReadRecoveryMode(SDDS_dataset, 0);
4375#if defined(zLib)
4376 if (SDDS_dataset->layout.gzipFile) {
4377 gzfp = SDDS_dataset->layout.gzfp;
4378 } else {
4379#endif
4380 if (SDDS_dataset->layout.lzmaFile) {
4381 lzmafp = SDDS_dataset->layout.lzmafp;
4382 } else {
4383 fp = SDDS_dataset->layout.fp;
4384 }
4385#if defined(zLib)
4386 }
4387#endif
4388 fBuffer = &SDDS_dataset->fBuffer;
4389 if (!fBuffer->buffer) {
4390 int32_t bufferSize = SDDS_GetLockedDefaultIOBufferSize();
4391 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * bufferSize))) {
4392 SDDS_SetError("Unable to do buffered read--allocation failure");
4393 return 0;
4394 }
4395 fBuffer->bufferSize = bufferSize;
4396 fBuffer->bytesLeft = 0;
4397 }
4398 SDDS_dataset->rowcount_offset = -1;
4399#if defined(zLib)
4400 if (SDDS_dataset->layout.gzipFile) {
4401 if (!SDDS_GZipBufferedRead(&n_rows32, sizeof(n_rows32), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4402 if (gzeof(gzfp))
4403 return (SDDS_dataset->page_number = -1);
4404 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4405 return (0);
4406 }
4407 SDDS_SwapLong(&n_rows32);
4408 if (n_rows32 == INT32_MIN) {
4409 if (!SDDS_GZipBufferedRead(&n_rows, sizeof(n_rows), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4410 if (gzeof(gzfp))
4411 return (SDDS_dataset->page_number = -1);
4412 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4413 return (0);
4414 }
4415 SDDS_SwapLong64(&n_rows);
4416 } else {
4417 n_rows = n_rows32;
4418 }
4419 } else {
4420#endif
4421 /* This value will only be valid if read buffering is turned off, which is done for
4422 * certain append operations! Should really modify SDDS_BufferedRead and SDDS_BufferedWrite
4423 * to provide ftell capability.
4424 */
4425 if (SDDS_dataset->layout.lzmaFile) {
4426 if (!SDDS_LZMABufferedRead(&n_rows32, sizeof(n_rows32), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4427 if (lzma_eof(lzmafp))
4428 return (SDDS_dataset->page_number = -1);
4429 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4430 return (0);
4431 }
4432 SDDS_SwapLong(&n_rows32);
4433 if (n_rows32 == INT32_MIN) {
4434 if (!SDDS_LZMABufferedRead(&n_rows, sizeof(n_rows), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4435 if (lzma_eof(lzmafp))
4436 return (SDDS_dataset->page_number = -1);
4437 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4438 return (0);
4439 }
4440 SDDS_SwapLong64(&n_rows);
4441 } else {
4442 n_rows = n_rows32;
4443 }
4444 } else {
4445 SDDS_dataset->rowcount_offset = ftell(fp);
4446 if (!SDDS_BufferedRead(&n_rows32, sizeof(n_rows32), fp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4447 if (feof(fp))
4448 return (SDDS_dataset->page_number = -1);
4449 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4450 return (0);
4451 }
4452 SDDS_SwapLong(&n_rows32);
4453 if (n_rows32 == INT32_MIN) {
4454 if (!SDDS_BufferedRead(&n_rows, sizeof(n_rows), fp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4455 if (feof(fp))
4456 return (SDDS_dataset->page_number = -1);
4457 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4458 return (0);
4459 }
4460 SDDS_SwapLong64(&n_rows);
4461 } else {
4462 n_rows = n_rows32;
4463 }
4464 }
4465#if defined(zLib)
4466 }
4467#endif
4468 if (n_rows < 0) {
4469 SDDS_SetError("Unable to read page--negative number of rows (SDDS_ReadNonNativeBinaryPage)");
4470 return (0);
4471 }
4472 if (last_rows < 0)
4473 last_rows = 0;
4474 /* Fix this limitation later */
4475 if (SDDS_dataset->layout.data_mode.column_major) {
4476 sparse_interval = 1;
4477 sparse_offset = 0;
4478 last_rows = 0;
4479 }
4480 if (last_rows) {
4481 sparse_interval = 1;
4482 sparse_offset = n_rows - last_rows;
4483 rows_to_store = last_rows + 2;
4484 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4485 }
4486 if (sparse_interval <= 0)
4487 sparse_interval = 1;
4488 if (sparse_offset < 0)
4489 sparse_offset = 0;
4490
4491 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
4492 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4493 if (!SDDS_StartPage(SDDS_dataset, 0) || !SDDS_LengthenTable(SDDS_dataset, alloc_rows)) {
4494 SDDS_SetError("Unable to read page--couldn't start page (SDDS_ReadNonNativeBinaryPage)");
4495 return (0);
4496 }
4497
4498 /* read the parameter values */
4499 if (!SDDS_ReadNonNativeBinaryParameters(SDDS_dataset)) {
4500 SDDS_SetError("Unable to read page--parameter reading error (SDDS_ReadNonNativeBinaryPage)");
4501 return (0);
4502 }
4503
4504 /* read the array values */
4505 if (!SDDS_ReadNonNativeBinaryArrays(SDDS_dataset)) {
4506 SDDS_SetError("Unable to read page--array reading error (SDDS_ReadNonNativeBinaryPage)");
4507 return (0);
4508 }
4509 if (SDDS_dataset->layout.data_mode.column_major) {
4510 SDDS_dataset->n_rows = n_rows;
4511 if (!SDDS_ReadNonNativeBinaryColumns(SDDS_dataset)) {
4512 SDDS_SetError("Unable to read page--column reading error (SDDS_ReadNonNativeBinaryPage)");
4513 return (0);
4514 }
4515 SDDS_SwapEndsColumnData(SDDS_dataset);
4516 return (SDDS_dataset->page_number);
4517 }
4518 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
4519 for (j = 0; j < n_rows; j++) {
4520 if (!SDDS_ReadNonNativeBinaryRow(SDDS_dataset, j, 0)) {
4521 SDDS_dataset->n_rows = j - 1;
4522 if (SDDS_dataset->autoRecover) {
4524 SDDS_SwapEndsColumnData(SDDS_dataset);
4525 return (SDDS_dataset->page_number);
4526 }
4527 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4528 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
4529 return (0);
4530 }
4531 }
4532 SDDS_dataset->n_rows = j;
4533 SDDS_SwapEndsColumnData(SDDS_dataset);
4534 return (SDDS_dataset->page_number);
4535 } else {
4536 for (j = 0; j < sparse_offset; j++) {
4537 if (!SDDS_ReadNonNativeBinaryRow(SDDS_dataset, 0, 1)) {
4538 SDDS_dataset->n_rows = 0;
4539 if (SDDS_dataset->autoRecover) {
4541 SDDS_SwapEndsColumnData(SDDS_dataset);
4542 return (SDDS_dataset->page_number);
4543 }
4544 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4545 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
4546 return (0);
4547 }
4548 }
4549 n_rows -= sparse_offset;
4550 for (j = k = 0; j < n_rows; j++) {
4551 if (!SDDS_ReadNonNativeBinaryRow(SDDS_dataset, k, mod = j % sparse_interval)) {
4552 SDDS_dataset->n_rows = k - 1;
4553 if (SDDS_dataset->autoRecover) {
4555 SDDS_SwapEndsColumnData(SDDS_dataset);
4556 return (SDDS_dataset->page_number);
4557 }
4558 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4559 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
4560 return (0);
4561 }
4562 k += mod ? 0 : 1;
4563 }
4564 SDDS_dataset->n_rows = k;
4565 SDDS_SwapEndsColumnData(SDDS_dataset);
4566 return (SDDS_dataset->page_number);
4567 }
4568}
int32_t SDDS_SwapEndsColumnData(SDDS_DATASET *SDDSin)
Swaps the endianness of the column data in an SDDS dataset.
void SDDS_SwapLong64(int64_t *data)
Swaps the endianness of a 64-bit integer.
int32_t SDDS_ReadNonNativeBinaryColumns(SDDS_DATASET *SDDS_dataset)
Reads the non-native endian binary columns from an SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row, int32_t skip)
Reads a non-native endian binary row from an SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryParameters(SDDS_DATASET *SDDS_dataset)
Reads non-native endian binary parameters from an SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryArrays(SDDS_DATASET *SDDS_dataset)
Reads non-native endian binary arrays from an SDDS dataset.

◆ SDDS_ReadNonNativeBinaryPageLastRows()

int32_t SDDS_ReadNonNativeBinaryPageLastRows ( SDDS_DATASET * SDDS_dataset,
int64_t last_rows )
extern

Reads the last few rows from a non-native endian binary page in an SDDS dataset.

This function reads the specified number of last rows from a binary page in the given SDDS dataset, handling data with non-native endianness. It performs necessary byte order conversions to ensure correct data interpretation on the host system.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]last_rowsNumber of last rows to read from the dataset.
Returns
int32_t Returns the number of rows read on success, or 0 on failure.
Return values
>0Number of rows successfully read.
0An error occurred during the read operation, such as I/O failures, data corruption, or unsupported data modes.
Note
This function is a wrapper for SDDS_ReadNonNativeBinaryPageDetailed with specific parameters to read the last few rows. It should be used when only the most recent rows are needed.

Definition at line 4334 of file SDDS_binary.c.

4334 {
4335 return SDDS_ReadNonNativeBinaryPageDetailed(SDDS_dataset, 1, 0, last_rows);
4336}
int32_t SDDS_ReadNonNativeBinaryPageDetailed(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows)
Reads a detailed non-native endian binary page from an SDDS dataset.

◆ SDDS_ReadNonNativeLZMABinaryString()

char * SDDS_ReadNonNativeLZMABinaryString ( struct lzmafile * lzmafp,
SDDS_FILEBUFFER * fBuffer,
int32_t skip )

Reads a non-native endian binary string from an LZMA-compressed file.

This function reads a binary string from the specified LZMA-compressed file pointer, handling non-native endianness. It first reads the length of the string, swaps its byte order if necessary, allocates memory for the string, reads the string data, and null-terminates it.

Parameters
[in]lzmafpPointer to the LZMAFILE from which to read the string.
[in,out]fBufferPointer to the SDDS_FILEBUFFER structure used for buffered reading.
[in]skipIf non-zero, the function will skip reading the string data, useful for sparse reading.
Returns
char* Returns a pointer to the read string on success, or NULL if an error occurred.
Return values
Non-NULLPointer to the newly allocated string.
NULLAn error occurred during reading or memory allocation.
Note
The caller is responsible for freeing the returned string to prevent memory leaks.

Definition at line 5035 of file SDDS_binary.c.

5035 {
5036 int32_t length;
5037 char *string;
5038
5039 if (!SDDS_LZMABufferedRead(&length, sizeof(length), lzmafp, fBuffer, SDDS_LONG, 0))
5040 return (0);
5041 SDDS_SwapLong(&length);
5042 if (length < 0)
5043 return (0);
5044 if (!(string = SDDS_Malloc(sizeof(*string) * (length + 1))))
5045 return (NULL);
5046 if (length && !SDDS_LZMABufferedRead(skip ? NULL : string, sizeof(*string) * length, lzmafp, fBuffer, SDDS_STRING, 0))
5047 return (NULL);
5048 string[length] = 0;
5049 return (string);
5050}

◆ SDDS_ReadNonNativePageDetailed()

int32_t SDDS_ReadNonNativePageDetailed ( SDDS_DATASET * SDDS_dataset,
uint32_t mode,
int64_t sparse_interval,
int64_t sparse_offset,
int64_t last_rows )
extern

Reads a detailed non-native endian page from an SDDS dataset.

This function reads a page of data from the specified SDDS dataset, handling data with non-native endianness. It supports both ASCII and binary data modes, performing necessary byte order conversions to ensure correct data interpretation on the host system. Additionally, it allows for sparse reading and reading of the last few rows based on the provided parameters.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]modeMode flag to support future expansion.
[in]sparse_intervalInterval between rows to be read for sparsity.
[in]sparse_offsetOffset to start reading rows for sparsity.
[in]last_rowsNumber of last rows to read from the dataset.
Returns
int32_t Returns the number of rows read on success, or 0 on failure.
Return values
>0Number of rows successfully read.
0An error occurred during the read operation, such as I/O failures, data corruption, or unsupported data modes.
Note
This function handles various compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files. It manages memory allocation for parameters, arrays, and columns, ensuring that data is correctly stored and byte-swapped as necessary.

Definition at line 4182 of file SDDS_binary.c.

4184{
4185 int32_t retval;
4186 /* SDDS_LAYOUT layout_copy; */
4187
4188 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativePageDetailed"))
4189 return (0);
4190 if (SDDS_dataset->layout.disconnected) {
4191 SDDS_SetError("Can't read page--file is disconnected (SDDS_ReadNonNativePageDetailed)");
4192 return 0;
4193 }
4194#if defined(zLib)
4195 if (SDDS_dataset->layout.gzipFile) {
4196 if (!SDDS_dataset->layout.gzfp) {
4197 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4198 return (0);
4199 }
4200 } else {
4201#endif
4202 if (SDDS_dataset->layout.lzmaFile) {
4203 if (!SDDS_dataset->layout.lzmafp) {
4204 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4205 return (0);
4206 }
4207 } else {
4208 if (!SDDS_dataset->layout.fp) {
4209 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4210 return (0);
4211 }
4212 }
4213#if defined(zLib)
4214 }
4215#endif
4216 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
4217 if ((retval = SDDS_ReadAsciiPage(SDDS_dataset, sparse_interval, sparse_offset, 0)) < 1) {
4218 return (retval);
4219 }
4220 } else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
4221 if ((retval = SDDS_ReadNonNativeBinaryPage(SDDS_dataset, sparse_interval, sparse_offset)) < 1) {
4222 return (retval);
4223 }
4224 } else {
4225 SDDS_SetError("Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageDetailed)");
4226 return (0);
4227 }
4228 return (retval);
4229}
int32_t SDDS_ReadAsciiPage(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
Reads the next SDDS ASCII page into memory with optional data sparsity and statistics.
int32_t SDDS_ReadNonNativeBinaryPage(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset)
Reads a non-native endian binary page from an SDDS dataset.

◆ SDDS_ReadNonNativePageLastRows()

int32_t SDDS_ReadNonNativePageLastRows ( SDDS_DATASET * SDDS_dataset,
int64_t last_rows )
extern

Reads the last few rows from a non-native endian page in an SDDS dataset.

This function reads the specified number of last rows from the non-native endian page of the given SDDS dataset. It handles data with non-native endianness, performing necessary byte order conversions to ensure correct data interpretation on the host system.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]last_rowsNumber of last rows to read from the dataset.
Returns
int32_t Returns the number of rows read on success, or 0 on failure.
Return values
>0Number of rows successfully read.
0An error occurred during the read operation, such as I/O failures, data corruption, or unsupported data modes.
Note
This function is a wrapper for SDDS_ReadNonNativePageDetailed with specific parameters to read the last few rows. It should be used when only the most recent rows are needed.

Definition at line 4249 of file SDDS_binary.c.

4249 {
4250 int32_t retval;
4251 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativePageLastRows"))
4252 return (0);
4253 if (SDDS_dataset->layout.disconnected) {
4254 SDDS_SetError("Can't read page--file is disconnected (SDDS_ReadNonNativePageLastRows)");
4255 return 0;
4256 }
4257#if defined(zLib)
4258 if (SDDS_dataset->layout.gzipFile) {
4259 if (!SDDS_dataset->layout.gzfp) {
4260 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4261 return (0);
4262 }
4263 } else {
4264#endif
4265 if (SDDS_dataset->layout.lzmaFile) {
4266 if (!SDDS_dataset->layout.lzmafp) {
4267 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4268 return (0);
4269 }
4270 } else {
4271 if (!SDDS_dataset->layout.fp) {
4272 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4273 return (0);
4274 }
4275 }
4276#if defined(zLib)
4277 }
4278#endif
4279 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
4280 if ((retval = SDDS_ReadAsciiPageLastRows(SDDS_dataset, last_rows)) < 1) {
4281 return (retval);
4282 }
4283 } else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
4284 if ((retval = SDDS_ReadNonNativeBinaryPageLastRows(SDDS_dataset, last_rows)) < 1) {
4285 return (retval);
4286 }
4287 } else {
4288 SDDS_SetError("Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageLastRows)");
4289 return (0);
4290 }
4291 return (retval);
4292}
int32_t SDDS_ReadAsciiPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last specified number of rows from an ASCII page of an SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last few rows from a non-native endian binary page in an SDDS dataset.

◆ SDDS_ResetSpecialCommentsModes()

void SDDS_ResetSpecialCommentsModes ( SDDS_DATASET * SDDS_dataset)

Resets the special comments modes in the SDDS dataset.

This function clears all special comment flags that have been set within the dataset. After calling this function, the dataset will no longer have any special configurations related to comments.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset. The commentFlags field will be reset to 0.
Note
  • Use this function to clear all special configurations before setting new ones or when resetting the dataset's state.
Warning
  • This operation cannot be undone. Ensure that you no longer require the existing special comment configurations before resetting.
See also
SDDS_GetSpecialCommentsModes, SDDS_ParseSpecialComments

Definition at line 5312 of file SDDS_utils.c.

5312 {
5313 SDDS_dataset->layout.commentFlags = 0;
5314}

◆ SDDS_TransferRow()

int32_t SDDS_TransferRow ( SDDS_DATASET * SDDS_dataset,
int64_t target,
int64_t source )
extern

Transfers data from a source row to a target row within an SDDS dataset.

This function copies all column data from the specified source row to the target row in the provided SDDS dataset. It handles both string and non-string data types appropriately, ensuring that memory is managed correctly for string entries.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
targetThe index of the target row where data will be copied to.
sourceThe index of the source row from which data will be copied.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the row transfer was successful.
0Indicates that an error occurred (e.g., invalid dataset, out-of-range indices, memory allocation failure, string copy failure).
Note
  • Both target and source must be valid row indices within the dataset.
  • The function does not allocate or deallocate rows; it only copies data between existing rows.
See also
SDDS_DeleteUnsetRows, SDDS_CopyColumn

Definition at line 3803 of file SDDS_extract.c.

3803 {
3804 int32_t size;
3805 int64_t i;
3806 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_TransferRow"))
3807 return (0);
3808 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
3809 if (SDDS_dataset->layout.column_definition[i].type != SDDS_STRING) {
3810 size = SDDS_type_size[SDDS_dataset->layout.column_definition[i].type - 1];
3811 memcpy((char *)SDDS_dataset->data[i] + target * size, (char *)SDDS_dataset->data[i] + source * size, size);
3812 } else {
3813 if (((char ***)SDDS_dataset->data)[i][target])
3814 free(((char ***)SDDS_dataset->data)[i][target]);
3815 ((char ***)SDDS_dataset->data)[i][target] = NULL;
3816 if (!SDDS_CopyString(((char ***)SDDS_dataset->data)[i] + target, ((char ***)SDDS_dataset->data)[i][source]))
3817 return ((int32_t)0);
3818 }
3819 }
3820 return (1);
3821}
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
Definition SDDS_utils.c:922

◆ SDDS_UpdateAsciiPage()

int32_t SDDS_UpdateAsciiPage ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )
extern

Updates the current ASCII page of an SDDS dataset with new data.

This function updates the ASCII page of the provided SDDS dataset, appending any new rows that have been added since the last write. It handles updating the row count in the file and ensures data consistency. If the dataset is not currently writing a page, it initiates a new page write.

Parameters
SDDS_datasetPointer to the SDDS dataset to update.
modeMode flags that control the update behavior. Common modes include:
  • FLUSH_TABLE: Flushes the data table after writing.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
This function cannot be used with compressed files (GZIP or LZMA). It requires a regular ASCII file. It also handles updating internal state variables such as the number of rows written and the last row written.

Definition at line 2167 of file SDDS_ascii.c.

2167 {
2168 FILE *fp;
2169 int32_t code;
2170 int64_t i, rows, offset;
2171 SDDS_FILEBUFFER *fBuffer;
2172
2173#ifdef DEBUG
2174 fprintf(stderr, "%" PRId64 " virtual rows present, first=%" PRId32 "\n", SDDS_CountRowsOfInterest(SDDS_dataset), SDDS_dataset->first_row_in_mem);
2175#endif
2176 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_UpdateAsciiPage"))
2177 return (0);
2178#if defined(zLib)
2179 if (SDDS_dataset->layout.gzipFile) {
2180 SDDS_SetError("Unable to perform page updates on a gzip file (SDDS_UpdateAsciiPage)");
2181 return 0;
2182 }
2183#endif
2184 if (SDDS_dataset->layout.lzmaFile) {
2185 SDDS_SetError("Unable to perform page updates on an .lzma or .xz file (SDDS_UpdateAsciiPage)");
2186 return 0;
2187 }
2188 if (!SDDS_dataset->writing_page) {
2189 if (!(code = SDDS_WriteAsciiPage(SDDS_dataset)))
2190 return 0;
2191 if (mode & FLUSH_TABLE) {
2192 SDDS_FreeTableStrings(SDDS_dataset);
2193 SDDS_dataset->first_row_in_mem = SDDS_CountRowsOfInterest(SDDS_dataset);
2194 SDDS_dataset->last_row_written = -1;
2195 SDDS_dataset->n_rows = 0;
2196 }
2197 return code;
2198 }
2199 if (!(fp = SDDS_dataset->layout.fp)) {
2200 SDDS_SetError("Unable to update page--file pointer is NULL (SDDS_UpdateAsciiPage)");
2201 return (0);
2202 }
2203 fBuffer = &SDDS_dataset->fBuffer;
2204 if (!SDDS_FlushBuffer(fp, fBuffer)) {
2205 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateAsciiPage)");
2206 return 0;
2207 }
2208 offset = ftell(fp);
2209
2210 rows = SDDS_CountRowsOfInterest(SDDS_dataset) + SDDS_dataset->first_row_in_mem;
2211 if (rows == SDDS_dataset->n_rows_written)
2212 return (1);
2213 if (rows < SDDS_dataset->n_rows_written) {
2214 SDDS_SetError("Unable to update page--new number of rows less than previous number (SDDS_UpdateAsciiPage)");
2215 return (0);
2216 }
2217 if ((!SDDS_dataset->layout.data_mode.fixed_row_count) || (((rows + rows - SDDS_dataset->n_rows_written) / SDDS_dataset->layout.data_mode.fixed_row_increment) != (rows / SDDS_dataset->layout.data_mode.fixed_row_increment))) {
2218 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
2219 if (SDDS_fseek(fp, SDDS_dataset->rowcount_offset, SEEK_SET) == -1) {
2220 SDDS_SetError("Unable to update page--failure doing fseek (SDDS_UpdateAsciiPage)");
2221 return (0);
2222 }
2223 /* overwrite the existing row count */
2224 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
2225 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
2226 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
2227 }
2228 fprintf(fp, "%20" PRId64 "\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
2229 } else
2230 fprintf(fp, "%20" PRId64 "\n", rows);
2231 if (SDDS_fseek(fp, offset, SEEK_SET) == -1) {
2232 SDDS_SetError("Unable to update page--failure doing fseek to end of page (SDDS_UpdateAsciiPage)");
2233 return (0);
2234 }
2235 }
2236 }
2237 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++)
2238 if (SDDS_dataset->row_flag[i])
2239 SDDS_WriteAsciiRow(SDDS_dataset, i, fp);
2240 if (!SDDS_FlushBuffer(fp, fBuffer)) {
2241 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateAsciiPage)");
2242 return 0;
2243 }
2244 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
2245 SDDS_dataset->n_rows_written = rows;
2246 if (mode & FLUSH_TABLE) {
2247 SDDS_FreeTableStrings(SDDS_dataset);
2248 SDDS_dataset->first_row_in_mem = rows;
2249 SDDS_dataset->last_row_written = -1;
2250 SDDS_dataset->n_rows = 0;
2251 }
2252 return (1);
2253}
int32_t SDDS_WriteAsciiPage(SDDS_DATASET *SDDS_dataset)
Writes a page of data in ASCII format to the SDDS dataset.
Definition SDDS_ascii.c:410
int32_t SDDS_WriteAsciiRow(SDDS_DATASET *SDDS_dataset, int64_t row, FILE *fp)
Writes a single row of data in ASCII format to a file.
Definition SDDS_ascii.c:775
int32_t SDDS_FlushBuffer(FILE *fp, SDDS_FILEBUFFER *fBuffer)
int32_t SDDS_fseek(FILE *fp, int64_t offset, int32_t dir)
Sets the file position indicator for a given file stream with retry logic.
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
void SDDS_FreeTableStrings(SDDS_DATASET *SDDS_dataset)

◆ SDDS_UpdateBinaryPage()

int32_t SDDS_UpdateBinaryPage ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )
extern

Updates the binary page of an SDDS dataset.

This function updates the binary page of the specified SDDS dataset based on the provided mode. It handles writing the dataset's binary data to the associated file, managing buffering, and handling different file formats such as gzip and LZMA if applicable.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to update.
modeBitmask indicating the update mode. It can be:
  • 0 for a standard update.
  • FLUSH_TABLE to flush the table after updating.
Returns
  • Returns 1 on successful update.
  • Returns 0 if an error occurs during the update process.

The function performs several checks before updating:

  • Checks the environment variable SDDS_OUTPUT_ENDIANESS to determine if a non-native binary update is required.
  • Validates the dataset structure.
  • Ensures that the dataset is not using gzip or LZMA compression, or is not in column-major data mode.
  • Handles writing the binary page, updating row counts, and managing buffer flushing.
Note
  • The function is not thread-safe and should be called in a synchronized context.
  • Requires that the dataset has been properly initialized and populated with data.

Definition at line 1098 of file SDDS_binary.c.

1098 {
1099 FILE *fp;
1100 int64_t i, rows, offset, code, fixed_rows;
1101 int32_t min32 = INT32_MIN, rows32;
1102 SDDS_FILEBUFFER *fBuffer;
1103 char *outputEndianess = NULL;
1104
1105 if ((outputEndianess = getenv("SDDS_OUTPUT_ENDIANESS"))) {
1106 if (((strncmp(outputEndianess, "big", 3) == 0) && (SDDS_IsBigEndianMachine() == 0)) || ((strncmp(outputEndianess, "little", 6) == 0) && (SDDS_IsBigEndianMachine() == 1)))
1107 return SDDS_UpdateNonNativeBinaryPage(SDDS_dataset, mode);
1108 }
1109
1110#ifdef DEBUG
1111 fprintf(stderr, "%" PRId64 " virtual rows present, first=%" PRId64 "\n", SDDS_CountRowsOfInterest(SDDS_dataset), SDDS_dataset->first_row_in_mem);
1112#endif
1113 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_UpdateBinaryPage"))
1114 return (0);
1115#if defined(zLib)
1116 if (SDDS_dataset->layout.gzipFile) {
1117 SDDS_SetError("Unable to perform page updates on a gzip file (SDDS_UpdateBinaryPage)");
1118 return 0;
1119 }
1120#endif
1121 if (SDDS_dataset->layout.lzmaFile) {
1122 SDDS_SetError("Unable to perform page updates on an .lzma or .xz file (SDDS_UpdateBinaryPage)");
1123 return 0;
1124 }
1125 if (SDDS_dataset->layout.data_mode.column_major) {
1126 SDDS_SetError("Unable to perform page updates on column major order file. (SDDS_UpdateBinaryPage)");
1127 return 0;
1128 }
1129 if (!SDDS_dataset->writing_page) {
1130#ifdef DEBUG
1131 fprintf(stderr, "Page not being written---calling SDDS_UpdateBinaryPage\n");
1132#endif
1133 if (!(code = SDDS_WriteBinaryPage(SDDS_dataset)))
1134 return 0;
1135 if (mode & FLUSH_TABLE) {
1136 SDDS_FreeTableStrings(SDDS_dataset);
1137 SDDS_dataset->first_row_in_mem = SDDS_CountRowsOfInterest(SDDS_dataset);
1138 SDDS_dataset->last_row_written = -1;
1139 SDDS_dataset->n_rows = 0;
1140 }
1141 return code;
1142 }
1143
1144 if (!(fp = SDDS_dataset->layout.fp)) {
1145 SDDS_SetError("Unable to update page--file pointer is NULL (SDDS_UpdateBinaryPage)");
1146 return (0);
1147 }
1148 fBuffer = &SDDS_dataset->fBuffer;
1149 if (!SDDS_FlushBuffer(fp, fBuffer)) {
1150 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateBinaryPage)");
1151 return 0;
1152 }
1153 offset = ftell(fp);
1154
1155 rows = SDDS_CountRowsOfInterest(SDDS_dataset) + SDDS_dataset->first_row_in_mem;
1156#ifdef DEBUG
1157 fprintf(stderr, "%" PRId64 " rows stored in table, %" PRId64 " already written\n", rows, SDDS_dataset->n_rows_written);
1158#endif
1159 if (rows == SDDS_dataset->n_rows_written)
1160 return (1);
1161 if (rows < SDDS_dataset->n_rows_written) {
1162 SDDS_SetError("Unable to update page--new number of rows less than previous number (SDDS_UpdateBinaryPage)");
1163 return (0);
1164 }
1165 if ((!SDDS_dataset->layout.data_mode.fixed_row_count) || (((rows + rows - SDDS_dataset->n_rows_written) / SDDS_dataset->layout.data_mode.fixed_row_increment) != (rows / SDDS_dataset->layout.data_mode.fixed_row_increment))) {
1166 if (SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
1167 SDDS_SetError("Unable to update page--failure doing fseek (SDDS_UpdateBinaryPage)");
1168 return (0);
1169 }
1170 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1171 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
1172 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
1173 }
1174 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
1175#if defined(DEBUG)
1176 fprintf(stderr, "Setting %" PRId64 " fixed rows\n", fixed_rows);
1177#endif
1178 if ((fixed_rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
1179 SDDS_SetError("Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateBinaryPage)");
1180 return (0);
1181 }
1182 if (fixed_rows > INT32_MAX) {
1183 if (fwrite(&min32, sizeof(min32), 1, fp) != 1) {
1184 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1185 return (0);
1186 }
1187 if (fwrite(&fixed_rows, sizeof(fixed_rows), 1, fp) != 1) {
1188 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1189 return (0);
1190 }
1191 } else {
1192 rows32 = (int32_t)fixed_rows;
1193 if (fwrite(&rows32, sizeof(rows32), 1, fp) != 1) {
1194 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1195 return (0);
1196 }
1197 }
1198 } else {
1199#if defined(DEBUG)
1200 fprintf(stderr, "Setting %" PRId64 " rows\n", rows);
1201#endif
1202 if ((rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
1203 SDDS_SetError("Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateBinaryPage)");
1204 return (0);
1205 }
1206 if (rows > INT32_MAX) {
1207 if (fwrite(&min32, sizeof(min32), 1, fp) != 1) {
1208 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1209 return (0);
1210 }
1211 if (fwrite(&rows, sizeof(rows), 1, fp) != 1) {
1212 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1213 return (0);
1214 }
1215 } else {
1216 rows32 = (int32_t)rows;
1217 if (fwrite(&rows32, sizeof(rows32), 1, fp) != 1) {
1218 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1219 return (0);
1220 }
1221 }
1222 }
1223 if (SDDS_fseek(fp, offset, 0) == -1) {
1224 SDDS_SetError("Unable to update page--failure doing fseek to end of page (SDDS_UpdateBinaryPage)");
1225 return (0);
1226 }
1227 }
1228 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++)
1229 if (SDDS_dataset->row_flag[i] && !SDDS_WriteBinaryRow(SDDS_dataset, i)) {
1230 SDDS_SetError("Unable to update page--failure writing row (SDDS_UpdateBinaryPage)");
1231 return (0);
1232 }
1233#ifdef DEBUG
1234 fprintf(stderr, "Flushing buffer\n");
1235#endif
1236 if (!SDDS_FlushBuffer(fp, fBuffer)) {
1237 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateBinaryPage)");
1238 return 0;
1239 }
1240 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
1241 SDDS_dataset->n_rows_written = rows;
1242 if (mode & FLUSH_TABLE) {
1243 SDDS_FreeTableStrings(SDDS_dataset);
1244 SDDS_dataset->first_row_in_mem = rows;
1245 SDDS_dataset->last_row_written = -1;
1246 SDDS_dataset->n_rows = 0;
1247 }
1248 return (1);
1249}
int32_t SDDS_UpdateNonNativeBinaryPage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates a non-native endian binary page in an SDDS dataset.
int32_t SDDS_WriteBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row)
Writes a single binary row of an SDDS dataset to the associated file.
int32_t SDDS_WriteBinaryPage(SDDS_DATASET *SDDS_dataset)

◆ SDDS_UpdateNonNativeBinaryPage()

int32_t SDDS_UpdateNonNativeBinaryPage ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )
extern

Updates a non-native endian binary page in an SDDS dataset.

This function updates an existing binary page in the specified SDDS dataset, handling byte order reversal to convert between little-endian and big-endian formats. It supports updating rows based on the provided mode flags, such as flushing the table. The function ensures that the buffer is flushed before performing the update and writes any new rows that have been flagged for writing. It also handles fixed row counts and manages byte order conversions as necessary.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to update.
[in]modeBitmask indicating the update mode (e.g., FLUSH_TABLE).
Returns
int32_t Returns 1 on successful update of the binary page, or 0 if an error occurred.
Return values
1The binary page was successfully updated and byte-swapped.
0An error occurred during the update operation, such as I/O failures, invalid row counts, or corrupted dataset definitions.
Note
This function modifies the dataset's internal structures during the update process. Ensure that the dataset is properly initialized and opened for writing before invoking this function. After updating, the dataset's state is updated to reflect the changes made to the page.

Definition at line 5844 of file SDDS_binary.c.

5844 {
5845 FILE *fp;
5846 int32_t code, min32 = INT32_MIN, rows32;
5847 int64_t i, rows, offset, fixed_rows;
5848 SDDS_FILEBUFFER *fBuffer;
5849
5850 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_UpdateNonNativeBinaryPage"))
5851 return (0);
5852#if defined(zLib)
5853 if (SDDS_dataset->layout.gzipFile) {
5854 SDDS_SetError("Unable to perform page updates on a gzip file (SDDS_UpdateNonNativeBinaryPage)");
5855 return 0;
5856 }
5857#endif
5858 if (SDDS_dataset->layout.lzmaFile) {
5859 SDDS_SetError("Unable to perform page updates on .lzma or .xz files (SDDS_UpdateNonNativeBinaryPage)");
5860 return 0;
5861 }
5862 if (SDDS_dataset->layout.data_mode.column_major) {
5863 SDDS_SetError("Unable to perform page updates on a column major order file (SDDS_UpdateNonNativeBinaryPage)");
5864 return 0;
5865 }
5866 if (!SDDS_dataset->writing_page) {
5867#ifdef DEBUG
5868 fprintf(stderr, "Page not being written---calling SDDS_UpdateNonNativeBinaryPage\n");
5869#endif
5870 if (!(code = SDDS_WriteNonNativeBinaryPage(SDDS_dataset))) {
5871 return 0;
5872 }
5873 if (mode & FLUSH_TABLE) {
5874 SDDS_FreeTableStrings(SDDS_dataset);
5875 SDDS_dataset->first_row_in_mem = SDDS_CountRowsOfInterest(SDDS_dataset);
5876 SDDS_dataset->last_row_written = -1;
5877 SDDS_dataset->n_rows = 0;
5878 }
5879 return code;
5880 }
5881
5882 if (!(fp = SDDS_dataset->layout.fp)) {
5883 SDDS_SetError("Unable to update page--file pointer is NULL (SDDS_UpdateNonNativeBinaryPage)");
5884 return (0);
5885 }
5886 fBuffer = &SDDS_dataset->fBuffer;
5887 if (!SDDS_FlushBuffer(fp, fBuffer)) {
5888 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5889 return 0;
5890 }
5891 offset = ftell(fp);
5892
5893 rows = SDDS_CountRowsOfInterest(SDDS_dataset) + SDDS_dataset->first_row_in_mem;
5894#ifdef DEBUG
5895 fprintf(stderr, "%" PRId64 " rows stored in table, %" PRId32 " already written\n", rows, SDDS_dataset->n_rows_written);
5896#endif
5897 if (rows == SDDS_dataset->n_rows_written) {
5898 return (1);
5899 }
5900 if (rows < SDDS_dataset->n_rows_written) {
5901 SDDS_SetError("Unable to update page--new number of rows less than previous number (SDDS_UpdateNonNativeBinaryPage)");
5902 return (0);
5903 }
5904 SDDS_SwapLong(&min32);
5905 if ((!SDDS_dataset->layout.data_mode.fixed_row_count) || (((rows + rows - SDDS_dataset->n_rows_written) / SDDS_dataset->layout.data_mode.fixed_row_increment) != (rows / SDDS_dataset->layout.data_mode.fixed_row_increment))) {
5906 if (SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
5907 SDDS_SetError("Unable to update page--failure doing fseek (SDDS_UpdateNonNativeBinaryPage)");
5908 return (0);
5909 }
5910 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5911 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
5912 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
5913 }
5914 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5915#if defined(DEBUG)
5916 fprintf(stderr, "Setting %" PRId64 " fixed rows\n", fixed_rows);
5917#endif
5918 if ((fixed_rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5919 SDDS_SetError("Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5920 return (0);
5921 }
5922 if (fixed_rows > INT32_MAX) {
5923 if (fwrite(&min32, sizeof(min32), 1, fp) != 1) {
5924 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5925 return (0);
5926 }
5927 SDDS_SwapLong64(&fixed_rows);
5928 if (fwrite(&fixed_rows, sizeof(fixed_rows), 1, fp) != 1) {
5929 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5930 return (0);
5931 }
5932 SDDS_SwapLong64(&fixed_rows);
5933 } else {
5934 rows32 = (int32_t)fixed_rows;
5935 SDDS_SwapLong(&rows32);
5936 if (fwrite(&rows32, sizeof(rows32), 1, fp) != 1) {
5937 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5938 return (0);
5939 }
5940 }
5941 } else {
5942#if defined(DEBUG)
5943 fprintf(stderr, "Setting %" PRId64 " rows\n", rows);
5944#endif
5945 if ((rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5946 SDDS_SetError("Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5947 return (0);
5948 }
5949 if (rows > INT32_MAX) {
5950 if (fwrite(&min32, sizeof(min32), 1, fp) != 1) {
5951 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5952 return (0);
5953 }
5954 SDDS_SwapLong64(&rows);
5955 if (fwrite(&rows, sizeof(rows), 1, fp) != 1) {
5956 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5957 return (0);
5958 }
5959 SDDS_SwapLong64(&rows);
5960 } else {
5961 rows32 = (int32_t)rows;
5962 SDDS_SwapLong(&rows32);
5963 if (fwrite(&rows32, sizeof(rows32), 1, fp) != 1) {
5964 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5965 return (0);
5966 }
5967 }
5968 }
5969 if (SDDS_fseek(fp, offset, 0) == -1) {
5970 SDDS_SetError("Unable to update page--failure doing fseek to end of page (SDDS_UpdateNonNativeBinaryPage)");
5971 return (0);
5972 }
5973 }
5974 SDDS_SwapEndsColumnData(SDDS_dataset);
5975 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++) {
5976 if (SDDS_dataset->row_flag[i] && !SDDS_WriteNonNativeBinaryRow(SDDS_dataset, i)) {
5977 SDDS_SetError("Unable to update page--failure writing row (SDDS_UpdateNonNativeBinaryPage)");
5978 return (0);
5979 }
5980 }
5981 SDDS_SwapEndsColumnData(SDDS_dataset);
5982#ifdef DEBUG
5983 fprintf(stderr, "Flushing buffer\n");
5984#endif
5985 if (!SDDS_FlushBuffer(fp, fBuffer)) {
5986 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5987 return 0;
5988 }
5989 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
5990 SDDS_dataset->n_rows_written = rows;
5991 if (mode & FLUSH_TABLE) {
5992 SDDS_FreeTableStrings(SDDS_dataset);
5993 SDDS_dataset->first_row_in_mem = rows;
5994 SDDS_dataset->last_row_written = -1;
5995 SDDS_dataset->n_rows = 0;
5996 }
5997 return (1);
5998}
int32_t SDDS_WriteNonNativeBinaryPage(SDDS_DATASET *SDDS_dataset)
Writes a non-native endian binary page to an SDDS dataset.
int32_t SDDS_WriteNonNativeBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row)
Writes a non-native endian binary row to an SDDS dataset.

◆ SDDS_WriteArrayDefinition()

int32_t SDDS_WriteArrayDefinition ( ARRAY_DEFINITION * array_definition,
FILE * fp )
extern

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_WriteAsciiArrays()

int32_t SDDS_WriteAsciiArrays ( SDDS_DATASET * SDDS_dataset,
FILE * fp )
extern

Writes the arrays of an SDDS dataset in ASCII format to a file.

This function writes all arrays contained in the provided SDDS dataset to the specified file pointer in ASCII format. For each array, it writes the dimensions, a description line, and the array elements formatted according to their data type.

Parameters
SDDS_datasetPointer to the SDDS dataset containing the arrays to be written.
fpFile pointer to the ASCII file where the array data will be written.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
The function checks the dataset for consistency before writing. It uses SDDS_WriteTypedValue() to write each array element according to its data type. Each array element is written, with up to 6 elements per line.

Definition at line 635 of file SDDS_ascii.c.

635 {
636 int32_t i, j;
637 SDDS_LAYOUT *layout;
638 /* char *predefined_format; */
639 ARRAY_DEFINITION *array_definition;
640 SDDS_ARRAY *array;
641
642 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteAsciiArrays"))
643 return (0);
644 layout = &SDDS_dataset->layout;
645 for (j = 0; j < layout->n_arrays; j++) {
646 array_definition = layout->array_definition + j;
647 array = &SDDS_dataset->array[j];
648 for (i = 0; i < array_definition->dimensions; i++)
649 fprintf(fp, "%" PRId32 " ", array->dimension[i]);
650 fprintf(fp, " ! %" PRId32 "-dimensional array %s:\n", array_definition->dimensions, array_definition->name);
651 for (i = 0; i < array->elements;) {
652 if (!SDDS_WriteTypedValue(array->data, i, array_definition->type, NULL, fp)) {
653 SDDS_SetError("Unable to write array--couldn't write ASCII data (SDDS_WriteAsciiArrays)");
654 return (0);
655 }
656 i++;
657 if (i % 6 == 0 || i == array->elements)
658 fputc('\n', fp);
659 else
660 fputc(' ', fp);
661 }
662 }
663 return (1);
664}
int32_t SDDS_WriteTypedValue(void *data, int64_t index, int32_t type, char *format, FILE *fp)
Writes a typed value to an ASCII file stream.
Definition SDDS_ascii.c:57

◆ SDDS_WriteAsciiPage()

int32_t SDDS_WriteAsciiPage ( SDDS_DATASET * SDDS_dataset)
extern

Writes a page of data in ASCII format to the SDDS dataset.

This function writes the current page of data from the SDDS dataset to an ASCII file. It handles writing to regular files, as well as LZMA and GZIP compressed files if enabled. The function writes the page number, parameters, arrays, and rows of data according to the SDDS format.

Parameters
SDDS_datasetPointer to the SDDS dataset containing the data to be written.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
This function checks the dataset for consistency before writing. It also updates internal state variables such as the last row written and the number of rows written.

Definition at line 410 of file SDDS_ascii.c.

410 {
411#if defined(zLib)
412 gzFile gzfp;
413#endif
414 FILE *fp;
415 struct lzmafile *lzmafp;
416 int64_t i, rows;
417
418 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteAsciiPage"))
419 return (0);
420#if defined(zLib)
421 if (SDDS_dataset->layout.gzipFile) {
422 if (!(gzfp = SDDS_dataset->layout.gzfp)) {
423 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteAsciiPage)");
424 return (0);
425 }
426 if (SDDS_dataset->layout.data_mode.no_row_counts && (SDDS_dataset->page_number > 1 || SDDS_dataset->file_had_data))
427 gzputc(gzfp, '\n');
428 gzprintf(gzfp, "! page number %" PRId32 "\n", SDDS_dataset->page_number);
429
430 if (!SDDS_GZipWriteAsciiParameters(SDDS_dataset, gzfp) || !SDDS_GZipWriteAsciiArrays(SDDS_dataset, gzfp))
431 return 0;
432 rows = 0;
433 if (SDDS_dataset->layout.n_columns) {
434 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
435 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
436 SDDS_dataset->rowcount_offset = gztell(gzfp);
437 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
438 gzprintf(gzfp, "%20" PRId64 "\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
439 } else
440 gzprintf(gzfp, "%20" PRId64 "\n", rows);
441 }
442 for (i = 0; i < SDDS_dataset->n_rows; i++)
443 if (SDDS_dataset->row_flag[i] && !SDDS_GZipWriteAsciiRow(SDDS_dataset, i, gzfp))
444 return 0;
445 }
446 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
447 SDDS_dataset->n_rows_written = rows;
448 SDDS_dataset->writing_page = 1;
449 /*gzflush(gzfp, Z_FULL_FLUSH); */
450 } else {
451#endif
452 if (SDDS_dataset->layout.lzmaFile) {
453 if (!(lzmafp = SDDS_dataset->layout.lzmafp)) {
454 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteAsciiPage)");
455 return (0);
456 }
457 if (SDDS_dataset->layout.data_mode.no_row_counts && (SDDS_dataset->page_number > 1 || SDDS_dataset->file_had_data))
458 lzma_putc('\n', lzmafp);
459 lzma_printf(lzmafp, "! page number %" PRId32 "\n", SDDS_dataset->page_number);
460
461 if (!SDDS_LZMAWriteAsciiParameters(SDDS_dataset, lzmafp) || !SDDS_LZMAWriteAsciiArrays(SDDS_dataset, lzmafp))
462 return 0;
463 rows = 0;
464 if (SDDS_dataset->layout.n_columns) {
465 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
466 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
467 SDDS_dataset->rowcount_offset = lzma_tell(lzmafp);
468 if (SDDS_dataset->layout.data_mode.fixed_row_count)
469 lzma_printf(lzmafp, "%20" PRId64 "\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
470 else
471 lzma_printf(lzmafp, "%20" PRId64 "\n", rows);
472 }
473 for (i = 0; i < SDDS_dataset->n_rows; i++)
474 if (SDDS_dataset->row_flag[i] && !SDDS_LZMAWriteAsciiRow(SDDS_dataset, i, lzmafp))
475 return 0;
476 }
477 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
478 SDDS_dataset->n_rows_written = rows;
479 SDDS_dataset->writing_page = 1;
480 } else {
481 if (!(fp = SDDS_dataset->layout.fp)) {
482 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteAsciiPage)");
483 return (0);
484 }
485 if (SDDS_dataset->layout.data_mode.no_row_counts && (SDDS_dataset->page_number > 1 || SDDS_dataset->file_had_data))
486 fputc('\n', fp);
487 fprintf(fp, "! page number %" PRId32 "\n", SDDS_dataset->page_number);
488
489 if (!SDDS_WriteAsciiParameters(SDDS_dataset, fp) || !SDDS_WriteAsciiArrays(SDDS_dataset, fp))
490 return 0;
491 rows = 0;
492 if (SDDS_dataset->layout.n_columns) {
493 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
494 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
495 SDDS_dataset->rowcount_offset = ftell(fp);
496 if (SDDS_dataset->layout.data_mode.fixed_row_count)
497 fprintf(fp, "%20" PRId64 "\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
498 else
499 fprintf(fp, "%20" PRId64 "\n", rows);
500 }
501 for (i = 0; i < SDDS_dataset->n_rows; i++)
502 if (SDDS_dataset->row_flag[i] && !SDDS_WriteAsciiRow(SDDS_dataset, i, fp))
503 return 0;
504 }
505 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
506 SDDS_dataset->n_rows_written = rows;
507 SDDS_dataset->writing_page = 1;
508 fflush(fp);
509 }
510#if defined(zLib)
511 }
512#endif
513
514 return (1);
515}
int32_t SDDS_LZMAWriteAsciiArrays(SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
Writes the arrays of an SDDS dataset in ASCII format to an LZMA compressed file.
Definition SDDS_ascii.c:680
int32_t SDDS_LZMAWriteAsciiParameters(SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
Writes the parameter data of an SDDS dataset in ASCII format to an LZMA compressed file.
Definition SDDS_ascii.c:565
int32_t SDDS_WriteAsciiParameters(SDDS_DATASET *SDDS_dataset, FILE *fp)
Writes the parameter data of an SDDS dataset in ASCII format to a file.
Definition SDDS_ascii.c:531
int32_t SDDS_LZMAWriteAsciiRow(SDDS_DATASET *SDDS_dataset, int64_t row, struct lzmafile *lzmafp)
Writes a single row of data in ASCII format to an LZMA compressed file.
Definition SDDS_ascii.c:826
int32_t SDDS_WriteAsciiArrays(SDDS_DATASET *SDDS_dataset, FILE *fp)
Writes the arrays of an SDDS dataset in ASCII format to a file.
Definition SDDS_ascii.c:635

◆ SDDS_WriteAsciiParameters()

int32_t SDDS_WriteAsciiParameters ( SDDS_DATASET * SDDS_dataset,
FILE * fp )
extern

Writes the parameter data of an SDDS dataset in ASCII format to a file.

This function writes all parameters of the SDDS dataset to the provided file pointer in ASCII format. Only parameters that do not have fixed values are written. Each parameter value is written on a new line.

Parameters
SDDS_datasetPointer to the SDDS dataset containing the parameter data.
fpFile pointer to the ASCII file where the parameter data will be written.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
The function checks the dataset for consistency before writing. It uses SDDS_WriteTypedValue() to write each parameter value according to its data type.

Definition at line 531 of file SDDS_ascii.c.

531 {
532 int32_t i;
533 SDDS_LAYOUT *layout;
534 /* char *predefined_format; */
535
536 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteAsciiParameters"))
537 return (0);
538 layout = &SDDS_dataset->layout;
539 for (i = 0; i < layout->n_parameters; i++) {
540 if (layout->parameter_definition[i].fixed_value)
541 continue;
542 if (!SDDS_WriteTypedValue(SDDS_dataset->parameter[i], 0, layout->parameter_definition[i].type, NULL, fp)) {
543 SDDS_SetError("Unable to write ascii parameters (SDDS_WriteAsciiParameters)");
544 return 0;
545 }
546 fputc('\n', fp);
547 }
548 return (1);
549}

◆ SDDS_WriteAsciiRow()

int32_t SDDS_WriteAsciiRow ( SDDS_DATASET * SDDS_dataset,
int64_t row,
FILE * fp )
extern

Writes a single row of data in ASCII format to a file.

This function writes the specified row from the SDDS dataset to the provided file pointer in ASCII format. The data is formatted according to the data types of the columns. Supports multi-line rows as specified by the data mode settings in the dataset layout.

Parameters
SDDS_datasetPointer to the SDDS dataset containing the data.
rowZero-based index of the row to write.
fpFile pointer to the ASCII file where the row data will be written.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
The function checks the dataset for consistency before writing. It uses SDDS_WriteTypedValue() to write each column value according to its data type. The number of values per line is determined by the lines_per_row setting in the dataset layout.

Definition at line 775 of file SDDS_ascii.c.

775 {
776 int32_t newline_needed;
777 int64_t i, n_per_line, line;
778 /* int32_t embedded_quotes_present; */
779 SDDS_LAYOUT *layout;
780 /* char *predefined_format, *s; */
781
782 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteAsciiRow"))
783 return (0);
784 layout = &SDDS_dataset->layout;
785 if (SDDS_dataset->layout.data_mode.lines_per_row <= 0)
786 SDDS_dataset->layout.data_mode.lines_per_row = 1;
787 n_per_line = SDDS_dataset->layout.n_columns / SDDS_dataset->layout.data_mode.lines_per_row;
788 line = 1;
789 newline_needed = 0;
790 for (i = 0; i < layout->n_columns; i++) {
791 if (!SDDS_WriteTypedValue(SDDS_dataset->data[i], row, layout->column_definition[i].type, NULL, fp)) {
792 SDDS_SetError("Unable to write ascii row (SDDS_WriteAsciiRow)");
793 return 0;
794 }
795 if ((i + 1) % n_per_line == 0 && line != SDDS_dataset->layout.data_mode.lines_per_row) {
796 newline_needed = 0;
797 fputc('\n', fp);
798 line++;
799 } else {
800 fputc(' ', fp);
801 newline_needed = 1;
802 }
803 }
804 if (newline_needed)
805 fputc('\n', fp);
806 return (1);
807}

◆ SDDS_WriteAssociateDefinition()

int32_t SDDS_WriteAssociateDefinition ( ASSOCIATE_DEFINITION * associate_definition,
FILE * fp )
extern

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_WriteBinaryArrays()

int32_t SDDS_WriteBinaryArrays ( SDDS_DATASET * SDDS_dataset)
extern

Writes the binary arrays of the SDDS dataset to a file.

This function writes all arrays defined in the SDDS dataset to the associated binary file. It handles arrays with and without dimensions, and manages different compression formats such as gzip and LZMA if enabled.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset to write.
Returns
  • Returns 1 on successful write of all arrays.
  • Returns 0 if an error occurs during the writing process.

The function performs the following steps:

  • Validates the dataset structure.
  • Iterates over all arrays defined in the dataset layout.
  • For each array:
    • If the array has no dimensions, it writes zeroes for each defined dimension.
    • If the array has dimensions, it writes the dimension sizes using the appropriate compression method.
    • If the array type is SDDS_STRING, it writes each string element using the appropriate compression method.
    • Otherwise, it writes the array's data using buffered write functions.

The function handles different file formats:

  • For gzip files, it uses SDDS_GZipWriteBinaryString and SDDS_GZipBufferedWrite.
  • For LZMA files, it uses SDDS_LZMAWriteBinaryString and SDDS_LZMABufferedWrite.
  • For standard binary files, it uses SDDS_WriteBinaryString and SDDS_BufferedWrite.
Note
  • The function assumes that the dataset has been properly initialized and that all arrays are correctly allocated.
  • Compression support (zLib or LZMA) must be enabled during compilation for handling compressed files.

Definition at line 1554 of file SDDS_binary.c.

1554 {
1555 int32_t i, j, zero = 0;
1556 SDDS_LAYOUT *layout;
1557#if defined(zLib)
1558 gzFile gzfp;
1559#endif
1560 FILE *fp;
1561 struct lzmafile *lzmafp;
1562 SDDS_FILEBUFFER *fBuffer;
1563
1564 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryArrays"))
1565 return (0);
1566 layout = &SDDS_dataset->layout;
1567#if defined(zLib)
1568 if (SDDS_dataset->layout.gzipFile) {
1569 gzfp = layout->gzfp;
1570 fBuffer = &SDDS_dataset->fBuffer;
1571 for (i = 0; i < layout->n_arrays; i++) {
1572 if (!SDDS_dataset->array[i].dimension) {
1573 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1574 if (!SDDS_GZipBufferedWrite(&zero, sizeof(zero), gzfp, fBuffer)) {
1575 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1576 return 0;
1577 }
1578 continue;
1579 }
1580 if (!SDDS_GZipBufferedWrite(SDDS_dataset->array[i].dimension, sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, gzfp, fBuffer)) {
1581 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1582 return (0);
1583 }
1584 if (layout->array_definition[i].type == SDDS_STRING) {
1585 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1586 if (!SDDS_GZipWriteBinaryString(((char **)SDDS_dataset->array[i].data)[j], gzfp, fBuffer)) {
1587 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1588 return (0);
1589 }
1590 }
1591 } else if (!SDDS_GZipBufferedWrite(SDDS_dataset->array[i].data, SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, gzfp, fBuffer)) {
1592 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1593 return (0);
1594 }
1595 }
1596 } else {
1597#endif
1598 if (SDDS_dataset->layout.gzipFile) {
1599 lzmafp = layout->lzmafp;
1600 fBuffer = &SDDS_dataset->fBuffer;
1601 for (i = 0; i < layout->n_arrays; i++) {
1602 if (!SDDS_dataset->array[i].dimension) {
1603 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1604 if (!SDDS_LZMABufferedWrite(&zero, sizeof(zero), lzmafp, fBuffer)) {
1605 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1606 return 0;
1607 }
1608 continue;
1609 }
1610 if (!SDDS_LZMABufferedWrite(SDDS_dataset->array[i].dimension, sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, lzmafp, fBuffer)) {
1611 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1612 return (0);
1613 }
1614 if (layout->array_definition[i].type == SDDS_STRING) {
1615 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1616 if (!SDDS_LZMAWriteBinaryString(((char **)SDDS_dataset->array[i].data)[j], lzmafp, fBuffer)) {
1617 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1618 return (0);
1619 }
1620 }
1621 } else if (!SDDS_LZMABufferedWrite(SDDS_dataset->array[i].data, SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, lzmafp, fBuffer)) {
1622 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1623 return (0);
1624 }
1625 }
1626 } else {
1627 fp = layout->fp;
1628 fBuffer = &SDDS_dataset->fBuffer;
1629 for (i = 0; i < layout->n_arrays; i++) {
1630 if (!SDDS_dataset->array[i].dimension) {
1631 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1632 if (!SDDS_BufferedWrite(&zero, sizeof(zero), fp, fBuffer)) {
1633 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1634 return 0;
1635 }
1636 continue;
1637 }
1638 if (!SDDS_BufferedWrite(SDDS_dataset->array[i].dimension, sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, fp, fBuffer)) {
1639 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1640 return (0);
1641 }
1642 if (layout->array_definition[i].type == SDDS_STRING) {
1643 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1644 if (!SDDS_WriteBinaryString(((char **)SDDS_dataset->array[i].data)[j], fp, fBuffer)) {
1645 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1646 return (0);
1647 }
1648 }
1649 } else if (!SDDS_BufferedWrite(SDDS_dataset->array[i].data, SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, fp, fBuffer)) {
1650 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1651 return (0);
1652 }
1653 }
1654 }
1655#if defined(zLib)
1656 }
1657#endif
1658 return (1);
1659}
int32_t SDDS_BufferedWrite(void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer)
int32_t SDDS_LZMAWriteBinaryString(char *string, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
Writes a binary string to a file with LZMA compression.
int32_t SDDS_WriteBinaryString(char *string, FILE *fp, SDDS_FILEBUFFER *fBuffer)
Writes a binary string to a file with buffering.

◆ SDDS_WriteBinaryColumns()

int32_t SDDS_WriteBinaryColumns ( SDDS_DATASET * SDDS_dataset)
extern

Writes the binary columns of an SDDS dataset to the associated file.

This function iterates over each column defined in the SDDS dataset layout and writes its data to the binary file. It handles different data types, including strings and numeric types, and supports various compression formats such as gzip and LZMA if enabled.

Depending on the dataset's configuration, the function writes directly to a standard binary file, a gzip-compressed file, or an LZMA-compressed file. It also handles sparse data by only writing rows flagged for inclusion.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to write.
Returns
  • Returns 1 on successful writing of all columns.
  • Returns 0 if an error occurs during the writing process.

The function performs the following steps:

  • Validates the dataset structure using SDDS_CheckDataset.
  • Determines the file format (standard, gzip, LZMA) and initializes the corresponding file pointer.
  • Iterates through each column in the dataset:
    • For string columns, writes each string entry individually using the appropriate write function.
    • For numeric columns, writes the entire column data in a buffered manner if all rows are flagged; otherwise, writes individual row entries.
  • Handles errors by setting appropriate error messages and aborting the write operation.
Note
  • The function assumes that the dataset has been properly initialized and populated with data.
  • Compression support (zLib for gzip, LZMA libraries) must be enabled during compilation for handling compressed files.
  • The function is not thread-safe and should be called in a synchronized context.

Definition at line 1694 of file SDDS_binary.c.

1694 {
1695 int64_t i, row, rows, type, size;
1696 SDDS_LAYOUT *layout;
1697#if defined(zLib)
1698 gzFile gzfp;
1699#endif
1700 FILE *fp;
1701 struct lzmafile *lzmafp;
1702 SDDS_FILEBUFFER *fBuffer;
1703
1704 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryColumns"))
1705 return (0);
1706 layout = &SDDS_dataset->layout;
1707 fBuffer = &SDDS_dataset->fBuffer;
1708 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
1709#if defined(zLib)
1710 if (SDDS_dataset->layout.gzipFile) {
1711 gzfp = layout->gzfp;
1712 for (i = 0; i < layout->n_columns; i++) {
1713 type = layout->column_definition[i].type;
1714 size = SDDS_type_size[type - 1];
1715 if (type == SDDS_STRING) {
1716 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1717 if (SDDS_dataset->row_flag[row] && !SDDS_GZipWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1718 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1719 return (0);
1720 }
1721 }
1722 } else {
1723 if (rows == SDDS_dataset->n_rows) {
1724 if (!SDDS_GZipBufferedWrite(SDDS_dataset->data[i], size * rows, gzfp, fBuffer)) {
1725 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1726 return (0);
1727 }
1728 } else {
1729 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1730 if (SDDS_dataset->row_flag[row] && !SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1731 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1732 return (0);
1733 }
1734 }
1735 }
1736 }
1737 }
1738 } else {
1739#endif
1740 if (SDDS_dataset->layout.lzmaFile) {
1741 lzmafp = layout->lzmafp;
1742 for (i = 0; i < layout->n_columns; i++) {
1743 type = layout->column_definition[i].type;
1744 size = SDDS_type_size[type - 1];
1745 if (layout->column_definition[i].type == SDDS_STRING) {
1746 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1747 if (SDDS_dataset->row_flag[row] && !SDDS_LZMAWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), lzmafp, fBuffer)) {
1748 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1749 return (0);
1750 }
1751 }
1752 } else {
1753 if (rows == SDDS_dataset->n_rows) {
1754 if (!SDDS_LZMABufferedWrite(SDDS_dataset->data[i], size * rows, lzmafp, fBuffer)) {
1755 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1756 return (0);
1757 }
1758 } else {
1759 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1760 if (SDDS_dataset->row_flag[row] && !SDDS_LZMABufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
1761 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1762 return (0);
1763 }
1764 }
1765 }
1766 }
1767 }
1768 } else {
1769 fp = layout->fp;
1770 for (i = 0; i < layout->n_columns; i++) {
1771 type = layout->column_definition[i].type;
1772 size = SDDS_type_size[type - 1];
1773 if (layout->column_definition[i].type == SDDS_STRING) {
1774 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1775 if (SDDS_dataset->row_flag[row] && !SDDS_WriteBinaryString(*((char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
1776 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1777 return (0);
1778 }
1779 }
1780 } else {
1781 if (rows == SDDS_dataset->n_rows) {
1782 if (!SDDS_BufferedWrite(SDDS_dataset->data[i], size * rows, fp, fBuffer)) {
1783 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1784 return (0);
1785 }
1786 } else {
1787 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1788 if (SDDS_dataset->row_flag[row] && !SDDS_BufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
1789 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1790 return (0);
1791 }
1792 }
1793 }
1794 }
1795 }
1796 }
1797#if defined(zLib)
1798 }
1799#endif
1800 return (1);
1801}

◆ SDDS_WriteBinaryPage()

int32_t SDDS_WriteBinaryPage ( SDDS_DATASET * SDDS_dataset)
extern

Writes a binary page of data to an SDDS dataset, handling compression and buffering.

This function writes a binary page (including parameters, arrays, and row data) to the SDDS dataset pointed to by SDDS_dataset. It handles different file types, including regular files, LZMA-compressed files, and GZIP-compressed files, and uses buffering to improve write performance.

The function performs the following steps:

  • Checks for output endianess and writes a non-native binary page if needed.
  • Determines the number of rows to write and calculates any fixed row counts.
  • Writes the number of rows to the file.
  • Writes parameters, arrays, and column data using the appropriate write functions.
  • Flushes the buffer to ensure all data is written.

It uses the appropriate buffered write functions (SDDS_BufferedWrite, SDDS_LZMABufferedWrite, or SDDS_GZipBufferedWrite) depending on the file type.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the SDDS dataset to write to.
Returns
Returns 1 on success; returns 0 on error.
Note
The function sets error messages using SDDS_SetError if any step fails.

Definition at line 767 of file SDDS_binary.c.

767 {
768#if defined(zLib)
769 gzFile gzfp;
770#endif
771 FILE *fp;
772 struct lzmafile *lzmafp;
773 int64_t i, rows, fixed_rows;
774 int32_t min32 = INT32_MIN, rows32;
775 /* static char buffer[SDDS_MAXLINE]; */
776 SDDS_FILEBUFFER *fBuffer;
777 char *outputEndianess = NULL;
778
779 if ((outputEndianess = getenv("SDDS_OUTPUT_ENDIANESS"))) {
780 if (((strncmp(outputEndianess, "big", 3) == 0) && (SDDS_IsBigEndianMachine() == 0)) || ((strncmp(outputEndianess, "little", 6) == 0) && (SDDS_IsBigEndianMachine() == 1)))
781 return SDDS_WriteNonNativeBinaryPage(SDDS_dataset);
782 }
783
784 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryPage"))
785 return (0);
786
787#if defined(zLib)
788 if (SDDS_dataset->layout.gzipFile) {
789 if (!(gzfp = SDDS_dataset->layout.gzfp)) {
790 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteBinaryPage)");
791 return (0);
792 }
793 fBuffer = &SDDS_dataset->fBuffer;
794
795 if (!fBuffer->buffer) {
796 int32_t bufferSize = SDDS_GetLockedDefaultIOBufferSize();
797 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * (bufferSize + 1)))) {
798 SDDS_SetError("Unable to do buffered read--allocation failure (SDDS_WriteBinaryPage)");
799 return 0;
800 }
801 fBuffer->bufferSize = bufferSize;
802 fBuffer->bytesLeft = bufferSize;
803 }
804
805 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
806 SDDS_dataset->rowcount_offset = gztell(gzfp);
807 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
808 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
809 if (fixed_rows > INT32_MAX) {
810 if (!SDDS_GZipBufferedWrite(&min32, sizeof(min32), gzfp, fBuffer)) {
811 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
812 return (0);
813 }
814 if (!SDDS_GZipBufferedWrite(&fixed_rows, sizeof(fixed_rows), gzfp, fBuffer)) {
815 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
816 return (0);
817 }
818 } else {
819 rows32 = (int32_t)fixed_rows;
820 if (!SDDS_GZipBufferedWrite(&rows32, sizeof(rows32), gzfp, fBuffer)) {
821 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
822 return (0);
823 }
824 }
825 } else {
826 if (rows > INT32_MAX) {
827 if (!SDDS_GZipBufferedWrite(&min32, sizeof(min32), gzfp, fBuffer)) {
828 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
829 return (0);
830 }
831 if (!SDDS_GZipBufferedWrite(&rows, sizeof(rows), gzfp, fBuffer)) {
832 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
833 return (0);
834 }
835 } else {
836 rows32 = (int32_t)rows;
837 if (!SDDS_GZipBufferedWrite(&rows32, sizeof(rows32), gzfp, fBuffer)) {
838 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
839 return (0);
840 }
841 }
842 }
843 if (!SDDS_WriteBinaryParameters(SDDS_dataset)) {
844 SDDS_SetError("Unable to write page--parameter writing problem (SDDS_WriteBinaryPage)");
845 return 0;
846 }
847 if (!SDDS_WriteBinaryArrays(SDDS_dataset)) {
848 SDDS_SetError("Unable to write page--array writing problem (SDDS_WriteBinaryPage)");
849 return 0;
850 }
851 if (SDDS_dataset->layout.n_columns) {
852 if (SDDS_dataset->layout.data_mode.column_major) {
853 if (!SDDS_WriteBinaryColumns(SDDS_dataset)) {
854 SDDS_SetError("Unable to write page--column writing problem (SDDS_WriteBinaryPage)");
855 return 0;
856 }
857 } else {
858 for (i = 0; i < SDDS_dataset->n_rows; i++) {
859 if (SDDS_dataset->row_flag[i] && !SDDS_WriteBinaryRow(SDDS_dataset, i)) {
860 SDDS_SetError("Unable to write page--row writing problem (SDDS_WriteBinaryPage)");
861 return 0;
862 }
863 }
864 }
865 }
866 if (!SDDS_GZipFlushBuffer(gzfp, fBuffer)) {
867 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
868 return 0;
869 }
870 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
871 SDDS_dataset->n_rows_written = rows;
872 SDDS_dataset->writing_page = 1;
873 } else {
874#endif
875 if (SDDS_dataset->layout.lzmaFile) {
876 if (!(lzmafp = SDDS_dataset->layout.lzmafp)) {
877 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteBinaryPage)");
878 return (0);
879 }
880 fBuffer = &SDDS_dataset->fBuffer;
881
882 if (!fBuffer->buffer) {
883 int32_t bufferSize = SDDS_GetLockedDefaultIOBufferSize();
884 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * (bufferSize + 1)))) {
885 SDDS_SetError("Unable to do buffered read--allocation failure (SDDS_WriteBinaryPage)");
886 return 0;
887 }
888 fBuffer->bufferSize = bufferSize;
889 fBuffer->bytesLeft = bufferSize;
890 }
891 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
892 SDDS_dataset->rowcount_offset = lzma_tell(lzmafp);
893 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
894 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
895 if (fixed_rows > INT32_MAX) {
896 if (!SDDS_LZMABufferedWrite(&min32, sizeof(min32), lzmafp, fBuffer)) {
897 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
898 return (0);
899 }
900 if (!SDDS_LZMABufferedWrite(&fixed_rows, sizeof(fixed_rows), lzmafp, fBuffer)) {
901 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
902 return (0);
903 }
904 } else {
905 rows32 = (int32_t)fixed_rows;
906 if (!SDDS_LZMABufferedWrite(&rows32, sizeof(rows32), lzmafp, fBuffer)) {
907 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
908 return (0);
909 }
910 }
911 } else {
912 if (rows > INT32_MAX) {
913 if (!SDDS_LZMABufferedWrite(&min32, sizeof(min32), lzmafp, fBuffer)) {
914 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
915 return (0);
916 }
917 if (!SDDS_LZMABufferedWrite(&rows, sizeof(rows), lzmafp, fBuffer)) {
918 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
919 return (0);
920 }
921 } else {
922 rows32 = (int32_t)rows;
923 if (!SDDS_LZMABufferedWrite(&rows32, sizeof(rows32), lzmafp, fBuffer)) {
924 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
925 return (0);
926 }
927 }
928 }
929 if (!SDDS_WriteBinaryParameters(SDDS_dataset)) {
930 SDDS_SetError("Unable to write page--parameter writing problem (SDDS_WriteBinaryPage)");
931 return 0;
932 }
933 if (!SDDS_WriteBinaryArrays(SDDS_dataset)) {
934 SDDS_SetError("Unable to write page--array writing problem (SDDS_WriteBinaryPage)");
935 return 0;
936 }
937 if (SDDS_dataset->layout.n_columns) {
938 if (SDDS_dataset->layout.data_mode.column_major) {
939 if (!SDDS_WriteBinaryColumns(SDDS_dataset)) {
940 SDDS_SetError("Unable to write page--column writing problem (SDDS_WriteBinaryPage)");
941 return 0;
942 }
943 } else {
944 for (i = 0; i < SDDS_dataset->n_rows; i++) {
945 if (SDDS_dataset->row_flag[i] && !SDDS_WriteBinaryRow(SDDS_dataset, i)) {
946 SDDS_SetError("Unable to write page--row writing problem (SDDS_WriteBinaryPage)");
947 return 0;
948 }
949 }
950 }
951 }
952 if (!SDDS_LZMAFlushBuffer(lzmafp, fBuffer)) {
953 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
954 return 0;
955 }
956 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
957 SDDS_dataset->n_rows_written = rows;
958 SDDS_dataset->writing_page = 1;
959 } else {
960 if (!(fp = SDDS_dataset->layout.fp)) {
961 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteBinaryPage)");
962 return (0);
963 }
964 fBuffer = &SDDS_dataset->fBuffer;
965
966 if (!fBuffer->buffer) {
967 int32_t bufferSize = SDDS_GetLockedDefaultIOBufferSize();
968 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * (bufferSize + 1)))) {
969 SDDS_SetError("Unable to do buffered read--allocation failure (SDDS_WriteBinaryPage)");
970 return 0;
971 }
972 fBuffer->bufferSize = bufferSize;
973 fBuffer->bytesLeft = bufferSize;
974 }
975
976 /* Flush any existing data in the output buffer so we can determine the
977 * row count offset for the file. This is probably unnecessary.
978 */
979 if (!SDDS_FlushBuffer(fp, fBuffer)) {
980 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
981 return 0;
982 }
983
984 /* output the row count and determine its byte offset in the file */
985 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
986 SDDS_dataset->rowcount_offset = ftell(fp);
987 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
988 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
989#if defined(DEBUG)
990 fprintf(stderr, "setting %" PRId64 " fixed rows\n", fixed_rows);
991#endif
992 if (fixed_rows > INT32_MAX) {
993 if (!SDDS_BufferedWrite(&min32, sizeof(min32), fp, fBuffer)) {
994 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
995 return (0);
996 }
997 if (!SDDS_BufferedWrite(&fixed_rows, sizeof(fixed_rows), fp, fBuffer)) {
998 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
999 return (0);
1000 }
1001 } else {
1002 rows32 = (int32_t)fixed_rows;
1003 if (!SDDS_BufferedWrite(&rows32, sizeof(rows32), fp, fBuffer)) {
1004 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
1005 return (0);
1006 }
1007 }
1008 } else {
1009#if defined(DEBUG)
1010 fprintf(stderr, "setting %" PRId64 " rows\n", rows);
1011#endif
1012 if (rows > INT32_MAX) {
1013 if (!SDDS_BufferedWrite(&min32, sizeof(min32), fp, fBuffer)) {
1014 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
1015 return (0);
1016 }
1017 if (!SDDS_BufferedWrite(&rows, sizeof(rows), fp, fBuffer)) {
1018 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
1019 return (0);
1020 }
1021 } else {
1022 rows32 = (int32_t)rows;
1023 if (!SDDS_BufferedWrite(&rows32, sizeof(rows32), fp, fBuffer)) {
1024 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
1025 return (0);
1026 }
1027 }
1028 }
1029
1030 /* write the data, using buffered I/O */
1031 if (!SDDS_WriteBinaryParameters(SDDS_dataset)) {
1032 SDDS_SetError("Unable to write page--parameter writing problem (SDDS_WriteBinaryPage)");
1033 return 0;
1034 }
1035 if (!SDDS_WriteBinaryArrays(SDDS_dataset)) {
1036 SDDS_SetError("Unable to write page--array writing problem (SDDS_WriteBinaryPage)");
1037 return 0;
1038 }
1039 if (SDDS_dataset->layout.n_columns) {
1040 if (SDDS_dataset->layout.data_mode.column_major) {
1041 if (!SDDS_WriteBinaryColumns(SDDS_dataset)) {
1042 SDDS_SetError("Unable to write page--column writing problem (SDDS_WriteBinaryPage)");
1043 return 0;
1044 }
1045 } else {
1046 for (i = 0; i < SDDS_dataset->n_rows; i++) {
1047 if (SDDS_dataset->row_flag[i] && !SDDS_WriteBinaryRow(SDDS_dataset, i)) {
1048 SDDS_SetError("Unable to write page--row writing problem (SDDS_WriteBinaryPage)");
1049 return 0;
1050 }
1051 }
1052 }
1053 }
1054 /* flush the page */
1055 if (!SDDS_FlushBuffer(fp, fBuffer)) {
1056 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
1057 return 0;
1058 }
1059 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
1060 SDDS_dataset->n_rows_written = rows;
1061 SDDS_dataset->writing_page = 1;
1062 }
1063#if defined(zLib)
1064 }
1065#endif
1066 return (1);
1067}
int32_t SDDS_WriteBinaryColumns(SDDS_DATASET *SDDS_dataset)
Writes the binary columns of an SDDS dataset to the associated file.
int32_t SDDS_WriteBinaryArrays(SDDS_DATASET *SDDS_dataset)
Writes the binary arrays of the SDDS dataset to a file.
int32_t SDDS_WriteBinaryParameters(SDDS_DATASET *SDDS_dataset)
Writes the binary parameters of the SDDS dataset.
int32_t SDDS_LZMAFlushBuffer(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)

◆ SDDS_WriteBinaryParameters()

int32_t SDDS_WriteBinaryParameters ( SDDS_DATASET * SDDS_dataset)
extern

Writes the binary parameters of the SDDS dataset.

This function writes all non-fixed parameters of the SDDS dataset to the associated binary file. It handles different compression formats such as gzip and LZMA if enabled.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset to write.
Returns
  • Returns 1 on successful write of all parameters.
  • Returns 0 if an error occurs during the writing process.

The function performs the following steps:

  • Validates the dataset structure.
  • Iterates over all parameters defined in the dataset layout.
  • For each parameter:
    • If it is a fixed value, it is skipped.
    • If the parameter is of type SDDS_STRING, it writes the string using the appropriate compression method.
    • Otherwise, it writes the parameter's value using buffered write functions.

The function handles different file formats:

  • For gzip files, it uses SDDS_GZipWriteBinaryString and SDDS_GZipBufferedWrite.
  • For LZMA files, it uses SDDS_LZMAWriteBinaryString and SDDS_LZMABufferedWrite.
  • For standard binary files, it uses SDDS_WriteBinaryString and SDDS_BufferedWrite.
Note
  • The function assumes that the dataset has been properly initialized and that all parameters are correctly allocated.
  • Compression support (zLib or LZMA) must be enabled during compilation for handling compressed files.

Definition at line 1447 of file SDDS_binary.c.

1447 {
1448 int32_t i;
1449 SDDS_LAYOUT *layout;
1450 /* char *predefined_format; */
1451 /* static char buffer[SDDS_MAXLINE]; */
1452#if defined(zLib)
1453 gzFile gzfp;
1454#endif
1455 FILE *fp;
1456 struct lzmafile *lzmafp;
1457 SDDS_FILEBUFFER *fBuffer;
1458
1459 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryParameters"))
1460 return (0);
1461 layout = &SDDS_dataset->layout;
1462#if defined(zLib)
1463 if (SDDS_dataset->layout.gzipFile) {
1464 gzfp = layout->gzfp;
1465 fBuffer = &SDDS_dataset->fBuffer;
1466 for (i = 0; i < layout->n_parameters; i++) {
1467 if (layout->parameter_definition[i].fixed_value)
1468 continue;
1469 if (layout->parameter_definition[i].type == SDDS_STRING) {
1470 if (!SDDS_GZipWriteBinaryString(*((char **)SDDS_dataset->parameter[i]), gzfp, fBuffer)) {
1471 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1472 return (0);
1473 }
1474 } else if (!SDDS_GZipBufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer)) {
1475 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1476 return (0);
1477 }
1478 }
1479 } else {
1480#endif
1481 if (SDDS_dataset->layout.lzmaFile) {
1482 lzmafp = layout->lzmafp;
1483 fBuffer = &SDDS_dataset->fBuffer;
1484 for (i = 0; i < layout->n_parameters; i++) {
1485 if (layout->parameter_definition[i].fixed_value)
1486 continue;
1487 if (layout->parameter_definition[i].type == SDDS_STRING) {
1488 if (!SDDS_LZMAWriteBinaryString(*((char **)SDDS_dataset->parameter[i]), lzmafp, fBuffer)) {
1489 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1490 return (0);
1491 }
1492 } else if (!SDDS_LZMABufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], lzmafp, fBuffer)) {
1493 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1494 return (0);
1495 }
1496 }
1497 } else {
1498 fp = layout->fp;
1499 fBuffer = &SDDS_dataset->fBuffer;
1500 for (i = 0; i < layout->n_parameters; i++) {
1501 if (layout->parameter_definition[i].fixed_value)
1502 continue;
1503 if (layout->parameter_definition[i].type == SDDS_STRING) {
1504 if (!SDDS_WriteBinaryString(*((char **)SDDS_dataset->parameter[i]), fp, fBuffer)) {
1505 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1506 return (0);
1507 }
1508 } else if (!SDDS_BufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], fp, fBuffer)) {
1509 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1510 return (0);
1511 }
1512 }
1513 }
1514#if defined(zLib)
1515 }
1516#endif
1517 return (1);
1518}

◆ SDDS_WriteBinaryRow()

int32_t SDDS_WriteBinaryRow ( SDDS_DATASET * SDDS_dataset,
int64_t row )
extern

Writes a single binary row of an SDDS dataset to the associated file.

This function writes the data of a specified row within the SDDS dataset to the binary file. It handles different data types, including strings and numeric types, and supports various compression formats such as gzip and LZMA if enabled.

Depending on the dataset's configuration, the function writes directly to a standard binary file, a gzip-compressed file, or an LZMA-compressed file.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
rowThe zero-based index of the row to write.
Returns
  • Returns 1 on successful writing of the row.
  • Returns 0 if an error occurs during the writing process.

The function performs the following steps:

  • Validates the dataset structure using SDDS_CheckDataset.
  • Determines the file format (standard, gzip, LZMA) and initializes the corresponding file pointer.
  • Iterates through each column in the dataset:
    • For string columns, writes the string entry of the specified row using the appropriate write function.
    • For numeric columns, writes the data of the specified row using buffered write functions.
  • Handles errors by setting appropriate error messages and aborting the write operation.
Note
  • The function assumes that the dataset has been properly initialized and that the specified row exists.
  • Compression support (zLib for gzip, LZMA libraries) must be enabled during compilation for handling compressed files.
  • The function is not thread-safe and should be called in a synchronized context.

Definition at line 1978 of file SDDS_binary.c.

1978 {
1979 int64_t i, type, size;
1980 SDDS_LAYOUT *layout;
1981#if defined(zLib)
1982 gzFile gzfp;
1983#endif
1984 FILE *fp;
1985 struct lzmafile *lzmafp;
1986 SDDS_FILEBUFFER *fBuffer;
1987
1988 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryRow"))
1989 return (0);
1990 layout = &SDDS_dataset->layout;
1991#if defined(zLib)
1992 if (SDDS_dataset->layout.gzipFile) {
1993 gzfp = layout->gzfp;
1994 fBuffer = &SDDS_dataset->fBuffer;
1995 for (i = 0; i < layout->n_columns; i++) {
1996 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
1997 if (!SDDS_GZipWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1998 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
1999 return (0);
2000 }
2001 } else {
2002 size = SDDS_type_size[type - 1];
2003 if (!SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
2004 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
2005 return (0);
2006 }
2007 }
2008 }
2009 } else {
2010#endif
2011 if (SDDS_dataset->layout.lzmaFile) {
2012 lzmafp = layout->lzmafp;
2013 fBuffer = &SDDS_dataset->fBuffer;
2014 for (i = 0; i < layout->n_columns; i++) {
2015 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2016 if (!SDDS_LZMAWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), lzmafp, fBuffer)) {
2017 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
2018 return (0);
2019 }
2020 } else {
2021 size = SDDS_type_size[type - 1];
2022 if (!SDDS_LZMABufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
2023 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
2024 return (0);
2025 }
2026 }
2027 }
2028 } else {
2029 fp = layout->fp;
2030 fBuffer = &SDDS_dataset->fBuffer;
2031 for (i = 0; i < layout->n_columns; i++) {
2032 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2033 if (!SDDS_WriteBinaryString(*((char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
2034 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
2035 return (0);
2036 }
2037 } else {
2038 size = SDDS_type_size[type - 1];
2039 if (!SDDS_BufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
2040 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
2041 return (0);
2042 }
2043 }
2044 }
2045 }
2046#if defined(zLib)
2047 }
2048#endif
2049 return (1);
2050}

◆ SDDS_WriteColumnDefinition()

int32_t SDDS_WriteColumnDefinition ( COLUMN_DEFINITION * column_definition,
FILE * fp )
extern

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 )
extern

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 )
extern

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_WriteNonNativeBinaryColumns()

int32_t SDDS_WriteNonNativeBinaryColumns ( SDDS_DATASET * SDDS_dataset)
extern

Writes non-native endian binary columns of an SDDS dataset to the associated file.

This function iterates over each column defined in the SDDS dataset layout and writes its data to the binary file using a non-native byte order. It handles different data types, including strings and numeric types, and supports various compression formats such as gzip and LZMA if enabled.

Depending on the dataset's configuration, the function writes directly to a standard binary file, a gzip-compressed file, or an LZMA-compressed file. It also handles sparse data by only writing rows flagged for inclusion.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to write.
Returns
  • Returns 1 on successful writing of all columns.
  • Returns 0 if an error occurs during the writing process.

The function performs the following steps:

  • Validates the dataset structure using SDDS_CheckDataset.
  • Determines the file format (standard, gzip, LZMA) and initializes the corresponding file pointer.
  • Iterates through each column in the dataset:
    • For string columns, writes each string entry individually using the appropriate non-native write function.
    • For numeric columns, writes the entire column data in a buffered manner if all rows are flagged; otherwise, writes individual row entries.
  • Handles errors by setting appropriate error messages and aborting the write operation.
Note
  • The function assumes that the dataset has been properly initialized and populated with data.
  • Compression support (zLib for gzip, LZMA libraries) must be enabled during compilation for handling compressed files.
  • The function is not thread-safe and should be called in a synchronized context.

Definition at line 1837 of file SDDS_binary.c.

1837 {
1838 int64_t i, row, rows, size, type;
1839 SDDS_LAYOUT *layout;
1840#if defined(zLib)
1841 gzFile gzfp;
1842#endif
1843 FILE *fp;
1844 struct lzmafile *lzmafp;
1845 SDDS_FILEBUFFER *fBuffer;
1846
1847 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteNonNativeBinaryColumns"))
1848 return (0);
1849 layout = &SDDS_dataset->layout;
1850 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
1851 fBuffer = &SDDS_dataset->fBuffer;
1852#if defined(zLib)
1853 if (SDDS_dataset->layout.gzipFile) {
1854 gzfp = layout->gzfp;
1855 for (i = 0; i < layout->n_columns; i++) {
1856 type = layout->column_definition[i].type;
1857 size = SDDS_type_size[type - 1];
1858 if (type == SDDS_STRING) {
1859 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1860 if (SDDS_dataset->row_flag[row] && !SDDS_GZipWriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1861 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1862 return (0);
1863 }
1864 }
1865 } else {
1866 if (rows == SDDS_dataset->n_rows) {
1867 if (!SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i], size * rows, gzfp, fBuffer)) {
1868 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1869 return (0);
1870 }
1871 } else {
1872 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1873 if (SDDS_dataset->row_flag[row] && !SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1874 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1875 return (0);
1876 }
1877 }
1878 }
1879 }
1880 }
1881 } else {
1882#endif
1883 if (SDDS_dataset->layout.lzmaFile) {
1884 lzmafp = layout->lzmafp;
1885 for (i = 0; i < layout->n_columns; i++) {
1886 type = layout->column_definition[i].type;
1887 size = SDDS_type_size[type - 1];
1888 if (type == SDDS_STRING) {
1889 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1890 if (SDDS_dataset->row_flag[row] && !SDDS_LZMAWriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), lzmafp, fBuffer)) {
1891 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1892 return (0);
1893 }
1894 }
1895 } else {
1896 if (rows == SDDS_dataset->n_rows) {
1897 if (!SDDS_LZMABufferedWrite(SDDS_dataset->data[i], size * rows, lzmafp, fBuffer)) {
1898 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1899 return (0);
1900 }
1901 } else {
1902 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1903 if (SDDS_dataset->row_flag[row] && !SDDS_LZMABufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
1904 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1905 return (0);
1906 }
1907 }
1908 }
1909 }
1910 }
1911 } else {
1912 fp = layout->fp;
1913 for (i = 0; i < layout->n_columns; i++) {
1914 type = layout->column_definition[i].type;
1915 size = SDDS_type_size[type - 1];
1916 if (type == SDDS_STRING) {
1917 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1918 if (SDDS_dataset->row_flag[row] && !SDDS_WriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
1919 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1920 return (0);
1921 }
1922 }
1923 } else {
1924 if (rows == SDDS_dataset->n_rows) {
1925 if (!SDDS_BufferedWrite(SDDS_dataset->data[i], size * rows, fp, fBuffer)) {
1926 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1927 return (0);
1928 }
1929 } else {
1930 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1931 if (SDDS_dataset->row_flag[row] && !SDDS_BufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
1932 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1933 return (0);
1934 }
1935 }
1936 }
1937 }
1938 }
1939 }
1940#if defined(zLib)
1941 }
1942#endif
1943 return (1);
1944}
int32_t SDDS_WriteNonNativeBinaryString(char *string, FILE *fp, SDDS_FILEBUFFER *fBuffer)
Writes a non-native endian binary string to a file.
int32_t SDDS_LZMAWriteNonNativeBinaryString(char *string, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
Writes a non-native endian binary string to an LZMA-compressed file.

◆ SDDS_WriteParameterDefinition()

int32_t SDDS_WriteParameterDefinition ( PARAMETER_DEFINITION * parameter_definition,
FILE * fp )
extern

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 )
extern

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}

◆ UnpackLZMAOpen()

void * UnpackLZMAOpen ( char * filename)

Definition at line 438 of file SDDS_lzma.c.

438 {
439 if (!filename)
440 return NULL;
441 return lzma_open(filename, "rb");
442}