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

This file contains the implementation of the SDDS output routines. More...

#include "SDDS.h"
#include "SDDS_internal.h"
#include "mdb.h"
#include <ctype.h>
#include <unistd.h>

Go to the source code of this file.

Functions

int32_t SDDS_DisconnectFile (SDDS_DATASET *SDDS_dataset)
 Disconnects the SDDS dataset from its associated file.
 
int32_t SDDS_ReconnectFile (SDDS_DATASET *SDDS_dataset)
 Reconnects the SDDS dataset to its previously associated file.
 
long SDDS_DisconnectInputFile (SDDS_DATASET *SDDS_dataset)
 Disconnects the input file from the SDDS dataset.
 
int32_t SDDS_ReconnectInputFile (SDDS_DATASET *SDDS_dataset, long position)
 Reconnects the input file for the SDDS dataset at a specified position.
 
int32_t SDDS_InitializeAppend (SDDS_DATASET *SDDS_dataset, const char *filename)
 Initializes the SDDS dataset for appending data by adding a new page to an existing file.
 
int32_t SDDS_InitializeAppendToPage (SDDS_DATASET *SDDS_dataset, const char *filename, int64_t updateInterval, int64_t *rowsPresentReturn)
 Initializes the SDDS dataset for appending data to the last page of an existing file.
 
