SDDSlib
Loading...
Searching...
No Matches
SDDS_internal.h File Reference

Internal definitions and function declarations for SDDS with LZMA support. More...

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

Go to the source code of this file.

Classes

struct  lzmafile
 

Macros

#define LZMA_BUF_SIZE   4096
 
#define TABLE_LENGTH_INCREMENT   100
 
#define SDDS_DESCRIPTION_COMMAND   0
 
#define SDDS_COLUMN_COMMAND   1
 
#define SDDS_PARAMETER_COMMAND   2
 
#define SDDS_ASSOCIATE_COMMAND   3
 
#define SDDS_DATA_COMMAND   4
 
#define SDDS_INCLUDE_COMMAND   5
 
#define SDDS_ARRAY_COMMAND   6
 
#define SDDS_NUM_COMMANDS   7
 

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

Variables

char * SDDS_command [SDDS_NUM_COMMANDS]
 Array of supported SDDS command names.
 

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.

Macro Definition Documentation

◆ LZMA_BUF_SIZE

#define LZMA_BUF_SIZE   4096

Definition at line 62 of file SDDS_internal.h.

◆ SDDS_ARRAY_COMMAND

#define SDDS_ARRAY_COMMAND   6

Definition at line 209 of file SDDS_internal.h.

◆ SDDS_ASSOCIATE_COMMAND

#define SDDS_ASSOCIATE_COMMAND   3

Definition at line 206 of file SDDS_internal.h.

◆ SDDS_COLUMN_COMMAND

#define SDDS_COLUMN_COMMAND   1

Definition at line 204 of file SDDS_internal.h.

◆ SDDS_DATA_COMMAND

#define SDDS_DATA_COMMAND   4

Definition at line 207 of file SDDS_internal.h.

◆ SDDS_DESCRIPTION_COMMAND

#define SDDS_DESCRIPTION_COMMAND   0

Definition at line 203 of file SDDS_internal.h.

◆ SDDS_INCLUDE_COMMAND

#define SDDS_INCLUDE_COMMAND   5

Definition at line 208 of file SDDS_internal.h.

◆ SDDS_NUM_COMMANDS

#define SDDS_NUM_COMMANDS   7

Definition at line 210 of file SDDS_internal.h.

◆ SDDS_PARAMETER_COMMAND

#define SDDS_PARAMETER_COMMAND   2

Definition at line 205 of file SDDS_internal.h.

◆ TABLE_LENGTH_INCREMENT

#define TABLE_LENGTH_INCREMENT   100

Definition at line 88 of file SDDS_internal.h.

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 1528 of file SDDS_utils.c.

1528 {
1529 while (lzma_gets(s, slen, lzmafp)) {
1530 if (s[0] != skip_char) {
1531 SDDS_CutOutComments(SDDS_dataset, s, skip_char);
1532 return (s);
1533 } else if (s[1] == '#') {
1534 SDDS_ParseSpecialComments(SDDS_dataset, s + 2);
1535 }
1536 }
1537 return (NULL);
1538}
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 1560 of file SDDS_utils.c.

1560 {
1561 int32_t spaceLeft, length, newLine;
1562 char *sInsert, *fgetsReturn;
1563
1564 sInsert = *s;
1565 spaceLeft = *slen;
1566 newLine = 1;
1567 while ((fgetsReturn = lzma_gets(sInsert, spaceLeft, lzmafp))) {
1568 if (newLine && sInsert[0] == '!')
1569 continue;
1570 SDDS_CutOutComments(SDDS_dataset, sInsert, skip_char);
1571 length = strlen(sInsert);
1572 if (sInsert[length - 1] != '\n' && !lzma_eof(lzmafp)) {
1573 /* buffer wasn't long enough to get the whole line. Resize and add more data. */
1574 spaceLeft = *slen;
1575 *slen = *slen * 2;
1576 *s = SDDS_Realloc(*s, sizeof(**s) * *slen);
1577 sInsert = *s + strlen(*s);
1578 newLine = 0;
1579 } else
1580 break;
1581 }
1582 if (!fgetsReturn)
1583 return NULL;
1584 return (*s);
1585}
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677

◆ lzma_close()

int lzma_close ( struct lzmafile * file)

Definition at line 100 of file SDDS_lzma.c.

100 {
101 int ret, outsize;
102 unsigned char buf[BUF_SIZE]; /* buffer used when flushing remaining
103 output data in write mode */
104 if (!file)
105 return -1;
106 if (file->mode == 'w') {
107 /* flush LZMA output buffer */
108 for (;;) {
109 file->str.next_out = buf;
110 file->str.avail_out = BUF_SIZE;
111 ret = lzma_code(&file->str, LZMA_FINISH);
112 if (ret != LZMA_STREAM_END && ret != LZMA_OK) {
113 fprintf(stderr, "lzma_close error: encoding failed: %d\n", ret);
114 lzma_end(&file->str);
115 fclose(file->fp);
116 free(file);
117 return EOF;
118 }
119 outsize = BUF_SIZE - file->str.avail_out;
120 if (fwrite(buf, 1, outsize, file->fp) != outsize) {
121 lzma_end(&file->str);
122 fclose(file->fp);
123 free(file);
124 return EOF;
125 }
126 if (ret == LZMA_STREAM_END)
127 break;
128 }
129 }
130 lzma_end(&file->str);
131 ret = fclose(file->fp);
132 free(file);
133 return ret;
134}

◆ lzma_eof()

int lzma_eof ( struct lzmafile * file)

Definition at line 378 of file SDDS_lzma.c.

378 {
379 lzma_stream *lstr;
380 lstr = &file->str;
381 if (lstr->avail_in == 0) {
382 return feof(file->fp);
383 } else {
384 return 0;
385 }
386}

◆ lzma_gets()

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

Definition at line 181 of file SDDS_lzma.c.

181 {
182 int ret;
183 int i = 0;
184 lzma_stream *lstr;
185 if (file->mode != 'r')
186 return NULL;
187 if (s == NULL || size < 1)
188 return NULL;
189 s[0] = '\0';
190 lstr = &file->str;
191 lstr->next_out = (void *)s;
192
193 /* decompress until newline or EOF or output buffer is full */
194 while (1) {
195 if (lstr->avail_in == 0) {
196 /* refill input buffer */
197 ret = fread(file->rdbuf, 1, BUF_SIZE, file->fp);
198 if (ret == 0) {
199 break; /* EOF */
200 }
201 lstr->next_in = file->rdbuf; /* buffer containing lzma data just read */
202 lstr->avail_in = ret; /* number of bytes read */
203 }
204 if (i + 1 == size) {
205 s[i] = '\0';
206 break;
207 }
208 lstr->avail_out = 1;
209 ret = lzma_code(lstr, LZMA_RUN);
210 /* this fills up lstr->next_out and decreases lstr->avail_out */
211 /* it also emptys lstr->next_in and decreases lstr->avail_in */
212 if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
213 fprintf(stderr, "lzma_gets error: decoding failed: %d\n", ret);
214 return NULL;
215 }
216 if (ret == LZMA_STREAM_END) { /* EOF */
217 s[i + 1] = '\0';
218 break;
219 }
220 if (s[i] == 10) { /* 10 is the value for \n */
221 if (i > 0) { /* we sometimes get \10\10 */
222 if ((i == 1) && (s[0] == 32)) {
223 /* when uncompressing the lzma stream we some times end
224 up with \10\32\10 instead of a simple \10 */
225 } else {
226 s[i + 1] = '\0';
227 break;
228 }
229 }
230 }
231 i++;
232 }
233 return s;
234}

◆ lzma_open()

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

Definition at line 70 of file SDDS_lzma.c.

70 {
71 int ret;
72
73 /* initialize LZMA stream */
74 struct lzmafile *lf = malloc(sizeof(struct lzmafile));
75 lf->fp = fopen(path, mode);
76 lf->str = lzma_stream_init;
77 lf->mode = mode[0];
78 if (mode[0] == 'r') {
79#if LZMA_VERSION <= UINT32_C(49990030)
80 ret = lzma_auto_decoder(&lf->str, NULL, NULL);
81#else
82 ret = lzma_auto_decoder(&lf->str, -1, 0);
83#endif
84 lf->str.avail_in = 0;
85 } else {
86 /* I decided to use level 2 encoding */
87 /* Perhaps this should be user configurable in an environment variable */
88 ret = LZMA_EASY_ENCODER(&lf->str, 2);
89 }
90 if (ret != LZMA_OK) {
91 fprintf(stderr, "lzma_open error: %d\n", ret);
92 return NULL;
93 }
94 return (void *)lf;
95}

◆ lzma_printf()

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

Definition at line 355 of file SDDS_lzma.c.

355 {
356 size_t size = 32768;
357 int len;
358 unsigned char in[32768];
359 va_list va;
360 va_start(va, format);
361
362 in[size - 1] = 0;
363 (void)vsnprintf((char *)in, size, format, va);
364 va_end(va);
365 len = strlen((char *)in);
366
367 /* check that printf() results fit in buffer */
368 if (len <= 0 || len >= (int)size || in[size - 1] != 0) {
369 fprintf(stderr, "lzma_printf error: the printf results do not fit in the buffer\n");
370 return -1;
371 }
372 in[len] = '\0';
373 len = lzma_write(file, in, len);
374
375 return len;
376}

◆ lzma_putc()

int lzma_putc ( int c,
struct lzmafile * file )

Definition at line 319 of file SDDS_lzma.c.

319 {
320 int ret;
321 lzma_stream *lstr = &file->str;
322
323 unsigned char bufout[1]; /* compressed output buffer */
324 char buf[1];
325
326 if (file->mode != 'w') {
327 fprintf(stderr, "lzma_putc error: file was not opened for writting\n");
328 return EOF;
329 }
330 buf[0] = c;
331
332 lstr->next_in = (void *)buf;
333 lstr->avail_in = 1;
334 while (lstr->avail_in) {
335 lstr->next_out = bufout;
336 lstr->avail_out = 1;
337 ret = lzma_code(lstr, LZMA_RUN);
338 if (ret != LZMA_OK) {
339 fprintf(stderr, "lzma_putc error: encoding failed: %d\n", ret);
340 return EOF;
341 }
342 ret = fwrite(bufout, 1, 1 - lstr->avail_out, file->fp);
343 if (ret != 1 - lstr->avail_out) {
344 fprintf(stderr, "lzma_putc error\n");
345 return EOF;
346 }
347 }
348 return (unsigned char)c;
349}

◆ lzma_puts()

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

Definition at line 275 of file SDDS_lzma.c.

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

◆ lzma_read()

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

Definition at line 140 of file SDDS_lzma.c.

