SDDSlib
|
SDDS ascii data input and output routines. More...
Go to the source code of this file.
Macros | |
#define | COMMENT_POSITION 40 |
#define | INITIAL_BIG_BUFFER_SIZE SDDS_MAXLINE |
Functions | |
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. | |
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. | |
int32_t | SDDS_WriteAsciiPage (SDDS_DATASET *SDDS_dataset) |
Writes a page of data in ASCII format to the SDDS dataset. | |
int32_t | SDDS_WriteAsciiParameters (SDDS_DATASET *SDDS_dataset, FILE *fp) |
Writes the parameter data of an SDDS dataset in ASCII format to a file. | |
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_WriteAsciiArrays (SDDS_DATASET *SDDS_dataset, FILE *fp) |
Writes the arrays of an SDDS dataset in ASCII format to a 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_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_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_ReadAsciiParameters (SDDS_DATASET *SDDS_dataset) |
Reads the parameters from an ASCII file into 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_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_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_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. | |
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. | |
int32_t | SDDS_AsciiDataExpected (SDDS_DATASET *SDDS_dataset) |
Checks whether the SDDS dataset expects ASCII data input. | |
int32_t | SDDS_UpdateAsciiPage (SDDS_DATASET *SDDS_dataset, uint32_t mode) |
Updates the current ASCII page of an SDDS dataset with new data. | |
SDDS ascii data input and output routines.
This file contains the implementation of the SDDS ascii data input and output routines. It provides functions for writing void pointer data to an ASCII file stream. The functions support different data types such as short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, long double, string, and character.
Definition in file SDDS_ascii.c.
#define COMMENT_POSITION 40 |
Definition at line 29 of file SDDS_ascii.c.
#define INITIAL_BIG_BUFFER_SIZE SDDS_MAXLINE |
Definition at line 39 of file SDDS_ascii.c.
int32_t SDDS_AsciiDataExpected | ( | SDDS_DATASET * | SDDS_dataset | ) |
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.
SDDS_dataset | Pointer to the SDDS dataset to check. |
Definition at line 2140 of file SDDS_ascii.c.
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.
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.
SDDS_dataset | Pointer to the SDDS dataset containing the arrays to be written. |
lzmafp | Pointer to the LZMA file stream where the array data will be written. |
SDDS_SetError()
.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.
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.
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.
SDDS_dataset | Pointer to the SDDS dataset containing the parameter data. |
lzmafp | Pointer to the LZMA file stream where the ASCII data will be written. |
SDDS_SetError()
.SDDS_LZMAWriteTypedValue()
to write each parameter value according to its data type. Definition at line 565 of file SDDS_ascii.c.
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.
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.
SDDS_dataset | Pointer to the SDDS dataset containing the data. |
row | Zero-based index of the row to write. |
lzmafp | Pointer to the LZMA file stream where the row data will be written. |
SDDS_SetError()
.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.
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.
This function writes a single value from the provided data pointer to the given LZMA compressed file stream. The value is formatted as an ASCII string according to the specified data type and optional format string. Supports various data types including integers, floating-point numbers, strings, and characters.
data | Pointer to the data to be written. The data should be of the type specified by the type parameter. For array data types, data should point to the base of the array. |
index | Zero-based index of the element to write if data is an array; use 0 if data is a single value. |
type | The SDDS data type of the value to be written. Determines how the data is interpreted and formatted. Valid types include:
|
format | Optional printf-style format string to specify the output format. If NULL, a default format is used based on the data type. |
lzmafp | Pointer to the LZMA file stream where the data will be written. |
Definition at line 180 of file SDDS_ascii.c.
int32_t SDDS_ReadAsciiArrays | ( | SDDS_DATASET * | SDDS_dataset | ) |
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.
SDDS_dataset | Pointer to the SDDS dataset where the arrays will be stored. |
Definition at line 1047 of file SDDS_ascii.c.
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.
This function reads the next page of data from an ASCII SDDS file into the provided dataset. It supports reading data with specified sparsity (interval and offset) and can compute statistics such as average, median, minimum, or maximum over the sparse data.
SDDS_dataset | Pointer to the SDDS dataset where the data will be stored. |
sparse_interval | Interval for sparsity; read every nth row if greater than 1. |
sparse_offset | Offset for sparsity; number of initial rows to skip. |
sparse_statistics | Statistic to compute over the sparse data:
|
SDDS_ReadAsciiPageDetailed()
to perform the actual reading. Definition at line 1225 of file SDDS_ascii.c.
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.
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.
SDDS_dataset | Pointer to the SDDS dataset where the data will be stored. |
sparse_interval | Interval for sparsity; reads every nth row if greater than 1. Use 1 to read every row. |
sparse_offset | Offset from the first row to start reading. Rows before this offset are skipped. |
last_rows | Number 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_statistics | Statistical operation to perform over the sparse data:
|
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.
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.
This function reads only the last specified number of rows from the next ASCII page in the SDDS dataset.
SDDS_dataset | Pointer to the SDDS dataset where the data will be stored. |
last_rows | Number of rows to read from the end of the page. |
SDDS_ReadAsciiPageDetailed()
to perform the actual reading. Definition at line 1241 of file SDDS_ascii.c.
int32_t SDDS_ReadAsciiParameters | ( | SDDS_DATASET * | SDDS_dataset | ) |
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.
SDDS_dataset | Pointer to the SDDS dataset where the parameters will be stored. |
Definition at line 927 of file SDDS_ascii.c.
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.
This function extracts data from a string and stores it in the provided data pointer. It handles various SDDS data types, including integers, floating-point numbers, strings, and characters. The function supports both fixed-field and variable-field formats and can process parameters and column data.
string | Pointer to the input string containing the data to be scanned. |
type | The SDDS data type to interpret the scanned data as. Valid types include:
|
field_length | Field length for fixed-field formats. Set to 0 for variable-field formats. If negative, indicates left-padding should be removed. |
data | Void pointer to the data storage where the scanned value will be saved. Must be pre-allocated and appropriate for the specified data type. |
index | The index within the data array where the value should be stored. |
is_parameter | Set to 1 if the data is from an SDDS parameter; set to 0 for column data. |
SDDS_SetError()
.SDDS_InterpretEscapes()
. For string data types, the function manages memory allocation for the data array elements. Definition at line 1748 of file SDDS_ascii.c.
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.
This function is similar to SDDS_ScanData
but optimized for very long strings. It modifies the input string by advancing the string pointer and reducing its length after each call, which can improve performance when processing large amounts of data.
string | Pointer to the input string containing the data to be scanned. |
pstring | Pointer to the string pointer; this is updated to point to the next unread character. |
strlength | Pointer to the length of the string; this is updated as the string is consumed. |
type | The SDDS data type to interpret the scanned data as. Valid types include:
|
field_length | Field length for fixed-field formats. Set to 0 for variable-field formats. If negative, indicates left-padding should be removed. |
data | Void pointer to the data storage where the scanned value will be saved. Must be pre-allocated and appropriate for the specified data type. |
index | The index within the data array where the value should be stored. |
is_parameter | Set to 1 if the data is from an SDDS parameter; set to 0 for column data. |
SDDS_SetError()
.SDDS_ScanData
. Definition at line 1953 of file SDDS_ascii.c.
int32_t SDDS_UpdateAsciiPage | ( | SDDS_DATASET * | SDDS_dataset, |
uint32_t | mode ) |
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.
SDDS_dataset | Pointer to the SDDS dataset to update. |
mode | Mode flags that control the update behavior. Common modes include:
|
SDDS_SetError()
.Definition at line 2167 of file SDDS_ascii.c.
int32_t SDDS_WriteAsciiArrays | ( | SDDS_DATASET * | SDDS_dataset, |
FILE * | fp ) |
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.
SDDS_dataset | Pointer to the SDDS dataset containing the arrays to be written. |
fp | File pointer to the ASCII file where the array data will be written. |
SDDS_SetError()
.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.
int32_t SDDS_WriteAsciiPage | ( | SDDS_DATASET * | SDDS_dataset | ) |
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.
SDDS_dataset | Pointer to the SDDS dataset containing the data to be written. |
Definition at line 410 of file SDDS_ascii.c.
int32_t SDDS_WriteAsciiParameters | ( | SDDS_DATASET * | SDDS_dataset, |
FILE * | fp ) |
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.
SDDS_dataset | Pointer to the SDDS dataset containing the parameter data. |
fp | File pointer to the ASCII file where the parameter data will be written. |
Definition at line 531 of file SDDS_ascii.c.
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.
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.
SDDS_dataset | Pointer to the SDDS dataset containing the data. |
row | Zero-based index of the row to write. |
fp | File pointer to the ASCII file where the row data will be written. |
SDDS_SetError()
.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.
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.
This function writes a value of a specified SDDS data type to an ASCII file stream. The data is provided as a void pointer, and the function handles various data types by casting the pointer appropriately based on the type
parameter. For string data, special characters are escaped according to SDDS conventions.
data | Pointer to the data to be written. Should be castable to the type specified by type . |
index | Array index of the data to be printed; use 0 if not an array. |
type | The SDDS data type of the data variable. Possible values include SDDS_SHORT, SDDS_LONG, SDDS_FLOAT, etc. |
format | Optional printf format string to use; pass NULL to use the default format for the data type. |
fp | The FILE pointer to the ASCII file stream where the data will be written. |
Definition at line 57 of file SDDS_ascii.c.