int32_t SDDS_InitializeOutput (SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
 Initializes the SDDS output dataset.
 
int32_t SDDS_Parallel_InitializeOutput (SDDS_DATASET *SDDS_dataset, const char *description, const char *contents, const char *filename)
 Initializes the SDDS output dataset for parallel processing.
 
int32_t SDDS_SetNoRowCounts (SDDS_DATASET *SDDS_dataset, int32_t value)
 Sets the flag to enable or disable row counts in the SDDS dataset.
 
int32_t SDDS_WriteLayout (SDDS_DATASET *SDDS_dataset)
 Writes the SDDS layout header to the output file.
 
int32_t SDDS_WritePage (SDDS_DATASET *SDDS_dataset)
 Writes the current data table to the output file.
 
int32_t SDDS_UpdatePage (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 Updates the current page of the SDDS dataset.
 
int32_t SDDS_SyncDataSet (SDDS_DATASET *SDDS_dataset)
 Synchronizes the SDDS dataset with the disk by flushing buffered data.
 
int32_t SDDS_DefineParameter1 (SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, void *fixed_value)
 Defines a data parameter with a fixed numerical value.
 
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.
 
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_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.
 
int32_t SDDS_DefineSimpleColumn (SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
 Defines a simple data column within the SDDS dataset.
 
int32_t SDDS_DefineSimpleParameter (SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
 Defines a simple data parameter within the SDDS dataset.
 
int32_t SDDS_DefineSimpleColumns (SDDS_DATASET *SDDS_dataset, int32_t number, char **name, char **unit, int32_t type)
 Defines multiple simple data columns of the same data type within the SDDS dataset.
 
int32_t SDDS_DefineSimpleParameters (SDDS_DATASET *SDDS_dataset, int32_t number, char **name, char **unit, int32_t type)
 Defines multiple simple data parameters of the same data type within the SDDS dataset.
 
int32_t SDDS_SetNameValidityFlags (uint32_t flags)
 Sets the validity flags for parameter and column names in the SDDS dataset.
 
int32_t SDDS_IsValidName (const char *name, const char *class)
 Checks if a given name is valid for a specified class within the SDDS dataset.
 
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.
 
int32_t SDDS_EraseData (SDDS_DATASET *SDDS_dataset)
 Erases all data entries in the SDDS dataset.
 
int32_t SDDS_SetRowCountMode (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 Sets the row count mode for the SDDS dataset.
 
void SDDS_DisableFSync (SDDS_DATASET *SDDS_dataset)
 Disables file synchronization for the SDDS dataset.
 
void SDDS_EnableFSync (SDDS_DATASET *SDDS_dataset)
 Enables file synchronization for the SDDS dataset.
 
int32_t SDDS_DoFSync (SDDS_DATASET *SDDS_dataset)
 Synchronizes the SDDS dataset's file to disk.
 

Variables

static uint32_t nameValidityFlags = 0
 

Detailed Description

This file contains the implementation of the SDDS output routines.

This file provides functions for outputting data in the Self-Describing Data Sets (SDDS) format. It includes functions for creating and writing SDDS files, as well as functions for defining and appending data to the SDDS files.

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

Definition in file SDDS_output.c.

Function Documentation

◆ SDDS_DefineArray()

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.

This function processes the definition of a data array in the SDDS dataset. It allows the user to specify the array's name, symbol, units, description, format string, data type, field length, number of dimensions, and associated group name. The function ensures that the array name is valid and unique within the dataset before defining it.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the array. This name must be unique within the dataset.
[in]symbolA NULL-terminated string specifying the symbol for the array. Pass NULL if no symbol is desired.
[in]unitsA NULL-terminated string specifying the units of the array. Pass NULL if no units are desired.
[in]descriptionA NULL-terminated string providing a description of the array. Pass NULL if no description is desired.
[in]format_stringA NULL-terminated string specifying the printf-style format for ASCII output. If NULL is passed, a default format is selected based on the array type.
[in]typeAn integer representing the data type of the array. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
[in]field_lengthAn integer specifying the length of the field allotted to the array for ASCII output. If set to 0, the field length is ignored. If negative, the field length is set to the absolute value, and leading and trailing white-space are eliminated for SDDS_STRING types upon reading.
[in]dimensionsAn integer specifying the number of dimensions of the array. Must be greater than 0.
[in]group_nameA NULL-terminated string specifying the name of the array group to which this array belongs. This allows related arrays to be grouped together (e.g., parallel arrays).
Returns
  • On success, returns the index of the newly defined array within the dataset.
  • Returns -1 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The array name must be unique and valid.
  • The specified data type must be supported by the dataset.
Postcondition
  • The array is defined within the dataset with the specified attributes.
  • The dataset's internal structures are updated to include the new array.
Note
  • For string-type arrays, the fixed value is managed differently, and leading/trailing white-space is handled based on the field length parameter.
  • The function supports multi-dimensional arrays as specified by the dimensions parameter.
Warning
  • Defining an array with an invalid type, field length, or number of dimensions will result in an error.
  • Attempting to define an array with a name that already exists within the dataset will result in an error.

Definition at line 1592 of file SDDS_output.c.

1592 {
1593 SDDS_LAYOUT *layout;
1594 ARRAY_DEFINITION *definition;
1595 char s[SDDS_MAXLINE];
1596 SORTED_INDEX *new_indexed_array;
1597 int32_t index, duplicate;
1598
1599 if (!SDDS_IsValidName(name, "array"))
1600 return -1;
1601 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DefineArray"))
1602 return (-1);
1603 if (!name) {
1604 SDDS_SetError("NULL name not allowed for array definition");
1605 return (-1);
1606 }
1607 layout = &SDDS_dataset->layout;
1608 if (!(layout->array_definition =
1609 SDDS_Realloc(layout->array_definition, sizeof(*layout->array_definition) * (layout->n_arrays + 1))) ||
1610 !(layout->array_index = SDDS_Realloc(layout->array_index, sizeof(*layout->array_index) * (layout->n_arrays + 1))) || !(new_indexed_array = (SORTED_INDEX *)SDDS_Malloc(sizeof(*new_indexed_array)))) {
1611 SDDS_SetError("Memory allocation failure (SDDS_DefineArray)");
1612 return (-1);
1613 }
1614
1615 if (!SDDS_CopyString(&new_indexed_array->name, name))
1616 return -1;
1617 index = binaryInsert((void **)layout->array_index, layout->n_arrays, new_indexed_array, SDDS_CompareIndexedNames, &duplicate);
1618 if (duplicate) {
1619 sprintf(s, "Array %s already exists (SDDS_DefineArray)", name);
1620 SDDS_SetError(s);
1621 return (-1);
1622 }
1623 layout->array_index[index]->index = layout->n_arrays;
1624
1625 if (!SDDS_ZeroMemory(definition = layout->array_definition + layout->n_arrays, sizeof(ARRAY_DEFINITION))) {
1626 SDDS_SetError("Unable to define array--can't zero memory for array definition (SDDS_DefineArray)");
1627 return (-1);
1628 }
1629 definition->name = new_indexed_array->name;
1630 if ((symbol && !SDDS_CopyString(&definition->symbol, symbol)) || (units && !SDDS_CopyString(&definition->units, units)) || (description && !SDDS_CopyString(&definition->description, description)) || (group_name && !SDDS_CopyString(&definition->group_name, group_name))) {
1631 SDDS_SetError("Memory allocation failure (SDDS_DefineArray)");
1632 return (-1);
1633 }
1634 if (type <= 0 || type > SDDS_NUM_TYPES) {
1635 SDDS_SetError("Unknown data type (SDDS_DefineArray)");
1636 return (-1);
1637 }
1638 definition->type = type;
1639 if (format_string) {
1640 if (!SDDS_VerifyPrintfFormat(format_string, type)) {
1641 SDDS_SetError("Invalid format string (SDDS_DefineArray)");
1642 return (-1);
1643 }
1644 if (!SDDS_CopyString(&definition->format_string, format_string)) {
1645 SDDS_SetError("Memory allocation failure (SDDS_DefineArray)");
1646 return (-1);
1647 }
1648 }
1649 if ((definition->field_length = field_length) < 0 && type != SDDS_STRING) {
1650 SDDS_SetError("Invalid field length (SDDS_DefineArray)");
1651 return (-1);
1652 }
1653 if ((definition->dimensions = dimensions) < 1) {
1654 SDDS_SetError("Invalid number of dimensions for array (SDDS_DefineArray)");
1655 return (-1);
1656 }
1657 layout->n_arrays += 1;
1658 return (layout->n_arrays - 1);
1659}
int32_t SDDS_IsValidName(const char *name, const char *class)
Checks if a given name is valid for a specified class within the SDDS dataset.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.
int SDDS_CompareIndexedNames(const void *s1, const void *s2)
Compares two SORTED_INDEX structures by their name fields.
int32_t SDDS_VerifyPrintfFormat(const char *string, int32_t type)
Verifies that a printf format string is compatible with a specified data type.
Definition SDDS_utils.c:750
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
Definition SDDS_utils.c:639
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
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
Definition SDDStypes.h:97
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85

◆ SDDS_DefineAssociate()

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.

This function defines an associate for the SDDS dataset, allowing the association of additional files or data with the primary dataset. Associates can provide supplementary information or link related datasets together. The function sets up the necessary attributes such as name, filename, path, description, contents, and SDDS flag to describe the associate.

Note: This function is NOT USED in the current implementation and will always return 0 unless compiled with RW_ASSOCIATES defined.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the associate. This name must be unique within the dataset.
[in]filenameA NULL-terminated string specifying the filename of the associate. Must be a valid filename.
[in]pathA NULL-terminated string specifying the path to the associate. Pass NULL if no path is desired.
[in]descriptionA NULL-terminated string providing a description of the associate. Pass NULL if no description is desired.
[in]contentsA NULL-terminated string detailing the contents of the associate. Pass NULL if no contents are desired.
[in]sddsAn integer flag indicating the type of associate. Typically used to specify whether the associate is an SDDS file.
Returns
  • On success, returns the index of the newly defined associate within the dataset.
  • Returns a negative value on failure, with an error message set internally.
  • Returns 0 if RW_ASSOCIATES is not defined.
Precondition
  • The dataset must be initialized and configured for output.
  • RW_ASSOCIATES must be defined during compilation to use this feature.
  • The associate name and filename must be unique and valid.
Postcondition
  • The associate is defined within the dataset with the specified attributes.
  • The dataset's internal structures are updated to include the new associate.
Note
  • Associates provide a mechanism to link additional data or files to the primary SDDS dataset.
  • Properly defining associates can enhance data organization and accessibility.
Warning
  • Defining an associate with an invalid type, name, or filename will result in an error.
  • Attempting to define an associate with a name that already exists within the dataset will result in an error.
  • Ensure that the filename and path (if provided) are valid and accessible.

Definition at line 2153 of file SDDS_output.c.

2153 {
2154
2155#if RW_ASSOCIATES == 0
2156 return 0;
2157#else
2158 SDDS_LAYOUT *layout;
2159 ASSOCIATE_DEFINITION *definition;
2160 char s[SDDS_MAXLINE];
2161 if (!SDDS_IsValidName(name, "associate"))
2162 return -1;
2163 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DefineAssociate"))
2164 return (-1);
2165 layout = &SDDS_dataset->layout;
2166 if (!(layout->associate_definition = SDDS_Realloc(layout->associate_definition, sizeof(*layout->associate_definition) * (layout->n_associates + 1)))) {
2167 SDDS_SetError("Memory allocation failure (SDDS_DefineAssociate)");
2168 return (-1);
2169 }
2170 if (!name) {
2171 SDDS_SetError("NULL name not allowed for associate file (SDDS_DefineAssociate)");
2172 return (-1);
2173 }
2174 if (!filename) {
2175 SDDS_SetError("NULL filename not allowed for associate file (SDDS_DefineAssociate)");
2176 return (-1);
2177 }
2178 if (SDDS_GetAssociateIndex(SDDS_dataset, name) >= 0) {
2179 sprintf(s, "Associate with name %s already exists (SDDS_DefineAssociate)", name);
2180 SDDS_SetError(s);
2181 return (-1);
2182 }
2183 if (!SDDS_ZeroMemory(definition = layout->associate_definition + layout->n_associates, sizeof(ASSOCIATE_DEFINITION))) {
2184 SDDS_SetError("Unable to define associate--can't zero memory for associate (SDDS_DefineAssociate)");
2185 return (-1);
2186 }
2187
2188 if (!SDDS_CopyString(&definition->name, name)) {
2189 SDDS_SetError("Memory allocation failure (SDDS_DefineAssociate)");
2190 return (-1);
2191 }
2192 if (!SDDS_CopyString(&definition->filename, filename)) {
2193 SDDS_SetError("Memory allocation failure (SDDS_DefineAssociate)");
2194 return (-1);
2195 }
2196 if (path && !SDDS_CopyString(&definition->path, path)) {
2197 SDDS_SetError("Memory allocation failure (SDDS_DefineAssociate)");
2198 return (-1);
2199 }
2200 if (contents && !SDDS_CopyString(&definition->contents, contents)) {
2201 SDDS_SetError("Memory allocation failure (SDDS_DefineAssociate)");
2202 return (-1);
2203 }
2204 if (description && !SDDS_CopyString(&definition->description, description)) {
2205 SDDS_SetError("Memory allocation failure (SDDS_DefineAssociate)");
2206 return (-1);
2207 }
2208 definition->sdds = sdds;
2209 layout->n_associates += 1;
2210 return (layout->n_associates - 1);
2211#endif
2212}
int32_t SDDS_GetAssociateIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named associate in the SDDS dataset.

◆ SDDS_DefineColumn()

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.

This function processes the definition of a data column in the SDDS dataset. It allows the user to specify the column's name, symbol, units, description, format string, data type, and field length. The function ensures that the column name is valid and unique within the dataset before defining it.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the column. This name must be unique within the dataset.
[in]symbolA NULL-terminated string specifying the symbol for the column. Pass NULL if no symbol is desired.
[in]unitsA NULL-terminated string specifying the units of the column. Pass NULL if no units are desired.
[in]descriptionA NULL-terminated string providing a description of the column. Pass NULL if no description is desired.
[in]format_stringA NULL-terminated string specifying the printf-style format for ASCII output. If NULL is passed, a default format is selected based on the column type.
[in]typeAn integer representing the data type of the column. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
[in]field_lengthAn integer specifying the length of the field allotted to the column for ASCII output. If set to 0, the field length is ignored. If negative, the field length is set to the absolute value, and leading and trailing white-space are eliminated for SDDS_STRING types upon reading.
Returns
  • On success, returns the index of the newly defined column within the dataset.
  • Returns -1 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The column name must be unique and valid.
  • The specified data type must be supported by the dataset.
Postcondition
  • The column is defined within the dataset with the specified attributes.
  • The dataset's internal structures are updated to include the new column.
  • If rows have already been allocated, the data arrays are resized to accommodate the new column.
Note
  • For string-type columns, the fixed value is managed differently, and leading/trailing white-space is handled based on the field length parameter.
  • The function ensures that data arrays are appropriately resized if data has already been allocated.
Warning
  • Defining a column with an invalid type, field length, or name will result in an error.
  • Attempting to define a column with a name that already exists within the dataset will result in an error.
  • Memory allocation failures during the definition process will lead to an error.

Definition at line 1709 of file SDDS_output.c.

1709 {
1710 SDDS_LAYOUT *layout;
1711 COLUMN_DEFINITION *definition;
1712 char s[SDDS_MAXLINE];
1713 SORTED_INDEX *new_indexed_column;
1714 int32_t index;
1715 int32_t duplicate;
1716
1717 if (!SDDS_IsValidName(name, "column"))
1718 return -1;
1719 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DefineColumn"))
1720 return (-1);
1721 if (!name) {
1722 SDDS_SetError("NULL name not allowed for column definition");
1723 return (-1);
1724 }
1725 layout = &SDDS_dataset->layout;
1726 if (!(layout->column_definition =
1727 SDDS_Realloc(layout->column_definition, sizeof(*layout->column_definition) * (layout->n_columns + 1))) ||
1728 !(layout->column_index = SDDS_Realloc(layout->column_index, sizeof(*layout->column_index) * (layout->n_columns + 1))) || !(new_indexed_column = (SORTED_INDEX *)SDDS_Malloc(sizeof(*new_indexed_column)))) {
1729 SDDS_SetError("Memory allocation failure (SDDS_DefineColumn)");
1730 return (-1);
1731 }
1732 if (!SDDS_CopyString(&new_indexed_column->name, name))
1733 return -1;
1734 index = binaryInsert((void **)layout->column_index, layout->n_columns, new_indexed_column, SDDS_CompareIndexedNames, &duplicate);
1735 if (duplicate) {
1736 sprintf(s, "Column %s already exists (SDDS_DefineColumn)", name);
1737 SDDS_SetError(s);
1738 return (-1);
1739 }
1740 layout->column_index[index]->index = layout->n_columns;
1741 if (!SDDS_ZeroMemory(definition = layout->column_definition + layout->n_columns, sizeof(COLUMN_DEFINITION))) {
1742 SDDS_SetError("Unable to define column--can't zero memory for column definition (SDDS_DefineColumn)");
1743 return (-1);
1744 }
1745 definition->name = new_indexed_column->name;
1746 if (symbol && !SDDS_CopyString(&definition->symbol, symbol)) {
1747 SDDS_SetError("Memory allocation failure (SDDS_DefineColumn)");
1748 return (-1);
1749 }
1750 if (units && !SDDS_CopyString(&definition->units, units)) {
1751 SDDS_SetError("Memory allocation failure (SDDS_DefineColumn)");
1752 return (-1);
1753 }
1754 if (description && !SDDS_CopyString(&definition->description, description)) {
1755 SDDS_SetError("Memory allocation failure (SDDS_DefineColumn)");
1756 return (-1);
1757 }
1758 if (type <= 0 || type > SDDS_NUM_TYPES) {
1759 SDDS_SetError("Unknown data type (SDDS_DefineColumn)");
1760 return (-1);
1761 }
1762 definition->type = type;
1763 if (format_string) {
1764 if (!SDDS_VerifyPrintfFormat(format_string, type)) {
1765 SDDS_SetError("Invalid format string (SDDS_DefineColumn)");
1766 return (-1);
1767 }
1768 if (!SDDS_CopyString(&definition->format_string, format_string)) {
1769 SDDS_SetError("Memory allocation failure (SDDS_DefineColumn)");
1770 return (-1);
1771 }
1772 }
1773 if ((definition->field_length = field_length) < 0 && type != SDDS_STRING) {
1774 SDDS_SetError("Invalid field length (SDDS_DefineColumn)");
1775 return (-1);
1776 }
1777
1778 if (SDDS_dataset->n_rows_allocated) {
1779 if (!SDDS_dataset->data) {
1780 SDDS_SetError("data array NULL but rows have been allocated! (SDDS_DefineColumn)");
1781 return (-1);
1782 }
1783 /* data already present--must resize data and parameter memory */
1784 if (!(SDDS_dataset->data = SDDS_Realloc(SDDS_dataset->data, sizeof(*SDDS_dataset->data) * (layout->n_columns + 1))) || !(SDDS_dataset->data[layout->n_columns] = calloc(SDDS_dataset->n_rows_allocated, SDDS_type_size[type - 1]))) {
1785 SDDS_SetError("Memory allocation failure (SDDS_DefineColumn)");
1786 return (-1);
1787 }
1788 }
1789
1790 /* not part of output: */
1791 definition->definition_mode = SDDS_NORMAL_DEFINITION;
1792 if (type == SDDS_STRING)
1793 definition->memory_number = SDDS_CreateRpnMemory(name, 1);
1794 else {
1795 definition->memory_number = SDDS_CreateRpnMemory(name, 0);
1796 }
1797 sprintf(s, "&%s", name);
1798 definition->pointer_number = SDDS_CreateRpnArray(s);
1799
1800 layout->n_columns += 1;
1801 return (layout->n_columns - 1);
1802}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
int64_t SDDS_CreateRpnMemory(const char *name, short is_string)
Stub function for creating RPN memory when RPN_SUPPORT is not enabled.
Definition SDDS_rpn.c:785
int64_t SDDS_CreateRpnArray(char *name)
Stub function for creating RPN arrays when RPN_SUPPORT is not enabled.
Definition SDDS_rpn.c:795

◆ SDDS_DefineParameter()

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.

This function processes the definition of a data parameter within the SDDS dataset. It allows the specification of a fixed string value for the parameter, which remains constant across all data entries. The function validates the parameter name, type, and format string before defining the parameter in the dataset.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the parameter. This name must be unique within the dataset.
[in]symbolA NULL-terminated string specifying the symbol for the parameter. Pass NULL if no symbol is desired.
[in]unitsA NULL-terminated string specifying the units of the parameter. Pass NULL if no units are desired.
[in]descriptionA NULL-terminated string providing a description of the parameter. Pass NULL if no description is desired.
[in]format_stringA NULL-terminated string specifying the printf-style format for ASCII output. If NULL is passed, a default format is selected based on the parameter type.
[in]typeAn integer representing the data type of the parameter. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
[in]fixed_valueA NULL-terminated string specifying the fixed value of the parameter. For non-string types, this string should be formatted appropriately using functions like sprintf.
Returns
  • On success, returns the index of the newly defined parameter within the dataset.
  • Returns -1 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The parameter name must be unique and valid.
  • The fixed value must be a valid string representation for the specified parameter type.
Postcondition
  • The parameter is defined within the dataset with the specified attributes and fixed value.
  • The dataset's internal structures are updated to include the new parameter.
Note
  • For numerical parameter types, the fixed value string should represent the numerical value correctly.
  • The function internally handles the conversion of the fixed value string to the appropriate type based on the parameter's data type.
Warning
  • Defining a parameter with an invalid type or format string will result in an error.
  • Passing an improperly formatted fixed value string for the specified type may lead to unexpected behavior.

Definition at line 1466 of file SDDS_output.c.

1466 {
1467 SDDS_LAYOUT *layout;
1468 PARAMETER_DEFINITION *definition;
1469 char s[SDDS_MAXLINE];
1470 SORTED_INDEX *new_indexed_parameter;
1471 int32_t index, duplicate;
1472
1473 if (!SDDS_IsValidName(name, "parameter"))
1474 return -1;
1475 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DefineParameter"))
1476 return (-1);
1477 if (!name) {
1478 SDDS_SetError("NULL name not allowed for parameter definition");
1479 return (-1);
1480 }
1481 layout = &SDDS_dataset->layout;
1482 if (!(layout->parameter_definition =
1483 SDDS_Realloc(layout->parameter_definition, sizeof(*layout->parameter_definition) * (layout->n_parameters + 1))) ||
1484 !(layout->parameter_index = SDDS_Realloc(layout->parameter_index, sizeof(*layout->parameter_index) * (layout->n_parameters + 1))) || !(new_indexed_parameter = (SORTED_INDEX *)SDDS_Malloc(sizeof(*new_indexed_parameter)))) {
1485 SDDS_SetError("Memory allocation failure (SDDS_DefineParameter)");
1486 return (-1);
1487 }
1488 if (!SDDS_CopyString(&new_indexed_parameter->name, name))
1489 return -1;
1490 index = binaryInsert((void **)layout->parameter_index, layout->n_parameters, new_indexed_parameter, SDDS_CompareIndexedNames, &duplicate);
1491 if (duplicate) {
1492 sprintf(s, "Parameter %s already exists (SDDS_DefineParameter)", name);
1493 SDDS_SetError(s);
1494 return (-1);
1495 }
1496 layout->parameter_index[index]->index = layout->n_parameters;
1497
1498 if (!SDDS_ZeroMemory(definition = layout->parameter_definition + layout->n_parameters, sizeof(PARAMETER_DEFINITION))) {
1499 SDDS_SetError("Unable to define parameter--can't zero memory for parameter definition (SDDS_DefineParameter)");
1500 return (-1);
1501 }
1502 definition->name = new_indexed_parameter->name;
1503 if (symbol && !SDDS_CopyString(&definition->symbol, symbol)) {
1504 SDDS_SetError("Memory allocation failure (SDDS_DefineParameter)");
1505 return (-1);
1506 }
1507 if (units && !SDDS_CopyString(&definition->units, units)) {
1508 SDDS_SetError("Memory allocation failure (SDDS_DefineParameter)");
1509 return (-1);
1510 }
1511 if (description && !SDDS_CopyString(&definition->description, description)) {
1512 SDDS_SetError("Memory allocation failure (SDDS_DefineParameter)");
1513 return (-1);
1514 }
1515 if (type <= 0 || type > SDDS_NUM_TYPES) {
1516 SDDS_SetError("Unknown data type (SDDS_DefineParameter)");
1517 return (-1);
1518 }
1519 definition->type = type;
1520 if (format_string) {
1521 if (!SDDS_VerifyPrintfFormat(format_string, type)) {
1522 SDDS_SetError("Invalid format string (SDDS_DefineParameter)");
1523 return (-1);
1524 }
1525 if (!SDDS_CopyString(&definition->format_string, format_string)) {
1526 SDDS_SetError("Memory allocation failure (SDDS_DefineParameter)");
1527 return (-1);
1528 }
1529 }
1530 if (fixed_value && !SDDS_CopyString(&(definition->fixed_value), fixed_value)) {
1531 SDDS_SetError("Couldn't copy fixed_value string (SDDS_DefineParameter)");
1532 return (-1);
1533 }
1534 definition->definition_mode = SDDS_NORMAL_DEFINITION;
1535 if (type == SDDS_STRING)
1536 definition->memory_number = SDDS_CreateRpnMemory(name, 1);
1537 else
1538 definition->memory_number = SDDS_CreateRpnMemory(name, 0);
1539 layout->n_parameters += 1;
1540 return (layout->n_parameters - 1);
1541}

◆ SDDS_DefineParameter1()

int32_t SDDS_DefineParameter1 ( SDDS_DATASET * SDDS_dataset,
const char * name,
const char * symbol,
const char * units,
const char * description,
const char * format_string,
int32_t type,
void * fixed_value )

Defines a data parameter with a fixed numerical value.

This function processes the definition of a data parameter within the SDDS dataset. It allows the specification of a fixed numerical value for the parameter, which remains constant across all data entries. The function validates the parameter name, type, and format string before defining the parameter in the dataset.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the parameter. This name must be unique within the dataset.
[in]symbolA NULL-terminated string specifying the symbol for the parameter. Pass NULL if no symbol is desired.
[in]unitsA NULL-terminated string specifying the units of the parameter. Pass NULL if no units are desired.
[in]descriptionA NULL-terminated string providing a description of the parameter. Pass NULL if no description is desired.
[in]format_stringA NULL-terminated string specifying the printf-style format for ASCII output. If NULL is passed, a default format is selected based on the parameter type.
[in]typeAn integer representing the data type of the parameter. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
[in]fixed_valueA pointer to the numerical value that remains constant for this parameter across all data entries. This value is used to initialize the parameter's fixed value.
Returns
  • On success, returns the index of the newly defined parameter within the dataset.
  • Returns -1 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The parameter name must be unique and valid.
  • The fixed value must be non-NULL for numerical types and should be prepared appropriately.
Postcondition
  • The parameter is defined within the dataset with the specified attributes and fixed value.
  • The dataset's internal structures are updated to include the new parameter.
Note
  • For string-type parameters, the fixed value should be a NULL-terminated string.
  • The function internally converts the fixed numerical value to a string representation if the parameter type is not SDDS_STRING.
Warning
  • Defining a parameter with an invalid type or format string will result in an error.
  • Passing a NULL fixed value for non-string types will result in an error.

Definition at line 1401 of file SDDS_output.c.

1401 {
1402 char buffer[SDDS_MAXLINE];
1403 if (!SDDS_IsValidName(name, "parameter"))
1404 return -1;
1405 if (!fixed_value || type == SDDS_STRING)
1406 return SDDS_DefineParameter(SDDS_dataset, name, symbol, units, description, format_string, type, fixed_value);
1407 if (type <= 0 || type > SDDS_NUM_TYPES) {
1408 SDDS_SetError("Unknown data type (SDDS_DefineParameter1)");
1409 return (-1);
1410 }
1411 buffer[SDDS_MAXLINE - 1] = 0;
1412 if (!SDDS_SprintTypedValue(fixed_value, 0, type, format_string, buffer, 0) || buffer[SDDS_MAXLINE - 1] != 0) {
1413 SDDS_SetError("Unable to define fixed value for parameter (SDDS_DefineParameter1)");
1414 return (-1);
1415 }
1416 return SDDS_DefineParameter(SDDS_dataset, name, symbol, units, description, format_string, type, buffer);
1417}
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.
int32_t SDDS_SprintTypedValue(void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode)
Formats a data value of a specified type into a string buffer using an optional printf format string.
Definition SDDS_utils.c:151

◆ SDDS_DefineSimpleColumn()

int32_t SDDS_DefineSimpleColumn ( SDDS_DATASET * SDDS_dataset,
const char * name,
const char * unit,
int32_t type )

Defines a simple data column within the SDDS dataset.

This function provides a simplified interface for defining a data column in the SDDS dataset. It allows the user to specify only the column's name, units, and data type, while omitting optional parameters such as symbol, description, format string, and field length. Internally, it calls SDDS_DefineColumn with default values for the omitted parameters.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the column. This name must be unique within the dataset.
[in]unitA NULL-terminated string specifying the units of the column. Pass NULL if no units are desired.
[in]typeAn integer representing the data type of the column. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
Returns
  • 1 on successful definition of the column.
  • 0 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The column name must be unique and valid.
Postcondition
  • The column is defined within the dataset with the specified name, units, and type.
  • The dataset's internal structures are updated to include the new column.
Note
  • This function is intended for scenarios where only basic column attributes are needed.
  • Optional parameters such as symbol, description, format string, and field length are set to default values.
Warning
  • Defining a column with an invalid type or name will result in an error.
  • Attempting to define a column with a name that already exists within the dataset will result in an error.

Definition at line 1846 of file SDDS_output.c.

1846 {
1847 if (SDDS_DefineColumn(SDDS_dataset, name, NULL, unit, NULL, NULL, type, 0) < 0)
1848 return 0;
1849 return (1);
1850}
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.

◆ SDDS_DefineSimpleColumns()

int32_t SDDS_DefineSimpleColumns ( SDDS_DATASET * SDDS_dataset,
int32_t number,
char ** name,
char ** unit,
int32_t type )

Defines multiple simple data columns of the same data type within the SDDS dataset.

This function provides a streamlined way to define multiple data columns in the SDDS dataset that share the same data type. It allows the user to specify the names and units of the columns, while omitting optional attributes such as symbol, description, format string, and field length. Internally, it calls SDDS_DefineColumn for each column with default values for the omitted parameters.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]numberThe number of columns to define. Must be greater than or equal to 0.
[in]nameAn array of NULL-terminated strings specifying the names of the columns. Each name must be unique within the dataset.
[in]unitAn array of NULL-terminated strings specifying the units of the columns. Pass NULL for elements where no units are desired.
[in]typeAn integer representing the data type for all the columns. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
Returns
  • 1 on successful definition of all specified columns.
  • 0 on failure to define any of the columns, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The name array must contain unique and valid names for each column.
  • The type must be a supported data type.
Postcondition
  • All specified columns are defined within the dataset with the provided names and units.
  • The dataset's internal structures are updated to include the new columns.
Note
  • Passing number as 0 results in no action and returns success.
  • This function is optimized for defining multiple columns of the same type, enhancing code readability and efficiency.
Warning
  • Defining a column with an invalid type or name will result in an error.
  • Attempting to define a column with a name that already exists within the dataset will result in an error.
  • Ensure that the name and unit arrays are properly allocated and contain valid strings.

Definition at line 1945 of file SDDS_output.c.

1945 {
1946 int32_t i;
1947 if (!number)
1948 return (1);
1949 if (!name)
1950 return 0;
1951 for (i = 0; i < number; i++)
1952 if (SDDS_DefineColumn(SDDS_dataset, name[i], NULL, unit ? unit[i] : NULL, NULL, NULL, type, 0) < 0)
1953 return 0;
1954 return (1);
1955}

◆ SDDS_DefineSimpleParameter()

int32_t SDDS_DefineSimpleParameter ( SDDS_DATASET * SDDS_dataset,
const char * name,
const char * unit,
int32_t type )

Defines a simple data parameter within the SDDS dataset.

This function provides a simplified interface for defining a data parameter in the SDDS dataset. It allows the user to specify only the parameter's name, units, and data type, while omitting optional attributes such as symbol, description, format string, and fixed value. Internally, it calls SDDS_DefineParameter with default values for the omitted parameters.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the parameter. This name must be unique within the dataset.
[in]unitA NULL-terminated string specifying the units of the parameter. Pass NULL if no units are desired.
[in]typeAn integer representing the data type of the parameter. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
Returns
  • 1 on successful definition of the parameter.
  • 0 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The parameter name must be unique and valid.
Postcondition
  • The parameter is defined within the dataset with the specified name, units, and type.
  • The dataset's internal structures are updated to include the new parameter.
Note
  • This function is intended for scenarios where only basic parameter attributes are needed.
  • Optional parameters such as symbol, description, format string, and fixed value are set to default values.
Warning
  • Defining a parameter with an invalid type or name will result in an error.
  • Attempting to define a parameter with a name that already exists within the dataset will result in an error.

Definition at line 1894 of file SDDS_output.c.

1894 {
1895 if (SDDS_DefineParameter(SDDS_dataset, name, NULL, unit, NULL, NULL, type, NULL) < 0)
1896 return 0;
1897 return (1);
1898}

◆ SDDS_DefineSimpleParameters()

int32_t SDDS_DefineSimpleParameters ( SDDS_DATASET * SDDS_dataset,
int32_t number,
char ** name,
char ** unit,
int32_t type )

Defines multiple simple data parameters of the same data type within the SDDS dataset.

This function provides a streamlined way to define multiple data parameters in the SDDS dataset that share the same data type. It allows the user to specify the names and units of the parameters, while omitting optional attributes such as symbol, description, format string, and fixed value. Internally, it calls SDDS_DefineParameter for each parameter with default values for the omitted parameters.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]numberThe number of parameters to define. Must be greater than or equal to 0.
[in]nameAn array of NULL-terminated strings specifying the names of the parameters. Each name must be unique within the dataset.
[in]unitAn array of NULL-terminated strings specifying the units of the parameters. Pass NULL for elements where no units are desired.
[in]typeAn integer representing the data type for all the parameters. Must be one of the following:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
Returns
  • 1 on successful definition of all specified parameters.
  • 0 on failure to define any of the parameters, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The name array must contain unique and valid names for each parameter.
  • The type must be a supported data type.
Postcondition
  • All specified parameters are defined within the dataset with the provided names and units.
  • The dataset's internal structures are updated to include the new parameters.
Note
  • Passing number as 0 results in no action and returns success.
  • This function is optimized for defining multiple parameters of the same type, enhancing code readability and efficiency.
Warning
  • Defining a parameter with an invalid type or name will result in an error.
  • Attempting to define a parameter with a name that already exists within the dataset will result in an error.
  • Ensure that the name and unit arrays are properly allocated and contain valid strings.

Definition at line 2002 of file SDDS_output.c.

2002 {
2003 int32_t i;
2004 if (!number)
2005 return (1);
2006 if (!name)
2007 return 0;
2008 for (i = 0; i < number; i++)
2009 if (SDDS_DefineParameter(SDDS_dataset, name[i], NULL, unit ? unit[i] : NULL, NULL, NULL, type, NULL) < 0)
2010 return 0;
2011 return (1);
2012}

◆ SDDS_DisableFSync()

void SDDS_DisableFSync ( SDDS_DATASET * SDDS_dataset)

Disables file synchronization for the SDDS dataset.

This function disables the file synchronization feature for the specified SDDS dataset. File synchronization ensures that all buffered data is immediately written to disk, enhancing data integrity. By disabling this feature, the dataset will no longer perform synchronous writes, which can improve performance but may risk data loss in the event of a system failure.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Postcondition
  • File synchronization is disabled, meaning that SDDS_SyncDataSet will not call fsync.
Note
  • Disabling file synchronization can lead to improved performance, especially when writing large datasets.
  • It is recommended to use this function only when performance is a higher priority than immediate data integrity.
Warning
  • Without file synchronization, there is a risk of data loss if the system crashes before buffered data is written to disk.
  • Ensure that data integrity is managed through other means if synchronization is disabled.

Definition at line 2374 of file SDDS_output.c.

2374 {
2375 SDDS_dataset->layout.data_mode.fsync_data = 0;
2376}

◆ SDDS_DisconnectFile()

int32_t SDDS_DisconnectFile ( SDDS_DATASET * SDDS_dataset)

Disconnects the SDDS dataset from its associated file.

This function terminates the connection between the SDDS dataset and the file it is currently linked to. It ensures that all pending data is flushed to the file, closes the file handle, and updates the dataset's internal state to reflect that it is no longer connected to any file.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to be disconnected.
Returns
  • 1 on successful disconnection.
  • 0 if an error occurred during disconnection. In this case, an error message is set internally.
Note
  • If the dataset is already disconnected, this function will return an error.
  • This function is not thread-safe if the dataset is being accessed concurrently.
Warning
  • Ensure that no further operations are performed on the dataset after disconnection unless it is reconnected.

Definition at line 70 of file SDDS_output.c.

70 {
71#if SDDS_MPI_IO
72 if (SDDS_dataset->parallel_io)
73 return SDDS_MPI_DisconnectFile(SDDS_dataset);
74#endif
75 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DisconnectFile"))
76 return 0;
77 if (!SDDS_dataset->layout.filename) {
78 SDDS_SetError("Can't disconnect file. No filename given. (SDDS_DisconnectFile)");
79 return 0;
80 }
81 if (SDDS_dataset->layout.gzipFile) {
82 SDDS_SetError("Can't disconnect file because it is a gzip file. (SDDS_DisconnectFile)");
83 return 0;
84 }
85 if (SDDS_dataset->layout.lzmaFile) {
86 SDDS_SetError("Can't disconnect file because it is a lzma or xz file. (SDDS_DisconnectFile)");
87 return 0;
88 }
89 if (SDDS_dataset->layout.disconnected) {
90 SDDS_SetError("Can't disconnect file. Already disconnected. (SDDS_DisconnectFile)");
91 return 0;
92 }
93 if (SDDS_dataset->page_started && !SDDS_UpdatePage(SDDS_dataset, FLUSH_TABLE)) {
94 SDDS_SetError("Can't disconnect file. Problem updating page. (SDDS_DisconnectFile)");
95 return 0;
96 }
97 if (fclose(SDDS_dataset->layout.fp)) {
98 SDDS_SetError("Can't disconnect file. Problem closing file. (SDDS_DisconnectFile)");
99 return 0;
100 }
101 SDDS_dataset->layout.disconnected = 1;
102 return 1;
103}
int32_t SDDS_UpdatePage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the current page of the SDDS dataset.
int32_t SDDS_MPI_DisconnectFile(SDDS_DATASET *SDDS_dataset)
Disconnects the MPI file associated with the SDDS dataset.

◆ SDDS_DisconnectInputFile()

long SDDS_DisconnectInputFile ( SDDS_DATASET * SDDS_dataset)

Disconnects the input file from the SDDS dataset.

This function severs the connection between the SDDS dataset and its input file. It closes the file handle, updates the dataset's internal state to indicate disconnection, and returns the current file position before closing. After disconnection, the dataset cannot read further data from the input file until it is reconnected.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure whose input file is to be disconnected.
Returns
  • On success, returns the current file position (as obtained by ftell) before disconnection.
  • On failure, returns -1 and sets an internal error message.
Note
  • This function cannot disconnect compressed input files (gzip, lzma, xz).
  • Attempting to disconnect an already disconnected dataset will result in an error.
Warning
  • Ensure that no further read operations are performed on the dataset after disconnection unless it is reconnected.

Definition at line 170 of file SDDS_output.c.

170 {
171 long position;
172#if SDDS_MPI_IO
173 if (SDDS_dataset->parallel_io) {
174 SDDS_SetError("Error: MPI mode not supported yet in SDDS_DisconnectInputFile");
175 return -1;
176 }
177#endif
178 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DisconnectInputFile"))
179 return -1;
180 if (!SDDS_dataset->layout.filename) {
181 SDDS_SetError("Can't disconnect file. No filename given. (SDDS_DisconnectInputFile)");
182 return -1;
183 }
184 if (SDDS_dataset->layout.gzipFile) {
185 SDDS_SetError("Can't disconnect file because it is a gzip file. (SDDS_DisconnectInputFile)");
186 return -1;
187 }
188 if (SDDS_dataset->layout.lzmaFile) {
189 SDDS_SetError("Can't disconnect file because it is a lzma or xz file. (SDDS_DisconnectInputFile)");
190 return -1;
191 }
192 if (SDDS_dataset->layout.disconnected) {
193 SDDS_SetError("Can't disconnect file. Already disconnected. (SDDS_DisconnectInputFile)");
194 return -1;
195 }
196 position = ftell(SDDS_dataset->layout.fp);
197 if (fclose(SDDS_dataset->layout.fp)) {
198 SDDS_SetError("Can't disconnect file. Problem closing file. (SDDS_DisconnectInputFile)");
199 return -1;
200 }
201 SDDS_dataset->layout.disconnected = 1;
202 return position;
203}

◆ SDDS_DoFSync()

int32_t SDDS_DoFSync ( SDDS_DATASET * SDDS_dataset)

Synchronizes the SDDS dataset's file to disk.

Performs a file synchronization operation on the specified SDDS dataset to ensure that all buffered data is flushed to the storage medium. This is crucial for maintaining data integrity, especially in scenarios where unexpected shutdowns or crashes may occur.

Platform-Specific Behavior

  • vxWorks, Windows (_WIN32), macOS (APPLE):
    • The function assumes that synchronization is always successful and returns 1.
  • Other Platforms:
    • Attempts to flush the dataset's file buffer to disk using the fsync system call.
    • Returns 1 if fsync succeeds, indicating successful synchronization.
    • Returns 0 if fsync fails or if the dataset/file pointer is invalid.
Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to be synchronized.
Returns
int32_t
  • 1 on successful synchronization.
  • 0 on failure.

Definition at line 2423 of file SDDS_output.c.

2423 {
2424#if defined(vxWorks) || defined(_WIN32) || defined(__APPLE__)
2425 return 1;
2426#else
2427 if (SDDS_dataset && SDDS_dataset->layout.fp)
2428 return fsync(fileno(SDDS_dataset->layout.fp)) == 0;
2429 return 0;
2430#endif
2431}

◆ SDDS_EnableFSync()

void SDDS_EnableFSync ( SDDS_DATASET * SDDS_dataset)

Enables file synchronization for the SDDS dataset.

This function enables the file synchronization feature for the specified SDDS dataset. File synchronization ensures that all buffered data is immediately written to disk, enhancing data integrity. Enabling this feature can be crucial for applications where data consistency and reliability are paramount.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Postcondition
  • File synchronization is enabled, meaning that SDDS_SyncDataSet will call fsync to flush buffers to disk.
Note
  • Enabling file synchronization may impact performance due to the increased number of disk write operations.
  • It is recommended to enable synchronization when data integrity is critical, such as in transactional systems.
Warning
  • Frequent synchronization can lead to reduced performance, especially when writing large amounts of data.
  • Balance the need for data integrity with performance requirements based on the specific use case.

Definition at line 2398 of file SDDS_output.c.

2398 {
2399 SDDS_dataset->layout.data_mode.fsync_data = 1;
2400}

◆ SDDS_EraseData()

int32_t SDDS_EraseData ( SDDS_DATASET * SDDS_dataset)

Erases all data entries in the SDDS dataset.

This function removes all data from the specified SDDS dataset, effectively resetting it to an empty state. It frees any allocated memory associated with data columns, parameters, and arrays, ensuring that all dynamic data is properly cleared. This is useful for reusing the dataset for new data without retaining previous entries.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Returns
  • 1 on successful erasure of all data.
  • 0 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured.
Postcondition
  • All data rows are removed from the dataset.
  • Memory allocated for data columns, parameters, and arrays is freed.
  • The dataset is ready to accept new data entries.
Note
  • This function does not alter the dataset's layout definitions; only the data entries are cleared.
  • After erasing data, the dataset can be reused to write new data tables without redefining the layout.
Warning
  • Erasing data is irreversible; ensure that any necessary data is backed up before calling this function.
  • Concurrent access to the dataset while erasing data may lead to undefined behavior.

Definition at line 2244 of file SDDS_output.c.

2244 {
2245 SDDS_LAYOUT *layout;
2246 int64_t i, j;
2247 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_EraseData"))
2248 return 0;
2249 layout = &SDDS_dataset->layout;
2250 if (SDDS_dataset->data) {
2251 for (i = 0; i < layout->n_columns; i++) {
2252 if (!SDDS_dataset->data[i])
2253 continue;
2254 if (layout->column_definition[i].type == SDDS_STRING) {
2255 for (j = 0; j < SDDS_dataset->n_rows; j++) {
2256 if (((char **)SDDS_dataset->data[i])[j]) {
2257 free(((char **)SDDS_dataset->data[i])[j]);
2258 ((char **)SDDS_dataset->data[i])[j] = NULL;
2259 }
2260 }
2261 }
2262 }
2263 }
2264 SDDS_dataset->n_rows = 0;
2265
2266 if (SDDS_dataset->parameter) {
2267 for (i = 0; i < layout->n_parameters; i++) {
2268 if (!SDDS_dataset->parameter[i])
2269 continue;
2270 if (layout->parameter_definition[i].type == SDDS_STRING && *(char **)(SDDS_dataset->parameter[i])) {
2271 free(*(char **)(SDDS_dataset->parameter[i]));
2272 *(char **)SDDS_dataset->parameter[i] = NULL;
2273 }
2274 }
2275 }
2276
2277 if (SDDS_dataset->array) {
2278 for (i = 0; i < layout->n_arrays; i++) {
2279 if (SDDS_dataset->array[i].definition->type == SDDS_STRING) {
2280 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
2281 if (((char **)SDDS_dataset->array[i].data)[j]) {
2282 free(((char **)SDDS_dataset->array[i].data)[j]);
2283 ((char **)SDDS_dataset->array[i].data)[j] = NULL;
2284 }
2285 }
2286 }
2287 }
2288 }
2289
2290 return (1);
2291}

◆ SDDS_InitializeAppend()

int32_t SDDS_InitializeAppend ( SDDS_DATASET * SDDS_dataset,
const char * filename )

Initializes the SDDS dataset for appending data by adding a new page to an existing file.

This function prepares the SDDS dataset for appending additional data to an existing SDDS file by initializing necessary data structures, verifying file integrity, and setting up for the addition of a new data page. It ensures that the file is writable, not compressed, and properly locked to prevent concurrent modifications.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to be initialized for appending.
[in]filenameThe name of the existing SDDS file to which data will be appended. If NULL, data will be appended to standard input.
Returns
  • 1 on successful initialization.
  • 0 on error. In this case, an internal error message is set describing the failure.
Precondition
  • The specified file must exist and be a valid SDDS file.
  • The file must not be compressed (gzip, lzma, xz) and must be accessible for read and write operations.
Postcondition
  • The dataset is ready to append data as a new page.
  • The file is locked to prevent concurrent writes.
Note
  • If filename is NULL, the dataset will append data from standard input.
  • The function sets internal flags indicating whether the file was previously empty or had existing data.
Warning
  • Appending to a compressed file is not supported and will result in an error.
  • Ensure that no other processes are accessing the file simultaneously to avoid conflicts.

Definition at line 287 of file SDDS_output.c.

287 {
288 /* char *ptr, *datafile, *headerfile; */
289 char s[SDDS_MAXLINE];
290 int64_t endOfLayoutOffset, endOfFileOffset;
291 char *extension;
292
293 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_InitializeAppend"))
294 return 0;
295 if (!SDDS_ZeroMemory((void *)SDDS_dataset, sizeof(SDDS_DATASET))) {
296 sprintf(s, "Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeAppend)", filename);
297 SDDS_SetError(s);
298 return 0;
299 }
300 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
301 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
302 if (!filename)
303 SDDS_dataset->layout.filename = NULL;
304 else if (!SDDS_CopyString(&SDDS_dataset->layout.filename, filename)) {
305 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeAppend)", filename);
306 SDDS_SetError(s);
307 return 0;
308 } else if ((extension = strrchr(filename, '.')) && ((strcmp(extension, ".gz") == 0) || (strcmp(extension, ".lzma") == 0) || (strcmp(extension, ".xz") == 0))) {
309 sprintf(s, "Cannot append to a compressed file %s (SDDS_InitializeAppend)", filename);
310 SDDS_SetError(s);
311 return 0;
312 }
313
314 SDDS_dataset->layout.popenUsed = 0;
315 if (!filename) {
316#if defined(_WIN32)
317 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
318 sprintf(s, "unable to set stdin to binary mode");
319 SDDS_SetError(s);
320 return 0;
321 }
322#endif
323 SDDS_dataset->layout.fp = stdin;
324 } else {
325 if (SDDS_FileIsLocked(filename)) {
326 sprintf(s, "unable to open file %s for appending--file is locked (SDDS_InitializeAppend)", filename);
327 SDDS_SetError(s);
328 return 0;
329 }
330 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_AND_WRITE_MODE))) {
331 sprintf(s, "Unable to open file %s for appending (SDDS_InitializeAppend)", filename);
332 SDDS_SetError(s);
333 return 0;
334 }
335 if (!SDDS_LockFile(SDDS_dataset->layout.fp, filename, "SDDS_InitializeAppend"))
336 return 0;
337 }
338
339 if (!SDDS_ReadLayout(SDDS_dataset, SDDS_dataset->layout.fp))
340 return 0;
341 endOfLayoutOffset = ftell(SDDS_dataset->layout.fp);
342 if (SDDS_dataset->layout.n_columns &&
343 (!(SDDS_dataset->column_flag = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
344 !(SDDS_dataset->column_order = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
345 !SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
346 !SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)0, (int32_t)1))) {
347 SDDS_SetError("Unable to initialize input--memory allocation failure (SDDS_InitializeAppend)");
348 return 0;
349 }
350 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
351 SDDS_SetError("Unable to initialize append--seek failure (SDDS_InitializeAppend)");
352 return 0;
353 }
354 endOfFileOffset = ftell(SDDS_dataset->layout.fp);
355 if (endOfFileOffset == endOfLayoutOffset)
356 SDDS_dataset->file_had_data = 0; /* appending to empty file */
357 else
358 SDDS_dataset->file_had_data = 1; /* appending to nonempty file */
359 SDDS_dataset->layout.layout_written = 1; /* its already in the file */
360 SDDS_dataset->mode = SDDS_WRITEMODE; /*writing */
361 return 1;
362}
int32_t SDDS_ReadLayout(SDDS_DATASET *SDDS_dataset, FILE *fp)
Definition SDDS_input.c:517
int32_t SDDS_FileIsLocked(const char *filename)
Determines if a specified file is locked.
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.
int32_t SDDS_LockFile(FILE *fp, const char *filename, const char *caller)
Attempts to lock a specified file.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61