140 {
141 int ret;
142 lzma_stream *lstr;
143 if (file->mode != 'r')
144 return -1;
145
146 lstr = &file->str;
147 lstr->next_out = buf;
148 lstr->avail_out = count;
149
150 /* decompress until EOF or output buffer is full */
151 while (lstr->avail_out) {
152 if (lstr->avail_in == 0) {
153 /* refill input buffer */
154 ret = fread(file->rdbuf, 1, BUF_SIZE, file->fp);
155 if (ret == 0) {
156 break; /* EOF */
157 }
158 lstr->next_in = file->rdbuf; /* buffer containing lzma data just read */
159 lstr->avail_in = ret; /* number of bytes read */
160 }
161 ret = lzma_code(lstr, LZMA_RUN);
162 /* this fills up lstr->next_out and decreases lstr->avail_out */
163 /* it also emptys lstr->next_in and decreases lstr->avail_in */
164 if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
165 fprintf(stderr, "lzma_read error: decoding failed: %d\n", ret);
166 return -1;
167 }
168 if (ret == LZMA_STREAM_END) {
169 break; /* EOF */
170 }
171 }
172 return count - lstr->avail_out; /* length of buf that has valid data */
173}

◆ lzma_seek()

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

Definition at line 397 of file SDDS_lzma.c.

397 {
398 return fseek(file->fp, offset, whence);
399}

◆ lzma_tell()

long lzma_tell ( struct lzmafile * file)

Definition at line 393 of file SDDS_lzma.c.

393 {
394 return ftell(file->fp);
395}

◆ lzma_write()

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

Definition at line 239 of file SDDS_lzma.c.

239 {
240 int ret;
241 lzma_stream *lstr = &file->str;
242 unsigned char *bufout; /* compressed output buffer */
243 bufout = malloc(sizeof(char) * count);
244
245 if (file->mode != 'w') {
246 fprintf(stderr, "lzma_write error: file was not opened for writting\n");
247 free(bufout);
248 return -1;
249 }
250 lstr->next_in = buf;
251 lstr->avail_in = count;
252 while (lstr->avail_in) {
253 lstr->next_out = bufout;
254 lstr->avail_out = count;
255 ret = lzma_code(lstr, LZMA_RUN);
256 if (ret != LZMA_OK) {
257 fprintf(stderr, "lzma_write error: encoding failed: %d\n", ret);
258 free(bufout);
259 return -1;
260 }
261 ret = fwrite(bufout, 1, count - lstr->avail_out, file->fp);
262 if (ret != count - lstr->avail_out) {
263 fprintf(stderr, "lzma_write error\n");
264 free(bufout);
265 return -1;
266 }
267 }
268 free(bufout);
269 return count;
270}

◆ 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:379

◆ 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 1491 of file SDDS_dataprep.c.

1491 {
1492 int32_t i;
1493
1494 for (i = n_indices - 1; i >= 0; i--)
1495 if (counter[i] != (max_count[i] - 1))
1496 break;
1497 if (i == -1)
1498 return (-1);
1499
1500 for (i = n_indices - 1; i >= 0; i--) {
1501 if (counter[i] < (max_count[i] - 1)) {
1502 counter[i]++;
1503 break;
1504 } else {
1505 counter[i] = 0;
1506 }
1507 }
1508 return (i);
1509}

◆ 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 36 of file SDDS_dataprep.c.

36 {
37 if (SDDS_target->layout.n_columns &&
38 ((!(SDDS_target->column_flag = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_target->layout.n_columns)) ||
39 !(SDDS_target->column_order = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_target->layout.n_columns))) ||
40 (!SDDS_SetMemory(SDDS_target->column_flag, SDDS_target->layout.n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
41 !SDDS_SetMemory(SDDS_target->column_order, SDDS_target->layout.n_columns, SDDS_LONG, (int32_t)0, (int32_t)1)))) {
42 SDDS_SetError("Unable to allocate column flags--memory allocation failure (SDDS_AllocateColumnFlags)");
43 return 0;
44 }
45 return 1;
46}
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:639
#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 3928 of file SDDS_extract.c.

3928 {
3929 COLUMN_DEFINITION *cd_target, *cd_source;
3930 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_CopyColumn"))
3931 return (0);
3932 if (target < 0 || source < 0 || target >= SDDS_dataset->layout.n_columns || source >= SDDS_dataset->layout.n_columns) {
3933 SDDS_SetError("Unable to copy column--target or source index out of range (SDDS_CopyColumn");
3934 return (0);
3935 }
3936 cd_target = SDDS_dataset->layout.column_definition + target;
3937 cd_source = SDDS_dataset->layout.column_definition + source;
3938 SDDS_dataset->column_flag[target] = SDDS_dataset->column_flag[source];
3939 if (SDDS_dataset->n_rows_allocated) {
3940 if (cd_target->type != cd_source->type) {
3941 if (!(SDDS_dataset->data[target] = SDDS_Realloc(SDDS_dataset->data[target], SDDS_type_size[cd_source->type - 1] * SDDS_dataset->n_rows_allocated))) {
3942 SDDS_SetError("Unable to copy column--memory allocation failure (SDDS_CopyColumn)");
3943 return (0);
3944 }
3945 }
3946 if (cd_source->type != SDDS_STRING)
3947 memcpy(SDDS_dataset->data[target], SDDS_dataset->data[source], SDDS_type_size[cd_source->type - 1] * SDDS_dataset->n_rows);
3948 else if (!SDDS_CopyStringArray(SDDS_dataset->data[target], SDDS_dataset->data[source], SDDS_dataset->n_rows)) {
3949 SDDS_SetError("Unable to copy column--string copy failure (SDDS_CopyColumn)");
3950 return (0);
3951 }
3952 }
3953 memcpy((char *)cd_target, (char *)cd_source, sizeof(*cd_target));
3954 return (1);
3955}
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:552
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 4017 of file SDDS_extract.c.

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

◆ 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 3012 of file SDDS_utils.c.

3016{
3017 if (!data || !dimension || !dimensions)
3018 return;
3019 if (dimensions > 1) {
3020 SDDS_FreePointerArray((void **)(data[0]), dimensions - 1, dimension + 1);
3021 free(data);
3022 }
3023}
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 1425 of file SDDS_input.c.

1425 {
1426 int64_t i, j;
1427 char **ptr;
1428 /* free stored strings */
1429 if (!SDDS_dataset)
1430 return;
1431 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
1432 if (SDDS_dataset->layout.column_definition[i].type == SDDS_STRING) {
1433 ptr = (char **)SDDS_dataset->data[i];
1434 for (j = 0; j < SDDS_dataset->n_rows; j++, ptr++)
1435 if (*ptr) {
1436 free(*ptr);
1437 *ptr = NULL;
1438 }
1439 }
1440}

◆ 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 1258 of file SDDS_binary.c.

1258 {
1259 int32_t try;
1260#if defined(vxWorks)
1261 struct timespec rqtp;
1262 rqtp.tv_sec = 1;
1263 rqtp.tv_nsec = 0;
1264#endif
1265 for (try = 0; try < FSEEK_TRIES; try++) {
1266 if (fseek(fp, offset, dir) == -1) {
1267#if defined(vxWorks)
1268 nanosleep(&rqtp, NULL);
1269#else
1270 sleep(1);
1271#endif
1272 } else
1273 break;
1274 }
1275 if (try == 0)
1276 return 0;
1277 if (try == FSEEK_TRIES) {
1278 fputs("warning: fseek problems--unable to recover\n", stderr);
1279 return -1;
1280 }
1281 fputs("warning: fseek problems--recovered\n", stderr);
1282 return 0;
1283}

◆ 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 1701 of file SDDS_extract.c.

1701 {
1702 int64_t i, j;
1703 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetSelectedRowIndex"))
1704 return (-1);
1705 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_GetSelectedRowIndex"))
1706 return (-1);
1707 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1708 if (SDDS_dataset->row_flag[i] && j++ == srow_index)
1709 break;
1710 }
1711 if (i == SDDS_dataset->n_rows)
1712 return (-1);
1713 return (i);
1714}
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:577

◆ 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 5201 of file SDDS_utils.c.

5201 {
5202 return SDDS_dataset->layout.commentFlags;
5203}

◆ 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 680 of file SDDS_input.c.

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

2549 {
2550 int32_t length;
2551 static char *dummy_string = "";
2552 if (!string)
2553 string = dummy_string;
2554 length = strlen(string);
2555 if (!SDDS_LZMABufferedWrite(&length, sizeof(length), lzmafp, fBuffer)) {
2556 SDDS_SetError("Unable to write string--error writing length");
2557 return (0);
2558 }
2559 if (length && !SDDS_LZMABufferedWrite(string, sizeof(*string) * length, lzmafp, fBuffer)) {
2560 SDDS_SetError("Unable to write string--error writing contents");
2561 return (0);
2562 }
2563 return (1);
2564}
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 5630 of file SDDS_binary.c.

5630 {
5631 int32_t length;
5632 static char *dummy_string = "";
5633 if (!string)
5634 string = dummy_string;
5635 length = strlen(string);
5636 SDDS_SwapLong(&length);
5637 if (!SDDS_LZMABufferedWrite(&length, sizeof(length), lzmafp, fBuffer)) {
5638 SDDS_SetError("Unable to write string--error writing length");
5639 return (0);
5640 }
5641 SDDS_SwapLong(&length);
5642 if (length && !SDDS_LZMABufferedWrite(string, sizeof(*string) * length, lzmafp, fBuffer)) {
5643 SDDS_SetError("Unable to write string--error writing contents");
5644 return (0);
5645 }
5646 return (1);
5647}
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 5251 of file SDDS_utils.c.

5251 {
5252 char buffer[SDDS_MAXLINE];
5253 int32_t i;
5254 if (SDDS_dataset == NULL)
5255 return;
5256 while (SDDS_GetToken(s, buffer, SDDS_MAXLINE) > 0) {
5257 for (i = 0; i < COMMENT_COMMANDS; i++) {
5258 if (strcmp(buffer, commentCommandName[i]) == 0) {
5259 SDDS_dataset->layout.commentFlags |= commentCommandFlag[i];
5260 break;
5261 }
5262 }
5263 }
5264}
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:318
#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:144
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 3053 of file SDDS_binary.c.

3053 {
3054 int32_t i, j;
3055 SDDS_LAYOUT *layout;
3056 /* char *predefined_format; */
3057 /* static char buffer[SDDS_MAXLINE]; */
3058#if defined(zLib)
3059 gzFile gzfp = NULL;
3060#endif
3061 FILE *fp = NULL;
3062 struct lzmafile *lzmafp = NULL;
3063 SDDS_ARRAY *array;
3064 SDDS_FILEBUFFER *fBuffer;
3065
3066 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryArrays"))
3067 return (0);
3068 layout = &SDDS_dataset->layout;
3069 if (!layout->n_arrays)
3070 return (1);
3071#if defined(zLib)
3072 if (SDDS_dataset->layout.gzipFile) {
3073 gzfp = layout->gzfp;
3074 } else {
3075#endif
3076 if (SDDS_dataset->layout.lzmaFile) {
3077 lzmafp = layout->lzmafp;
3078 } else {
3079 fp = layout->fp;
3080 }
3081#if defined(zLib)
3082 }
3083#endif
3084 fBuffer = &SDDS_dataset->fBuffer;
3085 if (!SDDS_dataset->array) {
3086 SDDS_SetError("Unable to read array--pointer to structure storage area is NULL (SDDS_ReadBinaryArrays)");
3087 return (0);
3088 }
3089 for (i = 0; i < layout->n_arrays; i++) {
3090 array = SDDS_dataset->array + i;
3091 if (array->definition && !SDDS_FreeArrayDefinition(array->definition)) {
3092 SDDS_SetError("Unable to get array--array definition corrupted (SDDS_ReadBinaryArrays)");
3093 return (0);
3094 }
3095 if (!SDDS_CopyArrayDefinition(&array->definition, layout->array_definition + i)) {
3096 SDDS_SetError("Unable to read array--definition copy failed (SDDS_ReadBinaryArrays)");
3097 return (0);
3098 }
3099 /*if (array->dimension) free(array->dimension); */
3100 if (!(array->dimension = SDDS_Realloc(array->dimension, sizeof(*array->dimension) * array->definition->dimensions))) {
3101 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3102 return (0);
3103 }
3104#if defined(zLib)
3105 if (SDDS_dataset->layout.gzipFile) {
3106 if (!SDDS_GZipBufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, gzfp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3107 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3108 return (0);
3109 }
3110 } else {
3111#endif
3112 if (SDDS_dataset->layout.lzmaFile) {
3113 if (!SDDS_LZMABufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, lzmafp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3114 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3115 return (0);
3116 }
3117 } else {
3118 if (!SDDS_BufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, fp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3119 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3120 return (0);
3121 }
3122 }
3123#if defined(zLib)
3124 }
3125#endif
3126 array->elements = 1;
3127 for (j = 0; j < array->definition->dimensions; j++)
3128 array->elements *= array->dimension[j];
3129 if (array->data)
3130 free(array->data);
3131 array->data = array->pointer = NULL;
3132 if (array->elements == 0)
3133 continue;
3134 if (array->elements < 0) {
3135 SDDS_SetError("Unable to read array--number of elements is negative (SDDS_ReadBinaryArrays)");
3136 return (0);
3137 }
3138 if (!(array->data = SDDS_Realloc(array->data, array->elements * SDDS_type_size[array->definition->type - 1]))) {
3139 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3140 return (0);
3141 }
3142 if (array->definition->type == SDDS_STRING) {
3143#if defined(zLib)
3144 if (SDDS_dataset->layout.gzipFile) {
3145 for (j = 0; j < array->elements; j++) {
3146 if (!(((char **)(array->data))[j] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3147 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3148 return (0);
3149 }
3150 }
3151 } else {
3152#endif
3153 if (SDDS_dataset->layout.lzmaFile) {
3154 for (j = 0; j < array->elements; j++) {
3155 if (!(((char **)(array->data))[j] = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
3156 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3157 return (0);
3158 }
3159 }
3160 } else {
3161 for (j = 0; j < array->elements; j++) {
3162 if (!(((char **)(array->data))[j] = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
3163 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3164 return (0);
3165 }
3166 }
3167 }
3168#if defined(zLib)
3169 }
3170#endif
3171 } else {
3172#if defined(zLib)
3173 if (SDDS_dataset->layout.gzipFile) {
3174 if (!SDDS_GZipBufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, gzfp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3175 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3176 return (0);
3177 }
3178 } else {
3179#endif
3180 if (SDDS_dataset->layout.lzmaFile) {
3181 if (!SDDS_LZMABufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, lzmafp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3182 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3183 return (0);
3184 }
3185 } else {
3186 if (!SDDS_BufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, fp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3187 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3188 return (0);
3189 }
3190 }
3191#if defined(zLib)
3192 }
3193#endif
3194 }
3195 }
3196 return (1);
3197}
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)
Definition SDDS_binary.c:96
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 3218 of file SDDS_binary.c.

3218 {
3219 int64_t i, j, k, row;
3220 SDDS_LAYOUT *layout;
3221 /* char *predefined_format; */
3222 /* static char buffer[SDDS_MAXLINE]; */
3223#if defined(zLib)
3224 gzFile gzfp = NULL;
3225#endif
3226 FILE *fp = NULL;
3227 struct lzmafile *lzmafp = NULL;
3228 SDDS_FILEBUFFER *fBuffer;
3229
3230 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryColumns"))
3231 return (0);
3232 layout = &SDDS_dataset->layout;
3233 if (!layout->n_columns || !SDDS_dataset->n_rows)
3234 return (1);
3235#if defined(zLib)
3236 if (SDDS_dataset->layout.gzipFile) {
3237 gzfp = layout->gzfp;
3238 } else {
3239#endif
3240 if (SDDS_dataset->layout.lzmaFile) {
3241 lzmafp = layout->lzmafp;
3242 } else {
3243 fp = layout->fp;
3244 }
3245#if defined(zLib)
3246 }
3247#endif
3248 fBuffer = &SDDS_dataset->fBuffer;
3249
3250 for (i = 0; i < layout->n_columns; i++) {
3251 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3252 continue;
3253 if (layout->column_definition[i].type == SDDS_STRING) {
3254#if defined(zLib)
3255 if (SDDS_dataset->layout.gzipFile) {
3256 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3257 if (((char ***)SDDS_dataset->data)[i][row])
3258 free((((char ***)SDDS_dataset->data)[i][row]));
3259 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3260 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadBinaryColumns)");
3261 return (0);
3262 }
3263 }
3264 } else {
3265#endif
3266 if (SDDS_dataset->layout.lzmaFile) {
3267 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3268 if (((char ***)SDDS_dataset->data)[i][row])
3269 free((((char ***)SDDS_dataset->data)[i][row]));
3270 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
3271 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3272 return (0);
3273 }
3274 }
3275 } else {
3276 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3277 if (((char ***)SDDS_dataset->data)[i][row])
3278 free((((char ***)SDDS_dataset->data)[i][row]));
3279 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
3280 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3281 return (0);
3282 }
3283 }
3284 }
3285#if defined(zLib)
3286 }
3287#endif
3288 } else {
3289#if defined(zLib)
3290 if (SDDS_dataset->layout.gzipFile) {
3291 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)) {
3292 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3293 return (0);
3294 }
3295 } else {
3296#endif
3297 if (SDDS_dataset->layout.lzmaFile) {
3298 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)) {
3299 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3300 return (0);
3301 }
3302 } else {
3303 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)) {
3304 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3305 return (0);
3306 }
3307 }
3308#if defined(zLib)
3309 }
3310#endif
3311 }
3312 }
3313
3314 if (sparse_interval == 1 && sparse_offset == 0) {
3315 return(1);
3316 }
3317
3318 j = SDDS_dataset->n_rows;
3319 for (i = 0; i < layout->n_columns; i++) {
3320 j = k = 0;
3321 switch (layout->column_definition[i].type) {
3322 case SDDS_SHORT:
3323 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3324 if (k % sparse_interval == 0) {
3325 ((short*)SDDS_dataset->data[i])[j] = ((short*)SDDS_dataset->data[i])[row];
3326 j++;
3327 }
3328 k++;
3329 }
3330 break;
3331 case SDDS_USHORT:
3332 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3333 if (k % sparse_interval == 0) {
3334 ((unsigned short*)SDDS_dataset->data[i])[j] = ((unsigned short*)SDDS_dataset->data[i])[row];
3335 j++;
3336 }
3337 k++;
3338 }
3339 break;
3340 case SDDS_LONG:
3341 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3342 if (k % sparse_interval == 0) {
3343 ((int32_t*)SDDS_dataset->data[i])[j] = ((int32_t*)SDDS_dataset->data[i])[row];
3344 j++;
3345 }
3346 k++;
3347 }
3348 break;
3349 case SDDS_ULONG:
3350 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3351 if (k % sparse_interval == 0) {
3352 ((uint32_t*)SDDS_dataset->data[i])[j] = ((uint32_t*)SDDS_dataset->data[i])[row];
3353 j++;
3354 }
3355 k++;
3356 }
3357 break;
3358 case SDDS_LONG64:
3359 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3360 if (k % sparse_interval == 0) {
3361 ((int64_t*)SDDS_dataset->data[i])[j] = ((int64_t*)SDDS_dataset->data[i])[row];
3362 j++;
3363 }
3364 k++;
3365 }
3366 break;
3367 case SDDS_ULONG64:
3368 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3369 if (k % sparse_interval == 0) {
3370 ((uint64_t*)SDDS_dataset->data[i])[j] = ((uint64_t*)SDDS_dataset->data[i])[row];
3371 j++;
3372 }
3373 k++;
3374 }
3375 break;
3376 case SDDS_FLOAT:
3377 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3378 if (k % sparse_interval == 0) {
3379 ((float*)SDDS_dataset->data[i])[j] = ((float*)SDDS_dataset->data[i])[row];
3380 j++;
3381 }
3382 k++;
3383 }
3384 break;
3385 case SDDS_DOUBLE:
3386 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3387 if (k % sparse_interval == 0) {
3388 ((double*)SDDS_dataset->data[i])[j] = ((double*)SDDS_dataset->data[i])[row];
3389 j++;
3390 }
3391 k++;
3392 }
3393 break;
3394 case SDDS_LONGDOUBLE:
3395 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3396 if (k % sparse_interval == 0) {
3397 ((long double*)SDDS_dataset->data[i])[j] = ((long double*)SDDS_dataset->data[i])[row];
3398 j++;
3399 }
3400 k++;
3401 }
3402 break;
3403 case SDDS_STRING:
3404 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3405 if (k % sparse_interval == 0) {
3406 ((char**)SDDS_dataset->data[i])[j] = ((char**)SDDS_dataset->data[i])[row];
3407 j++;
3408 }
3409 k++;
3410 }
3411 for (k=j; k<SDDS_dataset->n_rows; k++) {
3412 if (((char ***)SDDS_dataset->data)[i][k]) {
3413 free((((char ***)SDDS_dataset->data)[i][k]));
3414 ((char ***)SDDS_dataset->data)[i][k] = NULL;
3415 }
3416 }
3417
3418 break;
3419 case SDDS_CHARACTER:
3420 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3421 if (k % sparse_interval == 0) {
3422 ((char*)SDDS_dataset->data[i])[j] = ((char*)SDDS_dataset->data[i])[row];
3423 j++;
3424 }
3425 k++;
3426 }
3427 break;
3428 default:
3429 break;
3430 }
3431 }
3432
3433 SDDS_dataset->n_rows = j;
3434
3435 return (1);
3436}
#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 2120 of file SDDS_binary.c.

2120 {
2121 return SDDS_ReadBinaryPageDetailed(SDDS_dataset, sparse_interval, sparse_offset, 0, sparse_statistics);
2122}
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 2202 of file SDDS_binary.c.