◆ SDDS_InitializeAppendToPage()

int32_t SDDS_InitializeAppendToPage ( SDDS_DATASET * SDDS_dataset,
const char * filename,
int64_t updateInterval,
int64_t * rowsPresentReturn )

Initializes the SDDS dataset for appending data to the last page of an existing file.

This function sets up the SDDS dataset to append additional data rows to the last page of an existing SDDS file. It reads the existing file layout, determines the current state of data (including row counts), and prepares internal data structures to accommodate new data. The function also handles file locking, buffer management, and ensures that the file is ready for efficient data appending based on the specified update interval.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to be initialized for appending.
[in]filenameThe name of the existing SDDS file to which data will be appended. If NULL, data will be appended to standard input.
[in]updateIntervalThe number of rows to write before the dataset reallocates memory or flushes data. This parameter controls the frequency of memory allocation and disk I/O operations during the append process.
[out]rowsPresentReturnPointer to an int64_t variable where the function will store the number of rows present in the dataset after initialization. This provides information on the current dataset size.
Returns
  • 1 on successful initialization.
  • 0 on error. In this case, an internal error message is set detailing the issue.
Precondition
  • The specified file must exist and be a valid SDDS file.
  • The file must not be compressed (gzip, lzma, xz) and must be accessible for read and write operations.