2202 {
2203 int32_t n_rows32;
2204 int64_t n_rows, i, j, k, alloc_rows, rows_to_store, mod;
2205
2206 /* int32_t page_number, i; */
2207#if defined(zLib)
2208 gzFile gzfp = NULL;
2209#endif
2210 FILE *fp = NULL;
2211 struct lzmafile *lzmafp = NULL;
2212 SDDS_FILEBUFFER *fBuffer;
2213 void **statData=NULL;
2214 double statResult;
2215
2216 if (SDDS_dataset->autoRecovered)
2217 return -1;
2218 if (SDDS_dataset->swapByteOrder) {
2219 return SDDS_ReadNonNativePageDetailed(SDDS_dataset, 0, sparse_interval, sparse_offset, last_rows);
2220 }
2221
2222 /* static char s[SDDS_MAXLINE]; */
2223 n_rows = 0;
2224 SDDS_SetReadRecoveryMode(SDDS_dataset, 0);
2225#if defined(zLib)
2226 if (SDDS_dataset->layout.gzipFile) {
2227 gzfp = SDDS_dataset->layout.gzfp;
2228 } else {
2229#endif
2230 if (SDDS_dataset->layout.lzmaFile) {
2231 lzmafp = SDDS_dataset->layout.lzmafp;
2232 } else {
2233 fp = SDDS_dataset->layout.fp;
2234 }
2235#if defined(zLib)
2236 }
2237#endif
2238 fBuffer = &SDDS_dataset->fBuffer;
2239 if (!fBuffer->buffer) {
2240 if (defaultIOBufferSize == 0 && (SDDS_dataset->layout.popenUsed || !SDDS_dataset->layout.filename) && (sparse_interval > 1 || sparse_offset > 0 || last_rows > 0)) {
2241 SDDS_SetError("The IO buffer size is 0 for data being read from a pipe with sparsing. This is not supported.");
2242 return 0;
2243 }
2244 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * (defaultIOBufferSize + 1)))) {
2245 SDDS_SetError("Unable to do buffered read--allocation failure");
2246 return 0;
2247 }
2248 fBuffer->bufferSize = defaultIOBufferSize;
2249 fBuffer->bytesLeft = 0;
2250 }
2251 SDDS_dataset->rowcount_offset = -1;
2252#if defined(zLib)
2253 if (SDDS_dataset->layout.gzipFile) {
2254 if (!SDDS_GZipBufferedRead(&n_rows32, sizeof(n_rows32), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2255 if (gzeof(gzfp))
2256 return (SDDS_dataset->page_number = -1);
2257 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2258 return (0);
2259 }
2260 if (n_rows32 == INT32_MIN) {
2261 if (!SDDS_GZipBufferedRead(&n_rows, sizeof(n_rows), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
2262 if (gzeof(gzfp))
2263 return (SDDS_dataset->page_number = -1);
2264 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2265 return (0);
2266 }
2267 } else {
2268 n_rows = n_rows32;
2269 }
2270 } else {
2271#endif
2272 /* This value will only be valid if read buffering is turned off, which is done for
2273 * certain append operations! Should really modify SDDS_BufferedRead and SDDS_BufferedWrite
2274 * to provide ftell capability.
2275 */
2276 if (SDDS_dataset->layout.lzmaFile) {
2277 if (!SDDS_LZMABufferedRead(&n_rows32, sizeof(n_rows32), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2278 if (lzma_eof(lzmafp))
2279 return (SDDS_dataset->page_number = -1);
2280 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2281 return (0);
2282 }
2283 if (n_rows32 == INT32_MIN) {
2284 if (!SDDS_LZMABufferedRead(&n_rows, sizeof(n_rows), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
2285 if (lzma_eof(lzmafp))
2286 return (SDDS_dataset->page_number = -1);
2287 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2288 return (0);
2289 }
2290 } else {
2291 n_rows = n_rows32;
2292 }
2293 } else {
2294 SDDS_dataset->rowcount_offset = ftell(fp);
2295 if (!SDDS_BufferedRead(&n_rows32, sizeof(n_rows32), fp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2296 if (feof(fp))
2297 return (SDDS_dataset->page_number = -1);
2298 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2299 return (0);
2300 }
2301 if (n_rows32 == INT32_MIN) {
2302 if (!SDDS_BufferedRead(&n_rows, sizeof(n_rows), fp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
2303 if (feof(fp))
2304 return (SDDS_dataset->page_number = -1);
2305 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2306 return (0);
2307 }
2308 } else {
2309 n_rows = n_rows32;
2310 }
2311 }
2312#if defined(zLib)
2313 }
2314#endif
2315
2316#if defined(DEBUG)
2317 fprintf(stderr, "Expect %" PRId64 " rows of data\n", n_rows);
2318#endif
2319 if (n_rows < 0) {
2320 SDDS_SetError("Unable to read page--negative number of rows (SDDS_ReadBinaryPageDetailed)");
2321 return (0);
2322 }
2323 if (SDDS_dataset->layout.byteOrderDeclared == 0) {
2324 if (n_rows > 10000000) {
2325 SDDS_SetError("Unable to read page--endian byte order not declared and suspected to be non-native. (SDDS_ReadBinaryPageDetailed)");
2326 return (0);
2327 }
2328 }
2329 if (n_rows > SDDS_GetRowLimit()) {
2330 /* the number of rows is "unreasonably" large---treat like end-of-file */
2331 return (SDDS_dataset->page_number = -1);
2332 }
2333 if (last_rows < 0)
2334 last_rows = 0;
2335 /* Fix this limitation later */
2336 if (SDDS_dataset->layout.data_mode.column_major && sparse_statistics != 0) {
2337 SDDS_SetError("sparse_statistics is not yet supported for column-major layout. Use sddsconvert -majorOrder=row to convert first.\n");
2338 return (0);
2339 }
2340
2341 if (last_rows) {
2342 sparse_interval = 1;
2343 sparse_offset = n_rows - last_rows;
2344 }
2345 if (sparse_interval <= 0)
2346 sparse_interval = 1;
2347 if (sparse_offset < 0)
2348 sparse_offset = 0;
2349
2350 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
2351 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
2352
2353 if (!SDDS_StartPage(SDDS_dataset, 0) || !SDDS_LengthenTable(SDDS_dataset, alloc_rows)) {
2354 SDDS_SetError("Unable to read page--couldn't start page (SDDS_ReadBinaryPageDetailed)");
2355 return (0);
2356 }
2357
2358 /* read the parameter values */
2359 if (!SDDS_ReadBinaryParameters(SDDS_dataset)) {
2360 SDDS_SetError("Unable to read page--parameter reading error (SDDS_ReadBinaryPageDetailed)");
2361 return (0);
2362 }
2363
2364 /* read the array values */
2365 if (!SDDS_ReadBinaryArrays(SDDS_dataset)) {
2366 SDDS_SetError("Unable to read page--array reading error (SDDS_ReadBinaryPageDetailed)");
2367 return (0);
2368 }
2369 if (SDDS_dataset->layout.data_mode.column_major) {
2370 SDDS_dataset->n_rows = n_rows;
2371 if (!SDDS_ReadBinaryColumns(SDDS_dataset, sparse_interval, sparse_offset)) {
2372 SDDS_SetError("Unable to read page--column reading error (SDDS_ReadBinaryPageDetailed)");
2373 return (0);
2374 }
2375 return (SDDS_dataset->page_number);
2376 }
2377 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
2378 for (j = 0; j < n_rows; j++) {
2379 if (!SDDS_ReadBinaryRow(SDDS_dataset, j, 0)) {
2380 SDDS_dataset->n_rows = j;
2381 if (SDDS_dataset->autoRecover) {
2382#if defined(DEBUG)
2383 fprintf(stderr, "Doing auto-read recovery\n");
2384#endif
2385 SDDS_dataset->autoRecovered = 1;
2387 return (SDDS_dataset->page_number);
2388 }
2389 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2390 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2391 return (0);
2392 }
2393 }
2394 SDDS_dataset->n_rows = j;
2395 return (SDDS_dataset->page_number);
2396 } else {
2397 for (j = 0; j < sparse_offset; j++) {
2398 if (!SDDS_ReadBinaryRow(SDDS_dataset, 0, 1)) {
2399 SDDS_dataset->n_rows = 0;
2400 if (SDDS_dataset->autoRecover) {
2401 SDDS_dataset->autoRecovered = 1;
2403 return (SDDS_dataset->page_number);
2404 }
2405 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2406 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2407 return (0);
2408 }
2409 }
2410 n_rows -= sparse_offset;
2411 if (sparse_statistics != 0) {
2412 // Allocate buffer space for statistical sparsing
2413 statData = (void**)malloc(SDDS_dataset->layout.n_columns * sizeof(void*));
2414 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2415 if (SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type)) {
2416 // Not ideal for SDDS_LONGDOUBLE but we may never run across this error
2417 statData[i] = (double*)calloc(sparse_interval, sizeof(double));
2418 }
2419 }
2420 for (j = k = 0; j < n_rows; j++) {
2421 if (!SDDS_ReadBinaryRow(SDDS_dataset, k, 0)) {
2422 SDDS_dataset->n_rows = k;
2423 if (SDDS_dataset->autoRecover) {
2424 SDDS_dataset->autoRecovered = 1;
2426 return (SDDS_dataset->page_number);
2427 }
2428 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2429 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2430 return (0);
2431 }
2432 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2433 switch (SDDS_dataset->layout.column_definition[i].type) {
2434 case SDDS_FLOAT:
2435 ((double*)statData[i])[j % sparse_interval] = (double)(((float*)SDDS_dataset->data[i])[k]);
2436 break;
2437 case SDDS_DOUBLE:
2438 ((double*)statData[i])[j % sparse_interval] = ((double*)SDDS_dataset->data[i])[k];
2439 break;
2440 case SDDS_LONGDOUBLE:
2441 ((double*)statData[i])[j % sparse_interval] = (double)(((long double*)SDDS_dataset->data[i])[k]);
2442 break;
2443 }
2444 if (SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type)) {
2445 if (sparse_statistics == 1) {
2446 // Sparse and get average statistics
2447 compute_average(&statResult, (double*)statData[i], (j % sparse_interval) + 1);
2448 } else if (sparse_statistics == 2) {
2449 // Sparse and get median statistics
2450 compute_median(&statResult, (double*)statData[i], (j % sparse_interval) + 1);
2451 } else if (sparse_statistics == 3) {
2452 // Sparse and get minimum statistics
2453 statResult = min_in_array((double*)statData[i], (j % sparse_interval) + 1);
2454 } else if (sparse_statistics == 4) {
2455 // Sparse and get maximum statistics
2456 statResult = max_in_array((double*)statData[i], (j % sparse_interval) + 1);
2457 }
2458 }
2459 switch (SDDS_dataset->layout.column_definition[i].type) {
2460 case SDDS_FLOAT:
2461 ((float*)SDDS_dataset->data[i])[k] = statResult;
2462 break;
2463 case SDDS_DOUBLE:
2464 ((double*)SDDS_dataset->data[i])[k] = statResult;
2465 break;
2466 case SDDS_LONGDOUBLE:
2467 ((long double*)SDDS_dataset->data[i])[k] = statResult;
2468 break;
2469 }
2470 }
2471 if (j % sparse_interval == sparse_interval - 1) {
2472 k++;
2473 }
2474 }
2475 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2476 if (SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type)) {
2477 free(statData[i]);
2478 }
2479 }
2480 free(statData);
2481 } else {
2482 for (j = k = 0; j < n_rows; j++) {
2483 if (!SDDS_ReadBinaryRow(SDDS_dataset, k, mod = j % sparse_interval)) {
2484 SDDS_dataset->n_rows = k;
2485 if (SDDS_dataset->autoRecover) {
2486 SDDS_dataset->autoRecovered = 1;
2488 return (SDDS_dataset->page_number);
2489 }
2490 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2491 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
2492 return (0);
2493 }
2494 k += mod ? 0 : 1;
2495 }
2496 }
2497 SDDS_dataset->n_rows = k;
2498 return (SDDS_dataset->page_number);
2499 }
2500}
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 2150 of file SDDS_binary.c.

2150 {
2151 return SDDS_ReadBinaryPageDetailed(SDDS_dataset, 1, 0, last_rows, 0);
2152}

◆ 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 2941 of file SDDS_binary.c.

2941 {
2942 int32_t i;
2943 SDDS_LAYOUT *layout;
2944 /* char *predefined_format; */
2945 char buffer[SDDS_MAXLINE];
2946#if defined(zLib)
2947 gzFile gzfp = NULL;
2948#endif
2949 FILE *fp = NULL;
2950 struct lzmafile *lzmafp = NULL;
2951 SDDS_FILEBUFFER *fBuffer;
2952
2953 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryParameters"))
2954 return (0);
2955 layout = &SDDS_dataset->layout;
2956 if (!layout->n_parameters)
2957 return (1);
2958#if defined(zLib)
2959 if (SDDS_dataset->layout.gzipFile) {
2960 gzfp = layout->gzfp;
2961 } else {
2962#endif
2963 if (SDDS_dataset->layout.lzmaFile) {
2964 lzmafp = layout->lzmafp;
2965 } else {
2966 fp = layout->fp;
2967 }
2968#if defined(zLib)
2969 }
2970#endif
2971 fBuffer = &SDDS_dataset->fBuffer;
2972 for (i = 0; i < layout->n_parameters; i++) {
2973 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2974 continue;
2975 if (layout->parameter_definition[i].fixed_value) {
2976 strcpy(buffer, layout->parameter_definition[i].fixed_value);
2977 if (!SDDS_ScanData(buffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
2978 SDDS_SetError("Unable to read page--parameter scanning error (SDDS_ReadBinaryParameters)");
2979 return (0);
2980 }
2981 } else if (layout->parameter_definition[i].type == SDDS_STRING) {
2982 if (*(char **)SDDS_dataset->parameter[i])
2983 free(*(char **)SDDS_dataset->parameter[i]);
2984#if defined(zLib)
2985 if (SDDS_dataset->layout.gzipFile) {
2986 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
2987 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
2988 return (0);
2989 }
2990 } else {
2991#endif
2992 if (SDDS_dataset->layout.lzmaFile) {
2993 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
2994 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
2995 return (0);
2996 }
2997 } else {
2998 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
2999 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
3000 return (0);
3001 }
3002 }
3003#if defined(zLib)
3004 }
3005#endif
3006 } else {
3007#if defined(zLib)
3008 if (SDDS_dataset->layout.gzipFile) {
3009 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)) {
3010 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3011 return (0);
3012 }
3013 } else {
3014#endif
3015 if (SDDS_dataset->layout.lzmaFile) {
3016 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)) {
3017 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3018 return (0);
3019 }
3020 } else {
3021 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)) {
3022 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3023 return (0);
3024 }
3025 }
3026#if defined(zLib)
3027 }
3028#endif
3029 }
3030 }
3031 return (1);
3032}

◆ 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 2711 of file SDDS_binary.c.

2711 {
2712 int64_t i, type, size;
2713 SDDS_LAYOUT *layout;
2714#if defined(zLib)
2715 gzFile gzfp;
2716#endif
2717 FILE *fp;
2718 struct lzmafile *lzmafp;
2719 SDDS_FILEBUFFER *fBuffer;
2720
2721 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadBinaryRow"))
2722 return (0);
2723 layout = &SDDS_dataset->layout;
2724 fBuffer = &SDDS_dataset->fBuffer;
2725
2726#if defined(zLib)
2727 if (SDDS_dataset->layout.gzipFile) {
2728 gzfp = layout->gzfp;
2729 for (i = 0; i < layout->n_columns; i++) {
2730 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2731 continue;
2732 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2733 if (!skip) {
2734 if (((char ***)SDDS_dataset->data)[i][row])
2735 free((((char ***)SDDS_dataset->data)[i][row]));
2736 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
2737 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2738 return (0);
2739 }
2740 } else {
2741 if (!SDDS_ReadGZipBinaryString(gzfp, fBuffer, 1)) {
2742 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2743 return 0;
2744 }
2745 }
2746 } else {
2747 size = SDDS_type_size[type - 1];
2748 if (!SDDS_GZipBufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2749 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2750 return (0);
2751 }
2752 }
2753 }
2754 } else {
2755#endif
2756 if (SDDS_dataset->layout.lzmaFile) {
2757 lzmafp = layout->lzmafp;
2758 for (i = 0; i < layout->n_columns; i++) {
2759 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2760 continue;
2761 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2762 if (!skip) {
2763 if (((char ***)SDDS_dataset->data)[i][row])
2764 free((((char ***)SDDS_dataset->data)[i][row]));
2765 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 0))) {
2766 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2767 return (0);
2768 }
2769 } else {
2770 if (!SDDS_ReadLZMABinaryString(lzmafp, fBuffer, 1)) {
2771 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2772 return 0;
2773 }
2774 }
2775 } else {
2776 size = SDDS_type_size[type - 1];
2777 if (!SDDS_LZMABufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2778 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2779 return (0);
2780 }
2781 }
2782 }
2783 } else {
2784 fp = layout->fp;
2785 for (i = 0; i < layout->n_columns; i++) {
2786 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2787 continue;
2788 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2789 if (!skip) {
2790 if (((char ***)SDDS_dataset->data)[i][row])
2791 free((((char ***)SDDS_dataset->data)[i][row]));
2792 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadBinaryString(fp, fBuffer, 0))) {
2793 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2794 return (0);
2795 }
2796 } else {
2797 if (!SDDS_ReadBinaryString(fp, fBuffer, 1)) {
2798 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2799 return 0;
2800 }
2801 }
2802 } else {
2803 size = SDDS_type_size[type - 1];
2804 if (!SDDS_BufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2805 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2806 return (0);
2807 }
2808 }
2809 }
2810 }
2811#if defined(zLib)
2812 }
2813#endif
2814 return (1);
2815}

◆ 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 2616 of file SDDS_binary.c.

2616 {
2617 int32_t length;
2618 char *string;
2619
2620 if (!SDDS_BufferedRead(&length, sizeof(length), fp, fBuffer, SDDS_LONG, 0) || length < 0)
2621 return (0);
2622 if (!(string = SDDS_Malloc(sizeof(*string) * (length + 1))))
2623 return (NULL);
2624 if (length && !SDDS_BufferedRead(skip ? NULL : string, sizeof(*string) * length, fp, fBuffer, SDDS_STRING, 0))
2625 return (NULL);
2626 string[length] = 0;
2627 return (string);
2628}

◆ 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 517 of file SDDS_input.c.

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

◆ 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 3459 of file SDDS_binary.c.

3459 {
3460 int64_t i, row;
3461 SDDS_LAYOUT *layout;
3462 /* char *predefined_format; */
3463 /* static char buffer[SDDS_MAXLINE]; */
3464#if defined(zLib)
3465 gzFile gzfp = NULL;
3466#endif
3467 FILE *fp = NULL;
3468 struct lzmafile *lzmafp = NULL;
3469 SDDS_FILEBUFFER *fBuffer;
3470
3471 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativeBinaryColumns"))
3472 return (0);
3473 layout = &SDDS_dataset->layout;
3474 if (!layout->n_columns || !SDDS_dataset->n_rows)
3475 return (1);
3476#if defined(zLib)
3477 if (SDDS_dataset->layout.gzipFile) {
3478 gzfp = layout->gzfp;
3479 } else {
3480#endif
3481 if (SDDS_dataset->layout.lzmaFile) {
3482 lzmafp = layout->lzmafp;
3483 } else {
3484 fp = layout->fp;
3485 }
3486#if defined(zLib)
3487 }
3488#endif
3489 fBuffer = &SDDS_dataset->fBuffer;
3490
3491 for (i = 0; i < layout->n_columns; i++) {
3492 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3493 continue;
3494 if (layout->column_definition[i].type == SDDS_STRING) {
3495#if defined(zLib)
3496 if (SDDS_dataset->layout.gzipFile) {
3497 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3498 if (((char ***)SDDS_dataset->data)[i][row])
3499 free((((char ***)SDDS_dataset->data)[i][row]));
3500 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
3501 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumns)");
3502 return (0);
3503 }
3504 }
3505 } else {
3506#endif
3507 if (SDDS_dataset->layout.lzmaFile) {
3508 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3509 if (((char ***)SDDS_dataset->data)[i][row])
3510 free((((char ***)SDDS_dataset->data)[i][row]));
3511 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeLZMABinaryString(lzmafp, fBuffer, 0))) {
3512 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3513 return (0);
3514 }
3515 }
3516 } else {
3517 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3518 if (((char ***)SDDS_dataset->data)[i][row])
3519 free((((char ***)SDDS_dataset->data)[i][row]));
3520 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeBinaryString(fp, fBuffer, 0))) {
3521 SDDS_SetError("Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3522 return (0);
3523 }
3524 }
3525 }
3526#if defined(zLib)
3527 }
3528#endif
3529 } else {
3530#if defined(zLib)
3531 if (SDDS_dataset->layout.gzipFile) {
3532 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)) {
3533 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3534 return (0);
3535 }
3536 } else {
3537#endif
3538 if (SDDS_dataset->layout.lzmaFile) {
3539 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)) {
3540 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3541 return (0);
3542 }
3543 } else {
3544 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)) {
3545 SDDS_SetError("Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3546 return (0);
3547 }
3548 }
3549#if defined(zLib)
3550 }
3551#endif
3552 }
3553 }
3554 return (1);
3555}
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 4230 of file SDDS_binary.c.