Postcondition
  • The dataset is configured to append data to the last page of the file.
  • Internal structures are initialized to track row counts and manage memory efficiently based on the update interval.
  • The file is locked to prevent concurrent modifications.
  • rowsPresentReturn is updated with the current number of rows in the dataset.
Note
  • If filename is NULL, data will be appended from standard input.
  • The function sets internal flags indicating whether the file already contained data prior to appending.
Warning
  • Appending to a compressed file is not supported and will result in an error.
  • Ensure that no other processes are accessing the file simultaneously to avoid conflicts.

Definition at line 396 of file SDDS_output.c.

396 {
397 /* char *ptr, *datafile, *headerfile; */
398 char s[SDDS_MAXLINE];
399 int64_t endOfLayoutOffset, endOfFileOffset, rowCountOffset, offset;
400 int32_t rowsPresent32;
401 int64_t rowsPresent;
402 char *extension;
403 int32_t previousBufferSize;
404
405 *rowsPresentReturn = -1;
406 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_InitializeAppendToPage"))
407 return 0;
408 if (!SDDS_ZeroMemory((void *)SDDS_dataset, sizeof(SDDS_DATASET))) {
409 sprintf(s, "Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeAppendToPage)", filename);
410 SDDS_SetError(s);
411 return 0;
412 }
413 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
414 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
415 if (!filename)
416 SDDS_dataset->layout.filename = NULL;
417 else if (!SDDS_CopyString(&SDDS_dataset->layout.filename, filename)) {
418 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeAppendToPage)", filename);
419 SDDS_SetError(s);
420 return 0;
421 } else if ((extension = strrchr(filename, '.')) && ((strcmp(extension, ".gz") == 0) || (strcmp(extension, ".lzma") == 0) || (strcmp(extension, ".xz") == 0))) {
422 sprintf(s, "Cannot append to a compressed file %s (SDDS_InitializeAppendToPage)", filename);
423 SDDS_SetError(s);
424 return 0;
425 }
426
427 if (!filename) {
428#if defined(_WIN32)
429 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
430 sprintf(s, "unable to set stdin to binary mode");
431 SDDS_SetError(s);
432 return 0;
433 }
434#endif
435 SDDS_dataset->layout.fp = stdin;
436 } else {
437 if (SDDS_FileIsLocked(filename)) {
438 sprintf(s, "unable to open file %s for appending--file is locked (SDDS_InitializeAppendToPage)", filename);
439 SDDS_SetError(s);
440 return 0;
441 }
442 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_AND_WRITE_MODE))) {
443 sprintf(s, "Unable to open file %s for appending (SDDS_InitializeAppendToPage)", filename);
444 SDDS_SetError(s);
445 return 0;
446 }
447 if (!SDDS_LockFile(SDDS_dataset->layout.fp, filename, "SDDS_InitializeAppendToPage")) {
448 return 0;
449 }
450 }
451
452 if (!SDDS_ReadLayout(SDDS_dataset, SDDS_dataset->layout.fp)) {
453 return 0;
454 }
455 endOfLayoutOffset = ftell(SDDS_dataset->layout.fp);
456 if (SDDS_dataset->layout.n_columns &&
457 (!(SDDS_dataset->column_flag = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
458 !(SDDS_dataset->column_order = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
459 !SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
460 !SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)0, (int32_t)1))) {
461 SDDS_SetError("Unable to initialize input--memory allocation failure (SDDS_InitializeAppendToPage)");
462 return 0;
463 }
464 rowCountOffset = -1;
465 rowsPresent = 0;
466#ifdef DEBUG
467 fprintf(stderr, "Data mode is %s\n", SDDS_data_mode[SDDS_dataset->layout.data_mode.mode - 1]);
468#endif
469 SDDS_dataset->pagecount_offset = NULL;
470 previousBufferSize = SDDS_SetDefaultIOBufferSize(0);
471 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
472 /* read pages to get to the last page */
473 while (SDDS_ReadPageSparse(SDDS_dataset, 0, 10000, 0, 0) > 0) {
474 rowCountOffset = SDDS_dataset->rowcount_offset;
475 offset = ftell(SDDS_dataset->layout.fp);
476 fseek(SDDS_dataset->layout.fp, rowCountOffset, 0);
477
478 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
479 fread(&rowsPresent32, sizeof(rowsPresent32), 1, SDDS_dataset->layout.fp);
480 if (SDDS_dataset->swapByteOrder) {
481 SDDS_SwapLong(&rowsPresent32);
482 }
483 if (rowsPresent32 == INT32_MIN) {
484 fread(&rowsPresent, sizeof(rowsPresent), 1, SDDS_dataset->layout.fp);
485 if (SDDS_dataset->swapByteOrder) {
486 SDDS_SwapLong64(&rowsPresent);
487 }
488 } else {
489 rowsPresent = rowsPresent32;
490 }
491 } else {
492 char buffer[30];
493 if (!fgets(buffer, 30, SDDS_dataset->layout.fp) || strlen(buffer) != 21 || sscanf(buffer, "%" SCNd64, &rowsPresent) != 1) {
494#ifdef DEBUG
495 fprintf(stderr, "buffer for row count data: >%s<\n", buffer);
496#endif
497 SDDS_SetError("Unable to initialize input--row count not present or not correct length (SDDS_InitializeAppendToPage)");
498 SDDS_SetDefaultIOBufferSize(previousBufferSize);
499 return 0;
500 }
501 }
502 fseek(SDDS_dataset->layout.fp, offset, 0);
503#ifdef DEBUG
504 fprintf(stderr, "%" PRId64 " rows present\n", rowsPresent);
505#endif
506 }
507 if (rowCountOffset == -1) {
508 SDDS_SetDefaultIOBufferSize(previousBufferSize);
509 SDDS_SetError("Unable to initialize input--problem finding row count offset (SDDS_InitializeAppendToPage)");
510 return 0;
511 }
512 }
513 SDDS_SetDefaultIOBufferSize(previousBufferSize);
514 SDDS_dataset->fBuffer.bytesLeft = SDDS_dataset->fBuffer.bufferSize;
515
516#ifdef DEBUG
517 fprintf(stderr, "Starting page with %" PRId64 " rows\n", updateInterval);
518#endif
519 if (!SDDS_StartPage(SDDS_dataset, updateInterval)) {
520 SDDS_SetError("Unable to initialize input--problem starting page (SDDS_InitializeAppendToPage)");
521 return 0;
522 }
523
524 /* seek to the end of the file */
525 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
526 SDDS_SetError("Unable to initialize append--seek failure (SDDS_InitializeAppendToPage)");
527 return 0;
528 }
529 endOfFileOffset = ftell(SDDS_dataset->layout.fp);
530 if (endOfFileOffset == endOfLayoutOffset)
531 SDDS_dataset->file_had_data = 0; /* appending to empty file */
532 else {
533 SDDS_dataset->file_had_data = 1; /* appending to nonempty file */
534 if (rowCountOffset != -1) {
535 SDDS_dataset->rowcount_offset = rowCountOffset;
536 SDDS_dataset->n_rows_written = rowsPresent;
537 SDDS_dataset->first_row_in_mem = rowsPresent;
538 SDDS_dataset->last_row_written = -1;
539 *rowsPresentReturn = rowsPresent;
540 SDDS_dataset->writing_page = 1;
541 }
542 }
543#ifdef DEBUG
544 fprintf(stderr, "rowcount_offset = %" PRId64 ", n_rows_written = %" PRId64 ", first_row_in_mem = %" PRId64 ", last_row_written = %" PRId64 "\n", SDDS_dataset->rowcount_offset, SDDS_dataset->n_rows_written, SDDS_dataset->first_row_in_mem, SDDS_dataset->last_row_written);
545#endif
546 SDDS_dataset->page_number = 1;
547 SDDS_dataset->layout.layout_written = 1; /* its already in the file */
548 SDDS_dataset->mode = SDDS_WRITEMODE; /*writing */
549 return 1;
550}
int32_t SDDS_SetDefaultIOBufferSize(int32_t newValue)
Definition SDDS_binary.c:66
void SDDS_SwapLong64(int64_t *data)
Swaps the endianness of a 64-bit integer.
void SDDS_SwapLong(int32_t *data)
Swaps the endianness of a 32-bit integer.
char * SDDS_data_mode[SDDS_NUM_DATA_MODES]
Array of supported data modes.
Definition SDDS_data.c:33
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_ReadPageSparse(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)