4230 {
4231 int32_t n_rows32 = 0;
4232 int64_t n_rows, j, k, alloc_rows, rows_to_store, mod;
4233 /* int32_t page_number, i; */
4234#if defined(zLib)
4235 gzFile gzfp = NULL;
4236#endif
4237 FILE *fp = NULL;
4238 struct lzmafile *lzmafp = NULL;
4239 SDDS_FILEBUFFER *fBuffer;
4240
4241 /* static char s[SDDS_MAXLINE]; */
4242 n_rows = 0;
4243 SDDS_SetReadRecoveryMode(SDDS_dataset, 0);
4244#if defined(zLib)
4245 if (SDDS_dataset->layout.gzipFile) {
4246 gzfp = SDDS_dataset->layout.gzfp;
4247 } else {
4248#endif
4249 if (SDDS_dataset->layout.lzmaFile) {
4250 lzmafp = SDDS_dataset->layout.lzmafp;
4251 } else {
4252 fp = SDDS_dataset->layout.fp;
4253 }
4254#if defined(zLib)
4255 }
4256#endif
4257 fBuffer = &SDDS_dataset->fBuffer;
4258 if (!fBuffer->buffer) {
4259 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * defaultIOBufferSize))) {
4260 SDDS_SetError("Unable to do buffered read--allocation failure");
4261 return 0;
4262 }
4263 fBuffer->bufferSize = defaultIOBufferSize;
4264 fBuffer->bytesLeft = 0;
4265 }
4266 SDDS_dataset->rowcount_offset = -1;
4267#if defined(zLib)
4268 if (SDDS_dataset->layout.gzipFile) {
4269 if (!SDDS_GZipBufferedRead(&n_rows32, sizeof(n_rows32), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4270 if (gzeof(gzfp))
4271 return (SDDS_dataset->page_number = -1);
4272 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4273 return (0);
4274 }
4275 SDDS_SwapLong(&n_rows32);
4276 if (n_rows32 == INT32_MIN) {
4277 if (!SDDS_GZipBufferedRead(&n_rows, sizeof(n_rows), gzfp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4278 if (gzeof(gzfp))
4279 return (SDDS_dataset->page_number = -1);
4280 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4281 return (0);
4282 }
4283 SDDS_SwapLong64(&n_rows);
4284 } else {
4285 n_rows = n_rows32;
4286 }
4287 } else {
4288#endif
4289 /* This value will only be valid if read buffering is turned off, which is done for
4290 * certain append operations! Should really modify SDDS_BufferedRead and SDDS_BufferedWrite
4291 * to provide ftell capability.
4292 */
4293 if (SDDS_dataset->layout.lzmaFile) {
4294 if (!SDDS_LZMABufferedRead(&n_rows32, sizeof(n_rows32), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4295 if (lzma_eof(lzmafp))
4296 return (SDDS_dataset->page_number = -1);
4297 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4298 return (0);
4299 }
4300 SDDS_SwapLong(&n_rows32);
4301 if (n_rows32 == INT32_MIN) {
4302 if (!SDDS_LZMABufferedRead(&n_rows, sizeof(n_rows), lzmafp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4303 if (lzma_eof(lzmafp))
4304 return (SDDS_dataset->page_number = -1);
4305 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4306 return (0);
4307 }
4308 SDDS_SwapLong64(&n_rows);
4309 } else {
4310 n_rows = n_rows32;
4311 }
4312 } else {
4313 SDDS_dataset->rowcount_offset = ftell(fp);
4314 if (!SDDS_BufferedRead(&n_rows32, sizeof(n_rows32), fp, &SDDS_dataset->fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4315 if (feof(fp))
4316 return (SDDS_dataset->page_number = -1);
4317 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4318 return (0);
4319 }
4320 SDDS_SwapLong(&n_rows32);
4321 if (n_rows32 == INT32_MIN) {
4322 if (!SDDS_BufferedRead(&n_rows, sizeof(n_rows), fp, &SDDS_dataset->fBuffer, SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4323 if (feof(fp))
4324 return (SDDS_dataset->page_number = -1);
4325 SDDS_SetError("Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4326 return (0);
4327 }
4328 SDDS_SwapLong64(&n_rows);
4329 } else {
4330 n_rows = n_rows32;
4331 }
4332 }
4333#if defined(zLib)
4334 }
4335#endif
4336 if (n_rows < 0) {
4337 SDDS_SetError("Unable to read page--negative number of rows (SDDS_ReadNonNativeBinaryPage)");
4338 return (0);
4339 }
4340 if (last_rows < 0)
4341 last_rows = 0;
4342 /* Fix this limitation later */
4343 if (SDDS_dataset->layout.data_mode.column_major) {
4344 sparse_interval = 1;
4345 sparse_offset = 0;
4346 last_rows = 0;
4347 }
4348 if (last_rows) {
4349 sparse_interval = 1;
4350 sparse_offset = n_rows - last_rows;
4351 rows_to_store = last_rows + 2;
4352 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4353 }
4354 if (sparse_interval <= 0)
4355 sparse_interval = 1;
4356 if (sparse_offset < 0)
4357 sparse_offset = 0;
4358
4359 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
4360 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4361 if (!SDDS_StartPage(SDDS_dataset, 0) || !SDDS_LengthenTable(SDDS_dataset, alloc_rows)) {
4362 SDDS_SetError("Unable to read page--couldn't start page (SDDS_ReadNonNativeBinaryPage)");
4363 return (0);
4364 }
4365
4366 /* read the parameter values */
4367 if (!SDDS_ReadNonNativeBinaryParameters(SDDS_dataset)) {
4368 SDDS_SetError("Unable to read page--parameter reading error (SDDS_ReadNonNativeBinaryPage)");
4369 return (0);
4370 }
4371
4372 /* read the array values */
4373 if (!SDDS_ReadNonNativeBinaryArrays(SDDS_dataset)) {
4374 SDDS_SetError("Unable to read page--array reading error (SDDS_ReadNonNativeBinaryPage)");
4375 return (0);
4376 }
4377 if (SDDS_dataset->layout.data_mode.column_major) {
4378 SDDS_dataset->n_rows = n_rows;
4379 if (!SDDS_ReadNonNativeBinaryColumns(SDDS_dataset)) {
4380 SDDS_SetError("Unable to read page--column reading error (SDDS_ReadNonNativeBinaryPage)");
4381 return (0);
4382 }
4383 SDDS_SwapEndsColumnData(SDDS_dataset);
4384 return (SDDS_dataset->page_number);
4385 }
4386 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
4387 for (j = 0; j < n_rows; j++) {
4388 if (!SDDS_ReadNonNativeBinaryRow(SDDS_dataset, j, 0)) {
4389 SDDS_dataset->n_rows = j - 1;
4390 if (SDDS_dataset->autoRecover) {
4392 SDDS_SwapEndsColumnData(SDDS_dataset);
4393 return (SDDS_dataset->page_number);
4394 }
4395 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4396 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
4397 return (0);
4398 }
4399 }
4400 SDDS_dataset->n_rows = j;
4401 SDDS_SwapEndsColumnData(SDDS_dataset);
4402 return (SDDS_dataset->page_number);
4403 } else {
4404 for (j = 0; j < sparse_offset; j++) {
4405 if (!SDDS_ReadNonNativeBinaryRow(SDDS_dataset, 0, 1)) {
4406 SDDS_dataset->n_rows = 0;
4407 if (SDDS_dataset->autoRecover) {
4409 SDDS_SwapEndsColumnData(SDDS_dataset);
4410 return (SDDS_dataset->page_number);
4411 }
4412 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4413 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
4414 return (0);
4415 }
4416 }
4417 n_rows -= sparse_offset;
4418 for (j = k = 0; j < n_rows; j++) {
4419 if (!SDDS_ReadNonNativeBinaryRow(SDDS_dataset, k, mod = j % sparse_interval)) {
4420 SDDS_dataset->n_rows = k - 1;
4421 if (SDDS_dataset->autoRecover) {
4423 SDDS_SwapEndsColumnData(SDDS_dataset);
4424 return (SDDS_dataset->page_number);
4425 }
4426 SDDS_SetError("Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4427 SDDS_SetReadRecoveryMode(SDDS_dataset, 1);
4428 return (0);
4429 }
4430 k += mod ? 0 : 1;
4431 }
4432 SDDS_dataset->n_rows = k;
4433 SDDS_SwapEndsColumnData(SDDS_dataset);
4434 return (SDDS_dataset->page_number);
4435 }
4436}
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 4203 of file SDDS_binary.c.

4203 {
4204 return SDDS_ReadNonNativeBinaryPageDetailed(SDDS_dataset, 1, 0, last_rows);
4205}
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 4903 of file SDDS_binary.c.

4903 {
4904 int32_t length;
4905 char *string;
4906
4907 if (!SDDS_LZMABufferedRead(&length, sizeof(length), lzmafp, fBuffer, SDDS_LONG, 0))
4908 return (0);
4909 SDDS_SwapLong(&length);
4910 if (length < 0)
4911 return (0);
4912 if (!(string = SDDS_Malloc(sizeof(*string) * (length + 1))))
4913 return (NULL);
4914 if (length && !SDDS_LZMABufferedRead(skip ? NULL : string, sizeof(*string) * length, lzmafp, fBuffer, SDDS_STRING, 0))
4915 return (NULL);
4916 string[length] = 0;
4917 return (string);
4918}

◆ 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 4051 of file SDDS_binary.c.

4053{
4054 int32_t retval;
4055 /* SDDS_LAYOUT layout_copy; */
4056
4057 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativePageDetailed"))
4058 return (0);
4059 if (SDDS_dataset->layout.disconnected) {
4060 SDDS_SetError("Can't read page--file is disconnected (SDDS_ReadNonNativePageDetailed)");
4061 return 0;
4062 }
4063#if defined(zLib)
4064 if (SDDS_dataset->layout.gzipFile) {
4065 if (!SDDS_dataset->layout.gzfp) {
4066 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4067 return (0);
4068 }
4069 } else {
4070#endif
4071 if (SDDS_dataset->layout.lzmaFile) {
4072 if (!SDDS_dataset->layout.lzmafp) {
4073 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4074 return (0);
4075 }
4076 } else {
4077 if (!SDDS_dataset->layout.fp) {
4078 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4079 return (0);
4080 }
4081 }
4082#if defined(zLib)
4083 }
4084#endif
4085 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
4086 if ((retval = SDDS_ReadAsciiPage(SDDS_dataset, sparse_interval, sparse_offset, 0)) < 1) {
4087 return (retval);
4088 }
4089 } else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
4090 if ((retval = SDDS_ReadNonNativeBinaryPage(SDDS_dataset, sparse_interval, sparse_offset)) < 1) {
4091 return (retval);
4092 }
4093 } else {
4094 SDDS_SetError("Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageDetailed)");
4095 return (0);
4096 }
4097 return (retval);
4098}
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 4118 of file SDDS_binary.c.

4118 {
4119 int32_t retval;
4120 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativePageLastRows"))
4121 return (0);
4122 if (SDDS_dataset->layout.disconnected) {
4123 SDDS_SetError("Can't read page--file is disconnected (SDDS_ReadNonNativePageLastRows)");
4124 return 0;
4125 }
4126#if defined(zLib)
4127 if (SDDS_dataset->layout.gzipFile) {
4128 if (!SDDS_dataset->layout.gzfp) {
4129 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4130 return (0);
4131 }
4132 } else {
4133#endif
4134 if (SDDS_dataset->layout.lzmaFile) {
4135 if (!SDDS_dataset->layout.lzmafp) {
4136 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4137 return (0);
4138 }
4139 } else {
4140 if (!SDDS_dataset->layout.fp) {
4141 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4142 return (0);
4143 }
4144 }
4145#if defined(zLib)
4146 }
4147#endif
4148 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
4149 if ((retval = SDDS_ReadAsciiPageLastRows(SDDS_dataset, last_rows)) < 1) {
4150 return (retval);
4151 }
4152 } else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
4153 if ((retval = SDDS_ReadNonNativeBinaryPageLastRows(SDDS_dataset, last_rows)) < 1) {
4154 return (retval);
4155 }
4156 } else {
4157 SDDS_SetError("Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageLastRows)");
4158 return (0);
4159 }
4160 return (retval);
4161}
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 5221 of file SDDS_utils.c.

5221 {
5222 SDDS_dataset->layout.commentFlags = 0;
5223}

◆ 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 3802 of file SDDS_extract.c.

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

◆ 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 1077 of file SDDS_binary.c.

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

5711 {
5712 FILE *fp;
5713 int32_t code, min32 = INT32_MIN, rows32;
5714 int64_t i, rows, offset, fixed_rows;
5715 SDDS_FILEBUFFER *fBuffer;
5716
5717 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_UpdateNonNativeBinaryPage"))
5718 return (0);
5719#if defined(zLib)
5720 if (SDDS_dataset->layout.gzipFile) {
5721 SDDS_SetError("Unable to perform page updates on a gzip file (SDDS_UpdateNonNativeBinaryPage)");
5722 return 0;
5723 }
5724#endif
5725 if (SDDS_dataset->layout.lzmaFile) {
5726 SDDS_SetError("Unable to perform page updates on .lzma or .xz files (SDDS_UpdateNonNativeBinaryPage)");
5727 return 0;
5728 }
5729 if (SDDS_dataset->layout.data_mode.column_major) {
5730 SDDS_SetError("Unable to perform page updates on a column major order file (SDDS_UpdateNonNativeBinaryPage)");
5731 return 0;
5732 }
5733 if (!SDDS_dataset->writing_page) {
5734#ifdef DEBUG
5735 fprintf(stderr, "Page not being written---calling SDDS_UpdateNonNativeBinaryPage\n");
5736#endif
5737 if (!(code = SDDS_WriteNonNativeBinaryPage(SDDS_dataset))) {
5738 return 0;
5739 }
5740 if (mode & FLUSH_TABLE) {
5741 SDDS_FreeTableStrings(SDDS_dataset);
5742 SDDS_dataset->first_row_in_mem = SDDS_CountRowsOfInterest(SDDS_dataset);
5743 SDDS_dataset->last_row_written = -1;
5744 SDDS_dataset->n_rows = 0;
5745 }
5746 return code;
5747 }
5748
5749 if (!(fp = SDDS_dataset->layout.fp)) {
5750 SDDS_SetError("Unable to update page--file pointer is NULL (SDDS_UpdateNonNativeBinaryPage)");
5751 return (0);
5752 }
5753 fBuffer = &SDDS_dataset->fBuffer;
5754 if (!SDDS_FlushBuffer(fp, fBuffer)) {
5755 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5756 return 0;
5757 }
5758 offset = ftell(fp);
5759
5760 rows = SDDS_CountRowsOfInterest(SDDS_dataset) + SDDS_dataset->first_row_in_mem;
5761#ifdef DEBUG
5762 fprintf(stderr, "%" PRId64 " rows stored in table, %" PRId32 " already written\n", rows, SDDS_dataset->n_rows_written);
5763#endif
5764 if (rows == SDDS_dataset->n_rows_written) {
5765 return (1);
5766 }
5767 if (rows < SDDS_dataset->n_rows_written) {
5768 SDDS_SetError("Unable to update page--new number of rows less than previous number (SDDS_UpdateNonNativeBinaryPage)");
5769 return (0);
5770 }
5771 SDDS_SwapLong(&min32);
5772 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))) {
5773 if (SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
5774 SDDS_SetError("Unable to update page--failure doing fseek (SDDS_UpdateNonNativeBinaryPage)");
5775 return (0);
5776 }
5777 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5778 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
5779 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
5780 }
5781 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5782#if defined(DEBUG)
5783 fprintf(stderr, "Setting %" PRId64 " fixed rows\n", fixed_rows);
5784#endif
5785 if ((fixed_rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5786 SDDS_SetError("Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5787 return (0);
5788 }
5789 if (fixed_rows > INT32_MAX) {
5790 if (fwrite(&min32, sizeof(min32), 1, fp) != 1) {
5791 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5792 return (0);
5793 }
5794 SDDS_SwapLong64(&fixed_rows);
5795 if (fwrite(&fixed_rows, sizeof(fixed_rows), 1, fp) != 1) {
5796 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5797 return (0);
5798 }
5799 SDDS_SwapLong64(&fixed_rows);
5800 } else {
5801 rows32 = (int32_t)fixed_rows;
5802 SDDS_SwapLong(&rows32);
5803 if (fwrite(&rows32, sizeof(rows32), 1, fp) != 1) {
5804 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5805 return (0);
5806 }
5807 }
5808 } else {
5809#if defined(DEBUG)
5810 fprintf(stderr, "Setting %" PRId64 " rows\n", rows);
5811#endif
5812 if ((rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5813 SDDS_SetError("Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5814 return (0);
5815 }
5816 if (rows > INT32_MAX) {
5817 if (fwrite(&min32, sizeof(min32), 1, fp) != 1) {
5818 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5819 return (0);
5820 }
5821 SDDS_SwapLong64(&rows);
5822 if (fwrite(&rows, sizeof(rows), 1, fp) != 1) {
5823 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5824 return (0);
5825 }
5826 SDDS_SwapLong64(&rows);
5827 } else {
5828 rows32 = (int32_t)rows;
5829 SDDS_SwapLong(&rows32);
5830 if (fwrite(&rows32, sizeof(rows32), 1, fp) != 1) {
5831 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5832 return (0);
5833 }
5834 }
5835 }
5836 if (SDDS_fseek(fp, offset, 0) == -1) {
5837 SDDS_SetError("Unable to update page--failure doing fseek to end of page (SDDS_UpdateNonNativeBinaryPage)");
5838 return (0);
5839 }
5840 }
5841 SDDS_SwapEndsColumnData(SDDS_dataset);
5842 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++) {
5843 if (SDDS_dataset->row_flag[i] && !SDDS_WriteNonNativeBinaryRow(SDDS_dataset, i)) {
5844 SDDS_SetError("Unable to update page--failure writing row (SDDS_UpdateNonNativeBinaryPage)");
5845 return (0);
5846 }
5847 }
5848 SDDS_SwapEndsColumnData(SDDS_dataset);
5849#ifdef DEBUG
5850 fprintf(stderr, "Flushing buffer\n");
5851#endif
5852 if (!SDDS_FlushBuffer(fp, fBuffer)) {
5853 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5854 return 0;
5855 }
5856 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
5857 SDDS_dataset->n_rows_written = rows;
5858 if (mode & FLUSH_TABLE) {
5859 SDDS_FreeTableStrings(SDDS_dataset);
5860 SDDS_dataset->first_row_in_mem = rows;
5861 SDDS_dataset->last_row_written = -1;
5862 SDDS_dataset->n_rows = 0;
5863 }
5864 return (1);
5865}
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 1533 of file SDDS_binary.c.

1533 {
1534 int32_t i, j, zero = 0;
1535 SDDS_LAYOUT *layout;
1536#if defined(zLib)
1537 gzFile gzfp;
1538#endif
1539 FILE *fp;
1540 struct lzmafile *lzmafp;
1541 SDDS_FILEBUFFER *fBuffer;
1542
1543 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryArrays"))
1544 return (0);
1545 layout = &SDDS_dataset->layout;
1546#if defined(zLib)
1547 if (SDDS_dataset->layout.gzipFile) {
1548 gzfp = layout->gzfp;
1549 fBuffer = &SDDS_dataset->fBuffer;
1550 for (i = 0; i < layout->n_arrays; i++) {
1551 if (!SDDS_dataset->array[i].dimension) {
1552 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1553 if (!SDDS_GZipBufferedWrite(&zero, sizeof(zero), gzfp, fBuffer)) {
1554 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1555 return 0;
1556 }
1557 continue;
1558 }
1559 if (!SDDS_GZipBufferedWrite(SDDS_dataset->array[i].dimension, sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, gzfp, fBuffer)) {
1560 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1561 return (0);
1562 }
1563 if (layout->array_definition[i].type == SDDS_STRING) {
1564 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1565 if (!SDDS_GZipWriteBinaryString(((char **)SDDS_dataset->array[i].data)[j], gzfp, fBuffer)) {
1566 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1567 return (0);
1568 }
1569 }
1570 } 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)) {
1571 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1572 return (0);
1573 }
1574 }
1575 } else {
1576#endif
1577 if (SDDS_dataset->layout.gzipFile) {
1578 lzmafp = layout->lzmafp;
1579 fBuffer = &SDDS_dataset->fBuffer;
1580 for (i = 0; i < layout->n_arrays; i++) {
1581 if (!SDDS_dataset->array[i].dimension) {
1582 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1583 if (!SDDS_LZMABufferedWrite(&zero, sizeof(zero), lzmafp, fBuffer)) {
1584 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1585 return 0;
1586 }
1587 continue;
1588 }
1589 if (!SDDS_LZMABufferedWrite(SDDS_dataset->array[i].dimension, sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, lzmafp, fBuffer)) {
1590 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1591 return (0);
1592 }
1593 if (layout->array_definition[i].type == SDDS_STRING) {
1594 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1595 if (!SDDS_LZMAWriteBinaryString(((char **)SDDS_dataset->array[i].data)[j], lzmafp, fBuffer)) {
1596 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1597 return (0);
1598 }
1599 }
1600 } 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)) {
1601 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1602 return (0);
1603 }
1604 }
1605 } else {
1606 fp = layout->fp;
1607 fBuffer = &SDDS_dataset->fBuffer;
1608 for (i = 0; i < layout->n_arrays; i++) {
1609 if (!SDDS_dataset->array[i].dimension) {
1610 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1611 if (!SDDS_BufferedWrite(&zero, sizeof(zero), fp, fBuffer)) {
1612 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1613 return 0;
1614 }
1615 continue;
1616 }
1617 if (!SDDS_BufferedWrite(SDDS_dataset->array[i].dimension, sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, fp, fBuffer)) {
1618 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1619 return (0);
1620 }
1621 if (layout->array_definition[i].type == SDDS_STRING) {
1622 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1623 if (!SDDS_WriteBinaryString(((char **)SDDS_dataset->array[i].data)[j], fp, fBuffer)) {
1624 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1625 return (0);
1626 }
1627 }
1628 } 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)) {
1629 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1630 return (0);
1631 }
1632 }
1633 }
1634#if defined(zLib)
1635 }
1636#endif
1637 return (1);
1638}
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 1673 of file SDDS_binary.c.