◆ SDDS_InitializeOutput()

int32_t SDDS_InitializeOutput ( SDDS_DATASET * SDDS_dataset,
int32_t data_mode,
int32_t lines_per_row,
const char * description,
const char * contents,
const char * filename )

Initializes the SDDS output dataset.

This function sets up the SDDS dataset for output operations by initializing the necessary structures, configuring the data mode (ASCII, Binary, or Parallel), handling file opening (including compressed files), and setting dataset metadata such as description and contents. It ensures that the dataset is ready for writing data according to the specified parameters.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to be initialized for output.
[in]data_modeThe data mode for the output dataset. Acceptable values are:
  • SDDS_ASCII: ASCII text format.
  • SDDS_BINARY: Binary format.
  • SDDS_PARALLEL: Parallel processing mode.
[in]lines_per_rowThe number of lines per row in the output dataset. This parameter is used only for ASCII output and is typically set to 1.
[in]descriptionA string containing the description of the output dataset. Pass NULL if no description is desired.
[in]contentsA string detailing the contents of the output dataset. Pass NULL if no contents are desired.
[in]filenameThe name of the file to which the dataset will be written. If NULL, the dataset will be written to standard output.
Returns
  • 1 on successful initialization.
  • 0 if an error occurred during initialization. In this case, an error message is set internally.
Precondition
  • The SDDS_dataset pointer must be valid and point to a properly allocated SDDS_DATASET structure.
Postcondition
  • The dataset is configured for output according to the specified parameters.
  • The output file is opened and locked if a filename is provided.
  • The dataset's internal state reflects the initialization status.
Note
  • When using compressed file formats (e.g., .gz, .lzma, .xz), the output mode is forced to binary.
  • Environment variable SDDS_OUTPUT_ENDIANESS can be set to "big" or "little" to declare the byte order.
  • For ASCII output, ensure that lines_per_row is set appropriately to match the data structure.
Warning
  • Appending to compressed files is not supported and will result in an error.
  • Ensure that the specified file is not locked by another process to avoid initialization failures.
  • Changing data mode after initialization is not supported and may lead to undefined behavior.

Definition at line 595 of file SDDS_output.c.