1673 {
1674 int64_t i, row, rows, type, size;
1675 SDDS_LAYOUT *layout;
1676#if defined(zLib)
1677 gzFile gzfp;
1678#endif
1679 FILE *fp;
1680 struct lzmafile *lzmafp;
1681 SDDS_FILEBUFFER *fBuffer;
1682
1683 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryColumns"))
1684 return (0);
1685 layout = &SDDS_dataset->layout;
1686 fBuffer = &SDDS_dataset->fBuffer;
1687 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
1688#if defined(zLib)
1689 if (SDDS_dataset->layout.gzipFile) {
1690 gzfp = layout->gzfp;
1691 for (i = 0; i < layout->n_columns; i++) {
1692 type = layout->column_definition[i].type;
1693 size = SDDS_type_size[type - 1];
1694 if (type == SDDS_STRING) {
1695 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1696 if (SDDS_dataset->row_flag[row] && !SDDS_GZipWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1697 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1698 return (0);
1699 }
1700 }
1701 } else {
1702 if (rows == SDDS_dataset->n_rows) {
1703 if (!SDDS_GZipBufferedWrite(SDDS_dataset->data[i], size * rows, gzfp, fBuffer)) {
1704 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1705 return (0);
1706 }
1707 } else {
1708 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1709 if (SDDS_dataset->row_flag[row] && !SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1710 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1711 return (0);
1712 }
1713 }
1714 }
1715 }
1716 }
1717 } else {
1718#endif
1719 if (SDDS_dataset->layout.lzmaFile) {
1720 lzmafp = layout->lzmafp;
1721 for (i = 0; i < layout->n_columns; i++) {
1722 type = layout->column_definition[i].type;
1723 size = SDDS_type_size[type - 1];
1724 if (layout->column_definition[i].type == SDDS_STRING) {
1725 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1726 if (SDDS_dataset->row_flag[row] && !SDDS_LZMAWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), lzmafp, fBuffer)) {
1727 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1728 return (0);
1729 }
1730 }
1731 } else {
1732 if (rows == SDDS_dataset->n_rows) {
1733 if (!SDDS_LZMABufferedWrite(SDDS_dataset->data[i], size * rows, lzmafp, fBuffer)) {
1734 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1735 return (0);
1736 }
1737 } else {
1738 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1739 if (SDDS_dataset->row_flag[row] && !SDDS_LZMABufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
1740 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1741 return (0);
1742 }
1743 }
1744 }
1745 }
1746 }
1747 } else {
1748 fp = layout->fp;
1749 for (i = 0; i < layout->n_columns; i++) {
1750 type = layout->column_definition[i].type;
1751 size = SDDS_type_size[type - 1];
1752 if (layout->column_definition[i].type == SDDS_STRING) {
1753 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1754 if (SDDS_dataset->row_flag[row] && !SDDS_WriteBinaryString(*((char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
1755 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1756 return (0);
1757 }
1758 }
1759 } else {
1760 if (rows == SDDS_dataset->n_rows) {
1761 if (!SDDS_BufferedWrite(SDDS_dataset->data[i], size * rows, fp, fBuffer)) {
1762 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1763 return (0);
1764 }
1765 } else {
1766 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1767 if (SDDS_dataset->row_flag[row] && !SDDS_BufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
1768 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1769 return (0);
1770 }
1771 }
1772 }
1773 }
1774 }
1775 }
1776#if defined(zLib)
1777 }
1778#endif
1779 return (1);
1780}

◆ 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 749 of file SDDS_binary.c.

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

1426 {
1427 int32_t i;
1428 SDDS_LAYOUT *layout;
1429 /* char *predefined_format; */
1430 /* static char buffer[SDDS_MAXLINE]; */
1431#if defined(zLib)
1432 gzFile gzfp;
1433#endif
1434 FILE *fp;
1435 struct lzmafile *lzmafp;
1436 SDDS_FILEBUFFER *fBuffer;
1437
1438 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryParameters"))
1439 return (0);
1440 layout = &SDDS_dataset->layout;
1441#if defined(zLib)
1442 if (SDDS_dataset->layout.gzipFile) {
1443 gzfp = layout->gzfp;
1444 fBuffer = &SDDS_dataset->fBuffer;
1445 for (i = 0; i < layout->n_parameters; i++) {
1446 if (layout->parameter_definition[i].fixed_value)
1447 continue;
1448 if (layout->parameter_definition[i].type == SDDS_STRING) {
1449 if (!SDDS_GZipWriteBinaryString(*((char **)SDDS_dataset->parameter[i]), gzfp, fBuffer)) {
1450 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1451 return (0);
1452 }
1453 } else if (!SDDS_GZipBufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer)) {
1454 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1455 return (0);
1456 }
1457 }
1458 } else {
1459#endif
1460 if (SDDS_dataset->layout.lzmaFile) {
1461 lzmafp = layout->lzmafp;
1462 fBuffer = &SDDS_dataset->fBuffer;
1463 for (i = 0; i < layout->n_parameters; i++) {
1464 if (layout->parameter_definition[i].fixed_value)
1465 continue;
1466 if (layout->parameter_definition[i].type == SDDS_STRING) {
1467 if (!SDDS_LZMAWriteBinaryString(*((char **)SDDS_dataset->parameter[i]), lzmafp, fBuffer)) {
1468 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1469 return (0);
1470 }
1471 } else if (!SDDS_LZMABufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], lzmafp, fBuffer)) {
1472 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1473 return (0);
1474 }
1475 }
1476 } else {
1477 fp = layout->fp;
1478 fBuffer = &SDDS_dataset->fBuffer;
1479 for (i = 0; i < layout->n_parameters; i++) {
1480 if (layout->parameter_definition[i].fixed_value)
1481 continue;
1482 if (layout->parameter_definition[i].type == SDDS_STRING) {
1483 if (!SDDS_WriteBinaryString(*((char **)SDDS_dataset->parameter[i]), fp, fBuffer)) {
1484 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1485 return (0);
1486 }
1487 } else if (!SDDS_BufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], fp, fBuffer)) {
1488 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1489 return (0);
1490 }
1491 }
1492 }
1493#if defined(zLib)
1494 }
1495#endif
1496 return (1);
1497}

◆ 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 1957 of file SDDS_binary.c.

1957 {
1958 int64_t i, type, size;
1959 SDDS_LAYOUT *layout;
1960#if defined(zLib)
1961 gzFile gzfp;
1962#endif
1963 FILE *fp;
1964 struct lzmafile *lzmafp;
1965 SDDS_FILEBUFFER *fBuffer;
1966
1967 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteBinaryRow"))
1968 return (0);
1969 layout = &SDDS_dataset->layout;
1970#if defined(zLib)
1971 if (SDDS_dataset->layout.gzipFile) {
1972 gzfp = layout->gzfp;
1973 fBuffer = &SDDS_dataset->fBuffer;
1974 for (i = 0; i < layout->n_columns; i++) {
1975 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
1976 if (!SDDS_GZipWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1977 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
1978 return (0);
1979 }
1980 } else {
1981 size = SDDS_type_size[type - 1];
1982 if (!SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1983 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
1984 return (0);
1985 }
1986 }
1987 }
1988 } else {
1989#endif
1990 if (SDDS_dataset->layout.lzmaFile) {
1991 lzmafp = layout->lzmafp;
1992 fBuffer = &SDDS_dataset->fBuffer;
1993 for (i = 0; i < layout->n_columns; i++) {
1994 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
1995 if (!SDDS_LZMAWriteBinaryString(*((char **)SDDS_dataset->data[i] + row), lzmafp, fBuffer)) {
1996 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
1997 return (0);
1998 }
1999 } else {
2000 size = SDDS_type_size[type - 1];
2001 if (!SDDS_LZMABufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
2002 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
2003 return (0);
2004 }
2005 }
2006 }
2007 } else {
2008 fp = layout->fp;
2009 fBuffer = &SDDS_dataset->fBuffer;
2010 for (i = 0; i < layout->n_columns; i++) {
2011 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
2012 if (!SDDS_WriteBinaryString(*((char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
2013 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
2014 return (0);
2015 }
2016 } else {
2017 size = SDDS_type_size[type - 1];
2018 if (!SDDS_BufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
2019 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
2020 return (0);
2021 }
2022 }
2023 }
2024 }
2025#if defined(zLib)
2026 }
2027#endif
2028 return (1);
2029}

◆ 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 1816 of file SDDS_binary.c.

1816 {
1817 int64_t i, row, rows, size, type;
1818 SDDS_LAYOUT *layout;
1819#if defined(zLib)
1820 gzFile gzfp;
1821#endif
1822 FILE *fp;
1823 struct lzmafile *lzmafp;
1824 SDDS_FILEBUFFER *fBuffer;
1825
1826 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteNonNativeBinaryColumns"))
1827 return (0);
1828 layout = &SDDS_dataset->layout;
1829 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
1830 fBuffer = &SDDS_dataset->fBuffer;
1831#if defined(zLib)
1832 if (SDDS_dataset->layout.gzipFile) {
1833 gzfp = layout->gzfp;
1834 for (i = 0; i < layout->n_columns; i++) {
1835 type = layout->column_definition[i].type;
1836 size = SDDS_type_size[type - 1];
1837 if (type == SDDS_STRING) {
1838 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1839 if (SDDS_dataset->row_flag[row] && !SDDS_GZipWriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1840 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1841 return (0);
1842 }
1843 }
1844 } else {
1845 if (rows == SDDS_dataset->n_rows) {
1846 if (!SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i], size * rows, gzfp, fBuffer)) {
1847 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1848 return (0);
1849 }
1850 } else {
1851 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1852 if (SDDS_dataset->row_flag[row] && !SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1853 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1854 return (0);
1855 }
1856 }
1857 }
1858 }
1859 }
1860 } else {
1861#endif
1862 if (SDDS_dataset->layout.lzmaFile) {
1863 lzmafp = layout->lzmafp;
1864 for (i = 0; i < layout->n_columns; i++) {
1865 type = layout->column_definition[i].type;
1866 size = SDDS_type_size[type - 1];
1867 if (type == SDDS_STRING) {
1868 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1869 if (SDDS_dataset->row_flag[row] && !SDDS_LZMAWriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), lzmafp, fBuffer)) {
1870 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1871 return (0);
1872 }
1873 }
1874 } else {
1875 if (rows == SDDS_dataset->n_rows) {
1876 if (!SDDS_LZMABufferedWrite(SDDS_dataset->data[i], size * rows, lzmafp, fBuffer)) {
1877 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1878 return (0);
1879 }
1880 } else {
1881 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1882 if (SDDS_dataset->row_flag[row] && !SDDS_LZMABufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
1883 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1884 return (0);
1885 }
1886 }
1887 }
1888 }
1889 }
1890 } else {
1891 fp = layout->fp;
1892 for (i = 0; i < layout->n_columns; i++) {
1893 type = layout->column_definition[i].type;
1894 size = SDDS_type_size[type - 1];
1895 if (type == SDDS_STRING) {
1896 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1897 if (SDDS_dataset->row_flag[row] && !SDDS_WriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
1898 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1899 return (0);
1900 }
1901 }
1902 } else {
1903 if (rows == SDDS_dataset->n_rows) {
1904 if (!SDDS_BufferedWrite(SDDS_dataset->data[i], size * rows, fp, fBuffer)) {
1905 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1906 return (0);
1907 }
1908 } else {
1909 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1910 if (SDDS_dataset->row_flag[row] && !SDDS_BufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
1911 SDDS_SetError("Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1912 return (0);
1913 }
1914 }
1915 }
1916 }
1917 }
1918 }
1919#if defined(zLib)
1920 }
1921#endif
1922 return (1);
1923}
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 401 of file SDDS_lzma.c.

401 {
402 if (!filename)
403 return NULL;
404 return lzma_open(filename, "rb");
405}

Variable Documentation

◆ SDDS_command

char* SDDS_command[SDDS_NUM_COMMANDS]
extern

Array of supported SDDS command names.

Lists the command strings that can be used within SDDS files to define structure and data.

Definition at line 81 of file SDDS_data.c.

81 {
82 "description",
83 "column",
84 "parameter",
85 "associate",
86 "data",
87 "include",
88 "array",
89};