595 {
596 char s[SDDS_MAXLINE];
597 char *extension;
598 char *outputEndianess = NULL;
599
600 if (data_mode == SDDS_PARALLEL)
601 return SDDS_Parallel_InitializeOutput(SDDS_dataset, description, contents, filename);
602
603 if (sizeof(gzFile) != sizeof(void *)) {
604 SDDS_SetError("gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
605 return (0);
606 }
607 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_InitializeOutput"))
608 return 0;
609 if (!SDDS_ZeroMemory((void *)SDDS_dataset, sizeof(SDDS_DATASET))) {
610 sprintf(s, "Unable to initialize output for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeOutput)", filename);
611 SDDS_SetError(s);
612 return 0;
613 }
614 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
615 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
616 if (!filename) {
617#if defined(_WIN32)
618 if (_setmode(_fileno(stdout), _O_BINARY) == -1) {
619 sprintf(s, "unable to set stdout to binary mode");
620 SDDS_SetError(s);
621 return 0;
622 }
623#endif
624 SDDS_dataset->layout.fp = stdout;
625 } else {
626 if (SDDS_FileIsLocked(filename)) {
627 sprintf(s, "unable to open file %s for writing--file is locked (SDDS_InitializeOutput)", filename);
628 SDDS_SetError(s);
629 return 0;
630 }
631 if ((extension = strrchr(filename, '.')) && ((strcmp(extension, ".xz") == 0) || (strcmp(extension, ".lzma") == 0))) {
632 SDDS_dataset->layout.lzmaFile = 1;
633 data_mode = SDDS_BINARY; /* force binary mode for output lzma files. The reading of ascii lzma files is flaky because of the lzma_gets command, plus the output files will be much smaller */
634 if (!(SDDS_dataset->layout.lzmafp = lzma_open(filename, FOPEN_WRITE_MODE))) {
635 sprintf(s, "Unable to open file %s for writing (SDDS_InitializeOutput)", filename);
636 SDDS_SetError(s);
637 return 0;
638 }
639 SDDS_dataset->layout.fp = SDDS_dataset->layout.lzmafp->fp;
640 } else {
641 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_WRITE_MODE))) {
642 sprintf(s, "Unable to open file %s for writing (SDDS_InitializeOutput)", filename);
643 SDDS_SetError(s);
644 return 0;
645 }
646 }
647 if (!SDDS_LockFile(SDDS_dataset->layout.fp, filename, "SDDS_InitializeOutput"))
648 return 0;
649#if defined(zLib)
650 if ((extension = strrchr(filename, '.')) && (strcmp(extension, ".gz") == 0)) {
651 SDDS_dataset->layout.gzipFile = 1;
652 if ((SDDS_dataset->layout.gzfp = gzdopen(fileno(SDDS_dataset->layout.fp), FOPEN_WRITE_MODE)) == NULL) {
653 sprintf(s, "Unable to open compressed file %s for writing (SDDS_InitializeOutput)", filename);
654 SDDS_SetError(s);
655 return 0;
656 }
657 }
658#endif
659 }
660 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
661 SDDS_dataset->file_had_data = SDDS_dataset->layout.layout_written = 0;
662 if (!filename)
663 SDDS_dataset->layout.filename = NULL;
664 else if (!SDDS_CopyString(&SDDS_dataset->layout.filename, filename)) {
665 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename);
666 SDDS_SetError(s);
667 return 0;
668 }
669 if ((outputEndianess = getenv("SDDS_OUTPUT_ENDIANESS"))) {
670 if (strncmp(outputEndianess, "big", 3) == 0)
671 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN;
672 else if (strncmp(outputEndianess, "little", 6) == 0)
673 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN;
674 } else {
675 SDDS_dataset->layout.byteOrderDeclared = SDDS_IsBigEndianMachine() ? SDDS_BIGENDIAN : SDDS_LITTLEENDIAN;
676 }
677
678 if (data_mode < 0 || data_mode > SDDS_NUM_DATA_MODES) {
679 sprintf(s, "Invalid data mode for file %s (SDDS_InitializeOutput)", filename ? filename : "stdout");
680 SDDS_SetError(s);
681 return 0;
682 }
683 if (data_mode == SDDS_ASCII && lines_per_row <= 0) {
684 sprintf(s, "Invalid number of lines per row for file %s (SDDS_InitializeOutput)", filename ? filename : "stdout");
685 SDDS_SetError(s);
686 return 0;
687 }
688 SDDS_dataset->layout.version = SDDS_VERSION;
689 SDDS_dataset->layout.data_mode.mode = data_mode;
690 SDDS_dataset->layout.data_mode.lines_per_row = lines_per_row;
691 SDDS_dataset->layout.data_mode.no_row_counts = 0;
692 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
693 SDDS_dataset->layout.data_mode.fsync_data = 0;
694 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
695 /*This is only temporary, soon the default will be column major order */
696 SDDS_dataset->layout.data_mode.column_major = 0;
697 if (description && !SDDS_CopyString(&SDDS_dataset->layout.description, description)) {
698 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename : "stdout");
699 SDDS_SetError(s);
700 return 0;
701 }
702 if (contents && !SDDS_CopyString(&SDDS_dataset->layout.contents, contents)) {
703 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename : "stdout");
704 SDDS_SetError(s);
705 return 0;
706 }
707 SDDS_dataset->mode = SDDS_WRITEMODE; /*writing */
708 SDDS_dataset->pagecount_offset = NULL;
709 SDDS_dataset->parallel_io = 0;
710 return (1);
711}
int32_t SDDS_Parallel_InitializeOutput(SDDS_DATASET *SDDS_dataset, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset for parallel processing.
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.

◆ SDDS_IsValidName()

int32_t SDDS_IsValidName ( const char * name,
const char * class )

Checks if a given name is valid for a specified class within the SDDS dataset.

This function validates whether the provided name adheres to the naming conventions and rules defined by the current name validity flags for the specified class (e.g., parameter, column). It ensures that the name contains only allowed characters and follows the required structure.

Parameters
[in]nameThe name to be validated. Must be a NULL-terminated string.
[in]classThe class type to which the name belongs (e.g., "parameter", "column"). This is used primarily for error reporting.
Returns
  • 1 if the name is valid for the specified class.
  • 0 if the name is invalid, with an error message set internally.
Precondition
  • The name must be a valid NULL-terminated string.
  • The class must be a valid NULL-terminated string representing a recognized class type.
Postcondition
  • If the name is invalid, an error message is recorded detailing the reason.
Note
  • The validation rules are influenced by the current name validity flags set via SDDS_SetNameValidityFlags.
  • Environment variables or other configuration settings may also affect name validity.
Warning
  • Using names that do not adhere to the validation rules will result in parameters or columns not being defined.
  • Ensure that all names meet the required standards before attempting to define dataset elements.

Definition at line 2080 of file SDDS_output.c.

2080 {
2081 char *ptr;
2082 int32_t isValid = 1;
2083 char s[SDDS_MAXLINE];
2084 static char *validChars = "@:#+%-._$&/[]";
2085 static char *startChars = ".:";
2086
2087 if (nameValidityFlags & SDDS_ALLOW_ANY_NAME)
2088 return 1;
2089 ptr = (char *)name;
2090 if (strlen(name) == 0)
2091 isValid = 0;
2092 else if (!(nameValidityFlags & SDDS_ALLOW_V15_NAME)) {
2093 /* post V1.5 allows only alpha and startChars members as first character */
2094 /* V1.5 allows alpha, digits, and any validChars members */
2095 if (!(isalpha(*ptr) || strchr(startChars, *ptr)))
2096 isValid = 0;
2097 }
2098 while (isValid && *ptr) {
2099 if (!(isalnum(*ptr) || strchr(validChars, *ptr)))
2100 isValid = 0;
2101 ptr++;
2102 }
2103 if (!isValid) {
2104 sprintf(s, "The following %s name is invalid: >%s<\n(sddsconvert may be used to change the name)\n", class, name);
2105 SDDS_SetError(s);
2106 return 0;
2107 }
2108 return 1;
2109}

◆ SDDS_Parallel_InitializeOutput()

int32_t SDDS_Parallel_InitializeOutput ( SDDS_DATASET * SDDS_dataset,
const char * description,
const char * contents,
const char * filename )

Initializes the SDDS output dataset for parallel processing.

This function configures the SDDS dataset for parallel output operations. It sets the dataset's description, contents, and filename, ensuring that the output is in binary mode as parallel processing with compressed files is not supported. The function initializes necessary structures and prepares the dataset for efficient parallel data writing.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to be initialized for parallel output.
[in]descriptionA string containing the description of the dataset. Pass NULL if no description is desired.
[in]contentsA string detailing the contents of the dataset. Pass NULL if no contents are desired.
[in]filenameThe name of the file to which the dataset will be written. If NULL, the dataset will be written to standard output.
Returns
  • 1 on successful initialization.
  • 0 if an error occurred during initialization. In this case, an error message is set internally.
Precondition
  • The SDDS_dataset pointer must be valid and point to a properly allocated SDDS_DATASET structure.
  • The dataset memory should have been zeroed prior to calling this function (handled externally).
Postcondition
  • The dataset is configured for parallel binary output.
  • The dataset's internal state reflects the initialization status.
Note
  • Parallel output does not support compressed file formats.
  • The output mode is set to binary regardless of the specified data mode.
  • Environment variable SDDS_OUTPUT_ENDIANESS can be set to "big" or "little" to declare the byte order.
Warning
  • Attempting to use parallel initialization with compressed files will result in an error.
  • Ensure that no other processes are accessing the file simultaneously to prevent initialization failures.

Definition at line 748 of file SDDS_output.c.

748 {
749 /* SDDS_DATASET *SDDS_dataset; */
750 char s[SDDS_MAXLINE];
751 char *outputEndianess = NULL;
752
753 /* SDDS_dataset = &(MPI_dataset->sdds_dataset); */
754 if (sizeof(gzFile) != sizeof(void *)) {
755 SDDS_SetError("gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
756 return (0);
757 }
758 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_InitializeOutput"))
759 return 0;
760 /* if (!SDDS_ZeroMemory((void *)SDDS_dataset, sizeof(SDDS_DATASET))) {
761 sprintf(s,
762 "Unable to initialize output for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeOutput)",
763 filename);
764 SDDS_SetError(s);
765 return 0;
766 } */
767 /*the sdds dataset memory has been zeroed in the SDDS_MPI_Setup */
768 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
769 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
770 SDDS_dataset->layout.fp = NULL;
771
772 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
773 SDDS_dataset->file_had_data = SDDS_dataset->layout.layout_written = 0;
774 if (!filename)
775 SDDS_dataset->layout.filename = NULL;
776 else if (!SDDS_CopyString(&SDDS_dataset->layout.filename, filename)) {
777 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename);
778 SDDS_SetError(s);
779 return 0;
780 }
781 if ((outputEndianess = getenv("SDDS_OUTPUT_ENDIANESS"))) {
782 if (strncmp(outputEndianess, "big", 3) == 0)
783 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN;
784 else if (strncmp(outputEndianess, "little", 6) == 0)
785 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN;
786 } else {
787 SDDS_dataset->layout.byteOrderDeclared = SDDS_IsBigEndianMachine() ? SDDS_BIGENDIAN : SDDS_LITTLEENDIAN;
788 }
789 /* set big-endian for binary files, since it is the only type of MPI binary file.
790 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN; */
791 SDDS_dataset->layout.version = SDDS_VERSION;
792 /* it turned out that hard to write ascii file in parallel, fixed it as SDDS_BINARY */
793 SDDS_dataset->layout.data_mode.mode = SDDS_BINARY;
794 SDDS_dataset->layout.data_mode.lines_per_row = 0;
795 SDDS_dataset->layout.data_mode.no_row_counts = 0;
796 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
797 SDDS_dataset->layout.data_mode.fsync_data = 0;
798 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
799 /*This is only temporary, soon the default will be column major order */
800 SDDS_dataset->layout.data_mode.column_major = 0;
801 if (description && !SDDS_CopyString(&SDDS_dataset->layout.description, description)) {
802 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename : "stdout");
803 SDDS_SetError(s);
804 return 0;
805 }
806 if (contents && !SDDS_CopyString(&SDDS_dataset->layout.contents, contents)) {
807 sprintf(s, "Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename : "stdout");
808 SDDS_SetError(s);
809 return 0;
810 }
811 SDDS_dataset->layout.n_parameters = SDDS_dataset->layout.n_columns = SDDS_dataset->layout.n_arrays = SDDS_dataset->layout.n_associates = 0;
812 SDDS_dataset->mode = SDDS_WRITEMODE; /*writing */
813 SDDS_dataset->pagecount_offset = NULL;
814 SDDS_dataset->parallel_io = 1;
815 return (1);
816}

◆ SDDS_ReconnectFile()

int32_t SDDS_ReconnectFile ( SDDS_DATASET * SDDS_dataset)

Reconnects the SDDS dataset to its previously associated file.

This function re-establishes the connection between the SDDS dataset and the file it was previously linked to before being disconnected. It opens the file in read/write mode, seeks to the appropriate position, and updates the dataset's internal state to reflect that it is connected.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to be reconnected.
Returns
  • 1 on successful reconnection.
  • 0 if an error occurred during reconnection. In this case, an error message is set internally.
Precondition
  • The dataset must have been previously disconnected using SDDS_DisconnectFile.
  • The dataset must have a valid filename set.
Note
  • Reconnection will fail if the file is not accessible or if the dataset was not properly disconnected.
Warning
  • Ensure that the file has not been modified externally in a way that could disrupt the dataset's state.

Definition at line 126 of file SDDS_output.c.

126 {
127#if SDDS_MPI_IO
128 if (SDDS_dataset->parallel_io)
129 return SDDS_MPI_ReconnectFile(SDDS_dataset);
130#endif
131 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReconnectFile"))
132 return 0;
133 if (!SDDS_dataset->layout.disconnected || !SDDS_dataset->layout.filename) {
134 SDDS_SetError("Can't reconnect file. Not disconnected or missing filename. (SDDS_ReconnectFile)");
135 return 0;
136 }
137 if (!(SDDS_dataset->layout.fp = fopen(SDDS_dataset->layout.filename, FOPEN_READ_AND_WRITE_MODE))) {
138 char s[1024];
139 sprintf(s, "Unable to open file %s (SDDS_ReconnectFile)", SDDS_dataset->layout.filename);
140 SDDS_SetError(s);
141 return 0;
142 }
143 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
144 SDDS_SetError("Can't reconnect file. Fseek failed. (SDDS_ReconnectFile)");
145 return 0;
146 }
147 SDDS_dataset->original_layout.fp = SDDS_dataset->layout.fp;
148 SDDS_dataset->layout.disconnected = 0;
149 return 1;
150}
int32_t SDDS_MPI_ReconnectFile(SDDS_DATASET *SDDS_dataset)
Reconnects the MPI file associated with the SDDS dataset.

◆ SDDS_ReconnectInputFile()

int32_t SDDS_ReconnectInputFile ( SDDS_DATASET * SDDS_dataset,
long position )

Reconnects the input file for the SDDS dataset at a specified position.

This function re-establishes the connection between the SDDS dataset and its input file, positioning the file pointer at the specified byte offset. This allows the dataset to resume reading from a specific location within the input file.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to reconnect.
[in]positionThe byte offset position in the input file where reconnection should occur.
Returns
  • 1 on successful reconnection.
  • 0 on failure. In this case, an internal error message is set.
Precondition
  • The dataset must have been previously disconnected using SDDS_DisconnectInputFile.
  • The dataset must have a valid filename set.
  • The specified position must be valid within the input file.
Note
  • Reconnection will fail if the input file is compressed (gzip, lzma, xz).
  • The function seeks to the specified position after opening the file.
Warning
  • Ensure that the specified position does not disrupt the dataset's data integrity.

Definition at line 229 of file SDDS_output.c.

229 {
230#if SDDS_MPI_IO
231 if (SDDS_dataset->parallel_io) {
232 SDDS_SetError("Error: MPI mode not supported yet in SDDS_ReconnectInputFile");
233 return 0;
234 }
235#endif
236 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReconnectInputFile"))
237 return 0;
238 if (!SDDS_dataset->layout.disconnected || !SDDS_dataset->layout.filename) {
239 SDDS_SetError("Can't reconnect file. Not disconnected or missing filename. (SDDS_ReconnectInputFile)");
240 return 0;
241 }
242 if (!(SDDS_dataset->layout.fp = fopen(SDDS_dataset->layout.filename, FOPEN_READ_MODE))) {
243 char s[1024];
244 sprintf(s, "Unable to open file %s (SDDS_ReconnectInputFile)", SDDS_dataset->layout.filename);
245 SDDS_SetError(s);
246 return 0;
247 }
248 if (fseek(SDDS_dataset->layout.fp, position, SEEK_SET) == -1) {
249 SDDS_SetError("Can't reconnect file. Fseek failed. (SDDS_ReconnectInputFile)");
250 return 0;
251 }
252 SDDS_dataset->original_layout.fp = SDDS_dataset->layout.fp;
253 SDDS_dataset->layout.disconnected = 0;
254 return 1;
255}

◆ SDDS_SetNameValidityFlags()

int32_t SDDS_SetNameValidityFlags ( uint32_t flags)

Sets the validity flags for parameter and column names in the SDDS dataset.

This function allows the user to configure the rules for validating names of parameters and columns within the SDDS dataset. The validity flags determine the set of allowed characters and naming conventions.

Parameters
[in]flagsA bitmask representing the desired name validity flags. Possible flags include:
  • SDDS_ALLOW_ANY_NAME: Allows any name without restrictions.
  • SDDS_ALLOW_V15_NAME: Enables compatibility with SDDS version 1.5 naming conventions.
  • Additional flags as defined in the SDDS library.
Returns
  • The previous name validity flags before the update.
Precondition
  • The function can be called at any time before defining parameters or columns to influence name validation.
Postcondition
  • The name validity flags are updated to reflect the specified rules.
Note
  • Changing name validity flags affects how subsequent parameter and column names are validated.
  • It is recommended to set the desired validity flags before defining any dataset elements to avoid validation errors.
Warning
  • Improperly setting validity flags may lead to unintended acceptance or rejection of valid or invalid names.
  • Ensure that the flags are set according to the desired naming conventions for your dataset.

Definition at line 2043 of file SDDS_output.c.

2043 {
2044 uint32_t oldFlags;
2045 oldFlags = nameValidityFlags;
2046 nameValidityFlags = flags;
2047 return oldFlags;
2048}

◆ SDDS_SetNoRowCounts()

int32_t SDDS_SetNoRowCounts ( SDDS_DATASET * SDDS_dataset,
int32_t value )

Sets the flag to enable or disable row counts in the SDDS dataset.

This function configures the SDDS dataset to either include or exclude row counts in the output. Row counts provide metadata about the number of rows written, which can be useful for data integrity and validation. Disabling row counts can improve performance when such metadata is unnecessary.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure to be configured.
[in]valueThe flag value to set:
  • 0: Enable row counts (default behavior).
  • Non-zero: Disable row counts.
Returns
  • 1 on successful configuration.
  • 0 if an error occurred (e.g., attempting to change the flag after the layout has been written).
Precondition
  • The SDDS_dataset must be initialized and not have written the layout yet.
Postcondition
  • The dataset's configuration reflects the specified row count setting.
Note
  • Changing the row count setting affects how data rows are managed and stored in the output file.
Warning
  • This function cannot be called after the dataset layout has been written to the file or if the dataset is in read mode.
  • Disabling row counts may complicate data validation and integrity checks.

Definition at line 847 of file SDDS_output.c.

847 {
848 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetNoRowCounts"))
849 return 0;
850 if (SDDS_dataset->layout.layout_written) {
851 SDDS_SetError("Can't change no_row_counts after writing the layout, or for a file you are reading.");
852 return 0;
853 }
854 SDDS_dataset->layout.data_mode.no_row_counts = value ? 1 : 0;
855 return 1;
856}

◆ SDDS_SetRowCountMode()

int32_t SDDS_SetRowCountMode ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )

Sets the row count mode for the SDDS dataset.

This function configures how row counts are managed within the SDDS dataset. The row count mode determines whether row counts are variable, fixed, or entirely omitted during data writing. Proper configuration of row count modes can enhance data integrity and performance based on specific use cases.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]modeThe row count mode to be set. Must be one of the following:
  • SDDS_VARIABLEROWCOUNT: Enables variable row counts, allowing the number of rows to vary.
  • SDDS_FIXEDROWCOUNT: Sets a fixed row count mode, where the number of rows is constant.
  • SDDS_NOROWCOUNT: Disables row counts, omitting them from the dataset.
Returns
  • 1 on successful configuration of the row count mode.
  • 0 on failure, with an error message set internally.
Precondition
  • The dataset must be initialized and configured for output.
  • The layout must not have been written to the file yet.
Postcondition
  • The dataset's row count mode is updated according to the specified mode.
Note
  • Changing the row count mode affects how row metadata is handled during data writing.
  • The SDDS_FIXEDROWCOUNT mode may require specifying additional parameters such as row increment.
Warning
  • Attempting to change the row count mode after the layout has been written to the file or while reading from a file will result in an error.
  • Selecting an invalid row count mode will result in an error.

Definition at line 2326 of file SDDS_output.c.

2326 {
2327 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowCountMode"))
2328 return 0;
2329 if (SDDS_dataset->layout.layout_written) {
2330 SDDS_SetError("Can't change row count mode after writing the layout, or for a file you are reading.");
2331 return 0;
2332 }
2333 if (mode & SDDS_VARIABLEROWCOUNT) {
2334 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
2335 SDDS_dataset->layout.data_mode.no_row_counts = 0;
2336 } else if (mode & SDDS_FIXEDROWCOUNT) {
2337 SDDS_dataset->layout.data_mode.fixed_row_count = 1;
2338 SDDS_dataset->layout.data_mode.fixed_row_increment = 500;
2339 SDDS_dataset->layout.data_mode.no_row_counts = 0;
2340 SDDS_dataset->layout.data_mode.fsync_data = 0;
2341 } else if (mode & SDDS_NOROWCOUNT) {
2342 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
2343 SDDS_dataset->layout.data_mode.no_row_counts = 1;
2344 } else {
2345 SDDS_SetError("Invalid row count mode (SDDS_SetRowCountMode).");
2346 return 0;
2347 }
2348 if (!SDDS_SaveLayout(SDDS_dataset))
2349 return 0;
2350 return 1;
2351}
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
Definition SDDS_copy.c:615

◆ SDDS_SyncDataSet()

int32_t SDDS_SyncDataSet ( SDDS_DATASET * SDDS_dataset)

Synchronizes the SDDS dataset with the disk by flushing buffered data.

This function attempts to ensure that any buffered data associated with the SDDS dataset is written to the disk using the fsync system call. However, on certain platforms such as VxWorks, Windows, Linux, and macOS, this functionality is not implemented and the function simply returns success. This behavior should be considered when relying on data synchronization across different operating systems.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Returns
  • 0 on success, indicating that data synchronization is either not needed or was successful.
  • A negative value (e.g., -1) on failure to synchronize the data, with an error message set internally.
Note
  • On unsupported platforms, the function does not perform any synchronization and returns success.
  • The synchronization behavior depends on the operating system and its support for the fsync system call.
Warning
  • On platforms where synchronization is not implemented, relying on this function for data integrity is not possible.
  • Ensure that critical data is handled appropriately, considering the limitations of the target operating system.

Definition at line 1333 of file SDDS_output.c.

1333 {
1334#if defined(vxWorks) || defined(_WIN32) || defined(linux) || defined(__APPLE__)
1335 return (0);
1336#else
1337 if (!(SDDS_dataset->layout.fp)) {
1338 SDDS_SetError("Unable to sync file--file pointer is NULL (SDDS_SyncDataSet)");
1339 return (-1);
1340 }
1341 if (SDDS_dataset->layout.data_mode.fsync_data == 0)
1342 return (0);
1343 if (fsync(fileno(SDDS_dataset->layout.fp)) == 0)
1344 return (0);
1345 /*
1346 SDDS_SetError("Unable to sync file (SDDS_SyncDataSet)");
1347 return(-1);
1348 */
1349 /* This error should not be fatal */
1350 return (0);
1351#endif
1352}

◆ SDDS_UpdatePage()

int32_t SDDS_UpdatePage ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )

Updates the current page of the SDDS dataset.

This function finalizes and writes the current page of the SDDS dataset based on the specified mode. The mode can be either FLUSH_TABLE, indicating that the current page is complete and should be written to disk, or 0 for other update operations. Depending on the data mode (ASCII or Binary), the function delegates the update process to the appropriate handler.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]modeThe update mode, which can be:
  • FLUSH_TABLE: Indicates that the current page is complete and should be written to disk.
  • 0: Represents a standard update without flushing the table.
Returns
  • 1 on successful update of the current page.
  • 0 if an error occurred during the update process. An error message is set internally in this case.
Precondition
  • The dataset must be initialized and configured for output.
  • A page must have been started before calling this function.
Postcondition
  • The current page is updated and, if specified, written to the output file.
  • The dataset state is synchronized with the file to ensure data integrity.
Note
  • The function supports parallel I/O modes if enabled.
  • The FLUSH_TABLE mode ensures that all buffered data is written to the disk, which can be useful for data integrity.
Warning
  • Attempting to update a page without starting one will result in an error.
  • Concurrent access to the dataset while updating pages may lead to undefined behavior.

Definition at line 1285 of file SDDS_output.c.

1285 {
1286 int32_t result;
1287 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_UpdatePage"))
1288 return 0;
1289 if (SDDS_dataset->layout.disconnected) {
1290 SDDS_SetError("Can't write page--file is disconnected (SDDS_UpdatePage)");
1291 return 0;
1292 }
1293 if (SDDS_dataset->page_started == 0) {
1294 SDDS_SetError("Can't update page--no page started (SDDS_UpdatePage)");
1295 return 0;
1296 }
1297 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII)
1298 result = SDDS_UpdateAsciiPage(SDDS_dataset, mode);
1299 else if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY)
1300 result = SDDS_UpdateBinaryPage(SDDS_dataset, mode);
1301 else {
1302 SDDS_SetError("Unable to update page--unknown data mode (SDDS_UpdatePage)");
1303 return 0;
1304 }
1305 if (result == 1)
1306 if (SDDS_SyncDataSet(SDDS_dataset) != 0)
1307 return 0;
1308 return (result);
1309}
int32_t SDDS_UpdateAsciiPage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the current ASCII page of an SDDS dataset with new data.
int32_t SDDS_UpdateBinaryPage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the binary page of an SDDS dataset.
int32_t SDDS_SyncDataSet(SDDS_DATASET *SDDS_dataset)
Synchronizes the SDDS dataset with the disk by flushing buffered data.

◆ SDDS_WriteLayout()

int32_t SDDS_WriteLayout ( SDDS_DATASET * SDDS_dataset)

Writes the SDDS layout header to the output file.

This function serializes and writes the layout information of the SDDS dataset to the output file. The layout defines the structure of the data tables, including parameters, arrays, columns, and associates. The function handles different file types, including standard, gzip-compressed, and LZMA-compressed files, and ensures that the layout is written in the correct byte order and format based on the dataset's configuration.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure whose layout is to be written.
Returns
  • 1 on successful writing of the layout.
  • 0 if an error occurred during the writing process. An internal error message is set in this case.
Precondition
  • The dataset must be initialized and configured for output.
  • The layout must have been saved internally using SDDS_SaveLayout before calling this function.
  • The dataset must not be disconnected from the output file.
  • The layout must not have been previously written to the file.
Postcondition
  • The layout header is written to the output file in the appropriate format.
  • The dataset's internal state is updated to reflect that the layout has been written.
Note
  • The function automatically determines the layout version based on the data types used in parameters, arrays, and columns.
  • Environment variable SDDS_OUTPUT_ENDIANESS can influence the byte order declared in the layout.
  • The function handles both binary and ASCII modes, adjusting the layout accordingly.
Warning
  • Attempting to write the layout after it has already been written will result in an error.
  • The function does not support writing layouts to disconnected files.
  • Ensure that the output file is properly opened and writable before calling this function.

Definition at line 893 of file SDDS_output.c.

893 {
894 SDDS_LAYOUT *layout;
895#if defined(zLib)
896 gzFile gzfp;
897#endif
898 FILE *fp;
899 struct lzmafile *lzmafp;
900 int64_t i;
901 char *outputEndianess = NULL;
902
903#if SDDS_MPI_IO
904 if (SDDS_dataset->parallel_io)
905 return SDDS_MPI_WriteLayout(SDDS_dataset);
906#endif
907 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteLayout"))
908 return 0;
909
910 if (!SDDS_SaveLayout(SDDS_dataset))
911 return 0;
912
913 layout = &SDDS_dataset->layout;
914
915 if (SDDS_dataset->layout.disconnected) {
916 SDDS_SetError("Can't write layout--file is disconnected (SDDS_WriteLayout)");
917 return 0;
918 }
919
920 if (layout->layout_written) {
921 SDDS_SetError("Can't write layout--already written to file (SDDS_WriteLayout)");
922 return 0;
923 }
924
925 if ((outputEndianess = getenv("SDDS_OUTPUT_ENDIANESS"))) {
926 if (strncmp(outputEndianess, "big", 3) == 0)
927 layout->byteOrderDeclared = SDDS_BIGENDIAN;
928 else if (strncmp(outputEndianess, "little", 6) == 0)
929 layout->byteOrderDeclared = SDDS_LITTLEENDIAN;
930 }
931
932 if (!layout->byteOrderDeclared)
933 layout->byteOrderDeclared = SDDS_IsBigEndianMachine() ? SDDS_BIGENDIAN : SDDS_LITTLEENDIAN;
934
935 layout->version = 1;
936 for (i = 0; i < layout->n_parameters; i++) {
937 if ((layout->parameter_definition[i].type == SDDS_ULONG) || (layout->parameter_definition[i].type == SDDS_USHORT)) {
938 layout->version = 2;
939 break;
940 }
941 }
942 for (i = 0; i < layout->n_arrays; i++) {
943 if ((layout->array_definition[i].type == SDDS_ULONG) || (layout->array_definition[i].type == SDDS_USHORT)) {
944 layout->version = 2;
945 break;
946 }
947 }
948 for (i = 0; i < layout->n_columns; i++) {
949 if ((layout->column_definition[i].type == SDDS_ULONG) || (layout->column_definition[i].type == SDDS_USHORT)) {
950 layout->version = 2;
951 break;
952 }
953 }
954 if ((layout->data_mode.column_major) && (layout->data_mode.mode == SDDS_BINARY)) {
955 layout->version = 3;
956 }
957 for (i = 0; i < layout->n_parameters; i++) {
958 if (layout->parameter_definition[i].type == SDDS_LONGDOUBLE) {
959 layout->version = 4;
960 break;
961 }
962 }
963 for (i = 0; i < layout->n_arrays; i++) {
964 if (layout->array_definition[i].type == SDDS_LONGDOUBLE) {
965 layout->version = 4;
966 break;
967 }
968 }
969 for (i = 0; i < layout->n_columns; i++) {
970 if (layout->column_definition[i].type == SDDS_LONGDOUBLE) {
971 layout->version = 4;
972 break;
973 }
974 }
975 if ((LDBL_DIG != 18) && (layout->version == 4)) {
976 if (getenv("SDDS_LONGDOUBLE_64BITS") == NULL) {
977 SDDS_SetError("Error: Operating system does not support 80bit float variables used by SDDS_LONGDOUBLE (SDDS_WriteLayout)\nSet SDDS_LONGDOUBLE_64BITS environment variable to read old files that used 64bit float variables for SDDS_LONGDOUBLE");
978 return 0;
979 }
980 }
981 for (i = 0; i < layout->n_parameters; i++) {
982 if ((layout->parameter_definition[i].type == SDDS_ULONG64) || (layout->parameter_definition[i].type == SDDS_LONG64)) {
983 layout->version = 5;
984 break;
985 }
986 }
987 for (i = 0; i < layout->n_arrays; i++) {
988 if ((layout->array_definition[i].type == SDDS_ULONG64) || (layout->array_definition[i].type == SDDS_LONG64)) {
989 layout->version = 5;
990 break;
991 }
992 }
993 for (i = 0; i < layout->n_columns; i++) {
994 if ((layout->column_definition[i].type == SDDS_ULONG64) || (layout->column_definition[i].type == SDDS_LONG64)) {
995 layout->version = 5;
996 break;
997 }
998 }
999
1000 // force layout version 5 because the row and column indexes are now 64bit long integers
1001 // layout->version = 5;
1002
1003#if defined(zLib)
1004 if (SDDS_dataset->layout.gzipFile) {
1005 if (!(gzfp = layout->gzfp)) {
1006 SDDS_SetError("Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1007 return 0;
1008 }
1009
1010 /* write out the layout data */
1011 if (!SDDS_GZipWriteVersion(layout->version, gzfp)) {
1012 SDDS_SetError("Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1013 return 0;
1014 }
1015 if (layout->version < 3) {
1016 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1017 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1018 gzprintf(gzfp, "!# big-endian\n");
1019 else
1020 gzprintf(gzfp, "!# little-endian\n");
1021 }
1022 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1023 gzprintf(gzfp, "!# fixed-rowcount\n");
1024 }
1025 }
1026 if (!SDDS_GZipWriteDescription(layout->description, layout->contents, gzfp)) {
1027 SDDS_SetError("Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1028 return 0;
1029 }
1030
1031 for (i = 0; i < layout->n_parameters; i++)
1032 if (!SDDS_GZipWriteParameterDefinition(layout->parameter_definition + i, gzfp)) {
1033 SDDS_SetError("Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1034 return 0;
1035 }
1036
1037 for (i = 0; i < layout->n_arrays; i++)
1038 if (!SDDS_GZipWriteArrayDefinition(layout->array_definition + i, gzfp)) {
1039 SDDS_SetError("Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1040 return 0;
1041 }
1042
1043 for (i = 0; i < layout->n_columns; i++)
1044 if (!SDDS_GZipWriteColumnDefinition(layout->column_definition + i, gzfp)) {
1045 SDDS_SetError("Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1046 return 0;
1047 }
1048
1049# if RW_ASSOCIATES != 0
1050 for (i = 0; i < layout->n_associates; i++)
1051 if (!SDDS_GZipWriteAssociateDefinition(layout->associate_definition + i, gzfp)) {
1052 SDDS_SetError("Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1053 return 0;
1054 }
1055# endif
1056
1057 if (!SDDS_GZipWriteDataMode(layout, gzfp)) {
1058 SDDS_SetError("Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1059 return 0;
1060 }
1061
1062 layout->layout_written = 1;
1063 /*gzflush(gzfp, Z_FULL_FLUSH); */
1064 } else {
1065#endif
1066 if (SDDS_dataset->layout.lzmaFile) {
1067 if (!(lzmafp = layout->lzmafp)) {
1068 SDDS_SetError("Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1069 return 0;
1070 }
1071
1072 /* write out the layout data */
1073 if (!SDDS_LZMAWriteVersion(layout->version, lzmafp)) {
1074 SDDS_SetError("Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1075 return 0;
1076 }
1077 if (layout->version < 3) {
1078 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1079 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1080 lzma_printf(lzmafp, "!# big-endian\n");
1081 else
1082 lzma_printf(lzmafp, "!# little-endian\n");
1083 }
1084 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1085 lzma_printf(lzmafp, "!# fixed-rowcount\n");
1086 }
1087 }
1088 if (!SDDS_LZMAWriteDescription(layout->description, layout->contents, lzmafp)) {
1089 SDDS_SetError("Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1090 return 0;
1091 }
1092 for (i = 0; i < layout->n_parameters; i++)
1093 if (!SDDS_LZMAWriteParameterDefinition(layout->parameter_definition + i, lzmafp)) {
1094 SDDS_SetError("Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1095 return 0;
1096 }
1097 for (i = 0; i < layout->n_arrays; i++)
1098 if (!SDDS_LZMAWriteArrayDefinition(layout->array_definition + i, lzmafp)) {
1099 SDDS_SetError("Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1100 return 0;
1101 }
1102 for (i = 0; i < layout->n_columns; i++)
1103 if (!SDDS_LZMAWriteColumnDefinition(layout->column_definition + i, lzmafp)) {
1104 SDDS_SetError("Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1105 return 0;
1106 }
1107
1108#if RW_ASSOCIATES != 0
1109 for (i = 0; i < layout->n_associates; i++)
1110 if (!SDDS_LZMAWriteAssociateDefinition(layout->associate_definition + i, lzmafp)) {
1111 SDDS_SetError("Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1112 return 0;
1113 }
1114#endif
1115
1116 if (!SDDS_LZMAWriteDataMode(layout, lzmafp)) {
1117 SDDS_SetError("Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1118 return 0;
1119 }
1120
1121 layout->layout_written = 1;
1122 } else {
1123
1124 if (!(fp = layout->fp)) {
1125 SDDS_SetError("Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1126 return 0;
1127 }
1128
1129 /* write out the layout data */
1130 if (!SDDS_WriteVersion(layout->version, fp)) {
1131 SDDS_SetError("Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1132 return 0;
1133 }
1134 if (layout->version < 3) {
1135 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1136 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1137 fprintf(fp, "!# big-endian\n");
1138 else
1139 fprintf(fp, "!# little-endian\n");
1140 }
1141 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1142 fprintf(fp, "!# fixed-rowcount\n");
1143 }
1144 }
1145 if (!SDDS_WriteDescription(layout->description, layout->contents, fp)) {
1146 SDDS_SetError("Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1147 return 0;
1148 }
1149
1150 for (i = 0; i < layout->n_parameters; i++)
1151 if (!SDDS_WriteParameterDefinition(layout->parameter_definition + i, fp)) {
1152 SDDS_SetError("Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1153 return 0;
1154 }
1155
1156 for (i = 0; i < layout->n_arrays; i++)
1157 if (!SDDS_WriteArrayDefinition(layout->array_definition + i, fp)) {
1158 SDDS_SetError("Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1159 return 0;
1160 }
1161
1162 for (i = 0; i < layout->n_columns; i++)
1163 if (!SDDS_WriteColumnDefinition(layout->column_definition + i, fp)) {
1164 SDDS_SetError("Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1165 return 0;
1166 }
1167
1168#if RW_ASSOCIATES != 0
1169 for (i = 0; i < layout->n_associates; i++)
1170 if (!SDDS_WriteAssociateDefinition(layout->associate_definition + i, fp)) {
1171 SDDS_SetError("Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1172 return 0;
1173 }
1174#endif
1175
1176 if (!SDDS_WriteDataMode(layout, fp)) {
1177 SDDS_SetError("Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1178 return 0;
1179 }
1180
1181 layout->layout_written = 1;
1182 fflush(fp);
1183 }
1184#if defined(zLib)
1185 }
1186#endif
1187 if (SDDS_SyncDataSet(SDDS_dataset) != 0)
1188 return 0;
1189 return (1);
1190}
int32_t SDDS_LZMAWriteVersion(int32_t version_number, struct lzmafile *lzmafp)
Writes the SDDS protocol version to an LZMA-compressed file.
Definition SDDS_write.c:77
int32_t SDDS_LZMAWriteArrayDefinition(ARRAY_DEFINITION *array_definition, struct lzmafile *lzmafp)
Writes an array definition to an LZMA-compressed file.
Definition SDDS_write.c:722
int32_t SDDS_LZMAWriteColumnDefinition(COLUMN_DEFINITION *column, struct lzmafile *lzmafp)
Writes a column definition to an LZMA-compressed file.
Definition SDDS_write.c:356
int32_t SDDS_WriteAssociateDefinition(ASSOCIATE_DEFINITION *associate, FILE *fp)
Writes an associate definition to a standard file.
Definition SDDS_write.c:493
int32_t SDDS_LZMAWriteDescription(char *description, char *contents, struct lzmafile *lzmafp)
Writes the SDDS description section to an LZMA-compressed file.
Definition SDDS_write.c:280
int32_t SDDS_WriteVersion(int32_t version_number, FILE *fp)
Writes the SDDS protocol version to a standard file.
Definition SDDS_write.c:59
int32_t SDDS_WriteColumnDefinition(COLUMN_DEFINITION *column, FILE *fp)
Writes a column definition to a standard file.
Definition SDDS_write.c:329
int32_t SDDS_LZMAWriteDataMode(SDDS_LAYOUT *layout, struct lzmafile *lzmafp)
Writes the data mode section to an LZMA-compressed file.
Definition SDDS_write.c:614
int32_t SDDS_WriteArrayDefinition(ARRAY_DEFINITION *array_definition, FILE *fp)
Writes an array definition to a standard file.
Definition SDDS_write.c:692
int32_t SDDS_LZMAWriteAssociateDefinition(ASSOCIATE_DEFINITION *associate, struct lzmafile *lzmafp)
Writes an associate definition to an LZMA-compressed file.
Definition SDDS_write.c:520
int32_t SDDS_WriteDataMode(SDDS_LAYOUT *layout, FILE *fp)
Writes the data mode section to a standard file.
Definition SDDS_write.c:576
int32_t SDDS_WriteParameterDefinition(PARAMETER_DEFINITION *parameter, FILE *fp)
Writes a parameter definition to a standard file.
Definition SDDS_write.c:411
int32_t SDDS_WriteDescription(char *description, char *contents, FILE *fp)
Writes the SDDS description section to a standard file.
Definition SDDS_write.c:256
int32_t SDDS_LZMAWriteParameterDefinition(PARAMETER_DEFINITION *parameter, struct lzmafile *lzmafp)
Writes a parameter definition to an LZMA-compressed file.
Definition SDDS_write.c:438
int32_t SDDS_MPI_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the layout of the SDDS dataset to the MPI file.
#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_USHORT
Identifier for the unsigned short integer data type.
Definition SDDStypes.h:79
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
Definition SDDStypes.h:31
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49

◆ SDDS_WritePage()

int32_t SDDS_WritePage ( SDDS_DATASET * SDDS_dataset)

Writes the current data table to the output file.

This function serializes and writes the current data table of the SDDS dataset to the output file. It must be preceded by a call to SDDS_WriteLayout to ensure that the dataset layout is properly defined in the output file. Depending on the data mode (ASCII or Binary), the function delegates the writing process to the appropriate handler.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Returns
  • 1 on successful writing of the data table.
  • 0 if an error occurred during the write process. An error message is set internally in this case.
Precondition
  • The dataset must be initialized and configured for output.
  • SDDS_WriteLayout must have been called successfully before writing any pages.
Postcondition
  • The current data table is written to the output file.
  • The dataset state is synchronized with the file to ensure data integrity.
Note
  • The function supports parallel I/O modes if enabled.
  • Ensure that the dataset is not disconnected from the output file before calling this function.
Warning
  • Attempting to write a page without defining the layout first will result in an error.
  • Concurrent access to the dataset while writing pages may lead to undefined behavior.

Definition at line 1222 of file SDDS_output.c.

1222 {
1223 int32_t result;
1224#if SDDS_MPI_IO
1225 if (SDDS_dataset->parallel_io)
1226 return SDDS_MPI_WritePage(SDDS_dataset);
1227#endif
1228 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WritePage"))
1229 return 0;
1230 if (!SDDS_dataset->layout.layout_written) {
1231 SDDS_SetError("Unable to write page--layout not written (SDDS_WritePage)");
1232 return 0;
1233 }
1234 if (SDDS_dataset->layout.disconnected) {
1235 SDDS_SetError("Can't write page--file is disconnected (SDDS_WritePage)");
1236 return 0;
1237 }
1238 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII)
1239 result = SDDS_WriteAsciiPage(SDDS_dataset);
1240 else if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY)
1241 result = SDDS_WriteBinaryPage(SDDS_dataset);
1242 else {
1243 SDDS_SetError("Unable to write page--unknown data mode (SDDS_WritePage)");
1244 return 0;
1245 }
1246 if (result == 1)
1247 if (SDDS_SyncDataSet(SDDS_dataset) != 0)
1248 return 0;
1249 return (result);
1250}
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_WriteBinaryPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_MPI_WritePage(SDDS_DATASET *SDDS_dataset)
Writes a page of data to the MPI file associated with the SDDS dataset.

Variable Documentation

◆ nameValidityFlags

uint32_t nameValidityFlags = 0
static

Definition at line 2014 of file SDDS_output.c.