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

SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes. More...

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "SDDStypes.h"
#include <inttypes.h>
#include <lzma.h>

Go to the source code of this file.

Classes

struct  SDDS_DEFINITION
 
struct  PARAMETER_DEFINITION
 
struct  COLUMN_DEFINITION
 
struct  ARRAY_DEFINITION
 
struct  ASSOCIATE_DEFINITION
 
struct  SORTED_INDEX
 
struct  DATA_MODE
 
struct  lzmafile
 
struct  SDDS_ENUM_PAIR
 
struct  SDDS_FIELD_INFORMATION
 
struct  SDDS_LAYOUT
 
struct  SDDS_ARRAY
 
struct  SDDS_FILEBUFFER
 
struct  SDDS_DATASET
 

Macros

#define SDDS_READMODE   1
 
#define SDDS_WRITEMODE   2
 
#define SDDS_MEMMODE   3
 
#define SDDS_MPI_READ_ONLY   0x0001UL
 
#define SDDS_MPI_WRITE_ONLY   0x0002UL
 
#define SDDS_MPI_READ_WRITE   0x0004UL
 
#define SDDS_MPI_STRING_COLUMN_LEN   16
 
#define SDDS_COLUMN_MAJOR_ORDER   0x0001UL
 
#define SDDS_ROW_MAJOR_ORDER   0x0002UL
 
#define _SDDS_   1
 
#define SDDS_VERSION   5
 
#define SVN_VERSION   "unknown"
 
#define epicsShareFuncSDDS
 
#define epicsShareExtern   extern
 
#define RW_ASSOCIATES   0
 
#define SDDS_BINARY   1
 
#define SDDS_ASCII   2
 
#define SDDS_PARALLEL   3
 
#define SDDS_NUM_DATA_MODES   2
 
#define SDDS_MAXLINE   1024
 
#define SDDS_PRINT_BUFLEN   16834
 
#define SDDS_NORMAL_DEFINITION   0
 
#define SDDS_WRITEONLY_DEFINITION   1
 
#define SDDS_PARAMETER_FIELDS   7
 
#define SDDS_COLUMN_FIELDS   7
 
#define SDDS_ARRAY_FIELDS   9
 
#define SDDS_ASSOCIATE_FIELDS   6
 
#define LZMA_BUF_SIZE   40960
 
#define SDDS_DESCRIPTION_FIELDS   2
 
#define SDDS_DATA_FIELDS   7
 
#define SDDS_INCLUDE_FIELDS   1
 
#define SDDS_FILEBUFFER_SIZE   262144
 
#define SDDS_IsDisconnected(SDDSptr)
 
#define TERMINATE_DONT_FREE_TABLE_STRINGS   0x0001
 
#define TERMINATE_DONT_FREE_ARRAY_STRINGS   0x0002
 
#define DEFAULT_COLUMN_MEMORY_MODE   0
 
#define DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS   1
 
#define SDDS_VARIABLEROWCOUNT   0x0001UL
 
#define SDDS_FIXEDROWCOUNT   0x0002UL
 
#define SDDS_NOROWCOUNT   0x0004UL
 
#define SDDS_NOAUTOREADRECOVER   0x0001UL
 
#define SDDS_AUTOREADRECOVER   0x0002UL
 
#define SDDS_ALLOW_ANY_NAME   0x0001UL
 
#define SDDS_ALLOW_V15_NAME   0x0002UL
 
#define SDDS_LayoutWritten(SDDSptr)
 
#define SDDS_CopyTable(a, b)
 
#define SDDS_BY_INDEX   1
 
#define SDDS_BY_NAME   2
 
#define SDDS_StartTable(a, b)
 
#define SDDS_SET_BY_INDEX   SDDS_BY_INDEX
 
#define SDDS_SET_BY_NAME   SDDS_BY_NAME
 
#define SDDS_PASS_BY_VALUE   4
 
#define SDDS_PASS_BY_REFERENCE   8
 
#define SDDS_PASS_BY_STRING   16
 
#define SDDS_WriteTable(a)
 
#define FLUSH_TABLE   0x1UL
 
#define SDDS_UpdateTable(a)
 
#define SDDS_GET_BY_INDEX   SDDS_BY_INDEX
 
#define SDDS_GET_BY_NAME   SDDS_BY_NAME
 
#define SDDS_ReadTable(a)
 
#define SDDS_FLAG_ARRAY   0x001UL
 
#define SDDS_INDEX_LIMITS   0x002UL
 
#define SDDS_NAME_ARRAY   1
 
#define SDDS_NAMES_STRING   2
 
#define SDDS_NAME_STRINGS   3
 
#define SDDS_MATCH_STRING   4
 
#define SDDS_MATCH_EXCLUDE_STRING   5
 
#define SDDS_CI_NAME_ARRAY   6
 
#define SDDS_CI_NAMES_STRING   7
 
#define SDDS_CI_NAME_STRINGS   8
 
#define SDDS_CI_MATCH_STRING   9
 
#define SDDS_CI_MATCH_EXCLUDE_STRING   10
 
#define SDDS_AND   0x0001UL
 
#define SDDS_OR   0x0002UL
 
#define SDDS_NEGATE_MATCH   0x0004UL
 
#define SDDS_NEGATE_PREVIOUS   0x0008UL
 
#define SDDS_NEGATE_EXPRESSION   0x0010UL
 
#define SDDS_INDIRECT_MATCH   0x0020UL
 
#define SDDS_1_PREVIOUS   0x0040UL
 
#define SDDS_0_PREVIOUS   0x0080UL
 
#define SDDS_NOCASE_COMPARE   0x0100UL
 
#define SDDS_RowCount(SDDS_dataset)
 
#define NUMSCANFILTER_INVERT   0x0001UL
 
#define NUMSCANFILTER_STRICT   0x0002UL
 
#define SDDS_ROW_MAJOR_DATA   1
 
#define SDDS_COLUMN_MAJOR_DATA   2
 
#define SDDS_POINTER_ARRAY   1
 
#define SDDS_CONTIGUOUS_DATA   2
 
#define SDDS_VERBOSE_PrintErrors   1
 
#define SDDS_EXIT_PrintErrors   2
 
#define SDDS_LAST_GetErrorMessages   0
 
#define SDDS_ALL_GetErrorMessages   1
 
#define SDDS_TRANSFER_KEEPOLD   0x01UL
 
#define SDDS_TRANSFER_OVERWRITE   0x02UL
 
#define FIND_ANY_TYPE   0
 
#define FIND_SPECIFIED_TYPE   1
 
#define FIND_NUMERIC_TYPE   2
 
#define FIND_INTEGER_TYPE   3
 
#define FIND_FLOATING_TYPE   4
 
#define SDDS_CHECK_OKAY   0
 
#define SDDS_CHECK_OK   SDDS_CHECK_OKAY
 
#define SDDS_CHECK_NONEXISTENT   1
 
#define SDDS_CHECK_WRONGTYPE   2
 
#define SDDS_CHECK_WRONGUNITS   3
 
#define SDDS_PRINT_NOQUOTES   0x0001UL
 
#define SDDS_CheckTableStructureSize(a)
 
#define TABULAR_DATA_CHECKS   0x0001UL
 
#define SDDS_BIGENDIAN_SEEN   0x0001UL
 
#define SDDS_LITTLEENDIAN_SEEN   0x0002UL
 
#define SDDS_FIXED_ROWCOUNT_SEEN   0x0004UL
 
#define SDDS_BIGENDIAN   SDDS_BIGENDIAN_SEEN
 
#define SDDS_LITTLEENDIAN   SDDS_LITTLEENDIAN_SEEN
 
#define SDDS_FIXED_ROWCOUNT   SDDS_FIXED_ROWCOUNT_SEEN
 
#define SDDS_MATCH_COLUMN   0
 
#define SDDS_MATCH_PARAMETER   1
 
#define SDDS_MATCH_ARRAY   2
 

Typedefs

typedef void * voidp
 
typedef voidp gzFile
 
typedef SDDS_DATASET SDDS_TABLE
 

Functions

int SDDS_CompareIndexedNames (const void *s1, const void *s2)
 Compares two SORTED_INDEX structures by their name fields.
 
int SDDS_CompareIndexedNamesPtr (const void *s1, const void *s2)
 Compares two pointers to SORTED_INDEX structures by their name fields.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS int32_t SDDS_DisconnectFile (SDDS_DATASET *SDDS_dataset)
 Disconnects the SDDS dataset from its associated file.
 
epicsShareFuncSDDS int32_t SDDS_ReconnectFile (SDDS_DATASET *SDDS_dataset)
 Reconnects the SDDS dataset to its previously associated file.
 
epicsShareFuncSDDS long SDDS_DisconnectInputFile (SDDS_DATASET *SDDS_dataset)
 Disconnects the input file from the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ReconnectInputFile (SDDS_DATASET *SDDS_dataset, long position)
 Reconnects the input file for the SDDS dataset at a specified position.
 
epicsShareFuncSDDS int32_t SDDS_ReadNewBinaryRows (SDDS_DATASET *SDDS_dataset)
 Reads new binary rows from the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_FreeStringData (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS int32_t SDDS_Terminate (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS void SDDS_SetTerminateMode (uint32_t mode)
 
epicsShareFuncSDDS void SDDS_SetColumnMemoryMode (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 
epicsShareFuncSDDS int32_t SDDS_GetColumnMemoryMode (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS int32_t SDDS_SetRowCountMode (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 Sets the row count mode for the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetAutoReadRecovery (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 
epicsShareFuncSDDS int32_t SDDS_UpdateRowCount (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS void SDDS_DisableFSync (SDDS_DATASET *SDDS_dataset)
 Disables file synchronization for the SDDS dataset.
 
epicsShareFuncSDDS void SDDS_EnableFSync (SDDS_DATASET *SDDS_dataset)
 Enables file synchronization for the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_DoFSync (SDDS_DATASET *SDDS_dataset)
 Synchronizes the SDDS dataset's file to disk.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS int32_t SDDS_IsValidName (const char *name, const char *dataClass)
 Checks if a given name is valid for a specified class within the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetNameValidityFlags (uint32_t flags)
 Sets the validity flags for parameter and column names in the SDDS dataset.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS int32_t SDDS_SetNoRowCounts (SDDS_DATASET *SDDS_dataset, int32_t value)
 Sets the flag to enable or disable row counts in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_WriteLayout (SDDS_DATASET *SDDS_dataset)
 Writes the SDDS layout header to the output file.
 
epicsShareFuncSDDS int32_t SDDS_EraseData (SDDS_DATASET *SDDS_dataset)
 Erases all data entries in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ProcessColumnString (SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
 Process a column definition string.
 
epicsShareFuncSDDS int32_t SDDS_ProcessParameterString (SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
 Process a parameter definition string.
 
epicsShareFuncSDDS int32_t SDDS_ProcessArrayString (SDDS_DATASET *SDDS_dataset, char *string)
 Process an array definition string.
 
epicsShareFuncSDDS int32_t SDDS_ProcessAssociateString (SDDS_DATASET *SDDS_dataset, char *string)
 Process an associate definition string.
 
epicsShareFuncSDDS int32_t SDDS_InitializeCopy (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
 
epicsShareFuncSDDS int32_t SDDS_CopyLayout (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
 
epicsShareFuncSDDS int32_t SDDS_AppendLayout (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
 
epicsShareFuncSDDS int32_t SDDS_CopyPage (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
 
epicsShareFuncSDDS int32_t SDDS_CopyParameters (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
 
epicsShareFuncSDDS int32_t SDDS_CopyArrays (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
 
epicsShareFuncSDDS int32_t SDDS_CopyColumns (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
 
epicsShareFuncSDDS int32_t SDDS_CopyRowsOfInterest (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
 
epicsShareFuncSDDS int32_t SDDS_CopyRow (SDDS_DATASET *SDDS_target, int64_t target_row, SDDS_DATASET *SDDS_source, int64_t source_srow)
 
epicsShareFuncSDDS int32_t SDDS_CopyRowDirect (SDDS_DATASET *SDDS_target, int64_t target_row, SDDS_DATASET *SDDS_source, int64_t source_row)
 
epicsShareFuncSDDS int32_t SDDS_CopyAdditionalRows (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
 
epicsShareFuncSDDS int32_t SDDS_CopyRows (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, int64_t firstRow, int64_t lastRow)
 
epicsShareFuncSDDS void SDDS_DeferSavingLayout (SDDS_DATASET *SDDS_dataset, int32_t mode)
 
epicsShareFuncSDDS int32_t SDDS_SaveLayout (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS int32_t SDDS_RestoreLayout (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS int32_t SDDS_StartPage (SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
 
epicsShareFuncSDDS int32_t SDDS_ClearPage (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS int32_t SDDS_LengthenTable (SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
 
epicsShareFuncSDDS int32_t SDDS_ShortenTable (SDDS_DATASET *SDDS_dataset, int64_t rows)
 
epicsShareFuncSDDS int32_t SDDS_SetParameters (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 
epicsShareFuncSDDS int32_t SDDS_SetParameter (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 
epicsShareFuncSDDS int32_t SDDS_SetRowValues (SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
 
epicsShareFuncSDDS int32_t SDDS_WritePage (SDDS_DATASET *SDDS_dataset)
 Writes the current data table to the output file.
 
epicsShareFuncSDDS int32_t SDDS_UpdatePage (SDDS_DATASET *SDDS_dataset, uint32_t mode)
 Updates the current page of the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SyncDataSet (SDDS_DATASET *SDDS_dataset)
 Synchronizes the SDDS dataset with the disk by flushing buffered data.
 
epicsShareFuncSDDS int32_t SDDS_SetColumn (SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
 Sets the values for one data column in the current data table of an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetColumnFromDoubles (SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows,...)
 Sets the values for a single data column using double-precision floating-point numbers.
 
epicsShareFuncSDDS int32_t SDDS_SetColumnFromFloats (SDDS_DATASET *SDDS_dataset, int32_t mode, float *data, int64_t rows,...)
 Sets the values for a single data column using single-precision floating-point numbers.
 
epicsShareFuncSDDS int32_t SDDS_SetColumnFromLongs (SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t *data, int64_t rows,...)
 Sets the values for a single data column using long integer numbers.
 
epicsShareFuncSDDS int32_t SDDS_SetParametersFromDoubles (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 
epicsShareFuncSDDS int32_t SDDS_GetColumnInformation (SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
 Retrieves information about a specified column in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetParameterInformation (SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
 Retrieves information about a specified parameter in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetArrayInformation (SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
 Retrieves information about a specified array in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetAssociateInformation (SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
 Retrieves information about a specified associate in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ChangeColumnInformation (SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
 Modifies a specific field in a column definition within the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ChangeParameterInformation (SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
 Modifies a specific field in a parameter definition within the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ChangeArrayInformation (SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
 Modifies a specific field in an array definition within the SDDS dataset.
 
epicsShareFuncSDDS void SDDS_SetReadRecoveryMode (SDDS_DATASET *SDDS_dataset, int32_t mode)
 Sets the read recovery mode for an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetDefaultIOBufferSize (int32_t bufferSize)
 
epicsShareFuncSDDS int32_t SDDS_InitializeInputFromSearchPath (SDDS_DATASET *SDDSin, char *file)
 
epicsShareFuncSDDS int32_t SDDS_InitializeInput (SDDS_DATASET *SDDS_dataset, char *filename)
 
epicsShareFuncSDDS int32_t SDDS_ReadLayout (SDDS_DATASET *SDDS_dataset, FILE *fp)
 
epicsShareFuncSDDS int32_t SDDS_InitializeHeaderlessInput (SDDS_DATASET *SDDS_dataset, char *filename)
 Initializes the SDDS dataset for headerless input.
 
epicsShareFuncSDDS int64_t SDDS_GetRowLimit ()
 
epicsShareFuncSDDS int64_t SDDS_SetRowLimit (int64_t limit)
 
epicsShareFuncSDDS int32_t SDDS_GotoPage (SDDS_DATASET *SDDS_dataset, int32_t page_number)
 Sets the current page of the SDDS dataset to the specified page number.
 
epicsShareFuncSDDS int32_t SDDS_CheckEndOfFile (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS int32_t SDDS_ReadPage (SDDS_DATASET *SDDS_dataset)
 
epicsShareFuncSDDS int32_t SDDS_ReadPageSparse (SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
 
epicsShareFuncSDDS int32_t SDDS_ReadPageLastRows (SDDS_DATASET *SDDS_dataset, int64_t last_rows)
 
epicsShareFuncSDDS int32_t SDDS_ReadAsciiPage (SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
 Reads the next SDDS ASCII page into memory with optional data sparsity and statistics.
 
epicsShareFuncSDDS int32_t SDDS_ReadRecoveryPossible (SDDS_DATASET *SDDS_dataset)
 Checks if any data in an SDDS page was recovered after an error was detected.
 
epicsShareFuncSDDS int32_t SDDS_SetColumnFlags (SDDS_DATASET *SDDS_dataset, int32_t column_flag_value)
 Sets the acceptance flags for all columns in the current data table of a data set.
 
epicsShareFuncSDDS int32_t SDDS_SetRowFlags (SDDS_DATASET *SDDS_dataset, int32_t row_flag_value)
 Sets the acceptance flags for all rows in the current data table of a data set.
 
epicsShareFuncSDDS int32_t SDDS_GetRowFlag (SDDS_DATASET *SDDS_dataset, int64_t row)
 Retrieves the acceptance flag of a specific row in the current data table.
 
epicsShareFuncSDDS int32_t SDDS_GetRowFlags (SDDS_DATASET *SDDS_dataset, int32_t *flag, int64_t rows)
 Retrieves the acceptance flags for all rows in the current data table.
 
epicsShareFuncSDDS int32_t SDDS_BufferedRead (void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder)
 
epicsShareFuncSDDS int32_t SDDS_AssertRowFlags (SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
 Sets acceptance flags for rows based on specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_MatchColumns (SDDS_DATASET *SDDS_dataset, char ***match, int32_t matchMode, int32_t typeMode,...)
 Matches and retrieves column names from an SDDS dataset based on specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_MatchParameters (SDDS_DATASET *SDDS_dataset, char ***match, int32_t matchMode, int32_t typeMode,...)
 Matches and retrieves parameter names from an SDDS dataset based on specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_MatchArrays (SDDS_DATASET *SDDS_dataset, char ***match, int32_t matchMode, int32_t typeMode,...)
 Matches and retrieves array names from an SDDS dataset based on specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_Logic (int32_t previous, int32_t match, uint32_t logic)
 Applies logical operations to determine the new state of a row flag based on previous and current match conditions.
 
epicsShareFuncSDDS int32_t SDDS_SetColumnsOfInterest (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Sets the acceptance flags for columns based on specified naming criteria.
 
epicsShareFuncSDDS int32_t SDDS_AssertColumnFlags (SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
 Sets acceptance flags for columns based on specified criteria.
 
epicsShareFuncSDDS int64_t SDDS_SetRowsOfInterest (SDDS_DATASET *SDDS_dataset, char *selection_column, int32_t mode,...)
 Sets the rows of interest in an SDDS dataset based on various selection criteria.
 
epicsShareFuncSDDS int64_t SDDS_MatchRowsOfInterest (SDDS_DATASET *SDDS_dataset, char *selection_column, char *label_to_match, int32_t logic)
 Matches and marks rows of interest in an SDDS dataset based on label matching.
 
epicsShareFuncSDDS int32_t SDDS_DeleteColumn (SDDS_DATASET *SDDS_dataset, char *column_name)
 Deletes a specified column from an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_DeleteParameter (SDDS_DATASET *SDDS_dataset, char *parameter_name)
 Deletes a specified parameter from an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_DeleteUnsetColumns (SDDS_DATASET *SDDS_dataset)
 Deletes all columns from an SDDS dataset that are not marked as "of interest".
 
epicsShareFuncSDDS int32_t SDDS_CountColumnsOfInterest (SDDS_DATASET *SDDS_dataset)
 Counts the number of columns marked as "of interest" in the current data table.
 
epicsShareFuncSDDS int32_t SDDS_ColumnIsOfInterest (SDDS_DATASET *SDDS_dataset, char *name)
 Determines if a specified column is marked as of interest in the dataset.
 
epicsShareFuncSDDS int32_t SDDS_ColumnCount (SDDS_DATASET *dataset)
 Retrieves the number of columns in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ParameterCount (SDDS_DATASET *dataset)
 Retrieves the number of parameters in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ArrayCount (SDDS_DATASET *dataset)
 Retrieves the number of arrays in the SDDS dataset.
 
epicsShareFuncSDDS int64_t SDDS_CountRowsOfInterest (SDDS_DATASET *SDDS_dataset)
 Counts the number of rows marked as "of interest" in the current data table.
 
epicsShareFuncSDDS int32_t SDDS_DeleteUnsetRows (SDDS_DATASET *SDDS_dataset)
 Deletes rows from an SDDS dataset that are not marked as "of interest".
 
epicsShareFuncSDDS int64_t SDDS_FilterRowsOfInterest (SDDS_DATASET *SDDS_dataset, char *filter_column, double lower, double upper, int32_t logic)
 Filters rows of interest in an SDDS dataset based on numeric ranges in a specified column.
 
epicsShareFuncSDDS int32_t SDDS_ItemInsideWindow (void *data, int64_t index, int32_t type, double lower_limit, double upper_limit)
 Checks whether a data item is within a specified numeric window.
 
epicsShareFuncSDDS int64_t SDDS_FilterRowsByNumScan (SDDS_DATASET *SDDS_dataset, char *filter_column, uint32_t mode)
 Filters rows of interest in an SDDS dataset based on numeric scanning of a specified column.
 
epicsShareFuncSDDS void * SDDS_GetColumn (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves a copy of the data for a specified column, including only rows marked as "of interest".
 
epicsShareFuncSDDS void * SDDS_GetInternalColumn (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves an internal pointer to the data of a specified column, including all rows.
 
epicsShareFuncSDDS double * SDDS_GetColumnInDoubles (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of doubles, considering only rows marked as "of interest".
 
epicsShareFuncSDDS float * SDDS_GetColumnInFloats (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of floats, considering only rows marked as "of interest".
 
epicsShareFuncSDDS int32_t * SDDS_GetColumnInLong (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of 32-bit integers, considering only rows marked as "of interest".
 
epicsShareFuncSDDS short * SDDS_GetColumnInShort (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of short integers, considering only rows marked as "of interest".
 
epicsShareFuncSDDS char ** SDDS_GetColumnInString (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified column as an array of strings, considering only rows marked as "of interest".
 
epicsShareFuncSDDS void * SDDS_GetNumericColumn (SDDS_DATASET *SDDS_dataset, char *column_name, int32_t desiredType)
 Retrieves the data of a specified numerical column as an array of a desired numerical type, considering only rows marked as "of interest".
 
epicsShareFuncSDDS void * SDDS_GetRow (SDDS_DATASET *SDDS_dataset, int64_t srow_index, void *memory)
 Retrieves the data of a specific selected row as an array, considering only columns marked as "of interest".
 
epicsShareFuncSDDS void * SDDS_GetValue (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t srow_index, void *memory)
 Retrieves the value from a specified column and selected row, optionally storing it in provided memory.
 
epicsShareFuncSDDS double SDDS_GetValueAsDouble (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t srow_index)
 Retrieves the value from a specified column and selected row, casting it to a double.
 
epicsShareFuncSDDS double SDDS_GetValueByIndexAsDouble (SDDS_DATASET *SDDS_dataset, int32_t column_index, int64_t srow_index)
 Retrieves the value from a specified column and selected row, casting it to a double.
 
epicsShareFuncSDDS void * SDDS_GetValueByIndex (SDDS_DATASET *SDDS_dataset, int32_t column_index, int64_t srow_index, void *memory)
 Retrieves the value from a specified column and selected row, optionally storing it in provided memory.
 
epicsShareFuncSDDS void * SDDS_GetValueByAbsIndex (SDDS_DATASET *SDDS_dataset, int32_t column_index, int64_t srow_index, void *memory)
 Retrieves the value from a specified column and absolute row index, optionally storing it in provided memory.
 
epicsShareFuncSDDS void * SDDS_GetParameter (SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
 Retrieves the value of a specified parameter from the current data table of a data set.
 
epicsShareFuncSDDS void * SDDS_GetParameterByIndex (SDDS_DATASET *SDDS_dataset, int32_t index, void *memory)
 Retrieves the value of a specified parameter by its index from the current data table of a data set.
 
epicsShareFuncSDDS long double * SDDS_GetParameterAsLongDouble (SDDS_DATASET *SDDS_dataset, char *parameter_name, long double *data)
 Retrieves the value of a specified parameter as a long double from the current data table of an SDDS dataset.
 
epicsShareFuncSDDS double * SDDS_GetParameterAsDouble (SDDS_DATASET *SDDS_dataset, char *parameter_name, double *data)
 Retrieves the value of a specified parameter as a double from the current data table of an SDDS dataset.
 
epicsShareFuncSDDS int32_t * SDDS_GetParameterAsLong (SDDS_DATASET *SDDS_dataset, char *parameter_name, int32_t *data)
 Retrieves the value of a specified parameter as a 32-bit integer from the current data table of a data set.
 
epicsShareFuncSDDS int64_t * SDDS_GetParameterAsLong64 (SDDS_DATASET *SDDS_dataset, char *parameter_name, int64_t *data)
 Retrieves the value of a specified parameter as a 64-bit integer from the current data table of an SDDS dataset.
 
epicsShareFuncSDDS char * SDDS_GetParameterAsString (SDDS_DATASET *SDDS_dataset, char *parameter_name, char **memory)
 Retrieves the value of a specified parameter as a string from the current data table of an SDDS dataset.
 
epicsShareFuncSDDS char * SDDS_GetParameterAsFormattedString (SDDS_DATASET *SDDS_dataset, char *parameter_name, char **memory, char *suppliedformat)
 Retrieves the value of a specified parameter as a formatted string from the current data table of an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetParameters (SDDS_DATASET *SDDS_dataset,...)
 Retrieves multiple parameter values from the current data table of a data set.
 
epicsShareFuncSDDS void * SDDS_GetFixedValueParameter (SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
 Retrieves the fixed value of a specified parameter from an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetDescription (SDDS_DATASET *SDDS_dataset, char **text, char **contents)
 Retrieves the text and contents descriptions from an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetArrayUnitsConversion (SDDS_DATASET *SDDS_dataset, char *column_name, char *new_units, char *old_units, double factor)
 Sets unit conversions for a specified array in an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetColumnUnitsConversion (SDDS_DATASET *SDDS_dataset, char *column_name, char *new_units, char *old_units, double factor)
 Sets unit conversions for a specified column in an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetParameterUnitsConversion (SDDS_DATASET *SDDS_dataset, char *column_name, char *new_units, char *old_units, double factor)
 Sets unit conversions for a specified parameter in an SDDS dataset.
 
epicsShareFuncSDDS void * SDDS_GetMatrixOfRows (SDDS_DATASET *SDDS_dataset, int64_t *n_rows)
 Retrieves all rows marked as "of interest" as a matrix (array of row arrays).
 
epicsShareFuncSDDS void * SDDS_GetCastMatrixOfRows (SDDS_DATASET *SDDS_dataset, int64_t *n_rows, int32_t sddsType)
 Retrieves all rows marked as "of interest" as a matrix, casting each value to a specified numerical type.
 
epicsShareFuncSDDS void * SDDS_GetMatrixFromColumn (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t dimension1, int64_t dimension2, int32_t mode)
 Extracts a matrix from a specified column in the current data table of an SDDS dataset.
 
epicsShareFuncSDDS void * SDDS_GetDoubleMatrixFromColumn (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t dimension1, int64_t dimension2, int32_t mode)
 Extracts a matrix of doubles from a specified column in the current data table of an SDDS dataset.
 
epicsShareFuncSDDS SDDS_ARRAYSDDS_GetArray (SDDS_DATASET *SDDS_dataset, char *array_name, SDDS_ARRAY *memory)
 Retrieves an array from the current data table of an SDDS dataset.
 
epicsShareFuncSDDS double * SDDS_GetArrayInDoubles (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t *values)
 Retrieves an array from the current data table of an SDDS dataset and converts its elements to doubles.
 
epicsShareFuncSDDS int32_t * SDDS_GetArrayInLong (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t *values)
 Retrieves an array from the current data table of an SDDS dataset and converts its elements to 32-bit integers.
 
epicsShareFuncSDDS char ** SDDS_GetArrayInString (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t *values)
 Retrieves an array from the current data table of an SDDS dataset and converts its elements to strings.
 
epicsShareFuncSDDS int32_t SDDS_SetArrayVararg (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer,...)
 Sets the values of an array variable in the SDDS dataset using variable arguments for dimensions.
 
epicsShareFuncSDDS int32_t SDDS_SetArray (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t *dimension)
 Sets the values of an array variable in the SDDS dataset using specified dimensions.
 
epicsShareFuncSDDS int32_t SDDS_AppendToArrayVararg (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t elements,...)
 Appends data to an existing array variable in the SDDS dataset using variable arguments for dimensions.
 
epicsShareFuncSDDS void * SDDS_Realloc (void *old_ptr, size_t new_size)
 Reallocates memory to a new size.
 
epicsShareFuncSDDS void * SDDS_Malloc (size_t size)
 Allocates memory of a specified size.
 
epicsShareFuncSDDS void SDDS_Free (void *mem)
 Free memory previously allocated by SDDS_Malloc.
 
epicsShareFuncSDDS void * SDDS_Calloc (size_t nelem, size_t elem_size)
 Allocates zero-initialized memory for an array of elements.
 
epicsShareFuncSDDS int32_t SDDS_NumberOfErrors (void)
 Retrieves the number of errors recorded by SDDS library routines.
 
epicsShareFuncSDDS void SDDS_ClearErrors (void)
 Clears all recorded error messages from the SDDS error stack.
 
epicsShareFuncSDDS void SDDS_SetError (char *error_text)
 Records an error message in the SDDS error stack.
 
epicsShareFuncSDDS void SDDS_SetError0 (char *error_text)
 Internal function to record an error message in the SDDS error stack.
 
epicsShareFuncSDDS void SDDS_Bomb (char *message)
 Terminates the program after printing an error message and recorded errors.
 
epicsShareFuncSDDS void SDDS_Warning (char *message)
 Prints a warning message to stderr.
 
epicsShareFuncSDDS void SDDS_RegisterProgramName (const char *name)
 Registers the executable program name for use in error messages.
 
epicsShareFuncSDDS void SDDS_PrintErrors (FILE *fp, int32_t mode)
 Prints recorded error messages to a specified file stream.
 
epicsShareFuncSDDS char ** SDDS_GetErrorMessages (int32_t *number, int32_t mode)
 Retrieves recorded error messages from the SDDS error stack.
 
epicsShareFuncSDDS char ** SDDS_GetColumnNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all columns in the SDDS dataset.
 
epicsShareFuncSDDS char ** SDDS_GetParameterNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all parameters in the SDDS dataset.
 
epicsShareFuncSDDS char ** SDDS_GetAssociateNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all associates in the SDDS dataset.
 
epicsShareFuncSDDS char ** SDDS_GetArrayNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all arrays in the SDDS dataset.
 
epicsShareFuncSDDS COLUMN_DEFINITIONSDDS_GetColumnDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified column from the SDDS dataset.
 
epicsShareFuncSDDS COLUMN_DEFINITIONSDDS_CopyColumnDefinition (COLUMN_DEFINITION **target, COLUMN_DEFINITION *source)
 Creates a copy of a column definition.
 
epicsShareFuncSDDS int32_t SDDS_FreeColumnDefinition (COLUMN_DEFINITION *source)
 Frees memory allocated for a column definition.
 
epicsShareFuncSDDS int32_t SDDS_TransferColumnDefinition (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Transfers a column definition from a source dataset to a target dataset.
 
epicsShareFuncSDDS int32_t SDDS_DefineColumnLikeParameter (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Defines a column in the target dataset based on a parameter definition from the source dataset.
 
epicsShareFuncSDDS int32_t SDDS_DefineColumnLikeArray (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Defines a column in the target dataset based on an array definition from the source dataset.
 
epicsShareFuncSDDS int32_t SDDS_TransferAllColumnDefinitions (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
 Transfers all column definitions from a source dataset to a target dataset.
 
epicsShareFuncSDDS int32_t SDDS_ParseNamelist (void *data, SDDS_FIELD_INFORMATION *fieldInfo, int32_t fieldInfos, char *s)
 Parse a namelist string and populate the corresponding data structure.
 
epicsShareFuncSDDS PARAMETER_DEFINITIONSDDS_GetParameterDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified parameter from the SDDS dataset.
 
epicsShareFuncSDDS PARAMETER_DEFINITIONSDDS_CopyParameterDefinition (PARAMETER_DEFINITION **target, PARAMETER_DEFINITION *source)
 Creates a copy of a parameter definition.
 
epicsShareFuncSDDS int32_t SDDS_FreeParameterDefinition (PARAMETER_DEFINITION *source)
 Frees memory allocated for a parameter definition.
 
epicsShareFuncSDDS int32_t SDDS_TransferParameterDefinition (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Transfers a parameter definition from a source dataset to a target dataset.
 
epicsShareFuncSDDS int32_t SDDS_DefineParameterLikeColumn (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Defines a parameter in the target dataset based on a column definition from the source dataset.
 
epicsShareFuncSDDS int32_t SDDS_DefineParameterLikeArray (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Defines a parameter in the target dataset based on an array definition from the source dataset.
 
epicsShareFuncSDDS int32_t SDDS_TransferAllParameterDefinitions (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
 Transfers all parameter definitions from a source dataset to a target dataset.
 
epicsShareFuncSDDS ARRAY_DEFINITIONSDDS_GetArrayDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified array from the SDDS dataset.
 
epicsShareFuncSDDS ARRAY_DEFINITIONSDDS_CopyArrayDefinition (ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
 Creates a copy of an array definition.
 
epicsShareFuncSDDS int32_t SDDS_FreeArrayDefinition (ARRAY_DEFINITION *source)
 Frees memory allocated for an array definition.
 
epicsShareFuncSDDS int32_t SDDS_TransferArrayDefinition (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Transfers an array definition from a source dataset to a target dataset.
 
epicsShareFuncSDDS int32_t SDDS_TransferAllArrayDefinitions (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
 Transfers all array definitions from a source dataset to a target dataset.
 
epicsShareFuncSDDS ASSOCIATE_DEFINITIONSDDS_GetAssociateDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified associate from the SDDS dataset.
 
epicsShareFuncSDDS ASSOCIATE_DEFINITIONSDDS_CopyAssociateDefinition (ASSOCIATE_DEFINITION **target, ASSOCIATE_DEFINITION *source)
 Creates a copy of an associate definition.
 
epicsShareFuncSDDS int32_t SDDS_FreeAssociateDefinition (ASSOCIATE_DEFINITION *source)
 Frees memory allocated for an associate definition.
 
epicsShareFuncSDDS int32_t SDDS_TransferAssociateDefinition (SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
 Transfers an associate definition from a source dataset to a target dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetColumnIndex (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the index of a named column in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetParameterIndex (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the index of a named parameter in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetArrayIndex (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the index of a named array in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetAssociateIndex (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the index of a named associate in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_GetColumnType (SDDS_DATASET *SDDS_dataset, int32_t index)
 Retrieves the data type of a column in the SDDS dataset by its index.
 
epicsShareFuncSDDS int32_t SDDS_GetNamedColumnType (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the data type of a column in the SDDS dataset by its name.
 
epicsShareFuncSDDS int32_t SDDS_GetParameterType (SDDS_DATASET *SDDS_dataset, int32_t index)
 Retrieves the data type of a parameter in the SDDS dataset by its index.
 
epicsShareFuncSDDS int32_t SDDS_GetNamedParameterType (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the data type of a parameter in the SDDS dataset by its name.
 
epicsShareFuncSDDS int32_t SDDS_GetArrayType (SDDS_DATASET *SDDS_dataset, int32_t index)
 Retrieves the data type of an array in the SDDS dataset by its index.
 
epicsShareFuncSDDS int32_t SDDS_GetNamedArrayType (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the data type of an array in the SDDS dataset by its name.
 
epicsShareFuncSDDS int32_t SDDS_GetTypeSize (int32_t type)
 Retrieves the size in bytes of a specified SDDS data type.
 
epicsShareFuncSDDS char * SDDS_GetTypeName (int32_t type)
 Retrieves the name of a specified SDDS data type as a string.
 
epicsShareFuncSDDS int32_t SDDS_IdentifyType (char *typeName)
 Identifies the SDDS data type based on its string name.
 
epicsShareFuncSDDS char * SDDS_FindColumn (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Finds the first column in the SDDS dataset that matches the specified criteria.
 
epicsShareFuncSDDS char * SDDS_FindParameter (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Finds the first parameter in the SDDS dataset that matches the specified criteria.
 
epicsShareFuncSDDS char * SDDS_FindArray (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Finds the first array in the SDDS dataset that matches the specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_CheckColumn (SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
 Checks if a column exists in the SDDS dataset with the specified name, units, and type.
 
epicsShareFuncSDDS int32_t SDDS_CheckParameter (SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
 Checks if a parameter exists in the SDDS dataset with the specified name, units, and type.
 
epicsShareFuncSDDS int32_t SDDS_CheckArray (SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
 Checks if an array exists in the SDDS dataset with the specified name, units, and type.
 
epicsShareFuncSDDS int32_t SDDS_VerifyArrayExists (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Verifies the existence of an array in the SDDS dataset based on specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_VerifyColumnExists (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Verifies the existence of a column in the SDDS dataset based on specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_VerifyParameterExists (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Verifies the existence of a parameter in the SDDS dataset based on specified criteria.
 
epicsShareFuncSDDS int32_t SDDS_PrintCheckText (FILE *fp, char *name, char *units, int32_t type, char *class_name, int32_t error_code)
 Prints detailed error messages related to SDDS entity checks.
 
epicsShareFuncSDDS int32_t SDDS_IsActive (SDDS_DATASET *SDDS_dataset)
 Checks whether an SDDS dataset is currently active.
 
epicsShareFuncSDDS int32_t SDDS_ForceInactive (SDDS_DATASET *SDDS_dataset)
 Marks an SDDS dataset as inactive.
 
epicsShareFuncSDDS int32_t SDDS_LockFile (FILE *fp, const char *filename, const char *callerName)
 Attempts to lock a specified file.
 
epicsShareFuncSDDS int32_t SDDS_FileIsLocked (const char *filename)
 Determines if a specified file is locked.
 
epicsShareFuncSDDS int32_t SDDS_BreakIntoLockedFile (char *filename)
 Attempts to override a locked file by creating a temporary copy.
 
epicsShareFuncSDDS int32_t SDDS_CopyString (char **target, const char *source)
 Copies a source string to a target string with memory allocation.
 
epicsShareFuncSDDS int32_t SDDS_CopyStringArray (char **target, char **source, int64_t n_strings)
 Copies an array of strings from source to target.
 
epicsShareFuncSDDS int32_t SDDS_FreeStringArray (char **string, int64_t strings)
 Frees an array of strings by deallocating each individual string.
 
epicsShareFuncSDDS int32_t SDDS_VerifyPrintfFormat (const char *format_string, int32_t type)
 Verifies that a printf format string is compatible with a specified data type.
 
epicsShareFuncSDDS int32_t SDDS_HasWhitespace (char *string)
 Checks if a string contains any whitespace characters.
 
epicsShareFuncSDDS char * fgetsSkipComments (SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, FILE *fp, char skip_char)
 Reads a line from a file while skipping comment lines.
 
epicsShareFuncSDDS char * fgetsSkipCommentsResize (SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, FILE *fp, char skip_char)
 Reads a line from a file with dynamic buffer resizing while skipping comment lines.
 
epicsShareFuncSDDS void SDDS_CutOutComments (SDDS_DATASET *SDDS_dataset, char *s, char cc)
 Removes comments from a string based on a specified comment character.
 
epicsShareFuncSDDS void SDDS_EscapeNewlines (char *s)
 Escapes newline characters in a string by replacing them with "\\n".
 
epicsShareFuncSDDS void SDDS_EscapeQuotes (char *s, char quote_char)
 Escapes quote characters within a string by inserting backslashes.
 
epicsShareFuncSDDS void SDDS_UnescapeQuotes (char *s, char quote_char)
 Removes escape characters from quote characters within a string.
 
epicsShareFuncSDDS int32_t SDDS_IsQuoted (char *string, char *position, char quotation_mark)
 Checks if a position in a string is within a quoted section.
 
epicsShareFuncSDDS int32_t SDDS_GetToken (char *s, char *buffer, int32_t buflen)
 Extracts the next token from a string, handling quoted substrings and escape characters.
 
epicsShareFuncSDDS int32_t SDDS_GetToken2 (char *s, char **st, int32_t *strlength, char *buffer, int32_t buflen)
 Extracts the next token from a string, handling quoted substrings and escape characters, with updated string pointers.
 
epicsShareFuncSDDS int32_t SDDS_PadToLength (char *string, int32_t length)
 Pads a string with spaces to reach a specified length.
 
epicsShareFuncSDDS void SDDS_EscapeCommentCharacters (char *string, char cc)
 Escapes comment characters within a string by inserting backslashes.
 
epicsShareFuncSDDS void SDDS_InterpretEscapes (char *s)
 Interprets and converts escape sequences in a string.
 
epicsShareFuncSDDS int32_t SDDS_ZeroMemory (void *mem, int64_t n_bytes)
 Sets a block of memory to zero.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS 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.
 
epicsShareFuncSDDS int32_t SDDS_SprintTypedValueFactor (void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode, double factor)
 Reallocates memory to a new size and zero-initializes the additional space.
 
epicsShareFuncSDDS int32_t SDDS_PrintTypedValue (void *data, int64_t index, int32_t type, char *format, FILE *fp, uint32_t mode)
 Prints a data value of a specified type using an optional printf format string.
 
epicsShareFuncSDDS int32_t SDDS_WriteTypedValue (void *data, int64_t index, int32_t type, char *format, FILE *fp)
 Writes a typed value to an ASCII file stream.
 
epicsShareFuncSDDS void * SDDS_CastValue (void *data, int64_t index, int32_t data_type, int32_t desired_type, void *memory)
 Casts a value from one SDDS data type to another.
 
epicsShareFuncSDDS void SDDS_RemovePadding (char *s)
 Removes leading and trailing whitespace from a string.
 
epicsShareFuncSDDS int32_t SDDS_StringIsBlank (char *s)
 Checks if a string is blank (contains only whitespace characters).
 
epicsShareFuncSDDS void * SDDS_AllocateMatrix (int32_t size, int64_t dim1, int64_t dim2)
 Allocates a two-dimensional matrix with zero-initialized elements.
 
epicsShareFuncSDDS void SDDS_FreeMatrix (void **ptr, int64_t dim1)
 Frees memory allocated for a two-dimensional matrix.
 
epicsShareFuncSDDS void SDDS_FreeArray (SDDS_ARRAY *array)
 Frees memory allocated for an SDDS array structure.
 
epicsShareFuncSDDS void * SDDS_MakePointerArray (void *data, int32_t type, int32_t dimensions, int32_t *dimension)
 Creates a multi-dimensional pointer array from a contiguous data block.
 
epicsShareFuncSDDS int32_t SDDS_ApplyFactorToParameter (SDDS_DATASET *SDDS_dataset, char *name, double factor)
 Applies a scaling factor to a specific parameter in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ApplyFactorToColumn (SDDS_DATASET *SDDS_dataset, char *name, double factor)
 Applies a scaling factor to all elements of a specific column in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_DeleteParameterFixedValues (SDDS_DATASET *SDDS_dataset)
 Deletes fixed values from all parameters in the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SetDataMode (SDDS_DATASET *SDDS_dataset, int32_t newmode)
 Sets the data mode (ASCII or Binary) for the SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_CheckDataset (SDDS_DATASET *SDDS_dataset, const char *caller)
 Validates the SDDS dataset pointer.
 
epicsShareFuncSDDS int32_t SDDS_CheckTabularData (SDDS_DATASET *SDDS_dataset, const char *caller)
 Validates the consistency of tabular data within an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_CheckDatasetStructureSize (int32_t size)
 Verifies that the size of the SDDS_DATASET structure matches the expected size.
 
epicsShareFuncSDDS uint32_t SDDS_SetAutoCheckMode (uint32_t newMode)
 Sets the automatic check mode for SDDS dataset validation.
 
epicsShareFuncSDDS int32_t SDDS_FlushBuffer (FILE *fp, SDDS_FILEBUFFER *fBuffer)
 
epicsShareFuncSDDS int32_t SDDS_BufferedWrite (void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer)
 
epicsShareFuncSDDS int32_t SDDS_ScanData (char *string, int32_t type, int32_t field_length, void *data, int64_t index, int32_t is_parameter)
 Scans a string and saves the parsed value into a data pointer according to the specified data type.
 
epicsShareFuncSDDS int32_t SDDS_ScanData2 (char *string, char **pstring, int32_t *strlength, int32_t type, int32_t field_length, void *data, int64_t index, int32_t is_parameter)
 Scans a string and saves the parsed value into a data pointer, optimized for long strings.
 
epicsShareFuncSDDS long double SDDS_ConvertToLongDouble (int32_t type, void *data, int64_t index)
 Converts a value to long double based on its type.
 
epicsShareFuncSDDS double SDDS_ConvertToDouble (int32_t type, void *data, int64_t index)
 Converts a value to double based on its type.
 
epicsShareFuncSDDS int64_t SDDS_ConvertToLong64 (int32_t type, void *data, int64_t index)
 Converts a value to a 64-bit integer based on its type.
 
epicsShareFuncSDDS int32_t SDDS_ConvertToLong (int32_t type, void *data, int64_t index)
 Converts a value to a 32-bit integer based on its type.
 
epicsShareFuncSDDS int32_t SDDS_WriteBinaryString (char *string, FILE *fp, SDDS_FILEBUFFER *fBuffer)
 Writes a binary string to a file with buffering.
 
epicsShareFuncSDDS int64_t SDDS_CreateRpnMemory (const char *name, short is_string)
 Stub function for creating RPN memory when RPN_SUPPORT is not enabled.
 
epicsShareFuncSDDS int64_t SDDS_CreateRpnArray (char *name)
 Stub function for creating RPN arrays when RPN_SUPPORT is not enabled.
 
epicsShareFuncSDDS int32_t SDDS_IsBigEndianMachine ()
 Determines whether the current machine uses big-endian byte ordering.
 
void SDDS_SwapShort (short *data)
 Swaps the endianness of a short integer.
 
void SDDS_SwapUShort (unsigned short *data)
 Swaps the endianness of an unsigned short integer.
 
epicsShareFuncSDDS void SDDS_SwapLong (int32_t *data)
 Swaps the endianness of a 32-bit integer.
 
epicsShareFuncSDDS void SDDS_SwapULong (uint32_t *data)
 Swaps the endianness of a 32-bit unsigned integer.
 
epicsShareFuncSDDS void SDDS_SwapLong64 (int64_t *data)
 Swaps the endianness of a 64-bit integer.
 
epicsShareFuncSDDS void SDDS_SwapULong64 (uint64_t *data)
 Swaps the endianness of a 64-bit unsigned integer.
 
void SDDS_SwapFloat (float *data)
 Swaps the endianness of a float.
 
void SDDS_SwapDouble (double *data)
 Swaps the endianness of a double.
 
void SDDS_SwapLongDouble (long double *data)
 Swaps the endianness of a long double.
 
epicsShareFuncSDDS int32_t SDDS_SwapEndsArrayData (SDDS_DATASET *SDDSin)
 Swaps the endianness of the array data in an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SwapEndsParameterData (SDDS_DATASET *SDDSin)
 Swaps the endianness of the parameter data in an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_SwapEndsColumnData (SDDS_DATASET *SDDSin)
 Swaps the endianness of the column data in an SDDS dataset.
 
epicsShareFuncSDDS int32_t SDDS_ReadNonNativePage (SDDS_DATASET *SDDS_dataset)
 Reads a non-native endian page from an SDDS dataset.
 
int32_t SDDS_ReadNonNativePageSparse (SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset)
 Reads a sparse non-native endian page from an SDDS dataset.
 
int32_t SDDS_ReadNonNativeBinaryPage (SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset)
 Reads a non-native endian binary page from an SDDS dataset.
 
int32_t SDDS_ReadNonNativeBinaryParameters (SDDS_DATASET *SDDS_dataset)
 Reads non-native endian binary parameters from an SDDS dataset.
 
int32_t SDDS_ReadNonNativeBinaryArrays (SDDS_DATASET *SDDS_dataset)
 Reads non-native endian binary arrays from an SDDS dataset.
 
int32_t SDDS_ReadNonNativeBinaryRow (SDDS_DATASET *SDDS_dataset, int64_t row, int32_t skip)
 Reads a non-native endian binary row from an SDDS dataset.
 
char * SDDS_ReadNonNativeBinaryString (FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
 Reads a non-native endian binary string from a file.
 
epicsShareFuncSDDS int32_t SDDS_WriteNonNativeBinaryPage (SDDS_DATASET *SDDS_dataset)
 Writes a non-native endian binary page to an SDDS dataset.
 
int32_t SDDS_WriteNonNativeBinaryParameters (SDDS_DATASET *SDDS_dataset)
 Writes non-native endian binary parameters to an SDDS dataset.
 
int32_t SDDS_WriteNonNativeBinaryArrays (SDDS_DATASET *SDDS_dataset)
 Writes non-native endian binary arrays to an SDDS dataset.
 
int32_t SDDS_WriteNonNativeBinaryRow (SDDS_DATASET *SDDS_dataset, int64_t row)
 Writes a non-native endian binary row to an SDDS dataset.
 
int32_t SDDS_WriteNonNativeBinaryString (char *string, FILE *fp, SDDS_FILEBUFFER *fBuffer)
 Writes a non-native endian binary string to a file.
 
epicsShareFuncSDDS char ** getMatchingSDDSNames (SDDS_DATASET *dataset, char **matchName, int32_t matches, int32_t *names, short match_type)
 Retrieves an array of matching SDDS entity names based on specified criteria.
 
epicsShareFuncSDDS SDDS_DATASETSDDS_CreateEmptyDataset (void)
 Creates an empty SDDS dataset.
 

Variables

epicsShareExtern char * SDDS_type_name [SDDS_NUM_TYPES]
 
epicsShareExtern int32_t SDDS_type_size [SDDS_NUM_TYPES]
 
char * SDDS_data_mode [SDDS_NUM_DATA_MODES]
 Array of supported data modes.
 
SDDS_FIELD_INFORMATION SDDS_ArrayFieldInformation [SDDS_ARRAY_FIELDS]
 Field information for array definitions.
 
SDDS_FIELD_INFORMATION SDDS_ColumnFieldInformation [SDDS_COLUMN_FIELDS]
 Field information for column definitions.
 
SDDS_FIELD_INFORMATION SDDS_ParameterFieldInformation [SDDS_PARAMETER_FIELDS]
 Field information for parameter definitions.
 
SDDS_FIELD_INFORMATION SDDS_AssociateFieldInformation [SDDS_ASSOCIATE_FIELDS]
 Field information for associate definitions.
 
SDDS_FIELD_INFORMATION SDDS_DescriptionFieldInformation [SDDS_DESCRIPTION_FIELDS]
 Field information for SDDS layout descriptions.
 
SDDS_FIELD_INFORMATION SDDS_IncludeFieldInformation [SDDS_INCLUDE_FIELDS]
 Field information for include directives.
 
SDDS_FIELD_INFORMATION SDDS_DataFieldInformation [SDDS_DATA_FIELDS]
 Field information for data mode settings.
 

Detailed Description

SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.

This header file defines the data types, macros, structures, and function prototypes used for handling SDDS files. SDDS is a file protocol designed to store and transfer scientific data efficiently.

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

Definition in file SDDS.h.

Macro Definition Documentation

◆ _SDDS_

#define _SDDS_   1

Definition at line 76 of file SDDS.h.

◆ DEFAULT_COLUMN_MEMORY_MODE

#define DEFAULT_COLUMN_MEMORY_MODE   0

Definition at line 382 of file SDDS.h.

◆ DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS

#define DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS   1

Definition at line 383 of file SDDS.h.

◆ epicsShareExtern

#define epicsShareExtern   extern

Definition at line 136 of file SDDS.h.

◆ epicsShareFuncSDDS

#define epicsShareFuncSDDS

Definition at line 135 of file SDDS.h.

◆ FIND_ANY_TYPE

#define FIND_ANY_TYPE   0

Definition at line 682 of file SDDS.h.

◆ FIND_FLOATING_TYPE

#define FIND_FLOATING_TYPE   4

Definition at line 686 of file SDDS.h.

◆ FIND_INTEGER_TYPE

#define FIND_INTEGER_TYPE   3

Definition at line 685 of file SDDS.h.

◆ FIND_NUMERIC_TYPE

#define FIND_NUMERIC_TYPE   2

Definition at line 684 of file SDDS.h.

◆ FIND_SPECIFIED_TYPE

#define FIND_SPECIFIED_TYPE   1

Definition at line 683 of file SDDS.h.

◆ FLUSH_TABLE

#define FLUSH_TABLE   0x1UL

Definition at line 460 of file SDDS.h.

◆ LZMA_BUF_SIZE

#define LZMA_BUF_SIZE   40960

Definition at line 218 of file SDDS.h.

◆ NUMSCANFILTER_INVERT

#define NUMSCANFILTER_INVERT   0x0001UL

Definition at line 560 of file SDDS.h.

◆ NUMSCANFILTER_STRICT

#define NUMSCANFILTER_STRICT   0x0002UL

Definition at line 561 of file SDDS.h.

◆ RW_ASSOCIATES

#define RW_ASSOCIATES   0

Definition at line 140 of file SDDS.h.

◆ SDDS_0_PREVIOUS

#define SDDS_0_PREVIOUS   0x0080UL

Definition at line 534 of file SDDS.h.

◆ SDDS_1_PREVIOUS

#define SDDS_1_PREVIOUS   0x0040UL

Definition at line 533 of file SDDS.h.

◆ SDDS_ALL_GetErrorMessages

#define SDDS_ALL_GetErrorMessages   1

Definition at line 627 of file SDDS.h.

◆ SDDS_ALLOW_ANY_NAME

#define SDDS_ALLOW_ANY_NAME   0x0001UL

Definition at line 407 of file SDDS.h.

◆ SDDS_ALLOW_V15_NAME

#define SDDS_ALLOW_V15_NAME   0x0002UL

Definition at line 408 of file SDDS.h.

◆ SDDS_AND

#define SDDS_AND   0x0001UL

Definition at line 527 of file SDDS.h.

◆ SDDS_ARRAY_FIELDS

#define SDDS_ARRAY_FIELDS   9

Definition at line 190 of file SDDS.h.

◆ SDDS_ASCII

#define SDDS_ASCII   2

Definition at line 143 of file SDDS.h.

◆ SDDS_ASSOCIATE_FIELDS

#define SDDS_ASSOCIATE_FIELDS   6

Definition at line 196 of file SDDS.h.

◆ SDDS_AUTOREADRECOVER

#define SDDS_AUTOREADRECOVER   0x0002UL

Definition at line 390 of file SDDS.h.

◆ SDDS_BIGENDIAN

#define SDDS_BIGENDIAN   SDDS_BIGENDIAN_SEEN

Definition at line 793 of file SDDS.h.

◆ SDDS_BIGENDIAN_SEEN

#define SDDS_BIGENDIAN_SEEN   0x0001UL

Definition at line 790 of file SDDS.h.

◆ SDDS_BINARY

#define SDDS_BINARY   1

Definition at line 142 of file SDDS.h.

◆ SDDS_BY_INDEX

#define SDDS_BY_INDEX   1

Definition at line 441 of file SDDS.h.

◆ SDDS_BY_NAME

#define SDDS_BY_NAME   2

Definition at line 442 of file SDDS.h.

◆ SDDS_CHECK_NONEXISTENT

#define SDDS_CHECK_NONEXISTENT   1

Definition at line 701 of file SDDS.h.

◆ SDDS_CHECK_OK

#define SDDS_CHECK_OK   SDDS_CHECK_OKAY

Definition at line 700 of file SDDS.h.

◆ SDDS_CHECK_OKAY

#define SDDS_CHECK_OKAY   0

Definition at line 699 of file SDDS.h.

◆ SDDS_CHECK_WRONGTYPE

#define SDDS_CHECK_WRONGTYPE   2

Definition at line 702 of file SDDS.h.

◆ SDDS_CHECK_WRONGUNITS

#define SDDS_CHECK_WRONGUNITS   3

Definition at line 703 of file SDDS.h.

◆ SDDS_CheckTableStructureSize

#define SDDS_CheckTableStructureSize ( a)
Value:
epicsShareFuncSDDS int32_t SDDS_CheckDatasetStructureSize(int32_t size)
Verifies that the size of the SDDS_DATASET structure matches the expected size.

Definition at line 754 of file SDDS.h.

◆ SDDS_CI_MATCH_EXCLUDE_STRING

#define SDDS_CI_MATCH_EXCLUDE_STRING   10

Definition at line 524 of file SDDS.h.

◆ SDDS_CI_MATCH_STRING

#define SDDS_CI_MATCH_STRING   9

Definition at line 523 of file SDDS.h.

◆ SDDS_CI_NAME_ARRAY

#define SDDS_CI_NAME_ARRAY   6

Definition at line 520 of file SDDS.h.

◆ SDDS_CI_NAME_STRINGS

#define SDDS_CI_NAME_STRINGS   8

Definition at line 522 of file SDDS.h.

◆ SDDS_CI_NAMES_STRING

#define SDDS_CI_NAMES_STRING   7

Definition at line 521 of file SDDS.h.

◆ SDDS_COLUMN_FIELDS

#define SDDS_COLUMN_FIELDS   7

Definition at line 184 of file SDDS.h.

◆ SDDS_COLUMN_MAJOR_DATA

#define SDDS_COLUMN_MAJOR_DATA   2

Definition at line 596 of file SDDS.h.

◆ SDDS_COLUMN_MAJOR_ORDER

#define SDDS_COLUMN_MAJOR_ORDER   0x0001UL

Definition at line 38 of file SDDS.h.

◆ SDDS_CONTIGUOUS_DATA

#define SDDS_CONTIGUOUS_DATA   2

Definition at line 602 of file SDDS.h.

◆ SDDS_CopyTable

#define SDDS_CopyTable ( a,
b )
Value:
epicsShareFuncSDDS int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:578

Definition at line 427 of file SDDS.h.

◆ SDDS_DATA_FIELDS

#define SDDS_DATA_FIELDS   7

Definition at line 234 of file SDDS.h.

◆ SDDS_DESCRIPTION_FIELDS

#define SDDS_DESCRIPTION_FIELDS   2

Definition at line 233 of file SDDS.h.

◆ SDDS_EXIT_PrintErrors

#define SDDS_EXIT_PrintErrors   2

Definition at line 624 of file SDDS.h.

◆ SDDS_FILEBUFFER_SIZE

#define SDDS_FILEBUFFER_SIZE   262144

Definition at line 301 of file SDDS.h.

◆ SDDS_FIXED_ROWCOUNT

#define SDDS_FIXED_ROWCOUNT   SDDS_FIXED_ROWCOUNT_SEEN

Definition at line 795 of file SDDS.h.

◆ SDDS_FIXED_ROWCOUNT_SEEN

#define SDDS_FIXED_ROWCOUNT_SEEN   0x0004UL

Definition at line 792 of file SDDS.h.

◆ SDDS_FIXEDROWCOUNT

#define SDDS_FIXEDROWCOUNT   0x0002UL

Definition at line 386 of file SDDS.h.

◆ SDDS_FLAG_ARRAY

#define SDDS_FLAG_ARRAY   0x001UL

Definition at line 511 of file SDDS.h.

◆ SDDS_GET_BY_INDEX

#define SDDS_GET_BY_INDEX   SDDS_BY_INDEX

Definition at line 469 of file SDDS.h.

◆ SDDS_GET_BY_NAME

#define SDDS_GET_BY_NAME   SDDS_BY_NAME

Definition at line 470 of file SDDS.h.

◆ SDDS_INCLUDE_FIELDS

#define SDDS_INCLUDE_FIELDS   1

Definition at line 235 of file SDDS.h.

◆ SDDS_INDEX_LIMITS

#define SDDS_INDEX_LIMITS   0x002UL

Definition at line 512 of file SDDS.h.

◆ SDDS_INDIRECT_MATCH

#define SDDS_INDIRECT_MATCH   0x0020UL

Definition at line 532 of file SDDS.h.

◆ SDDS_IsDisconnected

#define SDDS_IsDisconnected ( SDDSptr)
Value:
((SDDSptr)->layout.disconnected)

Definition at line 371 of file SDDS.h.

◆ SDDS_LAST_GetErrorMessages

#define SDDS_LAST_GetErrorMessages   0

Definition at line 626 of file SDDS.h.

◆ SDDS_LayoutWritten

#define SDDS_LayoutWritten ( SDDSptr)
Value:
((SDDSptr)->layout.layout_written)

Definition at line 415 of file SDDS.h.

◆ SDDS_LITTLEENDIAN

#define SDDS_LITTLEENDIAN   SDDS_LITTLEENDIAN_SEEN

Definition at line 794 of file SDDS.h.

◆ SDDS_LITTLEENDIAN_SEEN

#define SDDS_LITTLEENDIAN_SEEN   0x0002UL

Definition at line 791 of file SDDS.h.

◆ SDDS_MATCH_ARRAY

#define SDDS_MATCH_ARRAY   2

Definition at line 842 of file SDDS.h.

◆ SDDS_MATCH_COLUMN

#define SDDS_MATCH_COLUMN   0

Definition at line 840 of file SDDS.h.

◆ SDDS_MATCH_EXCLUDE_STRING

#define SDDS_MATCH_EXCLUDE_STRING   5

Definition at line 519 of file SDDS.h.

◆ SDDS_MATCH_PARAMETER

#define SDDS_MATCH_PARAMETER   1

Definition at line 841 of file SDDS.h.

◆ SDDS_MATCH_STRING

#define SDDS_MATCH_STRING   4

Definition at line 518 of file SDDS.h.

◆ SDDS_MAXLINE

#define SDDS_MAXLINE   1024

Definition at line 158 of file SDDS.h.

◆ SDDS_MEMMODE

#define SDDS_MEMMODE   3

Definition at line 31 of file SDDS.h.

◆ SDDS_MPI_READ_ONLY

#define SDDS_MPI_READ_ONLY   0x0001UL

Definition at line 33 of file SDDS.h.

◆ SDDS_MPI_READ_WRITE

#define SDDS_MPI_READ_WRITE   0x0004UL

Definition at line 35 of file SDDS.h.

◆ SDDS_MPI_STRING_COLUMN_LEN

#define SDDS_MPI_STRING_COLUMN_LEN   16

Definition at line 36 of file SDDS.h.

◆ SDDS_MPI_WRITE_ONLY

#define SDDS_MPI_WRITE_ONLY   0x0002UL

Definition at line 34 of file SDDS.h.

◆ SDDS_NAME_ARRAY

#define SDDS_NAME_ARRAY   1

Definition at line 515 of file SDDS.h.

◆ SDDS_NAME_STRINGS

#define SDDS_NAME_STRINGS   3

Definition at line 517 of file SDDS.h.

◆ SDDS_NAMES_STRING

#define SDDS_NAMES_STRING   2

Definition at line 516 of file SDDS.h.

◆ SDDS_NEGATE_EXPRESSION

#define SDDS_NEGATE_EXPRESSION   0x0010UL

Definition at line 531 of file SDDS.h.

◆ SDDS_NEGATE_MATCH

#define SDDS_NEGATE_MATCH   0x0004UL

Definition at line 529 of file SDDS.h.

◆ SDDS_NEGATE_PREVIOUS

#define SDDS_NEGATE_PREVIOUS   0x0008UL

Definition at line 530 of file SDDS.h.

◆ SDDS_NOAUTOREADRECOVER

#define SDDS_NOAUTOREADRECOVER   0x0001UL

Definition at line 389 of file SDDS.h.

◆ SDDS_NOCASE_COMPARE

#define SDDS_NOCASE_COMPARE   0x0100UL

Definition at line 536 of file SDDS.h.

◆ SDDS_NORMAL_DEFINITION

#define SDDS_NORMAL_DEFINITION   0

Definition at line 162 of file SDDS.h.

◆ SDDS_NOROWCOUNT

#define SDDS_NOROWCOUNT   0x0004UL

Definition at line 387 of file SDDS.h.

◆ SDDS_NUM_DATA_MODES

#define SDDS_NUM_DATA_MODES   2

Definition at line 145 of file SDDS.h.

◆ SDDS_OR

#define SDDS_OR   0x0002UL

Definition at line 528 of file SDDS.h.

◆ SDDS_PARALLEL

#define SDDS_PARALLEL   3

Definition at line 144 of file SDDS.h.

◆ SDDS_PARAMETER_FIELDS

#define SDDS_PARAMETER_FIELDS   7

Definition at line 176 of file SDDS.h.

◆ SDDS_PASS_BY_REFERENCE

#define SDDS_PASS_BY_REFERENCE   8

Definition at line 452 of file SDDS.h.

◆ SDDS_PASS_BY_STRING

#define SDDS_PASS_BY_STRING   16

Definition at line 453 of file SDDS.h.

◆ SDDS_PASS_BY_VALUE

#define SDDS_PASS_BY_VALUE   4

Definition at line 451 of file SDDS.h.

◆ SDDS_POINTER_ARRAY

#define SDDS_POINTER_ARRAY   1

Definition at line 601 of file SDDS.h.

◆ SDDS_PRINT_BUFLEN

#define SDDS_PRINT_BUFLEN   16834

Definition at line 160 of file SDDS.h.

◆ SDDS_PRINT_NOQUOTES

#define SDDS_PRINT_NOQUOTES   0x0001UL

Definition at line 735 of file SDDS.h.

◆ SDDS_READMODE

#define SDDS_READMODE   1

Definition at line 29 of file SDDS.h.

◆ SDDS_ReadTable

#define SDDS_ReadTable ( a)
Value:
epicsShareFuncSDDS int32_t SDDS_ReadPage(SDDS_DATASET *SDDS_dataset)

Definition at line 496 of file SDDS.h.

◆ SDDS_ROW_MAJOR_DATA

#define SDDS_ROW_MAJOR_DATA   1

Definition at line 595 of file SDDS.h.

◆ SDDS_ROW_MAJOR_ORDER

#define SDDS_ROW_MAJOR_ORDER   0x0002UL

Definition at line 39 of file SDDS.h.

◆ SDDS_RowCount

#define SDDS_RowCount ( SDDS_dataset)
Value:
((SDDS_dataset)->n_rows)

Definition at line 555 of file SDDS.h.

◆ SDDS_SET_BY_INDEX

#define SDDS_SET_BY_INDEX   SDDS_BY_INDEX

Definition at line 449 of file SDDS.h.

◆ SDDS_SET_BY_NAME

#define SDDS_SET_BY_NAME   SDDS_BY_NAME

Definition at line 450 of file SDDS.h.

◆ SDDS_StartTable

#define SDDS_StartTable ( a,
b )
Value:
epicsShareFuncSDDS int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)

Definition at line 445 of file SDDS.h.

◆ SDDS_TRANSFER_KEEPOLD

#define SDDS_TRANSFER_KEEPOLD   0x01UL

Definition at line 650 of file SDDS.h.

◆ SDDS_TRANSFER_OVERWRITE

#define SDDS_TRANSFER_OVERWRITE   0x02UL

Definition at line 651 of file SDDS.h.

◆ SDDS_UpdateTable

#define SDDS_UpdateTable ( a)
Value:
epicsShareFuncSDDS int32_t SDDS_UpdatePage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the current page of the SDDS dataset.

Definition at line 461 of file SDDS.h.

◆ SDDS_VARIABLEROWCOUNT

#define SDDS_VARIABLEROWCOUNT   0x0001UL

Definition at line 385 of file SDDS.h.

◆ SDDS_VERBOSE_PrintErrors

#define SDDS_VERBOSE_PrintErrors   1

Definition at line 623 of file SDDS.h.

◆ SDDS_VERSION

#define SDDS_VERSION   5

Definition at line 78 of file SDDS.h.

◆ SDDS_WRITEMODE

#define SDDS_WRITEMODE   2

Definition at line 30 of file SDDS.h.

◆ SDDS_WRITEONLY_DEFINITION

#define SDDS_WRITEONLY_DEFINITION   1

Definition at line 163 of file SDDS.h.

◆ SDDS_WriteTable

#define SDDS_WriteTable ( a)
Value:
epicsShareFuncSDDS int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.

Definition at line 458 of file SDDS.h.

◆ SVN_VERSION

#define SVN_VERSION   "unknown"

Definition at line 81 of file SDDS.h.

◆ TABULAR_DATA_CHECKS

#define TABULAR_DATA_CHECKS   0x0001UL

Definition at line 756 of file SDDS.h.

◆ TERMINATE_DONT_FREE_ARRAY_STRINGS

#define TERMINATE_DONT_FREE_ARRAY_STRINGS   0x0002

Definition at line 379 of file SDDS.h.

◆ TERMINATE_DONT_FREE_TABLE_STRINGS

#define TERMINATE_DONT_FREE_TABLE_STRINGS   0x0001

Definition at line 378 of file SDDS.h.

Typedef Documentation

◆ gzFile

typedef voidp gzFile

Definition at line 213 of file SDDS.h.

◆ SDDS_TABLE

Definition at line 357 of file SDDS.h.

◆ voidp

typedef void* voidp

Definition at line 212 of file SDDS.h.

Function Documentation

◆ fgetsSkipComments()

epicsShareFuncSDDS char * fgetsSkipComments ( SDDS_DATASET * SDDS_dataset,
char * s,
int32_t slen,
FILE * fp,
char skip_char )
extern

Reads a line from a file while skipping comment lines.

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

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

Definition at line 1451 of file SDDS_utils.c.

1451 {
1452 while (fgets(s, slen, fp)) {
1453 if (s[0] != skip_char) {
1454 SDDS_CutOutComments(SDDS_dataset, s, skip_char);
1455 return (s);
1456 } else if (s[1] == '#') {
1457 SDDS_ParseSpecialComments(SDDS_dataset, s + 2);
1458 }
1459 }
1460 return (NULL);
1461}
void SDDS_CutOutComments(SDDS_DATASET *SDDS_dataset, char *s, char cc)
Removes comments from a string based on a specified comment character.
void SDDS_ParseSpecialComments(SDDS_DATASET *SDDS_dataset, char *s)
Parses and processes special comment commands within the SDDS dataset.

◆ fgetsSkipCommentsResize()

epicsShareFuncSDDS char * fgetsSkipCommentsResize ( SDDS_DATASET * SDDS_dataset,
char ** s,
int32_t * slen,
FILE * fp,
char skip_char )
extern

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

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

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

Definition at line 1482 of file SDDS_utils.c.

1482 {
1483 int32_t spaceLeft, length, newLine;
1484 char *sInsert, *fgetsReturn;
1485
1486 sInsert = *s;
1487 spaceLeft = *slen;
1488 newLine = 1;
1489 while ((fgetsReturn = fgets(sInsert, spaceLeft, fp))) {
1490 if (newLine && sInsert[0] == '!')
1491 continue;
1492 SDDS_CutOutComments(SDDS_dataset, sInsert, skip_char);
1493 length = strlen(sInsert);
1494 if (sInsert[length - 1] != '\n' && !feof(fp)) {
1495 /* buffer wasn't long enough to get the whole line. Resize and add more data. */
1496 spaceLeft = *slen;
1497 *slen = *slen * 2;
1498 *s = SDDS_Realloc(*s, sizeof(**s) * *slen);
1499 sInsert = *s + strlen(*s);
1500 newLine = 0;
1501 } else
1502 break;
1503 }
1504 if (!fgetsReturn)
1505 return NULL;
1506 return (*s);
1507}
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677

◆ getMatchingSDDSNames()

epicsShareFuncSDDS char ** getMatchingSDDSNames ( SDDS_DATASET * dataset,
char ** matchName,
int32_t matches,
int32_t * names,
short type )
extern

Retrieves an array of matching SDDS entity names based on specified criteria.

This function processes a list of SDDS entity names (columns, parameters, or arrays) and selects those that match the provided criteria. It supports wildcard matching and exact matching based on the presence of wildcards in the names.

Parameters
[in]datasetPointer to the SDDS_DATASET structure representing the dataset to be searched.
[in]matchNameArray of strings containing the names or patterns to match against the dataset's entities.
[in]matchesThe number of names/patterns provided in matchName.
[out]namesPointer to an int32_t that will be set to the number of matched names.
[in]typeSpecifies the type of SDDS entity to match. Valid values are:
  • SDDS_MATCH_COLUMN
  • SDDS_MATCH_PARAMETER
  • SDDS_MATCH_ARRAY
Returns
  • Returns an array of strings (char **) containing the names of the matched SDDS entities.
  • If no matches are found, returns NULL.
Note
  • The caller is responsible for freeing the memory allocated for the returned array and the individual strings within it.
  • The function uses wild_match for pattern matching when wildcards are present in the matchName entries.
Warning
  • Ensure that the type parameter is correctly specified to match the intended SDDS entity class.
  • Passing an invalid type value will cause the function to terminate the program with an error message.
See also
SDDS_MatchColumns, SDDS_MatchParameters, SDDS_MatchArrays, SDDS_Realloc, SDDS_CopyString

Definition at line 5556 of file SDDS_utils.c.

5556 {
5557 char **name, **selectedName, *ptr = NULL;
5558 int32_t names0 = 0, selected = 0, i, j;
5559 int32_t names32 = 0;
5560
5561 name = selectedName = NULL;
5562 switch (type) {
5563 case SDDS_MATCH_COLUMN:
5564 if (!(name = SDDS_GetColumnNames(dataset, &names0)))
5565 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5566 break;
5567 case SDDS_MATCH_PARAMETER:
5568 if (!(name = SDDS_GetParameterNames(dataset, &names32)))
5569 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5570 names0 = names32;
5571 break;
5572 case SDDS_MATCH_ARRAY:
5573 if (!(name = SDDS_GetArrayNames(dataset, &names32)))
5574 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5575 names0 = names32;
5576 break;
5577 default:
5578 SDDS_Bomb("Invalid match type provided.");
5579 break;
5580 }
5581 for (i = 0; i < matches; i++) {
5582 if (has_wildcards(matchName[i])) {
5583 ptr = expand_ranges(matchName[i]);
5584 for (j = 0; j < names0; j++) {
5585 if (wild_match(name[j], ptr)) {
5586 selectedName = SDDS_Realloc(selectedName, sizeof(*selectedName) * (selected + 1));
5587 SDDS_CopyString(&selectedName[selected], name[j]);
5588 selected++;
5589 }
5590 }
5591 free(ptr);
5592 } else {
5593 if (match_string(matchName[i], name, names0, EXACT_MATCH) < 0) {
5594 fprintf(stderr, "%s not found in input file.\n", matchName[i]);
5595 exit(1);
5596 } else {
5597 selectedName = SDDS_Realloc(selectedName, sizeof(*selectedName) * (selected + 1));
5598 SDDS_CopyString(&selectedName[selected], matchName[i]);
5599 selected++;
5600 }
5601 }
5602 }
5603 SDDS_FreeStringArray(name, names0);
5604 free(name);
5605 *names = selected;
5606 return selectedName;
5607}
int32_t SDDS_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters in the SDDS dataset.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
Definition SDDS_utils.c:432
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
char ** SDDS_GetArrayNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all arrays in the SDDS dataset.
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
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int has_wildcards(char *template)
Check if a template string contains any wildcard characters.
Definition wild_match.c:498
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
Definition wild_match.c:429
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
Definition wild_match.c:49

◆ SDDS_AllocateMatrix()

epicsShareFuncSDDS void * SDDS_AllocateMatrix ( int32_t size,
int64_t dim1,
int64_t dim2 )
extern

Allocates a two-dimensional matrix with zero-initialized elements.

This function allocates memory for a two-dimensional matrix based on the specified dimensions and element size. Each row of the matrix is individually allocated and initialized to zero.

Parameters
[in]sizeThe size in bytes of each element in the matrix.
[in]dim1The number of rows in the matrix.
[in]dim2The number of columns in the matrix.
Returns
  • Returns a pointer to the allocated two-dimensional matrix on success.
  • Returns NULL if memory allocation fails.
Note
  • The function uses calloc to ensure that all elements are zero-initialized.
  • The caller is responsible for freeing the allocated memory using SDDS_FreeMatrix.
See also
SDDS_FreeMatrix
calloc

Definition at line 2739 of file SDDS_utils.c.

2739 {
2740 int64_t i;
2741 void **data;
2742
2743 if (!(data = (void **)SDDS_Malloc(sizeof(*data) * dim1)))
2744 return (NULL);
2745 for (i = 0; i < dim1; i++)
2746 if (!(data[i] = (void *)calloc(dim2, size)))
2747 return (NULL);
2748 return (data);
2749}
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
Definition SDDS_utils.c:639

◆ SDDS_AppendLayout()

epicsShareFuncSDDS int32_t SDDS_AppendLayout ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
uint32_t mode )
extern

Appends layout definitions (columns, parameters, associates, arrays) from one SDDS_DATASET to another. Only definitions that do not already exist in the target dataset are added.

Parameters
SDDS_targetAddress of the SDDS_DATASET structure to which layout definitions will be appended.
SDDS_sourceAddress of the SDDS_DATASET structure from which layout definitions will be taken.
modeMode flag (currently unused; can be set to 0).
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 158 of file SDDS_copy.c.

158 {
159 SDDS_LAYOUT *source;
160 int64_t i;
161
162 if (!SDDS_CheckDataset(SDDS_target, "SDDS_AppendLayout"))
163 return (0);
164 if (!SDDS_CheckDataset(SDDS_source, "SDDS_AppendLayout"))
165 return (0);
166 source = &SDDS_source->layout;
167 SDDS_DeferSavingLayout(SDDS_target, 1);
168
169 for (i = 0; i < source->n_columns; i++)
170 if (SDDS_GetColumnIndex(SDDS_target, source->column_definition[i].name) < 0 &&
171 SDDS_DefineColumn(SDDS_target, source->column_definition[i].name,
172 source->column_definition[i].symbol, source->column_definition[i].units, source->column_definition[i].description, source->column_definition[i].format_string, source->column_definition[i].type, source->column_definition[i].field_length) < 0) {
173 SDDS_DeferSavingLayout(SDDS_target, 0);
174 SDDS_SetError("Unable to define column (SDDS_AppendLayout)");
175 return (0);
176 }
177
178 for (i = 0; i < source->n_parameters; i++)
179 if (SDDS_GetParameterIndex(SDDS_target, source->parameter_definition[i].name) < 0 &&
180 SDDS_DefineParameter(SDDS_target, source->parameter_definition[i].name,
181 source->parameter_definition[i].symbol, source->parameter_definition[i].units, source->parameter_definition[i].description, source->parameter_definition[i].format_string, source->parameter_definition[i].type, source->parameter_definition[i].fixed_value) < 0) {
182 SDDS_DeferSavingLayout(SDDS_target, 0);
183 SDDS_SetError("Unable to define parameter (SDDS_AppendLayout)");
184 return (0);
185 }
186
187 for (i = 0; i < source->n_associates; i++)
188 if (SDDS_GetAssociateIndex(SDDS_target, source->associate_definition[i].name) < 0 &&
189 SDDS_DefineAssociate(SDDS_target, source->associate_definition[i].name, source->associate_definition[i].filename, source->associate_definition[i].path, source->associate_definition[i].description, source->associate_definition[i].contents, source->associate_definition[i].sdds) < 0) {
190 SDDS_DeferSavingLayout(SDDS_target, 0);
191 SDDS_SetError("Unable to define associate (SDDS_AppendLayout)");
192 return (0);
193 }
194
195 for (i = 0; i < source->n_arrays; i++)
196 if (SDDS_GetArrayIndex(SDDS_target, source->array_definition[i].name) < 0 &&
197 SDDS_DefineArray(SDDS_target, source->array_definition[i].name,
198 source->array_definition[i].symbol,
199 source->array_definition[i].units, source->array_definition[i].description,
200 source->array_definition[i].format_string, source->array_definition[i].type, source->array_definition[i].field_length, source->array_definition[i].dimensions, source->array_definition[i].group_name) < 0) {
201 SDDS_DeferSavingLayout(SDDS_target, 0);
202 SDDS_SetError("Unable to define array (SDDS_AppendLayout)");
203 return (0);
204 }
205 SDDS_DeferSavingLayout(SDDS_target, 0);
206 if (!SDDS_SaveLayout(SDDS_target)) {
207 SDDS_SetError("Unable to save layout (SDDS_AppendLayout)");
208 return (0);
209 }
210 return (1);
211}
void SDDS_DeferSavingLayout(SDDS_DATASET *SDDS_dataset, int32_t mode)
Definition SDDS_copy.c:603
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
Definition SDDS_copy.c:615
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_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_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.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552
int32_t SDDS_GetAssociateIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named associate in the SDDS dataset.

◆ SDDS_AppendToArrayVararg()

epicsShareFuncSDDS int32_t SDDS_AppendToArrayVararg ( SDDS_DATASET * SDDS_dataset,
char * array_name,
int32_t mode,
void * data_pointer,
int32_t elements,
... )
extern

Appends data to an existing array variable in the SDDS dataset using variable arguments for dimensions.

This function appends additional data to a specified array within the current SDDS dataset. The elements parameter specifies the number of new elements to append. The mode parameter controls how the data is interpreted and stored. The dimensions of the array are provided as variable arguments, allowing for flexible handling of multi-dimensional arrays.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
array_nameThe name of the array to append data to within the dataset.
modeBitwise flags that determine how the array is set. Valid flags include:
  • SDDS_POINTER_ARRAY: Indicates that the array is a pointer array.
  • SDDS_CONTIGUOUS_DATA: Indicates that the data is contiguous in memory.
data_pointerPointer to the data to be appended to the array. The data must match the type defined for the array.
elementsThe number of elements to append to the array.
...Variable arguments specifying the dimensions of the array. The number of dimensions should match the array definition.
Returns
Returns 1 on successful appending of the array data. On failure, returns 0 and records an appropriate error message.
See also
SDDS_Realloc, SDDS_CopyStringArray, SDDS_SetError, SDDS_GetArrayIndex

Definition at line 1392 of file SDDS_dataprep.c.

1392 {
1393 va_list argptr;
1394 int32_t index, retval, size, startIndex = 0;
1395 SDDS_LAYOUT *layout;
1396 SDDS_ARRAY *array;
1397
1398 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_AppendToArrayVararg"))
1399 return (0);
1400 if (!(mode & SDDS_POINTER_ARRAY) && !(mode & SDDS_CONTIGUOUS_DATA)) {
1401 SDDS_SetError("Unable to set array--invalid mode (SDDS_AppendToArrayVararg)");
1402 return (0);
1403 }
1404 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
1405 SDDS_SetError("Unable to set array--unknown array name given (SDDS_AppendToArrayVararg)");
1406 return (0);
1407 }
1408 if (!data_pointer) {
1409 SDDS_SetError("Unable to set array--data pointer is NULL (SDDS_AppendToArrayVararg)");
1410 return (0);
1411 }
1412 if (!SDDS_dataset->array) {
1413 SDDS_SetError("Unable to set array--internal array pointer is NULL (SDDS_AppendToArrayVararg)");
1414 return (0);
1415 }
1416
1417 layout = &SDDS_dataset->layout;
1418 array = SDDS_dataset->array + index;
1419 if (!layout->array_definition) {
1420 SDDS_SetError("Unable to set array--internal array definition pointer is NULL (SDDS_AppendToArrayVararg)");
1421 return (0);
1422 }
1423 array->definition = layout->array_definition + index;
1424 if (!array->dimension && !(array->dimension = (int32_t *)SDDS_Malloc(sizeof(*array->dimension) * array->definition->dimensions))) {
1425 SDDS_SetError("Unable to set array--allocation failure (SDDS_SetArrayVararg)");
1426 return (0);
1427 }
1428 if (!(array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA)) {
1429 SDDS_SetError("Unable to set array--append operation requires contiguous data (SDDS_AppendToArrayVararg)");
1430 return (0);
1431 }
1432
1433 va_start(argptr, elements);
1434
1435 /* variable arguments are dimensions */
1436 retval = 1;
1437 index = 0;
1438 array->elements = 1;
1439 do {
1440 if ((array->dimension[index] = va_arg(argptr, int32_t)) < 0) {
1441 SDDS_SetError("Unable to set array--negative dimension given (SDDS_AppendToArrayVararg)");
1442 retval = 0;
1443 break;
1444 }
1445 array->elements *= array->dimension[index];
1446 } while (retval == 1 && ++index < array->definition->dimensions);
1447 va_end(argptr);
1448
1449 if (!retval)
1450 return (0);
1451 if (!array->elements)
1452 return (1);
1453
1454 size = SDDS_type_size[array->definition->type - 1];
1455 if (!(array->data = SDDS_Realloc(array->data, size * array->elements))) {
1456 SDDS_SetError("Unable to set array--allocation failure (SDDS_AppendToArrayVararg)");
1457 return (0);
1458 }
1459
1460 startIndex = array->elements - elements;
1461
1462 /* handle 1-d arrays and contiguous data as a special case */
1463 if (array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA) {
1464 if (array->definition->type != SDDS_STRING)
1465 memcpy((char *)array->data + size * startIndex, data_pointer, size * elements);
1466 else if (!SDDS_CopyStringArray(((char **)array->data) + startIndex, data_pointer, elements)) {
1467 SDDS_SetError("Unable to set array--string copy failure (SDDS_AppendToArrayVararg)");
1468 return (0);
1469 }
1470 return (1);
1471 }
1472
1473 return (1);
1474}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85

◆ SDDS_ApplyFactorToColumn()

epicsShareFuncSDDS int32_t SDDS_ApplyFactorToColumn ( SDDS_DATASET * SDDS_dataset,
char * name,
double factor )
extern

Applies a scaling factor to all elements of a specific column in the SDDS dataset.

This function multiplies each value in the specified column by the given factor. It first retrieves the column's index and verifies that it is of a numeric type. The scaling operation is performed in-place on each element of the column's data array.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the column to scale.
[in]factorThe scaling factor to apply to each element of the column.
Returns
  • Returns 1 on successful application of the factor to all elements.
  • Returns 0 if the column is not found, is non-numeric, or if the dataset lacks the necessary data array.
Note
  • The function modifies each element of the column's data array directly within the dataset.
  • It supports various numeric SDDS data types.
See also
SDDS_GetColumnIndex
SDDS_NUMERIC_TYPE
SDDS_SetError

Definition at line 3123 of file SDDS_utils.c.

3123 {
3124 int32_t type, index;
3125 int64_t i;
3126 void *data;
3127
3128 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0)
3129 return (0);
3130 type = SDDS_dataset->layout.column_definition[index].type;
3131 if (!SDDS_NUMERIC_TYPE(type)) {
3132 SDDS_SetError("Unable to apply factor to non-numeric column (SDDS_ApplyFactorToColumn)");
3133 return (0);
3134 }
3135 data = SDDS_dataset->data[index];
3136 for (i = 0; i < SDDS_dataset->n_rows; i++) {
3137 switch (type) {
3138 case SDDS_SHORT:
3139 *((short *)data + i) *= factor;
3140 break;
3141 case SDDS_USHORT:
3142 *((unsigned short *)data + i) *= factor;
3143 break;
3144 case SDDS_LONG:
3145 *((int32_t *)data + i) *= factor;
3146 break;
3147 case SDDS_ULONG:
3148 *((uint32_t *)data + i) *= factor;
3149 break;
3150 case SDDS_LONG64:
3151 *((int64_t *)data + i) *= factor;
3152 break;
3153 case SDDS_ULONG64:
3154 *((uint64_t *)data + i) *= factor;
3155 break;
3156 case SDDS_CHARACTER:
3157 *((char *)data + i) *= factor;
3158 break;
3159 case SDDS_FLOAT:
3160 *((float *)data + i) *= factor;
3161 break;
3162 case SDDS_DOUBLE:
3163 *((double *)data + i) *= factor;
3164 break;
3165 case SDDS_LONGDOUBLE:
3166 *((long double *)data + i) *= factor;
3167 break;
3168 default:
3169 return (0);
3170 }
3171 }
3172 return (1);
3173}
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
Definition SDDStypes.h:67
#define SDDS_FLOAT
Identifier for the float data type.
Definition SDDStypes.h:43
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
Definition SDDStypes.h:55
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
#define SDDS_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
Definition SDDStypes.h:79
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
Definition SDDStypes.h:138
#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_ApplyFactorToParameter()

epicsShareFuncSDDS int32_t SDDS_ApplyFactorToParameter ( SDDS_DATASET * SDDS_dataset,
char * name,
double factor )
extern

Applies a scaling factor to a specific parameter in the SDDS dataset.

This function multiplies the value of a specified parameter by the given factor. It first retrieves the parameter's index and verifies that it is of a numeric type. The scaling operation is performed in-place on the parameter's data.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the parameter to scale.
[in]factorThe scaling factor to apply to the parameter's value.
Returns
  • Returns 1 on successful application of the factor.
  • Returns 0 if the parameter is not found, is non-numeric, or if the dataset lacks the necessary data array.
Note
  • The function modifies the parameter's value directly within the dataset.
  • It supports various numeric SDDS data types.
See also
SDDS_GetParameterIndex
SDDS_NUMERIC_TYPE
SDDS_SetError

Definition at line 3046 of file SDDS_utils.c.

3046 {
3047 int32_t type, index;
3048 void *data;
3049
3050 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) < 0)
3051 return (0);
3052 type = SDDS_dataset->layout.parameter_definition[index].type;
3053 if (!SDDS_NUMERIC_TYPE(type)) {
3054 SDDS_SetError("Unable to apply factor to non-numeric parameter (SDDS_ApplyFactorToParameter)");
3055 return (0);
3056 }
3057 if (!SDDS_dataset->parameter) {
3058 SDDS_SetError("Unable to apply factor to parameter--no parameter data array (SDDS_ApplyFactorToParameter)");
3059 return (0);
3060 }
3061 if (!(data = SDDS_dataset->parameter[index])) {
3062 SDDS_SetError("Unable to apply factor to parameter--no data array (SDDS_ApplyFactorToParameter)");
3063 return (0);
3064 }
3065 switch (type) {
3066 case SDDS_SHORT:
3067 *((short *)data) *= factor;
3068 break;
3069 case SDDS_USHORT:
3070 *((unsigned short *)data) *= factor;
3071 break;
3072 case SDDS_LONG:
3073 *((int32_t *)data) *= factor;
3074 break;
3075 case SDDS_ULONG:
3076 *((uint32_t *)data) *= factor;
3077 break;
3078 case SDDS_LONG64:
3079 *((int64_t *)data) *= factor;
3080 break;
3081 case SDDS_ULONG64:
3082 *((uint64_t *)data) *= factor;
3083 break;
3084 case SDDS_CHARACTER:
3085 *((char *)data) *= factor;
3086 break;
3087 case SDDS_FLOAT:
3088 *((float *)data) *= factor;
3089 break;
3090 case SDDS_DOUBLE:
3091 *((double *)data) *= factor;
3092 break;
3093 case SDDS_LONGDOUBLE:
3094 *((long double *)data) *= factor;
3095 break;
3096 default:
3097 return (0);
3098 }
3099 return (1);
3100}

◆ SDDS_ArrayCount()

epicsShareFuncSDDS int32_t SDDS_ArrayCount ( SDDS_DATASET * page)
extern

Retrieves the number of arrays in the SDDS dataset.

This function returns the total count of arrays defined in the layout of the provided SDDS dataset.

Parameters
[in]pagePointer to the SDDS_DATASET structure representing the dataset.
Returns
  • The number of arrays (int32_t) in the dataset.
  • 0 if the provided dataset pointer is NULL.
Note
  • Ensure that the dataset is properly initialized before calling this function.
See also
SDDS_GetArrayIndex, SDDS_CheckArray

Definition at line 5053 of file SDDS_utils.c.

5053 {
5054 if (!page)
5055 return 0;
5056 return page->layout.n_arrays;
5057}

◆ SDDS_AssertColumnFlags()

epicsShareFuncSDDS int32_t SDDS_AssertColumnFlags ( SDDS_DATASET * SDDS_dataset,
uint32_t mode,
... )
extern

Sets acceptance flags for columns based on specified criteria.

This function allows setting column flags in two modes:

  • SDDS_FLAG_ARRAY: Sets flags based on an array of flag values.
  • SDDS_INDEX_LIMITS: Sets flags for a range of columns to a specific value.

A non-zero flag indicates that a column is "of interest", while a zero flag marks it for rejection.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeOperation mode determining how flags are set. Possible values:
  • SDDS_FLAG_ARRAY: c SDDS_AssertColumnFlags(SDDS_DATASET *SDDS_dataset, SDDS_FLAG_ARRAY, int32_t *flagArray, int32_t columnsInArray);
  • SDDS_INDEX_LIMITS: c SDDS_AssertColumnFlags(SDDS_DATASET *SDDS_dataset, SDDS_INDEX_LIMITS, int32_t start, int32_t end, int32_t value);
...Variable arguments based on the selected mode:
  • SDDS_FLAG_ARRAY:
    • int32_t *flagArray: Array of flag values to assign.
    • int32_t columnsInArray: Number of columns in flagArray.
  • SDDS_INDEX_LIMITS:
    • int32_t start: Starting column index (inclusive).
    • int32_t end: Ending column index (inclusive).
    • int32_t value: Flag value to assign to the specified range.
Returns
  • 1 on successful assignment of column flags.
  • 0 on failure, with an error message recorded (e.g., invalid parameters, memory issues).
Note
  • For SDDS_FLAG_ARRAY, if columnsInArray exceeds the number of allocated columns, it is truncated to fit.
  • For SDDS_INDEX_LIMITS, if end exceeds the number of columns, it is adjusted to the last valid column index.
See also
SDDS_SetColumnFlags, SDDS_GetColumnFlags, SDDS_GetColumnFlag

Definition at line 273 of file SDDS_extract.c.

273 {
274 int64_t i, j;
275 int32_t columns, startColumn, endColumn;
276 va_list argptr;
277 int32_t retval;
278 int32_t *flagArray, flagValue;
279
280 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_AssertColumnFlags"))
281 return (0);
282 if ((!SDDS_dataset->column_flag || !SDDS_dataset->column_order) && !SDDS_AllocateColumnFlags(SDDS_dataset))
283 return 0;
284
285 va_start(argptr, mode);
286 retval = 0;
287 switch (mode) {
288 case SDDS_FLAG_ARRAY:
289 if (!(flagArray = va_arg(argptr, int32_t *)))
290 SDDS_SetError("NULL flag array pointer seen (SDDS_AssertColumnFlags)");
291 else if ((columns = va_arg(argptr, int32_t)) < 0)
292 SDDS_SetError("invalid column count seen (SDDS_AssertColumnFlags)");
293 else {
294 if (columns >= SDDS_dataset->layout.n_columns)
295 columns = SDDS_dataset->layout.n_columns - 1;
296 for (i = 0; i < columns; i++)
297 SDDS_dataset->column_flag[i] = flagArray[i];
298 retval = 1;
299 }
300 break;
301 case SDDS_INDEX_LIMITS:
302 if ((startColumn = va_arg(argptr, int32_t)) < 0 || (endColumn = va_arg(argptr, int32_t)) < startColumn)
303 SDDS_SetError("invalid start and end column values (SDDS_AssertColumnFlags)");
304 else {
305 flagValue = va_arg(argptr, int32_t);
306 if (endColumn >= SDDS_dataset->layout.n_columns || endColumn < 0)
307 endColumn = SDDS_dataset->layout.n_columns - 1;
308 for (i = startColumn; i <= endColumn; i++)
309 SDDS_dataset->column_flag[i] = flagValue;
310 retval = 1;
311 }
312 break;
313 default:
314 SDDS_SetError("unknown mode passed (SDDS_AssertColumnFlags)");
315 break;
316 }
317 va_end(argptr);
318
319 for (i = j = 0; i < SDDS_dataset->layout.n_columns; i++) {
320 if (SDDS_dataset->column_flag[i])
321 SDDS_dataset->column_order[j++] = i;
322 }
323
324 SDDS_dataset->n_of_interest = j;
325
326 return retval;
327}
int32_t SDDS_AllocateColumnFlags(SDDS_DATASET *SDDS_target)

◆ SDDS_AssertRowFlags()

epicsShareFuncSDDS int32_t SDDS_AssertRowFlags ( SDDS_DATASET * SDDS_dataset,
uint32_t mode,
... )
extern

Sets acceptance flags for rows based on specified criteria.

This function allows setting row flags in two modes:

  • SDDS_FLAG_ARRAY: Sets flags based on an array of flag values.
  • SDDS_INDEX_LIMITS: Sets flags for a range of rows to a specific value.

A non-zero flag indicates that a row is "of interest", while a zero flag marks it for rejection.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeOperation mode determining how flags are set. Possible values:
  • SDDS_FLAG_ARRAY: c SDDS_AssertRowFlags(SDDS_DATASET *SDDS_dataset, SDDS_FLAG_ARRAY, int32_t *flagArray, int64_t rowsInArray);
  • SDDS_INDEX_LIMITS: c SDDS_AssertRowFlags(SDDS_DATASET *SDDS_dataset, SDDS_INDEX_LIMITS, int64_t start, int64_t end, int32_t value);
...Variable arguments based on the selected mode:
  • SDDS_FLAG_ARRAY:
    • int32_t *flagArray: Array of flag values to assign.
    • int64_t rowsInArray: Number of rows in flagArray.
  • SDDS_INDEX_LIMITS:
    • int64_t start: Starting row index (inclusive).
    • int64_t end: Ending row index (inclusive).
    • int32_t value: Flag value to assign to the specified range.
Returns
  • 1 on successful assignment of row flags.
  • 0 on failure, with an error message recorded (e.g., invalid parameters, memory issues).
Note
  • For SDDS_FLAG_ARRAY, if rowsInArray exceeds the number of allocated rows, it is truncated to fit.
  • For SDDS_INDEX_LIMITS, if end exceeds the number of rows, it is adjusted to the last valid row index.
See also
SDDS_SetRowFlags, SDDS_GetRowFlags, SDDS_GetRowFlag

Definition at line 148 of file SDDS_extract.c.

154{
155 int64_t i, rows, startRow, endRow;
156 va_list argptr;
157 int32_t retval;
158 int32_t *flagArray, flagValue;
159 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_AssertRowFlags"))
160 return (0);
161
162 va_start(argptr, mode);
163 retval = 0;
164 switch (mode) {
165 case SDDS_FLAG_ARRAY:
166 if (!(flagArray = va_arg(argptr, int32_t *)))
167 SDDS_SetError("NULL flag array pointer seen (SDDS_AssertRowFlags)");
168 else if ((rows = va_arg(argptr, int64_t)) < 0)
169 SDDS_SetError("invalid row count seen (SDDS_AssertRowFlags)");
170 else {
171 if (rows >= SDDS_dataset->n_rows)
172 rows = SDDS_dataset->n_rows;
173 for (i = 0; i < rows; i++)
174 SDDS_dataset->row_flag[i] = flagArray[i];
175 retval = 1;
176 }
177 break;
178 case SDDS_INDEX_LIMITS:
179 if ((startRow = va_arg(argptr, int64_t)) < 0 || (endRow = va_arg(argptr, int64_t)) < startRow)
180 SDDS_SetError("invalid start and end row values (SDDS_AssertRowFlags)");
181 else {
182 flagValue = va_arg(argptr, int32_t);
183 if (endRow >= SDDS_dataset->n_rows || endRow < 0)
184 endRow = SDDS_dataset->n_rows - 1;
185 for (i = startRow; i <= endRow; i++)
186 SDDS_dataset->row_flag[i] = flagValue;
187 retval = 1;
188 }
189 break;
190 default:
191 SDDS_SetError("unknown mode passed (SDDS_AssertRowFlags)");
192 break;
193 }
194
195 va_end(argptr);
196 return retval;
197}

◆ SDDS_Bomb()

epicsShareFuncSDDS void SDDS_Bomb ( char * message)
extern

Terminates the program after printing an error message and recorded errors.

This function prints a termination message to stderr, invokes SDDS_PrintErrors to display all recorded errors, and then exits the program with a non-zero status.

Parameters
[in]messageThe termination message to be printed. If NULL, a default message "?" is used.
Note
This function does not return; it exits the program.
See also
SDDS_PrintErrors
SDDS_SetError

Definition at line 342 of file SDDS_utils.c.

342 {
343 if (registeredProgramName)
344 fprintf(stderr, "Error (%s): %s\n", registeredProgramName, message ? message : "?");
345 else
346 fprintf(stderr, "Error: %s\n", message ? message : "?");
347 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
348 exit(1);
349}

◆ SDDS_BreakIntoLockedFile()

epicsShareFuncSDDS int32_t SDDS_BreakIntoLockedFile ( char * filename)
extern

Attempts to override a locked file by creating a temporary copy.

This function tries to break into a locked file by creating a temporary backup and replacing the original file with this backup. The process involves:

  • Generating a temporary filename with a .blXXX suffix, where XXX ranges from 1000 to 1019.
  • Copying the original file to the temporary file while preserving file attributes.
  • Replacing the original file with the temporary copy.

On Windows systems (_WIN32 defined), the function currently does not support breaking into locked files and will output an error message.

Parameters
[in]filenameThe path to the locked file that needs to be overridden.
Returns
  • 0 on successful override of the locked file.
  • 1 if the operation fails or is not supported on the current platform.
Warning
  • The function limits the filename length to 500 characters to prevent buffer overflows.
  • Ensure that the necessary permissions are available to create and modify files in the target directory.
Note
  • This function relies on the availability of the cp and mv system commands on Unix-like systems.
  • The function attempts up to 20 different temporary filenames before failing.
See also
SDDS_FileIsLocked, SDDS_LockFile

Definition at line 3372 of file SDDS_utils.c.

3372 {
3373#if defined(_WIN32)
3374 fprintf(stderr, "Unable to break into locked file\n");
3375 return (1);
3376#else
3377 char buffer[1024];
3378 int i = 1000, j = 0;
3379 FILE *fp;
3380
3381 /* limit filename length to 500 so we don't overflow the buffer variable */
3382 if (strlen(filename) > 500) {
3383 fprintf(stderr, "Unable to break into locked file\n");
3384 return (1);
3385 }
3386
3387 /* find a temporary file name that is not already in use */
3388 for (i = 1000; i < 1020; i++) {
3389 sprintf(buffer, "%s.bl%d", filename, i);
3390 if ((fp = fopen(buffer, "r"))) {
3391 fclose(fp);
3392 } else {
3393 j = i;
3394 break;
3395 }
3396 }
3397
3398 /* if no temporary file names could be found then return with an error message */
3399 if (j == 0) {
3400 fprintf(stderr, "Unable to break into locked file\n");
3401 return (1);
3402 }
3403
3404 /* copy the original file to the temp file name and preserve the attributes */
3405 /* the temp file name has to be in the same directory to preserve ACL settings */
3406 sprintf(buffer, "cp -p %s %s.bl%d", filename, filename, j);
3407 if (system(buffer) == -1) {
3408 fprintf(stderr, "Unable to break into locked file\n");
3409 return (1);
3410 }
3411
3412 /* move the temp file on top of the original file */
3413 sprintf(buffer, "mv -f %s.bl%d %s", filename, j, filename);
3414 if (system(buffer) == -1) {
3415 fprintf(stderr, "Unable to break into locked file\n");
3416 return (1);
3417 }
3418 return (0);
3419#endif
3420}

◆ SDDS_BufferedRead()

epicsShareFuncSDDS int32_t SDDS_BufferedRead ( void * target,
int64_t targetSize,
FILE * fp,
SDDS_FILEBUFFER * fBuffer,
int32_t type,
int32_t byteOrder )
extern

Reads data from a file into a buffer, optimizing performance with buffering.

This function reads targetSize bytes from the file fp into the memory pointed to by target. It uses the provided fBuffer to buffer file data, improving read performance. If the data type is SDDS_LONGDOUBLE and the long double precision is not 18 digits, it handles conversion to double precision if the environment variable SDDS_LONGDOUBLE_64BITS is not set.

If target is NULL, the function skips over targetSize bytes in the file.

Parameters
targetPointer to the memory location where the data will be stored. If NULL, the data is skipped.
targetSizeThe number of bytes to read from the file.
fpThe file pointer from which data is read.
fBufferPointer to an SDDS_FILEBUFFER structure used for buffering file data.
typeThe SDDS data type of the data being read (e.g., SDDS_LONGDOUBLE).
byteOrderThe byte order of the data (SDDS_LITTLEENDIAN or SDDS_BIGENDIAN).
Returns
Returns 1 on success; returns 0 on error.

Definition at line 96 of file SDDS_binary.c.

96 {
97 int float80tofloat64 = 0;
98 if ((LDBL_DIG != 18) && (type == SDDS_LONGDOUBLE)) {
99 if (getenv("SDDS_LONGDOUBLE_64BITS") == NULL) {
100 targetSize *= 2;
101 float80tofloat64 = 1;
102 }
103 }
104 if (!fBuffer->bufferSize) {
105 /* just read into users buffer or seek if no buffer given */
106 if (!target)
107 return !fseek(fp, (long)targetSize, SEEK_CUR);
108 else {
109 if (float80tofloat64) {
110 unsigned char x[16];
111 double d;
112 int64_t shift = 0;
113 while (shift < targetSize) {
114 if (fread(&x, (size_t)1, 16, fp) != 16)
115 return 0;
116 d = makeFloat64FromFloat80(x, byteOrder);
117 memcpy((char *)target + shift, &d, 8);
118 shift += 16;
119 }
120 return 1;
121 } else {
122 return fread(target, (size_t)1, (size_t)targetSize, fp) == targetSize;
123 }
124 }
125 }
126 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
127 /* sufficient data is already in the buffer */
128 if (target) {
129 if (float80tofloat64) {
130 unsigned char x[16];
131 double d;
132 int64_t shift = 0;
133 while (shift < targetSize) {
134 memcpy(x, (char *)fBuffer->data + shift, 16);
135 d = makeFloat64FromFloat80(x, byteOrder);
136 memcpy((char *)target + shift, &d, 8);
137 shift += 16;
138 }
139 } else {
140 memcpy((char *)target, (char *)fBuffer->data, targetSize);
141 }
142 }
143 fBuffer->data += targetSize;
144 return 1;
145 } else {
146 /* need to read additional data into buffer */
147 int64_t bytesNeeded, offset;
148 fBuffer->bytesLeft += targetSize; /* adds back amount subtracted above */
149
150 /* first, use the data that is already available. this cleans out the buffer */
151 if ((offset = fBuffer->bytesLeft)) {
152 /* some data is available in the buffer */
153 if (target) {
154 if (float80tofloat64) {
155 unsigned char x[16];
156 double d;
157 int64_t shift = 0;
158 while (shift < offset) {
159 memcpy(x, (char *)fBuffer->data + shift, 16);
160 d = makeFloat64FromFloat80(x, byteOrder);
161 memcpy((char *)target + shift, &d, 8);
162 shift += 16;
163 }
164 } else {
165 memcpy((char *)target, (char *)fBuffer->data, offset);
166 }
167 }
168 bytesNeeded = targetSize - offset;
169 fBuffer->bytesLeft = 0;
170 } else {
171 bytesNeeded = targetSize;
172 }
173 fBuffer->data = fBuffer->buffer;
174
175 if (fBuffer->bufferSize < bytesNeeded) {
176 /* just read what is needed directly into user's memory or seek */
177 if (!target)
178 return !fseek(fp, (long)bytesNeeded, SEEK_CUR);
179 else {
180 if (float80tofloat64) {
181 unsigned char x[16];
182 double d;
183 int64_t shift = 0;
184 while (shift < bytesNeeded) {
185 if (fread(&x, (size_t)1, 16, fp) != 16)
186 return 0;
187 d = makeFloat64FromFloat80(x, byteOrder);
188 memcpy((char *)target + offset + shift, &d, 8);
189 shift += 16;
190 }
191 return 1;
192 } else {
193 return fread((char *)target + offset, (size_t)1, (size_t)bytesNeeded, fp) == bytesNeeded;
194 }
195 }
196 }
197
198 /* fill the buffer */
199 if ((fBuffer->bytesLeft = fread(fBuffer->data, (size_t)1, (size_t)fBuffer->bufferSize, fp)) < bytesNeeded)
200 return 0;
201 if (target) {
202 if (float80tofloat64) {
203 unsigned char x[16];
204 double d;
205 int64_t shift = 0;
206 while (shift < bytesNeeded) {
207 memcpy(x, (char *)fBuffer->data + shift, 16);
208 d = makeFloat64FromFloat80(x, byteOrder);
209 memcpy((char *)target + offset + shift, &d, 8);
210 shift += 16;
211 }
212 } else {
213 memcpy((char *)target + offset, (char *)fBuffer->data, bytesNeeded);
214 }
215 }
216 fBuffer->data += bytesNeeded;
217 fBuffer->bytesLeft -= bytesNeeded;
218 return 1;
219 }
220}
double makeFloat64FromFloat80(unsigned char x[16], int32_t byteOrder)
Converts a 16-byte array representing a float80 value to a double.

◆ SDDS_BufferedWrite()

epicsShareFuncSDDS int32_t SDDS_BufferedWrite ( void * target,
int64_t targetSize,
FILE * fp,
SDDS_FILEBUFFER * fBuffer )
extern

Writes data to a file using a buffer to optimize performance.

This function writes targetSize bytes from the memory pointed to by target to the file fp. It uses the provided fBuffer to buffer file data, improving write performance. If the buffer is full, it flushes the buffer to the file before writing more data.

Parameters
targetPointer to the memory location of the data to write.
targetSizeThe number of bytes to write to the file.
fpThe file pointer to which data is written.
fBufferPointer to an SDDS_FILEBUFFER structure used for buffering file data.
Returns
Returns 1 on success; returns 0 on error.

Definition at line 484 of file SDDS_binary.c.

484 {
485 if (!fBuffer->bufferSize) {
486 return fwrite(target, (size_t)1, (size_t)targetSize, fp) == targetSize;
487 }
488 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
489 memcpy((char *)fBuffer->data, (char *)target, targetSize);
490 fBuffer->data += targetSize;
491#ifdef DEBUG
492 fprintf(stderr, "SDDS_BufferedWrite of %" PRId64 " bytes done in-memory, %" PRId64 " bytes left\n", targetSize, fBuffer->bytesLeft);
493#endif
494 return 1;
495 } else {
496 int64_t lastLeft;
497 /* add back what was subtracted in test above.
498 * lastLeft is the number of bytes left in the buffer before doing anything
499 * and also the number of bytes from the users data that get copied into the buffer.
500 */
501 lastLeft = (fBuffer->bytesLeft += targetSize);
502 /* copy part of the data into the buffer and write the buffer out */
503 memcpy((char *)fBuffer->data, (char *)target, (size_t)fBuffer->bytesLeft);
504 if (fwrite(fBuffer->buffer, (size_t)1, (size_t)fBuffer->bufferSize, fp) != fBuffer->bufferSize)
505 return 0;
506 if (fflush(fp)) {
507 SDDS_SetError("Problem flushing file (SDDS_BufferedWrite)");
508 SDDS_SetError(strerror(errno));
509 return 0;
510 }
511 /* reset the data pointer and the bytesLeft value.
512 * also, determine if the remaining data is too large for the buffer.
513 * if so, just write it out.
514 */
515 fBuffer->data = fBuffer->buffer;
516 if ((targetSize -= lastLeft) > (fBuffer->bytesLeft = fBuffer->bufferSize)) {
517 return fwrite((char *)target + lastLeft, (size_t)1, (size_t)targetSize, fp) == targetSize;
518 }
519 /* copy remaining data into the buffer.
520 * could do this with a recursive call, but this is more efficient.
521 */
522 memcpy((char *)fBuffer->data, (char *)target + lastLeft, targetSize);
523 fBuffer->data += targetSize;
524 fBuffer->bytesLeft -= targetSize;
525 return 1;
526 }
527}

◆ SDDS_Calloc()

epicsShareFuncSDDS void * SDDS_Calloc ( size_t nelem,
size_t elem_size )
extern

Allocates zero-initialized memory for an array of elements.

This function is a wrapper around the standard calloc function, used by SDDS routines to allocate memory. It ensures that even if the requested number of elements or element size is zero or negative, a minimum of 1 element with a size of 4 bytes is allocated.

Parameters
[in]nelemNumber of elements to allocate.
[in]elem_sizeSize in bytes of each element.
Returns
Pointer to the allocated memory. If allocation fails, returns NULL.
Note
If nelem or elem_size is less than or equal to zero, the function allocates memory for one element of 4 bytes by default.
See also
SDDS_Malloc
SDDS_Free

Definition at line 617 of file SDDS_utils.c.

617 {
618 if (elem_size <= 0)
619 elem_size = 4;
620 if (nelem <= 0)
621 nelem = 1;
622 return calloc(nelem, elem_size);
623}

◆ SDDS_CastValue()

epicsShareFuncSDDS void * SDDS_CastValue ( void * data,
int64_t index,
int32_t data_type,
int32_t desired_type,
void * memory )
extern

Casts a value from one SDDS data type to another.

This function converts a value from its original SDDS data type (data_type) to a desired SDDS data type (desired_type). It retrieves the value at the specified index from the data array and stores the converted value in the provided memory location.

Parameters
[in]dataPointer to the data array containing the original values.
[in]indexThe zero-based index of the value to be casted within the data array.
[in]data_typeThe original SDDS data type of the value. Must be one of the SDDS type constants:
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_LONG64
  • SDDS_ULONG64
  • SDDS_CHARACTER
  • SDDS_FLOAT
  • SDDS_DOUBLE
  • SDDS_LONGDOUBLE
[in]desired_typeThe desired SDDS data type to which the value should be casted. Must be one of the SDDS type constants listed above.
[out]memoryPointer to the memory location where the casted value will be stored.
Returns
  • Returns a pointer to the memory location containing the casted value on success.
  • Returns NULL if the casting fails due to invalid data types or other errors.
Note
  • The function does not handle casting for SDDS_STRING types.
  • The caller must ensure that the memory location has sufficient space to store the casted value.
See also
SDDS_CopyString
SDDS_SetError

Definition at line 2628 of file SDDS_utils.c.

2628 {
2629 long long integer_value;
2630 long double fp_value;
2631 if (!data || !memory || data_type == SDDS_STRING || desired_type == SDDS_STRING)
2632 return (NULL);
2633 if (data_type == desired_type) {
2634 memcpy(memory, (char *)data + SDDS_type_size[data_type - 1] * index, SDDS_type_size[data_type - 1]);
2635 return (memory);
2636 }
2637 switch (data_type) {
2638 case SDDS_SHORT:
2639 integer_value = *((short *)data + index);
2640 fp_value = integer_value;
2641 break;
2642 case SDDS_USHORT:
2643 integer_value = *((unsigned short *)data + index);
2644 fp_value = integer_value;
2645 break;
2646 case SDDS_LONG:
2647 integer_value = *((int32_t *)data + index);
2648 fp_value = integer_value;
2649 break;
2650 case SDDS_ULONG:
2651 integer_value = *((uint32_t *)data + index);
2652 fp_value = integer_value;
2653 break;
2654 case SDDS_LONG64:
2655 integer_value = *((int64_t *)data + index);
2656 fp_value = integer_value;
2657 break;
2658 case SDDS_ULONG64:
2659 integer_value = *((uint64_t *)data + index);
2660 fp_value = integer_value;
2661 break;
2662 case SDDS_CHARACTER:
2663 integer_value = *((unsigned char *)data + index);
2664 fp_value = integer_value;
2665 break;
2666 case SDDS_FLOAT:
2667 fp_value = *((float *)data + index);
2668 integer_value = fp_value;
2669 break;
2670 case SDDS_DOUBLE:
2671 fp_value = *((double *)data + index);
2672 integer_value = fp_value;
2673 break;
2674 case SDDS_LONGDOUBLE:
2675 fp_value = *((long double *)data + index);
2676 integer_value = fp_value;
2677 break;
2678 default:
2679 return (NULL);
2680 }
2681 switch (desired_type) {
2682 case SDDS_CHARACTER:
2683 *((char *)memory) = integer_value;
2684 break;
2685 case SDDS_SHORT:
2686 *((short *)memory) = integer_value;
2687 break;
2688 case SDDS_USHORT:
2689 *((unsigned short *)memory) = integer_value;
2690 break;
2691 case SDDS_LONG:
2692 *((int32_t *)memory) = integer_value;
2693 break;
2694 case SDDS_ULONG:
2695 *((uint32_t *)memory) = integer_value;
2696 break;
2697 case SDDS_LONG64:
2698 *((int64_t *)memory) = integer_value;
2699 break;
2700 case SDDS_ULONG64:
2701 *((uint64_t *)memory) = integer_value;
2702 break;
2703 case SDDS_FLOAT:
2704 *((float *)memory) = fp_value;
2705 break;
2706 case SDDS_DOUBLE:
2707 *((double *)memory) = fp_value;
2708 break;
2709 case SDDS_LONGDOUBLE:
2710 *((long double *)memory) = fp_value;
2711 break;
2712 default:
2713 SDDS_SetError("The impossible has happened (SDDS_CastValue)");
2714 return (NULL);
2715 }
2716 return (memory);
2717}

◆ SDDS_ChangeArrayInformation()

epicsShareFuncSDDS int32_t SDDS_ChangeArrayInformation ( SDDS_DATASET * SDDS_dataset,
char * field_name,
void * memory,
int32_t mode,
... )
extern

Modifies a specific field in an array definition within the SDDS dataset.

This function allows you to change a particular field of an array definition, identified either by its name or index. The new value for the field can be provided either as a direct value or as a string, depending on the field type.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]field_nameA null-terminated string specifying the name of the field to be modified.
[in]memoryPointer to the new value for the field. The type of this pointer should correspond to the data type of the field being modified:
  • For non-string fields, provide a pointer to the appropriate data type (e.g., int32_t*, double*).
  • For string fields, provide a char*.
[in]modeA bitwise combination of the following constants to specify how to identify the array and how to pass the new value:
  • SDDS_SET_BY_INDEX: Identify the array by its index. Requires an additional argument of type int32_t (array index).
  • SDDS_SET_BY_NAME: Identify the array by its name. Requires an additional argument of type char* (array name).
  • SDDS_PASS_BY_VALUE: The new value is provided as a direct value (non-string fields).
  • SDDS_PASS_BY_STRING: The new value is provided as a string (string fields).

The valid combinations of mode are:

Returns
On success, returns the SDDS data type of the modified information. On failure, returns zero and records an error message.
Note
This function uses variable arguments to accept either the array name or index based on the mode parameter.
See also
SDDS_GetArrayInformation

Definition at line 597 of file SDDS_info.c.

597 {
598 int32_t field_index, type, array_index, givenType;
599 ARRAY_DEFINITION *arraydef;
600 char *array_name;
601 va_list argptr;
602 int32_t retval;
603 double buffer[4];
604
605 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ChangeArrayInformation"))
606 return (0);
607
608 if (!field_name) {
609 SDDS_SetError("NULL field name passed. (SDDS_ChangeArrayInformation)");
610 return (0);
611 }
612
613 va_start(argptr, mode);
614 retval = 1;
615 if (mode & SDDS_SET_BY_INDEX) {
616 if ((array_index = va_arg(argptr, int32_t)) < 0 || array_index >= SDDS_dataset->layout.n_arrays) {
617 SDDS_SetError("Invalid array index passed. (SDDS_ChangeArrayInformation)");
618 retval = 0;
619 }
620 } else {
621 if (!(array_name = va_arg(argptr, char *))) {
622 SDDS_SetError("NULL array name passed. (SDDS_ChangeArrayInformation)");
623 retval = 0;
624 }
625 if ((array_index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
626 SDDS_SetError("Unknown array name given (SDDS_ChangeArrayInformation)");
627 retval = 0;
628 }
629 }
630 arraydef = SDDS_dataset->layout.array_definition + array_index;
631 va_end(argptr);
632 if (!retval)
633 return (0);
634
635 for (field_index = 0; field_index < SDDS_ARRAY_FIELDS; field_index++)
636 if (strcmp(field_name, SDDS_ArrayFieldInformation[field_index].name) == 0)
637 break;
638 if (field_index == SDDS_ARRAY_FIELDS) {
639 SDDS_SetError("Unknown field name given (SDDS_ChangeArrayInformation)");
640 return (0);
641 }
642 type = SDDS_ArrayFieldInformation[field_index].type;
643 if (!memory)
644 return (type);
645 if (type == SDDS_STRING) {
646 if (!SDDS_CopyString(((char **)((char *)arraydef + SDDS_ArrayFieldInformation[field_index].offset)), (char *)memory)) {
647 SDDS_SetError("Unable to copy field data (SDDS_ChangeArrayInformation)");
648 return (0);
649 }
650 if (strcmp(field_name, "name") == 0)
651 qsort((char *)SDDS_dataset->layout.array_index, SDDS_dataset->layout.n_arrays, sizeof(*SDDS_dataset->layout.array_index), SDDS_CompareIndexedNamesPtr);
652 } else {
653 if (mode & SDDS_PASS_BY_STRING) {
654 if (strcmp(field_name, "type") == 0 && (givenType = SDDS_IdentifyType((char *)memory)) > 0)
655 /* the type has been passed as a string (e.g., "double") */
656 memcpy((char *)buffer, (char *)&givenType, sizeof(givenType));
657 else if (!SDDS_ScanData((char *)memory, type, 0, (void *)buffer, 0, 0)) {
658 SDDS_SetError("Unable to scan string data (SDDS_ChangeArrayInformation)");
659 return (0);
660 }
661 memcpy((char *)arraydef + SDDS_ArrayFieldInformation[field_index].offset, (void *)buffer, SDDS_type_size[type - 1]);
662 } else
663 memcpy((char *)arraydef + SDDS_ArrayFieldInformation[field_index].offset, memory, SDDS_type_size[type - 1]);
664 }
665
666 return (type);
667}
int32_t SDDS_ScanData(char *string, int32_t type, int32_t field_length, void *data, int64_t index, int32_t is_parameter)
Scans a string and saves the parsed value into a data pointer according to the specified data type.
SDDS_FIELD_INFORMATION SDDS_ArrayFieldInformation[SDDS_ARRAY_FIELDS]
Field information for array definitions.
Definition SDDS_data.c:175
int SDDS_CompareIndexedNamesPtr(const void *s1, const void *s2)
Compares two pointers to SORTED_INDEX structures by their name fields.
int32_t SDDS_IdentifyType(char *typeName)
Identifies the SDDS data type based on its string name.

◆ SDDS_ChangeColumnInformation()

epicsShareFuncSDDS int32_t SDDS_ChangeColumnInformation ( SDDS_DATASET * SDDS_dataset,
char * field_name,
void * memory,
int32_t mode,
... )
extern

Modifies a specific field in a column definition within the SDDS dataset.

This function allows you to change a particular field of a column definition, identified either by its name or index. The new value for the field can be provided either as a direct value or as a string, depending on the field type.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]field_nameA null-terminated string specifying the name of the field to be modified.
[in]memoryPointer to the new value for the field. The type of this pointer should correspond to the data type of the field being modified:
  • For non-string fields, provide a pointer to the appropriate data type (e.g., int32_t*, double*).
  • For string fields, provide a char*.
[in]modeA bitwise combination of the following constants to specify how to identify the column and how to pass the new value:
  • SDDS_SET_BY_INDEX: Identify the column by its index. Requires an additional argument of type int32_t (column index).
  • SDDS_SET_BY_NAME: Identify the column by its name. Requires an additional argument of type char* (column name).
  • SDDS_PASS_BY_VALUE: The new value is provided as a direct value (non-string fields).
  • SDDS_PASS_BY_STRING: The new value is provided as a string (string fields).

The valid combinations of mode are:

Returns
On success, returns the SDDS data type of the modified information. On failure, returns zero and records an error message.
Note
This function uses variable arguments to accept either the column name or index based on the mode parameter.
See also
SDDS_GetColumnInformation

Definition at line 364 of file SDDS_info.c.

364 {
365 int32_t field_index, type, givenType;
366 int32_t i, column_index;
367 COLUMN_DEFINITION *columndef;
368 char *column_name;
369 va_list argptr;
370 int32_t retval;
371 double buffer[4];
372
373 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ChangeColumnInformation"))
374 return (0);
375
376 if (!field_name) {
377 SDDS_SetError("NULL field name passed. (SDDS_ChangeColumnInformation)");
378 return (0);
379 }
380
381 va_start(argptr, mode);
382 retval = 1;
383 if (mode & SDDS_SET_BY_INDEX) {
384 if ((column_index = va_arg(argptr, int32_t)) < 0 || column_index >= SDDS_dataset->layout.n_columns) {
385 SDDS_SetError("Invalid column index passed. (SDDS_ChangeColumnInformation)");
386 retval = 0;
387 }
388 } else {
389 if (!(column_name = va_arg(argptr, char *))) {
390 SDDS_SetError("NULL column name passed. (SDDS_ChangeColumnInformation)");
391 retval = 0;
392 }
393 if ((column_index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
394 SDDS_SetError("Unknown column name given (SDDS_ChangeColumnInformation)");
395 retval = 0;
396 }
397 }
398 columndef = SDDS_dataset->layout.column_definition + column_index;
399 va_end(argptr);
400 if (!retval)
401 return (0);
402
403 for (field_index = 0; field_index < SDDS_COLUMN_FIELDS; field_index++)
404 if (strcmp(field_name, SDDS_ColumnFieldInformation[field_index].name) == 0)
405 break;
406 if (field_index == SDDS_COLUMN_FIELDS) {
407 SDDS_SetError("Unknown field name given (SDDS_ChangeColumnInformation)");
408 return (0);
409 }
410 type = SDDS_ColumnFieldInformation[field_index].type;
411 if (!memory)
412 return (type);
413 if (type == SDDS_STRING) {
414 if (!SDDS_CopyString(((char **)((char *)columndef + SDDS_ColumnFieldInformation[field_index].offset)), (char *)memory)) {
415 SDDS_SetError("Unable to copy field data (SDDS_ChangeColumnInformation)");
416 return (0);
417 }
418 if (strcmp(field_name, "name") == 0) {
419 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
420 if (column_index == SDDS_dataset->layout.column_index[i]->index)
421 break;
422 if (i == SDDS_dataset->layout.n_columns) {
423 SDDS_SetError("Unable to copy field data--column indexing problem (SDDS_ChangeColumnInformation)");
424 return (0);
425 }
426 SDDS_dataset->layout.column_index[i]->name = SDDS_dataset->layout.column_definition[column_index].name;
427 qsort((char *)SDDS_dataset->layout.column_index, SDDS_dataset->layout.n_columns, sizeof(*SDDS_dataset->layout.column_index), SDDS_CompareIndexedNamesPtr);
428 }
429 } else {
430 if (mode & SDDS_PASS_BY_STRING) {
431 if (strcmp(field_name, "type") == 0 && (givenType = SDDS_IdentifyType((char *)memory)) > 0)
432 /* the type has been passed as a string (e.g., "double") */
433 memcpy((char *)buffer, (char *)&givenType, sizeof(givenType));
434 else if (!SDDS_ScanData((char *)memory, type, 0, (void *)buffer, 0, 0)) {
435 SDDS_SetError("Unable to scan string data (SDDS_ChangeColumnInformation)");
436 return (0);
437 }
438 memcpy((char *)columndef + SDDS_ColumnFieldInformation[field_index].offset, (void *)buffer, SDDS_type_size[type - 1]);
439 } else
440 memcpy((char *)columndef + SDDS_ColumnFieldInformation[field_index].offset, memory, SDDS_type_size[type - 1]);
441 }
442 return (type);
443}
SDDS_FIELD_INFORMATION SDDS_ColumnFieldInformation[SDDS_COLUMN_FIELDS]
Field information for column definitions.
Definition SDDS_data.c:193

◆ SDDS_ChangeParameterInformation()

epicsShareFuncSDDS int32_t SDDS_ChangeParameterInformation ( SDDS_DATASET * SDDS_dataset,
char * field_name,
void * memory,
int32_t mode,
... )
extern

Modifies a specific field in a parameter definition within the SDDS dataset.

This function allows you to change a particular field of a parameter definition, identified either by its name or index. The new value for the field can be provided either as a direct value or as a string, depending on the field type.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]field_nameA null-terminated string specifying the name of the field to be modified.
[in]memoryPointer to the new value for the field. The type of this pointer should correspond to the data type of the field being modified:
  • For non-string fields, provide a pointer to the appropriate data type (e.g., int32_t*, double*).
  • For string fields, provide a char*.
[in]modeA bitwise combination of the following constants to specify how to identify the parameter and how to pass the new value:
  • SDDS_SET_BY_INDEX: Identify the parameter by its index. Requires an additional argument of type int32_t (parameter index).
  • SDDS_SET_BY_NAME: Identify the parameter by its name. Requires an additional argument of type char* (parameter name).
  • SDDS_PASS_BY_VALUE: The new value is provided as a direct value (non-string fields).
  • SDDS_PASS_BY_STRING: The new value is provided as a string (string fields).

The valid combinations of mode are:

Returns
On success, returns the SDDS data type of the modified information. On failure, returns zero and records an error message.
Note
This function uses variable arguments to accept either the parameter name or index based on the mode parameter.
See also
SDDS_GetParameterInformation

Definition at line 485 of file SDDS_info.c.

485 {
486 int32_t field_index, type, parameter_index, givenType;
487 PARAMETER_DEFINITION *parameterdef;
488 char *parameter_name;
489 va_list argptr;
490 int32_t retval;
491 double buffer[4];
492
493 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ChangeParameterInformation"))
494 return (0);
495
496 if (!field_name) {
497 SDDS_SetError("NULL field name passed. (SDDS_ChangeParameterInformation)");
498 return (0);
499 }
500
501 va_start(argptr, mode);
502 retval = 1;
503 if (mode & SDDS_SET_BY_INDEX) {
504 if ((parameter_index = va_arg(argptr, int32_t)) < 0 || parameter_index >= SDDS_dataset->layout.n_parameters) {
505 SDDS_SetError("Invalid parameter index passed. (SDDS_ChangeParameterInformation)");
506 retval = 0;
507 }
508 } else {
509 if (!(parameter_name = va_arg(argptr, char *))) {
510 SDDS_SetError("NULL parameter name passed. (SDDS_ChangeParameterInformation)");
511 retval = 0;
512 }
513 if ((parameter_index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
514 SDDS_SetError("Unknown parameter name given (SDDS_ChangeParameterInformation)");
515 retval = 0;
516 }
517 }
518 parameterdef = SDDS_dataset->layout.parameter_definition + parameter_index;
519 va_end(argptr);
520 if (!retval)
521 return (0);
522
523 for (field_index = 0; field_index < SDDS_PARAMETER_FIELDS; field_index++)
524 if (strcmp(field_name, SDDS_ParameterFieldInformation[field_index].name) == 0)
525 break;
526 if (field_index == SDDS_PARAMETER_FIELDS) {
527 SDDS_SetError("Unknown field name given (SDDS_ChangeParameterInformation)");
528 return (0);
529 }
530 type = SDDS_ParameterFieldInformation[field_index].type;
531 if (!memory)
532 return (type);
533 if (type == SDDS_STRING) {
534 if (!SDDS_CopyString(((char **)((char *)parameterdef + SDDS_ParameterFieldInformation[field_index].offset)), (char *)memory)) {
535 SDDS_SetError("Unable to copy field data (SDDS_ChangeParameterInformation)");
536 return (0);
537 }
538 if (strcmp(field_name, "name") == 0)
539 qsort((char *)SDDS_dataset->layout.parameter_index, SDDS_dataset->layout.n_parameters, sizeof(*SDDS_dataset->layout.parameter_index), SDDS_CompareIndexedNamesPtr);
540 } else {
541 if (mode & SDDS_PASS_BY_STRING) {
542 if (strcmp(field_name, "type") == 0 && (givenType = SDDS_IdentifyType((char *)memory)) > 0)
543 /* the type has been passed as a string (e.g., "double") */
544 memcpy((char *)buffer, (char *)&givenType, sizeof(givenType));
545 else if (!SDDS_ScanData((char *)memory, type, 0, (void *)buffer, 0, 0)) {
546 SDDS_SetError("Unable to scan string data (SDDS_ChangeParameterInformation)");
547 return (0);
548 }
549 memcpy((char *)parameterdef + SDDS_ParameterFieldInformation[field_index].offset, (void *)buffer, SDDS_type_size[type - 1]);
550 } else
551 memcpy((char *)parameterdef + SDDS_ParameterFieldInformation[field_index].offset, memory, SDDS_type_size[type - 1]);
552 }
553
554 return (type);
555}
SDDS_FIELD_INFORMATION SDDS_ParameterFieldInformation[SDDS_PARAMETER_FIELDS]
Field information for parameter definitions.
Definition SDDS_data.c:209

◆ SDDS_CheckArray()

epicsShareFuncSDDS int32_t SDDS_CheckArray ( SDDS_DATASET * SDDS_dataset,
char * name,
char * units,
int32_t type,
FILE * fp_message )
extern

Checks if an array exists in the SDDS dataset with the specified name, units, and type.

This function verifies whether an array with the given name exists within the provided SDDS dataset. Additionally, it can check if the array's units and type match the specified criteria.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to be checked.
[in]nameThe name of the array to check.
[in]unitsThe units of the array. This parameter may be NULL if units are not to be validated.
[in]typeSpecifies the expected type of the array. Valid values are:
  • SDDS_ANY_NUMERIC_TYPE
  • SDDS_ANY_FLOATING_TYPE
  • SDDS_ANY_INTEGER_TYPE
  • 0 (if type is to be ignored)
[in]fp_messageFile pointer where error messages will be sent. Typically, this is stderr.
Returns
  • SDDS_CHECK_OKAY if the array exists and matches the specified criteria.
  • SDDS_CHECK_NONEXISTENT if the array does not exist.
  • SDDS_CHECK_WRONGTYPE if the array exists but does not match the specified type.
  • SDDS_CHECK_WRONGUNITS if the array exists but does not match the specified units.
Note
  • If units is NULL, the function does not perform units validation.
  • The function retrieves the array's units and type using SDDS_GetArrayInformation and SDDS_GetArrayType.
Warning
  • Ensure that the SDDS dataset is properly initialized and contains arrays before calling this function.
  • The function may set error messages using SDDS_SetError if it encounters issues accessing array information.
See also
SDDS_CheckColumn, SDDS_CheckParameter, SDDS_PrintCheckText, SDDS_SetError

Definition at line 4742 of file SDDS_utils.c.

4742 {
4743 char *units1;
4744 int32_t index;
4745 if ((index = SDDS_GetArrayIndex(SDDS_dataset, name)) < 0)
4746 return (SDDS_PrintCheckText(fp_message, name, units, type, "array", SDDS_CHECK_NONEXISTENT));
4747 if (SDDS_VALID_TYPE(type)) {
4748 if (type != SDDS_GetArrayType(SDDS_dataset, index))
4749 return (SDDS_PrintCheckText(fp_message, name, units, type, "array", SDDS_CHECK_WRONGTYPE));
4750 } else {
4751 switch (type) {
4752 case 0:
4753 break;
4755 if (!SDDS_NUMERIC_TYPE(SDDS_GetArrayType(SDDS_dataset, index)))
4756 return (SDDS_PrintCheckText(fp_message, name, units, type, "array", SDDS_CHECK_WRONGTYPE));
4757 break;
4759 if (!SDDS_FLOATING_TYPE(SDDS_GetArrayType(SDDS_dataset, index)))
4760 return (SDDS_PrintCheckText(fp_message, name, units, type, "array", SDDS_CHECK_WRONGTYPE));
4761 break;
4763 if (!SDDS_INTEGER_TYPE(SDDS_GetArrayType(SDDS_dataset, index)))
4764 return (SDDS_PrintCheckText(fp_message, name, units, type, "array", SDDS_CHECK_WRONGTYPE));
4765 break;
4766 default:
4767 return (SDDS_PrintCheckText(fp_message, name, units, type, "array", SDDS_CHECK_WRONGTYPE));
4768 }
4769 }
4770 if (SDDS_GetArrayInformation(SDDS_dataset, "units", &units1, SDDS_GET_BY_NAME, name) != SDDS_STRING) {
4771 SDDS_SetError("units field of array has wrong data type!");
4772 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4773 }
4774 if (!units) {
4775 /* don't care about units */
4776 return (SDDS_CHECK_OKAY);
4777 }
4778 if (!units1) {
4779 if (SDDS_StringIsBlank(units))
4780 return (SDDS_CHECK_OKAY);
4781 return (SDDS_CHECK_OKAY);
4782 }
4783 if (strcmp(units, units1) == 0) {
4784 free(units1);
4785 return (SDDS_CHECK_OKAY);
4786 }
4787 free(units1);
4788 return (SDDS_PrintCheckText(fp_message, name, units, type, "array", SDDS_CHECK_WRONGUNITS));
4789}
int32_t SDDS_GetArrayInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified array in the SDDS dataset.
Definition SDDS_info.c:192
int32_t SDDS_GetArrayType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of an array in the SDDS dataset by its index.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_PrintCheckText(FILE *fp, char *name, char *units, int32_t type, char *class_name, int32_t error_code)
Prints detailed error messages related to SDDS entity checks.
#define SDDS_INTEGER_TYPE(type)
Checks if the given type identifier corresponds to an integer type.
Definition SDDStypes.h:109
#define SDDS_VALID_TYPE(type)
Validates whether the given type identifier is within the defined range of SDDS types.
Definition SDDStypes.h:149
#define SDDS_FLOATING_TYPE(type)
Checks if the given type identifier corresponds to a floating-point type.
Definition SDDStypes.h:124
#define SDDS_ANY_FLOATING_TYPE
Special identifier used by SDDS_Check*() routines to accept any floating-point type.
Definition SDDStypes.h:165
#define SDDS_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric type.
Definition SDDStypes.h:157
#define SDDS_ANY_INTEGER_TYPE
Special identifier used by SDDS_Check*() routines to accept any integer type.
Definition SDDStypes.h:173

◆ SDDS_CheckColumn()

epicsShareFuncSDDS int32_t SDDS_CheckColumn ( SDDS_DATASET * SDDS_dataset,
char * name,
char * units,
int32_t type,
FILE * fp_message )
extern

Checks if a column exists in the SDDS dataset with the specified name, units, and type.

This function verifies whether a column with the given name exists in the SDDS dataset and optionally checks if its units and type match the specified criteria.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to be checked.
[in]nameThe name of the column to check.
[in]unitsThe units of the column. May be NULL if units are not to be checked.
[in]typeSpecifies the expected type of the column. Valid values are:
  • SDDS_ANY_NUMERIC_TYPE
  • SDDS_ANY_FLOATING_TYPE
  • SDDS_ANY_INTEGER_TYPE
  • 0 (if type is to be ignored)
[in]fp_messageFile pointer where error messages will be sent. Typically, this is stderr.
Returns
  • SDDS_CHECK_OKAY if the column exists and matches the specified criteria.
  • SDDS_CHECK_NONEXISTENT if the column does not exist.
  • SDDS_CHECK_WRONGTYPE if the column exists but does not match the specified type.
  • SDDS_CHECK_WRONGUNITS if the column exists but does not match the specified units.
Note
  • If units is NULL, the function does not check for units.
  • The function retrieves the column's units and type using SDDS_GetColumnInformation and SDDS_GetColumnType.
Warning
  • Ensure that the SDDS dataset is properly initialized and contains columns before calling this function.
  • The function may set error messages using SDDS_SetError if it encounters issues accessing column information.
See also
SDDS_CheckParameter, SDDS_GetColumnIndex, SDDS_SetError

Definition at line 4562 of file SDDS_utils.c.

4562 {
4563 char *units1;
4564 int32_t index;
4565 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0)
4566 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_NONEXISTENT));
4567 if (SDDS_VALID_TYPE(type)) {
4568 if (type != SDDS_GetColumnType(SDDS_dataset, index))
4569 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_WRONGTYPE));
4570 } else {
4571 switch (type) {
4572 case 0:
4573 break;
4575 if (!SDDS_NUMERIC_TYPE(SDDS_GetColumnType(SDDS_dataset, index)))
4576 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_WRONGTYPE));
4577 break;
4579 if (!SDDS_FLOATING_TYPE(SDDS_GetColumnType(SDDS_dataset, index))) {
4580 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_WRONGTYPE));
4581 }
4582 break;
4584 if (!SDDS_INTEGER_TYPE(SDDS_GetColumnType(SDDS_dataset, index))) {
4585 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_WRONGTYPE));
4586 }
4587 break;
4588 default:
4589 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_WRONGTYPE));
4590 }
4591 }
4592 if (!units) {
4593 /* don't care about units */
4594 return SDDS_CHECK_OKAY;
4595 }
4596 if (SDDS_GetColumnInformation(SDDS_dataset, "units", &units1, SDDS_GET_BY_NAME, name) != SDDS_STRING) {
4597 SDDS_SetError("units field of column has wrong data type!");
4598 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4599 }
4600 if (!units1) {
4601 if (SDDS_StringIsBlank(units))
4602 return (SDDS_CHECK_OKAY);
4603 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_WRONGUNITS));
4604 }
4605 if (strcmp(units, units1) == 0) {
4606 free(units1);
4607 return (SDDS_CHECK_OKAY);
4608 }
4609 free(units1);
4610 return (SDDS_PrintCheckText(fp_message, name, units, type, "column", SDDS_CHECK_WRONGUNITS));
4611}
int32_t SDDS_GetColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified column in the SDDS dataset.
Definition SDDS_info.c:41
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.

◆ SDDS_CheckDataset()

epicsShareFuncSDDS int32_t SDDS_CheckDataset ( SDDS_DATASET * SDDS_dataset,
const char * caller )
extern

Validates the SDDS dataset pointer.

This function checks whether the provided SDDS_DATASET pointer is valid (non-NULL). If the check fails, it records an appropriate error message.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure to be validated.
[in]callerName of the calling function, used for error reporting.
Returns
Returns 1 if the dataset pointer is valid; otherwise, returns 0 and records an error message.
See also
SDDS_SetError

Definition at line 552 of file SDDS_utils.c.

552 {
553 char buffer[100];
554 if (!SDDS_dataset) {
555 sprintf(buffer, "NULL SDDS_DATASET pointer passed to %s", caller);
556 SDDS_SetError(buffer);
557 return (0);
558 }
559 return (1);
560}

◆ SDDS_CheckDatasetStructureSize()

epicsShareFuncSDDS int32_t SDDS_CheckDatasetStructureSize ( int32_t size)
extern

Verifies that the size of the SDDS_DATASET structure matches the expected size.

This function ensures that the size of the SDDS_DATASET structure used by the program matches the size expected by the SDDS library. This check is crucial to prevent issues related to structure size mismatches, which can occur due to differences in compiler settings or library versions.

Parameters
[in]sizeThe size of the SDDS_DATASET structure as determined by the calling program (typically using sizeof(SDDS_DATASET)).
Returns
  • 1 if the provided size matches the expected size of the SDDS_DATASET structure.
  • 0 if there is a size mismatch, indicating potential incompatibility issues.
Note
  • This function should be called during initialization to ensure structural compatibility between the program and the SDDS library.
Warning
  • A size mismatch can lead to undefined behavior, including memory corruption and program crashes. Always ensure that both the program and the SDDS library are compiled with compatible settings.
See also
SDDS_DATASET, SDDS_SetError

Definition at line 4979 of file SDDS_utils.c.

4979 {
4980 char buffer[100];
4981 if (size != sizeof(SDDS_DATASET)) {
4982 SDDS_SetError("passed size is not equal to expected size for SDDS_DATASET structure");
4983 sprintf(buffer, "Passed size is %" PRId32 ", library size is %" PRId32 "\n", size, (int32_t)sizeof(SDDS_DATASET));
4984 SDDS_SetError(buffer);
4985 return 0;
4986 }
4987 return 1;
4988}

◆ SDDS_CheckEndOfFile()

epicsShareFuncSDDS int32_t SDDS_CheckEndOfFile ( SDDS_DATASET * SDDS_dataset)
extern

Checks if the end of the SDDS dataset file has been reached.

Parameters
SDDS_datasetThe SDDS dataset structure.
Returns
Returns 1 if the end of file has been reached, 0 if not, and 2 on error.

Definition at line 1020 of file SDDS_input.c.

1020 {
1021 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_EndOfFile"))
1022 return (0);
1023 if (SDDS_dataset->layout.disconnected) {
1024 SDDS_SetError("Can't check status--file is disconnected (SDDS_EndOfFile)");
1025 return 2;
1026 }
1027#if defined(zLib)
1028 if (SDDS_dataset->layout.gzipFile) {
1029 if (!SDDS_dataset->layout.gzfp) {
1030 SDDS_SetError("Unable to check status--NULL file pointer (SDDS_EndOfFile)");
1031 return 2;
1032 }
1033 } else {
1034#endif
1035 if (SDDS_dataset->layout.lzmaFile) {
1036 if (!SDDS_dataset->layout.lzmafp) {
1037 SDDS_SetError("Unable to check status--NULL file pointer (SDDS_EndOfFile)");
1038 return 2;
1039 }
1040 } else {
1041 if (!SDDS_dataset->layout.fp) {
1042 SDDS_SetError("Unable to check status--NULL file pointer (SDDS_EndOfFile)");
1043 return 2;
1044 }
1045 }
1046#if defined(zLib)
1047 }
1048#endif
1049 if (SDDS_dataset->fBuffer.bufferSize && SDDS_dataset->fBuffer.bytesLeft) {
1050 return 0;
1051 }
1052
1053#if defined(zLib)
1054 if (SDDS_dataset->layout.gzipFile) {
1055 if (gzeof(SDDS_dataset->layout.gzfp))
1056 return 1;
1057 } else {
1058#endif
1059 if (SDDS_dataset->layout.lzmaFile) {
1060 if (lzma_eof(SDDS_dataset->layout.lzmafp))
1061 return 1;
1062 } else {
1063 if (feof(SDDS_dataset->layout.fp))
1064 return 1;
1065 }
1066#if defined(zLib)
1067 }
1068#endif
1069 return 0;
1070}

◆ SDDS_CheckParameter()

epicsShareFuncSDDS int32_t SDDS_CheckParameter ( SDDS_DATASET * SDDS_dataset,
char * name,
char * units,
int32_t type,
FILE * fp_message )
extern

Checks if a parameter exists in the SDDS dataset with the specified name, units, and type.

This function verifies whether a parameter with the given name exists in the SDDS dataset and optionally checks if its units and type match the specified criteria.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to be checked.
[in]nameThe name of the parameter to check.
[in]unitsThe units of the parameter. May be NULL if units are not to be checked.
[in]typeSpecifies the expected type of the parameter. Valid values are:
  • SDDS_ANY_NUMERIC_TYPE
  • SDDS_ANY_FLOATING_TYPE
  • SDDS_ANY_INTEGER_TYPE
  • 0 (if type is to be ignored)
[in]fp_messageFile pointer where error messages will be sent. Typically, this is stderr.
Returns
  • SDDS_CHECK_OKAY if the parameter exists and matches the specified criteria.
  • SDDS_CHECK_NONEXISTENT if the parameter does not exist.
  • SDDS_CHECK_WRONGTYPE if the parameter exists but does not match the specified type.
  • SDDS_CHECK_WRONGUNITS if the parameter exists but does not match the specified units.
Note
  • If units is NULL, the function does not check for units.
  • The function retrieves the parameter's units and type using SDDS_GetParameterInformation and SDDS_GetParameterType.
Warning
  • Ensure that the SDDS dataset is properly initialized and contains parameters before calling this function.
  • The function may set error messages using SDDS_SetError if it encounters issues accessing parameter information.
See also
SDDS_CheckColumn, SDDS_GetParameterIndex, SDDS_SetError

Definition at line 4653 of file SDDS_utils.c.

4653 {
4654 char *units1;
4655 int32_t index;
4656 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) < 0)
4657 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_NONEXISTENT));
4658 if (SDDS_VALID_TYPE(type)) {
4659 if (type != SDDS_GetParameterType(SDDS_dataset, index))
4660 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_WRONGTYPE));
4661 } else {
4662 switch (type) {
4663 case 0:
4664 break;
4666 if (!SDDS_NUMERIC_TYPE(SDDS_GetParameterType(SDDS_dataset, index)))
4667 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_WRONGTYPE));
4668 break;
4670 if (!SDDS_FLOATING_TYPE(SDDS_GetParameterType(SDDS_dataset, index)))
4671 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_WRONGTYPE));
4672 break;
4674 if (!SDDS_INTEGER_TYPE(SDDS_GetParameterType(SDDS_dataset, index)))
4675 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_WRONGTYPE));
4676 break;
4677 default:
4678 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_WRONGTYPE));
4679 }
4680 }
4681 if (!units) {
4682 /* don't care about units */
4683 return (SDDS_CHECK_OKAY);
4684 }
4685 if (SDDS_GetParameterInformation(SDDS_dataset, "units", &units1, SDDS_GET_BY_NAME, name) != SDDS_STRING) {
4686 SDDS_SetError("units field of parameter has wrong data type!");
4687 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4688 }
4689 if (!units1) {
4690 if (SDDS_StringIsBlank(units))
4691 return (SDDS_CHECK_OKAY);
4692 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_WRONGUNITS));
4693 }
4694 if (strcmp(units, units1) == 0) {
4695 free(units1);
4696 return (SDDS_CHECK_OKAY);
4697 }
4698 free(units1);
4699 return (SDDS_PrintCheckText(fp_message, name, units, type, "parameter", SDDS_CHECK_WRONGUNITS));
4700}
int32_t SDDS_GetParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified parameter in the SDDS dataset.
Definition SDDS_info.c:117
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.

◆ SDDS_CheckTabularData()

epicsShareFuncSDDS int32_t SDDS_CheckTabularData ( SDDS_DATASET * SDDS_dataset,
const char * caller )
extern

Validates the consistency of tabular data within an SDDS dataset.

This function checks the integrity of tabular data in the given SDDS_DATASET. It verifies that if columns are defined, corresponding row flags and data arrays exist, and that the number of rows matches the column definitions.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure to be validated.
[in]callerName of the calling function, used for error reporting.
Returns
Returns 1 if the tabular data is consistent and valid; otherwise, returns 0 and records an error message.
Note
This function performs checks only if AutoCheckMode includes TABULAR_DATA_CHECKS.
See also
SDDS_SetAutoCheckMode
SDDS_SetError

Definition at line 577 of file SDDS_utils.c.

577 {
578 int64_t i;
579 char buffer[100];
580 if (!(AutoCheckMode & TABULAR_DATA_CHECKS))
581 return 1;
582 if (SDDS_dataset->layout.n_columns && (!SDDS_dataset->row_flag || !SDDS_dataset->data)) {
583 sprintf(buffer, "tabular data is invalid in %s (columns but no row flags or data array)", caller);
584 SDDS_SetError(buffer);
585 return (0);
586 }
587 if (SDDS_dataset->layout.n_columns == 0 && SDDS_dataset->n_rows) {
588 sprintf(buffer, "tabular data is invalid in %s (no columns present but nonzero row count)", caller);
589 SDDS_SetError(buffer);
590 return (0);
591 }
592 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
593 if (!SDDS_dataset->data[i]) {
594 sprintf(buffer, "tabular data is invalid in %s (null data pointer for column %" PRId64 ")", caller, i);
595 SDDS_SetError(buffer);
596 return (0);
597 }
598 }
599 return (1);
600}

◆ SDDS_ClearErrors()

epicsShareFuncSDDS void SDDS_ClearErrors ( void )
extern

Clears all recorded error messages from the SDDS error stack.

This function removes all error messages that have been recorded by SDDS library routines, resetting the error count to zero. It should be called after handling or logging the errors to prepare for future error recording.

Note
After calling this function, SDDS_NumberOfErrors will return zero until new errors are recorded.
See also
SDDS_SetError
SDDS_PrintErrors

Definition at line 318 of file SDDS_utils.c.

318 {
319 int32_t i;
320 for (i=0; i<n_errors; i++) {
321 free(error_description[i]);
322 error_description[i] = NULL;
323 }
324 free(error_description);
325 error_description = NULL;
326 n_errors = 0;
327 n_errors_max = 0;
328}

◆ SDDS_ClearPage()

epicsShareFuncSDDS int32_t SDDS_ClearPage ( SDDS_DATASET * SDDS_dataset)
extern

Clears the current page in the SDDS dataset, resetting all data and flags.

This function resets the current data page in the specified SDDS dataset by reinitializing column flags and order. It frees any allocated string data and zeros out the data arrays, parameters, and arrays in the dataset.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure whose current page will be cleared.
Returns
Returns 1 on successful clearing of the page. On failure, returns 0 and records an error message.
See also
SDDS_SetMemory, SDDS_FreeStringData, SDDS_ZeroMemory

Definition at line 188 of file SDDS_dataprep.c.

188 {
189 SDDS_LAYOUT *layout;
190 int64_t i;
191 int32_t size;
192
193 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ClearPage"))
194 return 0;
195 layout = &SDDS_dataset->layout;
196
197 if (layout->n_columns && ((SDDS_dataset->column_flag && !SDDS_SetMemory(SDDS_dataset->column_flag, layout->n_columns, SDDS_LONG, (int32_t)1, (int32_t)0)) ||
198 ((SDDS_dataset->column_order && !SDDS_SetMemory(SDDS_dataset->column_order, layout->n_columns, SDDS_LONG, (int32_t)0, (int32_t)1))))) {
199 SDDS_SetError("Unable to start page--memory initialization failure (SDDS_ClearPage)");
200 return 0;
201 }
202 SDDS_FreeStringData(SDDS_dataset);
203 if (SDDS_dataset->data) {
204 for (i = 0; i < layout->n_columns; i++) {
205 size = SDDS_type_size[layout->column_definition[i].type - 1];
206 if (SDDS_dataset->data[i])
207 SDDS_ZeroMemory(SDDS_dataset->data[i], size * SDDS_dataset->n_rows_allocated);
208 }
209 }
210 if (SDDS_dataset->parameter) {
211 for (i = 0; i < layout->n_parameters; i++) {
212 size = SDDS_type_size[layout->parameter_definition[i].type - 1];
213 SDDS_ZeroMemory(SDDS_dataset->parameter[i], size);
214 }
215 }
216 for (i = 0; i < layout->n_arrays; i++) {
217 size = SDDS_type_size[layout->array_definition[i].type - 1];
218 if (SDDS_dataset->array && SDDS_dataset->array[i].data && SDDS_dataset->array[i].elements)
219 SDDS_ZeroMemory(SDDS_dataset->array[i].data, size * SDDS_dataset->array[i].elements);
220 }
221 return 1;
222}
int32_t SDDS_FreeStringData(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.
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.

◆ SDDS_ColumnCount()

epicsShareFuncSDDS int32_t SDDS_ColumnCount ( SDDS_DATASET * page)
extern

Retrieves the number of columns in the SDDS dataset.

This function returns the total count of columns defined in the layout of the provided SDDS dataset.

Parameters
[in]pagePointer to the SDDS_DATASET structure representing the dataset.
Returns
  • The number of columns (int32_t) in the dataset.
  • 0 if the provided dataset pointer is NULL.
Note
  • Ensure that the dataset is properly initialized before calling this function.
See also
SDDS_GetColumnIndex, SDDS_CheckColumn

Definition at line 5007 of file SDDS_utils.c.

5007 {
5008 if (!page)
5009 return 0;
5010 return page->layout.n_columns;
5011}

◆ SDDS_ColumnIsOfInterest()

epicsShareFuncSDDS int32_t SDDS_ColumnIsOfInterest ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Determines if a specified column is marked as of interest in the dataset.

This function checks whether the column with the given name is flagged as of interest within the provided SDDS_dataset. It verifies the dataset's validity and then iterates through the columns to find a match based on the column_flag array.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA NULL-terminated string specifying the name of the column to check.
Returns
  • Returns 1 if the column is marked as of interest.
  • Returns 0 if the column is not marked as of interest or if column_flag is not set.
  • Returns -1 if the dataset is invalid.
See also
SDDS_CheckDataset

Definition at line 2428 of file SDDS_utils.c.

2428 {
2429 int64_t i;
2430 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ColumnIsOfInterest"))
2431 return -1;
2432 if (!SDDS_dataset->column_flag)
2433 return 0;
2434 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2435 if (SDDS_dataset->column_flag[i] && strcmp(name, SDDS_dataset->layout.column_definition[i].name) == 0)
2436 return 1;
2437 }
2438 return 0;
2439}

◆ SDDS_CompareIndexedNames()

int SDDS_CompareIndexedNames ( const void * s1,
const void * s2 )

Compares two SORTED_INDEX structures by their name fields.

This function is used as a comparison callback for sorting functions like qsort. It compares the name fields of two SORTED_INDEX structures lexicographically.

Parameters
[in]s1Pointer to the first SORTED_INDEX structure.
[in]s2Pointer to the second SORTED_INDEX structure.
Returns
An integer less than, equal to, or greater than zero if the name of s1 is found, respectively, to be less than, to match, or be greater than the name of s2.
See also
qsort
SORTED_INDEX

Definition at line 1272 of file SDDS_utils.c.

1272 {
1273 return strcmp(((SORTED_INDEX *)s1)->name, ((SORTED_INDEX *)s2)->name);
1274}

◆ SDDS_CompareIndexedNamesPtr()

int SDDS_CompareIndexedNamesPtr ( const void * s1,
const void * s2 )

Compares two pointers to SORTED_INDEX structures by their name fields.

This function is used as a comparison callback for sorting functions like qsort. It compares the name fields of two SORTED_INDEX structure pointers lexicographically.

Parameters
[in]s1Pointer to the first SORTED_INDEX* structure.
[in]s2Pointer to the second SORTED_INDEX* structure.
Returns
An integer less than, equal to, or greater than zero if the name of *s1 is found, respectively, to be less than, to match, or be greater than the name of *s2.
See also
qsort
SORTED_INDEX

Definition at line 1292 of file SDDS_utils.c.

1292 {
1293 return strcmp((*((SORTED_INDEX **)s1))->name, (*((SORTED_INDEX **)s2))->name);
1294}

◆ SDDS_ConvertToDouble()

epicsShareFuncSDDS double SDDS_ConvertToDouble ( int32_t type,
void * data,
int64_t index )
extern

Converts a value to double based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value, or 0.0 on error.

Definition at line 199 of file SDDS_rpn.c.

199 {
200 if (!data) {
201 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToDouble)");
202 return (0.0);
203 }
204 switch (type) {
205 case SDDS_SHORT:
206 return ((double)*((short *)data + index));
207 case SDDS_USHORT:
208 return ((double)*((unsigned short *)data + index));
209 case SDDS_LONG:
210 return ((double)*((int32_t *)data + index));
211 case SDDS_ULONG:
212 return ((double)*((uint32_t *)data + index));
213 case SDDS_LONG64:
214 return ((double)*((int64_t *)data + index));
215 case SDDS_ULONG64:
216 return ((double)*((uint64_t *)data + index));
217 case SDDS_FLOAT:
218 return ((double)*((float *)data + index));
219 case SDDS_DOUBLE:
220 return (*((double *)data + index));
221 case SDDS_LONGDOUBLE:
222 return ((double)*((long double *)data + index));
223 case SDDS_CHARACTER:
224 return ((double)*((unsigned char *)data + index));
225 default:
226 SDDS_SetError("Invalid data type seen (SDDS_ConvertToDouble)");
227 return (0.0);
228 }
229}

◆ SDDS_ConvertToLong()

epicsShareFuncSDDS int32_t SDDS_ConvertToLong ( int32_t type,
void * data,
int64_t index )
extern

Converts a value to a 32-bit integer based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted 32-bit integer, or 0 on error.

Definition at line 279 of file SDDS_rpn.c.

279 {
280 if (!data) {
281 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToLong)");
282 return (0.0);
283 }
284 switch (type) {
285 case SDDS_LONGDOUBLE:
286 return ((int32_t) * ((long double *)data + index));
287 case SDDS_DOUBLE:
288 return ((int32_t) * ((double *)data + index));
289 case SDDS_FLOAT:
290 return ((int32_t) * ((float *)data + index));
291 case SDDS_SHORT:
292 return ((int32_t) * ((short *)data + index));
293 case SDDS_USHORT:
294 return ((int32_t) * ((unsigned short *)data + index));
295 case SDDS_LONG:
296 return (*((int32_t *)data + index));
297 case SDDS_ULONG:
298 return ((int32_t) * ((uint32_t *)data + index));
299 case SDDS_LONG64:
300 return ((int32_t) * ((int64_t *)data + index));
301 case SDDS_ULONG64:
302 return ((int32_t) * ((uint64_t *)data + index));
303 case SDDS_CHARACTER:
304 return ((int32_t) * ((unsigned char *)data + index));
305 default:
306 SDDS_SetError("Invalid data type seen (SDDS_ConvertToLong)");
307 return (0.0);
308 }
309}

◆ SDDS_ConvertToLong64()

epicsShareFuncSDDS int64_t SDDS_ConvertToLong64 ( int32_t type,
void * data,
int64_t index )
extern

Converts a value to a 64-bit integer based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted 64-bit integer, or 0 on error.

Definition at line 239 of file SDDS_rpn.c.

239 {
240 if (!data) {
241 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToLong64)");
242 return (0.0);
243 }
244 switch (type) {
245 case SDDS_LONGDOUBLE:
246 return ((int64_t) * ((long double *)data + index));
247 case SDDS_DOUBLE:
248 return ((int64_t) * ((double *)data + index));
249 case SDDS_FLOAT:
250 return ((int64_t) * ((float *)data + index));
251 case SDDS_SHORT:
252 return ((int64_t) * ((short *)data + index));
253 case SDDS_USHORT:
254 return ((int64_t) * ((unsigned short *)data + index));
255 case SDDS_LONG:
256 return ((int64_t) * ((int32_t *)data + index));
257 case SDDS_ULONG:
258 return ((int64_t) * ((uint32_t *)data + index));
259 case SDDS_LONG64:
260 return (*((int64_t *)data + index));
261 case SDDS_ULONG64:
262 return ((int64_t) * ((uint64_t *)data + index));
263 case SDDS_CHARACTER:
264 return ((int64_t) * ((unsigned char *)data + index));
265 default:
266 SDDS_SetError("Invalid data type seen (SDDS_ConvertToLong64)");
267 return (0.0);
268 }
269}

◆ SDDS_ConvertToLongDouble()

epicsShareFuncSDDS long double SDDS_ConvertToLongDouble ( int32_t type,
void * data,
int64_t index )
extern

Converts a value to long double based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted long double value, or 0.0 on error.

Definition at line 159 of file SDDS_rpn.c.

159 {
160 if (!data) {
161 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToLongDouble)");
162 return (0.0);
163 }
164 switch (type) {
165 case SDDS_SHORT:
166 return ((long double)*((short *)data + index));
167 case SDDS_USHORT:
168 return ((long double)*((unsigned short *)data + index));
169 case SDDS_LONG:
170 return ((long double)*((int32_t *)data + index));
171 case SDDS_ULONG:
172 return ((long double)*((uint32_t *)data + index));
173 case SDDS_LONG64:
174 return ((long double)*((int64_t *)data + index));
175 case SDDS_ULONG64:
176 return ((long double)*((uint64_t *)data + index));
177 case SDDS_FLOAT:
178 return ((long double)*((float *)data + index));
179 case SDDS_DOUBLE:
180 return ((long double)*((double *)data + index));
181 case SDDS_LONGDOUBLE:
182 return (*((long double *)data + index));
183 case SDDS_CHARACTER:
184 return ((long double)*((unsigned char *)data + index));
185 default:
186 SDDS_SetError("Invalid data type seen (SDDS_ConvertToLongDouble)");
187 return (0.0);
188 }
189}

◆ SDDS_CopyAdditionalRows()

epicsShareFuncSDDS int32_t SDDS_CopyAdditionalRows ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source )
extern

Copies additional rows from one SDDS_DATASET to another. The rows from SDDS_source are appended to the existing rows in SDDS_target.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure where rows will be appended.
SDDS_sourcePointer to the SDDS_DATASET structure from which rows will be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 519 of file SDDS_copy.c.

519 {
520 int64_t i, j, sum;
521 int32_t size, target_index;
522 char buffer[1024];
523
524 if (SDDS_target->n_rows_allocated < (sum = SDDS_target->n_rows + SDDS_source->n_rows) && !SDDS_LengthenTable(SDDS_target, sum - SDDS_target->n_rows_allocated)) {
525 SDDS_SetError("Unable to copy additional rows (SDDS_CopyAdditionalRows)");
526 return (0);
527 }
528 if (SDDS_target->layout.n_columns == 0)
529 return 1;
530 for (i = 0; i < SDDS_source->layout.n_columns; i++) {
531 if ((target_index = SDDS_GetColumnIndex(SDDS_target, SDDS_source->layout.column_definition[i].name)) < 0)
532 continue;
533 size = SDDS_GetTypeSize(SDDS_source->layout.column_definition[i].type);
534 if (SDDS_source->layout.column_definition[i].type != SDDS_STRING) {
535 if (SDDS_source->layout.column_definition[i].type == SDDS_target->layout.column_definition[target_index].type) {
536 memcpy((char *)SDDS_target->data[target_index] + size * SDDS_target->n_rows, SDDS_source->data[i], SDDS_type_size[SDDS_source->layout.column_definition[i].type - 1] * SDDS_source->n_rows);
537 } else {
538 for (j = 0; j < SDDS_source->n_rows; j++) {
539 if (!SDDS_CastValue(SDDS_source->data[i], j,
540 SDDS_source->layout.column_definition[i].type, SDDS_target->layout.column_definition[target_index].type, (char *)(SDDS_target->data[target_index]) + (j + SDDS_target->n_rows) * SDDS_type_size[SDDS_target->layout.column_definition[target_index].type - 1])) {
541 sprintf(buffer, "Problem with cast for column %s (SDDS_CopyAdditionalRows)", SDDS_source->layout.column_definition[i].name);
542 SDDS_SetError(buffer);
543 return 0;
544 }
545 }
546 }
547 } else {
548 if (SDDS_source->layout.column_definition[i].type != SDDS_target->layout.column_definition[target_index].type) {
549 sprintf(buffer, "Unable to copy columns---inconsistent data types for %s (SDDS_CopyAdditionalRows)", SDDS_source->layout.column_definition[i].name);
550 SDDS_SetError(buffer);
551 return (0);
552 }
553 if (!SDDS_CopyStringArray((char **)((char *)SDDS_target->data[target_index] + size * SDDS_target->n_rows), SDDS_source->data[i], SDDS_source->n_rows)) {
554 SDDS_SetError("Unable to copy columns (SDDS_CopyAdditionalRows)");
555 return (0);
556 }
557 }
558 SDDS_target->column_flag[target_index] = 1;
559 SDDS_target->column_order[target_index] = target_index;
560 }
561 SDDS_target->n_rows += SDDS_source->n_rows;
562 if (SDDS_target->row_flag)
563 for (i = 0; i < SDDS_target->n_rows; i++)
564 SDDS_target->row_flag[i] = 1;
565
566 return (1);
567}
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
void * SDDS_CastValue(void *data, int64_t index, int32_t data_type, int32_t desired_type, void *memory)
Casts a value from one SDDS data type to another.
int32_t SDDS_GetTypeSize(int32_t type)
Retrieves the size in bytes of a specified SDDS data type.

◆ SDDS_CopyArrayDefinition()

epicsShareFuncSDDS ARRAY_DEFINITION * SDDS_CopyArrayDefinition ( ARRAY_DEFINITION ** target,
ARRAY_DEFINITION * source )
extern

Creates a copy of an array definition.

This function allocates memory for a new ARRAY_DEFINITION structure and copies the contents from the source array definition to the target. All string fields are duplicated to ensure independent memory management.

Parameters
[out]targetPointer to a ARRAY_DEFINITION* where the copied definition will be stored.
[in]sourcePointer to the ARRAY_DEFINITION structure to be copied. If source is NULL, the target is set to NULL.
Returns
Returns a pointer to the copied ARRAY_DEFINITION structure on success. Returns NULL on failure (e.g., memory allocation failure).
Note
The caller is responsible for freeing the copied array definition using SDDS_FreeArrayDefinition.
See also
SDDS_FreeArrayDefinition
SDDS_Malloc
SDDS_CopyString

Definition at line 1208 of file SDDS_utils.c.

1208 {
1209 if (!target)
1210 return NULL;
1211 if (!source)
1212 return (*target = NULL);
1213 if (!(*target = (ARRAY_DEFINITION *)SDDS_Malloc(sizeof(**target))) ||
1214 !SDDS_CopyString(&(*target)->name, source->name) ||
1215 !SDDS_CopyString(&(*target)->symbol, source->symbol) ||
1216 !SDDS_CopyString(&(*target)->units, source->units) || !SDDS_CopyString(&(*target)->description, source->description) || !SDDS_CopyString(&(*target)->format_string, source->format_string) || !SDDS_CopyString(&(*target)->group_name, source->group_name))
1217 return (NULL);
1218 (*target)->type = source->type;
1219 (*target)->field_length = source->field_length;
1220 (*target)->dimensions = source->dimensions;
1221 return (*target);
1222}

◆ SDDS_CopyArrays()

epicsShareFuncSDDS int32_t SDDS_CopyArrays ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source )
extern

Copies array data from one SDDS_DATASET structure into another for arrays with matching names.

Parameters
SDDS_targetAddress of the SDDS_DATASET structure into which array data will be copied.
SDDS_sourceAddress of the SDDS_DATASET structure from which array data will be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 334 of file SDDS_copy.c.

334 {
335 int32_t i, j, target_index;
336 char messageBuffer[1024];
337
338 for (i = 0; i < SDDS_source->layout.n_arrays; i++) {
339 if ((target_index = SDDS_GetArrayIndex(SDDS_target, SDDS_source->layout.array_definition[i].name)) < 0)
340 continue;
341 SDDS_target->array[target_index].definition = SDDS_target->layout.array_definition + target_index;
342 SDDS_target->array[target_index].elements = SDDS_source->array[i].elements;
343 if (!(SDDS_target->array[target_index].dimension = (int32_t *)SDDS_Malloc(sizeof(*SDDS_target->array[i].dimension) * SDDS_target->array[target_index].definition->dimensions)) ||
344 !(SDDS_target->array[target_index].data = SDDS_Realloc(SDDS_target->array[target_index].data, SDDS_type_size[SDDS_target->array[target_index].definition->type - 1] * SDDS_target->array[target_index].elements))) {
345 SDDS_SetError("Unable to copy arrays--allocation failure (SDDS_CopyArrays)");
346 return (0);
347 }
348
349 for (j = 0; j < SDDS_target->array[target_index].definition->dimensions; j++)
350 SDDS_target->array[target_index].dimension[j] = SDDS_source->array[i].dimension[j];
351 if (!SDDS_source->array[i].data) {
352 SDDS_target->array[target_index].data = NULL;
353 continue;
354 }
355 if (SDDS_source->layout.array_definition[i].type != SDDS_target->layout.array_definition[target_index].type) {
356 if (!SDDS_NUMERIC_TYPE(SDDS_source->layout.array_definition[i].type) || !SDDS_NUMERIC_TYPE(SDDS_target->layout.array_definition[target_index].type)) {
357 sprintf(messageBuffer, "Can't cast between nonnumeric types for parameters %s and %s (SDDS_CopyArrays)", SDDS_source->layout.array_definition[i].name, SDDS_target->layout.array_definition[target_index].name);
358 SDDS_SetError(messageBuffer);
359 return 0;
360 }
361 for (j = 0; j < SDDS_source->array[i].elements; j++) {
362 if (!SDDS_CastValue(SDDS_source->array[i].data, j, SDDS_source->layout.array_definition[i].type, SDDS_target->layout.array_definition[target_index].type, (char *)(SDDS_target->array[target_index].data) + j * SDDS_type_size[SDDS_target->layout.array_definition[target_index].type - 1])) {
363 SDDS_SetError("Problem with cast (SDDS_CopyArrays)");
364 return 0;
365 }
366 }
367 } else {
368 if (SDDS_target->array[target_index].definition->type != SDDS_STRING)
369 memcpy(SDDS_target->array[target_index].data, SDDS_source->array[i].data, SDDS_type_size[SDDS_target->array[target_index].definition->type - 1] * SDDS_target->array[target_index].elements);
370 else if (!SDDS_CopyStringArray(SDDS_target->array[target_index].data, SDDS_source->array[i].data, SDDS_target->array[target_index].elements)) {
371 SDDS_SetError("Unable to copy arrays (SDDS_CopyArrays)");
372 return (0);
373 }
374 }
375 }
376 return (1);
377}

◆ SDDS_CopyAssociateDefinition()

epicsShareFuncSDDS ASSOCIATE_DEFINITION * SDDS_CopyAssociateDefinition ( ASSOCIATE_DEFINITION ** target,
ASSOCIATE_DEFINITION * source )
extern

Creates a copy of an associate definition.

This function allocates memory for a new ASSOCIATE_DEFINITION structure and copies the contents from the source associate definition to the target. All string fields are duplicated to ensure independent memory management.

Parameters
[out]targetPointer to a ASSOCIATE_DEFINITION* where the copied definition will be stored.
[in]sourcePointer to the ASSOCIATE_DEFINITION structure to be copied. If source is NULL, the target is set to NULL.
Returns
Returns a pointer to the copied ASSOCIATE_DEFINITION structure on success. Returns NULL on failure (e.g., memory allocation failure).
Note
The caller is responsible for freeing the copied associate definition using SDDS_FreeAssociateDefinition.
See also
SDDS_FreeAssociateDefinition
SDDS_Malloc
SDDS_CopyString

Definition at line 920 of file SDDS_utils.c.

920 {
921 if (!source)
922 return (*target = NULL);
923 if (!(*target = (ASSOCIATE_DEFINITION *)SDDS_Malloc(sizeof(**target))) ||
924 !SDDS_CopyString(&(*target)->name, source->name) || !SDDS_CopyString(&(*target)->filename, source->filename) || !SDDS_CopyString(&(*target)->path, source->path) || !SDDS_CopyString(&(*target)->description, source->description) || !SDDS_CopyString(&(*target)->contents, source->contents))
925 return (NULL);
926 (*target)->sdds = source->sdds;
927 return (*target);
928}

◆ SDDS_CopyColumnDefinition()

epicsShareFuncSDDS COLUMN_DEFINITION * SDDS_CopyColumnDefinition ( COLUMN_DEFINITION ** target,
COLUMN_DEFINITION * source )
extern

Creates a copy of a column definition.

This function allocates memory for a new COLUMN_DEFINITION structure and copies the contents from the source column definition to the target. All string fields are duplicated to ensure independent memory management.

Parameters
[out]targetPointer to a COLUMN_DEFINITION* where the copied definition will be stored.
[in]sourcePointer to the COLUMN_DEFINITION structure to be copied. If source is NULL, the target is set to NULL.
Returns
Returns a pointer to the copied COLUMN_DEFINITION structure on success. Returns NULL on failure (e.g., memory allocation failure).
Note
The caller is responsible for freeing the copied column definition using SDDS_FreeColumnDefinition.
See also
SDDS_FreeColumnDefinition
SDDS_Malloc
SDDS_CopyString

Definition at line 1012 of file SDDS_utils.c.

1012 {
1013 if (!target)
1014 return NULL;
1015 if (!source)
1016 return (*target = NULL);
1017 if (!(*target = (COLUMN_DEFINITION *)SDDS_Malloc(sizeof(**target))) ||
1018 !SDDS_CopyString(&(*target)->name, source->name) ||
1019 !SDDS_CopyString(&(*target)->symbol, source->symbol) || !SDDS_CopyString(&(*target)->units, source->units) || !SDDS_CopyString(&(*target)->description, source->description) || !SDDS_CopyString(&(*target)->format_string, source->format_string))
1020 return (NULL);
1021 (*target)->type = source->type;
1022 (*target)->field_length = source->field_length;
1023 (*target)->definition_mode = source->definition_mode;
1024 (*target)->memory_number = source->memory_number;
1025 return (*target);
1026}

◆ SDDS_CopyColumns()

epicsShareFuncSDDS int32_t SDDS_CopyColumns ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source )
extern

Copies column data from one SDDS_DATASET structure into another for columns with matching names.

Parameters
SDDS_targetAddress of the SDDS_DATASET structure into which column data will be copied.
SDDS_sourceAddress of the SDDS_DATASET structure from which column data will be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 387 of file SDDS_copy.c.

387 {
388 int64_t i, j;
389 int32_t target_index;
390 SDDS_target->n_rows = 0;
391 if (SDDS_target->layout.n_columns && SDDS_target->n_rows_allocated < SDDS_source->n_rows) {
392 SDDS_SetError("Unable to copy columns--insufficient memory allocated to target table");
393 return (0);
394 }
395 if (!SDDS_target->layout.n_columns)
396 return 1;
397 for (i = 0; i < SDDS_source->layout.n_columns; i++) {
398 if ((target_index = SDDS_GetColumnIndex(SDDS_target, SDDS_source->layout.column_definition[i].name)) < 0)
399 continue;
400 if (SDDS_source->layout.column_definition[i].type != SDDS_STRING) {
401 if (SDDS_source->layout.column_definition[i].type == SDDS_target->layout.column_definition[target_index].type)
402 memcpy(SDDS_target->data[target_index], SDDS_source->data[i], SDDS_type_size[SDDS_source->layout.column_definition[i].type - 1] * SDDS_source->n_rows);
403 else {
404 /* Do a cast between the source and target types, if they are both numeric */
405 if (!SDDS_NUMERIC_TYPE(SDDS_source->layout.column_definition[i].type) || !SDDS_NUMERIC_TYPE(SDDS_target->layout.column_definition[target_index].type)) {
406 SDDS_SetError("Can't cast between nonnumeric types (SDDS_CopyColumns)");
407 return 0;
408 }
409 for (j = 0; j < SDDS_source->n_rows; j++) {
410 if (!SDDS_CastValue(SDDS_source->data[i], j, SDDS_source->layout.column_definition[i].type, SDDS_target->layout.column_definition[target_index].type, (char *)(SDDS_target->data[target_index]) + j * SDDS_type_size[SDDS_target->layout.column_definition[target_index].type - 1])) {
411 SDDS_SetError("Problem with cast (SDDS_CopyColumns)");
412 return 0;
413 }
414 }
415 }
416 } else if (!SDDS_CopyStringArray(SDDS_target->data[target_index], SDDS_source->data[i], SDDS_source->n_rows)) {
417 SDDS_SetError("Unable to copy columns (SDDS_CopyColumns)");
418 return (0);
419 }
420 SDDS_target->column_flag[target_index] = 1;
421 SDDS_target->column_order[target_index] = target_index;
422 }
423 SDDS_target->n_rows = SDDS_source->n_rows;
424 if (SDDS_target->row_flag)
425 for (i = 0; i < SDDS_target->n_rows; i++)
426 SDDS_target->row_flag[i] = 1;
427 return (1);
428}

◆ SDDS_CopyLayout()

epicsShareFuncSDDS int32_t SDDS_CopyLayout ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source )
extern

Copies the entire layout (including version, data mode, description, contents, columns, parameters, associates, and arrays) from one SDDS_DATASET to another. The target dataset's existing layout will be replaced.

Parameters
SDDS_targetAddress of the SDDS_DATASET structure into which the layout will be copied.
SDDS_sourceAddress of the SDDS_DATASET structure from which the layout will be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 222 of file SDDS_copy.c.

222 {
223 SDDS_LAYOUT *target, *source;
224 int64_t i;
225
226 if (!SDDS_CheckDataset(SDDS_target, "SDDS_CopyLayout"))
227 return (0);
228 if (!SDDS_CheckDataset(SDDS_source, "SDDS_CopyLayout"))
229 return (0);
230 target = &SDDS_target->layout;
231 source = &SDDS_source->layout;
232 target->version = source->version;
233 target->data_mode = source->data_mode;
234 target->data_mode.no_row_counts = 0;
235 target->data_mode.fixed_row_count = 0;
236 target->data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
237 target->layout_written = 0;
238 target->byteOrderDeclared = 0;
239 if (source->description)
240 SDDS_CopyString(&target->description, source->description);
241 if (source->contents)
242 SDDS_CopyString(&target->contents, source->contents);
243 SDDS_DeferSavingLayout(SDDS_target, 1);
244 for (i = 0; i < source->n_columns; i++)
245 if (SDDS_DefineColumn(SDDS_target, source->column_definition[i].name, source->column_definition[i].symbol,
246 source->column_definition[i].units, source->column_definition[i].description, source->column_definition[i].format_string, source->column_definition[i].type, source->column_definition[i].field_length) < 0) {
247 SDDS_SetError("Unable to define column (SDDS_CopyLayout)");
248 return (0);
249 }
250 for (i = 0; i < source->n_parameters; i++)
251 if (SDDS_DefineParameter(SDDS_target, source->parameter_definition[i].name, source->parameter_definition[i].symbol,
252 source->parameter_definition[i].units, source->parameter_definition[i].description, source->parameter_definition[i].format_string, source->parameter_definition[i].type, source->parameter_definition[i].fixed_value) < 0) {
253 SDDS_SetError("Unable to define parameter (SDDS_CopyLayout)");
254 return (0);
255 }
256
257 for (i = 0; i < source->n_associates; i++)
258 if (SDDS_DefineAssociate(SDDS_target, source->associate_definition[i].name, source->associate_definition[i].filename, source->associate_definition[i].path, source->associate_definition[i].description, source->associate_definition[i].contents, source->associate_definition[i].sdds) < 0) {
259 SDDS_SetError("Unable to define associate (SDDS_CopyLayout)");
260 return (0);
261 }
262
263 for (i = 0; i < source->n_arrays; i++)
264 if (SDDS_DefineArray(SDDS_target, source->array_definition[i].name, source->array_definition[i].symbol,
265 source->array_definition[i].units, source->array_definition[i].description,
266 source->array_definition[i].format_string, source->array_definition[i].type, source->array_definition[i].field_length, source->array_definition[i].dimensions, source->array_definition[i].group_name) < 0) {
267 SDDS_SetError("Unable to define array (SDDS_CopyLayout)");
268 return (0);
269 }
270 SDDS_DeferSavingLayout(SDDS_target, 0);
271 if (!SDDS_SaveLayout(SDDS_target)) {
272 SDDS_SetError("Unable to save layout (SDDS_CopyLayout)");
273 return (0);
274 }
275 return (1);
276}

◆ SDDS_CopyPage()

epicsShareFuncSDDS int32_t SDDS_CopyPage ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source )
extern

Copies the data from one SDDS_DATASET structure to another. This includes parameters, arrays, and columns.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure where data will be copied to.
SDDS_sourcePointer to the SDDS_DATASET structure from which data will be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 578 of file SDDS_copy.c.

578 {
579 if (!SDDS_CheckDataset(SDDS_target, "SDDS_CopyPage"))
580 return (0);
581 if (!SDDS_CheckDataset(SDDS_source, "SDDS_CopyPage"))
582 return (0);
583
584 if (!SDDS_StartPage(SDDS_target, SDDS_target->layout.n_columns ? SDDS_source->n_rows : 0)) {
585 SDDS_SetError("Unable to copy page (SDDS_CopyPage)");
586 return (0);
587 }
588 if (!SDDS_CopyParameters(SDDS_target, SDDS_source))
589 return (0);
590 if (!SDDS_CopyArrays(SDDS_target, SDDS_source))
591 return (0);
592 if (!SDDS_CopyColumns(SDDS_target, SDDS_source))
593 return (0);
594 return (1);
595}
int32_t SDDS_CopyColumns(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:387
int32_t SDDS_CopyParameters(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:286
int32_t SDDS_CopyArrays(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:334
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)

◆ SDDS_CopyParameterDefinition()

epicsShareFuncSDDS PARAMETER_DEFINITION * SDDS_CopyParameterDefinition ( PARAMETER_DEFINITION ** target,
PARAMETER_DEFINITION * source )
extern

Creates a copy of a parameter definition.

This function allocates memory for a new PARAMETER_DEFINITION structure and copies the contents from the source parameter definition to the target. All string fields are duplicated to ensure independent memory management.

Parameters
[out]targetPointer to a PARAMETER_DEFINITION* where the copied definition will be stored.
[in]sourcePointer to the PARAMETER_DEFINITION structure to be copied. If source is NULL, the target is set to NULL.
Returns
Returns a pointer to the copied PARAMETER_DEFINITION structure on success. Returns NULL on failure (e.g., memory allocation failure).
Note
The caller is responsible for freeing the copied parameter definition using SDDS_FreeParameterDefinition.
See also
SDDS_FreeParameterDefinition
SDDS_Malloc
SDDS_CopyString

Definition at line 1109 of file SDDS_utils.c.

1109 {
1110 if (!target)
1111 return NULL;
1112 if (!source)
1113 return (*target = NULL);
1114 if (!(*target = (PARAMETER_DEFINITION *)SDDS_Malloc(sizeof(**target))) ||
1115 !SDDS_CopyString(&(*target)->name, source->name) ||
1116 !SDDS_CopyString(&(*target)->symbol, source->symbol) ||
1117 !SDDS_CopyString(&(*target)->units, source->units) || !SDDS_CopyString(&(*target)->description, source->description) || !SDDS_CopyString(&(*target)->format_string, source->format_string) || !SDDS_CopyString(&(*target)->fixed_value, source->fixed_value))
1118 return (NULL);
1119 (*target)->type = source->type;
1120 (*target)->definition_mode = source->definition_mode;
1121 (*target)->memory_number = source->memory_number;
1122 return (*target);
1123}

◆ SDDS_CopyParameters()

epicsShareFuncSDDS int32_t SDDS_CopyParameters ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source )
extern

Copies parameter values from one SDDS_DATASET structure into another for parameters with matching names.

Parameters
SDDS_targetAddress of the SDDS_DATASET structure into which parameter values will be copied.
SDDS_sourceAddress of the SDDS_DATASET structure from which parameter values will be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 286 of file SDDS_copy.c.

286 {
287 int32_t i, target_index;
288 char *buffer = NULL; /* will be sized to hold any SDDS data type with room to spare */
289 char messageBuffer[1024];
290
291 if (!buffer && !(buffer = SDDS_Malloc(sizeof(char) * 16))) {
292 SDDS_SetError("Allocation failure (SDDS_CopyParameters)");
293 return 0;
294 }
295
296 if (!SDDS_CheckDataset(SDDS_target, "SDDS_CopyParameters"))
297 return (0);
298 if (!SDDS_CheckDataset(SDDS_source, "SDDS_CopyParameters"))
299 return (0);
300
301 for (i = 0; i < SDDS_source->layout.n_parameters; i++) {
302 if ((target_index = SDDS_GetParameterIndex(SDDS_target, SDDS_source->layout.parameter_definition[i].name)) < 0)
303 continue;
304 if (SDDS_source->layout.parameter_definition[i].type != SDDS_target->layout.parameter_definition[target_index].type) {
305 if (!SDDS_NUMERIC_TYPE(SDDS_source->layout.parameter_definition[i].type) || !SDDS_NUMERIC_TYPE(SDDS_target->layout.parameter_definition[target_index].type)) {
306 sprintf(messageBuffer, "Can't cast between nonnumeric types for parameters %s and %s (SDDS_CopyParameters)", SDDS_source->layout.parameter_definition[i].name, SDDS_target->layout.parameter_definition[target_index].name);
307 SDDS_SetError(messageBuffer);
308 return 0;
309 }
310 if (!SDDS_SetParameters(SDDS_target, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, target_index, SDDS_CastValue(SDDS_source->parameter[i], 0, SDDS_source->layout.parameter_definition[i].type, SDDS_target->layout.parameter_definition[target_index].type, buffer), -1)) {
311 sprintf(messageBuffer, "Error setting parameter with cast value for parameters %s and %s (SDDS_CopyParameters)", SDDS_source->layout.parameter_definition[i].name, SDDS_target->layout.parameter_definition[target_index].name);
312 SDDS_SetError(messageBuffer);
313 return 0;
314 }
315 } else if (!SDDS_SetParameters(SDDS_target, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, target_index, SDDS_source->parameter[i], -1)) {
316 sprintf(messageBuffer, "Unable to copy parameters for parameters %s and %s (SDDS_CopyParameters)", SDDS_source->layout.parameter_definition[i].name, SDDS_target->layout.parameter_definition[target_index].name);
317 SDDS_SetError(messageBuffer);
318 return (0);
319 }
320 }
321 if (buffer)
322 free(buffer);
323 return (1);
324}
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)

◆ SDDS_CopyRow()

epicsShareFuncSDDS int32_t SDDS_CopyRow ( SDDS_DATASET * SDDS_target,
int64_t target_row,
SDDS_DATASET * SDDS_source,
int64_t source_srow )
extern

Copies a row from the source SDDS_DATASET to the target SDDS_DATASET. Only columns that exist in both datasets are copied. The source row is determined by its position among the selected rows.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure where the row will be copied to.
target_rowIndex of the row in the target dataset where data will be placed.
SDDS_sourcePointer to the SDDS_DATASET structure from which the row will be copied.
source_srowIndex of the selected row (among rows of interest) in the source dataset.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 778 of file SDDS_copy.c.

778 {
779 int64_t i, j, source_row;
780 int32_t size, type;
781
782 if (!SDDS_CheckDataset(SDDS_target, "SDDS_CopyRow"))
783 return (0);
784 if (!SDDS_CheckDataset(SDDS_source, "SDDS_CopyRow"))
785 return (0);
786
787 if (target_row >= SDDS_target->n_rows_allocated) {
788 SDDS_SetError("Unable to copy row--target page not large enough");
789 return (0);
790 }
791 if (SDDS_target->n_rows <= target_row)
792 SDDS_target->n_rows = target_row + 1;
793
794 source_row = -1;
795 for (i = j = 0; i < SDDS_source->n_rows; i++)
796 if (SDDS_source->row_flag[i] && j++ == source_srow) {
797 source_row = i;
798 break;
799 }
800
801 if (source_row == -1) {
802 SDDS_SetError("Unable to copy row--source selected-row does not exist");
803 return (0);
804 }
805
806 for (i = 0; i < SDDS_target->layout.n_columns; i++) {
807 if ((j = SDDS_GetColumnIndex(SDDS_source, SDDS_target->layout.column_definition[i].name)) < 0 || !SDDS_source->column_flag[j])
808 continue;
809 if ((type = SDDS_GetColumnType(SDDS_target, i)) == SDDS_STRING) {
810 if (!SDDS_CopyString(((char ***)SDDS_target->data)[i] + target_row, ((char ***)SDDS_source->data)[j][source_row])) {
811 SDDS_SetError("Unable to copy row--string copy failed (SDDS_CopyRow)");
812 return (0);
813 }
814 } else {
815 size = SDDS_type_size[type - 1];
816 memcpy((char *)SDDS_target->data[i] + size * target_row, (char *)SDDS_source->data[j] + size * source_row, size);
817 }
818 SDDS_target->row_flag[target_row] = 1;
819 }
820 return (1);
821}

◆ SDDS_CopyRowDirect()

epicsShareFuncSDDS int32_t SDDS_CopyRowDirect ( SDDS_DATASET * SDDS_target,
int64_t target_row,
SDDS_DATASET * SDDS_source,
int64_t source_row )
extern

Copies a specific row from the source SDDS_DATASET to the target SDDS_DATASET. Only columns that exist in both datasets are copied.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure where the row will be copied to.
target_rowIndex of the row in the target dataset where data will be placed.
SDDS_sourcePointer to the SDDS_DATASET structure from which the row will be copied.
source_rowIndex of the row in the source dataset to be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 834 of file SDDS_copy.c.

834 {
835 int64_t i, j;
836 int32_t size, type;
837
838 if (!SDDS_CheckDataset(SDDS_target, "SDDS_CopyRow"))
839 return (0);
840 if (!SDDS_CheckDataset(SDDS_source, "SDDS_CopyRow"))
841 return (0);
842
843 if (target_row >= SDDS_target->n_rows_allocated) {
844 SDDS_SetError("Unable to copy row--target page not large enough");
845 return (0);
846 }
847 if (SDDS_target->n_rows <= target_row)
848 SDDS_target->n_rows = target_row + 1;
849 if (source_row >= SDDS_source->n_rows_allocated) {
850 SDDS_SetError("Unable to copy row--source row non-existent");
851 return (0);
852 }
853
854 for (i = 0; i < SDDS_target->layout.n_columns; i++) {
855 if ((j = SDDS_GetColumnIndex(SDDS_source, SDDS_target->layout.column_definition[i].name)) < 0 || !SDDS_source->column_flag[j])
856 continue;
857 if ((type = SDDS_GetColumnType(SDDS_target, i)) == SDDS_STRING) {
858 if (!SDDS_CopyString(((char ***)SDDS_target->data)[i] + target_row, ((char ***)SDDS_source->data)[j][source_row])) {
859 SDDS_SetError("Unable to copy row--string copy failed (SDDS_CopyRow)");
860 return (0);
861 }
862 } else {
863 size = SDDS_type_size[type - 1];
864 memcpy((char *)SDDS_target->data[i] + size * target_row, (char *)SDDS_source->data[j] + size * source_row, size);
865 }
866 SDDS_target->row_flag[target_row] = 1;
867 }
868 return (1);
869}

◆ SDDS_CopyRows()

epicsShareFuncSDDS int32_t SDDS_CopyRows ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
int64_t firstRow,
int64_t lastRow )
extern

Copies a range of rows from the source SDDS_DATASET to the target SDDS_DATASET. Only columns that exist in both datasets are copied.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure where rows will be copied to.
SDDS_sourcePointer to the SDDS_DATASET structure from which rows will be copied.
firstRowIndex of the first row to copy from the source dataset.
lastRowIndex of the last row to copy from the source dataset.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 882 of file SDDS_copy.c.

882 {
883 int64_t i, j, k;
884 int32_t size, target_index;
885 char buffer[1024];
886 int64_t *rowList, roi;
887 k = 0;
888
889 if (!SDDS_target->layout.n_columns)
890 return 1;
891 roi = lastRow - firstRow + 1;
892 if (roi > SDDS_target->n_rows_allocated) {
893 SDDS_SetError("Unable to copy rows of interest--insufficient memory allocated to target page (SDDS_CopyRows)");
894 return 0;
895 }
896 rowList = malloc(sizeof(*rowList) * roi);
897 k = 0;
898
899 for (j = firstRow; j <= lastRow; j++) {
900 rowList[k] = j;
901 k++;
902 }
903
904 for (i = 0; i < SDDS_source->layout.n_columns; i++) {
905 if ((target_index = SDDS_GetColumnIndex(SDDS_target, SDDS_source->layout.column_definition[i].name)) < 0)
906 continue;
907 if (SDDS_source->layout.column_definition[i].type != SDDS_STRING) {
908 if (SDDS_source->layout.column_definition[i].type == SDDS_target->layout.column_definition[target_index].type) {
909 size = SDDS_type_size[SDDS_source->layout.column_definition[i].type - 1];
910 for (k = 0; k < roi; k++) {
911
912 memcpy((char *)SDDS_target->data[target_index] + k * size, (char *)SDDS_source->data[i] + rowList[k] * size, SDDS_type_size[SDDS_source->layout.column_definition[i].type - 1]);
913 }
914 } else {
915 for (k = 0; k < roi; k++) {
916 if (!SDDS_CastValue(SDDS_source->data[i], rowList[k],
917 SDDS_source->layout.column_definition[i].type, SDDS_target->layout.column_definition[target_index].type, (char *)(SDDS_target->data[target_index]) + k * SDDS_type_size[SDDS_target->layout.column_definition[target_index].type - 1])) {
918 sprintf(buffer, "Problem with cast for column %s (SDDS_CopyRows)", SDDS_source->layout.column_definition[i].name);
919 SDDS_SetError(buffer);
920 return 0;
921 }
922 }
923 }
924 } else {
925 if (SDDS_source->layout.column_definition[i].type != SDDS_target->layout.column_definition[target_index].type) {
926 sprintf(buffer, "Unable to copy columns---inconsistent data types for %s (SDDS_CopyRows)", SDDS_source->layout.column_definition[i].name);
927 SDDS_SetError(buffer);
928 return (0);
929 }
930 for (k = 0; k < roi; k++) {
931 if (((char **)SDDS_target->data[target_index])[k])
932 free(((char **)SDDS_target->data[target_index])[k]);
933 if (!SDDS_CopyString(&((char **)SDDS_target->data[target_index])[k], ((char **)SDDS_source->data[i])[rowList[k]])) {
934 SDDS_SetError("Unable to copy rows (SDDS_CopyRows)");
935 return (0);
936 }
937 }
938 }
939 SDDS_target->column_flag[target_index] = 1;
940 SDDS_target->column_order[target_index] = target_index;
941 }
942
943 free(rowList);
944
945 SDDS_target->n_rows = roi;
946 if (SDDS_target->row_flag) {
947 for (i = 0; i < roi; i++) {
948 SDDS_target->row_flag[i] = 1;
949 }
950 }
951
952 return (1);
953}

◆ SDDS_CopyRowsOfInterest()

epicsShareFuncSDDS int32_t SDDS_CopyRowsOfInterest ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source )
extern

Copies rows of interest from the source SDDS_DATASET to the target SDDS_DATASET for columns with matching names. Rows of interest are those that have their row flags set in the source dataset.

Parameters
SDDS_targetAddress of the SDDS_DATASET structure into which rows will be copied.
SDDS_sourceAddress of the SDDS_DATASET structure from which rows will be copied.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 439 of file SDDS_copy.c.

439 {
440 int64_t i, j, k;
441 int32_t size, target_index;
442 /* int32_t rows; */
443 char buffer[1024];
444 int64_t *rowList, roi;
445 k = 0;
446
447 if (!SDDS_target->layout.n_columns)
448 return 1;
449 roi = SDDS_CountRowsOfInterest(SDDS_source);
450 if (roi > SDDS_target->n_rows_allocated) {
451 SDDS_SetError("Unable to copy rows of interest--insufficient memory allocated to target page (SDDS_CopyRowsOfInterest)");
452 return 0;
453 }
454
455 rowList = malloc(sizeof(*rowList) * roi);
456 k = 0;
457 for (j = 0; j < SDDS_source->n_rows; j++) {
458 if (SDDS_source->row_flag[j]) {
459 rowList[k] = j;
460 k++;
461 }
462 }
463
464 for (i = 0; i < SDDS_source->layout.n_columns; i++) {
465 if ((target_index = SDDS_GetColumnIndex(SDDS_target, SDDS_source->layout.column_definition[i].name)) < 0)
466 continue;
467 if (SDDS_source->layout.column_definition[i].type != SDDS_STRING) {
468 if (SDDS_source->layout.column_definition[i].type == SDDS_target->layout.column_definition[target_index].type) {
469 size = SDDS_type_size[SDDS_source->layout.column_definition[i].type - 1];
470 for (k = 0; k < roi; k++) {
471 memcpy((char *)SDDS_target->data[target_index] + k * size, (char *)SDDS_source->data[i] + rowList[k] * size, SDDS_type_size[SDDS_source->layout.column_definition[i].type - 1]);
472 }
473 } else {
474 for (k = 0; k < roi; k++) {
475 if (!SDDS_CastValue(SDDS_source->data[i], rowList[k],
476 SDDS_source->layout.column_definition[i].type, SDDS_target->layout.column_definition[target_index].type, (char *)(SDDS_target->data[target_index]) + k * SDDS_type_size[SDDS_target->layout.column_definition[target_index].type - 1])) {
477 sprintf(buffer, "Problem with cast for column %s (SDDS_CopyRowsOfInterest)", SDDS_source->layout.column_definition[i].name);
478 SDDS_SetError(buffer);
479 return 0;
480 }
481 }
482 }
483 } else {
484 if (SDDS_source->layout.column_definition[i].type != SDDS_target->layout.column_definition[target_index].type) {
485 sprintf(buffer, "Unable to copy columns---inconsistent data types for %s (SDDS_CopyRowsOfInterest)", SDDS_source->layout.column_definition[i].name);
486 SDDS_SetError(buffer);
487 return (0);
488 }
489 for (k = 0; k < roi; k++) {
490 if (((char **)SDDS_target->data[target_index])[k])
491 free(((char **)SDDS_target->data[target_index])[k]);
492 if (!SDDS_CopyString(&((char **)SDDS_target->data[target_index])[k], ((char **)SDDS_source->data[i])[rowList[k]])) {
493 SDDS_SetError("Unable to copy rows (SDDS_CopyRowsOfInterest)");
494 return (0);
495 }
496 }
497 }
498 SDDS_target->column_flag[target_index] = 1;
499 SDDS_target->column_order[target_index] = target_index;
500 }
501 free(rowList);
502 SDDS_target->n_rows = roi;
503 if (SDDS_target->row_flag)
504 for (i = 0; i < SDDS_target->n_rows; i++)
505 SDDS_target->row_flag[i] = 1;
506
507 return (1);
508}
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.

◆ SDDS_CopyString()

epicsShareFuncSDDS int32_t SDDS_CopyString ( char ** target,
const char * source )
extern

Copies a source string to a target string with memory allocation.

This function allocates memory for the target string and copies the contents of the source string into it. If the source string is NULL, the target string is set to NULL.

Parameters
[out]targetPointer to a char* variable where the copied string will be stored. Memory is allocated within this function and should be freed by the caller to avoid memory leaks.
[in]sourceThe source string to be copied. If NULL, the target is set to NULL.
Returns
Returns 1 on successful copy and memory allocation. Returns 0 on error (e.g., memory allocation failure).
Note
The caller is responsible for freeing the memory allocated for the target string.
See also
SDDS_Free
SDDS_Malloc

Definition at line 856 of file SDDS_utils.c.

856 {
857 if (!source)
858 *target = NULL;
859 else {
860 if (!(*target = SDDS_Malloc(sizeof(**target) * (strlen(source) + 1))))
861 return (0);
862 strcpy(*target, source);
863 }
864 return (1);
865}

◆ SDDS_CopyStringArray()

epicsShareFuncSDDS int32_t SDDS_CopyStringArray ( char ** target,
char ** source,
int64_t n_strings )
extern

Copies an array of strings from source to target.

This function duplicates each string from the source array into the target array. It handles memory allocation for each individual string using SDDS_CopyString.

Parameters
[in]targetPointer to the destination array of strings where the copied strings will be stored.
[in]sourcePointer to the source array of strings to be copied.
[in]n_stringsThe number of strings to copy from the source to the target.
Returns
  • Returns 1 on successful copying of all strings.
  • Returns 0 if either source or target is NULL, or if any string copy operation fails.
Note
  • The caller is responsible for ensuring that the target array has sufficient space allocated.
  • In case of failure, partially copied strings may remain in the target array.
See also
SDDS_CopyString
SDDS_Malloc

Definition at line 2837 of file SDDS_utils.c.

2837 {
2838 if (!source || !target)
2839 return (0);
2840 while (n_strings--) {
2841 if (!SDDS_CopyString(target + n_strings, source[n_strings]))
2842 return (0);
2843 }
2844 return (1);
2845}

◆ SDDS_CountColumnsOfInterest()

epicsShareFuncSDDS int32_t SDDS_CountColumnsOfInterest ( SDDS_DATASET * SDDS_dataset)
extern

Counts the number of columns marked as "of interest" in the current data table.

This function returns the total number of columns that have been flagged as "of interest" based on their acceptance flags.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
Returns
  • Non-negative integer representing the number of columns marked as "of interest".
  • -1 if the dataset is invalid.
See also
SDDS_CountRowsOfInterest, SDDS_SetColumnFlags, SDDS_GetColumnFlags

Definition at line 342 of file SDDS_extract.c.

342 {
343 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_CountRowsOfInterest"))
344 return (-1);
345 return (SDDS_dataset->n_of_interest);
346}

◆ SDDS_CountRowsOfInterest()

epicsShareFuncSDDS int64_t SDDS_CountRowsOfInterest ( SDDS_DATASET * SDDS_dataset)
extern

Counts the number of rows marked as "of interest" in the current data table.

This function iterates through the row acceptance flags and tallies the number of rows that are flagged as "of interest" (non-zero).

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
Returns
  • Number of rows with non-zero acceptance flags.
  • -1 on error (e.g., invalid dataset or tabular data).
Note
Ensure that the dataset contains tabular data before invoking this function.
See also
SDDS_SetRowFlags, SDDS_GetRowFlags, SDDS_GetRowFlag

Definition at line 364 of file SDDS_extract.c.

364 {
365 int64_t n_rows, i;
366 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_CountRowsOfInterest"))
367 return (-1);
368 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_CountRowsOfInterest"))
369 return (-1);
370 if (!SDDS_dataset->layout.n_columns)
371 return 0;
372 for (i = n_rows = 0; i < SDDS_dataset->n_rows; i++) {
373 if (SDDS_dataset->row_flag[i])
374 n_rows += 1;
375 }
376 return (n_rows);
377}
int32_t SDDS_CheckTabularData(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the consistency of tabular data within an SDDS dataset.
Definition SDDS_utils.c:577

◆ SDDS_CreateEmptyDataset()

epicsShareFuncSDDS SDDS_DATASET * SDDS_CreateEmptyDataset ( void )
extern

Creates an empty SDDS dataset.

This function allocates and initializes an empty SDDS_DATASET structure. The returned dataset can then be configured and populated with columns, parameters, and arrays as needed.

Returns
  • Pointer to the newly created SDDS_DATASET structure.
  • NULL if memory allocation fails.
Note
  • The caller is responsible for initializing the dataset's layout and other necessary fields before use.
  • Ensure that the returned dataset is properly freed using appropriate memory deallocation functions to prevent memory leaks.
Warning
  • Failing to initialize the dataset after creation may lead to undefined behavior when performing operations on it.
  • Always check if the returned pointer is not NULL before using it.
See also
SDDS_FreeDataset, SDDS_InitLayout

Definition at line 5628 of file SDDS_utils.c.

5628 {
5629 SDDS_DATASET *dataset;
5630 dataset = malloc(sizeof(SDDS_DATASET));
5631 return dataset;
5632}

◆ SDDS_CreateRpnArray()

epicsShareFuncSDDS int64_t SDDS_CreateRpnArray ( char * name)
extern

Stub function for creating RPN arrays when RPN_SUPPORT is not enabled.

Parameters
nameName of the RPN array.
Returns
Always returns 1.

Definition at line 795 of file SDDS_rpn.c.

795 {
796 return (1);
797}

◆ SDDS_CreateRpnMemory()

epicsShareFuncSDDS int64_t SDDS_CreateRpnMemory ( const char * name,
short is_string )
extern

Stub function for creating RPN memory when RPN_SUPPORT is not enabled.

Parameters
nameName of the RPN memory.
is_stringFlag indicating if the memory is for string data.
Returns
Always returns 1.

Definition at line 785 of file SDDS_rpn.c.

785 {
786 return (1);
787}

◆ SDDS_CutOutComments()

epicsShareFuncSDDS void SDDS_CutOutComments ( SDDS_DATASET * SDDS_dataset,
char * s,
char cc )
extern

Removes comments from a string based on a specified comment character.

This function processes a string s, removing any content that follows the comment character cc. It also handles special comment lines that start with !# by parsing them using SDDS_ParseSpecialComments. The function ensures that quoted sections within the string are preserved and not mistakenly identified as comments.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure used for processing special comments.
[in,out]sPointer to the character array containing the string to process. The string will be modified in place.
[in]ccThe comment character indicating the start of a comment.
Note
If the first character of the string is the comment character, the entire line is treated as a comment. Otherwise, only the portion of the string following the first unescaped comment character is removed.
See also
SDDS_ParseSpecialComments

Definition at line 1680 of file SDDS_utils.c.

1680 {
1681 int32_t length, hasNewline;
1682 char *s0;
1683
1684 if (!cc || !s)
1685 return;
1686
1687 hasNewline = 0;
1688 length = strlen(s);
1689 if (s[length - 1] == '\n')
1690 hasNewline = 1;
1691
1692 if (*s == cc) {
1693 /* check for special information */
1694 if (*(s + 1) == '#')
1695 SDDS_ParseSpecialComments(SDDS_dataset, s + 2);
1696 *s = 0;
1697 return;
1698 }
1699 s0 = s;
1700 while (*s) {
1701 if ((*s == '"') && (s == s0 || *(s - 1) != '\\')) {
1702 while (*++s && (*s != '"' || *(s - 1) == '\\'))
1703 ;
1704 if (!*s)
1705 return;
1706 s++;
1707 continue;
1708 }
1709 if (*s == cc) {
1710 if (s != s0 && *(s - 1) == '\\')
1711 strcpy_ss(s - 1, s);
1712 else {
1713 if (hasNewline) {
1714 *s = '\n';
1715 *(s + 1) = 0;
1716 } else
1717 *s = 0;
1718 return;
1719 }
1720 }
1721 s++;
1722 }
1723}
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.
Definition str_copy.c:34

◆ SDDS_DeferSavingLayout()

epicsShareFuncSDDS void SDDS_DeferSavingLayout ( SDDS_DATASET * SDDS_dataset,
int32_t mode )
extern

Sets the flag to defer or resume saving the layout of an SDDS_DATASET.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
modeNon-zero value to defer saving the layout; zero to resume saving.

Definition at line 603 of file SDDS_copy.c.

603 {
604 SDDS_dataset->deferSavingLayout = mode;
605}

◆ SDDS_DefineArray()

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

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.
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
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
Definition SDDStypes.h:97
long binaryInsert(void **array, long members, void *newMember, int(*compare)(const void *c1, const void *c2), int32_t *duplicate)
Inserts a new member into a sorted array using binary search.
Definition binsert.c:39

◆ SDDS_DefineAssociate()

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

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}

◆ SDDS_DefineColumn()

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

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}
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_DefineColumnLikeArray()

epicsShareFuncSDDS int32_t SDDS_DefineColumnLikeArray ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Defines a column in the target dataset based on an array definition from the source dataset.

This function creates a column in the target SDDS dataset with properties matching those of a specified array in the source dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the array in the source dataset whose definition is to be used.
newNameThe name of the column in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 302 of file SDDS_transfer.c.

302 {
303 ARRAY_DEFINITION *arrayDef;
304
305 if (!name || SDDS_StringIsBlank(name)) {
306 SDDS_SetError("Unable to define column--NULL or blank name passed (SDDS_DefineColumnLikeArray)");
307 return 0;
308 }
309 if (!newName)
310 newName = name;
311 if (!(arrayDef = SDDS_GetArrayDefinition(source, name))) {
312 SDDS_SetError("Unable to define column--unknown array named (SDDS_DefineColumnLikeArray)");
313 return 0;
314 }
315 if (SDDS_GetColumnIndex(target, newName) >= 0) {
316 SDDS_SetError("Unable to define column--already exists (SDDS_DefineColumnLikeArray)");
317 return 0;
318 }
319 if (SDDS_DefineColumn(target, newName, arrayDef->symbol, arrayDef->units, arrayDef->description, arrayDef->format_string, arrayDef->type, 0) < 0) {
320 SDDS_FreeArrayDefinition(arrayDef);
321 SDDS_SetError("Unable to define column--call to define column failed (SDDS_DefineColumnLikeArray)");
322 return 0;
323 }
324 SDDS_FreeArrayDefinition(arrayDef);
325 return 1;
326}
ARRAY_DEFINITION * SDDS_GetArrayDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified array from the SDDS dataset.
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.

◆ SDDS_DefineColumnLikeParameter()

epicsShareFuncSDDS int32_t SDDS_DefineColumnLikeParameter ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Defines a column in the target dataset based on a parameter definition from the source dataset.

This function creates a column in the target SDDS dataset with properties matching those of a specified parameter in the source dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the parameter in the source dataset whose definition is to be used.
newNameThe name of the column in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 264 of file SDDS_transfer.c.

264 {
265 PARAMETER_DEFINITION *pardef;
266
267 if (!name || SDDS_StringIsBlank(name)) {
268 SDDS_SetError("Unable to define column--NULL or blank name passed (SDDS_DefineColumnLikeParameter)");
269 return 0;
270 }
271 if (!newName)
272 newName = name;
273 if (!(pardef = SDDS_GetParameterDefinition(source, name))) {
274 SDDS_SetError("Unable to define column--unknown parameter named (SDDS_DefineColumnLikeParameter)");
275 return 0;
276 }
277 if (SDDS_GetColumnIndex(target, newName) >= 0) {
278 SDDS_SetError("Unable to define column--already exists (SDDS_DefineColumnLikeParameter)");
279 return 0;
280 }
281 if (SDDS_DefineColumn(target, newName, pardef->symbol, pardef->units, pardef->description, pardef->format_string, pardef->type, 0) < 0) {
283 SDDS_SetError("Unable to define column--call to define column failed (SDDS_DefineColumnLikeParameter)");
284 return 0;
285 }
287 return 1;
288}
PARAMETER_DEFINITION * SDDS_GetParameterDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified parameter from the SDDS dataset.
int32_t SDDS_FreeParameterDefinition(PARAMETER_DEFINITION *source)
Frees memory allocated for a parameter definition.

◆ SDDS_DefineParameter()

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

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

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

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

epicsShareFuncSDDS int32_t SDDS_DefineParameterLikeArray ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Defines a parameter in the target dataset based on an array definition from the source dataset.

This function creates a parameter in the target SDDS dataset with properties matching those of a specified array in the source dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the array in the source dataset whose definition is to be used.
newNameThe name of the parameter in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 226 of file SDDS_transfer.c.

226 {
227 ARRAY_DEFINITION *arrayDef;
228
229 if (!name || SDDS_StringIsBlank(name)) {
230 SDDS_SetError("Unable to define parameter--NULL or blank name passed (SDDS_DefineParameterLikeArray)");
231 return 0;
232 }
233 if (!newName)
234 newName = name;
235 if (!(arrayDef = SDDS_GetArrayDefinition(source, name))) {
236 SDDS_SetError("Unable to define parameter--unknown array named (SDDS_DefineParameterLikeArray)");
237 return 0;
238 }
239 if (SDDS_GetParameterIndex(target, newName) >= 0) {
240 SDDS_SetError("Unable to define parameter--already exists (SDDS_DefineParameterLikeArray)");
241 return 0;
242 }
243 if (SDDS_DefineParameter(target, newName, arrayDef->symbol, arrayDef->units, arrayDef->description, arrayDef->format_string, arrayDef->type, NULL) < 0) {
244 SDDS_FreeArrayDefinition(arrayDef);
245 SDDS_SetError("Unable to define parameter--call to define parameter failed (SDDS_DefineParameterLikeArray)");
246 return 0;
247 }
248 SDDS_FreeArrayDefinition(arrayDef);
249 return 1;
250}

◆ SDDS_DefineParameterLikeColumn()

epicsShareFuncSDDS int32_t SDDS_DefineParameterLikeColumn ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Defines a parameter in the target dataset based on a column definition from the source dataset.

This function creates a parameter in the target SDDS dataset with properties matching those of a specified column in the source dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the column in the source dataset whose definition is to be used.
newNameThe name of the parameter in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 188 of file SDDS_transfer.c.

188 {
189 COLUMN_DEFINITION *coldef;
190
191 if (!name || SDDS_StringIsBlank(name)) {
192 SDDS_SetError("Unable to define parameter--NULL or blank name passed (SDDS_DefineParameterLikeColumn)");
193 return 0;
194 }
195 if (!newName)
196 newName = name;
197 if (!(coldef = SDDS_GetColumnDefinition(source, name))) {
198 SDDS_SetError("Unable to define parameter--unknown column named (SDDS_DefineParameterLikeColumn)");
199 return 0;
200 }
201 if (SDDS_GetParameterIndex(target, newName) >= 0) {
202 SDDS_SetError("Unable to define parameter--already exists (SDDS_DefineParameterLikeColumn)");
203 return 0;
204 }
205 if (SDDS_DefineParameter(target, newName, coldef->symbol, coldef->units, coldef->description, coldef->format_string, coldef->type, NULL) < 0) {
207 SDDS_SetError("Unable to define parameter--call to define parameter failed (SDDS_DefineParameterLikeColumn)");
208 return 0;
209 }
211 return 1;
212}
int32_t SDDS_FreeColumnDefinition(COLUMN_DEFINITION *source)
Frees memory allocated for a column definition.
COLUMN_DEFINITION * SDDS_GetColumnDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified column from the SDDS dataset.
Definition SDDS_utils.c:978

◆ SDDS_DefineSimpleColumn()

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

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}

◆ SDDS_DefineSimpleColumns()

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

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

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

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

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

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

epicsShareFuncSDDS int32_t SDDS_DeleteColumn ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Deletes a specified column from an SDDS dataset.

Note: This function is currently non-functional and will abort execution if called.

This function is intended to remove a column identified by column_name from the provided SDDS dataset. It handles the reordering of remaining columns and updates the dataset's layout accordingly. However, as indicated by the current implementation, the function is not operational and will terminate the program when invoked.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
column_nameA null-terminated string specifying the name of the column to be deleted.
Returns
This function does not return as it aborts execution. If it were functional, it would return 1 on success and 0 on failure.
Warning
  • Currently Non-Functional: The function will terminate the program with an error message when called.
Todo
  • Implement the functionality to delete a column without aborting.
See also
SDDS_DeleteUnsetColumns, SDDS_CopyColumn

Definition at line 3845 of file SDDS_extract.c.

3845 {
3846 int32_t index;
3847 int64_t i, j;
3848
3849 SDDS_Bomb("SDDS_DeleteColumn is presently not functional.");
3850
3851 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DeleteColumn"))
3852 return (0);
3853 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
3854 SDDS_SetError("Unable to delete column--unrecognized column name (SDDS_DeleteColumn)");
3855 return (0);
3856 }
3857 for (i = index + 1; i < SDDS_dataset->layout.n_columns; i++) {
3858 if (!SDDS_CopyColumn(SDDS_dataset, i - 1, i)) {
3859 SDDS_SetError("Unable to delete column--error copying column (SDDS_DeleteColumn)");
3860 return (0);
3861 }
3862 for (j = 0; j < SDDS_dataset->n_of_interest; j++)
3863 if (SDDS_dataset->column_order[j] == index) {
3864 memcpy((char *)(SDDS_dataset->column_order + j), (char *)(SDDS_dataset->column_order + j + 1), sizeof(*SDDS_dataset->column_order) * (SDDS_dataset->n_of_interest - j - 1));
3865 SDDS_dataset->n_of_interest--;
3866 } else if (SDDS_dataset->column_order[j] > index)
3867 SDDS_dataset->column_order[j] -= 1;
3868 }
3869 if ((SDDS_dataset->layout.n_columns -= 1) == 0)
3870 SDDS_dataset->n_rows = 0;
3871 return (1);
3872}
int32_t SDDS_CopyColumn(SDDS_DATASET *SDDS_dataset, int32_t target, int32_t source)
Copies data from a source column to a target column within an SDDS dataset.

◆ SDDS_DeleteParameter()

epicsShareFuncSDDS int32_t SDDS_DeleteParameter ( SDDS_DATASET * SDDS_dataset,
char * parameter_name )
extern

Deletes a specified parameter from an SDDS dataset.

This function removes a parameter identified by parameter_name from the provided SDDS dataset. It shifts all subsequent parameters up to fill the gap left by the deleted parameter and updates the dataset's parameter count accordingly.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to be deleted.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the parameter was successfully deleted.
0Indicates that an error occurred (e.g., invalid dataset, unrecognized parameter name, error copying parameters).
Note
  • This operation modifies the dataset by removing the specified parameter.
  • It is recommended to ensure that the parameter to be deleted is not essential for further operations.
See also
SDDS_CopyParameter, SDDS_DeleteUnsetParameters

Definition at line 3978 of file SDDS_extract.c.

3978 {
3979 int32_t i, index;
3980 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DeleteParameter"))
3981 return (0);
3982 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
3983 SDDS_SetError("Unable to delete parameter--unrecognized parameter name (SDDS_DeleteParameter)");
3984 return (0);
3985 }
3986 for (i = index + 1; i < SDDS_dataset->layout.n_parameters; i++) {
3987 if (!SDDS_CopyParameter(SDDS_dataset, i - 1, i)) {
3988 SDDS_SetError("Unable to delete parameter--error copying parameter (SDDS_DeleteParameter)");
3989 return (0);
3990 }
3991 }
3992 SDDS_dataset->layout.n_parameters -= 1;
3993 return (1);
3994}
int32_t SDDS_CopyParameter(SDDS_DATASET *SDDS_dataset, int32_t target, int32_t source)
Copies a parameter from a source index to a target index within an SDDS dataset.

◆ SDDS_DeleteParameterFixedValues()

epicsShareFuncSDDS int32_t SDDS_DeleteParameterFixedValues ( SDDS_DATASET * SDDS_dataset)
extern

Deletes fixed values from all parameters in the SDDS dataset.

This function iterates through all parameters in the provided SDDS dataset and removes any fixed values associated with them. It ensures that both the current layout and the original layout of the dataset have their fixed values cleared.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset from which fixed values will be deleted.
Returns
  • 1 on successful deletion of all fixed values.
  • 0 if the dataset check fails or if saving the layout fails.
Note
  • The function requires that the SDDS dataset is properly initialized and that it contains parameters with fixed values.
  • Both the current layout and the original layout are updated to remove fixed values.
Warning
  • This operation cannot be undone. Ensure that fixed values are no longer needed before calling this function.
  • Improper handling of memory allocations related to fixed values may lead to memory leaks or undefined behavior.
See also
SDDS_CheckDataset, SDDS_SaveLayout

Definition at line 4883 of file SDDS_utils.c.

4883 {
4884 int32_t i;
4885 SDDS_LAYOUT *layout, *orig_layout;
4886
4887 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DeleteFixedValueParameters"))
4888 return 0;
4889 if (!SDDS_SaveLayout(SDDS_dataset))
4890 return 0;
4891 layout = &SDDS_dataset->layout;
4892 orig_layout = &SDDS_dataset->original_layout;
4893 for (i = 0; i < layout->n_parameters; i++) {
4894 if (layout->parameter_definition[i].fixed_value)
4895 free(layout->parameter_definition[i].fixed_value);
4896 if (orig_layout->parameter_definition[i].fixed_value && (!layout->parameter_definition[i].fixed_value || orig_layout->parameter_definition[i].fixed_value != layout->parameter_definition[i].fixed_value))
4897 free(orig_layout->parameter_definition[i].fixed_value);
4898 orig_layout->parameter_definition[i].fixed_value = NULL;
4899 layout->parameter_definition[i].fixed_value = NULL;
4900 }
4901 return 1;
4902}

◆ SDDS_DeleteUnsetColumns()

epicsShareFuncSDDS int32_t SDDS_DeleteUnsetColumns ( SDDS_DATASET * SDDS_dataset)
extern

Deletes all columns from an SDDS dataset that are not marked as "of interest".

This function iterates through all columns in the provided SDDS dataset and removes those that have not been flagged as "of interest". It ensures that only desired columns are retained, updating the dataset's layout and column order accordingly.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that columns were successfully deleted.
0Indicates that an error occurred (e.g., invalid dataset, failure to delete a column).
Note
  • This operation modifies the dataset in place by removing unset columns.
  • It is recommended to perform column selection before calling this function to ensure that only desired columns are retained.
See also
SDDS_SetColumnsOfInterest, SDDS_DeleteColumn, SDDS_CopyColumn

Definition at line 3893 of file SDDS_extract.c.

3893 {
3894 int64_t i;
3895 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DeleteUnsetColumns"))
3896 return (0);
3897 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3898 if (!SDDS_dataset->column_flag[i]) {
3899 if (!SDDS_DeleteColumn(SDDS_dataset, SDDS_dataset->layout.column_definition[i].name))
3900 return (0);
3901 else
3902 i--;
3903 }
3904 return (1);
3905}
int32_t SDDS_DeleteColumn(SDDS_DATASET *SDDS_dataset, char *column_name)
Deletes a specified column from an SDDS dataset.

◆ SDDS_DeleteUnsetRows()

epicsShareFuncSDDS int32_t SDDS_DeleteUnsetRows ( SDDS_DATASET * SDDS_dataset)
extern

Deletes rows from an SDDS dataset that are not marked as "of interest".

This function removes all rows in the provided SDDS dataset that have not been flagged as "of interest" using prior selection functions. It effectively compacts the dataset by retaining only the desired rows and updating the row count accordingly.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that rows were successfully deleted.
0Indicates that an error occurred (e.g., invalid dataset, problem copying rows).
Note
  • This operation modifies the dataset in place by removing unset rows.
  • It is recommended to perform row selection before calling this function to ensure that only desired rows are retained.
See also
SDDS_SetRowsOfInterest, SDDS_MatchRowsOfInterest, SDDS_FilterRowsOfInterest

Definition at line 3760 of file SDDS_extract.c.

3760 {
3761 int64_t i, j;
3762 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_DeleteUnsetRows"))
3763 return (0);
3764
3765 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
3766 if (SDDS_dataset->row_flag[i]) {
3767 if (i != j) {
3768 SDDS_dataset->row_flag[j] = SDDS_dataset->row_flag[i];
3769 if (!SDDS_TransferRow(SDDS_dataset, j, i)) {
3770 SDDS_SetError("Unable to delete unset rows--problem copying row (SDDS_DeleteUnsetRows)");
3771 return (0);
3772 }
3773 }
3774 j++;
3775 }
3776 }
3777 SDDS_dataset->n_rows = j;
3778 return (1);
3779}
int32_t SDDS_TransferRow(SDDS_DATASET *SDDS_dataset, int64_t target, int64_t source)
Transfers data from a source row to a target row within an SDDS dataset.

◆ SDDS_DisableFSync()

epicsShareFuncSDDS void SDDS_DisableFSync ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS int32_t SDDS_DisconnectFile ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS long SDDS_DisconnectInputFile ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS int32_t SDDS_DoFSync ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS void SDDS_EnableFSync ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS int32_t SDDS_EraseData ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS void SDDS_EscapeCommentCharacters ( char * string,
char cc )
extern

Escapes comment characters within a string by inserting backslashes.

This function scans the input string string and inserts a backslash (\) before each occurrence of the specified comment character cc, provided it is not already escaped. This is useful for preparing strings to include comment characters without them being interpreted as actual comments.

Parameters
[in,out]stringPointer to the string in which comment characters will be escaped. The string will be modified in place.
[in]ccThe comment character to escape (e.g., #).
Note
The function dynamically allocates a temporary buffer to perform the escaping process and ensures that the original string string is updated correctly. The caller must ensure that string has sufficient space to accommodate the additional backslashes.
See also
SDDS_CutOutComments

Definition at line 1955 of file SDDS_utils.c.

1955 {
1956 char *ptr, *s0;
1957 s0 = string;
1958 while (*string) {
1959 if (*string == cc && (string == s0 || *(string - 1) != '\\')) {
1960 ptr = string + strlen(string) + 1;
1961 while (ptr != string) {
1962 *ptr = *(ptr - 1);
1963 ptr--;
1964 }
1965 *string++ = '\\';
1966 }
1967 string++;
1968 }
1969}

◆ SDDS_EscapeNewlines()

epicsShareFuncSDDS void SDDS_EscapeNewlines ( char * s)
extern

Escapes newline characters in a string by replacing them with "\\n".

This function modifies the input string s in place by replacing each newline character (‘’
') with the two-character sequence'\'and'n'`. It shifts the subsequent characters in the string to accommodate the additional character introduced by the escape sequence.

Parameters
[in,out]sPointer to the null-terminated string to be modified. Important: The buffer pointed to by s must have sufficient space to accommodate the additional characters resulting from the escape sequences. Failure to ensure adequate space may lead to buffer overflows.
Warning
This function does not perform bounds checking on the buffer size. Ensure that the buffer is large enough to handle the increased length after escaping newlines.
See also
SDDS_UnescapeNewlines

Definition at line 3189 of file SDDS_utils.c.

3189 {
3190 char *ptr;
3191 while (*s) {
3192 if (*s == '\n') {
3193 ptr = s + strlen(s);
3194 *(ptr + 1) = 0;
3195 while (ptr != s) {
3196 *ptr = *(ptr - 1);
3197 ptr--;
3198 }
3199 *s++ = '\\';
3200 *s++ = 'n';
3201 } else
3202 s++;
3203 }
3204}

◆ SDDS_EscapeQuotes()

epicsShareFuncSDDS void SDDS_EscapeQuotes ( char * s,
char quote_char )
extern

Escapes quote characters within a string by inserting backslashes.

This function scans the input string s and inserts a backslash (\) before each occurrence of the specified quote_char, provided it is not already escaped. This is useful for preparing strings for formats that require escaped quotes.

Parameters
[in,out]sPointer to the string in which quotes will be escaped. The string will be modified in place.
[in]quote_charThe quote character to escape (e.g., ").
Note
The function dynamically allocates a temporary buffer to perform the escaping process and ensures that the original string s is updated correctly. The caller must ensure that s has sufficient space to accommodate the additional backslashes.
See also
SDDS_UnescapeQuotes

Definition at line 1901 of file SDDS_utils.c.

1901 {
1902 char *ptr, *bptr;
1903 char *buffer = NULL;
1904
1905 ptr = s;
1906 buffer = trealloc(buffer, sizeof(*buffer) * (4 * (strlen(s) + 1)));
1907 bptr = buffer;
1908
1909 while (*ptr) {
1910 if (*ptr == quote_char && (ptr == s || *(ptr - 1) != '\\'))
1911 *bptr++ = '\\';
1912 *bptr++ = *ptr++;
1913 }
1914 *bptr = 0;
1915 strcpy(s, buffer);
1916 if (buffer)
1917 free(buffer);
1918}
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181

◆ SDDS_FileIsLocked()

epicsShareFuncSDDS int32_t SDDS_FileIsLocked ( const char * filename)
extern

Determines if a specified file is locked.

This function checks whether the given file is currently locked. If file locking is enabled through the F_TEST and ALLOW_FILE_LOCKING macros, it attempts to open the file and apply a test lock using lockf. The function returns 1 if the file is locked and 0 otherwise.

If file locking is not enabled (i.e., the F_TEST and ALLOW_FILE_LOCKING macros are not defined), the function always returns 0, indicating that the file is not locked.

Parameters
[in]filenameThe path to the file to be checked for a lock.
Returns
  • 1 if the file is locked.
  • 0 if the file is not locked or if file locking is not enabled.
Note
The effectiveness of this function depends on the platform and the implementation of file locking mechanisms.
Warning
Ensure that the F_TEST and ALLOW_FILE_LOCKING macros are appropriately defined to enable file locking functionality.
See also
SDDS_LockFile

Definition at line 3282 of file SDDS_utils.c.

3282 {
3283#if defined(F_TEST) && ALLOW_FILE_LOCKING
3284 FILE *fp;
3285 if (!(fp = fopen(filename, "rb")))
3286 return 0;
3287 if (lockf(fileno(fp), F_TEST, 0) == -1) {
3288 fclose(fp);
3289 return 1;
3290 }
3291 fclose(fp);
3292 return 0;
3293#else
3294 return 0;
3295#endif
3296}

◆ SDDS_FilterRowsByNumScan()

epicsShareFuncSDDS int64_t SDDS_FilterRowsByNumScan ( SDDS_DATASET * SDDS_dataset,
char * filter_column,
uint32_t mode )
extern

Filters rows of interest in an SDDS dataset based on numeric scanning of a specified column.

This function marks rows in the provided SDDS dataset as "of interest" based on whether the entries in the specified filter column can be interpreted as valid numbers. It supports inversion of the filtering criterion through the mode parameter.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
filter_columnA null-terminated string specifying the name of the column used for numeric scanning. This column must not be of string type.
modeAn unsigned integer representing mode flags. Supported flags include:
  • NUMSCANFILTER_INVERT: Invert the filtering criterion (select rows where the entry is not a number).
Returns
On success, returns the number of rows marked as "of interest" after filtering. On failure, returns -1 and sets an appropriate error message.
Return values
-1Indicates that an error occurred (e.g., invalid dataset, unrecognized filter column, filter column is of string type).
Non-negativeInteger representing the count of rows marked as "of interest".
Note
  • The filter column must exist and must not be of string type.
  • The function uses tokenIsNumber to determine if an entry is a valid number.
See also
SDDS_SetRowsOfInterest, SDDS_MatchRowsOfInterest, SDDS_DeleteUnsetRows

Definition at line 3697 of file SDDS_extract.c.

3697 {
3698 int32_t accept, index;
3699 int64_t i, count;
3700 short invert;
3701 char *ptr;
3702
3703 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_FilterRowsByNumScan"))
3704 return (-1);
3705 if (!filter_column) {
3706 SDDS_SetError("Unable to filter rows--filter column name not given (SDDS_FilterRowsByNumScan)");
3707 return (-1);
3708 }
3709 if ((index = SDDS_GetColumnIndex(SDDS_dataset, filter_column)) < 0) {
3710 SDDS_SetError("Unable to filter rows--column name is unrecognized (SDDS_FilterRowsByNumScan)");
3711 return (-1);
3712 }
3713 switch (SDDS_GetColumnType(SDDS_dataset, index)) {
3714 case SDDS_SHORT:
3715 case SDDS_USHORT:
3716 case SDDS_LONG:
3717 case SDDS_ULONG:
3718 case SDDS_LONG64:
3719 case SDDS_ULONG64:
3720 case SDDS_FLOAT:
3721 case SDDS_DOUBLE:
3722 case SDDS_LONGDOUBLE:
3723 case SDDS_CHARACTER:
3724 SDDS_SetError("Unable to filter rows--filter column is not string type (SDDS_FilterRowsByNumScan)");
3725 return (-1);
3726 default:
3727 break;
3728 }
3729 invert = mode & NUMSCANFILTER_INVERT ? 1 : 0;
3730 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3731 ptr = ((char **)(SDDS_dataset->data[index]))[i];
3732 accept = !invert;
3733 if (!tokenIsNumber(ptr))
3734 accept = invert;
3735 if ((SDDS_dataset->row_flag[i] = accept))
3736 count++;
3737 }
3738 return (count);
3739}
long tokenIsNumber(char *token)
Checks if the given token represents a valid number.
Definition data_scan.c:530

◆ SDDS_FilterRowsOfInterest()

epicsShareFuncSDDS int64_t SDDS_FilterRowsOfInterest ( SDDS_DATASET * SDDS_dataset,
char * filter_column,
double lower_limit,
double upper_limit,
int32_t logic )
extern

Filters rows of interest in an SDDS dataset based on numeric ranges in a specified column.

This function marks rows in the provided SDDS dataset as "of interest" if the values in the specified filter column fall within the defined numeric range (lower_limit to upper_limit). Logical operations specified by the logic parameter determine how the filtering interacts with existing row flags.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
filter_columnA null-terminated string specifying the name of the column used for numeric filtering. This column must be of a numeric type.
lower_limitThe lower bound of the numeric range. Rows with values below this limit are excluded.
upper_limitThe upper bound of the numeric range. Rows with values above this limit are excluded.
logicAn integer representing logical operation flags. Supported flags include:
  • SDDS_NEGATE_PREVIOUS: Invert the previous row flag.
  • SDDS_NEGATE_MATCH: Invert the match result.
  • SDDS_AND: Combine with existing row flags using logical AND.
  • SDDS_OR: Combine with existing row flags using logical OR.
  • SDDS_NEGATE_EXPRESSION: Invert the entire logical expression.
Returns
On success, returns the number of rows marked as "of interest" after filtering. On failure, returns -1 and sets an appropriate error message.
Return values
-1Indicates that an error occurred (e.g., invalid dataset, unrecognized filter column, non-numeric filter column).
Non-negativeInteger representing the count of rows marked as "of interest".
Note
  • The filter column must exist and be of a numeric type (e.g., SDDS_SHORT, SDDS_USHORT, SDDS_LONG, SDDS_ULONG, SDDS_LONG64, SDDS_ULONG64, SDDS_FLOAT, SDDS_DOUBLE, SDDS_LONGDOUBLE).
  • Logical flags determine how the filtering interacts with existing row flags. Multiple flags can be combined using bitwise OR.
See also
SDDS_SetRowsOfInterest, SDDS_MatchRowsOfInterest, SDDS_DeleteUnsetRows

Definition at line 3628 of file SDDS_extract.c.

3628 {
3629 int32_t accept, type, index;
3630 int64_t i, count;
3631 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_FilterRowsOfInterest"))
3632 return (-1);
3633 if (!filter_column) {
3634 SDDS_SetError("Unable to filter rows--filter column name not given (SDDS_FilterRowsOfInterest)");
3635 return (-1);
3636 }
3637 if ((index = SDDS_GetColumnIndex(SDDS_dataset, filter_column)) < 0) {
3638 SDDS_SetError("Unable to filter rows--column name is unrecognized (SDDS_FilterRowsOfInterest)");
3639 return (-1);
3640 }
3641 switch (type = SDDS_GetColumnType(SDDS_dataset, index)) {
3642 case SDDS_SHORT:
3643 case SDDS_USHORT:
3644 case SDDS_LONG:
3645 case SDDS_ULONG:
3646 case SDDS_LONG64:
3647 case SDDS_ULONG64:
3648 case SDDS_FLOAT:
3649 case SDDS_DOUBLE:
3650 case SDDS_LONGDOUBLE:
3651 break;
3652 default:
3653 SDDS_SetError("Unable to filter rows--filter column is not a numeric type (SDDS_FilterRowsOfInterest)");
3654 return (-1);
3655 }
3656 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3657 if (logic & SDDS_NEGATE_PREVIOUS)
3658 SDDS_dataset->row_flag[i] = !SDDS_dataset->row_flag[i];
3659 accept = SDDS_ItemInsideWindow(SDDS_dataset->data[index], i, type, lower_limit, upper_limit);
3660 if (logic & SDDS_NEGATE_MATCH)
3661 accept = !accept;
3662 if (logic & SDDS_AND)
3663 accept = accept && SDDS_dataset->row_flag[i];
3664 else if (logic & SDDS_OR)
3665 accept = accept || SDDS_dataset->row_flag[i];
3666 if (logic & SDDS_NEGATE_EXPRESSION)
3667 accept = !accept;
3668 if ((SDDS_dataset->row_flag[i] = accept))
3669 count++;
3670 }
3671 return (count);
3672}
int32_t SDDS_ItemInsideWindow(void *data, int64_t index, int32_t type, double lower_limit, double upper_limit)
Checks whether a data item is within a specified numeric window.

◆ SDDS_FindArray()

epicsShareFuncSDDS char * SDDS_FindArray ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Finds the first array in the SDDS dataset that matches the specified criteria.

This function searches through the arrays of the provided SDDS dataset and returns the name of the first array that matches the given criteria based on the specified mode.

The function supports the following modes:

  • FIND_SPECIFIED_TYPE:
    • Parameters: int32_t type, char *name1, char *name2, ..., NULL
    • Description: Finds the first array with a specified type among the provided array names.
  • FIND_ANY_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first array with any type among the provided array names.
  • FIND_NUMERIC_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first array with a numeric type among the provided array names.
  • FIND_FLOATING_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first array with a floating type among the provided array names.
  • FIND_INTEGER_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first array with an integer type among the provided array names.
Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset.
[in]modeSpecifies the mode for matching arrays. Valid modes are:
  • FIND_SPECIFIED_TYPE
  • FIND_ANY_TYPE
  • FIND_NUMERIC_TYPE
  • FIND_FLOATING_TYPE
  • FIND_INTEGER_TYPE
[in]...Variable arguments depending on mode:
  • FIND_SPECIFIED_TYPE: int32_t type, followed by a list of array names (char *name1, char *name2, ..., NULL)
  • Other Modes: A list of array names (char *name1, char *name2, ..., NULL)
Returns
  • On success, returns a dynamically allocated string containing the name of the first matched array.
  • Returns NULL if no matching array is found or if an error occurs (e.g., memory allocation failure).
Note
  • The caller is responsible for freeing the memory allocated for the returned string using free() or an appropriate memory deallocation function.
  • Ensure that the SDDS dataset is properly initialized and contains arrays before calling this function.
Warning
  • Ensure that the variable arguments match the expected parameters for the specified mode.
  • Failure to free the returned string may lead to memory leaks.
See also
SDDS_FindColumn, SDDS_FindParameter, SDDS_MatchArrays, SDDS_SetError

Definition at line 4491 of file SDDS_utils.c.

4491 {
4492 int32_t index, error, type, thisType;
4493 va_list argptr;
4494 char *name, *buffer;
4495
4496 va_start(argptr, mode);
4497 buffer = NULL;
4498 error = type = 0;
4499
4500 if (mode == FIND_SPECIFIED_TYPE)
4501 type = va_arg(argptr, int32_t);
4502 while ((name = va_arg(argptr, char *))) {
4503 if ((index = SDDS_GetArrayIndex(SDDS_dataset, name)) >= 0) {
4504 thisType = SDDS_GetArrayType(SDDS_dataset, index);
4505 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE && SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE && SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE && SDDS_INTEGER_TYPE(thisType))) {
4506 if (!SDDS_CopyString(&buffer, name)) {
4507 SDDS_SetError("unable to return string from SDDS_FindArray");
4508 error = 1;
4509 break;
4510 }
4511 error = 0;
4512 break;
4513 }
4514 }
4515 }
4516 va_end(argptr);
4517 if (error)
4518 return NULL;
4519 return buffer;
4520}

◆ SDDS_FindColumn()

epicsShareFuncSDDS char * SDDS_FindColumn ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Finds the first column in the SDDS dataset that matches the specified criteria.

This function searches through the columns of the provided SDDS dataset and returns the name of the first column that matches the given criteria based on the specified mode.

The function supports the following modes:

  • FIND_SPECIFIED_TYPE:
    • Parameters: int32_t type, char *name1, char *name2, ..., NULL
    • Description: Finds the first column with a specified type among the provided column names.
  • FIND_ANY_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first column with any type among the provided column names.
  • FIND_NUMERIC_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first column with a numeric type among the provided column names.
  • FIND_FLOATING_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first column with a floating type among the provided column names.
  • FIND_INTEGER_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first column with an integer type among the provided column names.
Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset.
[in]modeSpecifies the mode for matching columns. Valid modes are:
  • FIND_SPECIFIED_TYPE
  • FIND_ANY_TYPE
  • FIND_NUMERIC_TYPE
  • FIND_FLOATING_TYPE
  • FIND_INTEGER_TYPE
[in]...Variable arguments depending on mode:
  • FIND_SPECIFIED_TYPE: int32_t type, followed by a list of column names (char *name1, char *name2, ..., NULL)
  • Other Modes: A list of column names (char *name1, char *name2, ..., NULL)
Returns
  • On success, returns a dynamically allocated string containing the name of the first matched column.
  • Returns NULL if no matching column is found or if an error occurs (e.g., memory allocation failure).
Note
  • The caller is responsible for freeing the memory allocated for the returned string using free() or an appropriate memory deallocation function.
  • Ensure that the SDDS dataset is properly initialized and contains columns before calling this function.
Warning
  • Ensure that the variable arguments match the expected parameters for the specified mode.
  • Failure to free the returned string may lead to memory leaks.
See also
SDDS_FindParameter, SDDS_FindArray, SDDS_MatchColumns, SDDS_SetError

Definition at line 4312 of file SDDS_utils.c.

4312 {
4313 /*
4314 SDDS_DATASET *SDDS_dataset, FIND_SPECIFIED_TYPE, int32_t type, char*, ..., NULL)
4315 SDDS_DATASET *SDDS_dataset, FIND_ANY_TYPE, char*, ..., NULL)
4316 */
4317 int32_t index;
4318 int32_t error, type, thisType;
4319 va_list argptr;
4320 char *name, *buffer;
4321
4322 va_start(argptr, mode);
4323 buffer = NULL;
4324 error = type = 0;
4325
4326 if (mode == FIND_SPECIFIED_TYPE)
4327 type = va_arg(argptr, int32_t);
4328 while ((name = va_arg(argptr, char *))) {
4329 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) >= 0) {
4330 thisType = SDDS_GetColumnType(SDDS_dataset, index);
4331 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE && SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE && SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE && SDDS_INTEGER_TYPE(thisType))) {
4332 if (!SDDS_CopyString(&buffer, name)) {
4333 SDDS_SetError("unable to return string from SDDS_FindColumn");
4334 error = 1;
4335 break;
4336 }
4337 error = 0;
4338 break;
4339 }
4340 }
4341 }
4342 va_end(argptr);
4343 if (error)
4344 return NULL;
4345 return buffer;
4346}

◆ SDDS_FindParameter()

epicsShareFuncSDDS char * SDDS_FindParameter ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Finds the first parameter in the SDDS dataset that matches the specified criteria.

This function searches through the parameters of the provided SDDS dataset and returns the name of the first parameter that matches the given criteria based on the specified mode.

The function supports the following modes:

  • FIND_SPECIFIED_TYPE:
    • Parameters: int32_t type, char *name1, char *name2, ..., NULL
    • Description: Finds the first parameter with a specified type among the provided parameter names.
  • FIND_ANY_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first parameter with any type among the provided parameter names.
  • FIND_NUMERIC_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first parameter with a numeric type among the provided parameter names.
  • FIND_FLOATING_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first parameter with a floating type among the provided parameter names.
  • FIND_INTEGER_TYPE:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Finds the first parameter with an integer type among the provided parameter names.
Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset.
[in]modeSpecifies the mode for matching parameters. Valid modes are:
  • FIND_SPECIFIED_TYPE
  • FIND_ANY_TYPE
  • FIND_NUMERIC_TYPE
  • FIND_FLOATING_TYPE
  • FIND_INTEGER_TYPE
[in]...Variable arguments depending on mode:
  • FIND_SPECIFIED_TYPE: int32_t type, followed by a list of parameter names (char *name1, char *name2, ..., NULL)
  • Other Modes: A list of parameter names (char *name1, char *name2, ..., NULL)
Returns
  • On success, returns a dynamically allocated string containing the name of the first matched parameter.
  • Returns NULL if no matching parameter is found or if an error occurs (e.g., memory allocation failure).
Note
  • The caller is responsible for freeing the memory allocated for the returned string using free() or an appropriate memory deallocation function.
  • Ensure that the SDDS dataset is properly initialized and contains parameters before calling this function.
Warning
  • Ensure that the variable arguments match the expected parameters for the specified mode.
  • Failure to free the returned string may lead to memory leaks.
See also
SDDS_FindColumn, SDDS_FindArray, SDDS_MatchParameters, SDDS_SetError

Definition at line 4404 of file SDDS_utils.c.

4404 {
4405 int32_t index, error, type, thisType;
4406 va_list argptr;
4407 char *name, *buffer;
4408
4409 va_start(argptr, mode);
4410 buffer = NULL;
4411 error = type = 0;
4412
4413 if (mode == FIND_SPECIFIED_TYPE)
4414 type = va_arg(argptr, int32_t);
4415 while ((name = va_arg(argptr, char *))) {
4416 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) >= 0) {
4417 thisType = SDDS_GetParameterType(SDDS_dataset, index);
4418 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE && SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE && SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE && SDDS_INTEGER_TYPE(thisType))) {
4419 if (!SDDS_CopyString(&buffer, name)) {
4420 SDDS_SetError("unable to return string from SDDS_FindParameter");
4421 error = 1;
4422 break;
4423 }
4424 error = 0;
4425 break;
4426 }
4427 }
4428 }
4429 va_end(argptr);
4430 if (error)
4431 return NULL;
4432 return buffer;
4433}

◆ SDDS_FlushBuffer()

epicsShareFuncSDDS int32_t SDDS_FlushBuffer ( FILE * fp,
SDDS_FILEBUFFER * fBuffer )
extern

Flushes the buffered data to a file to ensure all data is written.

This function writes any remaining data in the buffer (fBuffer) to the file pointed to by fp. If the buffer contains data, it writes the data to the file, resets the buffer, and flushes the file's output buffer using fflush. This ensures that all buffered data is physically written to the file.

Parameters
fpThe file pointer to which buffered data will be written.
fBufferPointer to an SDDS_FILEBUFFER structure containing the buffered data.
Returns
Returns 1 on success; returns 0 on error.
Note
If fBuffer->bufferSize is zero, the function will only call fflush(fp).
Warning
If fp or fBuffer is NULL, the function sets an error message and returns 0.

Definition at line 632 of file SDDS_binary.c.

632 {
633 int64_t writeBytes;
634 if (!fp) {
635 SDDS_SetError("Unable to flush buffer: file pointer is NULL. (SDDS_FlushBuffer)");
636 return 0;
637 }
638 if (!fBuffer->bufferSize) {
639 if (fflush(fp)) {
640 SDDS_SetError("Problem flushing file (SDDS_FlushBuffer.1)");
641 SDDS_SetError(strerror(errno));
642 return 0;
643 }
644 return 1;
645 }
646 if (!fBuffer) {
647 SDDS_SetError("Unable to flush buffer: buffer pointer is NULL. (SDDS_FlushBuffer)");
648 return 0;
649 }
650 if ((writeBytes = fBuffer->bufferSize - fBuffer->bytesLeft)) {
651 if (writeBytes < 0) {
652 SDDS_SetError("Unable to flush buffer: negative byte count (SDDS_FlushBuffer).");
653 return 0;
654 }
655#ifdef DEBUG
656 fprintf(stderr, "Writing %" PRId64 " bytes to disk\n", writeBytes);
657#endif
658 if (fwrite(fBuffer->buffer, 1, writeBytes, fp) != writeBytes) {
659 SDDS_SetError("Unable to flush buffer: write operation failed (SDDS_FlushBuffer).");
660 return 0;
661 }
662 fBuffer->bytesLeft = fBuffer->bufferSize;
663 fBuffer->data = fBuffer->buffer;
664 }
665 if (fflush(fp)) {
666 SDDS_SetError("Problem flushing file (SDDS_FlushBuffer.2)");
667 SDDS_SetError(strerror(errno));
668 return 0;
669 }
670 return 1;
671}

◆ SDDS_ForceInactive()

epicsShareFuncSDDS int32_t SDDS_ForceInactive ( SDDS_DATASET * SDDS_dataset)
extern

Marks an SDDS dataset as inactive.

This function forces the provided SDDS dataset to become inactive by setting its file pointer to NULL. An inactive dataset is typically not associated with any open file operations.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure to be marked as inactive.
Returns
  • 1 on successful operation.
  • -1 if a NULL pointer is passed, indicating an error.
Note
After calling this function, the dataset will be considered inactive, and any subsequent operations that require an active dataset may fail.
See also
SDDS_IsActive, SDDS_SetError

Definition at line 3223 of file SDDS_utils.c.

3223 {
3224 if (!SDDS_dataset) {
3225 SDDS_SetError("NULL SDDS_DATASET passed (SDDS_ForceInactive)");
3226 return (-1);
3227 }
3228 SDDS_dataset->layout.fp = NULL;
3229 return (1);
3230}

◆ SDDS_Free()

epicsShareFuncSDDS void SDDS_Free ( void * mem)
extern

Free memory previously allocated by SDDS_Malloc.

This function frees memory that wsa previously allocated by SDDS_Malloc.

Parameters
[in]memPointer to the memory block.
See also
SDDS_Malloc
SDDS_Calloc

Definition at line 655 of file SDDS_utils.c.

655 {
656 /* this is required so the free will be consistent with the malloc.
657 On WIN32 the release (optimized) version of malloc is different
658 from the debug (unoptimized) version, so debug programs freeing
659 memory that was allocated by release, library routines encounter
660 problems. */
661 free(mem);
662}

◆ SDDS_FreeArray()

epicsShareFuncSDDS void SDDS_FreeArray ( SDDS_ARRAY * array)
extern

Frees memory allocated for an SDDS array structure.

This function deallocates all memory associated with an SDDS_ARRAY structure, including its data and definition. It handles the freeing of string elements if the array type is SDDS_STRING and ensures that all pointers are set to NULL after deallocation to prevent dangling references.

Parameters
[in]arrayPointer to the SDDS_ARRAY structure to be freed.
Note
  • The function assumes that the array's data and definitions were allocated using SDDS memory management functions.
  • After calling this function, the array pointer becomes invalid and should not be used.
See also
SDDS_FreePointerArray
SDDS_FreeArrayDefinition
SDDS_Free

Definition at line 2766 of file SDDS_utils.c.

2766 {
2767 int i;
2768 if (!array)
2769 return;
2770 if (array->definition) {
2771 if ((array->definition->type == SDDS_STRING) && (array->data)) {
2772 char **str = (char **)array->data;
2773 for (i = 0; i < array->elements; i++) {
2774 if (str[i])
2775 free(str[i]);
2776 str[i] = NULL;
2777 }
2778 }
2779 }
2780 if (array->definition && array->pointer)
2781 SDDS_FreePointerArray(array->pointer, array->definition->dimensions, array->dimension);
2782 if (array->data)
2783 free(array->data);
2784 array->pointer = array->data = NULL;
2785 if (array->dimension)
2786 free(array->dimension);
2787 if (array->definition)
2788 SDDS_FreeArrayDefinition(array->definition);
2789 array->definition = NULL;
2790 free(array);
2791 array = NULL;
2792}
void SDDS_FreePointerArray(void **data, int32_t dimensions, int32_t *dimension)
Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.

◆ SDDS_FreeArrayDefinition()

epicsShareFuncSDDS int32_t SDDS_FreeArrayDefinition ( ARRAY_DEFINITION * source)
extern

Frees memory allocated for an array definition.

This function deallocates all memory associated with an ARRAY_DEFINITION structure, including its string fields. After freeing, the structure is zeroed out to prevent dangling pointers.

Parameters
[in]sourcePointer to the ARRAY_DEFINITION structure to be freed.
Returns
Returns 1 on successful deallocation. Returns 0 if the source is NULL.
Note
After calling this function, the source pointer becomes invalid and should not be used.
See also
SDDS_CopyArrayDefinition
SDDS_Free

Definition at line 1238 of file SDDS_utils.c.

1238 {
1239 if (!source)
1240 return (0);
1241 if (source->name)
1242 free(source->name);
1243 if (source->symbol)
1244 free(source->symbol);
1245 if (source->units)
1246 free(source->units);
1247 if (source->description)
1248 free(source->description);
1249 if (source->format_string)
1250 free(source->format_string);
1251 if (source->group_name)
1252 free(source->group_name);
1253 SDDS_ZeroMemory(source, sizeof(*source));
1254 free(source);
1255 source = NULL;
1256 return (1);
1257}

◆ SDDS_FreeAssociateDefinition()

epicsShareFuncSDDS int32_t SDDS_FreeAssociateDefinition ( ASSOCIATE_DEFINITION * source)
extern

Frees memory allocated for an associate definition.

This function deallocates all memory associated with an ASSOCIATE_DEFINITION structure, including its string fields. After freeing, the structure is zeroed out to prevent dangling pointers.

Parameters
[in]sourcePointer to the ASSOCIATE_DEFINITION structure to be freed.
Returns
Returns 1 on successful deallocation. Returns 0 if the source is NULL or if required fields are missing.
Note
After calling this function, the source pointer becomes invalid and should not be used.
See also
SDDS_CopyAssociateDefinition
SDDS_Free

Definition at line 944 of file SDDS_utils.c.

944 {
945 if (!source->name)
946 return (0);
947 free(source->name);
948 if (!source->filename)
949 return (0);
950 free(source->filename);
951 if (source->path)
952 free(source->path);
953 if (source->description)
954 free(source->description);
955 if (source->contents)
956 free(source->contents);
957 SDDS_ZeroMemory(source, sizeof(*source));
958 free(source);
959 return (1);
960}

◆ SDDS_FreeColumnDefinition()

epicsShareFuncSDDS int32_t SDDS_FreeColumnDefinition ( COLUMN_DEFINITION * source)
extern

Frees memory allocated for a column definition.

This function deallocates all memory associated with a COLUMN_DEFINITION structure, including its string fields. After freeing, the structure is zeroed out to prevent dangling pointers.

Parameters
[in]sourcePointer to the COLUMN_DEFINITION structure to be freed.
Returns
Returns 1 on successful deallocation. Returns 0 if the source is NULL or if required fields are missing.
Note
After calling this function, the source pointer becomes invalid and should not be used.
See also
SDDS_CopyColumnDefinition
SDDS_Free

Definition at line 1042 of file SDDS_utils.c.

1042 {
1043 if (!source || !source->name)
1044 return (0);
1045 free(source->name);
1046 if (source->symbol)
1047 free(source->symbol);
1048 if (source->units)
1049 free(source->units);
1050 if (source->description)
1051 free(source->description);
1052 if (source->format_string)
1053 free(source->format_string);
1054 SDDS_ZeroMemory(source, sizeof(*source));
1055 free(source);
1056 return (1);
1057}

◆ SDDS_FreeMatrix()

epicsShareFuncSDDS void SDDS_FreeMatrix ( void ** ptr,
int64_t dim1 )
extern

Frees memory allocated for a two-dimensional matrix.

This function deallocates a two-dimensional matrix by freeing each row individually followed by the matrix pointer itself.

Parameters
[in]ptrPointer to the two-dimensional matrix to be freed.
[in]dim1The number of rows in the matrix.
Note
  • The function assumes that the matrix was allocated using SDDS_AllocateMatrix or similar memory allocation functions.
See also
SDDS_AllocateMatrix
free

Definition at line 2808 of file SDDS_utils.c.

2808 {
2809 int64_t i;
2810 if (!ptr)
2811 return;
2812 for (i = 0; i < dim1; i++)
2813 free(ptr[i]);
2814 free(ptr);
2815}

◆ SDDS_FreeParameterDefinition()

epicsShareFuncSDDS int32_t SDDS_FreeParameterDefinition ( PARAMETER_DEFINITION * source)
extern

Frees memory allocated for a parameter definition.

This function deallocates all memory associated with a PARAMETER_DEFINITION structure, including its string fields. After freeing, the structure is zeroed out to prevent dangling pointers.

Parameters
[in]sourcePointer to the PARAMETER_DEFINITION structure to be freed.
Returns
Returns 1 on successful deallocation. Returns 0 if the source is NULL or if required fields are missing.
Note
After calling this function, the source pointer becomes invalid and should not be used.
See also
SDDS_CopyParameterDefinition
SDDS_Free

Definition at line 1139 of file SDDS_utils.c.

1139 {
1140 if (!source || !source->name)
1141 return (0);
1142 free(source->name);
1143 if (source->symbol)
1144 free(source->symbol);
1145 if (source->units)
1146 free(source->units);
1147 if (source->description)
1148 free(source->description);
1149 if (source->format_string)
1150 free(source->format_string);
1151 if (source->fixed_value)
1152 free(source->fixed_value);
1153 SDDS_ZeroMemory(source, sizeof(*source));
1154 free(source);
1155 return (1);
1156}

◆ SDDS_FreeStringArray()

epicsShareFuncSDDS int32_t SDDS_FreeStringArray ( char ** string,
int64_t strings )
extern

Frees an array of strings by deallocating each individual string.

This function iterates through an array of strings, freeing each non-NULL string and setting its pointer to NULL to prevent dangling references.

Parameters
[in,out]stringArray of strings to be freed.
[in]stringsThe number of elements in the string array.
Returns
  • Returns 1 if the array is successfully freed.
  • Returns 0 if the string pointer is NULL.
Note
  • After calling this function, all string pointers within the array are set to NULL.
See also
SDDS_Free
free

Definition at line 2865 of file SDDS_utils.c.

2865 {
2866 int64_t i;
2867 if (!string)
2868 return 0;
2869 for (i = 0; i < strings; i++)
2870 if (string[i]) {
2871 free(string[i]);
2872 string[i] = NULL;
2873 }
2874 return 1;
2875}

◆ SDDS_FreeStringData()

epicsShareFuncSDDS int32_t SDDS_FreeStringData ( SDDS_DATASET * SDDS_dataset)
extern

Frees all allocated string data in the SDDS dataset.

This function frees any strings allocated for parameters, arrays, and columns within the SDDS dataset. It is typically called during termination to clean up allocated memory.

Parameters
SDDS_datasetThe SDDS dataset to free string data from.
Returns
Returns 1 on success, 0 on failure.

Definition at line 1374 of file SDDS_input.c.

1374 {
1375 SDDS_LAYOUT *layout;
1376 char **ptr;
1377 int64_t i, j;
1378 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_Terminate"))
1379 return (0);
1380 layout = &SDDS_dataset->original_layout;
1381
1382 if (SDDS_dataset->parameter) {
1383 for (i = 0; i < layout->n_parameters; i++) {
1384 if (layout->parameter_definition[i].type == SDDS_STRING) {
1385 free(*(char **)(SDDS_dataset->parameter[i]));
1386 *(char **)(SDDS_dataset->parameter[i]) = NULL;
1387 }
1388 }
1389 }
1390 if (SDDS_dataset->array) {
1391 for (i = 0; i < layout->n_arrays; i++) {
1392 if (layout->array_definition[i].type == SDDS_STRING) {
1393 for (j = 0; j < SDDS_dataset->array[i].elements; j++)
1394 if (((char **)SDDS_dataset->array[i].data)[j]) {
1395 free(((char **)SDDS_dataset->array[i].data)[j]);
1396 ((char **)SDDS_dataset->array[i].data)[j] = NULL;
1397 }
1398 }
1399 }
1400 }
1401 if (SDDS_dataset->data) {
1402 for (i = 0; i < layout->n_columns; i++)
1403 if (SDDS_dataset->data[i]) {
1404 if (layout->column_definition[i].type == SDDS_STRING) {
1405 ptr = (char **)SDDS_dataset->data[i];
1406 for (j = 0; j < SDDS_dataset->n_rows_allocated; j++, ptr++)
1407 if (*ptr) {
1408 free(*ptr);
1409 *ptr = NULL;
1410 }
1411 }
1412 }
1413 }
1414 return (1);
1415}

◆ SDDS_GetArray()

epicsShareFuncSDDS SDDS_ARRAY * SDDS_GetArray ( SDDS_DATASET * SDDS_dataset,
char * array_name,
SDDS_ARRAY * memory )
extern

Retrieves an array from the current data table of an SDDS dataset.

This function returns a pointer to a SDDS_ARRAY structure containing the data and other information about a specified array within the current data table of an SDDS dataset. The function can either populate a provided SDDS_ARRAY structure or allocate a new one if memory is NULL.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
array_nameA null-terminated string specifying the name of the SDDS array to retrieve.
memoryOptional pointer to an existing SDDS_ARRAY structure where the array information will be stored. If NULL, a new SDDS_ARRAY structure is allocated and returned.
Returns
On success, returns a pointer to a SDDS_ARRAY structure containing the array data and metadata. If memory is not NULL, the function populates the provided structure. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, unrecognized array name, memory allocation failure).
Non-NULLPointer to a SDDS_ARRAY structure containing the array data and metadata.
Note
  • The caller is responsible for freeing the allocated memory for the SDDS_ARRAY structure if memory is NULL.
  • The definition field in the returned structure points to the internal copy of the array definition.
See also
SDDS_GetArrayInDoubles, SDDS_GetArrayInString, SDDS_GetArrayInLong

Definition at line 4209 of file SDDS_extract.c.

4209 {
4210 int32_t index, type, size;
4211 SDDS_ARRAY *copy, *original;
4212
4213 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArray"))
4214 return (NULL);
4215 if (!array_name) {
4216 SDDS_SetError("Unable to get array--array name pointer is NULL (SDDS_GetArray)");
4217 return (NULL);
4218 }
4219 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
4220 SDDS_SetError("Unable to get array--array name is unrecognized (SDDS_GetArray)");
4221 return (NULL);
4222 }
4223 if (memory)
4224 copy = memory;
4225 else if (!(copy = (SDDS_ARRAY *)calloc(1, sizeof(*copy)))) {
4226 SDDS_SetError("Unable to get array--allocation failure (SDDS_GetArray)");
4227 return (NULL);
4228 }
4229 original = SDDS_dataset->array + index;
4230 if (copy->definition && !SDDS_FreeArrayDefinition(copy->definition)) {
4231 SDDS_SetError("Unable to get array--array definition corrupted (SDDS_GetArray)");
4232 return (NULL);
4233 }
4234 if (!SDDS_CopyArrayDefinition(&copy->definition, original->definition)) {
4235 SDDS_SetError("Unable to get array--array definition missing (SDDS_GetArray)");
4236 return (NULL);
4237 }
4238 type = copy->definition->type;
4239 size = SDDS_type_size[copy->definition->type - 1];
4240 if (!(copy->dimension = SDDS_Realloc(copy->dimension, sizeof(*copy->dimension) * copy->definition->dimensions))) {
4241 SDDS_SetError("Unable to get array--allocation failure (SDDS_GetArray)");
4242 return (NULL);
4243 }
4244 memcpy((void *)copy->dimension, (void *)original->dimension, sizeof(*copy->dimension) * copy->definition->dimensions);
4245 if (!(copy->elements = original->elements))
4246 return (copy);
4247 if (!(copy->data = SDDS_Realloc(copy->data, size * original->elements))) {
4248 SDDS_SetError("Unable to get array--allocation failure (SDDS_GetArray)");
4249 return (NULL);
4250 }
4251
4252 if (copy->definition->type != SDDS_STRING)
4253 memcpy(copy->data, original->data, size * copy->elements);
4254 else if (!SDDS_CopyStringArray((char **)copy->data, (char **)original->data, original->elements)) {
4255 SDDS_SetError("Unable to get array--string copy failure (SDDS_GetArray)");
4256 return (NULL);
4257 }
4258
4259 /* should free existing subpointers here, but probably not worth the trouble */
4260 if (copy->pointer && copy->definition->dimensions != 1)
4261 free(copy->pointer);
4262 if (!(copy->pointer = SDDS_MakePointerArray(copy->data, type, copy->definition->dimensions, copy->dimension))) {
4263 SDDS_SetError("Unable to get array--couldn't make pointer array (SDDS_GetArray)");
4264 return (NULL);
4265 }
4266 return (copy);
4267}
ARRAY_DEFINITION * SDDS_CopyArrayDefinition(ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
Creates a copy of an array definition.
void * SDDS_MakePointerArray(void *data, int32_t type, int32_t dimensions, int32_t *dimension)
Creates a multi-dimensional pointer array from a contiguous data block.

◆ SDDS_GetArrayDefinition()

epicsShareFuncSDDS ARRAY_DEFINITION * SDDS_GetArrayDefinition ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the definition of a specified array from the SDDS dataset.

This function searches for an array by its name within the provided SDDS dataset. If found, it creates a copy of the array's definition and returns a pointer to it. The returned pointer should be freed by the caller using SDDS_FreeArrayDefinition to avoid memory leaks.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the array to retrieve.
Returns
On success, returns a pointer to a newly allocated ARRAY_DEFINITION structure containing the array's information. On failure (e.g., if the array is not found or a copy fails), returns NULL and records an error message.
Note
The caller is responsible for freeing the returned ARRAY_DEFINITION pointer using SDDS_FreeArrayDefinition.
See also
SDDS_CopyArrayDefinition
SDDS_FreeArrayDefinition
SDDS_SetError

Definition at line 1174 of file SDDS_utils.c.

1174 {
1175 int32_t i;
1176 ARRAY_DEFINITION *arraydef;
1177 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayDefinition"))
1178 return (NULL);
1179 if (!name) {
1180 SDDS_SetError("Unable to get array definition--name is NULL (SDDS_GetArrayDefinition)");
1181 return (NULL);
1182 }
1183 if ((i = SDDS_GetArrayIndex(SDDS_dataset, name)) < 0)
1184 return NULL;
1185 if (!SDDS_CopyArrayDefinition(&arraydef, SDDS_dataset->layout.array_definition + i)) {
1186 SDDS_SetError("Unable to get array definition--copy failure (SDDS_GetArrayDefinition)");
1187 return (NULL);
1188 }
1189 return (arraydef);
1190}

◆ SDDS_GetArrayIndex()

epicsShareFuncSDDS int32_t SDDS_GetArrayIndex ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the index of a named array in the SDDS dataset.

This function searches for an array by its name within the provided SDDS dataset and returns its index. The index can then be used with other routines for faster access to the array's data or metadata.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the array whose index is desired.
Returns
On success, returns a non-negative integer representing the index of the array. On failure (e.g., if the array is not found), returns -1 and records an error message.
See also
SDDS_GetArrayDefinition
SDDS_SetError

Definition at line 1367 of file SDDS_utils.c.

1367 {
1368 int32_t i;
1369 SORTED_INDEX key;
1370
1371 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayIndex"))
1372 return (-1);
1373 if (!name) {
1374 SDDS_SetError("Unable to get array index--name is NULL (SDDS_GetArrayIndex)");
1375 return (-1);
1376 }
1377 key.name = name;
1378 if ((i = binaryIndexSearch((void **)SDDS_dataset->layout.array_index, SDDS_dataset->layout.n_arrays, &key, SDDS_CompareIndexedNames, 0)) < 0)
1379 return -1;
1380 return SDDS_dataset->layout.array_index[i]->index;
1381}
long binaryIndexSearch(void **array, long members, void *key, int(*compare)(const void *c1, const void *c2), long bracket)
Searches for a key in a sorted array of pointers using binary search.
Definition binsert.c:98

◆ SDDS_GetArrayInDoubles()

epicsShareFuncSDDS double * SDDS_GetArrayInDoubles ( SDDS_DATASET * SDDS_dataset,
char * array_name,
int32_t * values )
extern

Retrieves an array from the current data table of an SDDS dataset and converts its elements to doubles.

This function extracts the specified array from the provided SDDS dataset and converts each of its elements into a double value. It ensures that the array is of a compatible numeric type before performing the conversion.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
array_nameA null-terminated string specifying the name of the SDDS array to retrieve and convert.
valuesPointer to an integer where the number of elements in the array will be stored upon successful completion.
Returns
On success, returns a pointer to an array of double values representing the SDDS array elements. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, unrecognized array name, incompatible array type, memory allocation failure).
Non-NULLPointer to an array of double values representing the SDDS array elements.
Note
  • The caller is responsible for freeing the allocated memory for the returned double array.
  • The function does not handle string-type arrays; attempting to retrieve a string array will result in an error.
See also
SDDS_GetArray, SDDS_GetArrayInString, SDDS_GetArrayInLong

Definition at line 4413 of file SDDS_extract.c.

4413 {
4414 int32_t index, type, i, elements;
4415 SDDS_ARRAY *original;
4416 double *data;
4417 void *rawData;
4418
4419 *values = 0;
4420 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayInDoubles"))
4421 return (NULL);
4422 if (!array_name) {
4423 SDDS_SetError("Unable to get array--array name pointer is NULL (SDDS_GetArrayInDoubles)");
4424 return (NULL);
4425 }
4426 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
4427 SDDS_SetError("Unable to get array--array name is unrecognized (SDDS_GetArrayInDoubles)");
4428 return (NULL);
4429 }
4430 original = SDDS_dataset->array + index;
4431 if ((type = original->definition->type) == SDDS_STRING) {
4432 SDDS_SetError("Unable to get array--string type (SDDS_GetArrayInDoubles)");
4433 return (NULL);
4434 }
4435 elements = original->elements;
4436 if (!(data = SDDS_Malloc(sizeof(*data) * elements))) {
4437 SDDS_SetError("Unable to get array--allocation failure (SDDS_GetArrayInDoubles)");
4438 return (NULL);
4439 }
4440 rawData = original->data;
4441 switch (type) {
4442 case SDDS_LONGDOUBLE:
4443 for (i = 0; i < elements; i++) {
4444 data[i] = ((long double *)rawData)[i];
4445 }
4446 break;
4447 case SDDS_DOUBLE:
4448 for (i = 0; i < elements; i++) {
4449 data[i] = ((double *)rawData)[i];
4450 }
4451 break;
4452 case SDDS_FLOAT:
4453 for (i = 0; i < elements; i++) {
4454 data[i] = ((float *)rawData)[i];
4455 }
4456 break;
4457 case SDDS_LONG64:
4458 for (i = 0; i < elements; i++) {
4459 data[i] = ((int64_t *)rawData)[i];
4460 }
4461 break;
4462 case SDDS_ULONG64:
4463 for (i = 0; i < elements; i++) {
4464 data[i] = ((uint64_t *)rawData)[i];
4465 }
4466 break;
4467 case SDDS_LONG:
4468 for (i = 0; i < elements; i++) {
4469 data[i] = ((int32_t *)rawData)[i];
4470 }
4471 break;
4472 case SDDS_ULONG:
4473 for (i = 0; i < elements; i++) {
4474 data[i] = ((uint32_t *)rawData)[i];
4475 }
4476 break;
4477 case SDDS_SHORT:
4478 for (i = 0; i < elements; i++) {
4479 data[i] = ((short *)rawData)[i];
4480 }
4481 break;
4482 case SDDS_USHORT:
4483 for (i = 0; i < elements; i++) {
4484 data[i] = ((unsigned short *)rawData)[i];
4485 }
4486 break;
4487 case SDDS_CHARACTER:
4488 for (i = 0; i < elements; i++) {
4489 data[i] = ((char *)rawData)[i];
4490 }
4491 break;
4492 }
4493 *values = elements;
4494 return data;
4495}

◆ SDDS_GetArrayInformation()

epicsShareFuncSDDS int32_t SDDS_GetArrayInformation ( SDDS_DATASET * SDDS_dataset,
char * field_name,
void * memory,
int32_t mode,
... )
extern

Retrieves information about a specified array in the SDDS dataset.

This function is the preferred alternative to SDDS_GetArrayDefinition. It allows you to obtain information about a specific field of an array, either by the array's name or index.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]field_nameA null-terminated string specifying the name of the field for which information is requested.
[out]memoryPointer to a variable where the retrieved information will be stored. The variable should be of type data_type*, where data_type corresponds to the type of the requested information. For STRING information, use char*. If memory is NULL, the function will verify the existence and type of the information, returning the data type without storing any data.
[in]modeSpecifies how to identify the array. Valid values are:
  • SDDS_GET_BY_NAME: Identify the array by its name. Requires an additional argument of type char* (array name).
  • SDDS_GET_BY_INDEX: Identify the array by its index. Requires an additional argument of type int32_t (array index).
Returns
On success, returns the SDDS data type of the requested information. On failure, returns zero and records an error message.
Note
This function uses variable arguments to accept either the array name or index based on the mode parameter.
See also
SDDS_GetArrayDefinition

Definition at line 192 of file SDDS_info.c.

192 {
193 int32_t field_index, type, array_index;
194 ARRAY_DEFINITION *arraydef;
195 char *array_name;
196 va_list argptr;
197 int32_t retval;
198
199 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayInformation"))
200 return (0);
201
202 if (!field_name) {
203 SDDS_SetError("NULL field name passed. (SDDS_GetArrayInformation)");
204 return (0);
205 }
206
207 va_start(argptr, mode);
208 retval = 1;
209 if (mode & SDDS_GET_BY_INDEX) {
210 if ((array_index = va_arg(argptr, int32_t)) < 0 || array_index >= SDDS_dataset->layout.n_arrays) {
211 SDDS_SetError("Invalid array index passed. (SDDS_GetArrayInformation)");
212 retval = 0;
213 }
214 } else {
215 if (!(array_name = va_arg(argptr, char *))) {
216 SDDS_SetError("NULL array name passed. (SDDS_GetArrayInformation)");
217 retval = 0;
218 }
219 if ((array_index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
220 SDDS_SetError("Unknown array name given (SDDS_GetArrayInformation)");
221 retval = 0;
222 }
223 }
224 arraydef = SDDS_dataset->layout.array_definition + array_index;
225 va_end(argptr);
226 if (!retval)
227 return (0);
228
229 for (field_index = 0; field_index < SDDS_ARRAY_FIELDS; field_index++)
230 if (strcmp(field_name, SDDS_ArrayFieldInformation[field_index].name) == 0)
231 break;
232 if (field_index == SDDS_ARRAY_FIELDS) {
233 SDDS_SetError("Unknown field name given (SDDS_GetArrayInformation)");
234 return (0);
235 }
236 type = SDDS_ArrayFieldInformation[field_index].type;
237 if (!memory)
238 return (type);
239 if (type == SDDS_STRING) {
240 if (!SDDS_CopyString((char **)memory, *((char **)((char *)arraydef + SDDS_ArrayFieldInformation[field_index].offset)))) {
241 SDDS_SetError("Unable to copy field data (SDDS_GetArrayInformation)");
242 return (0);
243 }
244 } else
245 memcpy(memory, (char *)arraydef + SDDS_ArrayFieldInformation[field_index].offset, SDDS_type_size[type - 1]);
246 return (type);
247}

◆ SDDS_GetArrayInLong()

epicsShareFuncSDDS int32_t * SDDS_GetArrayInLong ( SDDS_DATASET * SDDS_dataset,
char * array_name,
int32_t * values )
extern

Retrieves an array from the current data table of an SDDS dataset and converts its elements to 32-bit integers.

This function extracts the specified array from the provided SDDS dataset and converts each of its elements into a 32-bit integer (int32_t). It ensures that the array is of a compatible numeric type before performing the conversion.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
array_nameA null-terminated string specifying the name of the SDDS array to retrieve and convert.
valuesPointer to an integer where the number of elements in the array will be stored upon successful completion.
Returns
On success, returns a pointer to an array of int32_t values representing the SDDS array elements. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, unrecognized array name, incompatible array type, memory allocation failure).
Non-NULLPointer to an array of int32_t values representing the SDDS array elements.
Note
  • The caller is responsible for freeing the allocated memory for the returned int32_t array.
  • The function does not handle string-type arrays; attempting to retrieve a string array will result in an error.
See also
SDDS_GetArray, SDDS_GetArrayInDoubles, SDDS_GetArrayInString

Definition at line 4518 of file SDDS_extract.c.

4518 {
4519 int32_t index, type, i, elements;
4520 SDDS_ARRAY *original;
4521 int32_t *data;
4522 void *rawData;
4523
4524 *values = 0;
4525 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayInLong"))
4526 return (NULL);
4527 if (!array_name) {
4528 SDDS_SetError("Unable to get array--array name pointer is NULL (SDDS_GetArrayInLong)");
4529 return (NULL);
4530 }
4531 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
4532 SDDS_SetError("Unable to get array--array name is unrecognized (SDDS_GetArrayInLong)");
4533 return (NULL);
4534 }
4535 original = SDDS_dataset->array + index;
4536 if ((type = original->definition->type) == SDDS_STRING) {
4537 SDDS_SetError("Unable to get array--string type (SDDS_GetArrayInLong)");
4538 return (NULL);
4539 }
4540 elements = original->elements;
4541 if (!(data = SDDS_Malloc(sizeof(*data) * elements))) {
4542 SDDS_SetError("Unable to get array--allocation failure (SDDS_GetArrayInLong)");
4543 return (NULL);
4544 }
4545 rawData = original->data;
4546 switch (type) {
4547 case SDDS_LONGDOUBLE:
4548 for (i = 0; i < elements; i++) {
4549 data[i] = ((long double *)rawData)[i];
4550 }
4551 break;
4552 case SDDS_DOUBLE:
4553 for (i = 0; i < elements; i++) {
4554 data[i] = ((double *)rawData)[i];
4555 }
4556 break;
4557 case SDDS_FLOAT:
4558 for (i = 0; i < elements; i++) {
4559 data[i] = ((float *)rawData)[i];
4560 }
4561 break;
4562 case SDDS_LONG64:
4563 for (i = 0; i < elements; i++) {
4564 data[i] = ((int64_t *)rawData)[i];
4565 }
4566 break;
4567 case SDDS_ULONG64:
4568 for (i = 0; i < elements; i++) {
4569 data[i] = ((uint64_t *)rawData)[i];
4570 }
4571 break;
4572 case SDDS_LONG:
4573 for (i = 0; i < elements; i++) {
4574 data[i] = ((int32_t *)rawData)[i];
4575 }
4576 break;
4577 case SDDS_ULONG:
4578 for (i = 0; i < elements; i++) {
4579 data[i] = ((uint32_t *)rawData)[i];
4580 }
4581 break;
4582 case SDDS_SHORT:
4583 for (i = 0; i < elements; i++) {
4584 data[i] = ((short *)rawData)[i];
4585 }
4586 break;
4587 case SDDS_USHORT:
4588 for (i = 0; i < elements; i++) {
4589 data[i] = ((unsigned short *)rawData)[i];
4590 }
4591 break;
4592 case SDDS_CHARACTER:
4593 for (i = 0; i < elements; i++) {
4594 data[i] = ((char *)rawData)[i];
4595 }
4596 break;
4597 }
4598 *values = elements;
4599 return data;
4600}

◆ SDDS_GetArrayInString()

epicsShareFuncSDDS char ** SDDS_GetArrayInString ( SDDS_DATASET * SDDS_dataset,
char * array_name,
int32_t * values )
extern

Retrieves an array from the current data table of an SDDS dataset and converts its elements to strings.

This function extracts the specified array from the provided SDDS dataset and converts each of its elements into a null-terminated string representation. The conversion respects the data type of the array elements, ensuring accurate string formatting.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
array_nameA null-terminated string specifying the name of the SDDS array to retrieve and convert.
valuesPointer to an integer where the number of elements in the array will be stored upon successful completion.
Returns
On success, returns a pointer to an array of null-terminated strings (char **). Each string represents an element of the original SDDS array. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, unrecognized array name, memory allocation failure).
Non-NULLPointer to an array of strings representing the SDDS array elements.
Note
  • The caller is responsible for freeing each string in the returned array as well as the array itself.
  • The function handles different data types, including numeric types and strings, ensuring proper formatting for each type.
See also
SDDS_GetArray, SDDS_GetArrayInDoubles, SDDS_GetArrayInLong

Definition at line 4291 of file SDDS_extract.c.

4291 {
4292 int32_t index, type, i, elements;
4293 SDDS_ARRAY *original;
4294 char **data;
4295 char buffer[SDDS_MAXLINE];
4296 void *rawData;
4297
4298 *values = 0;
4299 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayInString"))
4300 return (NULL);
4301 if (!array_name) {
4302 SDDS_SetError("Unable to get array--array name pointer is NULL (SDDS_GetArrayInString)");
4303 return (NULL);
4304 }
4305 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
4306 SDDS_SetError("Unable to get array--array name is unrecognized (SDDS_GetArrayInString)");
4307 return (NULL);
4308 }
4309 original = SDDS_dataset->array + index;
4310 type = original->definition->type;
4311 elements = original->elements;
4312 if (!(data = (char **)SDDS_Malloc(sizeof(*data) * elements))) {
4313 SDDS_SetError("Unable to get array--allocation failure (SDDS_GetArrayInString)");
4314 return (NULL);
4315 }
4316 rawData = original->data;
4317 switch (type) {
4318 case SDDS_LONGDOUBLE:
4319 for (i = 0; i < elements; i++) {
4320 if (LDBL_DIG == 18) {
4321 sprintf(buffer, "%22.18Le", ((long double *)rawData)[i]);
4322 } else {
4323 sprintf(buffer, "%22.15Le", ((long double *)rawData)[i]);
4324 }
4325 SDDS_CopyString(&data[i], buffer);
4326 }
4327 break;
4328 case SDDS_DOUBLE:
4329 for (i = 0; i < elements; i++) {
4330 sprintf(buffer, "%22.15le", ((double *)rawData)[i]);
4331 SDDS_CopyString(&data[i], buffer);
4332 }
4333 break;
4334 case SDDS_FLOAT:
4335 for (i = 0; i < elements; i++) {
4336 sprintf(buffer, "%15.8e", ((float *)rawData)[i]);
4337 SDDS_CopyString(&data[i], buffer);
4338 }
4339 break;
4340 case SDDS_LONG64:
4341 for (i = 0; i < elements; i++) {
4342 sprintf(buffer, "%" PRId64, ((int64_t *)rawData)[i]);
4343 SDDS_CopyString(&data[i], buffer);
4344 }
4345 break;
4346 case SDDS_ULONG64:
4347 for (i = 0; i < elements; i++) {
4348 sprintf(buffer, "%" PRIu64, ((uint64_t *)rawData)[i]);
4349 SDDS_CopyString(&data[i], buffer);
4350 }
4351 break;
4352 case SDDS_LONG:
4353 for (i = 0; i < elements; i++) {
4354 sprintf(buffer, "%" PRId32, ((int32_t *)rawData)[i]);
4355 SDDS_CopyString(&data[i], buffer);
4356 }
4357 break;
4358 case SDDS_ULONG:
4359 for (i = 0; i < elements; i++) {
4360 sprintf(buffer, "%" PRIu32, ((uint32_t *)rawData)[i]);
4361 SDDS_CopyString(&data[i], buffer);
4362 }
4363 break;
4364 case SDDS_SHORT:
4365 for (i = 0; i < elements; i++) {
4366 sprintf(buffer, "%hd", ((short *)rawData)[i]);
4367 SDDS_CopyString(&data[i], buffer);
4368 }
4369 break;
4370 case SDDS_USHORT:
4371 for (i = 0; i < elements; i++) {
4372 sprintf(buffer, "%hu", ((unsigned short *)rawData)[i]);
4373 SDDS_CopyString(&data[i], buffer);
4374 }
4375 break;
4376 case SDDS_CHARACTER:
4377 for (i = 0; i < elements; i++) {
4378 sprintf(buffer, "%c", ((char *)rawData)[i]);
4379 SDDS_CopyString(&data[i], buffer);
4380 }
4381 break;
4382 case SDDS_STRING:
4383 for (i = 0; i < elements; i++) {
4384 SDDS_CopyString(&data[i], ((char **)rawData)[i]);
4385 }
4386 break;
4387 }
4388 *values = elements;
4389 return data;
4390}

◆ SDDS_GetArrayNames()

epicsShareFuncSDDS char ** SDDS_GetArrayNames ( SDDS_DATASET * SDDS_dataset,
int32_t * number )
extern

Retrieves the names of all arrays in the SDDS dataset.

This function allocates and returns an array of NULL-terminated strings containing the names of the arrays in the provided SDDS_dataset.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[out]numberPointer to an int32_t variable where the number of retrieved array names will be stored.
Returns
  • Returns a pointer to an array of NULL-terminated strings containing the array names on success.
  • Returns NULL on failure (e.g., if the dataset is invalid or memory allocation fails) and records an error message.
Note
The caller is responsible for freeing the memory allocated for the returned array and its strings using SDDS_FreeStringArray or similar functions.
See also
SDDS_CheckDataset
SDDS_Malloc
SDDS_CopyString
SDDS_SetError

Definition at line 2539 of file SDDS_utils.c.

2539 {
2540 int32_t i;
2541 char **name;
2542 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayNames"))
2543 return (NULL);
2544 *number = SDDS_dataset->layout.n_arrays;
2545 if (!(name = (char **)SDDS_Malloc(sizeof(*name) * SDDS_dataset->layout.n_arrays))) {
2546 SDDS_SetError("Unable to get array names--allocation failure (SDDS_GetArrayNames)");
2547 return (NULL);
2548 }
2549 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++) {
2550 if (!SDDS_CopyString(name + i, SDDS_dataset->layout.array_definition[i].name)) {
2551 free(name);
2552 return (NULL);
2553 }
2554 }
2555 return (name);
2556}

◆ SDDS_GetArrayType()

epicsShareFuncSDDS int32_t SDDS_GetArrayType ( SDDS_DATASET * SDDS_dataset,
int32_t index )
extern

Retrieves the data type of an array in the SDDS dataset by its index.

This function returns the SDDS data type of the specified array within the dataset. The data type corresponds to one of the predefined SDDS type constants, such as SDDS_LONGDOUBLE, SDDS_DOUBLE, SDDS_FLOAT, etc.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]indexThe zero-based index of the array whose data type is to be retrieved. The index should be obtained from SDDS_DefineArray or SDDS_GetArrayIndex.
Returns
On success, returns the SDDS data type of the array as an int32_t. On failure (e.g., if the index is out of range or the dataset is invalid), returns 0 and records an error message.
Note
The function does not perform type validation beyond checking the index range. It assumes that the dataset's array definitions are correctly initialized.
See also
SDDS_GetArrayIndex
SDDS_SetError

Definition at line 2202 of file SDDS_utils.c.

2202 {
2203 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetArrayType"))
2204 return (0);
2205 if (index < 0 || index >= SDDS_dataset->layout.n_arrays) {
2206 SDDS_SetError("Unable to get array type--array index is out of range (SDDS_GetArrayType)");
2207 return (0);
2208 }
2209 return (SDDS_dataset->layout.array_definition[index].type);
2210}

◆ SDDS_GetAssociateDefinition()

epicsShareFuncSDDS ASSOCIATE_DEFINITION * SDDS_GetAssociateDefinition ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the definition of a specified associate from the SDDS dataset.

This function searches for an associate by its name within the provided SDDS dataset. If found, it creates a copy of the associate's definition and returns a pointer to it. The returned pointer should be freed by the caller using SDDS_FreeAssociateDefinition to avoid memory leaks.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the associate to retrieve.
Returns
On success, returns a pointer to a newly allocated ASSOCIATE_DEFINITION structure containing the associate's information. On failure (e.g., if the associate is not found or a copy fails), returns NULL and records an error message.
Note
The caller is responsible for freeing the returned ASSOCIATE_DEFINITION pointer using SDDS_FreeAssociateDefinition.
See also
SDDS_CopyAssociateDefinition
SDDS_FreeAssociateDefinition
SDDS_SetError

Definition at line 883 of file SDDS_utils.c.

883 {
884 int32_t i;
885 ASSOCIATE_DEFINITION *assdef;
886 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetAssociateDefinition"))
887 return (NULL);
888 if (!name) {
889 SDDS_SetError("Unable to get associate definition--name is NULL (SDDS_GetAssociateDefinition)");
890 return (NULL);
891 }
892 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
893 if (strcmp(SDDS_dataset->layout.associate_definition[i].name, name) == 0) {
894 if (!SDDS_CopyAssociateDefinition(&assdef, SDDS_dataset->layout.associate_definition + i)) {
895 SDDS_SetError("Unable to get associate definition--copy failure (SDDS_GetAssociateDefinition)");
896 return (NULL);
897 }
898 return (assdef);
899 }
900 }
901 return (NULL);
902}
ASSOCIATE_DEFINITION * SDDS_CopyAssociateDefinition(ASSOCIATE_DEFINITION **target, ASSOCIATE_DEFINITION *source)
Creates a copy of an associate definition.
Definition SDDS_utils.c:920

◆ SDDS_GetAssociateIndex()

epicsShareFuncSDDS int32_t SDDS_GetAssociateIndex ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the index of a named associate in the SDDS dataset.

This function searches for an associate by its name within the provided SDDS dataset and returns its index. The index can then be used with other routines for faster access to the associate's data or metadata.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the associate whose index is desired.
Returns
On success, returns a non-negative integer representing the index of the associate. On failure (e.g., if the associate is not found), returns -1 and records an error message.
See also
SDDS_GetAssociateDefinition
SDDS_SetError

Definition at line 1396 of file SDDS_utils.c.

1396 {
1397 int32_t i;
1398 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetAssociateIndex"))
1399 return (-1);
1400 if (!name) {
1401 SDDS_SetError("Unable to get associate index--name is NULL (SDDS_GetAssociateIndex)");
1402 return (-1);
1403 }
1404 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
1405 if (strcmp(SDDS_dataset->layout.associate_definition[i].name, name) == 0)
1406 return (i);
1407 }
1408 return (-1);
1409}

◆ SDDS_GetAssociateInformation()

epicsShareFuncSDDS int32_t SDDS_GetAssociateInformation ( SDDS_DATASET * SDDS_dataset,
char * field_name,
void * memory,
int32_t mode,
... )
extern

Retrieves information about a specified associate in the SDDS dataset.

This function allows you to obtain information about a specific field of an associate, either by the associate's name or index.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]field_nameA null-terminated string specifying the name of the field for which information is requested.
[out]memoryPointer to a variable where the retrieved information will be stored. The variable should be of type data_type*, where data_type corresponds to the type of the requested information. For STRING information, use char*. If memory is NULL, the function will verify the existence and type of the information, returning the data type without storing any data.
[in]modeSpecifies how to identify the associate. Valid values are:
  • SDDS_GET_BY_NAME: Identify the associate by its name. Requires an additional argument of type char* (associate name).
  • SDDS_GET_BY_INDEX: Identify the associate by its index. Requires an additional argument of type int32_t (associate index).
Returns
On success, returns the SDDS data type of the requested information. On failure, returns zero and records an error message.
Note
This function uses variable arguments to accept either the associate name or index based on the mode parameter.
See also
SDDS_GetAssociateDefinition

Definition at line 267 of file SDDS_info.c.

267 {
268 int32_t field_index, type, associate_index;
269 ASSOCIATE_DEFINITION *associatedef;
270 char *associate_name;
271 va_list argptr;
272 int32_t retval;
273
274 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetAssociateInformation"))
275 return (0);
276
277 if (!field_name) {
278 SDDS_SetError("NULL field name passed. (SDDS_GetAssociateInformation)");
279 return (0);
280 }
281
282 va_start(argptr, mode);
283 retval = 1;
284 if (mode & SDDS_GET_BY_INDEX) {
285 if ((associate_index = va_arg(argptr, int32_t)) < 0 || associate_index >= SDDS_dataset->layout.n_associates) {
286 SDDS_SetError("Invalid associate index passed. (SDDS_GetAssociateInformation)");
287 retval = 0;
288 }
289 } else {
290 if (!(associate_name = va_arg(argptr, char *))) {
291 SDDS_SetError("NULL associate name passed. (SDDS_GetAssociateInformation)");
292 retval = 0;
293 }
294 if ((associate_index = SDDS_GetAssociateIndex(SDDS_dataset, associate_name)) < 0) {
295 SDDS_SetError("Unknown associate name given (SDDS_GetAssociateInformation)");
296 retval = 0;
297 }
298 }
299 associatedef = SDDS_dataset->layout.associate_definition + associate_index;
300 va_end(argptr);
301 if (!retval)
302 return (0);
303
304 for (field_index = 0; field_index < SDDS_ASSOCIATE_FIELDS; field_index++)
305 if (strcmp(field_name, SDDS_AssociateFieldInformation[field_index].name) == 0)
306 break;
307 if (field_index == SDDS_ASSOCIATE_FIELDS) {
308 SDDS_SetError("Unknown field name given (SDDS_GetAssociateInformation)");
309 return (0);
310 }
311 type = SDDS_AssociateFieldInformation[field_index].type;
312 if (!memory)
313 return (type);
314 if (type == SDDS_STRING) {
315 if (!SDDS_CopyString((char **)memory, *((char **)((char *)associatedef + SDDS_AssociateFieldInformation[field_index].offset)))) {
316 SDDS_SetError("Unable to copy field data (SDDS_GetAssociateInformation)");
317 return (0);
318 }
319 } else
320 memcpy(memory, (char *)associatedef + SDDS_AssociateFieldInformation[field_index].offset, SDDS_type_size[type - 1]);
321 return (type);
322}
SDDS_FIELD_INFORMATION SDDS_AssociateFieldInformation[SDDS_ASSOCIATE_FIELDS]
Field information for associate definitions.
Definition SDDS_data.c:225

◆ SDDS_GetAssociateNames()

epicsShareFuncSDDS char ** SDDS_GetAssociateNames ( SDDS_DATASET * SDDS_dataset,
int32_t * number )
extern

Retrieves the names of all associates in the SDDS dataset.

This function allocates and returns an array of NULL-terminated strings containing the names of the associates in the provided SDDS_dataset.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[out]numberPointer to an int32_t variable where the number of retrieved associate names will be stored.
Returns
  • Returns a pointer to an array of NULL-terminated strings containing the associate names on success.
  • Returns NULL on failure (e.g., if the dataset is invalid or memory allocation fails) and records an error message.
Note
The caller is responsible for freeing the memory allocated for the returned array and its strings using SDDS_FreeStringArray or similar functions.
See also
SDDS_CheckDataset
SDDS_Malloc
SDDS_CopyString
SDDS_SetError

Definition at line 2577 of file SDDS_utils.c.

2577 {
2578 int32_t i;
2579 char **name;
2580 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetAssociateNames"))
2581 return (NULL);
2582 if (!(name = (char **)SDDS_Malloc(sizeof(*name) * SDDS_dataset->layout.n_associates))) {
2583 SDDS_SetError("Unable to get associate names--allocation failure (SDDS_GetAssociateNames)");
2584 return (NULL);
2585 }
2586 *number = SDDS_dataset->layout.n_associates;
2587 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
2588 if (!SDDS_CopyString(name + i, SDDS_dataset->layout.associate_definition[i].name)) {
2589 free(name);
2590 return (NULL);
2591 }
2592 }
2593 return (name);
2594}

◆ SDDS_GetCastMatrixOfRows()

epicsShareFuncSDDS void * SDDS_GetCastMatrixOfRows ( SDDS_DATASET * SDDS_dataset,
int64_t * n_rows,
int32_t sddsType )
extern

Retrieves all rows marked as "of interest" as a matrix, casting each value to a specified numerical type.

This function extracts all rows that are flagged as "of interest" within the current data table of a dataset and casts each value to a specified numerical type. It processes only those columns that are flagged as "of interest" and returns the data as a matrix, where each row is an array of casted values corresponding to the selected columns.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
n_rowsPointer to an int64_t variable where the number of rows retrieved will be stored.
sddsTypeInteger constant representing the desired data type for casting (e.g., SDDS_DOUBLE, SDDS_FLOAT, etc.). Must be a valid numerical type as defined by SDDS.
Returns
  • Pointer to an array of pointers, where each pointer references a row's data array cast to the specified type.
  • NULL if an error occurs (e.g., invalid dataset, no columns selected, inconsistent data types among selected columns, non-numeric sddsType, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks. This includes freeing each individual row array followed by the array of pointers itself.
  • All selected columns must have numerical data types. If any selected column is non-numeric, the function will fail.
  • Ensure that sddsType is a valid numerical type supported by SDDS.
Note
  • The number of rows retrieved is stored in the variable pointed to by n_rows.
  • This function performs type casting using SDDS_CastValue. If casting fails for any value, the function will terminate and return NULL.
  • If the dataset's memory mode for the columns is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the columns may be freed after access.
See also

Definition at line 2343 of file SDDS_extract.c.

2343 {
2344 void **data;
2345 int32_t size;
2346 int64_t i, j, k;
2347
2348 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetCastMatrixOfRows"))
2349 return (NULL);
2350 if (!SDDS_NUMERIC_TYPE(sddsType)) {
2351 SDDS_SetError("Unable to get matrix of rows--no columns selected (SDDS_GetCastMatrixOfRows)");
2352 return NULL;
2353 }
2354 if (SDDS_dataset->n_of_interest <= 0) {
2355 SDDS_SetError("Unable to get matrix of rows--no columns selected (SDDS_GetCastMatrixOfRows)");
2356 return (NULL);
2357 }
2358 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_GetCastMatrixOfRows"))
2359 return (NULL);
2360 size = SDDS_type_size[sddsType - 1];
2361 if ((*n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
2362 SDDS_SetError("Unable to get matrix of rows--no rows of interest (SDDS_GetCastMatrixOfRows)");
2363 return (NULL);
2364 }
2365 if (!(data = (void **)SDDS_Malloc(sizeof(*data) * (*n_rows)))) {
2366 SDDS_SetError("Unable to get matrix of rows--memory allocation failure (SDDS_GetCastMatrixOfRows)");
2367 return (NULL);
2368 }
2369 for (i = 0; i < SDDS_dataset->n_of_interest; i++) {
2370 if (!SDDS_NUMERIC_TYPE(SDDS_dataset->layout.column_definition[SDDS_dataset->column_order[i]].type)) {
2371 SDDS_SetError("Unable to get matrix of rows--not all columns are numeric (SDDS_GetCastMatrixOfRows)");
2372 return NULL;
2373 }
2374 }
2375 for (j = k = 0; j < SDDS_dataset->n_rows; j++) {
2376 if (SDDS_dataset->row_flag[j]) {
2377 if (!(data[k] = SDDS_Malloc(size * SDDS_dataset->n_of_interest))) {
2378 SDDS_SetError("Unable to get matrix of rows--memory allocation failure (SDDS_GetCastMatrixOfRows)");
2379 return (NULL);
2380 }
2381 for (i = 0; i < SDDS_dataset->n_of_interest; i++)
2382 SDDS_CastValue(SDDS_dataset->data[SDDS_dataset->column_order[i]], j, SDDS_dataset->layout.column_definition[SDDS_dataset->column_order[i]].type, sddsType, (char *)data[k] + i * sizeof(double));
2383 k++;
2384 }
2385 }
2386 return (data);
2387}

◆ SDDS_GetColumn()

epicsShareFuncSDDS void * SDDS_GetColumn ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Retrieves a copy of the data for a specified column, including only rows marked as "of interest".

This function returns a newly allocated array containing data from the specified column for all rows that are flagged as "of interest". The data type of the returned array matches the column's data type.

For columns of type SDDS_STRING, the returned array is of type char**, with each element being a dynamically allocated string.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column to retrieve.
Returns
  • Pointer to the data array on success. The type of the array corresponds to the column's data type.
  • NULL on failure, with an error message recorded (e.g., unrecognized column name, memory allocation failure, no rows of interest).
Warning
The caller is responsible for freeing the allocated memory to avoid memory leaks. For SDDS_STRING types, each string within the array should be freed individually, followed by the array itself.
Note
  • The number of rows in the returned array can be obtained using SDDS_CountRowsOfInterest.
  • If the column's memory mode is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data may be freed after access.
See also
SDDS_GetInternalColumn, SDDS_CountRowsOfInterest, SDDS_SetRowFlags

Definition at line 611 of file SDDS_extract.c.

611 {
612 int32_t size, type, index;
613 int64_t i, j, n_rows;
614 void *data;
615 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumn"))
616 return (NULL);
617 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
618 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetColumn)");
619 return (NULL);
620 }
621 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
622 SDDS_SetError("Unable to get column--no rows left (SDDS_GetColumn)");
623 return (NULL);
624 }
625 if (!(type = SDDS_GetColumnType(SDDS_dataset, index))) {
626 SDDS_SetError("Unable to get column--data type undefined (SDDS_GetColumn)");
627 return (NULL);
628 }
629 size = SDDS_type_size[type - 1];
630 if (!(data = SDDS_Malloc(size * n_rows))) {
631 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetColumn)");
632 return (NULL);
633 }
634 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
635 if (SDDS_dataset->row_flag[i]) {
636 if (type != SDDS_STRING)
637 memcpy((char *)data + size * j++, (char *)SDDS_dataset->data[index] + size * i, size);
638 else if (!SDDS_CopyString((char **)data + j++, ((char ***)SDDS_dataset->data)[index][i]))
639 return (NULL);
640 }
641 }
642 if (j != n_rows) {
643 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetColumn)");
644 return (NULL);
645 }
646 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
647 SDDS_dataset->column_track_memory[index] = 0;
648 //Free internal copy now under the assumption that the program will not ask for it again.
649 if (type == SDDS_STRING) {
650 if (0) {
651 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
652 char **ptr = (char **)SDDS_dataset->data[index];
653 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
654 if (*ptr)
655 free(*ptr);
656 free(SDDS_dataset->data[index]);
657 SDDS_dataset->data[index] = NULL;
658 }
659 } else {
660 free(SDDS_dataset->data[index]);
661 SDDS_dataset->data[index] = NULL;
662 }
663 }
664 return (data);
665}
int32_t SDDS_GetColumnMemoryMode(SDDS_DATASET *SDDS_dataset)

◆ SDDS_GetColumnDefinition()

epicsShareFuncSDDS COLUMN_DEFINITION * SDDS_GetColumnDefinition ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the definition of a specified column from the SDDS dataset.

This function searches for a column by its name within the provided SDDS dataset. If found, it creates a copy of the column's definition and returns a pointer to it. The returned pointer should be freed by the caller using SDDS_FreeColumnDefinition to avoid memory leaks.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the column to retrieve.
Returns
On success, returns a pointer to a newly allocated COLUMN_DEFINITION structure containing the column's information. On failure (e.g., if the column is not found or a copy fails), returns NULL and records an error message.
Note
The caller is responsible for freeing the returned COLUMN_DEFINITION pointer using SDDS_FreeColumnDefinition.
See also
SDDS_CopyColumnDefinition
SDDS_FreeColumnDefinition
SDDS_SetError

Definition at line 978 of file SDDS_utils.c.

978 {
979 int64_t i;
980 COLUMN_DEFINITION *coldef;
981 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnDefinition"))
982 return (NULL);
983 if (!name) {
984 SDDS_SetError("Unable to get column definition--name is NULL (SDDS_GetColumnDefinition)");
985 return (NULL);
986 }
987 if ((i = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0)
988 return NULL;
989 if (!SDDS_CopyColumnDefinition(&coldef, SDDS_dataset->layout.column_definition + i)) {
990 SDDS_SetError("Unable to get column definition--copy failure (SDDS_GetColumnDefinition)");
991 return (NULL);
992 }
993 return (coldef);
994}
COLUMN_DEFINITION * SDDS_CopyColumnDefinition(COLUMN_DEFINITION **target, COLUMN_DEFINITION *source)
Creates a copy of a column definition.

◆ SDDS_GetColumnIndex()

epicsShareFuncSDDS int32_t SDDS_GetColumnIndex ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the index of a named column in the SDDS dataset.

This function searches for a column by its name within the provided SDDS dataset and returns its index. The index can then be used with other routines for faster access to the column's data or metadata.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the column whose index is desired.
Returns
On success, returns a non-negative integer representing the index of the column. On failure (e.g., if the column is not found), returns -1 and records an error message.
See also
SDDS_GetColumnDefinition
SDDS_SetError

Definition at line 1309 of file SDDS_utils.c.

1309 {
1310 int64_t i;
1311 SORTED_INDEX key;
1312
1313 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnIndex"))
1314 return (-1);
1315 if (!name) {
1316 SDDS_SetError("Unable to get column index--name is NULL (SDDS_GetColumnIndex)");
1317 return (-1);
1318 }
1319 key.name = name;
1320 if ((i = binaryIndexSearch((void **)SDDS_dataset->layout.column_index, SDDS_dataset->layout.n_columns, &key, SDDS_CompareIndexedNames, 0)) < 0)
1321 return -1;
1322 return SDDS_dataset->layout.column_index[i]->index;
1323}

◆ SDDS_GetColumnInDoubles()

epicsShareFuncSDDS double * SDDS_GetColumnInDoubles ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Retrieves the data of a specified numerical column as an array of doubles, considering only rows marked as "of interest".

This function extracts data from a specified column within the current data table of a dataset. It processes only those rows that are flagged as "of interest" (i.e., have a non-zero acceptance flag). The extracted data is returned as a newly allocated array of double values.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which data is to be retrieved.
Returns
  • Pointer to an array of double containing the data from the specified column for all rows marked as "of interest".
  • NULL if an error occurs (e.g., invalid dataset, unrecognized column name, non-numeric column type, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks.
  • This function assumes that the specified column contains numerical data. Attempting to retrieve data from a non-numeric column (excluding SDDS_CHARACTER) will result in an error.
Note
  • The number of elements in the returned array corresponds to the number of rows marked as "of interest", which can be obtained using SDDS_CountRowsOfInterest.
  • If the dataset's memory mode for the column is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the column may be freed after access.
See also

Definition at line 872 of file SDDS_extract.c.

872 {
873 int32_t size, type, index;
874 int64_t i, j, n_rows;
875 double *data;
876 void *rawData;
877
878 j = 0;
879
880 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnInDoubles"))
881 return (NULL);
882 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
883 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetColumnInDoubles)");
884 return (NULL);
885 }
886 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
887 SDDS_SetError("Unable to get column--no rows left (SDDS_GetColumnInDoubles)");
888 return (NULL);
889 }
890 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) <= 0 || (size = SDDS_GetTypeSize(type)) <= 0 || (!SDDS_NUMERIC_TYPE(type) && type != SDDS_CHARACTER)) {
891 SDDS_SetError("Unable to get column--data size or type undefined or non-numeric (SDDS_GetColumnInDoubles)");
892 return (NULL);
893 }
894 if (!(data = (double *)SDDS_Malloc(sizeof(double) * n_rows))) {
895 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetColumnInDoubles)");
896 return (NULL);
897 }
898 rawData = SDDS_dataset->data[index];
899 switch (type) {
900 case SDDS_LONGDOUBLE:
901 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
902 if (SDDS_dataset->row_flag[i])
903 data[j++] = ((long double *)rawData)[i];
904 }
905 break;
906 case SDDS_DOUBLE:
907 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
908 if (SDDS_dataset->row_flag[i])
909 data[j++] = ((double *)rawData)[i];
910 }
911 break;
912 case SDDS_FLOAT:
913 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
914 if (SDDS_dataset->row_flag[i])
915 data[j++] = ((float *)rawData)[i];
916 }
917 break;
918 case SDDS_LONG:
919 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
920 if (SDDS_dataset->row_flag[i])
921 data[j++] = ((int32_t *)rawData)[i];
922 }
923 break;
924 case SDDS_ULONG:
925 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
926 if (SDDS_dataset->row_flag[i])
927 data[j++] = ((uint32_t *)rawData)[i];
928 }
929 break;
930 case SDDS_LONG64:
931 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
932 if (SDDS_dataset->row_flag[i])
933 data[j++] = ((int64_t *)rawData)[i];
934 }
935 break;
936 case SDDS_ULONG64:
937 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
938 if (SDDS_dataset->row_flag[i])
939 data[j++] = ((uint64_t *)rawData)[i];
940 }
941 break;
942 case SDDS_SHORT:
943 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
944 if (SDDS_dataset->row_flag[i])
945 data[j++] = ((short *)rawData)[i];
946 }
947 break;
948 case SDDS_USHORT:
949 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
950 if (SDDS_dataset->row_flag[i])
951 data[j++] = ((unsigned short *)rawData)[i];
952 }
953 break;
954 case SDDS_CHARACTER:
955 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
956 if (SDDS_dataset->row_flag[i])
957 data[j++] = ((char *)rawData)[i];
958 }
959 break;
960 }
961 if (j != n_rows) {
962 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetColumnInDoubles)");
963 return (NULL);
964 }
965 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
966 SDDS_dataset->column_track_memory[index] = 0;
967 //Free internal copy now under the assumption that the program will not ask for it again.
968 if (type == SDDS_STRING) {
969 if (0) {
970 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
971 char **ptr = (char **)SDDS_dataset->data[index];
972 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
973 if (*ptr)
974 free(*ptr);
975 free(SDDS_dataset->data[index]);
976 SDDS_dataset->data[index] = NULL;
977 }
978 } else {
979 free(SDDS_dataset->data[index]);
980 SDDS_dataset->data[index] = NULL;
981 }
982 }
983 return (data);
984}

◆ SDDS_GetColumnInFloats()

epicsShareFuncSDDS float * SDDS_GetColumnInFloats ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Retrieves the data of a specified numerical column as an array of floats, considering only rows marked as "of interest".

This function extracts data from a specified column within the current data table of a dataset. It processes only those rows that are flagged as "of interest" (i.e., have a non-zero acceptance flag). The extracted data is returned as a newly allocated array of float values.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which data is to be retrieved.
Returns
  • Pointer to an array of float containing the data from the specified column for all rows marked as "of interest".
  • NULL if an error occurs (e.g., invalid dataset, unrecognized column name, non-numeric column type, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks.
  • This function assumes that the specified column contains numerical data. Attempting to retrieve data from a non-numeric column (excluding SDDS_CHARACTER) will result in an error.
Note
  • The number of elements in the returned array corresponds to the number of rows marked as "of interest", which can be obtained using SDDS_CountRowsOfInterest.
  • If the dataset's memory mode for the column is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the column may be freed after access.
See also

Definition at line 1014 of file SDDS_extract.c.

1014 {
1015 int32_t size, type, index;
1016 int64_t i, j, n_rows;
1017 float *data;
1018 void *rawData;
1019
1020 j = 0;
1021
1022 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnInFloats"))
1023 return (NULL);
1024 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
1025 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetColumnInFloats)");
1026 return (NULL);
1027 }
1028 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
1029 SDDS_SetError("Unable to get column--no rows left (SDDS_GetColumnInFloats)");
1030 return (NULL);
1031 }
1032 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) <= 0 || (size = SDDS_GetTypeSize(type)) <= 0 || (!SDDS_NUMERIC_TYPE(type) && type != SDDS_CHARACTER)) {
1033 SDDS_SetError("Unable to get column--data size or type undefined or non-numeric (SDDS_GetColumnInFloats)");
1034 return (NULL);
1035 }
1036 if (!(data = (float *)SDDS_Malloc(sizeof(float) * n_rows))) {
1037 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetColumnInFloats)");
1038 return (NULL);
1039 }
1040 rawData = SDDS_dataset->data[index];
1041 switch (type) {
1042 case SDDS_LONGDOUBLE:
1043 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1044 if (SDDS_dataset->row_flag[i])
1045 data[j++] = ((long double *)rawData)[i];
1046 }
1047 break;
1048 case SDDS_DOUBLE:
1049 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1050 if (SDDS_dataset->row_flag[i])
1051 data[j++] = ((double *)rawData)[i];
1052 }
1053 break;
1054 case SDDS_FLOAT:
1055 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1056 if (SDDS_dataset->row_flag[i])
1057 data[j++] = ((float *)rawData)[i];
1058 }
1059 break;
1060 case SDDS_LONG:
1061 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1062 if (SDDS_dataset->row_flag[i])
1063 data[j++] = ((int32_t *)rawData)[i];
1064 }
1065 break;
1066 case SDDS_ULONG:
1067 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1068 if (SDDS_dataset->row_flag[i])
1069 data[j++] = ((uint32_t *)rawData)[i];
1070 }
1071 break;
1072 case SDDS_LONG64:
1073 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1074 if (SDDS_dataset->row_flag[i])
1075 data[j++] = ((int64_t *)rawData)[i];
1076 }
1077 break;
1078 case SDDS_ULONG64:
1079 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1080 if (SDDS_dataset->row_flag[i])
1081 data[j++] = ((uint64_t *)rawData)[i];
1082 }
1083 break;
1084 case SDDS_SHORT:
1085 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1086 if (SDDS_dataset->row_flag[i])
1087 data[j++] = ((short *)rawData)[i];
1088 }
1089 break;
1090 case SDDS_USHORT:
1091 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1092 if (SDDS_dataset->row_flag[i])
1093 data[j++] = ((unsigned short *)rawData)[i];
1094 }
1095 break;
1096 case SDDS_CHARACTER:
1097 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1098 if (SDDS_dataset->row_flag[i])
1099 data[j++] = ((char *)rawData)[i];
1100 }
1101 break;
1102 }
1103 if (j != n_rows) {
1104 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetColumnInFloats)");
1105 return (NULL);
1106 }
1107 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
1108 SDDS_dataset->column_track_memory[index] = 0;
1109 //Free internal copy now under the assumption that the program will not ask for it again.
1110 if (type == SDDS_STRING) {
1111 if (0) {
1112 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
1113 char **ptr = (char **)SDDS_dataset->data[index];
1114 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
1115 if (*ptr)
1116 free(*ptr);
1117 free(SDDS_dataset->data[index]);
1118 SDDS_dataset->data[index] = NULL;
1119 }
1120 } else {
1121 free(SDDS_dataset->data[index]);
1122 SDDS_dataset->data[index] = NULL;
1123 }
1124 }
1125 return (data);
1126}

◆ SDDS_GetColumnInformation()

epicsShareFuncSDDS int32_t SDDS_GetColumnInformation ( SDDS_DATASET * SDDS_dataset,
char * field_name,
void * memory,
int32_t mode,
... )
extern

Retrieves information about a specified column in the SDDS dataset.

This function is the preferred alternative to SDDS_GetColumnDefinition. It allows you to obtain information about a specific field of a column, either by the column's name or index.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]field_nameA null-terminated string specifying the name of the field for which information is requested.
[out]memoryPointer to a variable where the retrieved information will be stored. The variable should be of type data_type*, where data_type corresponds to the type of the requested information. For STRING information, use char*. If memory is NULL, the function will verify the existence and type of the information, returning the data type without storing any data.
[in]modeSpecifies how to identify the column. Valid values are:
  • SDDS_GET_BY_NAME: Identify the column by its name. Requires an additional argument of type char* (column name).
  • SDDS_GET_BY_INDEX: Identify the column by its index. Requires an additional argument of type int32_t (column index).
Returns
On success, returns the SDDS data type of the requested information. On failure, returns zero and records an error message.
Note
This function uses variable arguments to accept either the column name or index based on the mode parameter.
See also
SDDS_GetColumnDefinition

Definition at line 41 of file SDDS_info.c.

41 {
42 int32_t field_index, type;
43 int32_t column_index;
44 COLUMN_DEFINITION *columndef;
45 char *column_name;
46 va_list argptr;
47 int32_t retval;
48
49 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnInformation"))
50 return (0);
51
52 if (!field_name) {
53 SDDS_SetError("NULL field name passed. (SDDS_GetColumnInformation)");
54 return (0);
55 }
56
57 va_start(argptr, mode);
58 retval = 1;
59 if (mode & SDDS_GET_BY_INDEX) {
60 if ((column_index = va_arg(argptr, int32_t)) < 0 || column_index >= SDDS_dataset->layout.n_columns) {
61 SDDS_SetError("Invalid column index passed. (SDDS_GetColumnInformation)");
62 retval = 0;
63 }
64 } else {
65 if (!(column_name = va_arg(argptr, char *))) {
66 SDDS_SetError("NULL column name passed. (SDDS_GetColumnInformation)");
67 retval = 0;
68 }
69 if ((column_index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
70 SDDS_SetError("Unknown column name given (SDDS_GetColumnInformation)");
71 retval = 0;
72 }
73 }
74 columndef = SDDS_dataset->layout.column_definition + column_index;
75 va_end(argptr);
76 if (!retval)
77 return (0);
78
79 for (field_index = 0; field_index < SDDS_COLUMN_FIELDS; field_index++)
80 if (strcmp(field_name, SDDS_ColumnFieldInformation[field_index].name) == 0)
81 break;
82 if (field_index == SDDS_COLUMN_FIELDS) {
83 SDDS_SetError("Unknown field name given (SDDS_GetColumnInformation)");
84 return (0);
85 }
86 type = SDDS_ColumnFieldInformation[field_index].type;
87 if (!memory)
88 return (type);
89 if (type == SDDS_STRING) {
90 if (!SDDS_CopyString((char **)memory, *((char **)((char *)columndef + SDDS_ColumnFieldInformation[field_index].offset)))) {
91 SDDS_SetError("Unable to copy field data (SDDS_GetColumnInformation)");
92 return (0);
93 }
94 } else
95 memcpy(memory, (char *)columndef + SDDS_ColumnFieldInformation[field_index].offset, SDDS_type_size[type - 1]);
96 return (type);
97}

◆ SDDS_GetColumnInLong()

epicsShareFuncSDDS int32_t * SDDS_GetColumnInLong ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Retrieves the data of a specified numerical column as an array of 32-bit integers, considering only rows marked as "of interest".

This function extracts data from a specified column within the current data table of a dataset. It processes only those rows that are flagged as "of interest" (i.e., have a non-zero acceptance flag). The extracted data is returned as a newly allocated array of int32_t values.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which data is to be retrieved.
Returns
  • Pointer to an array of int32_t containing the data from the specified column for all rows marked as "of interest".
  • NULL if an error occurs (e.g., invalid dataset, unrecognized column name, non-numeric column type, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks.
  • This function assumes that the specified column contains numerical data. Attempting to retrieve data from a non-numeric column (excluding SDDS_CHARACTER) will result in an error.
Note
  • The number of elements in the returned array corresponds to the number of rows marked as "of interest", which can be obtained using SDDS_CountRowsOfInterest.
  • If the dataset's memory mode for the column is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the column may be freed after access.
See also

Definition at line 1157 of file SDDS_extract.c.

1157 {
1158 int32_t size, type, index;
1159 int64_t i, j, n_rows;
1160 int32_t *data;
1161 void *rawData;
1162 j = 0;
1163 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnInLong"))
1164 return (NULL);
1165 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
1166 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetColumnInLong)");
1167 return (NULL);
1168 }
1169 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
1170 SDDS_SetError("Unable to get column--no rows left (SDDS_GetColumnInLong)");
1171 return (NULL);
1172 }
1173 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) <= 0 || (size = SDDS_GetTypeSize(type)) <= 0 || (!SDDS_NUMERIC_TYPE(type) && type != SDDS_CHARACTER)) {
1174 SDDS_SetError("Unable to get column--data size or type undefined or non-numeric (SDDS_GetColumnInLong)");
1175 return (NULL);
1176 }
1177 if (!(data = (int32_t *)SDDS_Malloc(sizeof(int32_t) * n_rows))) {
1178 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetColumnInLong)");
1179 return (NULL);
1180 }
1181 rawData = SDDS_dataset->data[index];
1182 switch (type) {
1183 case SDDS_LONGDOUBLE:
1184 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1185 if (SDDS_dataset->row_flag[i])
1186 data[j++] = ((long double *)rawData)[i];
1187 }
1188 break;
1189 case SDDS_DOUBLE:
1190 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1191 if (SDDS_dataset->row_flag[i])
1192 data[j++] = ((double *)rawData)[i];
1193 }
1194 break;
1195 case SDDS_FLOAT:
1196 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1197 if (SDDS_dataset->row_flag[i])
1198 data[j++] = ((float *)rawData)[i];
1199 }
1200 break;
1201 case SDDS_LONG:
1202 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1203 if (SDDS_dataset->row_flag[i])
1204 data[j++] = ((int32_t *)rawData)[i];
1205 }
1206 break;
1207 case SDDS_ULONG:
1208 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1209 if (SDDS_dataset->row_flag[i])
1210 data[j++] = ((uint32_t *)rawData)[i];
1211 }
1212 break;
1213 case SDDS_LONG64:
1214 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1215 if (SDDS_dataset->row_flag[i])
1216 data[j++] = ((int64_t *)rawData)[i];
1217 }
1218 break;
1219 case SDDS_ULONG64:
1220 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1221 if (SDDS_dataset->row_flag[i])
1222 data[j++] = ((uint64_t *)rawData)[i];
1223 }
1224 break;
1225 case SDDS_SHORT:
1226 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1227 if (SDDS_dataset->row_flag[i])
1228 data[j++] = ((short *)rawData)[i];
1229 }
1230 break;
1231 case SDDS_USHORT:
1232 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1233 if (SDDS_dataset->row_flag[i])
1234 data[j++] = ((unsigned short *)rawData)[i];
1235 }
1236 break;
1237 case SDDS_CHARACTER:
1238 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1239 if (SDDS_dataset->row_flag[i])
1240 data[j++] = ((char *)rawData)[i];
1241 }
1242 break;
1243 }
1244 if (j != n_rows) {
1245 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetColumnInLong)");
1246 return (NULL);
1247 }
1248 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
1249 SDDS_dataset->column_track_memory[index] = 0;
1250 //Free internal copy now under the assumption that the program will not ask for it again.
1251 if (type == SDDS_STRING) {
1252 if (0) {
1253 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
1254 char **ptr = (char **)SDDS_dataset->data[index];
1255 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
1256 if (*ptr)
1257 free(*ptr);
1258 free(SDDS_dataset->data[index]);
1259 SDDS_dataset->data[index] = NULL;
1260 }
1261 } else {
1262 free(SDDS_dataset->data[index]);
1263 SDDS_dataset->data[index] = NULL;
1264 }
1265 }
1266 return (data);
1267}

◆ SDDS_GetColumnInShort()

epicsShareFuncSDDS short * SDDS_GetColumnInShort ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Retrieves the data of a specified numerical column as an array of short integers, considering only rows marked as "of interest".

This function extracts data from a specified column within the current data table of a dataset. It processes only those rows that are flagged as "of interest" (i.e., have a non-zero acceptance flag). The extracted data is returned as a newly allocated array of short values.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which data is to be retrieved.
Returns
  • Pointer to an array of short containing the data from the specified column for all rows marked as "of interest".
  • NULL if an error occurs (e.g., invalid dataset, unrecognized column name, non-numeric column type, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks.
  • This function assumes that the specified column contains numerical data. Attempting to retrieve data from a non-numeric column (excluding SDDS_CHARACTER) will result in an error.
Note
  • The number of elements in the returned array corresponds to the number of rows marked as "of interest", which can be obtained using SDDS_CountRowsOfInterest.
  • If the dataset's memory mode for the column is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the column may be freed after access.
See also

Definition at line 1298 of file SDDS_extract.c.

1298 {
1299 int32_t size, type, index;
1300 int64_t i, j, n_rows;
1301 short *data;
1302 void *rawData;
1303 j = 0;
1304 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnInShort"))
1305 return (NULL);
1306 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
1307 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetColumnInShort)");
1308 return (NULL);
1309 }
1310 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
1311 SDDS_SetError("Unable to get column--no rows left (SDDS_GetColumnInShort)");
1312 return (NULL);
1313 }
1314 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) <= 0 || (size = SDDS_GetTypeSize(type)) <= 0 || (!SDDS_NUMERIC_TYPE(type) && type != SDDS_CHARACTER)) {
1315 SDDS_SetError("Unable to get column--data size or type undefined or non-numeric (SDDS_GetColumnInShort)");
1316 return (NULL);
1317 }
1318 if (!(data = (short *)SDDS_Malloc(sizeof(short) * n_rows))) {
1319 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetColumnInShort)");
1320 return (NULL);
1321 }
1322 rawData = SDDS_dataset->data[index];
1323 switch (type) {
1324 case SDDS_LONGDOUBLE:
1325 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1326 if (SDDS_dataset->row_flag[i])
1327 data[j++] = ((long double *)rawData)[i];
1328 }
1329 break;
1330 case SDDS_DOUBLE:
1331 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1332 if (SDDS_dataset->row_flag[i])
1333 data[j++] = ((double *)rawData)[i];
1334 }
1335 break;
1336 case SDDS_FLOAT:
1337 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1338 if (SDDS_dataset->row_flag[i])
1339 data[j++] = ((float *)rawData)[i];
1340 }
1341 break;
1342 case SDDS_LONG:
1343 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1344 if (SDDS_dataset->row_flag[i])
1345 data[j++] = ((int32_t *)rawData)[i];
1346 }
1347 break;
1348 case SDDS_ULONG:
1349 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1350 if (SDDS_dataset->row_flag[i])
1351 data[j++] = ((uint32_t *)rawData)[i];
1352 }
1353 break;
1354 case SDDS_LONG64:
1355 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1356 if (SDDS_dataset->row_flag[i])
1357 data[j++] = ((int64_t *)rawData)[i];
1358 }
1359 break;
1360 case SDDS_ULONG64:
1361 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1362 if (SDDS_dataset->row_flag[i])
1363 data[j++] = ((uint64_t *)rawData)[i];
1364 }
1365 break;
1366 case SDDS_SHORT:
1367 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1368 if (SDDS_dataset->row_flag[i])
1369 data[j++] = ((short *)rawData)[i];
1370 }
1371 break;
1372 case SDDS_USHORT:
1373 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1374 if (SDDS_dataset->row_flag[i])
1375 data[j++] = ((unsigned short *)rawData)[i];
1376 }
1377 break;
1378 case SDDS_CHARACTER:
1379 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1380 if (SDDS_dataset->row_flag[i])
1381 data[j++] = ((char *)rawData)[i];
1382 }
1383 break;
1384 }
1385 if (j != n_rows) {
1386 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetColumnInShort)");
1387 return (NULL);
1388 }
1389 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
1390 SDDS_dataset->column_track_memory[index] = 0;
1391 //Free internal copy now under the assumption that the program will not ask for it again.
1392 if (type == SDDS_STRING) {
1393 if (0) {
1394 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
1395 char **ptr = (char **)SDDS_dataset->data[index];
1396 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
1397 if (*ptr)
1398 free(*ptr);
1399 free(SDDS_dataset->data[index]);
1400 SDDS_dataset->data[index] = NULL;
1401 }
1402 } else {
1403 free(SDDS_dataset->data[index]);
1404 SDDS_dataset->data[index] = NULL;
1405 }
1406 }
1407 return (data);
1408}

◆ SDDS_GetColumnInString()

epicsShareFuncSDDS char ** SDDS_GetColumnInString ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Retrieves the data of a specified column as an array of strings, considering only rows marked as "of interest".

This function extracts data from a specified column within the current data table of a dataset. It processes only those rows that are flagged as "of interest" (i.e., have a non-zero acceptance flag). The extracted data is returned as a newly allocated array of char* (strings).

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which data is to be retrieved.
Returns
  • Pointer to an array of char* containing the data from the specified column for all rows marked as "of interest".
  • NULL if an error occurs (e.g., invalid dataset, unrecognized column name, non-string column type, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks. Each string within the array should be freed individually, followed by the array itself.
  • This function assumes that the specified column contains string data (SDDS_STRING or SDDS_CHARACTER). Attempting to retrieve data from a non-string column will result in an error.
Note
  • The number of elements in the returned array corresponds to the number of rows marked as "of interest", which can be obtained using SDDS_CountRowsOfInterest.
  • If the dataset's memory mode for the column is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the column may be freed after access.
See also

Definition at line 1439 of file SDDS_extract.c.

1439 {
1440 int32_t size, type, index;
1441 int64_t i, j, n_rows;
1442 char **data;
1443 char buffer[SDDS_MAXLINE];
1444
1445 void *rawData;
1446 j = 0;
1447 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnInString"))
1448 return (NULL);
1449 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
1450 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetColumnInString)");
1451 return (NULL);
1452 }
1453 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
1454 SDDS_SetError("Unable to get column--no rows left (SDDS_GetColumnInString)");
1455 return (NULL);
1456 }
1457
1458 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) <= 0 || (size = SDDS_GetTypeSize(type)) <= 0 ||
1459 (!SDDS_NUMERIC_TYPE(type) && type != SDDS_CHARACTER && type != SDDS_STRING)) {
1460 SDDS_SetError("Unable to get column--data size or type undefined or non-numeric (SDDS_GetColumnInString)");
1461 return (NULL);
1462 }
1463 if (!(data = (char **)SDDS_Malloc(sizeof(*data) * n_rows))) {
1464 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetColumnInString)");
1465 return (NULL);
1466 }
1467 rawData = SDDS_dataset->data[index];
1468 switch (type) {
1469 case SDDS_LONGDOUBLE:
1470 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1471 if (SDDS_dataset->row_flag[i]) {
1472 if (LDBL_DIG == 18) {
1473 sprintf(buffer, "%22.18Le", ((long double *)rawData)[i]);
1474 } else {
1475 sprintf(buffer, "%22.15Le", ((long double *)rawData)[i]);
1476 }
1477 SDDS_CopyString(&data[j++], buffer);
1478 }
1479 }
1480 break;
1481 case SDDS_DOUBLE:
1482 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1483 if (SDDS_dataset->row_flag[i]) {
1484 sprintf(buffer, "%22.15le", ((double *)rawData)[i]);
1485 SDDS_CopyString(&data[j++], buffer);
1486 }
1487 }
1488 break;
1489 case SDDS_FLOAT:
1490 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1491 if (SDDS_dataset->row_flag[i]) {
1492 sprintf(buffer, "%15.8e", ((float *)rawData)[i]);
1493 SDDS_CopyString(&data[j++], buffer);
1494 }
1495 }
1496 break;
1497 case SDDS_LONG64:
1498 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1499 if (SDDS_dataset->row_flag[i]) {
1500 sprintf(buffer, "%" PRId64, ((int64_t *)rawData)[i]);
1501 SDDS_CopyString(&data[j++], buffer);
1502 }
1503 }
1504 break;
1505 case SDDS_ULONG64:
1506 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1507 if (SDDS_dataset->row_flag[i]) {
1508 sprintf(buffer, "%" PRIu64, ((uint64_t *)rawData)[i]);
1509 SDDS_CopyString(&data[j++], buffer);
1510 }
1511 }
1512 break;
1513 case SDDS_LONG:
1514 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1515 if (SDDS_dataset->row_flag[i]) {
1516 sprintf(buffer, "%" PRId32, ((int32_t *)rawData)[i]);
1517 SDDS_CopyString(&data[j++], buffer);
1518 }
1519 }
1520 break;
1521 case SDDS_ULONG:
1522 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1523 if (SDDS_dataset->row_flag[i]) {
1524 sprintf(buffer, "%" PRIu32, ((uint32_t *)rawData)[i]);
1525 SDDS_CopyString(&data[j++], buffer);
1526 }
1527 }
1528 break;
1529 case SDDS_SHORT:
1530 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1531 if (SDDS_dataset->row_flag[i]) {
1532 sprintf(buffer, "%hd", ((short *)rawData)[i]);
1533 SDDS_CopyString(&data[j++], buffer);
1534 }
1535 }
1536 break;
1537 case SDDS_USHORT:
1538 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1539 if (SDDS_dataset->row_flag[i]) {
1540 sprintf(buffer, "%hu", ((unsigned short *)rawData)[i]);
1541 SDDS_CopyString(&data[j++], buffer);
1542 }
1543 }
1544 break;
1545 case SDDS_CHARACTER:
1546 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1547 if (SDDS_dataset->row_flag[i]) {
1548 sprintf(buffer, "%c", ((char *)rawData)[i]);
1549 SDDS_CopyString(&data[j++], buffer);
1550 }
1551 }
1552 case SDDS_STRING:
1553 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1554 if (SDDS_dataset->row_flag[i]) {
1555 SDDS_CopyString(&data[j++], ((char **)rawData)[i]);
1556 }
1557 }
1558 break;
1559 }
1560 if (j != n_rows) {
1561 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetColumnInString)");
1562 return (NULL);
1563 }
1564 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
1565 SDDS_dataset->column_track_memory[index] = 0;
1566 //Free internal copy now under the assumption that the program will not ask for it again.
1567 if (type == SDDS_STRING) {
1568 if (0) {
1569 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
1570 char **ptr = (char **)SDDS_dataset->data[index];
1571 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
1572 if (*ptr)
1573 free(*ptr);
1574 free(SDDS_dataset->data[index]);
1575 SDDS_dataset->data[index] = NULL;
1576 }
1577 } else {
1578 free(SDDS_dataset->data[index]);
1579 SDDS_dataset->data[index] = NULL;
1580 }
1581 }
1582 return (data);
1583}

◆ SDDS_GetColumnMemoryMode()

epicsShareFuncSDDS int32_t SDDS_GetColumnMemoryMode ( SDDS_DATASET * SDDS_dataset)
extern

Retrieves the current column memory mode for the SDDS dataset.

Parameters
SDDS_datasetThe SDDS dataset to query.
Returns
The current column memory mode.

Definition at line 1358 of file SDDS_input.c.

1358 {
1359 return (SDDS_dataset->layout.data_mode.column_memory_mode);
1360}

◆ SDDS_GetColumnNames()

epicsShareFuncSDDS char ** SDDS_GetColumnNames ( SDDS_DATASET * SDDS_dataset,
int32_t * number )
extern

Retrieves the names of all columns in the SDDS dataset.

This function allocates and returns an array of NULL-terminated strings containing the names of the columns in the provided SDDS_dataset. It only includes columns that are flagged as of interest if column_flag is set.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[out]numberPointer to an int32_t variable where the number of retrieved column names will be stored.
Returns
  • Returns a pointer to an array of NULL-terminated strings containing the column names on success.
  • Returns NULL on failure (e.g., if the dataset is invalid or memory allocation fails) and records an error message.
Note
The caller is responsible for freeing the memory allocated for the returned array and its strings using SDDS_FreeStringArray or similar functions.
See also
SDDS_CheckDataset
SDDS_Malloc
SDDS_CopyString
SDDS_SetError

Definition at line 2460 of file SDDS_utils.c.

2460 {
2461 int64_t i;
2462 char **name;
2463 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnNames"))
2464 return (NULL);
2465 *number = 0;
2466 if (!(name = (char **)SDDS_Malloc(sizeof(*name) * SDDS_dataset->layout.n_columns))) {
2467 SDDS_SetError("Unable to get column names--allocation failure (SDDS_GetColumnNames)");
2468 return (NULL);
2469 }
2470 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2471 if (!SDDS_dataset->column_flag || SDDS_dataset->column_flag[i]) {
2472 if (!SDDS_CopyString(name + *number, SDDS_dataset->layout.column_definition[i].name)) {
2473 free(name);
2474 return (NULL);
2475 }
2476 *number += 1;
2477 }
2478 }
2479 return (name);
2480}

◆ SDDS_GetColumnType()

epicsShareFuncSDDS int32_t SDDS_GetColumnType ( SDDS_DATASET * SDDS_dataset,
int32_t index )
extern

Retrieves the data type of a column in the SDDS dataset by its index.

This function returns the SDDS data type of the specified column within the dataset. The data type corresponds to one of the predefined SDDS type constants, such as SDDS_LONGDOUBLE, SDDS_DOUBLE, SDDS_FLOAT, etc.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]indexThe zero-based index of the column whose data type is to be retrieved. The index should be obtained from SDDS_DefineColumn or SDDS_GetColumnIndex.
Returns
On success, returns the SDDS data type of the column as an int32_t. On failure (e.g., if the index is out of range or the dataset is invalid), returns 0 and records an error message.
Note
The function does not perform type validation beyond checking the index range. It assumes that the dataset's column definitions are correctly initialized.
See also
SDDS_GetColumnIndex
SDDS_SetError

Definition at line 2153 of file SDDS_utils.c.

2153 {
2154 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnType"))
2155 return (0);
2156 if (index < 0 || index >= SDDS_dataset->layout.n_columns) {
2157 SDDS_SetError("Unable to get column type--column index is out of range (SDDS_GetColumnType)");
2158 return (0);
2159 }
2160 return (SDDS_dataset->layout.column_definition[index].type);
2161}

◆ SDDS_GetDescription()

epicsShareFuncSDDS int32_t SDDS_GetDescription ( SDDS_DATASET * SDDS_dataset,
char ** text,
char ** contents )
extern

Retrieves the text and contents descriptions from an SDDS dataset.

This function extracts the text description and contents description from the specified SDDS dataset. The descriptions are copied into the provided pointers if they are not NULL. This allows users to obtain metadata information about the dataset's content and purpose.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
textPointer to a char* variable where the text description will be copied. If NULL, the text description is not retrieved.
contentsPointer to a char* variable where the contents description will be copied. If NULL, the contents description is not retrieved.
Returns
Returns 1 on successful retrieval of the descriptions. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the descriptions were successfully retrieved and copied.
0Indicates that an error occurred (e.g., invalid dataset, memory allocation failure).
Note
  • The caller is responsible for freeing the memory allocated for text and contents if they are not NULL.
  • Ensure that the dataset is properly initialized before calling this function.
See also
SDDS_SetDescription, SDDS_GetArray, SDDS_GetParameter

Definition at line 4626 of file SDDS_extract.c.

4626 {
4627 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetDescription"))
4628 return (0);
4629 if (text) {
4630 *text = NULL;
4631 if (!SDDS_CopyString(text, SDDS_dataset->layout.description)) {
4632 SDDS_SetError("Unable to retrieve description data (SDDS_GetDescription)");
4633 return (0);
4634 }
4635 }
4636 if (contents) {
4637 *contents = NULL;
4638 if (!SDDS_CopyString(contents, SDDS_dataset->layout.contents)) {
4639 SDDS_SetError("Unable to retrieve description data (SDDS_GetDescription)");
4640 return (0);
4641 }
4642 }
4643
4644 return (1);
4645}

◆ SDDS_GetDoubleMatrixFromColumn()

epicsShareFuncSDDS void * SDDS_GetDoubleMatrixFromColumn ( SDDS_DATASET * SDDS_dataset,
char * column_name,
int64_t dimension1,
int64_t dimension2,
int32_t mode )
extern

Extracts a matrix of doubles from a specified column in the current data table of an SDDS dataset.

This function retrieves the data from the specified column as double values and organizes it into a matrix with the given dimensions. The data is arranged in either row-major or column-major order based on the mode parameter. The function allocates memory for the matrix, which should be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
column_nameA null-terminated string specifying the name of the column from which to extract the matrix.
dimension1The number of rows in the resulting matrix.
dimension2The number of columns in the resulting matrix.
modeSpecifies the data layout in the matrix. Use SDDS_ROW_MAJOR_DATA for row-major order or SDDS_COLUMN_MAJOR_DATA for column-major order.
Returns
On success, returns a pointer to the allocated matrix containing double values. The matrix is an array of pointers, where each pointer refers to a row (for row-major) or a column (for column-major) in the matrix. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, column not found, dimension mismatch, memory allocation failure).
Non-NULLPointer to the allocated matrix containing double values.
Note
The caller is responsible for freeing the allocated matrix and its contents.
See also
SDDS_GetMatrixFromColumn, SDDS_GetDoubleMatrixFromRow, SDDS_AllocateMatrix

Definition at line 3214 of file SDDS_extract.c.

3214 {
3215 int32_t size, index;
3216 int64_t n_rows, i, j;
3217 void **data, *column;
3218 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetDoubleMatrixFromColumn"))
3219 return (NULL);
3220 if (!column_name) {
3221 SDDS_SetError("Unable to get matrix--column name is NULL (SDDS_GetDoubleMatrixFromColumn)");
3222 return (NULL);
3223 }
3224 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
3225 SDDS_SetError("Unable to get matrix--no rows selected (SDDS_GetDoubleMatrixFromColumn)");
3226 return (NULL);
3227 }
3228 if (n_rows != dimension1 * dimension2) {
3229 char s[1024];
3230 sprintf(s, "Unable to get matrix--number of rows (%" PRId64 ") doesn't correspond to given dimensions (%" PRId64 " x %" PRId64 ") (SDDS_GetDoubleMatrixFromColumn)", n_rows, dimension1, dimension2);
3231 SDDS_SetError(s);
3232 return (NULL);
3233 }
3234 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
3235 SDDS_SetError("Unable to get matrix--column name is unrecognized (SDDS_GetDoubleMatrixFromColumn)");
3236 return (NULL);
3237 }
3238 if (!(column = SDDS_GetColumnInDoubles(SDDS_dataset, column_name))) {
3239 SDDS_SetError("Unable to get matrix (SDDS_GetDoubleMatrixFromColumn)");
3240 return (NULL);
3241 }
3242 size = sizeof(double);
3243 if (!(data = SDDS_AllocateMatrix(size, dimension1, dimension2))) {
3244 SDDS_SetError("Unable to allocate matrix (SDDS_GetDoubleMatrixFromColumn)");
3245 return (NULL);
3246 }
3247 if (mode & SDDS_ROW_MAJOR_DATA || !(mode & SDDS_COLUMN_MAJOR_DATA)) {
3248 for (i = 0; i < dimension1; i++)
3249 memcpy(data[i], (char *)column + i * dimension2 * size, dimension2 * size);
3250 } else {
3251 for (i = 0; i < dimension1; i++) {
3252 for (j = 0; j < dimension2; j++) {
3253 memcpy((char *)data[i] + size * j, (char *)column + (j * dimension1 + i) * size, size);
3254 }
3255 }
3256 }
3257
3258 free(column);
3259 return (data);
3260}
double * SDDS_GetColumnInDoubles(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves the data of a specified numerical column as an array of doubles, considering only rows mark...
void * SDDS_AllocateMatrix(int32_t size, int64_t dim1, int64_t dim2)
Allocates a two-dimensional matrix with zero-initialized elements.

◆ SDDS_GetErrorMessages()

epicsShareFuncSDDS char ** SDDS_GetErrorMessages ( int32_t * number,
int32_t mode )
extern

Retrieves recorded error messages from the SDDS error stack.

This function fetches error messages that have been recorded by SDDS library routines. Depending on the mode parameter, it can retrieve a single error message or all recorded errors.

Parameters
[out]numberPointer to an int32_t variable where the number of retrieved error messages will be stored. If NULL, the function returns NULL.
[in]modeFlags controlling the retrieval behavior:
  • 0: Retrieve only the most recent error message.
  • SDDS_ALL_GetErrorMessages: Retrieve all recorded error messages.
Returns
A dynamically allocated array of strings containing the error messages. Returns NULL if no errors are recorded or if memory allocation fails.
Note
The caller is responsible for freeing the memory allocated for the returned error messages.
See also
SDDS_SetError
SDDS_ClearErrors

Definition at line 480 of file SDDS_utils.c.

480 {
481 int32_t i, depth;
482 char **message;
483
484 if (!number)
485 return NULL;
486
487 *number = 0;
488 if (!n_errors)
489 return NULL;
490
491 if (mode & SDDS_ALL_GetErrorMessages)
492 depth = n_errors;
493 else
494 depth = 1;
495 if (!(message = (char **)SDDS_Malloc(sizeof(*message) * depth)))
496 return NULL;
497 if (!error_description) {
498 fprintf(stderr, "warning: internal error: error_description pointer is unexpectedly NULL (SDDS_GetErrorMessages)\n");
499 return NULL;
500 } else {
501 for (i = depth - 1; i >= 0; i--) {
502 if (!error_description[i]) {
503 fprintf(stderr, "internal error: error_description[%" PRId32 "] is unexpectedly NULL (SDDS_GetErrorMessages)\n", i);
504 return NULL;
505 }
506 if (!SDDS_CopyString(message + i, error_description[i])) {
507 fprintf(stderr, "unable to copy error message text (SDDS_GetErrorMessages)\n");
508 return NULL;
509 }
510 }
511 }
512 *number = depth;
513 return message;
514}

◆ SDDS_GetFixedValueParameter()

epicsShareFuncSDDS void * SDDS_GetFixedValueParameter ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
void * memory )
extern

Retrieves the fixed value of a specified parameter from an SDDS dataset.

This function accesses the fixed value defined for a given parameter in the dataset's layout and converts it to the appropriate data type. If the memory pointer is provided, the converted value is stored at the specified memory location. Otherwise, memory is allocated internally to hold the value, which must be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter whose fixed value is to be retrieved.
memoryOptional pointer to a memory location where the fixed value will be stored. The size of the memory should correspond to the size of the parameter's data type. If NULL, memory is allocated internally to hold the value.
Returns
On success, returns a pointer to the memory containing the fixed value. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, parameter not found, invalid data type, memory allocation failure, or scan failure).
Non-NULLPointer to the memory containing the fixed parameter value.
Note
The caller is responsible for freeing the allocated memory if the memory parameter is NULL.
See also
SDDS_SetParameterFixedValue, SDDS_GetParameterAsDouble, SDDS_GetParameterAsString

Definition at line 3084 of file SDDS_extract.c.

3084 {
3085 int32_t index, type, size;
3086 void *data;
3087 char s[SDDS_MAXLINE];
3088
3089 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetFixValueParameter"))
3090 return (NULL);
3091 if (!parameter_name) {
3092 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetFixedValueParameter)");
3093 return (NULL);
3094 }
3095 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
3096 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetFixedValueParameter)");
3097 return (NULL);
3098 }
3099 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
3100 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetFixedValueParameter)");
3101 return (NULL);
3102 }
3103 size = SDDS_type_size[type - 1];
3104 if (memory)
3105 data = memory;
3106 else if (!(data = SDDS_Malloc(size))) {
3107 SDDS_SetError("Unable to get parameter value--parameter data size is invalid (SDDS_GetFixedValueParameter)");
3108 return (NULL);
3109 }
3110 strcpy(s, SDDS_dataset->layout.parameter_definition[index].fixed_value);
3111 if (!SDDS_ScanData(s, type, 0, data, 0, 1)) {
3112 SDDS_SetError("Unable to retrieve fixed-value paramter--scan failed (SDDS_GetFixedValueParameter)");
3113 return (NULL);
3114 }
3115 return (data);
3116}

◆ SDDS_GetInternalColumn()

epicsShareFuncSDDS void * SDDS_GetInternalColumn ( SDDS_DATASET * SDDS_dataset,
char * column_name )
extern

Retrieves an internal pointer to the data of a specified column, including all rows.

This function returns a direct pointer to the internal data array of the specified column. Unlike SDDS_GetColumn, it includes all rows, regardless of their acceptance flags.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column to retrieve.
Returns
  • Pointer to the internal data array on success. The type of the pointer corresponds to the column's data type.
  • NULL on failure, with an error message recorded (e.g., unrecognized column name).
Warning
Modifying the data through the returned pointer affects the internal state of the dataset. Use with caution to avoid unintended side effects.
Note
  • If the column's memory mode is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data may be freed after access.
  • This function does not allocate new memory; it provides direct access to the dataset's internal structures.
See also
SDDS_GetColumn, SDDS_SetColumnFlags, SDDS_CountColumnsOfInterest

Definition at line 688 of file SDDS_extract.c.

688 {
689 int32_t index;
690 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetInternalColumn"))
691 return (NULL);
692 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
693 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetInternalColumn)");
694 return (NULL);
695 }
696 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
697 SDDS_dataset->column_track_memory[index] = 0;
698 }
699 return SDDS_dataset->data[index];
700}

◆ SDDS_GetMatrixFromColumn()

epicsShareFuncSDDS void * SDDS_GetMatrixFromColumn ( SDDS_DATASET * SDDS_dataset,
char * column_name,
int64_t dimension1,
int64_t dimension2,
int32_t mode )
extern

Extracts a matrix from a specified column in the current data table of an SDDS dataset.

This function retrieves the data from the specified column and organizes it into a matrix with the given dimensions. The data is arranged in either row-major or column-major order based on the mode parameter. The function allocates memory for the matrix, which should be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
column_nameA null-terminated string specifying the name of the column from which to extract the matrix.
dimension1The number of rows in the resulting matrix.
dimension2The number of columns in the resulting matrix.
modeSpecifies the data layout in the matrix. Use SDDS_ROW_MAJOR_DATA for row-major order or SDDS_COLUMN_MAJOR_DATA for column-major order.
Returns
On success, returns a pointer to the allocated matrix. The matrix is an array of pointers, where each pointer refers to a row (for row-major) or a column (for column-major) in the matrix. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, column not found, dimension mismatch, memory allocation failure).
Non-NULLPointer to the allocated matrix.
Note
The caller is responsible for freeing the allocated matrix and its contents.
See also
SDDS_GetDoubleMatrixFromColumn, SDDS_GetMatrixFromRow, SDDS_AllocateMatrix

Definition at line 3142 of file SDDS_extract.c.

3142 {
3143 int32_t size, type, index;
3144 int64_t n_rows, i, j;
3145 void **data, *column;
3146 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetMatrixFromColumn"))
3147 return (NULL);
3148 if (!column_name) {
3149 SDDS_SetError("Unable to get matrix--column name is NULL (SDDS_GetMatrixFromColumn)");
3150 return (NULL);
3151 }
3152 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
3153 SDDS_SetError("Unable to get matrix--no rows selected (SDDS_GetMatrixFromColumn)");
3154 return (NULL);
3155 }
3156 if (n_rows != dimension1 * dimension2) {
3157 char s[1024];
3158 sprintf(s, "Unable to get matrix--number of rows (%" PRId64 ") doesn't correspond to given dimensions (%" PRId64 " x %" PRId64 ") (SDDS_GetMatrixFromColumn)", n_rows, dimension1, dimension2);
3159 SDDS_SetError(s);
3160 return (NULL);
3161 }
3162 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0 || (type = SDDS_GetColumnType(SDDS_dataset, index)) < 0 || (size = SDDS_GetTypeSize(type)) <= 0) {
3163 SDDS_SetError("Unable to get matrix--column name is unrecognized (SDDS_GetMatrixFromColumn)");
3164 return (NULL);
3165 }
3166 if (!(column = SDDS_GetColumn(SDDS_dataset, column_name))) {
3167 SDDS_SetError("Unable to get matrix (SDDS_GetMatrixFromColumn)");
3168 return (NULL);
3169 }
3170 if (!(data = SDDS_AllocateMatrix(size, dimension1, dimension2))) {
3171 SDDS_SetError("Unable to allocate matrix (SDDS_GetMatrixFromColumn)");
3172 return (NULL);
3173 }
3174 if (mode & SDDS_ROW_MAJOR_DATA || !(mode & SDDS_COLUMN_MAJOR_DATA)) {
3175 for (i = 0; i < dimension1; i++)
3176 memcpy(data[i], (char *)column + i * dimension2 * size, dimension2 * size);
3177 } else {
3178 for (i = 0; i < dimension1; i++) {
3179 for (j = 0; j < dimension2; j++) {
3180 memcpy((char *)data[i] + size * j, (char *)column + (j * dimension1 + i) * size, size);
3181 }
3182 }
3183 }
3184
3185 free(column);
3186 return (data);
3187}
void * SDDS_GetColumn(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves a copy of the data for a specified column, including only rows marked as "of interest".

◆ SDDS_GetMatrixOfRows()

epicsShareFuncSDDS void * SDDS_GetMatrixOfRows ( SDDS_DATASET * SDDS_dataset,
int64_t * n_rows )
extern

Retrieves all rows marked as "of interest" as a matrix (array of row arrays).

This function extracts all rows that are flagged as "of interest" within the current data table of a dataset. It processes only those columns that are flagged as "of interest" and returns the data as a matrix, where each row is an array of values corresponding to the selected columns.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
n_rowsPointer to an int64_t variable where the number of rows retrieved will be stored.
Returns
  • Pointer to an array of pointers, where each pointer references a row's data array.
  • NULL if an error occurs (e.g., invalid dataset, no columns selected, inconsistent row types, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks. This includes freeing each individual row array followed by the array of pointers itself.
  • All selected columns must have the same data type. If there is an inconsistency, the function will fail.
Note
  • The number of rows retrieved is stored in the variable pointed to by n_rows.
  • For columns containing string data (SDDS_STRING), each element in the row arrays is a dynamically allocated string that must be freed individually.
  • If the dataset's memory mode for the columns is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the columns may be freed after access.
See also

Definition at line 2266 of file SDDS_extract.c.

2266 {
2267 void **data;
2268 int32_t size, type;
2269 int64_t i, j, k;
2270 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetMatrixOfRows"))
2271 return (NULL);
2272 if (SDDS_dataset->n_of_interest <= 0) {
2273 SDDS_SetError("Unable to get matrix of rows--no columns selected (SDDS_GetMatrixOfRows)");
2274 return (NULL);
2275 }
2276 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_GetMatrixOfRows"))
2277 return (NULL);
2278 if ((type = SDDS_GetRowType(SDDS_dataset)) <= 0) {
2279 SDDS_SetError("Unable to get row--inconsistent data type in selected columns (SDDS_GetMatrixOfRows)");
2280 return (NULL);
2281 }
2282 size = SDDS_type_size[type - 1];
2283 if ((*n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
2284 SDDS_SetError("Unable to get matrix of rows--no rows of interest (SDDS_GetMatrixOfRows)");
2285 return (NULL);
2286 }
2287 if (!(data = (void **)SDDS_Malloc(sizeof(*data) * (*n_rows)))) {
2288 SDDS_SetError("Unable to get matrix of rows--memory allocation failure (SDDS_GetMatrixOfRows)");
2289 return (NULL);
2290 }
2291 for (j = k = 0; j < SDDS_dataset->n_rows; j++) {
2292 if (SDDS_dataset->row_flag[j]) {
2293 if (!(data[k] = SDDS_Malloc(size * SDDS_dataset->n_of_interest))) {
2294 SDDS_SetError("Unable to get matrix of rows--memory allocation failure (SDDS_GetMatrixOfRows)");
2295 return (NULL);
2296 }
2297 if (type != SDDS_STRING)
2298 for (i = 0; i < SDDS_dataset->n_of_interest; i++)
2299 memcpy((char *)data[k] + i * size, (char *)SDDS_dataset->data[SDDS_dataset->column_order[i]] + j * size, size);
2300 else
2301 for (i = 0; i < SDDS_dataset->n_of_interest; i++)
2302 if (!SDDS_CopyString((char **)(data[k]) + i, ((char **)SDDS_dataset->data[SDDS_dataset->column_order[i]])[j]))
2303 return (NULL);
2304 k++;
2305 }
2306 }
2307 return (data);
2308}
int32_t SDDS_GetRowType(SDDS_DATASET *SDDS_dataset)
Determines the data type of the rows based on selected columns in the current data table.

◆ SDDS_GetNamedArrayType()

epicsShareFuncSDDS int32_t SDDS_GetNamedArrayType ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the data type of an array in the SDDS dataset by its name.

This function searches for an array by its name within the dataset and returns its SDDS data type. The data type corresponds to one of the predefined SDDS type constants, such as SDDS_LONGDOUBLE, SDDS_DOUBLE, SDDS_FLOAT, etc.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the array whose data type is to be retrieved.
Returns
On success, returns the SDDS data type of the array as an int32_t. On failure (e.g., if the array name is not found or the dataset is invalid), returns 0 and records an error message.
Note
The function internally uses SDDS_GetArrayIndex to find the array's index before retrieving its type.
See also
SDDS_GetArrayIndex
SDDS_SetError

Definition at line 2227 of file SDDS_utils.c.

2227 {
2228 int32_t index;
2229 if ((index = SDDS_GetArrayIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_arrays) {
2230 SDDS_SetError("Unable to get array type--array index is out of range (SDDS_GetNamedArrayType)");
2231 return (0);
2232 }
2233 return (SDDS_dataset->layout.array_definition[index].type);
2234}

◆ SDDS_GetNamedColumnType()

epicsShareFuncSDDS int32_t SDDS_GetNamedColumnType ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the data type of a column in the SDDS dataset by its name.

This function searches for a column by its name within the dataset and returns its SDDS data type. The data type corresponds to one of the predefined SDDS type constants, such as SDDS_LONGDOUBLE, SDDS_DOUBLE, SDDS_FLOAT, etc.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the column whose data type is to be retrieved.
Returns
On success, returns the SDDS data type of the column as an int32_t. On failure (e.g., if the column name is not found or the dataset is invalid), returns 0 and records an error message.
Note
The function internally uses SDDS_GetColumnIndex to find the column's index before retrieving its type.
See also
SDDS_GetColumnIndex
SDDS_SetError

Definition at line 2178 of file SDDS_utils.c.

2178 {
2179 int64_t index;
2180 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_columns) {
2181 SDDS_SetError("Unable to get column type--column index is out of range (SDDS_GetNamedColumnType)");
2182 return (0);
2183 }
2184 return (SDDS_dataset->layout.column_definition[index].type);
2185}

◆ SDDS_GetNamedParameterType()

epicsShareFuncSDDS int32_t SDDS_GetNamedParameterType ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the data type of a parameter in the SDDS dataset by its name.

This function searches for a parameter by its name within the dataset and returns its SDDS data type. The data type corresponds to one of the predefined SDDS type constants, such as SDDS_LONGDOUBLE, SDDS_DOUBLE, SDDS_FLOAT, etc.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the parameter whose data type is to be retrieved.
Returns
On success, returns the SDDS data type of the parameter as an int32_t. On failure (e.g., if the parameter name is not found or the dataset is invalid), returns 0 and records an error message.
Note
The function internally uses SDDS_GetParameterIndex to find the parameter's index before retrieving its type.
See also
SDDS_GetParameterIndex
SDDS_SetError

Definition at line 2276 of file SDDS_utils.c.

2276 {
2277 int32_t index;
2278 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_parameters) {
2279 SDDS_SetError("Unable to get parameter type--parameter index is out of range (SDDS_GetNamedParameterType)");
2280 return (0);
2281 }
2282 return (SDDS_dataset->layout.parameter_definition[index].type);
2283}

◆ SDDS_GetNumericColumn()

epicsShareFuncSDDS void * SDDS_GetNumericColumn ( SDDS_DATASET * SDDS_dataset,
char * column_name,
int32_t desiredType )
extern

Retrieves the data of a specified numerical column as an array of a desired numerical type, considering only rows marked as "of interest".

This function extracts data from a specified column within the current data table of a dataset. It processes only those rows that are flagged as "of interest" (i.e., have a non-zero acceptance flag). The extracted data is returned as a newly allocated array of the specified numerical type.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which data is to be retrieved.
desiredTypeInteger constant representing the desired data type for the returned array. Must be one of the supported SDDS numerical types (e.g., SDDS_DOUBLE, SDDS_FLOAT, etc.).
Returns
  • Pointer to an array of the desired numerical type containing the data from the specified column for all rows marked as "of interest".
  • NULL if an error occurs (e.g., invalid dataset, unrecognized column name, non-numeric column type, memory allocation failure, type casting failure). In this case, an error message is recorded internally.
Warning
  • The caller is responsible for freeing the allocated memory to prevent memory leaks.
  • This function assumes that the specified column contains numerical data. Attempting to retrieve data from a non-numeric column (excluding SDDS_CHARACTER) will result in an error.
Note
  • The number of elements in the returned array corresponds to the number of rows marked as "of interest", which can be obtained using SDDS_CountRowsOfInterest.
  • If the dataset's memory mode for the column is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the column may be freed after access.
  • If the desiredType matches the column's data type, this function internally calls SDDS_GetColumn. Otherwise, it performs type casting using SDDS_CastValue.
See also

Definition at line 1617 of file SDDS_extract.c.

1617 {
1618 int32_t size, type, desiredTypeSize, index;
1619 int64_t i, j, n_rows;
1620 void *data;
1621 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetNumericColumn"))
1622 return (NULL);
1623 if (!SDDS_NUMERIC_TYPE(desiredType) && desiredType != SDDS_CHARACTER) {
1624 SDDS_SetError("Unable to get column--desired type is nonnumeric (SDDS_GetNumericColumn)");
1625 return (NULL);
1626 }
1627 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
1628 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetNumericColumn)");
1629 return (NULL);
1630 }
1631 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) <= 0 || (size = SDDS_GetTypeSize(type)) <= 0 || (!SDDS_NUMERIC_TYPE(type) && type != SDDS_CHARACTER)) {
1632 SDDS_SetError("Unable to get column--data size or type undefined or non-numeric (SDDS_GetNumericColumn)");
1633 return (NULL);
1634 }
1635 if (type == desiredType)
1636 return SDDS_GetColumn(SDDS_dataset, column_name);
1637 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
1638 SDDS_SetError("Unable to get column--no rows left (SDDS_GetNumericColumn)");
1639 return (NULL);
1640 }
1641 if (!(data = (void *)SDDS_Malloc((desiredTypeSize = SDDS_GetTypeSize(desiredType)) * n_rows))) {
1642 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetNumericColumn)");
1643 return (NULL);
1644 }
1645 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
1646 if (SDDS_dataset->row_flag[i] && !SDDS_CastValue(SDDS_dataset->data[index], i, type, desiredType, (char *)data + desiredTypeSize * j++)) {
1647 SDDS_SetError("Unable to get column--cast to double failed (SDDS_GetNumericColumn)");
1648 return (NULL);
1649 }
1650 }
1651 if (j != n_rows) {
1652 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetNumericColumn)");
1653 return (NULL);
1654 }
1655 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
1656 SDDS_dataset->column_track_memory[index] = 0;
1657 //Free internal copy now under the assumption that the program will not ask for it again.
1658 if (type == SDDS_STRING) {
1659 if (0) {
1660 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
1661 char **ptr = (char **)SDDS_dataset->data[index];
1662 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
1663 if (*ptr)
1664 free(*ptr);
1665 free(SDDS_dataset->data[index]);
1666 SDDS_dataset->data[index] = NULL;
1667 }
1668 } else {
1669 free(SDDS_dataset->data[index]);
1670 SDDS_dataset->data[index] = NULL;
1671 }
1672 }
1673 return (data);
1674}

◆ SDDS_GetParameter()

epicsShareFuncSDDS void * SDDS_GetParameter ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
void * memory )
extern

Retrieves the value of a specified parameter from the current data table of a data set.

This function accesses the value of a specific parameter (identified by its name) within the current data table of a dataset. The retrieved value is either copied into user-provided memory or returned as a direct pointer to the internal data.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
parameter_nameNULL-terminated string specifying the name of the parameter from which the value is to be retrieved.
memoryPointer to user-allocated memory where the retrieved parameter value will be stored. If NULL, the function allocates memory.
Returns
  • Pointer to the retrieved parameter value stored in memory (if provided) or to newly allocated memory.
  • NULL if an error occurs (e.g., invalid dataset, unrecognized parameter name, undefined data type, memory allocation failure, string copy failure). In this case, an error message is recorded internally.
Warning
  • If memory is NULL, the function allocates memory that the caller must free to prevent memory leaks.
  • For parameters containing string data (SDDS_STRING), the function copies the string into memory. A typical usage would involve passing a pointer to a char* variable. c char *string; SDDS_GetParameter(&SDDS_dataset, "parameter_name", &string); // or string = *(char**)SDDS_GetParameter(&SDDS_dataset, "parameter_name", NULL);
Note
  • The size of the allocated memory corresponds to the parameter's data type, which can be obtained using SDDS_GetParameterType.
  • If the dataset's memory mode for the parameter is set to DONT_TRACK_PARAMETER_MEMORY_AFTER_ACCESS, the internal data for the parameter may be freed after access.
See also

Definition at line 2481 of file SDDS_extract.c.

2481 {
2482 int32_t index, type, size;
2483 char s[SDDS_MAXLINE];
2484 void *data;
2485 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameter"))
2486 return (NULL);
2487 if (!parameter_name) {
2488 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameter)");
2489 return (NULL);
2490 }
2491 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
2492 sprintf(s, "Unable to get parameter value--parameter name %s is unrecognized (SDDS_GetParameter)", parameter_name);
2493 SDDS_SetError(s);
2494 return (NULL);
2495 }
2496 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2497 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameter)");
2498 return (NULL);
2499 }
2500 if (!SDDS_dataset->parameter || !SDDS_dataset->parameter[index]) {
2501 SDDS_SetError("Unable to get parameter value--parameter data array is NULL (SDDS_GetParameter)");
2502 return (NULL);
2503 }
2504 size = SDDS_type_size[type - 1];
2505 if (memory)
2506 data = memory;
2507 else if (!(data = SDDS_Malloc(size))) {
2508 SDDS_SetError("Unable to get parameter value--parameter data size is invalid (SDDS_GetParameter)");
2509 return (NULL);
2510 }
2511 if (type != SDDS_STRING)
2512 memcpy(data, SDDS_dataset->parameter[index], size);
2513 else if (!SDDS_CopyString((char **)data, *(char **)SDDS_dataset->parameter[index]))
2514 return (NULL);
2515 return (data);
2516}

◆ SDDS_GetParameterAsDouble()

epicsShareFuncSDDS double * SDDS_GetParameterAsDouble ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
double * memory )
extern

Retrieves the value of a specified parameter as a double from the current data table of an SDDS dataset.

This function searches for the parameter by name within the provided SDDS dataset and retrieves its value as a double. If the memory pointer is supplied, the value is stored at the specified memory location. If memory is NULL, the function allocates memory for storing the value, which should be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to retrieve.
memoryOptional pointer to a double variable where the parameter value will be stored. If NULL, memory is allocated internally to hold the value.
Returns
On success, returns a pointer to the double containing the parameter value. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, parameter not found, type mismatch, or memory allocation failure).
Non-NULLPointer to the double containing the parameter value.
Note
The caller is responsible for freeing the allocated memory if the memory parameter is NULL.
See also
SDDS_GetParameterAsLong64, SDDS_GetParameterAsLongDouble, SDDS_GetParameterAsString

Definition at line 2782 of file SDDS_extract.c.

2782 {
2783 int32_t index = -1, type = -1;
2784 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterAsDouble"))
2785 return (NULL);
2786 if (!parameter_name) {
2787 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameterAsDouble)");
2788 return (NULL);
2789 }
2790 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
2791 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetParameterAsDouble)");
2792 return (NULL);
2793 }
2794 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2795 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterAsDouble)");
2796 return (NULL);
2797 }
2798 if (type == SDDS_STRING) {
2799 SDDS_SetError("Unable to get parameter value--parameter data type is SDDS_STRING (SDDS_GetParameterAsDouble)");
2800 return (NULL);
2801 }
2802 if (!SDDS_dataset->parameter || !SDDS_dataset->parameter[index]) {
2803 SDDS_SetError("Unable to get parameter value--parameter data array is NULL (SDDS_GetParameterAsDouble)");
2804 return (NULL);
2805 }
2806
2807 if (!memory && !(memory = (double *)SDDS_Malloc(sizeof(double)))) {
2808 SDDS_SetError("Unable to get parameter value--memory allocation failure (SDDS_GetParameterAsDouble)");
2809 return (NULL);
2810 }
2811 *memory = SDDS_ConvertToDouble(type, SDDS_dataset->parameter[index], 0);
2812 return (memory);
2813}
double SDDS_ConvertToDouble(int32_t type, void *data, int64_t index)
Converts a value to double based on its type.
Definition SDDS_rpn.c:199

◆ SDDS_GetParameterAsFormattedString()

epicsShareFuncSDDS char * SDDS_GetParameterAsFormattedString ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
char ** memory,
char * suppliedformat )
extern

Retrieves the value of a specified parameter as a formatted string from the current data table of an SDDS dataset.

This function searches for the parameter by name within the provided SDDS dataset, formats its value based on the supplied format string, and returns it as a null-terminated string. If suppliedformat is NULL, the function uses the format string defined in the parameter's definition. If the memory pointer is provided, the formatted string is stored at the specified memory location. Otherwise, memory is allocated internally to hold the string, which must be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to retrieve.
memoryOptional pointer to a char* variable where the formatted string will be stored. If NULL, memory is allocated internally to hold the string.
suppliedformatA null-terminated format string (similar to printf format specifiers) to format the parameter value. If NULL, the function uses the format string defined in the parameter's definition within the dataset.
Returns
On success, returns a pointer to the null-terminated formatted string containing the parameter value. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, parameter not found, invalid format string, type mismatch, memory allocation failure, or unknown data type).
Non-NULLPointer to the null-terminated string containing the formatted parameter value.
Note
The caller is responsible for freeing the allocated memory if the memory parameter is NULL.
See also
SDDS_GetParameterAsDouble, SDDS_GetParameterAsString, SDDS_GetParameterAsLong64, SDDS_GetParameterAsLongDouble

Definition at line 2935 of file SDDS_extract.c.

2935 {
2936 int32_t index, type;
2937 char buffer[SDDS_MAXLINE], *parValue;
2938 void *value;
2939 char *format = NULL;
2940
2941 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterAsFormattedString"))
2942 return (NULL);
2943 if (!parameter_name) {
2944 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameterAsFormattedString)");
2945 return (NULL);
2946 }
2947 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
2948 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetParameterAsFormattedString)");
2949 return (NULL);
2950 }
2951 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2952 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterAsFormattedString)");
2953 return (NULL);
2954 }
2955 if (suppliedformat != NULL) {
2956 format = suppliedformat;
2957 if (!SDDS_VerifyPrintfFormat(format, type)) {
2958 SDDS_SetError("Unable to get parameter value--given format for parameter is invalid (SDDS_GetParameterAsFormattedString)");
2959 return (NULL);
2960 }
2961 } else {
2962 if (SDDS_GetParameterInformation(SDDS_dataset, "format_string", &format, SDDS_GET_BY_INDEX, index) != SDDS_STRING) {
2963 SDDS_SetError("Unable to get parameter value--parameter definition is invalid (SDDS_GetParameterAsFormattedString)");
2964 return (NULL);
2965 }
2966 }
2967 value = SDDS_dataset->parameter[index];
2968
2969 if (!SDDS_StringIsBlank(format)) {
2970 switch (type) {
2971 case SDDS_LONGDOUBLE:
2972 sprintf(buffer, format, *(long double *)value);
2973 break;
2974 case SDDS_DOUBLE:
2975 sprintf(buffer, format, *(double *)value);
2976 break;
2977 case SDDS_FLOAT:
2978 sprintf(buffer, format, *(float *)value);
2979 break;
2980 case SDDS_LONG64:
2981 sprintf(buffer, format, *(int64_t *)value);
2982 break;
2983 case SDDS_ULONG64:
2984 sprintf(buffer, format, *(uint64_t *)value);
2985 break;
2986 case SDDS_LONG:
2987 sprintf(buffer, format, *(int32_t *)value);
2988 break;
2989 case SDDS_ULONG:
2990 sprintf(buffer, format, *(uint32_t *)value);
2991 break;
2992 case SDDS_SHORT:
2993 sprintf(buffer, format, *(short *)value);
2994 break;
2995 case SDDS_USHORT:
2996 sprintf(buffer, format, *(unsigned short *)value);
2997 break;
2998 case SDDS_CHARACTER:
2999 sprintf(buffer, format, *(char *)value);
3000 break;
3001 case SDDS_STRING:
3002 sprintf(buffer, format, *(char **)value);
3003 break;
3004 default:
3005 SDDS_SetError("Unknown data type of parameter (SDDS_GetParameterAsFormattedString)");
3006 return (NULL);
3007 }
3008 } else {
3009 switch (type) {
3010 case SDDS_LONGDOUBLE:
3011 if (LDBL_DIG == 18) {
3012 sprintf(buffer, "%22.18Le", *(long double *)value);
3013 } else {
3014 sprintf(buffer, "%22.15Le", *(long double *)value);
3015 }
3016 break;
3017 case SDDS_DOUBLE:
3018 sprintf(buffer, "%22.15le", *(double *)value);
3019 break;
3020 case SDDS_FLOAT:
3021 sprintf(buffer, "%15.8e", *(float *)value);
3022 break;
3023 case SDDS_LONG64:
3024 sprintf(buffer, "%" PRId64, *(int64_t *)value);
3025 break;
3026 case SDDS_ULONG64:
3027 sprintf(buffer, "%" PRIu64, *(uint64_t *)value);
3028 break;
3029 case SDDS_LONG:
3030 sprintf(buffer, "%" PRId32, *(int32_t *)value);
3031 break;
3032 case SDDS_ULONG:
3033 sprintf(buffer, "%" PRIu32, *(uint32_t *)value);
3034 break;
3035 case SDDS_SHORT:
3036 sprintf(buffer, "%hd", *(short *)value);
3037 break;
3038 case SDDS_USHORT:
3039 sprintf(buffer, "%hu", *(unsigned short *)value);
3040 break;
3041 case SDDS_CHARACTER:
3042 sprintf(buffer, "%c", *(char *)value);
3043 break;
3044 case SDDS_STRING:
3045 sprintf(buffer, "%s", *(char **)value);
3046 break;
3047 default:
3048 SDDS_SetError("Unknown data type of parameter (SDDS_GetParameterAsFormattedString)");
3049 return (NULL);
3050 }
3051 }
3052 if (!(parValue = malloc(sizeof(char) * (strlen(buffer) + 1)))) {
3053 SDDS_SetError("Unable to get parameter value--memory allocation failure (SDDS_GetParameterAsFormattedString)");
3054 return (NULL);
3055 }
3056 strcpy(parValue, buffer);
3057 if (memory)
3058 *memory = parValue;
3059 return parValue;
3060}

◆ SDDS_GetParameterAsLong()

epicsShareFuncSDDS int32_t * SDDS_GetParameterAsLong ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
int32_t * memory )
extern

Retrieves the value of a specified parameter as a 32-bit integer from the current data table of a data set.

This function accesses the value of a specific parameter (identified by its name) within the current data table of a dataset and converts it to a 32-bit integer (int32_t). The converted value is either stored in user-provided memory or allocated by the function.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
parameter_nameNULL-terminated string specifying the name of the parameter from which the value is to be retrieved.
memoryPointer to a 32-bit integer where the converted parameter value will be stored. If NULL, the function allocates memory.
Returns
  • Pointer to the int32_t value stored in memory (if provided) or to newly allocated memory containing the converted value.
  • NULL if an error occurs (e.g., invalid dataset, unrecognized parameter name, undefined data type, memory allocation failure, parameter type is SDDS_STRING). In this case, an error message is recorded internally.
Warning
  • If memory is NULL, the function allocates memory that the caller must free to prevent memory leaks.
  • This function does not support parameters of type SDDS_STRING. Attempting to retrieve string parameters as long integers will result in an error.
Note
  • The conversion is performed using SDDS_ConvertToLong, which handles casting from various numerical types to int32_t.
  • Ensure that the parameter's data type is compatible with 32-bit integer conversion to avoid data loss or undefined behavior.
See also

Definition at line 2615 of file SDDS_extract.c.

2615 {
2616 int32_t index, type;
2617 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterAsLong"))
2618 return (NULL);
2619 if (!parameter_name) {
2620 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameterAsLong)");
2621 return (NULL);
2622 }
2623 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
2624 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetParameterAsLong)");
2625 return (NULL);
2626 }
2627 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2628 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterAsLong)");
2629 return (NULL);
2630 }
2631 if (type == SDDS_STRING) {
2632 SDDS_SetError("Unable to get parameter value--parameter data type is SDDS_STRING (SDDS_GetParameterAsLong)");
2633 return (NULL);
2634 }
2635 if (!SDDS_dataset->parameter || !SDDS_dataset->parameter[index]) {
2636 SDDS_SetError("Unable to get parameter value--parameter data array is NULL (SDDS_GetParameterAsLong)");
2637 return (NULL);
2638 }
2639
2640 if (!memory && !(memory = (int32_t *)SDDS_Malloc(sizeof(int32_t)))) {
2641 SDDS_SetError("Unable to get parameter value--memory allocation failure (SDDS_GetParameterAsLong)");
2642 return (NULL);
2643 }
2644
2645 *memory = SDDS_ConvertToLong(type, SDDS_dataset->parameter[index], 0);
2646 return (memory);
2647}
int32_t SDDS_ConvertToLong(int32_t type, void *data, int64_t index)
Converts a value to a 32-bit integer based on its type.
Definition SDDS_rpn.c:279

◆ SDDS_GetParameterAsLong64()

epicsShareFuncSDDS int64_t * SDDS_GetParameterAsLong64 ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
int64_t * memory )
extern

Retrieves the value of a specified parameter as a 64-bit integer from the current data table of an SDDS dataset.

This function looks up the parameter by name within the given SDDS dataset and returns its value as an int64_t. If the memory pointer is provided, the value is stored at the given memory location. Otherwise, the function allocates memory to store the value, which must be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to retrieve.
memoryOptional pointer to an int64_t variable where the parameter value will be stored. If NULL, memory is allocated internally to hold the value.
Returns
On success, returns a pointer to the int64_t containing the parameter value. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, parameter not found, type mismatch, or memory allocation failure).
Non-NULLPointer to the int64_t containing the parameter value.
Note
The caller is responsible for freeing the allocated memory if the memory parameter is NULL.
See also
SDDS_GetParameterAsDouble, SDDS_GetParameterAsString

Definition at line 2671 of file SDDS_extract.c.

2671 {
2672 int32_t index, type;
2673 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterAsLong64"))
2674 return (NULL);
2675 if (!parameter_name) {
2676 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameterAsLong64)");
2677 return (NULL);
2678 }
2679 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
2680 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetParameterAsLong64)");
2681 return (NULL);
2682 }
2683 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2684 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterAsLong64)");
2685 return (NULL);
2686 }
2687 if (type == SDDS_STRING) {
2688 SDDS_SetError("Unable to get parameter value--parameter data type is SDDS_STRING (SDDS_GetParameterAsLong64)");
2689 return (NULL);
2690 }
2691 if (!SDDS_dataset->parameter || !SDDS_dataset->parameter[index]) {
2692 SDDS_SetError("Unable to get parameter value--parameter data array is NULL (SDDS_GetParameterAsLong64)");
2693 return (NULL);
2694 }
2695
2696 if (!memory && !(memory = (int64_t *)SDDS_Malloc(sizeof(int64_t)))) {
2697 SDDS_SetError("Unable to get parameter value--memory allocation failure (SDDS_GetParameterAsLong64)");
2698 return (NULL);
2699 }
2700
2701 *memory = SDDS_ConvertToLong64(type, SDDS_dataset->parameter[index], 0);
2702 return (memory);
2703}
int64_t SDDS_ConvertToLong64(int32_t type, void *data, int64_t index)
Converts a value to a 64-bit integer based on its type.
Definition SDDS_rpn.c:239

◆ SDDS_GetParameterAsLongDouble()

epicsShareFuncSDDS long double * SDDS_GetParameterAsLongDouble ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
long double * memory )
extern

Retrieves the value of a specified parameter as a long double from the current data table of an SDDS dataset.

This function searches for the parameter by name within the provided SDDS dataset and retrieves its value as a long double. If the memory pointer is supplied, the value is stored at the specified memory location. If memory is NULL, the function allocates memory for storing the value, which should be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to retrieve.
memoryOptional pointer to a long double variable where the parameter value will be stored. If NULL, memory is allocated internally to hold the value.
Returns
On success, returns a pointer to the long double containing the parameter value. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, parameter not found, type mismatch, or memory allocation failure).
Non-NULLPointer to the long double containing the parameter value.
Note
The caller is responsible for freeing the allocated memory if the memory parameter is NULL.
See also
SDDS_GetParameterAsDouble, SDDS_GetParameterAsLong64, SDDS_GetParameterAsString

Definition at line 2727 of file SDDS_extract.c.

2727 {
2728 int32_t index = -1, type = -1;
2729 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterAsLongDouble"))
2730 return (NULL);
2731 if (!parameter_name) {
2732 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameterAsLongDouble)");
2733 return (NULL);
2734 }
2735 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
2736 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetParameterAsLongDouble)");
2737 return (NULL);
2738 }
2739 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2740 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterAsLongDouble)");
2741 return (NULL);
2742 }
2743 if (type == SDDS_STRING) {
2744 SDDS_SetError("Unable to get parameter value--parameter data type is SDDS_STRING (SDDS_GetParameterAsLongDouble)");
2745 return (NULL);
2746 }
2747 if (!SDDS_dataset->parameter || !SDDS_dataset->parameter[index]) {
2748 SDDS_SetError("Unable to get parameter value--parameter data array is NULL (SDDS_GetParameterAsLongDouble)");
2749 return (NULL);
2750 }
2751
2752 if (!memory && !(memory = (long double *)SDDS_Malloc(sizeof(long double)))) {
2753 SDDS_SetError("Unable to get parameter value--memory allocation failure (SDDS_GetParameterAsLongDouble)");
2754 return (NULL);
2755 }
2756 *memory = SDDS_ConvertToLongDouble(type, SDDS_dataset->parameter[index], 0);
2757 return (memory);
2758}
long double SDDS_ConvertToLongDouble(int32_t type, void *data, int64_t index)
Converts a value to long double based on its type.
Definition SDDS_rpn.c:159

◆ SDDS_GetParameterAsString()

epicsShareFuncSDDS char * SDDS_GetParameterAsString ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
char ** memory )
extern

Retrieves the value of a specified parameter as a string from the current data table of an SDDS dataset.

This function searches for the parameter by name within the provided SDDS dataset and retrieves its value as a string. The function formats the parameter's value based on its data type. If the memory pointer is provided, the string is stored at the specified memory location. Otherwise, the function allocates memory to hold the string, which must be freed by the caller.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to retrieve.
memoryOptional pointer to a char* variable where the string will be stored. If NULL, memory is allocated internally to hold the string.
Returns
On success, returns a pointer to the null-terminated string containing the parameter value. On failure, returns NULL and sets an appropriate error message.
Return values
NULLIndicates that an error occurred (e.g., invalid dataset, parameter not found, type mismatch, memory allocation failure, or unknown data type).
Non-NULLPointer to the null-terminated string containing the parameter value.
Note
The caller is responsible for freeing the allocated memory if the memory parameter is NULL.
See also
SDDS_GetParameterAsDouble, SDDS_GetParameterAsLong64, SDDS_GetParameterAsLongDouble

Definition at line 2838 of file SDDS_extract.c.

2838 {
2839 int32_t index, type;
2840 char buffer[SDDS_MAXLINE], *parValue;
2841 void *value;
2842
2843 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterAsString"))
2844 return (NULL);
2845 if (!parameter_name) {
2846 SDDS_SetError("Unable to get parameter value--parameter name pointer is NULL (SDDS_GetParameterAsString)");
2847 return (NULL);
2848 }
2849 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
2850 SDDS_SetError("Unable to get parameter value--parameter name is unrecognized (SDDS_GetParameterAsString)");
2851 return (NULL);
2852 }
2853 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2854 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterAsString)");
2855 return (NULL);
2856 }
2857 value = SDDS_dataset->parameter[index];
2858 switch (type) {
2859 case SDDS_LONGDOUBLE:
2860 if (LDBL_DIG == 18) {
2861 sprintf(buffer, "%.18Le", *(long double *)value);
2862 } else {
2863 sprintf(buffer, "%.15Le", *(long double *)value);
2864 }
2865 break;
2866 case SDDS_DOUBLE:
2867 sprintf(buffer, "%.15le", *(double *)value);
2868 break;
2869 case SDDS_FLOAT:
2870 sprintf(buffer, "%.8e", *(float *)value);
2871 break;
2872 case SDDS_LONG64:
2873 sprintf(buffer, "%" PRId64, *(int64_t *)value);
2874 break;
2875 case SDDS_ULONG64:
2876 sprintf(buffer, "%" PRIu64, *(uint64_t *)value);
2877 break;
2878 case SDDS_LONG:
2879 sprintf(buffer, "%" PRId32, *(int32_t *)value);
2880 break;
2881 case SDDS_ULONG:
2882 sprintf(buffer, "%" PRIu32, *(uint32_t *)value);
2883 break;
2884 case SDDS_SHORT:
2885 sprintf(buffer, "%hd", *(short *)value);
2886 break;
2887 case SDDS_USHORT:
2888 sprintf(buffer, "%hu", *(unsigned short *)value);
2889 break;
2890 case SDDS_CHARACTER:
2891 sprintf(buffer, "%c", *(char *)value);
2892 break;
2893 case SDDS_STRING:
2894 sprintf(buffer, "%s", *(char **)value);
2895 break;
2896 default:
2897 SDDS_SetError("Unknown data type of parameter (SDDS_GetParameterAsString)");
2898 return (NULL);
2899 }
2900 if (!(parValue = malloc(sizeof(char) * (strlen(buffer) + 1)))) {
2901 SDDS_SetError("Unable to get parameter value--memory allocation failure (SDDS_GetParameterAsString)");
2902 return (NULL);
2903 }
2904 strcpy(parValue, buffer);
2905 if (memory)
2906 *memory = parValue;
2907 return parValue;
2908}

◆ SDDS_GetParameterByIndex()

epicsShareFuncSDDS void * SDDS_GetParameterByIndex ( SDDS_DATASET * SDDS_dataset,
int32_t index,
void * memory )
extern

Retrieves the value of a specified parameter by its index from the current data table of a data set.

This function accesses the value of a specific parameter (identified by its index) within the current data table of a dataset. The retrieved value is either copied into user-provided memory or returned as a direct pointer to the internal data.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
indexZero-based index of the parameter to retrieve. Must be within the range [0, n_parameters-1].
memoryPointer to user-allocated memory where the retrieved parameter value will be stored. If NULL, the function allocates memory.
Returns
  • Pointer to the retrieved parameter value stored in memory (if provided) or to newly allocated memory.
  • NULL if an error occurs (e.g., invalid dataset, parameter index out of range, undefined data type, memory allocation failure, string copy failure). In this case, an error message is recorded internally.
Warning
  • If memory is NULL, the function allocates memory that the caller must free to prevent memory leaks.
  • For parameters containing string data (SDDS_STRING), the function copies the string into memory. A typical usage would involve passing a pointer to a char* variable. c char *string; SDDS_GetParameterByIndex(&SDDS_dataset, index, &string); // or string = *(char**)SDDS_GetParameterByIndex(&SDDS_dataset, index, NULL);
Note
  • The size of the allocated memory corresponds to the parameter's data type, which can be obtained using SDDS_GetParameterType.
  • If the dataset's memory mode for the parameter is set to DONT_TRACK_PARAMETER_MEMORY_AFTER_ACCESS, the internal data for the parameter may be freed after access.
See also

Definition at line 2554 of file SDDS_extract.c.

2554 {
2555 int32_t type, size;
2556 void *data;
2557 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameter"))
2558 return (NULL);
2559 if (index < 0 || index >= SDDS_dataset->layout.n_parameters) {
2560 SDDS_SetError("Unable to get parameter value--parameter index is invalid (SDDS_GetParameterByIndex)");
2561 return (NULL);
2562 }
2563 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
2564 SDDS_SetError("Unable to get parameter value--parameter data type is invalid (SDDS_GetParameterByIndex)");
2565 return (NULL);
2566 }
2567 if (!SDDS_dataset->parameter || !SDDS_dataset->parameter[index]) {
2568 SDDS_SetError("Unable to get parameter value--parameter data array is NULL (SDDS_GetParameterByIndex)");
2569 return (NULL);
2570 }
2571 size = SDDS_type_size[type - 1];
2572 if (memory)
2573 data = memory;
2574 else if (!(data = SDDS_Malloc(size))) {
2575 SDDS_SetError("Unable to get parameter value--parameter data size is invalid (SDDS_GetParameterByIndex)");
2576 return (NULL);
2577 }
2578 if (type != SDDS_STRING)
2579 memcpy(data, SDDS_dataset->parameter[index], size);
2580 else if (!SDDS_CopyString((char **)data, *(char **)SDDS_dataset->parameter[index]))
2581 return (NULL);
2582 return (data);
2583}

◆ SDDS_GetParameterDefinition()

epicsShareFuncSDDS PARAMETER_DEFINITION * SDDS_GetParameterDefinition ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the definition of a specified parameter from the SDDS dataset.

This function searches for a parameter by its name within the provided SDDS dataset. If found, it creates a copy of the parameter's definition and returns a pointer to it. The returned pointer should be freed by the caller using SDDS_FreeParameterDefinition to avoid memory leaks.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the parameter to retrieve.
Returns
On success, returns a pointer to a newly allocated PARAMETER_DEFINITION structure containing the parameter's information. On failure (e.g., if the parameter is not found or a copy fails), returns NULL and records an error message.
Note
The caller is responsible for freeing the returned PARAMETER_DEFINITION pointer using SDDS_FreeParameterDefinition.
See also
SDDS_CopyParameterDefinition
SDDS_FreeParameterDefinition
SDDS_SetError

Definition at line 1075 of file SDDS_utils.c.

1075 {
1076 int32_t i;
1077 PARAMETER_DEFINITION *pardef;
1078 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterDefinition"))
1079 return (NULL);
1080 if (!name) {
1081 SDDS_SetError("Unable to get parameter definition--name is NULL (SDDS_GetParameterDefinition)");
1082 return (NULL);
1083 }
1084 if ((i = SDDS_GetParameterIndex(SDDS_dataset, name)) < 0)
1085 return NULL;
1086 if (!SDDS_CopyParameterDefinition(&pardef, SDDS_dataset->layout.parameter_definition + i)) {
1087 SDDS_SetError("Unable to get parameter definition--copy failure (SDDS_GetParameterDefinition)");
1088 return (NULL);
1089 }
1090 return (pardef);
1091}
PARAMETER_DEFINITION * SDDS_CopyParameterDefinition(PARAMETER_DEFINITION **target, PARAMETER_DEFINITION *source)
Creates a copy of a parameter definition.

◆ SDDS_GetParameterIndex()

epicsShareFuncSDDS int32_t SDDS_GetParameterIndex ( SDDS_DATASET * SDDS_dataset,
char * name )
extern

Retrieves the index of a named parameter in the SDDS dataset.

This function searches for a parameter by its name within the provided SDDS dataset and returns its index. The index can then be used with other routines for faster access to the parameter's data or metadata.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]nameA null-terminated string specifying the name of the parameter whose index is desired.
Returns
On success, returns a non-negative integer representing the index of the parameter. On failure (e.g., if the parameter is not found), returns -1 and records an error message.
See also
SDDS_GetParameterDefinition
SDDS_SetError

Definition at line 1338 of file SDDS_utils.c.

1338 {
1339 int32_t i;
1340 SORTED_INDEX key;
1341
1342 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterIndex"))
1343 return (-1);
1344 if (!name) {
1345 SDDS_SetError("Unable to get parameter index--name is NULL (SDDS_GetParameterIndex)");
1346 return (-1);
1347 }
1348 key.name = name;
1349 if ((i = binaryIndexSearch((void **)SDDS_dataset->layout.parameter_index, SDDS_dataset->layout.n_parameters, &key, SDDS_CompareIndexedNames, 0)) < 0)
1350 return -1;
1351 return SDDS_dataset->layout.parameter_index[i]->index;
1352}

◆ SDDS_GetParameterInformation()

epicsShareFuncSDDS int32_t SDDS_GetParameterInformation ( SDDS_DATASET * SDDS_dataset,
char * field_name,
void * memory,
int32_t mode,
... )
extern

Retrieves information about a specified parameter in the SDDS dataset.

This function is the preferred alternative to SDDS_GetParameterDefinition. It allows you to obtain information about a specific field of a parameter, either by the parameter's name or index.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]field_nameA null-terminated string specifying the name of the field for which information is requested.
[out]memoryPointer to a variable where the retrieved information will be stored. The variable should be of type data_type*, where data_type corresponds to the type of the requested information. For STRING information, use char*. If memory is NULL, the function will verify the existence and type of the information, returning the data type without storing any data.
[in]modeSpecifies how to identify the parameter. Valid values are:
  • SDDS_GET_BY_NAME: Identify the parameter by its name. Requires an additional argument of type char* (parameter name).
  • SDDS_GET_BY_INDEX: Identify the parameter by its index. Requires an additional argument of type int32_t (parameter index).
Returns
On success, returns the SDDS data type of the requested information. On failure, returns zero and records an error message.
Note
This function uses variable arguments to accept either the parameter name or index based on the mode parameter.
See also
SDDS_GetParameterDefinition

Definition at line 117 of file SDDS_info.c.

117 {
118 int32_t field_index, type, parameter_index;
119 PARAMETER_DEFINITION *parameterdef;
120 char *parameter_name;
121 va_list argptr;
122 int32_t retval;
123
124 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterInformation"))
125 return (0);
126
127 if (!field_name) {
128 SDDS_SetError("NULL field name passed. (SDDS_GetParameterInformation)");
129 return (0);
130 }
131
132 va_start(argptr, mode);
133 retval = 1;
134 if (mode & SDDS_GET_BY_INDEX) {
135 if ((parameter_index = va_arg(argptr, int32_t)) < 0 || parameter_index >= SDDS_dataset->layout.n_parameters) {
136 SDDS_SetError("Invalid parameter index passed. (SDDS_GetParameterInformation)");
137 retval = 0;
138 }
139 } else {
140 if (!(parameter_name = va_arg(argptr, char *))) {
141 SDDS_SetError("NULL parameter name passed. (SDDS_GetParameterInformation)");
142 retval = 0;
143 }
144 if ((parameter_index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
145 SDDS_SetError("Unknown parameter name given (SDDS_GetParameterInformation)");
146 retval = 0;
147 }
148 }
149 parameterdef = SDDS_dataset->layout.parameter_definition + parameter_index;
150 va_end(argptr);
151 if (!retval)
152 return (0);
153
154 for (field_index = 0; field_index < SDDS_PARAMETER_FIELDS; field_index++)
155 if (strcmp(field_name, SDDS_ParameterFieldInformation[field_index].name) == 0)
156 break;
157 if (field_index == SDDS_PARAMETER_FIELDS) {
158 SDDS_SetError("Unknown field name given (SDDS_GetParameterInformation)");
159 return (0);
160 }
161 type = SDDS_ParameterFieldInformation[field_index].type;
162 if (!memory)
163 return (type);
164 if (type == SDDS_STRING) {
165 if (!SDDS_CopyString((char **)memory, *((char **)((char *)parameterdef + SDDS_ParameterFieldInformation[field_index].offset)))) {
166 SDDS_SetError("Unable to copy field data (SDDS_GetParameterInformation)");
167 return (0);
168 }
169 } else
170 memcpy(memory, (char *)parameterdef + SDDS_ParameterFieldInformation[field_index].offset, SDDS_type_size[type - 1]);
171 return (type);
172}

◆ SDDS_GetParameterNames()

epicsShareFuncSDDS char ** SDDS_GetParameterNames ( SDDS_DATASET * SDDS_dataset,
int32_t * number )
extern

Retrieves the names of all parameters in the SDDS dataset.

This function allocates and returns an array of NULL-terminated strings containing the names of the parameters in the provided SDDS_dataset.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[out]numberPointer to an int32_t variable where the number of retrieved parameter names will be stored.
Returns
  • Returns a pointer to an array of NULL-terminated strings containing the parameter names on success.
  • Returns NULL on failure (e.g., if the dataset is invalid or memory allocation fails) and records an error message.
Note
The caller is responsible for freeing the memory allocated for the returned array and its strings using SDDS_FreeStringArray or similar functions.
See also
SDDS_CheckDataset
SDDS_Malloc
SDDS_CopyString
SDDS_SetError

Definition at line 2501 of file SDDS_utils.c.

2501 {
2502 int32_t i;
2503 char **name;
2504 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterNames"))
2505 return (NULL);
2506 *number = SDDS_dataset->layout.n_parameters;
2507 if (!(name = (char **)SDDS_Malloc(sizeof(*name) * SDDS_dataset->layout.n_parameters))) {
2508 SDDS_SetError("Unable to get parameter names--allocation failure (SDDS_GetParameterNames)");
2509 return (NULL);
2510 }
2511 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++) {
2512 if (!SDDS_CopyString(name + i, SDDS_dataset->layout.parameter_definition[i].name)) {
2513 free(name);
2514 return (NULL);
2515 }
2516 }
2517 return (name);
2518}

◆ SDDS_GetParameters()

epicsShareFuncSDDS int32_t SDDS_GetParameters ( SDDS_DATASET * SDDS_dataset,
... )
extern

Retrieves multiple parameter values from the current data table of a data set.

This variadic function allows the retrieval of multiple parameter values in a single call. Each parameter's name and corresponding memory location are provided as pairs of arguments.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
...Variable arguments consisting of pairs of:
  • char *parameter_name: NULL-terminated string specifying the name of the parameter.
  • void *memory: Pointer to memory where the parameter's value will be stored. If NULL, the function will fail for that parameter.
  • The argument list should be terminated when parameter_name is NULL.
Returns
  • 1 on successful retrieval of all specified parameters.
  • 0 if any parameter retrieval fails. An error message is recorded for the first failure encountered.
Warning
  • The function expects an even number of arguments (pairs of parameter names and memory pointers). An odd number may result in undefined behavior.
  • Ensure that the memory pointers provided are of appropriate types and have sufficient space to hold the parameter values.
Note
  • To terminate the argument list, pass a NULL as the parameter name. c SDDS_GetParameters(&SDDS_dataset, "param1", &value1, "param2", &value2, NULL);
See also

Definition at line 2420 of file SDDS_extract.c.

2420 {
2421 va_list argptr;
2422 char *name;
2423 void *data;
2424 int32_t retval;
2425 char s[SDDS_MAXLINE];
2426
2427 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameters"))
2428 return 0;
2429 va_start(argptr, SDDS_dataset);
2430 retval = 1;
2431 do {
2432 if (!(name = va_arg(argptr, char *)))
2433 break;
2434 if (!(data = va_arg(argptr, void *)))
2435 retval = 0;
2436 if (!SDDS_GetParameter(SDDS_dataset, name, data)) {
2437 sprintf(s, "Unable to get value of parameter %s (SDDS_GetParameters)", name);
2438 SDDS_SetError(s);
2439 }
2440 } while (retval);
2441 va_end(argptr);
2442 return retval;
2443}
void * SDDS_GetParameter(SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
Retrieves the value of a specified parameter from the current data table of a data set.

◆ SDDS_GetParameterType()

epicsShareFuncSDDS int32_t SDDS_GetParameterType ( SDDS_DATASET * SDDS_dataset,
int32_t index )
extern

Retrieves the data type of a parameter in the SDDS dataset by its index.

This function returns the SDDS data type of the specified parameter within the dataset. The data type corresponds to one of the predefined SDDS type constants, such as SDDS_LONGDOUBLE, SDDS_DOUBLE, SDDS_FLOAT, etc.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
[in]indexThe zero-based index of the parameter whose data type is to be retrieved. The index should be obtained from SDDS_DefineParameter or SDDS_GetParameterIndex.
Returns
On success, returns the SDDS data type of the parameter as an int32_t. On failure (e.g., if the index is out of range or the dataset is invalid), returns 0 and records an error message.
Note
The function does not perform type validation beyond checking the index range. It assumes that the dataset's parameter definitions are correctly initialized.
See also
SDDS_GetParameterIndex
SDDS_SetError

Definition at line 2251 of file SDDS_utils.c.

2251 {
2252 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetParameterType"))
2253 return (0);
2254 if (index < 0 || index >= SDDS_dataset->layout.n_parameters) {
2255 SDDS_SetError("Unable to get parameter type--parameter index is out of range (SDDS_GetParameterType)");
2256 return (0);
2257 }
2258 return (SDDS_dataset->layout.parameter_definition[index].type);
2259}

◆ SDDS_GetRow()

epicsShareFuncSDDS void * SDDS_GetRow ( SDDS_DATASET * SDDS_dataset,
int64_t srow_index,
void * memory )
extern

Retrieves the data of a specific selected row as an array, considering only columns marked as "of interest".

This function extracts data from a specific selected row (identified by its selected row index among rows marked as "of interest") within the current data table of a dataset. It processes only those columns that are flagged as "of interest" and returns the row's data as a newly allocated array or stores it in user-provided memory.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
srow_indexZero-based index representing the position of the selected row among all rows marked as "of interest".
memoryPointer to user-allocated memory where the retrieved row data will be stored. If NULL, the function allocates memory.
Returns
  • Pointer to the retrieved row data array stored in memory (if provided) or to newly allocated memory.
  • NULL if an error occurs (e.g., invalid dataset, row index out of range, inconsistent row types, memory allocation failure). In this case, an error message is recorded internally.
Warning
  • If memory is NULL, the function allocates memory that the caller must free to prevent memory leaks.
  • All selected columns must have the same data type. If there is an inconsistency, the function will fail.
  • For columns containing string data (SDDS_STRING), each element in the returned array is a dynamically allocated string that must be freed individually, followed by the array itself.
Note
  • The number of elements in the returned array corresponds to the number of columns marked as "of interest", which can be obtained using SDDS_CountColumnsOfInterest.
  • If the dataset's memory mode for the columns is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the columns may be freed after access.
See also

Definition at line 2201 of file SDDS_extract.c.

2201 {
2202 void *data;
2203 int32_t size, type;
2204 int64_t i, row_index;
2205
2206 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetRow"))
2207 return (NULL);
2208 if ((row_index = SDDS_GetSelectedRowIndex(SDDS_dataset, srow_index)) < 0) {
2209 SDDS_SetError("Unable to get row--row index out of range (SDDS_GetRow)");
2210 return (NULL);
2211 }
2212 if (SDDS_dataset->n_of_interest <= 0) {
2213 SDDS_SetError("Unable to get row--no columns selected (SDDS_GetRow)");
2214 return (NULL);
2215 }
2216 if ((type = SDDS_GetRowType(SDDS_dataset)) <= 0) {
2217 SDDS_SetError("Unable to get row--inconsistent data type in selected columns (SDDS_GetRow)");
2218 return (NULL);
2219 }
2220 size = SDDS_type_size[type - 1];
2221 if (memory)
2222 data = memory;
2223 else if (!(data = SDDS_Malloc(size * SDDS_dataset->n_of_interest))) {
2224 SDDS_SetError("Unable to get row--memory allocation failure (SDDS_GetRow)");
2225 return (NULL);
2226 }
2227 if (type != SDDS_STRING)
2228 for (i = 0; i < SDDS_dataset->n_of_interest; i++)
2229 memcpy((char *)data + i * size, (char *)SDDS_dataset->data[SDDS_dataset->column_order[i]] + row_index * size, size);
2230 else
2231 for (i = 0; i < SDDS_dataset->n_of_interest; i++)
2232 if (!SDDS_CopyString((char **)data + i, ((char **)SDDS_dataset->data[SDDS_dataset->column_order[i]])[row_index]))
2233 return (NULL);
2234 return (data);
2235}
int64_t SDDS_GetSelectedRowIndex(SDDS_DATASET *SDDS_dataset, int64_t srow_index)
Retrieves the actual row index corresponding to a selected row position within the current data table...

◆ SDDS_GetRowFlag()

epicsShareFuncSDDS int32_t SDDS_GetRowFlag ( SDDS_DATASET * SDDS_dataset,
int64_t row )
extern

Retrieves the acceptance flag of a specific row in the current data table.

This function fetches the acceptance flag for a given row. The flag indicates whether the row is "of interest" (non-zero) or rejected (zero).

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
rowIndex of the row whose flag is to be retrieved. Must be within the range [0, n_rows-1].
Returns
  • Non-negative integer representing the flag value of the specified row.
  • -1 if the dataset is invalid or the row index is out of bounds.
See also
SDDS_SetRowFlags, SDDS_GetRowFlags

Definition at line 71 of file SDDS_extract.c.

71 {
72 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetRowFlag"))
73 return -1;
74 if (row < 0 || row >= SDDS_dataset->n_rows)
75 return -1;
76 return SDDS_dataset->row_flag[row];
77}

◆ SDDS_GetRowFlags()

epicsShareFuncSDDS int32_t SDDS_GetRowFlags ( SDDS_DATASET * SDDS_dataset,
int32_t * flag,
int64_t rows )
extern

Retrieves the acceptance flags for all rows in the current data table.

This function copies the acceptance flags of each row into a provided array. Each flag indicates whether the corresponding row is "of interest" (non-zero) or rejected (zero).

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
flagPointer to an integer array where the row flags will be stored. The array must have at least rows elements.
rowsNumber of rows to retrieve flags for. Typically, this should match the total number of rows in the data table.
Returns
  • 1 on successful retrieval of all row flags.
  • 0 on failure, with an error message recorded (e.g., if row count mismatches).
Note
Ensure that the flag array is adequately allocated to hold the flags for all specified rows.
See also
SDDS_SetRowFlags, SDDS_GetRowFlag

Definition at line 97 of file SDDS_extract.c.

97 {
98 int64_t i;
99 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetRowFlags"))
100 return 0;
101 if (rows != SDDS_dataset->n_rows) {
102 SDDS_SetError("Row count mismatch (SDDS_GetRowFlags)");
103 return 0;
104 }
105 for (i = 0; i < rows; i++)
106 flag[i] = SDDS_dataset->row_flag[i];
107 return 1;
108}

◆ SDDS_GetRowLimit()

epicsShareFuncSDDS int64_t SDDS_GetRowLimit ( )
extern

Retrieves the current row limit for the SDDS dataset.

Returns
The current row limit.

Definition at line 1247 of file SDDS_input.c.

1247 {
1248 return SDDS_RowLimit;
1249}
static int64_t SDDS_RowLimit
Global variable to set a limit on the number of rows read.

◆ SDDS_GetToken()

epicsShareFuncSDDS int32_t SDDS_GetToken ( char * s,
char * buffer,
int32_t buflen )
extern

Extracts the next token from a string, handling quoted substrings and escape characters.

This function parses the input string s to extract the next token, considering quoted substrings and escape characters. If the token is enclosed in double quotes ("), the function ensures that embedded quotes are handled correctly. After extracting the token, the original string s is updated to remove the extracted portion.

Parameters
[in,out]sPointer to the string from which to extract the token. This string will be modified to remove the extracted token.
[out]bufferPointer to a character array where the extracted token will be stored.
[in]buflenThe maximum number of characters to copy into buffer, including the null terminator.
Returns
On success, returns the length of the extracted token as an int32_t. If no token is found or an error occurs (e.g., buffer overflow), returns -1.
Note
The function assumes that the input string s is null-terminated. The caller must ensure that buffer has sufficient space to hold the extracted token.
See also
SDDS_GetToken2

Definition at line 1740 of file SDDS_utils.c.

1740 {
1741 char *ptr0, *ptr1, *escptr, *temp;
1742
1743 /* save the pointer to the head of the string */
1744 ptr0 = s;
1745
1746 /* skip leading white-space */
1747 while (isspace(*s))
1748 s++;
1749 if (*s == 0)
1750 return (-1);
1751 ptr1 = s;
1752
1753 if (*s == '"') {
1754 /* if quoted string, skip to next quotation mark */
1755 ptr1 = s + 1; /* beginning of actual token */
1756 do {
1757 s++;
1758 escptr = NULL;
1759 if (*s == '\\' && *(s + 1) == '\\') {
1760 /* skip and remember literal \ (indicated by \\ in the string) */
1761 escptr = s + 1;
1762 s += 2;
1763 }
1764 } while (*s && (*s != '"' || (*(s - 1) == '\\' && (s - 1) != escptr)));
1765 /* replace trailing quotation mark with a space */
1766 if (*s == '"')
1767 *s = ' ';
1768 } else {
1769 /* skip to first white-space following token */
1770 do {
1771 s++;
1772 /* imbedded quotation marks are handled here */
1773 if (*s == '"' && *(s - 1) != '\\') {
1774 while (*++s && !(*s == '"' && *(s - 1) != '\\'))
1775 ;
1776 }
1777 } while (*s && !isspace(*s));
1778 }
1779
1780 if ((int32_t)(s - ptr1) >= buflen)
1781 return (-1);
1782 strncpy(buffer, ptr1, s - ptr1);
1783 buffer[s - ptr1] = 0;
1784
1785 /* update the original string to delete the token */
1786 temp = malloc(sizeof(char) * (strlen(s) + 1));
1787 strcpy(temp, s);
1788 strcpy(ptr0, temp);
1789 free(temp);
1790
1791 /* return the string length */
1792 return ((int32_t)(s - ptr1));
1793}

◆ SDDS_GetToken2()

epicsShareFuncSDDS int32_t SDDS_GetToken2 ( char * s,
char ** st,
int32_t * strlength,
char * buffer,
int32_t buflen )
extern

Extracts the next token from a string, handling quoted substrings and escape characters, with updated string pointers.

This function parses the input string s to extract the next token, considering quoted substrings and escape characters. If the token is enclosed in double quotes ("), the function ensures that embedded quotes are handled correctly. After extracting the token, the original string s is updated by adjusting the string pointer st and the remaining string length strlength.

Parameters
[in,out]sPointer to the string from which to extract the token. This string will be modified to remove the extracted token.
[in,out]stPointer to the current position in the string s. This will be updated to point to the next character after the extracted token.
[in,out]strlengthPointer to an int32_t variable representing the remaining length of the string s. This will be decremented by the length of the extracted token.
[out]bufferPointer to a character array where the extracted token will be stored.
[in]buflenThe maximum number of characters to copy into buffer, including the null terminator.
Returns
On success, returns the length of the extracted token as an int32_t. If no token is found or an error occurs (e.g., buffer overflow), returns -1.
Note
The caller is responsible for ensuring that buffer has sufficient space to hold the extracted token. Additionally, st and strlength should accurately reflect the current parsing state of the string.
See also
SDDS_GetToken

Definition at line 1812 of file SDDS_utils.c.

1812 {
1813 char *ptr0, *ptr1, *escptr;
1814
1815 /* save the pointer to the head of the string */
1816 ptr0 = s;
1817
1818 /* skip leading white-space */
1819 while (isspace(*s))
1820 s++;
1821 if (*s == 0)
1822 return (-1);
1823 ptr1 = s;
1824
1825 if (*s == '"') {
1826 /* if quoted string, skip to next quotation mark */
1827 ptr1 = s + 1; /* beginning of actual token */
1828 do {
1829 s++;
1830 escptr = NULL;
1831 if (*s == '\\' && *(s + 1) == '\\') {
1832 /* skip and remember literal \ (indicated by \\ in the string) */
1833 escptr = s + 1;
1834 s += 2;
1835 }
1836 } while (*s && (*s != '"' || (*(s - 1) == '\\' && (s - 1) != escptr)));
1837 /* replace trailing quotation mark with a space */
1838 if (*s == '"')
1839 *s = ' ';
1840 } else {
1841 /* skip to first white-space following token */
1842 do {
1843 s++;
1844 /* imbedded quotation marks are handled here */
1845 if (*s == '"' && *(s - 1) != '\\') {
1846 while (*++s && !(*s == '"' && *(s - 1) != '\\'))
1847 ;
1848 }
1849 } while (*s && !isspace(*s));
1850 }
1851
1852 if ((int32_t)(s - ptr1) >= buflen)
1853 return (-1);
1854 strncpy(buffer, ptr1, s - ptr1);
1855 buffer[s - ptr1] = 0;
1856
1857 /* update the original string to delete the token */
1858 *st += s - ptr0;
1859 *strlength -= s - ptr0;
1860
1861 /* return the string length including whitespace */
1862 return ((int32_t)(s - ptr1));
1863}

◆ SDDS_GetTypeName()

epicsShareFuncSDDS char * SDDS_GetTypeName ( int32_t type)
extern

Retrieves the name of a specified SDDS data type as a string.

This function returns a dynamically allocated string containing the name of the specified SDDS data type. The name corresponds to the textual representation of the data type, such as "double", "float", "int32", etc.

Parameters
[in]typeThe SDDS data type for which the name is requested. Must be one of the predefined constants:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
Returns
On success, returns a pointer to a newly allocated string containing the name of the data type. On failure (e.g., if the type is invalid or memory allocation fails), returns NULL.
Note
The caller is responsible for freeing the memory allocated for the returned string using SDDS_Free.
See also
SDDS_GetTypeSize
SDDS_SetError

Definition at line 2337 of file SDDS_utils.c.

2337 {
2338 char *name;
2339 if (!SDDS_VALID_TYPE(type))
2340 return NULL;
2341 if (!SDDS_CopyString(&name, SDDS_type_name[type - 1]))
2342 return NULL;
2343 return name;
2344}
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
Definition SDDS_data.c:43

◆ SDDS_GetTypeSize()

epicsShareFuncSDDS int32_t SDDS_GetTypeSize ( int32_t type)
extern

Retrieves the size in bytes of a specified SDDS data type.

This function returns the size, in bytes, of the specified SDDS data type. The size corresponds to the memory footprint of the data type when stored in the dataset.

Parameters
[in]typeThe SDDS data type for which the size is requested. Must be one of the predefined constants:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
Returns
On success, returns a positive integer representing the size of the data type in bytes. On failure (e.g., if the type is invalid), returns -1 and records an error message.
Note
The function relies on the SDDS_type_size array, which should be properly initialized with the sizes of all supported SDDS data types.
See also
SDDS_GetTypeName
SDDS_SetError

Definition at line 2308 of file SDDS_utils.c.

2308 {
2309 if (!SDDS_VALID_TYPE(type))
2310 return (-1);
2311 return (SDDS_type_size[type - 1]);
2312}

◆ SDDS_GetValue()

epicsShareFuncSDDS void * SDDS_GetValue ( SDDS_DATASET * SDDS_dataset,
char * column_name,
int64_t srow_index,
void * memory )
extern

Retrieves the value from a specified column and selected row, optionally storing it in provided memory.

This function accesses the value of a specific column and selected row within the current data table of a dataset. It returns the value as a pointer to the data, allowing for both direct access and optional storage in user-provided memory.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which the value is to be retrieved.
srow_indexZero-based index representing the position of the selected row among all rows marked as "of interest".
memoryPointer to user-allocated memory where the retrieved value will be stored. If NULL, the function allocates memory internally, and the caller is responsible for freeing it.
Returns
  • Pointer to the retrieved value stored in memory (if provided) or in newly allocated memory.
  • NULL if an error occurs (e.g., invalid dataset, unrecognized column name, undefined data type, memory allocation failure, invalid row index). In this case, an error message is recorded internally.
Warning
  • If memory is NULL, the function allocates memory that the caller must free to prevent memory leaks.
  • The function does not perform type casting. Ensure that the provided memory is of the appropriate type matching the column's data type.
  • Modifying the data through the returned pointer affects the internal state of the dataset. Use with caution to avoid unintended side effects.
Note
  • For columns containing string data (SDDS_STRING), the function copies the string into memory. A typical usage would involve passing a pointer to a char* variable. c char *string; SDDS_GetValue(&SDDS_dataset, "name", index, &string); // or string = *(char**)SDDS_GetValue(&SDDS_dataset, "name", index, NULL);
  • The number of rows marked as "of interest" can be obtained using SDDS_CountRowsOfInterest.
See also

Definition at line 1754 of file SDDS_extract.c.

1754 {
1755 int32_t type, size, column_index;
1756 int64_t row_index;
1757 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetValue"))
1758 return (NULL);
1759 if ((column_index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
1760 SDDS_SetError("Unable to get value--column name is not recognized (SDDS_GetValue)");
1761 return (NULL);
1762 }
1763 if (!(type = SDDS_GetColumnType(SDDS_dataset, column_index))) {
1764 SDDS_SetError("Unable to get value--data type undefined (SDDS_GetValue)");
1765 return (NULL);
1766 }
1767 size = SDDS_type_size[type - 1];
1768 if ((row_index = SDDS_GetSelectedRowIndex(SDDS_dataset, srow_index)) < 0) {
1769 SDDS_SetError("Unable to get value--row index out of range (SDDS_GetValue)");
1770 return (NULL);
1771 }
1772 if (type != SDDS_STRING) {
1773 if (!memory && !(memory = SDDS_Malloc(size))) {
1774 SDDS_SetError("Unable to get value--memory allocation failure (SDDS_GetValue)");
1775 return (NULL);
1776 }
1777 memcpy(memory, (char *)SDDS_dataset->data[column_index] + row_index * size, size);
1778 return (memory);
1779 }
1780 /* for character string data, a typical call would be
1781 * char *string;
1782 * SDDS_GetValue(&SDDS_dataset, "name", index, &string) or
1783 * string = *(char**)SDDS_GetValue(&SDDS_dataset, "name", index, NULL)
1784 */
1785 if (!memory && !(memory = SDDS_Malloc(size))) {
1786 SDDS_SetError("Unable to get value--memory allocation failure (SDDS_GetValue)");
1787 return (NULL);
1788 }
1789 if (SDDS_CopyString(memory, ((char **)SDDS_dataset->data[column_index])[row_index]))
1790 return (memory);
1791 return (NULL);
1792}

◆ SDDS_GetValueAsDouble()

epicsShareFuncSDDS double SDDS_GetValueAsDouble ( SDDS_DATASET * SDDS_dataset,
char * column_name,
int64_t srow_index )
extern

Retrieves the value from a specified column and selected row, casting it to a double.

This function accesses the value of a specific column and selected row within the current data table of a dataset. It casts the retrieved value to a double before returning it.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_nameNULL-terminated string specifying the name of the column from which the value is to be retrieved.
srow_indexZero-based index representing the position of the selected row among all rows marked as "of interest".
Returns
  • Double representing the casted value from the specified column and row.
  • 0 if an error occurs (e.g., invalid dataset, unrecognized column name, undefined data type, invalid row index, non-numeric column type). In this case, an error message is recorded internally.
Warning
  • This function only supports numerical data types. Attempting to retrieve and cast data from non-numeric columns (excluding SDDS_CHARACTER) will result in an error.
Note
  • The function internally allocates temporary memory to store the value before casting. This memory is freed before the function returns.
See also

Definition at line 1821 of file SDDS_extract.c.

1821 {
1822 int32_t type, size, column_index;
1823 int64_t row_index;
1824 void *memory;
1825 double value = 0;
1826 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetValueAsDouble"))
1827 return (0);
1828 if ((column_index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
1829 SDDS_SetError("Unable to get value--column name is not recognized (SDDS_GetValueAsDouble)");
1830 return (0);
1831 }
1832 if (!(type = SDDS_GetColumnType(SDDS_dataset, column_index))) {
1833 SDDS_SetError("Unable to get value--data type undefined (SDDS_GetValueAsDouble)");
1834 return (0);
1835 }
1836 size = SDDS_type_size[type - 1];
1837 if ((row_index = SDDS_GetSelectedRowIndex(SDDS_dataset, srow_index)) < 0) {
1838 SDDS_SetError("Unable to get value--row index out of range (SDDS_GetValueAsDouble)");
1839 return (0);
1840 }
1841 if ((type != SDDS_STRING) && (type != SDDS_CHARACTER)) {
1842 memory = SDDS_Malloc(size);
1843 memcpy(memory, (char *)SDDS_dataset->data[column_index] + row_index * size, size);
1844 switch (type) {
1845 case SDDS_SHORT:
1846 value = *(short *)memory;
1847 break;
1848 case SDDS_USHORT:
1849 value = *(unsigned short *)memory;
1850 break;
1851 case SDDS_LONG:
1852 value = *(int32_t *)memory;
1853 break;
1854 case SDDS_ULONG:
1855 value = *(uint32_t *)memory;
1856 break;
1857 case SDDS_LONG64:
1858 value = *(int64_t *)memory;
1859 break;
1860 case SDDS_ULONG64:
1861 value = *(uint64_t *)memory;
1862 break;
1863 case SDDS_FLOAT:
1864 value = *(float *)memory;
1865 break;
1866 case SDDS_DOUBLE:
1867 value = *(double *)memory;
1868 break;
1869 case SDDS_LONGDOUBLE:
1870 value = *(long double *)memory;
1871 break;
1872 }
1873 free(memory);
1874 return (value);
1875 }
1876 SDDS_SetError("Unable to get non-numeric value as double (SDDS_GetValueAsDouble)");
1877 return (0);
1878}

◆ SDDS_GetValueByAbsIndex()

epicsShareFuncSDDS void * SDDS_GetValueByAbsIndex ( SDDS_DATASET * SDDS_dataset,
int32_t column_index,
int64_t row_index,
void * memory )
extern

Retrieves the value from a specified column and absolute row index, optionally storing it in provided memory.

This function accesses the value of a specific column (identified by its index) and an absolute row index within the current data table of a dataset. The retrieved value is either copied into user-provided memory or returned as a direct pointer to the internal data.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_indexZero-based index of the column from which the value is to be retrieved. Must be within the range [0, n_columns-1].
row_indexAbsolute zero-based row index within the dataset's data table. Must be within the range [0, n_rows-1].
memoryPointer to user-allocated memory where the retrieved value will be stored. If NULL, the function returns a pointer to the internal data.
Returns
  • Pointer to the retrieved value stored in memory (if provided) or to the internal data.
  • NULL if an error occurs (e.g., invalid dataset, column index out of range, row index out of range, undefined data type, memory allocation failure, non-numeric column type). In this case, an error message is recorded internally.
Warning
  • If memory is NULL, the function returns a direct pointer to the internal data. Modifying the data through this pointer affects the dataset's internal state.
  • If memory is provided, ensure that it points to sufficient memory to hold the data type of the column.
  • This function does not perform type casting. Ensure that the memory type matches the column's data type.
Note
  • Unlike SDDS_GetValueByIndex, this function uses an absolute row index rather than a selected row index among rows marked as "of interest".
  • For columns containing string data (SDDS_STRING), the function copies the string into memory. A typical usage would involve passing a pointer to a char* variable. c char *string; SDDS_GetValueByAbsIndex(&SDDS_dataset, column_index, row_index, &string); // or string = *(char**)SDDS_GetValueByAbsIndex(&SDDS_dataset, column_index, row_index, NULL);
See also

Definition at line 2090 of file SDDS_extract.c.

2090 {
2091 int32_t type, size;
2092 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetValueByAbsIndex"))
2093 return (NULL);
2094 if (column_index < 0 || column_index >= SDDS_dataset->layout.n_columns) {
2095 SDDS_SetError("Unable to get value--column index out of range (SDDS_GetValueByAbsIndex)");
2096 return (NULL);
2097 }
2098 if (row_index < 0 || row_index >= SDDS_dataset->n_rows) {
2099 SDDS_SetError("Unable to get value--index out of range (SDDS_GetValueByAbsIndex)");
2100 return (NULL);
2101 }
2102 if (!(type = SDDS_GetColumnType(SDDS_dataset, column_index))) {
2103 SDDS_SetError("Unable to get value--data type undefined (SDDS_GetValueByAbsIndex)");
2104 return (NULL);
2105 }
2106 size = SDDS_type_size[type - 1];
2107 if (type != SDDS_STRING) {
2108 if (memory) {
2109 memcpy(memory, (char *)SDDS_dataset->data[column_index] + row_index * size, size);
2110 return (memory);
2111 }
2112 return ((char *)SDDS_dataset->data[column_index] + row_index * size);
2113 }
2114 /* for character string data, a typical call would be
2115 * char *string;
2116 * SDDS_GetValueByAbsIndex(&SDDS_dataset, cindex, index, &string) or
2117 * string = *(char**)SDDS_GetValue(&SDDS_dataset, cindex, index, NULL)
2118 */
2119 if (!memory)
2120 memory = SDDS_Malloc(size);
2121 if (SDDS_CopyString(memory, ((char **)SDDS_dataset->data[column_index])[row_index]))
2122 return (memory);
2123 return (NULL);
2124}

◆ SDDS_GetValueByIndex()

epicsShareFuncSDDS void * SDDS_GetValueByIndex ( SDDS_DATASET * SDDS_dataset,
int32_t column_index,
int64_t srow_index,
void * memory )
extern

Retrieves the value from a specified column and selected row, optionally storing it in provided memory.

This function accesses the value of a specific column (identified by its index) and a selected row (identified by its selected row index among rows marked as "of interest") within the current data table of a dataset. The retrieved value is either copied into user-provided memory or returned as a direct pointer to the internal data.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_indexZero-based index of the column from which the value is to be retrieved. Must be within the range [0, n_columns-1].
srow_indexZero-based index representing the position of the selected row among all rows marked as "of interest".
memoryPointer to user-allocated memory where the retrieved value will be stored. If NULL, the function returns a pointer to the internal data.
Returns
  • Pointer to the retrieved value stored in memory (if provided) or to the internal data.
  • NULL if an error occurs (e.g., invalid dataset, column index out of range, undefined data type, row index out of range, memory allocation failure, non-numeric column type). In this case, an error message is recorded internally.
Warning
  • If memory is NULL, the function returns a direct pointer to the internal data. Modifying the data through this pointer affects the dataset's internal state.
  • If memory is provided, ensure that it points to sufficient memory to hold the data type of the column.
  • This function does not perform type casting. Ensure that the memory type matches the column's data type.
Note
  • For columns containing string data (SDDS_STRING), the function copies the string into memory. A typical usage would involve passing a pointer to a char* variable. c char *string; SDDS_GetValueByIndex(&SDDS_dataset, column_index, index, &string); // or string = *(char**)SDDS_GetValueByIndex(&SDDS_dataset, column_index, index, NULL);
  • The number of rows marked as "of interest" can be obtained using SDDS_CountRowsOfInterest.
See also

Definition at line 2014 of file SDDS_extract.c.

2014 {
2015 int32_t type, size;
2016 int64_t row_index;
2017 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetValueByIndex"))
2018 return (NULL);
2019 if (column_index < 0 || column_index >= SDDS_dataset->layout.n_columns) {
2020 SDDS_SetError("Unable to get value--column index out of range (SDDS_GetValueByIndex)");
2021 return (NULL);
2022 }
2023 if (!(type = SDDS_GetColumnType(SDDS_dataset, column_index))) {
2024 SDDS_SetError("Unable to get value--data type undefined (SDDS_GetValueByIndex)");
2025 return (NULL);
2026 }
2027 size = SDDS_type_size[type - 1];
2028 if ((row_index = SDDS_GetSelectedRowIndex(SDDS_dataset, srow_index)) < 0) {
2029 SDDS_SetError("Unable to get value--row index out of range (SDDS_GetValueByIndex)");
2030 return (NULL);
2031 }
2032 if (type != SDDS_STRING) {
2033 if (memory) {
2034 memcpy(memory, (char *)SDDS_dataset->data[column_index] + row_index * size, size);
2035 return (memory);
2036 }
2037 return ((char *)SDDS_dataset->data[column_index] + row_index * size);
2038 }
2039 /* for character string data, a typical call would be
2040 * char *string;
2041 * SDDS_GetValueByIndex(&SDDS_dataset, cindex, index, &string) or
2042 * string = *(char**)SDDS_GetValue(&SDDS_dataset, cindex, index, NULL)
2043 */
2044 if (!memory)
2045 memory = SDDS_Malloc(size);
2046 if (SDDS_CopyString(memory, ((char **)SDDS_dataset->data[column_index])[row_index]))
2047 return (memory);
2048 return (NULL);
2049}

◆ SDDS_GetValueByIndexAsDouble()

epicsShareFuncSDDS double SDDS_GetValueByIndexAsDouble ( SDDS_DATASET * SDDS_dataset,
int32_t column_index,
int64_t srow_index )
extern

Retrieves the value from a specified column and selected row, casting it to a double.

This function accesses the value of a specific column (identified by its index) and a selected row (identified by its selected row index among rows marked as "of interest") within the current data table of a dataset. It casts the retrieved value to a double before returning it.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_indexZero-based index of the column from which the value is to be retrieved. Must be within the range [0, n_columns-1].
srow_indexZero-based index representing the position of the selected row among all rows marked as "of interest".
Returns
  • Double representing the casted value from the specified column and row.
  • 0.0 if an error occurs (e.g., invalid dataset, column index out of range, undefined data type, row index out of range, non-numeric column type). In this case, an error message is recorded internally.
Warning
  • This function only supports numerical data types. Attempting to retrieve and cast data from non-numeric columns (excluding SDDS_CHARACTER) will result in an error.
  • The returned value 0.0 may be ambiguous if it is a valid data value. Always check for errors using SDDS_CheckError or similar mechanisms.
Note
  • The number of rows marked as "of interest" can be obtained using SDDS_CountRowsOfInterest.
  • If the dataset's memory mode for the column is set to DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS, the internal data for the column may be freed after access.
See also

Definition at line 1914 of file SDDS_extract.c.

1914 {
1915 int32_t type, size;
1916 int64_t row_index;
1917 void *memory;
1918 double value = 0;
1919 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetValueByIndexAsDouble"))
1920 return (0);
1921 if (column_index < 0 || column_index >= SDDS_dataset->layout.n_columns) {
1922 SDDS_SetError("Unable to get value--column index out of range (SDDS_GetValueByIndexAsDouble)");
1923 return (0);
1924 }
1925 if (!(type = SDDS_GetColumnType(SDDS_dataset, column_index))) {
1926 SDDS_SetError("Unable to get value--data type undefined (SDDS_GetValueByIndexAsDouble)");
1927 return (0);
1928 }
1929 size = SDDS_type_size[type - 1];
1930 if ((row_index = SDDS_GetSelectedRowIndex(SDDS_dataset, srow_index)) < 0) {
1931 SDDS_SetError("Unable to get value--row index out of range (SDDS_GetValueByIndexAsDouble)");
1932 return (0);
1933 }
1934 if ((type != SDDS_STRING) && (type != SDDS_CHARACTER)) {
1935 memory = SDDS_Malloc(size);
1936 memcpy(memory, (char *)SDDS_dataset->data[column_index] + row_index * size, size);
1937 switch (type) {
1938 case SDDS_SHORT:
1939 value = *(short *)memory;
1940 break;
1941 case SDDS_USHORT:
1942 value = *(unsigned short *)memory;
1943 break;
1944 case SDDS_LONG:
1945 value = *(int32_t *)memory;
1946 break;
1947 case SDDS_ULONG:
1948 value = *(uint32_t *)memory;
1949 break;
1950 case SDDS_LONG64:
1951 value = *(int64_t *)memory;
1952 break;
1953 case SDDS_ULONG64:
1954 value = *(uint64_t *)memory;
1955 break;
1956 case SDDS_FLOAT:
1957 value = *(float *)memory;
1958 break;
1959 case SDDS_DOUBLE:
1960 value = *(double *)memory;
1961 break;
1962 case SDDS_LONGDOUBLE:
1963 value = *(long double *)memory;
1964 break;
1965 }
1966 free(memory);
1967 return (value);
1968 }
1969 SDDS_SetError("Unable to get non-numeric value as double (SDDS_GetValueByIndexAsDouble)");
1970 return (0);
1971}

◆ SDDS_GotoPage()

epicsShareFuncSDDS int32_t SDDS_GotoPage ( SDDS_DATASET * SDDS_dataset,
int32_t page_number )
extern

Sets the current page of the SDDS dataset to the specified page number.

This function is used to navigate to a specific page of the SDDS dataset. It is only supported for non-zip files and does not work for pipe input.

Parameters
SDDS_datasetThe SDDS dataset to operate on.
page_numberThe page number to navigate to.
Returns
Returns 1 on success, 0 on failure.

Definition at line 1261 of file SDDS_input.c.

1261 {
1262 int64_t offset;
1263
1264 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GotoPage"))
1265 return (0);
1266 if (SDDS_dataset->layout.disconnected) {
1267 SDDS_SetError("Can't go to page--file is disconnected (SDDS_GotoPage)");
1268 return 0;
1269 }
1270 if (SDDS_dataset->layout.popenUsed || !SDDS_dataset->layout.filename) {
1271 SDDS_SetError("Can't go to page of pipe is used (SDDS_GotoPage)");
1272 return 0;
1273 }
1274#if defined(zLib)
1275 if (SDDS_dataset->layout.gzipFile) {
1276 SDDS_SetError("Can not go to page of a gzip file (SDDS_GotoPage)");
1277 return (0);
1278 } else {
1279#endif
1280 if (SDDS_dataset->layout.lzmaFile) {
1281 SDDS_SetError("Can not go to page of an .lzma or .xz file (SDDS_GotoPage)");
1282 return (0);
1283 } else {
1284 if (!SDDS_dataset->layout.fp) {
1285 SDDS_SetError("Unable to go to page--NULL file pointer (SDDS_GotoPage)");
1286 return (0);
1287 }
1288 }
1289#if defined(zLib)
1290 }
1291#endif
1292 if (!SDDS_dataset->layout.filename) {
1293 SDDS_SetError("Can't go to page--NULL filename pointer (SDDS_GotoPage)");
1294 return 0;
1295 }
1296 if (SDDS_dataset->mode != SDDS_READMODE) {
1297 SDDS_SetError("Can't go to page--file mode has to be reading mode (SDDS_GotoPage)");
1298 return 0;
1299 }
1300 if (SDDS_dataset->fBuffer.bufferSize) {
1301 SDDS_SetError("Can't go to page--file buffering is turned on (SDDS_GotoPage)");
1302 return 0;
1303 }
1304 if (page_number < 1) {
1305 SDDS_SetError("The page_number can not be less than 1 (SDDS_GotoPage)");
1306 return (0);
1307 }
1308 if (page_number > SDDS_dataset->pages_read) {
1309 offset = SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] - ftell(SDDS_dataset->layout.fp);
1310 fseek(SDDS_dataset->layout.fp, offset, 1);
1311 SDDS_dataset->page_number = SDDS_dataset->pages_read;
1312 while (SDDS_dataset->pages_read < page_number) {
1313 if (SDDS_ReadPageSparse(SDDS_dataset, 0, 10000, 0, 0) <= 0) {
1314 SDDS_SetError("The page_number is greater than the total pages (SDDS_GotoPage)");
1315 return (0);
1316 }
1317 }
1318 } else {
1319 offset = SDDS_dataset->pagecount_offset[page_number - 1] - ftell(SDDS_dataset->layout.fp);
1320 fseek(SDDS_dataset->layout.fp, offset, 1); /*seek to the position from current offset */
1321 SDDS_dataset->page_number = page_number - 1;
1322 }
1323 return 1;
1324}
int32_t SDDS_ReadPageSparse(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)

◆ SDDS_HasWhitespace()

epicsShareFuncSDDS int32_t SDDS_HasWhitespace ( char * string)
extern

Checks if a string contains any whitespace characters.

This function scans through the provided string to determine if it contains any whitespace characters (e.g., space, tab, newline).

Parameters
[in]stringPointer to the null-terminated string to be checked.
Returns
Returns 1 if the string contains at least one whitespace character. Returns 0 if no whitespace characters are found or if the input string is NULL.
See also
isspace

Definition at line 1422 of file SDDS_utils.c.

1422 {
1423 if (!string)
1424 return (0);
1425 while (*string) {
1426 if (isspace(*string))
1427 return (1);
1428 string++;
1429 }
1430 return (0);
1431}

◆ SDDS_IdentifyType()

epicsShareFuncSDDS int32_t SDDS_IdentifyType ( char * typeName)
extern

Identifies the SDDS data type based on its string name.

This function searches for the SDDS data type that matches the provided string typeName. It returns the corresponding SDDS data type constant if a match is found.

Parameters
[in]typeNameA null-terminated string representing the name of the SDDS data type to identify.
Returns
On success, returns the SDDS data type constant (int32_t) corresponding to typeName. On failure (e.g., if typeName does not match any known data type), returns 0.
Note
The function performs a case-sensitive comparison between typeName and the names of supported SDDS data types.
See also
SDDS_GetTypeName
SDDS_SetError

Definition at line 2360 of file SDDS_utils.c.

2360 {
2361 int32_t i;
2362 for (i = 0; i < SDDS_NUM_TYPES; i++)
2363 if (strcmp(typeName, SDDS_type_name[i]) == 0)
2364 return i + 1;
2365 return 0;
2366}

◆ SDDS_InitializeAppend()

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

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_LockFile(FILE *fp, const char *filename, const char *caller)
Attempts to lock a specified file.

◆ SDDS_InitializeAppendToPage()

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

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

◆ SDDS_InitializeCopy()

epicsShareFuncSDDS int32_t SDDS_InitializeCopy ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
char * filename,
char * filemode )
extern

Initializes an SDDS_DATASET structure in preparation for copying a data table from another SDDS_DATASET structure.

Parameters
SDDS_targetAddress of SDDS_DATASET structure into which to copy data.
SDDS_sourceAddress of SDDS_DATASET structure from which to copy data.
filenameA NULL-terminated character string giving a filename to be associated with the new SDDS_DATASET. Typically, the name of a file to which the copied data will be written after modification. Ignored if NULL.
filemodeA NULL-terminated character string giving the fopen file mode to be used to open the file named by filename. Ignored if filename is NULL.
Returns
1 on success. On failure, returns 0 and records an error message.

Definition at line 40 of file SDDS_copy.c.

40 {
41 char s[SDDS_MAXLINE];
42#if defined(zLib)
43 char *extension;
44#endif
45
46 if (sizeof(gzFile) != sizeof(void *)) {
47 SDDS_SetError("gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
48 return (0);
49 }
50 if (!SDDS_CheckDataset(SDDS_source, "SDDS_InitializeCopy"))
51 return (0);
52 if (!SDDS_CheckDataset(SDDS_target, "SDDS_InitializeCopy"))
53 return (0);
54 if (!SDDS_ZeroMemory((void *)SDDS_target, sizeof(SDDS_DATASET))) {
55 SDDS_SetError("Unable to copy layout--can't zero SDDS_DATASET structure (SDDS_InitializeCopy)");
56 return (0);
57 }
58 if (strcmp(filemode, "r") == 0) {
59 filemode = FOPEN_READ_MODE;
60 SDDS_target->mode = SDDS_READMODE;
61 } else if (strcmp(filemode, "w") == 0) {
62 filemode = FOPEN_WRITE_MODE;
63 SDDS_target->mode = SDDS_WRITEMODE;
64 }
65 SDDS_target->pagecount_offset = NULL;
66 if (!(strcmp(filemode, "r") == 0 || strcmp(filemode, "w") == 0 || strcmp(filemode, "rb") == 0 || strcmp(filemode, "wb") == 0 || strcmp(filemode, "m") == 0)) {
67 SDDS_SetError("Programming error--invalid file mode (SDDS_InitializeCopy)");
68 return (0);
69 }
70
71 SDDS_target->layout.popenUsed = 0;
72 SDDS_target->layout.gzipFile = 0;
73 SDDS_target->layout.lzmaFile = 0;
74 if (filename) {
75 if (SDDS_FileIsLocked(filename)) {
76 sprintf(s, "unable to open file %s for copy--file is locked (SDDS_InitializeCopy)", filename);
78 return 0;
79 }
80
81 if ((extension = strrchr(filename, '.')) && ((strcmp(extension, ".xz") == 0) || (strcmp(extension, ".lzma") == 0))) {
82 SDDS_target->layout.lzmaFile = 1;
83 if (!filemode) {
84 sprintf(s, "Unable to open file %s (SDDS_InitializeCopy)", filename);
86 return (0);
87 }
88 if (!(SDDS_target->layout.lzmafp = lzma_open(filename, filemode))) {
89 sprintf(s, "Unable to open file %s for writing (SDDS_InitializeCopy)", filename);
91 return 0;
92 }
93 SDDS_target->layout.fp = SDDS_target->layout.lzmafp->fp;
94 } else {
95 if (!filemode || !(SDDS_target->layout.fp = fopen(filename, filemode))) {
96 sprintf(s, "Unable to open file %s (SDDS_InitializeCopy)", filename);
98 return (0);
99 }
100 }
101 if ((strcmp(filemode, "w") == 0 || strcmp(filemode, "wb") == 0) && !SDDS_LockFile(SDDS_target->layout.fp, filename, "SDDS_InitializeCopy"))
102 return 0;
103 if (!SDDS_CopyString(&SDDS_target->layout.filename, filename)) {
104 SDDS_SetError("Memory allocation failure (SDDS_InitializeCopy)");
105 return (0);
106 }
107#if defined(zLib)
108 if ((extension = strrchr(filename, '.')) && strcmp(extension, ".gz") == 0) {
109 SDDS_target->layout.gzipFile = 1;
110 if ((SDDS_target->layout.gzfp = gzdopen(fileno(SDDS_target->layout.fp), filemode)) == NULL) {
111 sprintf(s, "Unable to open compressed file %s for writing (SDDS_InitializeCopy)", filename);
112 SDDS_SetError(s);
113 return 0;
114 }
115 }
116#endif
117 } else {
118 SDDS_target->layout.filename = NULL;
119 SDDS_target->layout.fp = NULL;
120 SDDS_target->mode = SDDS_MEMMODE;
121 if (filemode) {
122 if (strcmp(filemode, "w") == 0 || strcmp(filemode, "wb") == 0)
123 SDDS_target->layout.fp = stdout;
124 else if (strcmp(filemode, "r") == 0 || strcmp(filemode, "rb") == 0)
125 SDDS_target->layout.fp = stdin;
126
127 /* else if (strcmp(filemode, "m")!=0) {
128 SDDS_SetError("Unknown filemode (SDDS_InitializeCopy)");
129 return(0);
130 } */
131#if defined(_WIN32)
132 if (strcmp(filemode, "m") != 0) {
133 if (_setmode(_fileno(SDDS_target->layout.fp), _O_BINARY) == -1) {
134 sprintf(s, "unable to set stdout or stdin to binary mode");
135 SDDS_SetError(s);
136 return 0;
137 }
138 }
139#endif
140 }
141 }
142 SDDS_target->page_number = SDDS_target->page_started = 0;
143 if (!SDDS_CopyLayout(SDDS_target, SDDS_source))
144 return (0);
145 return (1);
146}
int32_t SDDS_CopyLayout(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:222

◆ SDDS_InitializeHeaderlessInput()

epicsShareFuncSDDS int32_t SDDS_InitializeHeaderlessInput ( SDDS_DATASET * SDDS_dataset,
char * filename )
extern

Initializes the SDDS dataset for headerless input.

This function initializes the SDDS dataset structure for reading data from a file without a header.

Parameters
SDDS_datasetA pointer to the SDDS_DATASET structure to be initialized.
filenameThe name of the file to read data from.
Returns
Returns 1 on success, 0 on failure.

Definition at line 175 of file SDDS_input.c.

175 {
176 /* char *ptr, *datafile; */
177
178 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_InitializeInput"))
179 return (0);
180 if (!SDDS_ZeroMemory((void *)SDDS_dataset, sizeof(SDDS_DATASET))) {
181 SDDS_SetError("Unable to initialize input--can't zero SDDS_DATASET structure (SDDS_InitializeInput)");
182 return (0);
183 }
184 SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = 0;
185 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
186 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_MODE))) {
187 SDDS_SetError("Unable to open file (SDDS_InitializeInput)");
188 return (0);
189 }
190 if (!SDDS_CopyString(&SDDS_dataset->layout.filename, filename)) {
191 SDDS_SetError("Memory allocation failure (SDDS_InitializeInput)");
192 return (0);
193 }
194 SDDS_dataset->mode = SDDS_READMODE; /*reading */
195 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
196 SDDS_dataset->pages_read = 0;
197 SDDS_dataset->pagecount_offset = malloc(sizeof(*SDDS_dataset->pagecount_offset));
198 SDDS_dataset->pagecount_offset[0] = ftell(SDDS_dataset->layout.fp);
199 fseek(SDDS_dataset->layout.fp, 0, 2); /*point to the end of the file */
200 SDDS_dataset->endOfFile_offset = ftell(SDDS_dataset->layout.fp);
201 fseek(SDDS_dataset->layout.fp, SDDS_dataset->pagecount_offset[0], 0);
202 /*point to the beginning of the first page */
203 return (1);
204}

◆ SDDS_InitializeInput()

epicsShareFuncSDDS int32_t SDDS_InitializeInput ( SDDS_DATASET * SDDS_dataset,
char * filename )
extern

Initializes a SDDS_DATASET structure for use in reading data from a SDDS file. This involves opening the file and reading the SDDS header.

Parameters
SDDS_datasetAddress of the SDDS_DATASET structure for the data set.
filenameA NULL-terminated character string giving the name of the file to set up for input.
Returns
1 on success. On failure, returns 0 and records an error message.

Definition at line 49 of file SDDS_input.c.

49 {
50 /* char *ptr, *datafile, *headerfile; */
51 char s[SDDS_MAXLINE];
52#if defined(zLib)
53 char *extension;
54#endif
55 if (sizeof(gzFile) != sizeof(void *)) {
56 SDDS_SetError("gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
57 return (0);
58 }
59 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_InitializeInput"))
60 return (0);
61
62 if (!SDDS_ZeroMemory((void *)SDDS_dataset, sizeof(SDDS_DATASET))) {
63 sprintf(s, "Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeInput)", filename);
65 return (0);
66 }
67 SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = SDDS_dataset->layout.popenUsed = 0;
68 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
69 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
70 if (!filename)
71 SDDS_dataset->layout.filename = NULL;
72 else if (!SDDS_CopyString(&SDDS_dataset->layout.filename, filename)) {
73 sprintf(s, "Memory allocation failure initializing file \"%s\" (SDDS_InitializeInput)", filename);
75 return (0);
76 }
77 if (!filename) {
78#if defined(_WIN32)
79 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
80 sprintf(s, "unable to set stdin to binary mode");
82 return 0;
83 }
84#endif
85 SDDS_dataset->layout.fp = stdin;
86 } else {
87#if defined(zLib)
88 if (!(extension = strrchr(filename, '.')) || strcmp(extension, ".gz") != 0) {
89#endif
90 if ((extension = strrchr(filename, '.')) && ((strcmp(extension, ".lzma") == 0) || (strcmp(extension, ".xz") == 0))) {
91 SDDS_dataset->layout.lzmaFile = 1;
92 if (!(SDDS_dataset->layout.lzmafp = UnpackLZMAOpen(filename))) {
93 sprintf(s, "Unable to open file \"%s\" for reading (SDDS_InitializeInput)", filename);
95 return (0);
96 }
97 SDDS_dataset->layout.fp = SDDS_dataset->layout.lzmafp->fp;
98 } else {
99 if (!(SDDS_dataset->layout.fp = UnpackFopen(filename, UNPACK_REQUIRE_SDDS | UNPACK_USE_PIPE, &SDDS_dataset->layout.popenUsed, NULL))) {
100 sprintf(s, "Unable to open file \"%s\" for reading (SDDS_InitializeInput)", filename);
101 SDDS_SetError(s);
102 return (0);
103 }
104 }
105#if defined(zLib)
106 } else {
107 SDDS_dataset->layout.gzipFile = 1;
108 if (!(SDDS_dataset->layout.gzfp = UnpackGZipOpen(filename))) {
109 sprintf(s, "Unable to open file \"%s\" for reading (SDDS_InitializeInput)", filename);
110 SDDS_SetError(s);
111 return (0);
112 }
113 }
114#endif
115 }
116 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
117 SDDS_dataset->file_had_data = 0;
118 SDDS_DeferSavingLayout(SDDS_dataset, 1);
119#if defined(zLib)
120 if (SDDS_dataset->layout.gzipFile) {
121 if (!SDDS_GZipReadLayout(SDDS_dataset, SDDS_dataset->layout.gzfp))
122 return (0);
123 } else {
124#endif
125 if (SDDS_dataset->layout.lzmaFile) {
126 if (!SDDS_LZMAReadLayout(SDDS_dataset, SDDS_dataset->layout.lzmafp))
127 return (0);
128 } else {
129 if (!SDDS_ReadLayout(SDDS_dataset, SDDS_dataset->layout.fp))
130 return (0);
131 }
132#if defined(zLib)
133 }
134#endif
135 SDDS_dataset->layout.layout_written = 0;
136 SDDS_DeferSavingLayout(SDDS_dataset, 0);
137 if (!SDDS_SaveLayout(SDDS_dataset))
138 return 0;
139 if (SDDS_dataset->layout.n_columns &&
140 ((!(SDDS_dataset->column_flag = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
141 !(SDDS_dataset->column_order = (int32_t *)SDDS_Malloc(sizeof(int32_t) * SDDS_dataset->layout.n_columns))) ||
142 (!SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
143 !SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)0, (int32_t)1)))) {
144 SDDS_SetError("Unable to initialize input--memory allocation failure (SDDS_InitializeInput)");
145 return (0);
146 }
147 SDDS_dataset->mode = SDDS_READMODE; /*reading */
148 SDDS_dataset->pagecount_offset = NULL;
149 if (!SDDS_dataset->layout.gzipFile && !SDDS_dataset->layout.lzmaFile && !SDDS_dataset->layout.popenUsed && SDDS_dataset->layout.filename) {
150 /* Data is not:
151 1. from a gzip file
152 2. from a file that is being internally decompressed by a command executed with popen()
153 3. from a pipe set up externally (e.g., -pipe=in on commandline)
154 */
155 SDDS_dataset->pages_read = 0;
156 SDDS_dataset->pagecount_offset = malloc(sizeof(*SDDS_dataset->pagecount_offset));
157 SDDS_dataset->pagecount_offset[0] = ftell(SDDS_dataset->layout.fp);
158 fseek(SDDS_dataset->layout.fp, 0, 2); /*point to the end of the file */
159 SDDS_dataset->endOfFile_offset = ftell(SDDS_dataset->layout.fp);
160 fseek(SDDS_dataset->layout.fp, SDDS_dataset->pagecount_offset[0], 0);
161 /*point to the beginning of the first page */
162 }
163 return (1);
164}
int32_t SDDS_LZMAReadLayout(SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
Definition SDDS_input.c:680
FILE * UnpackFopen(char *filename, unsigned long mode, short *popenUsed, char **tmpFileUsed)
Opens a file, potentially unpacking it based on its extension and mode.
Definition unpack.c:93

◆ SDDS_InitializeInputFromSearchPath()

epicsShareFuncSDDS int32_t SDDS_InitializeInputFromSearchPath ( SDDS_DATASET * SDDSin,
char * file )
extern

Initializes the SDDS_DATASET structure for input from the search path.

The search path is defined by calling setSearchPath. This function attempts to find the file in the search path and initializes the SDDS dataset for input.

Parameters
SDDSinThe SDDS_DATASET structure to be initialized.
fileThe name of the file to be opened for input.
Returns
1 on success, 0 on failure.

Definition at line 1786 of file SDDS_input.c.

1786 {
1787 char *filename;
1788 int32_t value;
1789 if (!(filename = findFileInSearchPath(file))) {
1790 char *s;
1791 if (!(s = SDDS_Malloc(sizeof(*s) * (strlen(file) + 100))))
1792 SDDS_SetError("file does not exist in search path (InitializeInputFromSearchPath)");
1793 else {
1794 sprintf(s, "file %s does not exist in search path (InitializeInputFromSearchPath)", file);
1795 SDDS_SetError(s);
1796 free(s);
1797 }
1798 return 0;
1799 }
1800 value = SDDS_InitializeInput(SDDSin, filename);
1801 free(filename);
1802 return value;
1803}
int32_t SDDS_InitializeInput(SDDS_DATASET *SDDS_dataset, char *filename)
Definition SDDS_input.c:49
char * findFileInSearchPath(char *filename)
Finds a file within the configured search path.
Definition searchPath.c:49

◆ SDDS_InitializeOutput()

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

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

epicsShareFuncSDDS void SDDS_InterpretEscapes ( char * s)
extern

Interprets and converts escape sequences in a string.

This function processes a string containing escape sequences and converts them into their corresponding character representations. Supported escape sequences include:

  • Standard ANSI escape codes: \n, \t, \b, \r, \f, \v, \\, \', \", \a, \?
  • Octal values: \ddd
  • SDDS-specific escape codes: \!, \)

The function modifies the input string s in place, replacing escape sequences with their actual character values.

Parameters
[in,out]sPointer to the null-terminated string to be processed. The string will be modified in place.
Note
  • Ensure that the input string s has sufficient buffer space to accommodate the modified characters, especially when dealing with octal escape sequences that may reduce the overall string length.
Warning
  • The function does not perform bounds checking. Ensure that the input string is properly null-terminated to prevent undefined behavior.
  • Unrecognized escape sequences (other than the ones specified) will result in the backslash being retained in the string.
See also
SDDS_EscapeNewlines, SDDS_UnescapeNewlines

Definition at line 5082 of file SDDS_utils.c.

5087{
5088 char *ptr;
5089 int32_t count;
5090
5091 ptr = s;
5092 while (*s) {
5093 if (*s != '\\')
5094 *ptr++ = *s++;
5095 else {
5096 s++;
5097 if (!*s) {
5098 *ptr++ = '\\';
5099 *ptr++ = 0;
5100 return;
5101 }
5102 switch (*s) {
5103 case 'n':
5104 *ptr++ = '\n';
5105 s++;
5106 break;
5107 case 't':
5108 *ptr++ = '\t';
5109 s++;
5110 break;
5111 case 'b':
5112 *ptr++ = '\b';
5113 s++;
5114 break;
5115 case 'r':
5116 *ptr++ = '\r';
5117 s++;
5118 break;
5119 case 'f':
5120 *ptr++ = '\f';
5121 s++;
5122 break;
5123 case 'v':
5124 *ptr++ = '\v';
5125 s++;
5126 break;
5127 case '\\':
5128 *ptr++ = '\\';
5129 s++;
5130 break;
5131 case '\'':
5132 *ptr++ = '\'';
5133 s++;
5134 break;
5135 case '"':
5136 *ptr++ = '\"';
5137 s++;
5138 break;
5139 case 'a':
5140 *ptr++ = '\a';
5141 s++;
5142 break;
5143 case '?':
5144 *ptr++ = '\?';
5145 s++;
5146 break;
5147 case '!':
5148 *ptr++ = '!';
5149 s++;
5150 break;
5151 default:
5152 if (*s >= '0' && *s <= '9') {
5153 *ptr = 0;
5154 count = 0;
5155 while (++count <= 3 && *s >= '0' && *s <= '9')
5156 *ptr = 8 * (*ptr) + *s++ - '0';
5157 ptr++;
5158 } else {
5159 *ptr++ = '\\';
5160 }
5161 break;
5162 }
5163 }
5164 }
5165 *ptr = 0;
5166}

◆ SDDS_IsActive()

epicsShareFuncSDDS int32_t SDDS_IsActive ( SDDS_DATASET * SDDS_dataset)
extern

Checks whether an SDDS dataset is currently active.

This function determines the active status of the provided SDDS dataset by verifying if its file pointer is non-NULL.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure to be checked.
Returns
  • 1 if the dataset is active (i.e., the file pointer is non-NULL).
  • 0 if the dataset is inactive (i.e., the file pointer is NULL).
  • -1 if a NULL pointer is passed, indicating an error.
Note
An inactive dataset does not have an associated open file, and certain operations may not be applicable.
See also
SDDS_ForceInactive, SDDS_SetError

Definition at line 3250 of file SDDS_utils.c.

3250 {
3251 if (!SDDS_dataset) {
3252 SDDS_SetError("NULL SDDS_DATASET passed (SDDS_IsActive)");
3253 return (-1);
3254 }
3255 if (!SDDS_dataset->layout.fp)
3256 return (0);
3257 return (1);
3258}

◆ SDDS_IsBigEndianMachine()

epicsShareFuncSDDS int32_t SDDS_IsBigEndianMachine ( )
extern

Determines whether the current machine uses big-endian byte ordering.

This function checks the byte order of the machine on which the program is running. It returns 1 if the machine is big-endian and 0 if it is little-endian.

Returns
  • 1 if the machine is big-endian.
  • 0 if the machine is little-endian.
Note
  • Endianness detection is based on inspecting the byte order of an integer value.
Warning
  • This function assumes that int32_t is 4 bytes in size. If compiled on a system where int32_t differs in size, the behavior may be incorrect.
See also
SDDS_SetDataMode

Definition at line 5283 of file SDDS_utils.c.

5283 {
5284 int32_t x = 1;
5285 if (*((char *)&x))
5286 return 0;
5287 return 1;
5288}

◆ SDDS_IsQuoted()

epicsShareFuncSDDS int32_t SDDS_IsQuoted ( char * string,
char * position,
char quotation_mark )
extern

Checks if a position in a string is within a quoted section.

Determines whether the specified position within a string falls inside a quoted section delimited by the given quotation mark.

Parameters
stringThe string to examine.
positionThe position within the string to check.
quotation_markThe character used as the quotation mark.
Returns
Returns 1 if the position is within a quoted section, 0 otherwise.

Definition at line 217 of file SDDS_input.c.

217 {
218 int32_t in_quoted_section;
219 char *string0;
220
221 if (*position == quotation_mark)
222 return (1);
223
224 in_quoted_section = 0;
225 string0 = string;
226 while (*string) {
227 if (*string == quotation_mark && (string == string0 || *(string - 1) != '\\'))
228 in_quoted_section = !in_quoted_section;
229 else if (string == position)
230 return (in_quoted_section);
231 string++;
232 }
233 return (0);
234}

◆ SDDS_IsValidName()

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

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

epicsShareFuncSDDS int32_t SDDS_ItemInsideWindow ( void * data,
int64_t index,
int32_t type,
double lower_limit,
double upper_limit )
extern

Checks whether a data item is within a specified numeric window.

This function determines if the data item at the given index within the data array falls within the range defined by lower_limit and upper_limit. It handles various numeric data types and ensures that the value is neither NaN nor infinity.

Parameters
dataPointer to the data array.
indexThe index of the item within the data array to be checked.
typeThe data type of the item. Supported types include:
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_LONG64
  • SDDS_ULONG64
  • SDDS_FLOAT
  • SDDS_DOUBLE
  • SDDS_LONGDOUBLE
lower_limitThe lower bound of the numeric window.
upper_limitThe upper bound of the numeric window.
Returns
Returns 1 if the item is within the window and valid, otherwise returns 0.
Return values
1Indicates that the item is within the specified numeric window and is a valid number.
0Indicates that the item is outside the specified window, is NaN, is infinite, or the data type is non-numeric.
Note
  • The function sets an error message if the data type is non-numeric.
  • It is essential to ensure that the data array is properly initialized and contains valid data before calling this function.
See also
SDDS_FilterRowsOfInterest, SDDS_GetParameterAsDouble

Definition at line 4077 of file SDDS_extract.c.

4077 {
4078 short short_val;
4079 unsigned short ushort_val;
4080 int32_t long_val;
4081 uint32_t ulong_val;
4082 int64_t long64_val;
4083 uint64_t ulong64_val;
4084 long double ldouble_val;
4085 double double_val;
4086 float float_val;
4087
4088 switch (type) {
4089 case SDDS_SHORT:
4090 if ((short_val = *((short *)data + index)) < lower_limit || short_val > upper_limit)
4091 return (0);
4092 return (1);
4093 case SDDS_USHORT:
4094 if ((ushort_val = *((unsigned short *)data + index)) < lower_limit || ushort_val > upper_limit)
4095 return (0);
4096 return (1);
4097 case SDDS_LONG:
4098 if ((long_val = *((int32_t *)data + index)) < lower_limit || long_val > upper_limit)
4099 return (0);
4100 return (1);
4101 case SDDS_ULONG:
4102 if ((ulong_val = *((uint32_t *)data + index)) < lower_limit || ulong_val > upper_limit)
4103 return (0);
4104 return (1);
4105 case SDDS_LONG64:
4106 if ((long64_val = *((int64_t *)data + index)) < lower_limit || long64_val > upper_limit)
4107 return (0);
4108 return (1);
4109 case SDDS_ULONG64:
4110 if ((ulong64_val = *((uint64_t *)data + index)) < lower_limit || ulong64_val > upper_limit)
4111 return (0);
4112 return (1);
4113 case SDDS_FLOAT:
4114 if ((float_val = *((float *)data + index)) < lower_limit || float_val > upper_limit)
4115 return (0);
4116 if (isnan(float_val) || isinf(float_val))
4117 return 0;
4118 return (1);
4119 case SDDS_DOUBLE:
4120 if ((double_val = *((double *)data + index)) < lower_limit || double_val > upper_limit)
4121 return 0;
4122 if (isnan(double_val) || isinf(double_val))
4123 return 0;
4124 return (1);
4125 case SDDS_LONGDOUBLE:
4126 if ((ldouble_val = *((long double *)data + index)) < lower_limit || ldouble_val > upper_limit)
4127 return 0;
4128 if (isnan(ldouble_val) || isinf(ldouble_val))
4129 return 0;
4130 return (1);
4131 default:
4132 SDDS_SetError("Unable to complete window check--item type is non-numeric (SDDS_ItemInsideWindow)");
4133 return (0);
4134 }
4135}

◆ SDDS_LengthenTable()

epicsShareFuncSDDS int32_t SDDS_LengthenTable ( SDDS_DATASET * SDDS_dataset,
int64_t n_additional_rows )
extern

Increases the number of allocated rows in the SDDS dataset's data table.

This function extends the allocated memory for the data table in the specified SDDS dataset by adding the specified number of additional rows. It reallocates memory for each column's data array and the row flags, initializing the newly allocated memory to zero.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure whose table will be lengthened.
n_additional_rowsThe number of additional rows to allocate. If n_additional_rows is less than zero, it is treated as zero.
Returns
Returns 1 on successful reallocation and initialization. On failure, returns 0 and records an error message.
See also
SDDS_Realloc, SDDS_SetMemory, SDDS_ZeroMemory, SDDS_SetError

Definition at line 297 of file SDDS_dataprep.c.

297 {
298 SDDS_LAYOUT *layout;
299 int64_t i, size;
300 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_LengthenTable"))
301 return (0);
302 layout = &SDDS_dataset->layout;
303#if defined(DEBUG)
304 fprintf(stderr, "table size being increased from %" PRId64 " to %" PRId64 " rows\n", SDDS_dataset->n_rows_allocated, SDDS_dataset->n_rows_allocated + n_additional_rows);
305#endif
306 if (!SDDS_dataset->data && !(SDDS_dataset->data = (void **)calloc(layout->n_columns, sizeof(*SDDS_dataset->data)))) {
307 SDDS_SetError("Unable to start page--memory allocation failure1 (SDDS_LengthenTable)");
308 return (0);
309 }
310 if (n_additional_rows < 0)
311 n_additional_rows = 0;
312 for (i = 0; i < layout->n_columns; i++) {
313 size = SDDS_type_size[layout->column_definition[i].type - 1];
314 if (!(SDDS_dataset->data[i] = (void *)SDDS_Realloc(SDDS_dataset->data[i], (SDDS_dataset->n_rows_allocated + n_additional_rows) * size))) {
315 SDDS_SetError("Unable to lengthen page--memory allocation failure2 (SDDS_LengthenTable)");
316 return (0);
317 }
318 SDDS_ZeroMemory((char *)SDDS_dataset->data[i] + size * SDDS_dataset->n_rows_allocated, size * n_additional_rows);
319 }
320 if (!(SDDS_dataset->row_flag = (int32_t *)SDDS_Realloc(SDDS_dataset->row_flag, (SDDS_dataset->n_rows_allocated + n_additional_rows) * sizeof(int32_t)))) {
321 SDDS_SetError("Unable to lengthen page--memory allocation failure3 (SDDS_LengthenTable)");
322 return (0);
323 }
324 SDDS_dataset->n_rows_allocated += n_additional_rows;
325
326 if (!SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated, SDDS_LONG, (int32_t)1, (int32_t)0) ||
327 !SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
328 !SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)0, (int32_t)1)) {
329 SDDS_SetError("Unable to lengthen page--memory initialization failure4 (SDDS_LengthenTable)");
330 return (0);
331 }
332 return (1);
333}

◆ SDDS_LockFile()

epicsShareFuncSDDS int32_t SDDS_LockFile ( FILE * fp,
const char * filename,
const char * caller )
extern

Attempts to lock a specified file.

This function tries to acquire a lock on the provided file using the given file pointer. If file locking is enabled via the F_TEST and ALLOW_FILE_LOCKING macros, it first tests whether the file can be locked and then attempts to establish an exclusive lock. If locking fails at any step, an error message is set, and the function returns 0.

If file locking is not enabled, the function assumes that the file is not locked and returns 1.

Parameters
[in]fpPointer to the open FILE stream associated with the file to be locked.
[in]filenameThe path to the file to be locked. Used primarily for error messaging.
[in]callerA string identifying the caller or the context in which the lock is being attempted. This is used in error messages to provide more information about the lock attempt.
Returns
  • 1 if the file lock is successfully acquired or if file locking is not enabled.
  • 0 if the file is already locked or if locking fails for another reason.
Note
The function relies on the lockf system call for file locking, which may not be supported on all platforms.
Warning
Proper error handling should be implemented by the caller to handle cases where file locking fails.
See also
SDDS_FileIsLocked, SDDS_SetError

Definition at line 3326 of file SDDS_utils.c.

3326 {
3327#if defined(F_TEST) && ALLOW_FILE_LOCKING
3328 char s[1024];
3329 if (lockf(fileno(fp), F_TEST, 0) == -1) {
3330 sprintf(s, "Unable to access file %s--file is locked (%s)", filename, caller);
3331 SDDS_SetError(s);
3332 return 0;
3333 }
3334 if (lockf(fileno(fp), F_TLOCK, 0) == -1) {
3335 sprintf(s, "Unable to establish lock on file %s (%s)", filename, caller);
3336 SDDS_SetError(s);
3337 return 0;
3338 }
3339 return 1;
3340#else
3341 return 1;
3342#endif
3343}

◆ SDDS_Logic()

epicsShareFuncSDDS int32_t SDDS_Logic ( int32_t previous,
int32_t match,
uint32_t logic )
extern

Applies logical operations to determine the new state of a row flag based on previous and current match conditions.

This function evaluates logical conditions between a previous flag (previous) and a current match flag (match) based on the provided logic flags. It supports various logical operations such as AND, OR, negation of previous flags, and negation of match results.

Parameters
previousThe previous state of the row flag (typically 0 or 1).
matchThe current match result to be combined with the previous flag.
logicAn unsigned integer representing logical operation flags. Supported flags include:
  • SDDS_0_PREVIOUS: Set the previous flag to 0.
  • SDDS_1_PREVIOUS: Set the previous flag to 1.
  • SDDS_NEGATE_PREVIOUS: Negate the previous flag.
  • SDDS_NEGATE_MATCH: Negate the current match result.
  • SDDS_AND: Perform a logical AND between the previous flag and the match result.
  • SDDS_OR: Perform a logical OR between the previous flag and the match result.
  • SDDS_NEGATE_EXPRESSION: Negate the final logical expression result.
Returns
Returns the result of the logical operation as an integer (0 or 1).
Return values
1Indicates that the final logical condition evaluates to true.
0Indicates that the final logical condition evaluates to false.
Note
  • Multiple logic flags can be combined using bitwise OR to perform complex logical operations.
  • The order of operations follows the precedence defined within the function implementation.
See also
SDDS_SetRowsOfInterest, SDDS_MatchRowsOfInterest

Definition at line 4165 of file SDDS_extract.c.

4165 {
4166 if (logic & SDDS_0_PREVIOUS)
4167 previous = 0;
4168 else if (logic & SDDS_1_PREVIOUS)
4169 previous = 1;
4170 if (logic & SDDS_NEGATE_PREVIOUS)
4171 previous = !previous;
4172 if (logic & SDDS_NEGATE_MATCH)
4173 match = !match;
4174 if (logic & SDDS_AND)
4175 match = match && previous;
4176 else if (logic & SDDS_OR)
4177 match = match || previous;
4178 else
4179 match = previous;
4180 if (logic & SDDS_NEGATE_EXPRESSION)
4181 match = !match;
4182 return (match);
4183}

◆ SDDS_MakePointerArray()

epicsShareFuncSDDS void * SDDS_MakePointerArray ( void * data,
int32_t type,
int32_t dimensions,
int32_t * dimension )
extern

Creates a multi-dimensional pointer array from a contiguous data block.

This function generates a multi-dimensional pointer array that maps to a contiguous block of data. It supports arrays with multiple dimensions by recursively creating pointer layers. The dimensions parameter specifies the number of dimensions, and the dimension array provides the size for each dimension.

Parameters
[in]dataPointer to the contiguous data block to be mapped.
[in]typeThe SDDS data type of the elements in the data block. Must be one of the SDDS type constants:
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_LONG64
  • SDDS_ULONG64
  • SDDS_FLOAT
  • SDDS_DOUBLE
  • SDDS_LONGDOUBLE
  • SDDS_CHARACTER
[in]dimensionsThe number of dimensions for the pointer array.
[in]dimensionAn array specifying the size of each dimension.
Returns
  • Returns a pointer to the newly created multi-dimensional pointer array on success.
  • Returns NULL if the input data is NULL, the dimension array is invalid, the type is unknown, or memory allocation fails.
Note
  • The function uses SDDS_MakePointerArrayRecursively to handle multi-dimensional allocations.
  • The caller is responsible for freeing the allocated pointer array using SDDS_FreePointerArray.
See also
SDDS_MakePointerArrayRecursively
SDDS_FreePointerArray
SDDS_SetError

Definition at line 2971 of file SDDS_utils.c.

2971 {
2972 int32_t i;
2973
2974 if (!data) {
2975 SDDS_SetError("Unable to make pointer array--NULL data array (SDDS_MakePointerArray)");
2976 return (NULL);
2977 }
2978 if (!dimension || !dimensions) {
2979 SDDS_SetError("Unable to make pointer array--NULL or zero-length dimension array (SDDS_MakePointerArray)");
2980 return (NULL);
2981 }
2982 if (type <= 0 || type > SDDS_NUM_TYPES) {
2983 SDDS_SetError("Unable to make pointer array--unknown data type (SDDS_MakePointerArray)");
2984 return (NULL);
2985 }
2986 for (i = 0; i < dimensions; i++)
2987 if (dimension[i] <= 0) {
2988 SDDS_SetError("Unable to make pointer array--number of elements invalid (SDDS_MakePointerArray)");
2989 return (NULL);
2990 }
2991 if (dimensions == 1)
2992 return (data);
2993 return (SDDS_MakePointerArrayRecursively(data, SDDS_type_size[type - 1], dimensions, dimension));
2994}
void * SDDS_MakePointerArrayRecursively(void *data, int32_t size, int32_t dimensions, int32_t *dimension)
Recursively creates a multi-dimensional pointer array from a contiguous data block.

◆ SDDS_Malloc()

epicsShareFuncSDDS void * SDDS_Malloc ( size_t size)
extern

Allocates memory of a specified size.

This function is a wrapper around the standard malloc function, used by SDDS routines to allocate memory. It ensures that a minimum allocation size is enforced.

Parameters
[in]sizeNumber of bytes to allocate.
Returns
Pointer to the allocated memory. If size is less than or equal to zero, it allocates memory for 4 bytes by default. Returns NULL if memory allocation fails.
Note
Users should always check the returned pointer for NULL before using it.
See also
SDDS_Calloc
SDDS_Free

Definition at line 639 of file SDDS_utils.c.

639 {
640 if (size <= 0)
641 size = 4;
642 return malloc(size);
643}

◆ SDDS_MatchArrays()

epicsShareFuncSDDS int32_t SDDS_MatchArrays ( SDDS_DATASET * SDDS_dataset,
char *** nameReturn,
int32_t matchMode,
int32_t typeMode,
... )
extern

Matches and retrieves array names from an SDDS dataset based on specified criteria.

This function selects arrays from the provided SDDS dataset according to the specified matching mode and type mode. It supports various calling conventions depending on the matching criteria.

The function supports the following matching modes:

  • SDDS_NAME_ARRAY:
    • Parameters: int32_t n_entries, char **name
    • Description: Matches arrays whose names are present in the provided array.
  • SDDS_NAMES_STRING:
    • Parameters: char *names
    • Description: Matches arrays whose names are specified in a single comma-separated string.
  • SDDS_NAME_STRINGS:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Matches arrays whose names are specified as individual string arguments, terminated by a NULL pointer.
  • SDDS_MATCH_STRING:
    • Parameters: char *name, int32_t logic_mode
    • Description: Matches arrays based on a wildcard pattern provided in name, using the specified logical mode.
  • SDDS_MATCH_EXCLUDE_STRING:
    • Parameters: char *name, char *exclude, int32_t logic_mode
    • Description: Matches arrays based on a wildcard pattern provided in name, excluding those that match the exclude pattern, using the specified logical mode.

Additionally, the typeMode parameter allows filtering based on array types, such as numeric, floating, or integer types.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset.
[out]nameReturnPointer to a char** that will be allocated and populated with the names of the matched arrays. The caller is responsible for freeing the allocated memory.
[in]matchModeSpecifies the matching mode (e.g., SDDS_NAME_ARRAY, SDDS_NAMES_STRING, etc.).
[in]typeModeSpecifies the type matching mode (e.g., FIND_SPECIFIED_TYPE, FIND_NUMERIC_TYPE, FIND_FLOATING_TYPE, FIND_INTEGER_TYPE).
[in]...Variable arguments depending on matchMode:
  • SDDS_NAME_ARRAY: int32_t n_entries, char **name
  • SDDS_NAMES_STRING: char *names
  • SDDS_NAME_STRINGS: char *name1, char *name2, ..., NULL
  • SDDS_MATCH_STRING: char *name, int32_t logic_mode
  • SDDS_MATCH_EXCLUDE_STRING: char *name, char *exclude, int32_t logic_mode
Returns
  • Returns the number of matched arrays on success.
  • Returns -1 if an error occurs (e.g., invalid parameters, memory allocation failure).
Note
  • The function internally manages memory for the matching process and allocates memory for nameReturn, which must be freed by the caller using appropriate memory deallocation functions.
  • The dataset must be properly initialized and contain a valid layout before calling this function.
Warning
  • Ensure that the variable arguments match the expected parameters for the specified matchMode.
  • The caller is responsible for freeing the memory allocated for nameReturn to avoid memory leaks.
See also
SDDS_MatchColumns, SDDS_MatchParameters, SDDS_SetError

Definition at line 4040 of file SDDS_utils.c.

4048{
4049 static int32_t flags = 0, *flag = NULL;
4050 char **name, *string, *match_string, *ptr, *exclude_string;
4051 va_list argptr;
4052 int32_t i, j, index, n_names, retval, requiredType, matches;
4053 /* int32_t type; */
4054 int32_t local_memory; /* (0,1,2) --> (none, pointer array, pointer array + strings) locally allocated */
4055 char buffer[SDDS_MAXLINE];
4056 int32_t logic;
4057
4058 name = NULL;
4059 match_string = exclude_string = NULL;
4060 n_names = requiredType = local_memory = logic = 0;
4061
4062 matches = -1;
4063 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_MatchArrays"))
4064 return -1;
4065 if (nameReturn)
4066 *nameReturn = NULL;
4067
4068 retval = 1;
4069 va_start(argptr, typeMode);
4070 if (typeMode == FIND_SPECIFIED_TYPE)
4071 requiredType = va_arg(argptr, int32_t);
4072 switch (matchMode) {
4073 case SDDS_NAME_ARRAY:
4074 local_memory = 0;
4075 n_names = va_arg(argptr, int32_t);
4076 name = va_arg(argptr, char **);
4077 break;
4078 case SDDS_NAMES_STRING:
4079 local_memory = 2;
4080 n_names = 0;
4081 name = NULL;
4082 ptr = va_arg(argptr, char *);
4083 SDDS_CopyString(&string, ptr);
4084 while ((ptr = strchr(string, ',')))
4085 *ptr = ' ';
4086 while ((SDDS_GetToken(string, buffer, SDDS_MAXLINE) > 0)) {
4087 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1))) || !SDDS_CopyString(name + n_names, buffer)) {
4088 SDDS_SetError("Unable to process array selection--memory allocation failure (SDDS_MatchArrays)");
4089 retval = 0;
4090 break;
4091 }
4092 n_names++;
4093 }
4094 free(string);
4095 break;
4096 case SDDS_NAME_STRINGS:
4097 local_memory = 1;
4098 n_names = 0;
4099 name = NULL;
4100 while ((string = va_arg(argptr, char *))) {
4101 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1)))) {
4102 SDDS_SetError("Unable to process array selection--memory allocation failure (SDDS_MatchArrays)");
4103 retval = 0;
4104 break;
4105 }
4106 name[n_names++] = string;
4107 }
4108 break;
4109 case SDDS_MATCH_STRING:
4110 local_memory = 0;
4111 n_names = 1;
4112 if (!(string = va_arg(argptr, char *))) {
4113 SDDS_SetError("Unable to process array selection--invalid matching string (SDDS_MatchArrays)");
4114 retval = 0;
4115 break;
4116 }
4117 match_string = expand_ranges(string);
4118 logic = va_arg(argptr, int32_t);
4119 break;
4120 case SDDS_MATCH_EXCLUDE_STRING:
4121 local_memory = 0;
4122 n_names = 1;
4123 if (!(string = va_arg(argptr, char *))) {
4124 SDDS_SetError("Unable to process array selection--invalid matching string (SDDS_MatchArrays)");
4125 retval = 0;
4126 break;
4127 }
4128 match_string = expand_ranges(string);
4129 if (!(string = va_arg(argptr, char *))) {
4130 SDDS_SetError("Unable to process array exclusion--invalid matching string (SDDS_MatchArrays)");
4131 retval = 0;
4132 break;
4133 }
4134 exclude_string = expand_ranges(string);
4135 logic = va_arg(argptr, int32_t);
4136 break;
4137 default:
4138 SDDS_SetError("Unable to process array selection--unknown match mode (SDDS_MatchArrays)");
4139 retval = 0;
4140 break;
4141 }
4142 va_end(argptr);
4143 if (retval == 0)
4144 return -1;
4145
4146 if (n_names == 0) {
4147 SDDS_SetError("Unable to process array selection--no names in call (SDDS_MatchArrays)");
4148 return -1;
4149 }
4150
4151 if (SDDS_dataset->layout.n_arrays != flags) {
4152 flags = SDDS_dataset->layout.n_arrays;
4153 if (flag)
4154 free(flag);
4155 if (!(flag = (int32_t *)calloc(flags, sizeof(*flag)))) {
4156 SDDS_SetError("Memory allocation failure (SDDS_MatchArrays)");
4157 return -1;
4158 }
4159 }
4160
4161 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
4162 for (i = 0; i < n_names; i++) {
4163 if ((index = SDDS_GetArrayIndex(SDDS_dataset, name[i])) >= 0)
4164 flag[index] = 1;
4165 else
4166 flag[index] = 0;
4167 }
4168 } else {
4169 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4170 if (SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.array_definition[i].name, match_string), logic)) {
4171 if (exclude_string != NULL) {
4172 if (SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.array_definition[i].name, exclude_string), logic))
4173 flag[i] = 0;
4174 else
4175 flag[i] = 1;
4176 } else {
4177 flag[i] = 1;
4178 }
4179 } else {
4180#if defined(DEBUG)
4181 fprintf(stderr, "no logic match of %s to %s\n", SDDS_dataset->layout.array_definition[i].name, match_string);
4182#endif
4183 flag[i] = 0;
4184 }
4185 }
4186 }
4187 if (match_string)
4188 free(match_string);
4189 if (exclude_string)
4190 free(exclude_string);
4191#if defined(DEBUG)
4192 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4193 fprintf(stderr, "flag[%" PRId32 "] = %" PRId32 " : %s\n", i, flag[i], SDDS_dataset->layout.array_definition[i].name);
4194#endif
4195
4196 if (local_memory == 2) {
4197 for (i = 0; i < n_names; i++)
4198 free(name[i]);
4199 }
4200 if (local_memory >= 1)
4201 free(name);
4202
4203 switch (typeMode) {
4204 case FIND_SPECIFIED_TYPE:
4205 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4206 if (SDDS_dataset->layout.array_definition[i].type != requiredType)
4207 flag[i] = 0;
4208 break;
4209 case FIND_NUMERIC_TYPE:
4210 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4211 if (!SDDS_NUMERIC_TYPE(SDDS_dataset->layout.array_definition[i].type))
4212 flag[i] = 0;
4213 break;
4214 case FIND_FLOATING_TYPE:
4215 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4216 if (!SDDS_FLOATING_TYPE(SDDS_dataset->layout.array_definition[i].type))
4217 flag[i] = 0;
4218 break;
4219 case FIND_INTEGER_TYPE:
4220 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4221 if (!SDDS_INTEGER_TYPE(SDDS_dataset->layout.array_definition[i].type))
4222 flag[i] = 0;
4223 break;
4224 default:
4225 break;
4226 }
4227#if defined(DEBUG)
4228 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4229 if (flag[i])
4230 fprintf(stderr, "array %s matched\n", SDDS_dataset->layout.array_definition[i].name);
4231#endif
4232
4233 for (i = matches = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4234 if (flag[i])
4235 matches++;
4236 }
4237 if (!matches || !nameReturn)
4238 return matches;
4239 if (!((*nameReturn) = (char **)SDDS_Malloc(matches * sizeof(**nameReturn)))) {
4240 SDDS_SetError("Memory allocation failure (SDDS_MatchArrays)");
4241 return -1;
4242 }
4243 for (i = j = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4244 if (flag[i]) {
4245 if (!SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.array_definition[i].name)) {
4246 SDDS_SetError("String copy failure (SDDS_MatchArrays)");
4247 return -1;
4248 }
4249 j++;
4250 }
4251 }
4252
4253 return matches;
4254}
int32_t SDDS_Logic(int32_t previous, int32_t match, uint32_t logic)
Applies logical operations to determine the new state of a row flag based on previous and current mat...
int32_t SDDS_GetToken(char *s, char *buffer, int32_t buflen)
Extracts the next token from a string, handling quoted substrings and escape characters.

◆ SDDS_MatchColumns()

epicsShareFuncSDDS int32_t SDDS_MatchColumns ( SDDS_DATASET * SDDS_dataset,
char *** nameReturn,
int32_t matchMode,
int32_t typeMode,
... )
extern

Matches and retrieves column names from an SDDS dataset based on specified criteria.

This function selects columns from the provided SDDS dataset according to the specified matching mode and type mode. It supports various calling conventions depending on the matching criteria.

The function supports the following matching modes:

  • SDDS_NAME_ARRAY:
    • Parameters: int32_t n_entries, char **name
    • Description: Matches columns whose names are present in the provided array.
  • SDDS_NAMES_STRING:
    • Parameters: char *names
    • Description: Matches columns whose names are specified in a single comma-separated string.
  • SDDS_NAME_STRINGS:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Matches columns whose names are specified as individual string arguments, terminated by a NULL pointer.
  • SDDS_MATCH_STRING:
    • Parameters: char *name, int32_t logic_mode
    • Description: Matches columns based on a wildcard pattern provided in name, using the specified logical mode.
  • SDDS_MATCH_EXCLUDE_STRING:
    • Parameters: char *name, char *exclude, int32_t logic_mode
    • Description: Matches columns based on a wildcard pattern provided in name, excluding those that match the exclude pattern, using the specified logical mode.

Additionally, the typeMode parameter allows filtering based on column types, such as numeric, floating, or integer types.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset.
[out]nameReturnPointer to a char** that will be allocated and populated with the names of the matched columns. The caller is responsible for freeing the allocated memory.
[in]matchModeSpecifies the matching mode (e.g., SDDS_NAME_ARRAY, SDDS_NAMES_STRING, etc.).
[in]typeModeSpecifies the type matching mode (e.g., FIND_SPECIFIED_TYPE, FIND_NUMERIC_TYPE, FIND_FLOATING_TYPE, FIND_INTEGER_TYPE).
[in]...Variable arguments depending on matchMode:
  • SDDS_NAME_ARRAY: int32_t n_entries, char **name
  • SDDS_NAMES_STRING: char *names
  • SDDS_NAME_STRINGS: char *name1, char *name2, ..., NULL
  • SDDS_MATCH_STRING: char *name, int32_t logic_mode
  • SDDS_MATCH_EXCLUDE_STRING: char *name, char *exclude, int32_t logic_mode
Returns
  • Returns the number of matched columns on success.
  • Returns -1 if an error occurs (e.g., invalid parameters, memory allocation failure).
Note
  • The function internally manages memory for the matching process and allocates memory for nameReturn, which must be freed by the caller using appropriate memory deallocation functions.
  • The dataset must be properly initialized and contain a valid layout before calling this function.
Warning
  • Ensure that the variable arguments match the expected parameters for the specified matchMode.
  • The caller is responsible for freeing the memory allocated for nameReturn to avoid memory leaks.
See also
SDDS_MatchParameters, SDDS_SetError

Definition at line 3484 of file SDDS_utils.c.

3492{
3493 static int32_t flags = 0;
3494 static int32_t *flag = NULL;
3495 char **name, *string, *match_string, *ptr, *exclude_string;
3496 va_list argptr;
3497 int32_t retval, requiredType;
3498 int32_t i, j, n_names, index, matches;
3499 int32_t local_memory; /* (0,1,2) --> (none, pointer array, pointer array + strings) locally allocated */
3500 char buffer[SDDS_MAXLINE];
3501 int32_t logic;
3502
3503 name = NULL;
3504 match_string = exclude_string = NULL;
3505 n_names = requiredType = local_memory = logic = 0;
3506
3507 matches = -1;
3508 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_MatchColumns"))
3509 return -1;
3510 if (nameReturn)
3511 *nameReturn = NULL;
3512
3513 retval = 1;
3514 va_start(argptr, typeMode);
3515 if (typeMode == FIND_SPECIFIED_TYPE)
3516 requiredType = va_arg(argptr, int32_t);
3517 switch (matchMode) {
3518 case SDDS_NAME_ARRAY:
3519 local_memory = 0;
3520 n_names = va_arg(argptr, int32_t);
3521 name = va_arg(argptr, char **);
3522 break;
3523 case SDDS_NAMES_STRING:
3524 local_memory = 2;
3525 n_names = 0;
3526 name = NULL;
3527 ptr = va_arg(argptr, char *);
3528 SDDS_CopyString(&string, ptr);
3529 while ((ptr = strchr(string, ',')))
3530 *ptr = ' ';
3531 while (SDDS_GetToken(string, buffer, SDDS_MAXLINE) > 0) {
3532 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1))) || !SDDS_CopyString(name + n_names, buffer)) {
3533 SDDS_SetError("Unable to process column selection--memory allocation failure (SDDS_MatchColumns)");
3534 retval = 0;
3535 break;
3536 }
3537 n_names++;
3538 }
3539 free(string);
3540 break;
3541 case SDDS_NAME_STRINGS:
3542 local_memory = 1;
3543 n_names = 0;
3544 name = NULL;
3545 while ((string = va_arg(argptr, char *))) {
3546 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1)))) {
3547 SDDS_SetError("Unable to process column selection--memory allocation failure (SDDS_MatchColumns)");
3548 retval = 0;
3549 break;
3550 }
3551 name[n_names++] = string;
3552 }
3553 break;
3554 case SDDS_MATCH_STRING:
3555 local_memory = 0;
3556 n_names = 1;
3557 if (!(string = va_arg(argptr, char *))) {
3558 SDDS_SetError("Unable to process column selection--invalid matching string (SDDS_MatchColumns)");
3559 retval = 0;
3560 break;
3561 }
3562 match_string = expand_ranges(string);
3563 logic = va_arg(argptr, int32_t);
3564 break;
3565 case SDDS_MATCH_EXCLUDE_STRING:
3566 local_memory = 0;
3567 n_names = 1;
3568 if (!(string = va_arg(argptr, char *))) {
3569 SDDS_SetError("Unable to process column selection--invalid matching string (SDDS_MatchColumns)");
3570 retval = 0;
3571 break;
3572 }
3573 match_string = expand_ranges(string);
3574 if (!(string = va_arg(argptr, char *))) {
3575 SDDS_SetError("Unable to process column exclusion--invalid matching string (SDDS_MatchColumns)");
3576 retval = 0;
3577 break;
3578 }
3579 exclude_string = expand_ranges(string);
3580 logic = va_arg(argptr, int32_t);
3581 break;
3582 default:
3583 SDDS_SetError("Unable to process column selection--unknown match mode (SDDS_MatchColumns)");
3584 retval = 0;
3585 break;
3586 }
3587 va_end(argptr);
3588 if (retval == 0)
3589 return -1;
3590
3591 if (n_names == 0) {
3592 SDDS_SetError("Unable to process column selection--no names in call (SDDS_MatchColumns)");
3593 return -1;
3594 }
3595
3596 if (SDDS_dataset->layout.n_columns != flags) {
3597 flags = SDDS_dataset->layout.n_columns;
3598 if (flag)
3599 free(flag);
3600 if (!(flag = (int32_t *)calloc(flags, sizeof(*flag)))) {
3601 SDDS_SetError("Memory allocation failure (SDDS_MatchColumns)");
3602 return -1;
3603 }
3604 }
3605
3606 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
3607 for (i = 0; i < n_names; i++) {
3608 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name[i])) >= 0)
3609 flag[index] = 1;
3610 else
3611 flag[index] = 0;
3612 }
3613 } else {
3614 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
3615 if (SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.column_definition[i].name, match_string), logic)) {
3616 if (exclude_string != NULL) {
3617 if (SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.column_definition[i].name, exclude_string), logic))
3618 flag[i] = 0;
3619 else
3620 flag[i] = 1;
3621 } else {
3622 flag[i] = 1;
3623 }
3624 } else {
3625#if defined(DEBUG)
3626 fprintf(stderr, "no logic match of %s to %s\n", SDDS_dataset->layout.column_definition[i].name, match_string);
3627#endif
3628 flag[i] = 0;
3629 }
3630 }
3631 }
3632 if (match_string)
3633 free(match_string);
3634 if (exclude_string)
3635 free(exclude_string);
3636#if defined(DEBUG)
3637 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3638 fprintf(stderr, "flag[%" PRId32 "] = %" PRId32 " : %s\n", i, flag[i], SDDS_dataset->layout.column_definition[i].name);
3639#endif
3640
3641 if (local_memory == 2) {
3642 for (i = 0; i < n_names; i++)
3643 free(name[i]);
3644 }
3645 if (local_memory >= 1)
3646 free(name);
3647
3648 switch (typeMode) {
3649 case FIND_SPECIFIED_TYPE:
3650 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3651 if (SDDS_dataset->layout.column_definition[i].type != requiredType)
3652 flag[i] = 0;
3653 break;
3654 case FIND_NUMERIC_TYPE:
3655 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3656 if (!SDDS_NUMERIC_TYPE(SDDS_dataset->layout.column_definition[i].type))
3657 flag[i] = 0;
3658 break;
3659 case FIND_FLOATING_TYPE:
3660 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3661 if (!SDDS_FLOATING_TYPE(SDDS_dataset->layout.column_definition[i].type))
3662 flag[i] = 0;
3663 break;
3664 case FIND_INTEGER_TYPE:
3665 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3666 if (!SDDS_INTEGER_TYPE(SDDS_dataset->layout.column_definition[i].type))
3667 flag[i] = 0;
3668 break;
3669 default:
3670 break;
3671 }
3672#if defined(DEBUG)
3673 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3674 if (flag[i])
3675 fprintf(stderr, "column %s matched\n", SDDS_dataset->layout.column_definition[i].name);
3676#endif
3677
3678 for (i = matches = 0; i < SDDS_dataset->layout.n_columns; i++) {
3679 if (flag[i])
3680 matches++;
3681 }
3682 if (!matches || !nameReturn)
3683 return matches;
3684 if (!((*nameReturn) = (char **)SDDS_Malloc(matches * sizeof(**nameReturn)))) {
3685 SDDS_SetError("Memory allocation failure (SDDS_MatchColumns)");
3686 return -1;
3687 }
3688 for (i = j = 0; i < SDDS_dataset->layout.n_columns; i++) {
3689 if (flag[i]) {
3690 if (!SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.column_definition[i].name)) {
3691 SDDS_SetError("String copy failure (SDDS_MatchColumns)");
3692 return -1;
3693 }
3694 j++;
3695 }
3696 }
3697 return matches;
3698}

◆ SDDS_MatchParameters()

epicsShareFuncSDDS int32_t SDDS_MatchParameters ( SDDS_DATASET * SDDS_dataset,
char *** nameReturn,
int32_t matchMode,
int32_t typeMode,
... )
extern

Matches and retrieves parameter names from an SDDS dataset based on specified criteria.

This function selects parameters from the provided SDDS dataset according to the specified matching mode and type mode. It supports various calling conventions depending on the matching criteria.

The function supports the following matching modes:

  • SDDS_NAME_ARRAY:
    • Parameters: int32_t n_entries, char **name
    • Description: Matches parameters whose names are present in the provided array.
  • SDDS_NAMES_STRING:
    • Parameters: char *names
    • Description: Matches parameters whose names are specified in a single comma-separated string.
  • SDDS_NAME_STRINGS:
    • Parameters: char *name1, char *name2, ..., NULL
    • Description: Matches parameters whose names are specified as individual string arguments, terminated by a NULL pointer.
  • SDDS_MATCH_STRING:
    • Parameters: char *name, int32_t logic_mode
    • Description: Matches parameters based on a wildcard pattern provided in name, using the specified logical mode.
  • SDDS_MATCH_EXCLUDE_STRING:
    • Parameters: char *name, char *exclude, int32_t logic_mode
    • Description: Matches parameters based on a wildcard pattern provided in name, excluding those that match the exclude pattern, using the specified logical mode.

Additionally, the typeMode parameter allows filtering based on parameter types, such as numeric, floating, or integer types.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure containing the dataset.
[out]nameReturnPointer to a char** that will be allocated and populated with the names of the matched parameters. The caller is responsible for freeing the allocated memory.
[in]matchModeSpecifies the matching mode (e.g., SDDS_NAME_ARRAY, SDDS_NAMES_STRING, etc.).
[in]typeModeSpecifies the type matching mode (e.g., FIND_SPECIFIED_TYPE, FIND_NUMERIC_TYPE, FIND_FLOATING_TYPE, FIND_INTEGER_TYPE).
[in]...Variable arguments depending on matchMode:
  • SDDS_NAME_ARRAY: int32_t n_entries, char **name
  • SDDS_NAMES_STRING: char *names
  • SDDS_NAME_STRINGS: char *name1, char *name2, ..., NULL
  • SDDS_MATCH_STRING: char *name, int32_t logic_mode
  • SDDS_MATCH_EXCLUDE_STRING: char *name, char *exclude, int32_t logic_mode
Returns
  • Returns the number of matched parameters on success.
  • Returns -1 if an error occurs (e.g., invalid parameters, memory allocation failure).
Note
  • The function internally manages memory for the matching process and allocates memory for nameReturn, which must be freed by the caller using appropriate memory deallocation functions.
  • The dataset must be properly initialized and contain a valid layout before calling this function.
Warning
  • Ensure that the variable arguments match the expected parameters for the specified matchMode.
  • The caller is responsible for freeing the memory allocated for nameReturn to avoid memory leaks.
See also
SDDS_MatchColumns, SDDS_SetError

Definition at line 3762 of file SDDS_utils.c.

3770{
3771 static int32_t flags = 0, *flag = NULL;
3772 char **name, *string, *match_string, *ptr, *exclude_string;
3773 va_list argptr;
3774 int32_t i, j, index, n_names, retval, requiredType, matches;
3775 /* int32_t type; */
3776 int32_t local_memory; /* (0,1,2) --> (none, pointer array, pointer array + strings) locally allocated */
3777 char buffer[SDDS_MAXLINE];
3778 int32_t logic;
3779
3780 name = NULL;
3781 match_string = exclude_string = NULL;
3782 n_names = requiredType = local_memory = logic = 0;
3783
3784 matches = -1;
3785 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_MatchParameters"))
3786 return -1;
3787 if (nameReturn)
3788 *nameReturn = NULL;
3789
3790 retval = 1;
3791 va_start(argptr, typeMode);
3792 if (typeMode == FIND_SPECIFIED_TYPE)
3793 requiredType = va_arg(argptr, int32_t);
3794 switch (matchMode) {
3795 case SDDS_NAME_ARRAY:
3796 local_memory = 0;
3797 n_names = va_arg(argptr, int32_t);
3798 name = va_arg(argptr, char **);
3799 break;
3800 case SDDS_NAMES_STRING:
3801 local_memory = 2;
3802 n_names = 0;
3803 name = NULL;
3804 ptr = va_arg(argptr, char *);
3805 SDDS_CopyString(&string, ptr);
3806 while ((ptr = strchr(string, ',')))
3807 *ptr = ' ';
3808 while (SDDS_GetToken(string, buffer, SDDS_MAXLINE) > 0) {
3809 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1))) || !SDDS_CopyString(name + n_names, buffer)) {
3810 SDDS_SetError("Unable to process parameter selection--memory allocation failure (SDDS_MatchParameters)");
3811 retval = 0;
3812 break;
3813 }
3814 n_names++;
3815 }
3816 free(string);
3817 break;
3818 case SDDS_NAME_STRINGS:
3819 local_memory = 1;
3820 n_names = 0;
3821 name = NULL;
3822 while ((string = va_arg(argptr, char *))) {
3823 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1)))) {
3824 SDDS_SetError("Unable to process parameter selection--memory allocation failure (SDDS_MatchParameters)");
3825 retval = 0;
3826 break;
3827 }
3828 name[n_names++] = string;
3829 }
3830 break;
3831 case SDDS_MATCH_STRING:
3832 local_memory = 0;
3833 n_names = 1;
3834 if (!(string = va_arg(argptr, char *))) {
3835 SDDS_SetError("Unable to process parameter selection--invalid matching string (SDDS_MatchParameters)");
3836 retval = 0;
3837 break;
3838 }
3839 match_string = expand_ranges(string);
3840 logic = va_arg(argptr, int32_t);
3841 break;
3842 case SDDS_MATCH_EXCLUDE_STRING:
3843 local_memory = 0;
3844 n_names = 1;
3845 if (!(string = va_arg(argptr, char *))) {
3846 SDDS_SetError("Unable to process parameter selection--invalid matching string (SDDS_MatchParameters)");
3847 retval = 0;
3848 break;
3849 }
3850 match_string = expand_ranges(string);
3851 if (!(string = va_arg(argptr, char *))) {
3852 SDDS_SetError("Unable to process parameter exclusion--invalid matching string (SDDS_MatchParameters)");
3853 retval = 0;
3854 break;
3855 }
3856 exclude_string = expand_ranges(string);
3857 logic = va_arg(argptr, int32_t);
3858 break;
3859 default:
3860 SDDS_SetError("Unable to process parameter selection--unknown match mode (SDDS_MatchParameters)");
3861 retval = 0;
3862 break;
3863 }
3864 va_end(argptr);
3865 if (retval == 0)
3866 return -1;
3867
3868 if (n_names == 0) {
3869 SDDS_SetError("Unable to process parameter selection--no names in call (SDDS_MatchParameters)");
3870 return -1;
3871 }
3872
3873 if (SDDS_dataset->layout.n_parameters != flags) {
3874 flags = SDDS_dataset->layout.n_parameters;
3875 if (flag)
3876 free(flag);
3877 if (!(flag = (int32_t *)calloc(flags, sizeof(*flag)))) {
3878 SDDS_SetError("Memory allocation failure (SDDS_MatchParameters)");
3879 return -1;
3880 }
3881 }
3882
3883 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
3884 for (i = 0; i < n_names; i++) {
3885 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name[i])) >= 0)
3886 flag[index] = 1;
3887 else
3888 flag[index] = 0;
3889 }
3890 } else {
3891 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++) {
3892 if (SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.parameter_definition[i].name, match_string), logic)) {
3893 if (exclude_string != NULL) {
3894 if (SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.parameter_definition[i].name, exclude_string), logic))
3895 flag[i] = 0;
3896 else
3897 flag[i] = 1;
3898 } else {
3899 flag[i] = 1;
3900 }
3901 } else {
3902#if defined(DEBUG)
3903 fprintf(stderr, "no logic match of %s to %s\n", SDDS_dataset->layout.parameter_definition[i].name, match_string);
3904#endif
3905 flag[i] = 0;
3906 }
3907 }
3908 }
3909 if (match_string)
3910 free(match_string);
3911 if (exclude_string)
3912 free(exclude_string);
3913#if defined(DEBUG)
3914 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3915 fprintf(stderr, "flag[%" PRId32 "] = %" PRId32 " : %s\n", i, flag[i], SDDS_dataset->layout.parameter_definition[i].name);
3916#endif
3917
3918 if (local_memory == 2) {
3919 for (i = 0; i < n_names; i++)
3920 free(name[i]);
3921 }
3922 if (local_memory >= 1)
3923 free(name);
3924
3925 switch (typeMode) {
3926 case FIND_SPECIFIED_TYPE:
3927 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3928 if (SDDS_dataset->layout.parameter_definition[i].type != requiredType)
3929 flag[i] = 0;
3930 break;
3931 case FIND_NUMERIC_TYPE:
3932 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3933 if (!SDDS_NUMERIC_TYPE(SDDS_dataset->layout.parameter_definition[i].type))
3934 flag[i] = 0;
3935 break;
3936 case FIND_FLOATING_TYPE:
3937 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3938 if (!SDDS_FLOATING_TYPE(SDDS_dataset->layout.parameter_definition[i].type))
3939 flag[i] = 0;
3940 break;
3941 case FIND_INTEGER_TYPE:
3942 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3943 if (!SDDS_INTEGER_TYPE(SDDS_dataset->layout.parameter_definition[i].type))
3944 flag[i] = 0;
3945 break;
3946 default:
3947 break;
3948 }
3949#if defined(DEBUG)
3950 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3951 if (flag[i])
3952 fprintf(stderr, "parameter %s matched\n", SDDS_dataset->layout.parameter_definition[i].name);
3953#endif
3954
3955 for (i = matches = 0; i < SDDS_dataset->layout.n_parameters; i++) {
3956 if (flag[i])
3957 matches++;
3958 }
3959 if (!matches || !nameReturn)
3960 return matches;
3961 if (!((*nameReturn) = (char **)SDDS_Malloc(matches * sizeof(**nameReturn)))) {
3962 SDDS_SetError("Memory allocation failure (SDDS_MatchParameters)");
3963 return -1;
3964 }
3965 for (i = j = 0; i < SDDS_dataset->layout.n_parameters; i++) {
3966 if (flag[i]) {
3967 if (!SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.parameter_definition[i].name)) {
3968 SDDS_SetError("String copy failure (SDDS_MatchParameters)");
3969 return -1;
3970 }
3971 j++;
3972 }
3973 }
3974
3975 return matches;
3976}

◆ SDDS_MatchRowsOfInterest()

epicsShareFuncSDDS int64_t SDDS_MatchRowsOfInterest ( SDDS_DATASET * SDDS_dataset,
char * selection_column,
char * label_to_match,
int32_t logic )
extern

Matches and marks rows of interest in an SDDS dataset based on label matching.

This function marks rows in the provided SDDS dataset as "of interest" by matching labels in a specified column against a target label. It supports both direct and indirect matching, as well as case-sensitive and case-insensitive comparisons, based on the provided logic flags.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
selection_columnA null-terminated string specifying the name of the column used for label matching. This column must be of string or character type.
label_to_matchA null-terminated string specifying the label to match against the entries in the selection column. If logic includes SDDS_INDIRECT_MATCH, this parameter is treated as the name of another column used for indirect matching.
logicAn integer representing logical operation flags. Supported flags include:
  • SDDS_NOCASE_COMPARE: Perform case-insensitive comparison.
  • SDDS_INDIRECT_MATCH: Use indirect matching via another column.
Returns
On success, returns the number of rows marked as "of interest". On failure, returns -1 and sets an appropriate error message.
Return values
-1Indicates that an error occurred (e.g., invalid dataset, unrecognized selection column, type mismatch, unrecognized indirect column).
Non-negativeInteger representing the count of rows marked as "of interest".
Note
  • The selection column must exist and be of string or character type.
  • If using indirect matching (SDDS_INDIRECT_MATCH), the indirect column must exist and be of the same type as the selection column.
See also
SDDS_SetRowsOfInterest, SDDS_FilterRowsOfInterest, SDDS_DeleteUnsetRows

Definition at line 3506 of file SDDS_extract.c.

3506 {
3507 int32_t match, type, index, indirect_index;
3508 int64_t i, count;
3509 char *match_string;
3510#ifndef tolower
3511# if !defined(_MINGW)
3512 int tolower(int c);
3513# endif
3514#endif
3515
3516 index = type = indirect_index = 0;
3517
3518 match_string = NULL;
3519 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_MatchRowsOfInterest"))
3520 return (-1);
3521 if (selection_column) {
3522 if ((index = SDDS_GetColumnIndex(SDDS_dataset, selection_column)) < 0) {
3523 SDDS_SetError("Unable to select rows--column name is unrecognized (SDDS_MatchRowsOfInterest)");
3524 return (-1);
3525 }
3526 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) != SDDS_STRING && type != SDDS_CHARACTER) {
3527 SDDS_SetError("Unable to select rows--selection column is not a string (SDDS_MatchRowsOfInterest)");
3528 return (-1);
3529 }
3530 if (!label_to_match) {
3531 SDDS_SetError("Unable to select rows--selection label is NULL (SDDS_MatchRowsOfInterest)");
3532 return (-1);
3533 }
3534 if (!(logic & SDDS_INDIRECT_MATCH))
3535 match_string = expand_ranges(label_to_match);
3536 else {
3537 if ((indirect_index = SDDS_GetColumnIndex(SDDS_dataset, label_to_match)) < 0) {
3538 SDDS_SetError("Unable to select rows--indirect column name is unrecognized (SDDS_MatchRowsOfInterest)");
3539 return (-1);
3540 }
3541 if (SDDS_GetColumnType(SDDS_dataset, indirect_index) != type) {
3542 SDDS_SetError("Unable to select rows--indirect column is not same type as main column (SDDS_MatchRowsOfInterest)");
3543 return (-1);
3544 }
3545 }
3546 }
3547 if (type == SDDS_STRING) {
3548 int (*stringCompare)(const char *s, const char *t);
3549 int (*wildMatch)(char *s, char *t);
3550 if (logic & SDDS_NOCASE_COMPARE) {
3551 stringCompare = strcmp_ci;
3552 wildMatch = wild_match_ci;
3553 } else {
3554 stringCompare = strcmp;
3555 wildMatch = wild_match;
3556 }
3557 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3558 if (selection_column)
3559 match = SDDS_Logic(SDDS_dataset->row_flag[i], (logic & SDDS_INDIRECT_MATCH ? (*stringCompare)(*((char **)SDDS_dataset->data[index] + i), *((char **)SDDS_dataset->data[indirect_index] + i)) == 0 : (*wildMatch)(*((char **)SDDS_dataset->data[index] + i), match_string)), logic);
3560 else
3561 match = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3562 if ((SDDS_dataset->row_flag[i] = match))
3563 count++;
3564 }
3565 } else {
3566 char c1, c2;
3567 c2 = 0;
3568 if (!(logic & SDDS_INDIRECT_MATCH))
3569 c2 = *match_string;
3570 if (logic & SDDS_NOCASE_COMPARE) {
3571 c2 = tolower(c2);
3572 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3573 c1 = tolower(*((char *)SDDS_dataset->data[index] + i));
3574 if (selection_column)
3575 match = SDDS_Logic(SDDS_dataset->row_flag[i], logic & SDDS_INDIRECT_MATCH ? c1 == tolower(*((char *)SDDS_dataset->data[indirect_index] + i)) : c1 == c2, logic);
3576 else
3577 match = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3578 if ((SDDS_dataset->row_flag[i] = match))
3579 count++;
3580 }
3581 } else {
3582 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3583 c1 = *((char *)SDDS_dataset->data[index] + i);
3584 if (selection_column)
3585 match = SDDS_Logic(SDDS_dataset->row_flag[i], logic & SDDS_INDIRECT_MATCH ? c1 == *((char *)SDDS_dataset->data[indirect_index] + i) : c1 == c2, logic);
3586 else
3587 match = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3588 if ((SDDS_dataset->row_flag[i] = match))
3589 count++;
3590 }
3591 }
3592 }
3593 if (match_string)
3594 free(match_string);
3595 return (count);
3596}
int wild_match_ci(char *string, char *template)
Determine whether one string is a case-insensitive wildcard match for another.
Definition wild_match.c:220
int strcmp_ci(const char *s, const char *t)
Compare two strings case-insensitively.
Definition wild_match.c:396

◆ SDDS_NumberOfErrors()

epicsShareFuncSDDS int32_t SDDS_NumberOfErrors ( void )
extern

Retrieves the number of errors recorded by SDDS library routines.

This function returns the total number of errors that have been recorded by the SDDS library since the last invocation of SDDS_PrintErrors.

Returns
The number of recorded errors.
See also
SDDS_PrintErrors

Definition at line 304 of file SDDS_utils.c.

304 {
305 return (n_errors);
306}

◆ SDDS_PadToLength()

epicsShareFuncSDDS int32_t SDDS_PadToLength ( char * string,
int32_t length )
extern

Pads a string with spaces to reach a specified length.

This function appends space characters to the end of the input string string until it reaches the desired length. If the original string is longer than the specified length, the function returns an error without modifying the string.

Parameters
[in,out]stringPointer to the null-terminated string to be padded.
[in]lengthThe target length for the string after padding.
Returns
Returns 1 on successful padding. Returns 0 if the input string is NULL or if the original string length exceeds the specified length.
Note
The function ensures that the padded string is null-terminated. The caller must ensure that the buffer string has sufficient space to accommodate the additional padding.
See also
SDDS_RemovePadding

Definition at line 1879 of file SDDS_utils.c.

1879 {
1880 int32_t i;
1881 if (!string || (i = strlen(string)) > length)
1882 return (0);
1883 while (i < length)
1884 string[i++] = ' ';
1885 string[i] = 0;
1886 return (1);
1887}

◆ SDDS_Parallel_InitializeOutput()

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

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

epicsShareFuncSDDS int32_t SDDS_ParameterCount ( SDDS_DATASET * page)
extern

Retrieves the number of parameters in the SDDS dataset.

This function returns the total count of parameters defined in the layout of the provided SDDS dataset.

Parameters
[in]pagePointer to the SDDS_DATASET structure representing the dataset.
Returns
  • The number of parameters (int32_t) in the dataset.
  • 0 if the provided dataset pointer is NULL.
Note
  • Ensure that the dataset is properly initialized before calling this function.
See also
SDDS_GetParameterIndex, SDDS_CheckParameter

Definition at line 5030 of file SDDS_utils.c.

5030 {
5031 if (!page)
5032 return 0;
5033 return page->layout.n_parameters;
5034}

◆ SDDS_ParseNamelist()

epicsShareFuncSDDS int32_t SDDS_ParseNamelist ( void * data,
SDDS_FIELD_INFORMATION * fieldInfo,
int32_t fieldInfos,
char * s )
extern

Parse a namelist string and populate the corresponding data structure.

This function parses a namelist string containing tag-value pairs and assigns the values to the appropriate fields in the provided data structure based on the field information provided.

Parameters
dataPointer to the data structure to populate.
fieldInfoArray of SDDS_FIELD_INFORMATION structures describing the fields.
fieldInfosNumber of elements in the fieldInfo array.
sPointer to the namelist string.
Returns
Returns 1 on success, 0 on failure.

Definition at line 588 of file SDDS_process.c.

588 {
589 char buffer[1024], *ptr, *tag, *value;
590 int32_t index, longValue;
591
593 while (*ptr && !SDDS_StringIsBlank(ptr) && (ptr = SDDS_GetTagValuePair(ptr, &tag, &value))) {
594 if (!tag)
595 break; /* normal termination */
596 if ((index = SDDS_FindFieldIndex(tag, fieldInfo, fieldInfos)) < 0) {
597 sprintf(buffer, "Unrecognized namelist tag given: %s", tag);
598 SDDS_SetError(buffer);
599 return 0;
600 } else {
601 if (fieldInfo[index].enumPair) {
602 if (fieldInfo[index].type != SDDS_LONG) {
603 fprintf(stderr, "SDDS_ParseNamelist: namelist setup problem---get expert help!\n");
604 exit(1);
605 }
606 /* map a string value into an integer */
607 if ((longValue = SDDS_MatchEnum(value, fieldInfo[index].enumPair)) < 0) {
608 sprintf(buffer, "Unrecognized value given for %s: %s", tag, value);
609 SDDS_SetError(buffer);
610 return 0;
611 } else
612 *((int32_t *)((char *)data + fieldInfo[index].offset)) = longValue;
613 } else {
614 switch (fieldInfo[index].type) {
615 case SDDS_STRING:
616 if (!(SDDS_CopyString((char **)((char *)data + fieldInfo[index].offset), value))) {
617 SDDS_SetError("Problem setting string value for namelist");
618 return 0;
619 }
620 break;
621 case SDDS_CHARACTER:
622 *((char *)data + fieldInfo[index].offset) = *value;
623 break;
624 case SDDS_SHORT:
625 if (!sscanf(value, "%hd", (short *)((char *)data + fieldInfo[index].offset))) {
626 SDDS_SetError("Problem scanning short value for namelist");
627 return 0;
628 }
629 break;
630 case SDDS_USHORT:
631 if (!sscanf(value, "%hu", (unsigned short *)((char *)data + fieldInfo[index].offset))) {
632 SDDS_SetError("Problem scanning unsigned short value for namelist");
633 return 0;
634 }
635 break;
636 case SDDS_LONG:
637 if (!sscanf(value, "%" SCNd32, (int32_t *)((char *)data + fieldInfo[index].offset))) {
638 SDDS_SetError("Problem scanning int32_t value for namelist");
639 return 0;
640 }
641 break;
642 case SDDS_ULONG:
643 if (!sscanf(value, "%" SCNu32, (uint32_t *)((char *)data + fieldInfo[index].offset))) {
644 SDDS_SetError("Problem scanning uint32_t value for namelist");
645 return 0;
646 }
647 break;
648 case SDDS_LONG64:
649 if (!sscanf(value, "%" SCNd64, (int64_t *)((char *)data + fieldInfo[index].offset))) {
650 SDDS_SetError("Problem scanning int64_t value for namelist");
651 return 0;
652 }
653 break;
654 case SDDS_ULONG64:
655 if (!sscanf(value, "%" SCNu64, (uint64_t *)((char *)data + fieldInfo[index].offset))) {
656 SDDS_SetError("Problem scanning uint64_t value for namelist");
657 return 0;
658 }
659 break;
660 case SDDS_LONGDOUBLE:
661 if (!sscanf(value, "%Lf", (long double *)((char *)data + fieldInfo[index].offset))) {
662 SDDS_SetError("Problem scanning long double value for namelist");
663 return 0;
664 }
665 break;
666 case SDDS_DOUBLE:
667 if (!sscanf(value, "%lf", (double *)((char *)data + fieldInfo[index].offset))) {
668 SDDS_SetError("Problem scanning double value for namelist");
669 return 0;
670 }
671 break;
672 case SDDS_FLOAT:
673 if (!sscanf(value, "%f", (float *)((char *)data + fieldInfo[index].offset))) {
674 SDDS_SetError("Problem scanning float value for namelist");
675 return 0;
676 }
677 break;
678 default:
679 SDDS_SetError("Internal error: unknown field information type");
680 return 0;
681 }
682 }
683 }
684 }
685 if (!ptr) {
686 SDDS_SetError("Problem parsing description namelist");
687 return 0;
688 }
689 return 1;
690}
int32_t SDDS_MatchEnum(char *value, SDDS_ENUM_PAIR *enumPair)
Match an enumeration string to its corresponding value.
char * SDDS_GetTagValuePair(char *ptr, char **tag, char **value)
Retrieve a tag-value pair from the input string.
char * SDDS_PrepareToParseTagValuePairs(char *s)
Prepare the string for parsing tag-value pairs.
int32_t SDDS_FindFieldIndex(char *tag, SDDS_FIELD_INFORMATION *fieldInfo, int32_t fieldInfos)
Find the index of a field based on its tag.

◆ SDDS_PrintCheckText()

epicsShareFuncSDDS int32_t SDDS_PrintCheckText ( FILE * fp,
char * name,
char * units,
int32_t type,
char * class_name,
int32_t error_code )
extern

Prints detailed error messages related to SDDS entity checks.

This function outputs error messages to the specified file pointer based on the provided error code. It is primarily used by functions like SDDS_CheckColumn, SDDS_CheckParameter, and SDDS_CheckArray to report issues during validation checks.

Parameters
[in]fpFile pointer where the error messages will be printed. Typically, this is stderr.
[in]nameThe name of the SDDS entity (e.g., column, parameter, array) being checked.
[in]unitsThe expected units of the SDDS entity. May be NULL if units are not relevant.
[in]typeThe expected type code of the SDDS entity. This can be a specific type or a general category like SDDS_ANY_NUMERIC_TYPE.
[in]class_nameA string representing the class of the SDDS entity (e.g., "column", "parameter", "array").
[in]error_codeThe specific error code indicating the type of error encountered. Valid values include:
  • SDDS_CHECK_OKAY
  • SDDS_CHECK_NONEXISTENT
  • SDDS_CHECK_WRONGTYPE
  • SDDS_CHECK_WRONGUNITS
Returns
Returns the same error_code that was passed as an argument.
Note
  • This function assumes that registeredProgramName is a globally accessible string containing the name of the program for contextual error messages.
  • Ensure that fp, name, and class_name are not NULL to prevent undefined behavior.
Warning
  • Passing invalid error_code values that are not handled in the switch statement will result in a generic error message being printed to stderr.
See also
SDDS_CheckColumn, SDDS_CheckParameter, SDDS_CheckArray

Definition at line 4830 of file SDDS_utils.c.

4830 {
4831 if (!fp || !name || !class_name)
4832 return (error_code);
4833 switch (error_code) {
4834 case SDDS_CHECK_OKAY:
4835 break;
4836 case SDDS_CHECK_NONEXISTENT:
4837 fprintf(fp, "Problem with %s %s: nonexistent (%s)\n", class_name, name, registeredProgramName ? registeredProgramName : "?");
4838 break;
4839 case SDDS_CHECK_WRONGTYPE:
4840 if (SDDS_VALID_TYPE(type))
4841 fprintf(fp, "Problem with %s %s: wrong data type--expected %s (%s)\n", class_name, name, SDDS_type_name[type - 1], registeredProgramName ? registeredProgramName : "?");
4842 else if (type == SDDS_ANY_NUMERIC_TYPE)
4843 fprintf(fp, "Problem with %s %s: wrong data type--expected numeric data (%s)\n", class_name, name, registeredProgramName ? registeredProgramName : "?");
4844 else if (type == SDDS_ANY_FLOATING_TYPE)
4845 fprintf(fp, "Problem with %s %s: wrong data type--expected floating point data (%s)\n", class_name, name, registeredProgramName ? registeredProgramName : "?");
4846 else if (type == SDDS_ANY_INTEGER_TYPE)
4847 fprintf(fp, "Problem with %s %s: wrong data type--expected integer data (%s)\n", class_name, name, registeredProgramName ? registeredProgramName : "?");
4848 else if (type)
4849 fprintf(fp, "Problem with %s %s: invalid data type code seen---may be a programming error (%s)\n", class_name, name, registeredProgramName ? registeredProgramName : "?");
4850 break;
4851 case SDDS_CHECK_WRONGUNITS:
4852 fprintf(fp, "Problem with %s %s: wrong units--expected %s (%s)\n", class_name, name, units ? units : "none", registeredProgramName ? registeredProgramName : "?");
4853 break;
4854 default:
4855 fprintf(stderr, "Problem with call to SDDS_PrintCheckText--invalid error code (%s)\n", registeredProgramName ? registeredProgramName : "?");
4856 return (SDDS_CHECK_OKAY);
4857 }
4858 return (error_code);
4859}

◆ SDDS_PrintErrors()

epicsShareFuncSDDS void SDDS_PrintErrors ( FILE * fp,
int32_t mode )
extern

Prints recorded error messages to a specified file stream.

This function outputs the errors that have been recorded by SDDS library routines to the given file stream. Depending on the mode parameter, it can print a single error, all recorded errors, and optionally terminate the program after printing.

Parameters
[in]fpPointer to the FILE stream where errors will be printed. Typically stderr.
[in]modeFlags controlling the error printing behavior:
  • 0: Print only the first recorded error.
  • SDDS_VERBOSE_PrintErrors: Print all recorded errors.
  • SDDS_EXIT_PrintErrors: After printing errors, terminate the program by calling exit(1).
Note
After printing, the error stack is cleared. If mode includes SDDS_EXIT_PrintErrors, the program will terminate.
See also
SDDS_SetError
SDDS_NumberOfErrors
SDDS_ClearErrors

Definition at line 432 of file SDDS_utils.c.

432 {
433 int32_t i, depth;
434
435 if (!n_errors)
436 return;
437 if (!fp) {
438 n_errors = 0;
439 return;
440 }
441 if (mode & SDDS_VERBOSE_PrintErrors)
442 depth = n_errors;
443 else
444 depth = 1;
445 if (registeredProgramName)
446 fprintf(fp, "Error for %s:\n", registeredProgramName);
447 else
448 fputs("Error:\n", fp);
449 if (!error_description)
450 fprintf(stderr, "warning: internal error: error_description pointer is unexpectedly NULL\n");
451 else
452 for (i = 0; i < depth; i++) {
453 if (!error_description[i])
454 fprintf(stderr, "warning: internal error: error_description[%" PRId32 "] is unexpectedly NULL\n", i);
455 fprintf(fp, "%s", error_description[i]);
456 }
457 fflush(fp);
458 n_errors = 0;
459 if (mode & SDDS_EXIT_PrintErrors)
460 exit(1);
461}

◆ SDDS_PrintTypedValue()

epicsShareFuncSDDS int32_t SDDS_PrintTypedValue ( void * data,
int64_t index,
int32_t type,
char * format,
FILE * fp,
uint32_t mode )
extern

Prints a data value of a specified type using an optional printf format string.

This function prints a single data value from a data array based on the specified type and index. It supports various data types defined by SDDS constants and allows customization of the output format.

Parameters
[in]dataPointer to the base address of the data array to be printed.
[in]indexThe index of the item within the data array to be printed.
[in]typeThe data type of the value to be printed, specified by one of the SDDS constants:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
[in]format(Optional) NULL-terminated string specifying a printf format. If NULL, a default format is used based on the data type.
[in]fpPointer to the FILE stream where the data will be printed.
[in]modeFlags controlling the printing behavior. Valid values are:
  • 0: Default behavior.
  • SDDS_PRINT_NOQUOTES: When printing strings, do not enclose them in quotes.
Returns
Returns 1 on success. On failure, returns 0 and records an error message.
Note
This function assumes that the data pointer points to an array of the specified type, and index is within the bounds of this array.
See also
SDDS_SetError

Definition at line 59 of file SDDS_utils.c.

59 {
60 char buffer[SDDS_PRINT_BUFLEN], *s;
61
62 if (!data) {
63 SDDS_SetError("Unable to print value--data pointer is NULL (SDDS_PrintTypedValue)");
64 return (0);
65 }
66 if (!fp) {
67 SDDS_SetError("Unable to print value--file pointer is NULL (SDDS_PrintTypedValue)");
68 return (0);
69 }
70 switch (type) {
71 case SDDS_SHORT:
72 fprintf(fp, format ? format : "%hd", *((short *)data + index));
73 break;
74 case SDDS_USHORT:
75 fprintf(fp, format ? format : "%hu", *((unsigned short *)data + index));
76 break;
77 case SDDS_LONG:
78 fprintf(fp, format ? format : "%" PRId32, *((int32_t *)data + index));
79 break;
80 case SDDS_ULONG:
81 fprintf(fp, format ? format : "%" PRIu32, *((uint32_t *)data + index));
82 break;
83 case SDDS_LONG64:
84 fprintf(fp, format ? format : "%" PRId64, *((int64_t *)data + index));
85 break;
86 case SDDS_ULONG64:
87 fprintf(fp, format ? format : "%" PRIu64, *((uint64_t *)data + index));
88 break;
89 case SDDS_FLOAT:
90 fprintf(fp, format ? format : "%15.8e", *((float *)data + index));
91 break;
92 case SDDS_DOUBLE:
93 fprintf(fp, format ? format : "%21.15e", *((double *)data + index));
94 break;
95 case SDDS_LONGDOUBLE:
96 if (LDBL_DIG == 18) {
97 fprintf(fp, format ? format : "%21.18Le", *((long double *)data + index));
98 } else {
99 fprintf(fp, format ? format : "%21.15Le", *((long double *)data + index));
100 }
101 break;
102 case SDDS_STRING:
103 s = *((char **)data + index);
104 if ((int32_t)strlen(s) > SDDS_PRINT_BUFLEN - 3) {
105 SDDS_SetError("Buffer size overflow (SDDS_PrintTypedValue)");
106 return 0;
107 }
108 SDDS_SprintTypedValue(data, index, type, format, buffer, mode);
109 fputs(buffer, fp);
110 break;
111 case SDDS_CHARACTER:
112 fprintf(fp, format ? format : "%c", *((char *)data + index));
113 break;
114 default:
115 SDDS_SetError("Unable to print value--unknown data type (SDDS_PrintTypedValue)");
116 return (0);
117 }
118 return (1);
119}

◆ SDDS_ProcessArrayString()

epicsShareFuncSDDS int32_t SDDS_ProcessArrayString ( SDDS_DATASET * SDDS_dataset,
char * string )
extern

Process an array definition string.

This function parses a string containing array definition information and updates the SDDS dataset accordingly.

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

Definition at line 362 of file SDDS_process.c.

362 {
363 char *ptr1, *ptr2;
364 char *s;
365 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessArrayString"))
366 return (0);
367 if (!string)
368 return (0);
369 if (!SDDS_CopyString(&s, string))
370 return 0;
371 if (!(ptr1 = strchr(s, '&')) || !(ptr2 = strchr(ptr1, ' '))) {
372 free(s);
373 return 0;
374 }
375 *ptr2 = 0;
376 if (strcmp(ptr1, "&array") != 0) {
377 free(s);
378 return (0);
379 }
380 if (SDDS_ProcessArrayDefinition(SDDS_dataset, ptr2 + 1)) {
381 free(s);
382 if (!SDDS_SaveLayout(SDDS_dataset))
383 return (0);
384 return (1);
385 }
386 free(s);
387 return (0);
388}
int32_t SDDS_ProcessArrayDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the array definition section of the SDDS dataset.

◆ SDDS_ProcessAssociateString()

epicsShareFuncSDDS int32_t SDDS_ProcessAssociateString ( SDDS_DATASET * SDDS_dataset,
char * string )
extern

Process an associate definition string.

This function parses a string containing associate definition information and updates the SDDS dataset accordingly.

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

Definition at line 400 of file SDDS_process.c.

400 {
401 char *ptr1, *ptr2;
402 char *s;
403
404 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessAssociateString"))
405 return (0);
406 if (!string)
407 return (0);
408 if (!SDDS_CopyString(&s, string))
409 return 0;
410 if (!(ptr1 = strchr(s, '&')) || !(ptr2 = strchr(ptr1, ' '))) {
411 free(s);
412 return 0;
413 }
414 *ptr2 = 0;
415 if (strcmp(ptr1, "&associate") != 0) {
416 free(s);
417 return (0);
418 }
419 *ptr2 = ' ';
420 if (SDDS_ProcessAssociateDefinition(SDDS_dataset, ptr2 + 1)) {
421 free(s);
422 if (!SDDS_SaveLayout(SDDS_dataset))
423 return (0);
424 return (1);
425 }
426 free(s);
427 return (0);
428}
int32_t SDDS_ProcessAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the associate definition section of the SDDS dataset.

◆ SDDS_ProcessColumnString()

epicsShareFuncSDDS int32_t SDDS_ProcessColumnString ( SDDS_DATASET * SDDS_dataset,
char * string,
int32_t mode )
extern

Process a column definition string.

This function parses a string containing column definition information and updates the SDDS dataset accordingly.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
stringPointer to the column definition string.
modeMode indicating how the column is defined.
Returns
Returns 1 on success, 0 on failure.

Definition at line 283 of file SDDS_process.c.

283 {
284 char *ptr1, *ptr2;
285 char *s;
286 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessColumnString"))
287 return (0);
288 if (!string)
289 return (0);
290 if (!SDDS_CopyString(&s, string))
291 return 0;
292 if (!(ptr1 = strchr(s, '&')) || !(ptr2 = strchr(ptr1, ' '))) {
293 free(s);
294 return 0;
295 }
296 *ptr2 = 0;
297 if (strcmp(ptr1, "&column") != 0) {
298 free(s);
299 return (0);
300 }
301 if (SDDS_ProcessColumnDefinition(SDDS_dataset, ptr2 + 1)) {
302 free(s);
303 SDDS_dataset->layout.column_definition[SDDS_dataset->layout.n_columns - 1].definition_mode = mode;
304 if (!SDDS_SaveLayout(SDDS_dataset))
305 return (0);
306 return (1);
307 }
308 free(s);
309 return (0);
310}
int32_t SDDS_ProcessColumnDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the column definition section of the SDDS dataset.

◆ SDDS_ProcessParameterString()

epicsShareFuncSDDS int32_t SDDS_ProcessParameterString ( SDDS_DATASET * SDDS_dataset,
char * string,
int32_t mode )
extern

Process a parameter definition string.

This function parses a string containing parameter definition information and updates the SDDS dataset accordingly.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure.
stringPointer to the parameter definition string.
modeMode indicating how the parameter is defined.
Returns
Returns 1 on success, 0 on failure.

Definition at line 323 of file SDDS_process.c.

323 {
324 char *ptr1, *ptr2;
325 char *s;
326 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ProcessParameterString"))
327 return (0);
328 if (!string)
329 return (0);
330 if (!SDDS_CopyString(&s, string))
331 return 0;
332 if (!(ptr1 = strchr(s, '&')) || !(ptr2 = strchr(ptr1, ' '))) {
333 free(s);
334 return 0;
335 }
336 *ptr2 = 0;
337 if (strcmp(ptr1, "&parameter") != 0) {
338 free(s);
339 return (0);
340 }
341 if (SDDS_ProcessParameterDefinition(SDDS_dataset, ptr2 + 1)) {
342 free(s);
343 SDDS_dataset->layout.parameter_definition[SDDS_dataset->layout.n_parameters - 1].definition_mode = mode;
344 if (!SDDS_SaveLayout(SDDS_dataset))
345 return (0);
346 return (1);
347 }
348 free(s);
349 return (0);
350}
int32_t SDDS_ProcessParameterDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the parameter definition section of the SDDS dataset.

◆ SDDS_ReadAsciiPage()

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

Reads the next SDDS ASCII page into memory with optional data sparsity and statistics.

This function reads the next page of data from an ASCII SDDS file into the provided dataset. It supports reading data with specified sparsity (interval and offset) and can compute statistics such as average, median, minimum, or maximum over the sparse data.

Parameters
SDDS_datasetPointer to the SDDS dataset where the data will be stored.
sparse_intervalInterval for sparsity; read every nth row if greater than 1.
sparse_offsetOffset for sparsity; number of initial rows to skip.
sparse_statisticsStatistic to compute over the sparse data:
  • 0: None
  • 1: Average
  • 2: Median
  • 3: Minimum
  • 4: Maximum
Returns
Returns the page number on success, -1 if end-of-file is reached, or 0 on error.
Note
The function utilizes SDDS_ReadAsciiPageDetailed() to perform the actual reading.

Definition at line 1225 of file SDDS_ascii.c.

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

◆ SDDS_ReadLayout()

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

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

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

Definition at line 517 of file SDDS_input.c.

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

◆ SDDS_ReadNewBinaryRows()

epicsShareFuncSDDS int32_t SDDS_ReadNewBinaryRows ( SDDS_DATASET * SDDS_dataset)
extern

Reads new binary rows from the SDDS dataset.

This function updates the SDDS dataset by reading any new rows that have been added to the underlying file since the last read operation. It verifies that the dataset is in a compatible binary format and ensures that byte order and compression settings are supported. If the number of rows in the file exceeds the currently allocated rows in memory, the function expands the dataset's internal storage to accommodate the new rows.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
Returns
int32_t Returns the number of new rows successfully read on success, or -1 if an error occurred.
Return values
>0The number of new rows read and added to the dataset.
-1An error occurred during the read operation, such as unsupported file format, I/O errors, or memory allocation failures.
Note
This function does not support MPI parallel I/O, ASCII files, column-major order binary files, non-native byte orders, or compressed files (gzip or lzma). Attempts to use these features will result in an error.

Definition at line 2837 of file SDDS_binary.c.

2837 {
2838 int64_t row, offset, newRows = 0;
2839 int32_t rowsPresent32;
2840 int64_t rowsPresent;
2841
2842#if SDDS_MPI_IO
2843 if (SDDS_dataset->parallel_io) {
2844 SDDS_SetError("Error: MPI mode not supported yet in SDDS_ReadNewBinaryRows");
2845 return -1;
2846 }
2847#endif
2848 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
2849 SDDS_SetError("Error: ASCII files not supported in SDDS_ReadNewBinaryRows");
2850 return -1;
2851 }
2852 if (SDDS_dataset->layout.data_mode.column_major) {
2853 SDDS_SetError("Error: column-major order binary files not supported in SDDS_ReadNewBinaryRows");
2854 return -1;
2855 }
2856 if (SDDS_dataset->swapByteOrder) {
2857 SDDS_SetError("Error: Non-native endian not supported yet in SDDS_ReadNewBinaryRows");
2858 return -1;
2859 }
2860#if defined(zLib)
2861 if (SDDS_dataset->layout.gzipFile) {
2862 SDDS_SetError("Error: gzip compressed files not supported yet in SDDS_ReadNewBinaryRows");
2863 return -1;
2864 } else {
2865#endif
2866 if (SDDS_dataset->layout.lzmaFile) {
2867 SDDS_SetError("Error: lzma compressed files not supported yet in SDDS_ReadNewBinaryRows");
2868 return -1;
2869 }
2870#if defined(zLib)
2871 }
2872#endif
2873
2874 // Read how many rows we have now
2875 offset = ftell(SDDS_dataset->layout.fp);
2876 fseek(SDDS_dataset->layout.fp, SDDS_dataset->rowcount_offset, 0);
2877 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
2878 fread(&rowsPresent32, sizeof(rowsPresent32), 1, SDDS_dataset->layout.fp);
2879 if (SDDS_dataset->swapByteOrder) {
2880 SDDS_SwapLong(&rowsPresent32);
2881 }
2882 if (rowsPresent32 == INT32_MIN) {
2883 fread(&rowsPresent, sizeof(rowsPresent), 1, SDDS_dataset->layout.fp);
2884 if (SDDS_dataset->swapByteOrder) {
2885 SDDS_SwapLong64(&rowsPresent);
2886 }
2887 } else {
2888 rowsPresent = rowsPresent32;
2889 }
2890 } else {
2891 char buffer[30];
2892 if (!fgets(buffer, 30, SDDS_dataset->layout.fp) || strlen(buffer) != 21 || sscanf(buffer, "%" SCNd64, &rowsPresent) != 1) {
2893 SDDS_SetError("Error: row count not present or not correct length");
2894 return -1;
2895 }
2896 }
2897 fseek(SDDS_dataset->layout.fp, offset, 0);
2898
2899 // If the row count listed in the file is greather than the allocated rows, then lengthen the table in memory
2900 if (rowsPresent > SDDS_dataset->n_rows_allocated) {
2901 if (!SDDS_LengthenTable(SDDS_dataset, rowsPresent + 3)) {
2902 return -1;
2903 }
2904 }
2905
2906 for (row = SDDS_dataset->n_rows; row < rowsPresent; row++) {
2907 if (!SDDS_ReadBinaryRow(SDDS_dataset, row, 0)) {
2908 if (SDDS_dataset->autoRecover) {
2909 row--;
2910 SDDS_dataset->autoRecovered = 1;
2912 break;
2913 }
2914 SDDS_SetError("Unable to read page--error reading data row");
2915 return -1;
2916 }
2917 }
2918 newRows = row + 1 - SDDS_dataset->n_rows;
2919 SDDS_dataset->n_rows = row + 1;
2920 return newRows;
2921}
int32_t SDDS_ReadBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row, int32_t skip)
Reads a binary row from the specified SDDS dataset.
void SDDS_ClearErrors()
Clears all recorded error messages from the SDDS error stack.
Definition SDDS_utils.c:318

◆ SDDS_ReadNonNativeBinaryArrays()

int32_t SDDS_ReadNonNativeBinaryArrays ( SDDS_DATASET * SDDS_dataset)

Reads non-native endian binary arrays from an SDDS dataset.

This function iterates through all array definitions in the specified SDDS dataset and reads their binary data from the underlying file. It handles various data types, including short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, and long double. For string arrays, it reads each string individually, ensuring proper memory allocation and byte order conversion. The function supports different compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files. After reading, it swaps the endianness of the array data to match the system's native byte order.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
Returns
int32_t Returns 1 on successful reading and byte-swapping of all arrays, or 0 if an error occurred.
Return values
1All non-native endian arrays were successfully read and byte-swapped.
0An error occurred during the read or byte-swapping process, such as I/O failures, memory allocation issues, or corrupted array definitions.
Note
This function modifies the dataset's array data in place. It should be called after successfully opening and preparing the dataset for reading. Ensure that the dataset structure is properly initialized to prevent undefined behavior.

Definition at line 4576 of file SDDS_binary.c.

4576 {
4577 int32_t i, j;
4578 SDDS_LAYOUT *layout;
4579 /* char *predefined_format; */
4580 /* static char buffer[SDDS_MAXLINE]; */
4581#if defined(zLib)
4582 gzFile gzfp = NULL;
4583#endif
4584 FILE *fp = NULL;
4585 struct lzmafile *lzmafp = NULL;
4586 SDDS_ARRAY *array;
4587 SDDS_FILEBUFFER *fBuffer;
4588
4589 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativeBinaryArrays"))
4590 return (0);
4591 layout = &SDDS_dataset->layout;
4592 if (!layout->n_arrays)
4593 return (1);
4594#if defined(zLib)
4595 if (SDDS_dataset->layout.gzipFile) {
4596 gzfp = layout->gzfp;
4597 } else {
4598#endif
4599 if (SDDS_dataset->layout.lzmaFile) {
4600 lzmafp = layout->lzmafp;
4601 } else {
4602 fp = layout->fp;
4603 }
4604#if defined(zLib)
4605 }
4606#endif
4607 fBuffer = &SDDS_dataset->fBuffer;
4608 if (!SDDS_dataset->array) {
4609 SDDS_SetError("Unable to read array--pointer to structure storage area is NULL (SDDS_ReadNonNativeBinaryArrays)");
4610 return (0);
4611 }
4612 for (i = 0; i < layout->n_arrays; i++) {
4613 array = SDDS_dataset->array + i;
4614 if (array->definition && !SDDS_FreeArrayDefinition(array->definition)) {
4615 SDDS_SetError("Unable to get array--array definition corrupted (SDDS_ReadNonNativeBinaryArrays)");
4616 return (0);
4617 }
4618 if (!SDDS_CopyArrayDefinition(&array->definition, layout->array_definition + i)) {
4619 SDDS_SetError("Unable to read array--definition copy failed (SDDS_ReadNonNativeBinaryArrays)");
4620 return (0);
4621 }
4622 /*if (array->dimension) free(array->dimension); */
4623 if (!(array->dimension = SDDS_Realloc(array->dimension, sizeof(*array->dimension) * array->definition->dimensions))) {
4624 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadNonNativeBinaryArrays)");
4625 return (0);
4626 }
4627#if defined(zLib)
4628 if (SDDS_dataset->layout.gzipFile) {
4629 if (!SDDS_GZipBufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, gzfp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4630 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4631 return (0);
4632 }
4633 } else {
4634#endif
4635 if (SDDS_dataset->layout.lzmaFile) {
4636 if (!SDDS_LZMABufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, lzmafp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4637 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4638 return (0);
4639 }
4640 } else {
4641 if (!SDDS_BufferedRead(array->dimension, sizeof(*array->dimension) * array->definition->dimensions, fp, fBuffer, SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4642 SDDS_SetError("Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4643 return (0);
4644 }
4645 }
4646#if defined(zLib)
4647 }
4648#endif
4649 array->elements = 1;
4650 for (j = 0; j < array->definition->dimensions; j++) {
4651 SDDS_SwapLong(&(array->dimension[j]));
4652 array->elements *= array->dimension[j];
4653 }
4654 if (array->data)
4655 free(array->data);
4656 array->data = array->pointer = NULL;
4657 if (array->elements == 0)
4658 continue;
4659 if (array->elements < 0) {
4660 SDDS_SetError("Unable to read array--number of elements is negative (SDDS_ReadNonNativeBinaryArrays)");
4661 return (0);
4662 }
4663 if (!(array->data = SDDS_Realloc(array->data, array->elements * SDDS_type_size[array->definition->type - 1]))) {
4664 SDDS_SetError("Unable to read array--allocation failure (SDDS_ReadNonNativeBinaryArrays)");
4665 return (0);
4666 }
4667 if (array->definition->type == SDDS_STRING) {
4668#if defined(zLib)
4669 if (SDDS_dataset->layout.gzipFile) {
4670 for (j = 0; j < array->elements; j++) {
4671 if (!(((char **)(array->data))[j] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4672 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4673 return (0);
4674 }
4675 }
4676 } else {
4677#endif
4678 if (SDDS_dataset->layout.lzmaFile) {
4679 for (j = 0; j < array->elements; j++) {
4680 if (!(((char **)(array->data))[j] = SDDS_ReadNonNativeLZMABinaryString(lzmafp, fBuffer, 0))) {
4681 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4682 return (0);
4683 }
4684 }
4685 } else {
4686 for (j = 0; j < array->elements; j++) {
4687 if (!(((char **)(array->data))[j] = SDDS_ReadNonNativeBinaryString(fp, fBuffer, 0))) {
4688 SDDS_SetError("Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4689 return (0);
4690 }
4691 }
4692 }
4693#if defined(zLib)
4694 }
4695#endif
4696 } else {
4697#if defined(zLib)
4698 if (SDDS_dataset->layout.gzipFile) {
4699 if (!SDDS_GZipBufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, gzfp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4700 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4701 return (0);
4702 }
4703 } else {
4704#endif
4705 if (SDDS_dataset->layout.lzmaFile) {
4706 if (!SDDS_LZMABufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, lzmafp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4707 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4708 return (0);
4709 }
4710 } else {
4711 if (!SDDS_BufferedRead(array->data, SDDS_type_size[array->definition->type - 1] * array->elements, fp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4712 SDDS_SetError("Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4713 return (0);
4714 }
4715 }
4716#if defined(zLib)
4717 }
4718#endif
4719 }
4720 }
4721 SDDS_SwapEndsArrayData(SDDS_dataset);
4722 return (1);
4723}
char * SDDS_ReadNonNativeLZMABinaryString(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a non-native endian binary string from an LZMA-compressed file.
int32_t SDDS_LZMABufferedRead(void *target, int64_t targetSize, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder)
int32_t SDDS_BufferedRead(void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder)
Definition SDDS_binary.c:96
int32_t SDDS_SwapEndsArrayData(SDDS_DATASET *SDDSin)
Swaps the endianness of the array data in an SDDS dataset.
char * SDDS_ReadNonNativeBinaryString(FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a non-native endian binary string from a file.

◆ SDDS_ReadNonNativeBinaryPage()

int32_t SDDS_ReadNonNativeBinaryPage ( SDDS_DATASET * SDDS_dataset,
int64_t sparse_interval,
int64_t sparse_offset )

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

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

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]sparse_intervalInterval between rows to be read for sparsity.
[in]sparse_offsetOffset to start reading rows for sparsity.
Returns
int32_t Returns the number of rows read on success, or 0 on failure.
Return values
>0Number of rows successfully read.
0An error occurred during the read operation, such as I/O failures, data corruption, or unsupported data modes.
Note
This function is a wrapper for SDDS_ReadNonNativeBinaryPageDetailed with specific parameters.

Definition at line 4181 of file SDDS_binary.c.

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

◆ SDDS_ReadNonNativeBinaryParameters()

int32_t SDDS_ReadNonNativeBinaryParameters ( SDDS_DATASET * SDDS_dataset)

Reads non-native endian binary parameters from an SDDS dataset.

This function iterates through all parameter definitions in the specified SDDS dataset and reads their binary data from the underlying file. It handles various data types, including short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, and long double. For string parameters, it reads each string individually, ensuring proper memory allocation and byte order conversion. Parameters with fixed values are processed by scanning the fixed value strings into the appropriate data types. The function supports different compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
Returns
int32_t Returns 1 on successful reading and byte-swapping of all parameters, or 0 if an error occurred.
Return values
1All non-native endian parameters were successfully read and byte-swapped.
0An error occurred during the read or byte-swapping process, such as I/O failures, memory allocation issues, or corrupted parameter definitions.
Note
This function modifies the dataset's parameter data in place. It should be called after successfully opening and preparing the dataset for reading. Ensure that the dataset structure is properly initialized to prevent undefined behavior.

Definition at line 4460 of file SDDS_binary.c.

4460 {
4461 int32_t i;
4462 SDDS_LAYOUT *layout;
4463 /* char *predefined_format; */
4464 char buffer[SDDS_MAXLINE];
4465#if defined(zLib)
4466 gzFile gzfp = NULL;
4467#endif
4468 FILE *fp = NULL;
4469 struct lzmafile *lzmafp = NULL;
4470 SDDS_FILEBUFFER *fBuffer;
4471
4472 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativeBinaryParameters"))
4473 return (0);
4474 layout = &SDDS_dataset->layout;
4475 if (!layout->n_parameters)
4476 return (1);
4477#if defined(zLib)
4478 if (SDDS_dataset->layout.gzipFile) {
4479 gzfp = layout->gzfp;
4480 } else {
4481#endif
4482 if (SDDS_dataset->layout.lzmaFile) {
4483 lzmafp = layout->lzmafp;
4484 } else {
4485 fp = layout->fp;
4486 }
4487#if defined(zLib)
4488 }
4489#endif
4490 fBuffer = &SDDS_dataset->fBuffer;
4491 for (i = 0; i < layout->n_parameters; i++) {
4492 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4493 continue;
4494 if (layout->parameter_definition[i].fixed_value) {
4495 strcpy(buffer, layout->parameter_definition[i].fixed_value);
4496 if (!SDDS_ScanData(buffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
4497 SDDS_SetError("Unable to read page--parameter scanning error (SDDS_ReadNonNativeBinaryParameters)");
4498 return (0);
4499 }
4500 } else if (layout->parameter_definition[i].type == SDDS_STRING) {
4501 if (*(char **)SDDS_dataset->parameter[i])
4502 free(*(char **)SDDS_dataset->parameter[i]);
4503#if defined(zLib)
4504 if (SDDS_dataset->layout.gzipFile) {
4505 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4506 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4507 return (0);
4508 }
4509 } else {
4510#endif
4511 if (SDDS_dataset->layout.lzmaFile) {
4512 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadNonNativeLZMABinaryString(lzmafp, fBuffer, 0))) {
4513 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4514 return (0);
4515 }
4516 } else {
4517 if (!(*((char **)SDDS_dataset->parameter[i]) = SDDS_ReadNonNativeBinaryString(fp, fBuffer, 0))) {
4518 SDDS_SetError("Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4519 return (0);
4520 }
4521 }
4522#if defined(zLib)
4523 }
4524#endif
4525 } else {
4526#if defined(zLib)
4527 if (SDDS_dataset->layout.gzipFile) {
4528 if (!SDDS_GZipBufferedRead(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
4529 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4530 return (0);
4531 }
4532 } else {
4533#endif
4534 if (SDDS_dataset->layout.lzmaFile) {
4535 if (!SDDS_LZMABufferedRead(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], lzmafp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
4536 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4537 return (0);
4538 }
4539 } else {
4540 if (!SDDS_BufferedRead(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], fp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
4541 SDDS_SetError("Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4542 return (0);
4543 }
4544 }
4545#if defined(zLib)
4546 }
4547#endif
4548 }
4549 }
4550 SDDS_SwapEndsParameterData(SDDS_dataset);
4551 return (1);
4552}
int32_t SDDS_SwapEndsParameterData(SDDS_DATASET *SDDSin)
Swaps the endianness of the parameter data in an SDDS dataset.

◆ SDDS_ReadNonNativeBinaryRow()

int32_t SDDS_ReadNonNativeBinaryRow ( SDDS_DATASET * SDDS_dataset,
int64_t row,
int32_t skip )

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

This function reads a single row of data from the specified SDDS dataset, handling data with non-native endianness. It iterates through all column definitions and reads each column's data for the given row. For string columns, it ensures proper memory allocation and byte order conversion. For other data types, it reads the binary data and performs necessary byte swapping. The function supports different compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]rowThe index of the row to read.
[in]skipIf non-zero, the function will skip reading the row data, useful for sparse reading.
Returns
int32_t Returns 1 on successful reading of the row, or 0 if an error occurred.
Return values
1The row was successfully read and byte-swapped.
0An error occurred during the read or byte-swapping process, such as I/O failures or corrupted data.
Note
This function modifies the dataset's data in place. It should be called after successfully opening and preparing the dataset for reading. Ensure that the dataset structure is properly initialized to prevent undefined behavior.

Definition at line 4746 of file SDDS_binary.c.

4746 {
4747 int64_t i, type, size;
4748 SDDS_LAYOUT *layout;
4749#if defined(zLib)
4750 gzFile gzfp;
4751#endif
4752 FILE *fp;
4753 struct lzmafile *lzmafp;
4754 SDDS_FILEBUFFER *fBuffer;
4755
4756 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadNonNativeBinaryRow"))
4757 return (0);
4758 layout = &SDDS_dataset->layout;
4759 fBuffer = &SDDS_dataset->fBuffer;
4760
4761#if defined(zLib)
4762 if (SDDS_dataset->layout.gzipFile) {
4763 gzfp = layout->gzfp;
4764 for (i = 0; i < layout->n_columns; i++) {
4765 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4766 continue;
4767 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
4768 if (!skip) {
4769 if (((char ***)SDDS_dataset->data)[i][row])
4770 free((((char ***)SDDS_dataset->data)[i][row]));
4771 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4772 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4773 return (0);
4774 }
4775 } else {
4776 if (!SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 1)) {
4777 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4778 return 0;
4779 }
4780 }
4781 } else {
4782 size = SDDS_type_size[type - 1];
4783 if (!SDDS_GZipBufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4784 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4785 return (0);
4786 }
4787 }
4788 }
4789 } else {
4790#endif
4791 if (SDDS_dataset->layout.lzmaFile) {
4792 lzmafp = layout->lzmafp;
4793 for (i = 0; i < layout->n_columns; i++) {
4794 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4795 continue;
4796 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
4797 if (!skip) {
4798 if (((char ***)SDDS_dataset->data)[i][row])
4799 free((((char ***)SDDS_dataset->data)[i][row]));
4800 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeLZMABinaryString(lzmafp, fBuffer, 0))) {
4801 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4802 return (0);
4803 }
4804 } else {
4805 if (!SDDS_ReadNonNativeLZMABinaryString(lzmafp, fBuffer, 1)) {
4806 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4807 return 0;
4808 }
4809 }
4810 } else {
4811 size = SDDS_type_size[type - 1];
4812 if (!SDDS_LZMABufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4813 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4814 return (0);
4815 }
4816 }
4817 }
4818 } else {
4819 fp = layout->fp;
4820 for (i = 0; i < layout->n_columns; i++) {
4821 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4822 continue;
4823 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
4824 if (!skip) {
4825 if (((char ***)SDDS_dataset->data)[i][row])
4826 free((((char ***)SDDS_dataset->data)[i][row]));
4827 if (!(((char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeBinaryString(fp, fBuffer, 0))) {
4828 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4829 return (0);
4830 }
4831 } else {
4832 if (!SDDS_ReadNonNativeBinaryString(fp, fBuffer, 1)) {
4833 SDDS_SetError("Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4834 return 0;
4835 }
4836 }
4837 } else {
4838 size = SDDS_type_size[type - 1];
4839 if (!SDDS_BufferedRead(skip ? NULL : (char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4840 SDDS_SetError("Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4841 return (0);
4842 }
4843 }
4844 }
4845 }
4846#if defined(zLib)
4847 }
4848#endif
4849 return (1);
4850}

◆ SDDS_ReadNonNativeBinaryString()

char * SDDS_ReadNonNativeBinaryString ( FILE * fp,
SDDS_FILEBUFFER * fBuffer,
int32_t skip )

Reads a non-native endian binary string from a file.

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

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

Definition at line 4869 of file SDDS_binary.c.

4869 {
4870 int32_t length;
4871 char *string;
4872
4873 if (!SDDS_BufferedRead(&length, sizeof(length), fp, fBuffer, SDDS_LONG, 0))
4874 return (0);
4875 SDDS_SwapLong(&length);
4876 if (length < 0)
4877 return (0);
4878 if (!(string = SDDS_Malloc(sizeof(*string) * (length + 1))))
4879 return (NULL);
4880 if (length && !SDDS_BufferedRead(skip ? NULL : string, sizeof(*string) * length, fp, fBuffer, SDDS_STRING, 0))
4881 return (NULL);
4882 string[length] = 0;
4883 return (string);
4884}

◆ SDDS_ReadNonNativePage()

epicsShareFuncSDDS int32_t SDDS_ReadNonNativePage ( SDDS_DATASET * SDDS_dataset)
extern

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

This function reads a page of data from the specified SDDS dataset, handling data with non-native endianness. It supports both ASCII and binary data modes, performing necessary byte order conversions to ensure correct data interpretation on the host system.

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

Definition at line 4002 of file SDDS_binary.c.

4002 {
4003 return SDDS_ReadNonNativePageDetailed(SDDS_dataset, 0, 1, 0, 0);
4004}
int32_t SDDS_ReadNonNativePageDetailed(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows)
Reads a detailed non-native endian page from an SDDS dataset.

◆ SDDS_ReadNonNativePageSparse()

int32_t SDDS_ReadNonNativePageSparse ( SDDS_DATASET * SDDS_dataset,
uint32_t mode,
int64_t sparse_interval,
int64_t sparse_offset )

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

This function reads a sparse page of data from the specified SDDS dataset, handling data with non-native endianness. Sparse reading allows for selective row retrieval based on the provided interval and offset.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to read from.
[in]modeMode flag to support future expansion.
[in]sparse_intervalInterval between rows to be read for sparsity.
[in]sparse_offsetOffset to start reading rows for sparsity.
Returns
int32_t Returns the number of rows read on success, or 0 on failure.
Return values
>0Number of rows successfully read.
0An error occurred during the read operation, such as I/O failures, data corruption, or unsupported data modes.
Note
This function is a wrapper for SDDS_ReadNonNativePageDetailed with specific parameters to enable sparse reading. It should be used when selective row retrieval is desired.

Definition at line 4024 of file SDDS_binary.c.

4024 {
4025 return SDDS_ReadNonNativePageDetailed(SDDS_dataset, mode, sparse_interval, sparse_offset, 0);
4026}

◆ SDDS_ReadPage()

epicsShareFuncSDDS int32_t SDDS_ReadPage ( SDDS_DATASET * SDDS_dataset)
extern

Reads a page of an SDDS file. Usually called after SDDS_InitializeInput.

Parameters
SDDS_datasetAddress of the SDDS_DATASET structure for the data set.
Returns
Page number on success, -1 if it is the end-of-file, 0 on error.

Definition at line 1006 of file SDDS_input.c.

1006 {
1007#if SDDS_MPI_IO
1008 if (SDDS_dataset->parallel_io)
1009 return SDDS_MPI_ReadPage(SDDS_dataset);
1010#endif
1011 return SDDS_ReadPageSparse(SDDS_dataset, 0, 1, 0, 0);
1012}
int32_t SDDS_MPI_ReadPage(SDDS_DATASET *SDDS_dataset)
Reads a page from an SDDS dataset using MPI.

◆ SDDS_ReadPageLastRows()

epicsShareFuncSDDS int32_t SDDS_ReadPageLastRows ( SDDS_DATASET * SDDS_dataset,
int64_t last_rows )
extern

Reads the last specified number of rows from the SDDS dataset.

Parameters
SDDS_datasetThe pointer to the SDDS dataset structure.
last_rowsThe number of rows to read from the end of the dataset.
Returns
Page number on success, -1 if it is the end-of-file, 0 on error.

Definition at line 1156 of file SDDS_input.c.

1156 {
1157 int32_t retval;
1158
1159 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadPageLastRows"))
1160 return (0);
1161 if (SDDS_dataset->layout.disconnected) {
1162 SDDS_SetError("Can't read page--file is disconnected (SDDS_ReadPageLastRows)");
1163 return 0;
1164 }
1165#if defined(zLib)
1166 if (SDDS_dataset->layout.gzipFile) {
1167 if (!SDDS_dataset->layout.gzfp) {
1168 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadPageLastRows)");
1169 return (0);
1170 }
1171 } else {
1172#endif
1173 if (SDDS_dataset->layout.lzmaFile) {
1174 if (!SDDS_dataset->layout.lzmafp) {
1175 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadPageLastRows)");
1176 return (0);
1177 }
1178 } else {
1179 if (!SDDS_dataset->layout.fp) {
1180 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadPageLastRows)");
1181 return (0);
1182 }
1183 }
1184#if defined(zLib)
1185 }
1186#endif
1187 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
1188 if ((retval = SDDS_ReadAsciiPageLastRows(SDDS_dataset, last_rows)) < 1) {
1189 return (retval);
1190 }
1191 } else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
1192 if ((retval = SDDS_ReadBinaryPageLastRows(SDDS_dataset, last_rows)) < 1) {
1193 return (retval);
1194 }
1195 } else {
1196 SDDS_SetError("Unable to read page--unrecognized data mode (SDDS_ReadPageLastRows)");
1197 return (0);
1198 }
1199 if (!SDDS_dataset->layout.gzipFile && !SDDS_dataset->layout.lzmaFile && !SDDS_dataset->layout.popenUsed && SDDS_dataset->layout.filename && SDDS_dataset->pagecount_offset) {
1200 /* Data is not:
1201 1. from a gzip file
1202 2. from a file that is being internally decompressed by a command executed with popen()
1203 3. from a pipe set up externally (e.g., -pipe=in on commandline)
1204 and pagecount_offset has been allocate memory from SDDS_initializeInput()
1205 */
1206 if (SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] < SDDS_dataset->endOfFile_offset) {
1207 SDDS_dataset->pages_read++;
1208 if (!(SDDS_dataset->pagecount_offset = realloc(SDDS_dataset->pagecount_offset, sizeof(int64_t) * (SDDS_dataset->pages_read + 1)))) {
1209 SDDS_SetError("Unable to allocate memory for pagecount_offset (SDDS_ReadPageLastRows)");
1210 exit(1);
1211 }
1212 SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] = ftell(SDDS_dataset->layout.fp);
1213 }
1214 } else {
1215 SDDS_dataset->pages_read++;
1216 }
1217 return (retval);
1218}
int32_t SDDS_ReadAsciiPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last specified number of rows from an ASCII page of an SDDS dataset.
int32_t SDDS_ReadBinaryPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last specified number of rows from a binary page of an SDDS dataset.

◆ SDDS_ReadPageSparse()

epicsShareFuncSDDS int32_t SDDS_ReadPageSparse ( SDDS_DATASET * SDDS_dataset,
uint32_t mode,
int64_t sparse_interval,
int64_t sparse_offset,
int32_t sparse_statistics )
extern

Reads a sparsed page of an SDDS file. Usually called after SDDS_InitializeInput.

Parameters
SDDS_datasetA pointer to an SDDS dataset.
modeNot used.
sparse_intervalThe column data can be sparsified over row intervals if this is greater than 1.
sparse_offsetThis is used to skip the initial rows of the column data.
sparse_statisticsNot used.
Returns
Page number on success, -1 if it is the end-of-file, 0 on error.

Definition at line 1082 of file SDDS_input.c.

1084{
1085 int32_t retval;
1086 /* SDDS_LAYOUT layout_copy; */
1087
1088 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ReadPageSparse"))
1089 return (0);
1090 if (SDDS_dataset->layout.disconnected) {
1091 SDDS_SetError("Can't read page--file is disconnected (SDDS_ReadPageSparse)");
1092 return 0;
1093 }
1094#if defined(zLib)
1095 if (SDDS_dataset->layout.gzipFile) {
1096 if (!SDDS_dataset->layout.gzfp) {
1097 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadPageSparse)");
1098 return (0);
1099 }
1100 } else {
1101#endif
1102 if (SDDS_dataset->layout.lzmaFile) {
1103 if (!SDDS_dataset->layout.lzmafp) {
1104 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadPageSparse)");
1105 return (0);
1106 }
1107 } else {
1108 if (!SDDS_dataset->layout.fp) {
1109 SDDS_SetError("Unable to read page--NULL file pointer (SDDS_ReadPageSparse)");
1110 return (0);
1111 }
1112 }
1113#if defined(zLib)
1114 }
1115#endif
1116 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
1117 if ((retval = SDDS_ReadAsciiPage(SDDS_dataset, sparse_interval, sparse_offset, sparse_statistics)) < 1) {
1118 return (retval);
1119 }
1120 } else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
1121 if ((retval = SDDS_ReadBinaryPage(SDDS_dataset, sparse_interval, sparse_offset, sparse_statistics)) < 1) {
1122 return (retval);
1123 }
1124 } else {
1125 SDDS_SetError("Unable to read page--unrecognized data mode (SDDS_ReadPageSparse)");
1126 return (0);
1127 }
1128 if (!SDDS_dataset->layout.gzipFile && !SDDS_dataset->layout.lzmaFile && !SDDS_dataset->layout.popenUsed && SDDS_dataset->layout.filename && SDDS_dataset->pagecount_offset) {
1129 /* Data is not:
1130 1. from a gzip file
1131 2. from a file that is being internally decompressed by a command executed with popen()
1132 3. from a pipe set up externally (e.g., -pipe=in on commandline)
1133 and pagecount_offset has been allocate memory from SDDS_initializeInput()
1134 */
1135 if (SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] < SDDS_dataset->endOfFile_offset) {
1136 SDDS_dataset->pages_read++;
1137 if (!(SDDS_dataset->pagecount_offset = realloc(SDDS_dataset->pagecount_offset, sizeof(int64_t) * (SDDS_dataset->pages_read + 1)))) {
1138 SDDS_SetError("Unable to allocate memory for pagecount_offset (SDDS_ReadPageSparse)");
1139 exit(1);
1140 }
1141 SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] = ftell(SDDS_dataset->layout.fp);
1142 }
1143 } else {
1144 SDDS_dataset->pages_read++;
1145 }
1146 return (retval);
1147}
int32_t SDDS_ReadAsciiPage(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
Reads the next SDDS ASCII page into memory with optional data sparsity and statistics.
int32_t SDDS_ReadBinaryPage(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
Reads a binary page from an SDDS dataset.

◆ SDDS_ReadRecoveryPossible()

epicsShareFuncSDDS int32_t SDDS_ReadRecoveryPossible ( SDDS_DATASET * SDDS_dataset)
extern

Checks if any data in an SDDS page was recovered after an error was detected.

This function inspects the SDDS dataset to determine if any data recovery was possible following an error during data reading. It resets the recovery flag after checking.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
Returns
  • Returns 1 if recovery was possible.
  • Returns 0 if no recovery was performed or if recovery was not possible.

The function performs the following steps:

  • Retrieves the current state of the readRecoveryPossible flag from the dataset.
  • Resets the readRecoveryPossible flag to 0.
  • Returns the original state of the readRecoveryPossible flag.
Note
  • This function is typically used after attempting to recover from a read error to verify if any partial data was successfully recovered.
  • The recovery flag is automatically managed by other functions within the SDDS library.

Definition at line 2054 of file SDDS_binary.c.

2054 {
2055 int32_t returnValue;
2056
2057 returnValue = SDDS_dataset->readRecoveryPossible;
2058 SDDS_dataset->readRecoveryPossible = 0;
2059 return returnValue;
2060}

◆ SDDS_Realloc()

epicsShareFuncSDDS void * SDDS_Realloc ( void * old_ptr,
size_t new_size )
extern

Reallocates memory to a new size.

This function extends the standard realloc functionality by zero-initializing any newly allocated memory beyond the original size. It ensures that memory is consistently reallocated and initialized across different build configurations.

Parameters
[in]old_ptrPointer to the original memory block. If NULL, the function behaves like SDDS_Malloc.
[in]new_sizeNew size in bytes for the memory block.
Returns
Pointer to the reallocated memory block with the new size. If new_size is less than or equal to zero, a minimum of 4 bytes is allocated. Returns NULL if memory reallocation fails.
See also
SDDS_Malloc
SDDS_Free

Definition at line 677 of file SDDS_utils.c.

677 {
678 /* this is required because some realloc's don't behave properly when asked to return a
679 * pointer to 0 memory. They return NULL.
680 */
681 if (new_size <= 0)
682 new_size = 4;
683 /* this is required because some realloc's don't behave properly when given a NULL pointer */
684 if (!old_ptr)
685 return (SDDS_Malloc(new_size));
686 else
687 return (realloc(old_ptr, new_size));
688}

◆ SDDS_ReconnectFile()

epicsShareFuncSDDS int32_t SDDS_ReconnectFile ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS int32_t SDDS_ReconnectInputFile ( SDDS_DATASET * SDDS_dataset,
long position )
extern

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

epicsShareFuncSDDS void SDDS_RegisterProgramName ( const char * name)
extern

Registers the executable program name for use in error messages.

This function stores the name of the executing program, which is included in various error and warning messages generated by the SDDS library routines.

Parameters
[in]nameThe name of the program. If NULL, the registered program name is cleared.
Note
This function should be called at the beginning of the program to provide context in error messages.
See also
SDDS_Bomb
SDDS_Warning

Definition at line 288 of file SDDS_utils.c.

288 {
289 if (name)
290 SDDS_CopyString(&registeredProgramName, (char *)name);
291 else
292 registeredProgramName = NULL;
293}

◆ SDDS_RemovePadding()

epicsShareFuncSDDS void SDDS_RemovePadding ( char * s)
extern

Removes leading and trailing whitespace from a string.

This function trims all leading and trailing whitespace characters from the input string s. It modifies the string in place, ensuring that any padding spaces are removed while preserving the internal content.

Parameters
[in,out]sPointer to the null-terminated string to be trimmed. The string will be modified in place.
Note
The function handles all standard whitespace characters as defined by the isspace function. If the string consists entirely of whitespace, the function will result in an empty string.
See also
isspace

Definition at line 2379 of file SDDS_utils.c.

2379 {
2380 char *ptr;
2381 ptr = s;
2382 while (isspace(*ptr))
2383 ptr++;
2384 if (ptr != s)
2385 strcpy(s, ptr);
2386 ptr = s + strlen(s) - 1;
2387 while (isspace(*ptr))
2388 *ptr-- = 0;
2389}

◆ SDDS_RestoreLayout()

epicsShareFuncSDDS int32_t SDDS_RestoreLayout ( SDDS_DATASET * SDDS_dataset)
extern

Restores a previously saved layout of the SDDS_DATASET.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure whose layout is to be restored.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 697 of file SDDS_copy.c.

697 {
698 SDDS_LAYOUT *source, *target;
699
700 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_RestoreLayout"))
701 return (0);
702
703 source = &SDDS_dataset->original_layout;
704 target = &SDDS_dataset->layout;
705
706 /* copy pointer elements of structure into new memory */
707 if (source->n_columns) {
708 if (target->column_definition == source->column_definition) {
709 SDDS_SetError("Unable to restore layout--column definition pointers are the same (SDDS_RestoreLayout)");
710 return (0);
711 }
712 if (!(target->column_definition = (COLUMN_DEFINITION *)SDDS_Realloc((void *)target->column_definition, sizeof(COLUMN_DEFINITION) * source->n_columns))) {
713 SDDS_SetError("Unable to restore layout--allocation failure (SDDS_RestoreLayout)");
714 return (0);
715 }
716 memcpy((char *)target->column_definition, (char *)source->column_definition, sizeof(COLUMN_DEFINITION) * source->n_columns);
717 }
718 if (source->n_parameters) {
719 if (target->parameter_definition == source->parameter_definition) {
720 SDDS_SetError("Unable to restore layout--parameter definition pointers are the same (SDDS_RestoreLayout)");
721 return (0);
722 }
723 if (!(target->parameter_definition = (PARAMETER_DEFINITION *)SDDS_Realloc((void *)target->parameter_definition, sizeof(PARAMETER_DEFINITION) * source->n_parameters))) {
724 SDDS_SetError("Unable to restore layout--allocation failure (SDDS_RestoreLayout)");
725 return (0);
726 }
727 memcpy((char *)target->parameter_definition, (char *)source->parameter_definition, sizeof(PARAMETER_DEFINITION) * source->n_parameters);
728 }
729 if (source->n_arrays) {
730 if (target->array_definition == source->array_definition) {
731 SDDS_SetError("Unable to restore layout--array definition pointers are the same (SDDS_RestoreLayout)");
732 return (0);
733 }
734 if (!(target->array_definition = (ARRAY_DEFINITION *)SDDS_Realloc((void *)target->array_definition, sizeof(ARRAY_DEFINITION) * source->n_arrays))) {
735 SDDS_SetError("Unable to restore layout--allocation failure (SDDS_RestoreLayout)");
736 return (0);
737 }
738 memcpy((char *)target->array_definition, (char *)source->array_definition, sizeof(ARRAY_DEFINITION) * source->n_arrays);
739 }
740 if (source->n_associates) {
741 if (target->associate_definition == source->associate_definition) {
742 SDDS_SetError("Unable to restore layout--associate definition pointers are the same (SDDS_RestoreLayout)");
743 return (0);
744 }
745 if (!(target->associate_definition = (ASSOCIATE_DEFINITION *)SDDS_Realloc((void *)target->associate_definition, sizeof(ASSOCIATE_DEFINITION) * source->n_associates))) {
746 SDDS_SetError("Unable to restore layout--allocation failure (SDDS_RestoreLayout)");
747 return (0);
748 }
749 memcpy((char *)target->associate_definition, (char *)source->associate_definition, sizeof(ASSOCIATE_DEFINITION) * source->n_associates);
750 }
751
752 target->n_columns = source->n_columns;
753 target->n_parameters = source->n_parameters;
754 target->n_associates = source->n_associates;
755 target->n_arrays = source->n_arrays;
756 target->description = source->description;
757 target->contents = source->contents;
758 target->version = source->version;
759 target->data_mode = source->data_mode;
760 target->filename = source->filename;
761 target->fp = source->fp;
762
763 return (1);
764}

◆ SDDS_SaveLayout()

epicsShareFuncSDDS int32_t SDDS_SaveLayout ( SDDS_DATASET * SDDS_dataset)
extern

Saves the current layout of the SDDS_DATASET. The layout is stored internally for future restoration if needed.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure whose layout is to be saved.
Returns
Returns 1 on success; 0 on failure, with an error message recorded.

Definition at line 615 of file SDDS_copy.c.

615 {
616 SDDS_LAYOUT *source, *target;
617
618 if (SDDS_dataset->deferSavingLayout)
619 return 1;
620
621 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SaveLayout"))
622 return (0);
623
624 if ((source = &SDDS_dataset->layout) == (target = &SDDS_dataset->original_layout)) {
625 SDDS_SetError("\"original\" and working page layouts share memory!");
626 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
627 }
628
629 /* copy pointer elements of structure into new memory */
630 if (source->n_columns) {
631 if (!(target->column_definition = (COLUMN_DEFINITION *)SDDS_Realloc((void *)target->column_definition, sizeof(COLUMN_DEFINITION) * source->n_columns)) || !(target->column_index = (SORTED_INDEX **)SDDS_Realloc((void *)target->column_index, sizeof(SORTED_INDEX *) * source->n_columns))) {
632 SDDS_SetError("Unable to save layout--allocation failure (SDDS_SaveLayout)");
633 return (0);
634 }
635 memcpy((char *)target->column_definition, (char *)source->column_definition, sizeof(COLUMN_DEFINITION) * source->n_columns);
636 memcpy((char *)target->column_index, (char *)source->column_index, sizeof(SORTED_INDEX *) * source->n_columns);
637 }
638 if (source->n_parameters) {
639 if (!(target->parameter_definition =
640 (PARAMETER_DEFINITION *)SDDS_Realloc((void *)target->parameter_definition, sizeof(PARAMETER_DEFINITION) * source->n_parameters)) ||
641 !(target->parameter_index = (SORTED_INDEX **)SDDS_Realloc((void *)target->parameter_index, sizeof(SORTED_INDEX *) * source->n_parameters))) {
642 SDDS_SetError("Unable to save layout--allocation failure (SDDS_SaveLayout)");
643 return (0);
644 }
645 memcpy((char *)target->parameter_definition, (char *)source->parameter_definition, sizeof(PARAMETER_DEFINITION) * source->n_parameters);
646 memcpy((char *)target->parameter_index, (char *)source->parameter_index, sizeof(SORTED_INDEX *) * source->n_parameters);
647 }
648 if (source->n_arrays) {
649 if (!(target->array_definition = (ARRAY_DEFINITION *)SDDS_Realloc((void *)target->array_definition, sizeof(ARRAY_DEFINITION) * source->n_arrays)) || !(target->array_index = (SORTED_INDEX **)SDDS_Realloc((void *)target->array_index, sizeof(SORTED_INDEX *) * source->n_arrays))) {
650 SDDS_SetError("Unable to save layout--allocation failure (SDDS_SaveLayout)");
651 return (0);
652 }
653 memcpy((char *)target->array_definition, (char *)source->array_definition, sizeof(ARRAY_DEFINITION) * source->n_arrays);
654 memcpy((char *)target->array_index, (char *)source->array_index, sizeof(SORTED_INDEX *) * source->n_arrays);
655 }
656 if (source->n_associates) {
657 if (!(target->associate_definition = (ASSOCIATE_DEFINITION *)SDDS_Realloc((void *)target->associate_definition, sizeof(ASSOCIATE_DEFINITION) * source->n_associates))) {
658 SDDS_SetError("Unable to save layout--allocation failure (SDDS_SaveLayout)");
659 return (0);
660 }
661 memcpy((char *)target->associate_definition, (char *)source->associate_definition, sizeof(ASSOCIATE_DEFINITION) * source->n_associates);
662 }
663
664 target->n_columns = source->n_columns;
665 target->n_parameters = source->n_parameters;
666 target->n_associates = source->n_associates;
667 target->n_arrays = source->n_arrays;
668 target->description = source->description;
669 target->contents = source->contents;
670 target->version = source->version;
671 target->data_mode = source->data_mode;
672 target->filename = source->filename;
673 target->fp = source->fp;
674 target->popenUsed = source->popenUsed;
675
676 if (SDDS_dataset->layout.n_columns) {
677 if (!(SDDS_dataset->column_track_memory = (short *)SDDS_Realloc(SDDS_dataset->column_track_memory, sizeof(short) * SDDS_dataset->layout.n_columns))) {
678 SDDS_SetError("memory allocation failure (SDDS_SaveLayout)");
679 return(0);
680 }
681 if (!SDDS_SetMemory(SDDS_dataset->column_track_memory, SDDS_dataset->layout.n_columns, SDDS_SHORT, (short)1, (short)0)) {
682 SDDS_SetError("Unable to initialize memory (SDDS_SaveLayout)");
683 return (0);
684 }
685 }
686
687 return (1);
688}

◆ SDDS_ScanData()

epicsShareFuncSDDS int32_t SDDS_ScanData ( char * string,
int32_t type,
int32_t field_length,
void * data,
int64_t index,
int32_t is_parameter )
extern

Scans a string and saves the parsed value into a data pointer according to the specified data type.

This function extracts data from a string and stores it in the provided data pointer. It handles various SDDS data types, including integers, floating-point numbers, strings, and characters. The function supports both fixed-field and variable-field formats and can process parameters and column data.

Parameters
stringPointer to the input string containing the data to be scanned.
typeThe SDDS data type to interpret the scanned data as. Valid types include:
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_LONG64
  • SDDS_ULONG64
  • SDDS_FLOAT
  • SDDS_DOUBLE
  • SDDS_LONGDOUBLE
  • SDDS_STRING
  • SDDS_CHARACTER
field_lengthField length for fixed-field formats. Set to 0 for variable-field formats. If negative, indicates left-padding should be removed.
dataVoid pointer to the data storage where the scanned value will be saved. Must be pre-allocated and appropriate for the specified data type.
indexThe index within the data array where the value should be stored.
is_parameterSet to 1 if the data is from an SDDS parameter; set to 0 for column data.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
The function allocates a buffer internally to process the input string. It handles escape sequences for strings and characters using SDDS_InterpretEscapes(). For string data types, the function manages memory allocation for the data array elements.

Definition at line 1748 of file SDDS_ascii.c.

1748 {
1749 char *buffer = NULL;
1750 int32_t abs_field_length, length;
1751 int32_t bufferSize = 0;
1752
1753 abs_field_length = abs(field_length);
1754 if (!string) {
1755 SDDS_SetError("Unable to scan data--input string is NULL (SDDS_ScanData)");
1756 return (0);
1757 }
1758 if (!data) {
1759 SDDS_SetError("Unable to scan data--data pointer is NULL (SDDS_ScanData)");
1760 return (0);
1761 }
1762 if (!(buffer = SDDS_Malloc(sizeof(*buffer) * (bufferSize = SDDS_MAXLINE)))) {
1763 SDDS_SetError("Unable to scan data--allocation failure (SDDS_ScanData)");
1764 return (0);
1765 }
1766 if ((length = strlen(string)) < abs_field_length)
1767 length = abs_field_length;
1768 if (bufferSize <= length) {
1769 if (!(buffer = SDDS_Realloc(buffer, sizeof(*buffer) * (bufferSize = 2 * length)))) {
1770 /* I allocate 2*length in the hopes that I won't need to realloc too often if I do this */
1771 SDDS_SetError("Unable to scan data--allocation failure (SDDS_ScanData)");
1772 return (0);
1773 }
1774 }
1775 if (type != SDDS_STRING) {
1776 /* for non-string data, fill buffer with string to be scanned */
1777 if (field_length) {
1778 /* fill with fixed number of characters */
1779 if (abs_field_length > (int32_t)strlen(string)) {
1780 strcpy(buffer, string);
1781 *string = 0;
1782 } else {
1783 strncpy(buffer, string, abs_field_length);
1784 buffer[field_length] = 0;
1785 strcpy(string, string + abs_field_length);
1786 }
1787 } else if (SDDS_GetToken(string, buffer, bufferSize) < 0) {
1788 SDDS_SetError("Unable to scan data--tokenizing error (SDDS_ScanData)");
1789 return (0);
1790 }
1791 }
1792 switch (type) {
1793 case SDDS_SHORT:
1794 if (sscanf(buffer, "%hd", ((short *)data) + index) == 1) {
1795 if (buffer)
1796 free(buffer);
1797 return (1);
1798 }
1799 break;
1800 case SDDS_USHORT:
1801 if (sscanf(buffer, "%hu", ((unsigned short *)data) + index) == 1) {
1802 if (buffer)
1803 free(buffer);
1804 return (1);
1805 }
1806 break;
1807 case SDDS_LONG:
1808 if (sscanf(buffer, "%" SCNd32, ((int32_t *)data) + index) == 1) {
1809 if (buffer)
1810 free(buffer);
1811 return (1);
1812 }
1813 break;
1814 case SDDS_ULONG:
1815 if (sscanf(buffer, "%" SCNu32, ((uint32_t *)data) + index) == 1) {
1816 if (buffer)
1817 free(buffer);
1818 return (1);
1819 }
1820 break;
1821 case SDDS_LONG64:
1822 if (sscanf(buffer, "%" SCNd64, ((int64_t *)data) + index) == 1) {
1823 if (buffer)
1824 free(buffer);
1825 return (1);
1826 }
1827 break;
1828 case SDDS_ULONG64:
1829 if (sscanf(buffer, "%" SCNu64, ((uint64_t *)data) + index) == 1) {
1830 if (buffer)
1831 free(buffer);
1832 return (1);
1833 }
1834 break;
1835 case SDDS_FLOAT:
1836 if (sscanf(buffer, "%f", ((float *)data) + index) == 1) {
1837 if (buffer)
1838 free(buffer);
1839 return (1);
1840 }
1841 break;
1842 case SDDS_DOUBLE:
1843 if (sscanf(buffer, "%lf", ((double *)data) + index) == 1) {
1844 if (buffer)
1845 free(buffer);
1846 return (1);
1847 }
1848 break;
1849 case SDDS_LONGDOUBLE:
1850 if (sscanf(buffer, "%Lf", ((long double *)data) + index) == 1) {
1851 if (buffer)
1852 free(buffer);
1853 return (1);
1854 }
1855 break;
1856 case SDDS_STRING:
1857 if (is_parameter) {
1858 int32_t len;
1859 if (((char **)data)[index]) {
1860 free(((char **)data)[index]);
1861 ((char **)data)[index] = NULL;
1862 }
1863 if ((len = strlen(string)) > 0) {
1864 if (string[len - 1] == '\r')
1865 string[len - 1] = 0;
1866 }
1867 if (string[0] == '"')
1868 SDDS_GetToken(string, buffer, bufferSize);
1869 else
1870 strcpy(buffer, string);
1871 SDDS_InterpretEscapes(buffer);
1872 if (SDDS_CopyString(((char **)data) + index, buffer)) {
1873 if (buffer)
1874 free(buffer);
1875 return (1);
1876 }
1877 } else {
1878 if (field_length) {
1879 if (abs_field_length > (int32_t)strlen(string)) {
1880 strcpy(buffer, string);
1881 *string = 0;
1882 } else {
1883 strncpy(buffer, string, abs_field_length);
1884 buffer[abs_field_length] = 0;
1885 strcpy(string, string + abs_field_length);
1886 }
1887 if (field_length < 0)
1888 SDDS_RemovePadding(buffer);
1889 } else if (SDDS_GetToken(string, buffer, bufferSize) < 0)
1890 break;
1891 if (((char **)data)[index]) {
1892 free(((char **)data)[index]);
1893 ((char **)data)[index] = NULL;
1894 }
1895 SDDS_InterpretEscapes(buffer);
1896 if (SDDS_CopyString(((char **)data) + index, buffer)) {
1897 if (buffer)
1898 free(buffer);
1899 return (1);
1900 }
1901 }
1902 break;
1903 case SDDS_CHARACTER:
1904 SDDS_InterpretEscapes(buffer);
1905 *(((char *)data) + index) = buffer[0];
1906 if (buffer)
1907 free(buffer);
1908 return (1);
1909 default:
1910 SDDS_SetError("Unknown data type encountered (SDDS_ScanData)");
1911 return (0);
1912 }
1913 SDDS_SetError("Unable to scan data--scanning or allocation error (SDDS_ScanData)");
1914 return (0);
1915}
void SDDS_InterpretEscapes(char *s)
Interprets and converts escape sequences in a string.
void SDDS_RemovePadding(char *s)
Removes leading and trailing whitespace from a string.

◆ SDDS_ScanData2()

epicsShareFuncSDDS int32_t SDDS_ScanData2 ( char * string,
char ** pstring,
int32_t * strlength,
int32_t type,
int32_t field_length,
void * data,
int64_t index,
int32_t is_parameter )
extern

Scans a string and saves the parsed value into a data pointer, optimized for long strings.

This function is similar to SDDS_ScanData but optimized for very long strings. It modifies the input string by advancing the string pointer and reducing its length after each call, which can improve performance when processing large amounts of data.

Parameters
stringPointer to the input string containing the data to be scanned.
pstringPointer to the string pointer; this is updated to point to the next unread character.
strlengthPointer to the length of the string; this is updated as the string is consumed.
typeThe SDDS data type to interpret the scanned data as. Valid types include:
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_LONG64
  • SDDS_ULONG64
  • SDDS_FLOAT
  • SDDS_DOUBLE
  • SDDS_LONGDOUBLE
  • SDDS_STRING
  • SDDS_CHARACTER
field_lengthField length for fixed-field formats. Set to 0 for variable-field formats. If negative, indicates left-padding should be removed.
dataVoid pointer to the data storage where the scanned value will be saved. Must be pre-allocated and appropriate for the specified data type.
indexThe index within the data array where the value should be stored.
is_parameterSet to 1 if the data is from an SDDS parameter; set to 0 for column data.
Returns
Returns 1 on success, or 0 on error. If an error occurs, an error message is set via SDDS_SetError().
Note
This function modifies the input string by advancing the pointer and reducing the length, which can lead to the original string being altered after each call. It is more efficient for processing very long strings compared to SDDS_ScanData.

Definition at line 1953 of file SDDS_ascii.c.

1953 {
1954 char *buffer = NULL;
1955 int32_t abs_field_length, length;
1956 int32_t bufferSize = 0;
1957
1958 abs_field_length = abs(field_length);
1959 if (!string) {
1960 SDDS_SetError("Unable to scan data--input string is NULL (SDDS_ScanData2)");
1961 return (0);
1962 }
1963 if (!data) {
1964 SDDS_SetError("Unable to scan data--data pointer is NULL (SDDS_ScanData2)");
1965 return (0);
1966 }
1967 if (!(buffer = SDDS_Malloc(sizeof(*buffer) * (bufferSize = SDDS_MAXLINE)))) {
1968 SDDS_SetError("Unable to scan data--allocation failure (SDDS_ScanData2)");
1969 return (0);
1970 }
1971 length = *strlength;
1972 if (length < abs_field_length)
1973 length = abs_field_length;
1974 if (bufferSize <= length) {
1975 if (!(buffer = SDDS_Realloc(buffer, sizeof(*buffer) * (bufferSize = 2 * length)))) {
1976 /* I allocate 2*length in the hopes that I won't need to realloc too often if I do this */
1977 SDDS_SetError("Unable to scan data--allocation failure (SDDS_ScanData2)");
1978 return (0);
1979 }
1980 }
1981 if (type != SDDS_STRING) {
1982 /* for non-string data, fill buffer with string to be scanned */
1983 if (field_length) {
1984 /* fill with fixed number of characters */
1985 if (abs_field_length > *strlength) {
1986 strcpy(buffer, string);
1987 **pstring = 0;
1988 *strlength = 0;
1989 } else {
1990 strncpy(buffer, string, abs_field_length);
1991 buffer[abs_field_length] = 0;
1992 *pstring += abs_field_length;
1993 *strlength -= abs_field_length;
1994 }
1995 } else if (SDDS_GetToken2(string, pstring, strlength, buffer, bufferSize) < 0) {
1996 SDDS_SetError("Unable to scan data--tokenizing error (SDDS_ScanData2)");
1997 return (0);
1998 }
1999 }
2000 switch (type) {
2001 case SDDS_SHORT:
2002 if (sscanf(buffer, "%hd", ((short *)data) + index) == 1) {
2003 if (buffer)
2004 free(buffer);
2005 return (1);
2006 }
2007 break;
2008 case SDDS_USHORT:
2009 if (sscanf(buffer, "%hu", ((unsigned short *)data) + index) == 1) {
2010 if (buffer)
2011 free(buffer);
2012 return (1);
2013 }
2014 break;
2015 case SDDS_LONG:
2016 if (sscanf(buffer, "%" SCNd32, ((int32_t *)data) + index) == 1) {
2017 if (buffer)
2018 free(buffer);
2019 return (1);
2020 }
2021 break;
2022 case SDDS_ULONG:
2023 if (sscanf(buffer, "%" SCNu32, ((uint32_t *)data) + index) == 1) {
2024 if (buffer)
2025 free(buffer);
2026 return (1);
2027 }
2028 break;
2029 case SDDS_LONG64:
2030 if (sscanf(buffer, "%" SCNd64, ((int64_t *)data) + index) == 1) {
2031 if (buffer)
2032 free(buffer);
2033 return (1);
2034 }
2035 break;
2036 case SDDS_ULONG64:
2037 if (sscanf(buffer, "%" SCNu64, ((uint64_t *)data) + index) == 1) {
2038 if (buffer)
2039 free(buffer);
2040 return (1);
2041 }
2042 break;
2043 case SDDS_FLOAT:
2044 if (sscanf(buffer, "%f", ((float *)data) + index) == 1) {
2045 if (buffer)
2046 free(buffer);
2047 return (1);
2048 }
2049 break;
2050 case SDDS_DOUBLE:
2051 if (sscanf(buffer, "%lf", ((double *)data) + index) == 1) {
2052 if (buffer)
2053 free(buffer);
2054 return (1);
2055 }
2056 break;
2057 case SDDS_LONGDOUBLE:
2058 if (sscanf(buffer, "%Lf", ((long double *)data) + index) == 1) {
2059 if (buffer)
2060 free(buffer);
2061 return (1);
2062 }
2063 break;
2064 case SDDS_STRING:
2065 if (is_parameter) {
2066 int32_t len;
2067 if (((char **)data)[index]) {
2068 free(((char **)data)[index]);
2069 ((char **)data)[index] = NULL;
2070 }
2071 if ((len = *strlength) > 0) {
2072 if (*pstring[len - 1] == '\r') {
2073 *pstring[len - 1] = 0;
2074 *strlength -= 1;
2075 }
2076 }
2077 if (*pstring[0] == '"')
2078 SDDS_GetToken2(*pstring, pstring, strlength, buffer, bufferSize);
2079 else
2080 strcpy(buffer, string);
2081 SDDS_InterpretEscapes(buffer);
2082 if (SDDS_CopyString(((char **)data) + index, buffer)) {
2083 if (buffer)
2084 free(buffer);
2085 return (1);
2086 }
2087 } else {
2088 if (field_length) {
2089 if (abs_field_length > *strlength) {
2090 strcpy(buffer, string);
2091 **pstring = 0;
2092 *strlength = 0;
2093 } else {
2094 strncpy(buffer, string, abs_field_length);
2095 buffer[abs_field_length] = 0;
2096 *pstring += abs_field_length;
2097 *strlength -= abs_field_length;
2098 }
2099 if (field_length < 0)
2100 SDDS_RemovePadding(buffer);
2101 } else if (SDDS_GetToken2(string, pstring, strlength, buffer, bufferSize) < 0)
2102 break;
2103 if (((char **)data)[index]) {
2104 free(((char **)data)[index]);
2105 ((char **)data)[index] = NULL;
2106 }
2107 SDDS_InterpretEscapes(buffer);
2108 if (SDDS_CopyString(((char **)data) + index, buffer)) {
2109 if (buffer)
2110 free(buffer);
2111 return (1);
2112 }
2113 }
2114 break;
2115 case SDDS_CHARACTER:
2116 SDDS_InterpretEscapes(buffer);
2117 *(((char *)data) + index) = buffer[0];
2118 if (buffer)
2119 free(buffer);
2120 return 1;
2121 default:
2122 SDDS_SetError("Unknown data type encountered (SDDS_ScanData2)");
2123 return (0);
2124 }
2125 SDDS_SetError("Unable to scan data--scanning or allocation error (SDDS_ScanData2)");
2126 return (0);
2127}
int32_t SDDS_GetToken2(char *s, char **st, int32_t *strlength, char *buffer, int32_t buflen)
Extracts the next token from a string, handling quoted substrings and escape characters,...

◆ SDDS_SetArray()

epicsShareFuncSDDS int32_t SDDS_SetArray ( SDDS_DATASET * SDDS_dataset,
char * array_name,
int32_t mode,
void * data_pointer,
int32_t * dimension )
extern

Sets the values of an array variable in the SDDS dataset using specified dimensions.

This function assigns data to a specified array within the current SDDS dataset. The dimensions of the array are provided as an array of integers, allowing for the assignment of multi-dimensional arrays. The mode parameter controls how the data is interpreted and stored. This function handles both pointer arrays and contiguous data.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
array_nameThe name of the array to set within the dataset.
modeBitwise flags that determine how the array is set. Valid flags include:
  • SDDS_POINTER_ARRAY: Indicates that the array is a pointer array.
  • SDDS_CONTIGUOUS_DATA: Indicates that the data is contiguous in memory.
data_pointerPointer to the data to be assigned to the array. The data must match the type defined for the array.
dimensionPointer to an array of integers specifying the dimensions of the array. The number of dimensions should match the array definition.
Returns
Returns 1 on successful assignment of the array data. On failure, returns 0 and records an appropriate error message.
See also
SDDS_Realloc, SDDS_CopyStringArray, SDDS_SetError, SDDS_GetArrayIndex, SDDS_ZeroMemory, SDDS_AdvanceCounter

Definition at line 1278 of file SDDS_dataprep.c.

1278 {
1279 int32_t index, i, size;
1280 int32_t *counter = NULL;
1281 SDDS_LAYOUT *layout;
1282 SDDS_ARRAY *array;
1283 void *ptr;
1284
1285 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetArray"))
1286 return (0);
1287 if (!(mode & SDDS_POINTER_ARRAY) && !(mode & SDDS_CONTIGUOUS_DATA)) {
1288 SDDS_SetError("Unable to set array--invalid mode (SDDS_SetArray)");
1289 return (0);
1290 }
1291 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
1292 SDDS_SetError("Unable to set array--unknown array name given (SDDS_SetArray)");
1293 return (0);
1294 }
1295
1296 if (!dimension) {
1297 SDDS_SetError("Unable to set array--dimension pointer is NULL (SDDS_SetArray)");
1298 return (0);
1299 }
1300 if (!SDDS_dataset->array) {
1301 SDDS_SetError("Unable to set array--internal array pointer is NULL (SDDS_SetArray)");
1302 return (0);
1303 }
1304
1305 layout = &SDDS_dataset->layout;
1306 array = SDDS_dataset->array + index;
1307 if (!layout->array_definition) {
1308 SDDS_SetError("Unable to set array--internal array definition pointer is NULL (SDDS_SetArray)");
1309 return (0);
1310 }
1311 array->definition = layout->array_definition + index;
1312 if (!array->dimension && !(array->dimension = (int32_t *)SDDS_Malloc(sizeof(*array->dimension) * array->definition->dimensions))) {
1313 SDDS_SetError("Unable to set array--allocation failure (SDDS_SetArray)");
1314 return (0);
1315 }
1316 array->elements = 1;
1317 for (i = 0; i < array->definition->dimensions; i++) {
1318 if ((array->dimension[i] = dimension[i]) < 0) {
1319 SDDS_SetError("Unable to set array--negative dimension specified (SDDS_SetArray)");
1320 return (0);
1321 }
1322 array->elements *= dimension[i];
1323 if (array->elements && !data_pointer) {
1324 SDDS_SetError("Unable to set array--data pointer is NULL (SDDS_SetArray)");
1325 return (0);
1326 }
1327 }
1328 if (!array->elements)
1329 return (1);
1330
1331 size = SDDS_type_size[array->definition->type - 1];
1332 if (!(array->data = SDDS_Realloc(array->data, size * array->elements))) {
1333 SDDS_SetError("Unable to set array--allocation failure (SDDS_SetArray)");
1334 return (0);
1335 }
1336
1337 /* handle 1-d arrays and contiguous data as a special case */
1338 if (array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA) {
1339 if (array->definition->type != SDDS_STRING)
1340 memcpy(array->data, data_pointer, size * array->elements);
1341 else if (!SDDS_CopyStringArray(array->data, data_pointer, array->elements)) {
1342 SDDS_SetError("Unable to set array--string copy failure (SDDS_SetArrayVararg");
1343 return (0);
1344 }
1345 return (1);
1346 }
1347
1348 if (!(counter = SDDS_Realloc(counter, sizeof(*counter) * (array->elements - 1)))) {
1349 SDDS_SetError("Unable to set array--allocation failure (SDDS_SetArray)");
1350 return (0);
1351 }
1352 SDDS_ZeroMemory(counter, sizeof(*counter) * (array->elements - 1));
1353 index = 0;
1354 do {
1355 ptr = data_pointer;
1356 for (i = 0; i < array->definition->dimensions - 1; i++)
1357 ptr = ((void **)ptr)[counter[i]];
1358 if (array->definition->type != SDDS_STRING)
1359 memcpy((char *)array->data + size * index, ptr, size * array->dimension[i]);
1360 else if (!SDDS_CopyStringArray(((char **)array->data) + index, ptr, array->dimension[i])) {
1361 SDDS_SetError("Unable to set array--string copy failure (SDDS_SetArray)");
1362 return (0);
1363 }
1364 index += array->dimension[i];
1365 } while (SDDS_AdvanceCounter(counter, array->dimension, array->definition->dimensions - 1) != -1);
1366 if (counter)
1367 free(counter);
1368 return (1);
1369}
int32_t SDDS_AdvanceCounter(int32_t *counter, int32_t *max_count, int32_t n_indices)
Advances a multi-dimensional counter based on maximum counts for each dimension.

◆ SDDS_SetArrayUnitsConversion()

epicsShareFuncSDDS int32_t SDDS_SetArrayUnitsConversion ( SDDS_DATASET * SDDS_dataset,
char * array_name,
char * new_units,
char * old_units,
double factor )
extern

Sets unit conversions for a specified array in an SDDS dataset.

This function updates the units of the specified array within the SDDS dataset and applies a conversion factor to all its elements if the dataset has already been read (i.e., pages_read > 0). The function ensures that the new units are consistent with the old units if provided.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
array_nameA null-terminated string specifying the name of the array to update.
new_unitsA null-terminated string specifying the new units to assign to the array. This parameter must not be NULL.
old_unitsA null-terminated string specifying the expected current units of the array. If NULL, the function does not verify the existing units.
factorA double representing the conversion factor to apply to each element of the array. Each element will be multiplied by this factor.
Returns
Returns 1 on successful unit conversion and update. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the unit conversion was successfully applied.
0Indicates that an error occurred (e.g., invalid dataset, unrecognized array name, type undefined, memory allocation failure).
Note
  • The new_units parameter must not be NULL. Passing NULL will result in an error.
  • If the dataset has not been read yet (pages_read == 0), the conversion factor is stored but not applied immediately.
  • The function handles various data types, ensuring that the conversion factor is appropriately applied based on the array's type.
See also
SDDS_SetColumnUnitsConversion, SDDS_SetParameterUnitsConversion, SDDS_GetArray

Definition at line 4675 of file SDDS_extract.c.

4675 {
4676 int32_t index, type;
4677 int64_t i;
4678 void *rawData;
4679 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetArrayUnitsConversion"))
4680 return(0);
4681 if (new_units == NULL) {
4682 SDDS_SetError("new_units is NULL (SDDS_SetArrayUnitsConversion)");
4683 return(0);
4684 }
4685 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
4686 SDDS_SetError("Unable to get array--name is not recognized (SDDS_SetArrayUnitsConversion)");
4687 return(0);
4688 }
4689 if (!(type = SDDS_GetArrayType(SDDS_dataset, index))) {
4690 SDDS_SetError("Unable to get array--data type undefined (SDDS_SetArrayUnitsConversion)");
4691 return(0);
4692 }
4693 if (SDDS_dataset->layout.array_definition[index].units != NULL) {
4694 if (strcmp(new_units, SDDS_dataset->layout.array_definition[index].units) != 0) {
4695 if ((old_units != NULL) && (strcmp(old_units, SDDS_dataset->layout.array_definition[index].units) != 0)) {
4696 SDDS_SetError("Unexpected units value found (SDDS_SetArrayUnitsConversion)");
4697 return(0);
4698 }
4699 /* free(SDDS_dataset->layout.array_definition[index].units); */
4700 cp_str(&(SDDS_dataset->layout.array_definition[index].units), new_units);
4701 }
4702 } else {
4703 cp_str(&(SDDS_dataset->layout.array_definition[index].units), new_units);
4704 }
4705
4706 if (SDDS_dataset->pages_read == 0) {
4707 return(1);
4708 }
4709 rawData = SDDS_dataset->array[index].data;
4710 switch (type) {
4711 case SDDS_LONGDOUBLE:
4712 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4713 ((long double *)rawData)[i] *= factor;
4714 }
4715 break;
4716 case SDDS_DOUBLE:
4717 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4718 ((double *)rawData)[i] *= factor;
4719 }
4720 break;
4721 case SDDS_FLOAT:
4722 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4723 ((float *)rawData)[i] *= factor;
4724 }
4725 break;
4726 case SDDS_LONG:
4727 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4728 ((int32_t *)rawData)[i] *= factor;
4729 }
4730 break;
4731 case SDDS_ULONG:
4732 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4733 ((uint32_t *)rawData)[i] *= factor;
4734 }
4735 break;
4736 case SDDS_LONG64:
4737 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4738 ((int64_t *)rawData)[i] *= factor;
4739 }
4740 break;
4741 case SDDS_ULONG64:
4742 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4743 ((uint64_t *)rawData)[i] *= factor;
4744 }
4745 break;
4746 case SDDS_SHORT:
4747 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4748 ((short *)rawData)[i] *= factor;
4749 }
4750 break;
4751 case SDDS_USHORT:
4752 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4753 ((unsigned short *)rawData)[i] *= factor;
4754 }
4755 break;
4756 }
4757 return(1);
4758}
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
Definition cp_str.c:28

◆ SDDS_SetArrayVararg()

epicsShareFuncSDDS int32_t SDDS_SetArrayVararg ( SDDS_DATASET * SDDS_dataset,
char * array_name,
int32_t mode,
void * data_pointer,
... )
extern

Sets the values of an array variable in the SDDS dataset using variable arguments for dimensions.

This function assigns data to a specified array within the current SDDS dataset. The dimensions of the array are provided as variable arguments, allowing for flexible assignment of multi-dimensional arrays. The mode parameter controls how the data is interpreted and stored. This function handles both pointer arrays and contiguous data.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
array_nameThe name of the array to set within the dataset.
modeBitwise flags that determine how the array is set. Valid flags include:
  • SDDS_POINTER_ARRAY: Indicates that the array is a pointer array.
  • SDDS_CONTIGUOUS_DATA: Indicates that the data is contiguous in memory.
data_pointerPointer to the data to be assigned to the array. The data must match the type defined for the array.
...Variable arguments specifying the dimensions of the array. The number of dimensions should match the array definition.
Returns
Returns 1 on successful assignment of the array data. On failure, returns 0 and records an appropriate error message.
See also
SDDS_Realloc, SDDS_CopyStringArray, SDDS_SetError, SDDS_GetArrayIndex, SDDS_ZeroMemory, SDDS_AdvanceCounter

Definition at line 1157 of file SDDS_dataprep.c.

1157 {
1158 va_list argptr;
1159 int32_t index, retval, i, size;
1160 int32_t *counter = NULL;
1161 SDDS_LAYOUT *layout;
1162 SDDS_ARRAY *array;
1163 void *ptr;
1164
1165 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetArrayVararg"))
1166 return (0);
1167 if (!(mode & SDDS_POINTER_ARRAY) && !(mode & SDDS_CONTIGUOUS_DATA)) {
1168 SDDS_SetError("Unable to set array--invalid mode (SDDS_SetArrayVararg)");
1169 return (0);
1170 }
1171 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
1172 SDDS_SetError("Unable to set array--unknown array name given (SDDS_SetArrayVararg)");
1173 return (0);
1174 }
1175 if (!SDDS_dataset->array) {
1176 SDDS_SetError("Unable to set array--internal array pointer is NULL (SDDS_SetArrayVararg)");
1177 return (0);
1178 }
1179
1180 layout = &SDDS_dataset->layout;
1181 array = SDDS_dataset->array + index;
1182 if (!layout->array_definition) {
1183 SDDS_SetError("Unable to set array--internal array definition pointer is NULL (SDDS_SetArrayVararg)");
1184 return (0);
1185 }
1186 array->definition = layout->array_definition + index;
1187 if (!array->dimension && !(array->dimension = (int32_t *)SDDS_Malloc(sizeof(*array->dimension) * array->definition->dimensions))) {
1188 SDDS_SetError("Unable to set array--allocation failure (SDDS_SetArrayVararg)");
1189 return (0);
1190 }
1191
1192 va_start(argptr, data_pointer);
1193
1194 /* variable arguments are dimensions */
1195 retval = 1;
1196 index = 0;
1197 array->elements = 1;
1198 do {
1199 if ((array->dimension[index] = va_arg(argptr, int32_t)) < 0) {
1200 SDDS_SetError("Unable to set array--negative dimension given (SDDS_SetArrayVararg)");
1201 retval = 0;
1202 break;
1203 }
1204 array->elements *= array->dimension[index];
1205 } while (retval == 1 && ++index < array->definition->dimensions);
1206 va_end(argptr);
1207
1208 if (!retval)
1209 return (0);
1210 if (!array->elements)
1211 return (1);
1212 if (!data_pointer) {
1213 SDDS_SetError("Unable to set array--data pointer is NULL (SDDS_SetArrayVararg)");
1214 return (0);
1215 }
1216
1217 size = SDDS_type_size[array->definition->type - 1];
1218 if (!(array->data = SDDS_Realloc(array->data, size * array->elements))) {
1219 SDDS_SetError("Unable to set array--allocation failure (SDDS_SetArrayVararg");
1220 return (0);
1221 }
1222
1223 /* handle 1-d arrays and contiguous data as a special case */
1224 if (array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA) {
1225 if (array->definition->type != SDDS_STRING)
1226 memcpy(array->data, data_pointer, size * array->elements);
1227 else if (!SDDS_CopyStringArray(array->data, data_pointer, array->elements)) {
1228 SDDS_SetError("Unable to set array--string copy failure (SDDS_SetArrayVararg");
1229 return (0);
1230 }
1231 return (1);
1232 }
1233
1234 if (!(counter = SDDS_Realloc(counter, sizeof(*counter) * (array->elements - 1)))) {
1235 SDDS_SetError("Unable to set array--allocation failure (SDDS_SetArrayVararg");
1236 return (0);
1237 }
1238 SDDS_ZeroMemory(counter, sizeof(*counter) * (array->elements - 1));
1239 index = 0;
1240 do {
1241 ptr = data_pointer;
1242 for (i = 0; i < array->definition->dimensions - 1; i++)
1243 ptr = ((void **)ptr)[counter[i]];
1244 if (array->definition->type != SDDS_STRING)
1245 memcpy((char *)array->data + size * index, ptr, size * array->dimension[i]);
1246 else if (!SDDS_CopyStringArray(((char **)array->data) + index, ptr, array->dimension[i])) {
1247 SDDS_SetError("Unable to set array--string copy failure (SDDS_SetArrayVararg");
1248 return (0);
1249 }
1250 index += array->dimension[i];
1251 } while (SDDS_AdvanceCounter(counter, array->dimension, array->definition->dimensions - 1) != -1);
1252 if (counter)
1253 free(counter);
1254 return (1);
1255}

◆ SDDS_SetAutoCheckMode()

epicsShareFuncSDDS uint32_t SDDS_SetAutoCheckMode ( uint32_t newMode)

Sets the automatic check mode for SDDS dataset validation.

This function updates the auto-check mode, which controls the automatic validation of SDDS datasets during operations. The previous mode is returned.

Parameters
[in]newModeThe new auto-check mode to be set. It should be a bitwise combination of the following constants:
  • TABULAR_DATA_CHECKS: Enables checks for tabular data consistency.
  • (Other mode flags as defined by SDDS)
Returns
The previous auto-check mode before the update.
See also
SDDS_CheckDataset
SDDS_CheckTabularData

Definition at line 533 of file SDDS_utils.c.

533 {
534 uint32_t oldMode;
535 oldMode = AutoCheckMode;
536 AutoCheckMode = newMode;
537 return oldMode;
538}

◆ SDDS_SetAutoReadRecovery()

epicsShareFuncSDDS int32_t SDDS_SetAutoReadRecovery ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )
extern

Sets the auto-read recovery mode for the SDDS dataset.

Parameters
SDDS_datasetThe SDDS dataset to modify.
modeThe mode to set (SDDS_AUTOREADRECOVER or SDDS_NOAUTOREADRECOVER).
Returns
1 on success, 0 on error.

Definition at line 1762 of file SDDS_input.c.

1762 {
1763 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetAutoReadRecovery"))
1764 return 0;
1765 if (mode & SDDS_AUTOREADRECOVER) {
1766 SDDS_dataset->autoRecover = 1;
1767 } else if (mode & SDDS_NOAUTOREADRECOVER) {
1768 SDDS_dataset->autoRecover = 0;
1769 } else {
1770 SDDS_SetError("Invalid Auto Read Recovery mode (SDDS_SetAutoReadRecovery).");
1771 return 0;
1772 }
1773 return 1;
1774}

◆ SDDS_SetColumn()

epicsShareFuncSDDS int32_t SDDS_SetColumn ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
void * data,
int64_t rows,
... )
extern

Sets the values for one data column in the current data table of an SDDS dataset.

This function assigns data to a specified column within the current data table of the given SDDS dataset. The column can be identified either by its index or by its name. The mode parameter determines how the column is identified. The function ensures that the number of rows in the new column matches the existing data table.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeBitwise flags that determine how the column is identified. Valid flags include:
  • SDDS_SET_BY_INDEX: Identify the column by its index.
  • SDDS_SET_BY_NAME: Identify the column by its name.
dataPointer to an array of data to be assigned to the column. The elements of the array must be of the same type as the column type.
rowsThe number of rows in the column. This should match the number of rows in the existing data table.
...Variable arguments specifying either the column index or column name, depending on the mode parameter:
  • If mode includes SDDS_SET_BY_INDEX: Provide an int32_t index.
  • If mode includes SDDS_SET_BY_NAME: Provide a char* name.
Returns
Returns 1 on successful assignment of the column data. On failure, returns 0 and records an appropriate error message.
Note
The function ensures that the number of rows in the new column matches the existing data table. If the data type of the column is SDDS_STRING, it handles memory allocation and copying of strings appropriately.
See also
SDDS_SetRowValues, SDDS_SetError, SDDS_GetColumnIndex, SDDS_CopyStringArray

Definition at line 1536 of file SDDS_dataprep.c.

1536 {
1537 va_list argptr;
1538 int32_t index;
1539 int32_t retval;
1540 SDDS_LAYOUT *layout;
1541 char *name;
1542
1543 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumn"))
1544 return (0);
1545 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
1546 SDDS_SetError("Unable to set column values--unknown mode (SDDS_SetColumn)");
1547 return (0);
1548 }
1549 if (rows > SDDS_dataset->n_rows_allocated) {
1550 SDDS_SetError("Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumn)");
1551 return (0);
1552 }
1553 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_SetColumn"))
1554 return (0);
1555 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
1556 SDDS_SetError("Number of rows in new column unequal to number in other columns (SDDS_SetColumn)");
1557 return (0);
1558 }
1559 SDDS_dataset->n_rows = rows;
1560 layout = &SDDS_dataset->layout;
1561
1562 retval = 1;
1563 va_start(argptr, rows);
1564 if (mode & SDDS_SET_BY_INDEX) {
1565 index = va_arg(argptr, int32_t);
1566 if (index < 0 || index >= layout->n_columns) {
1567 SDDS_SetError("Unable to set column values--index out of range (SDDS_SetColumn)");
1568 retval = 0;
1569 }
1570 } else {
1571 name = va_arg(argptr, char *);
1572 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0) {
1573 SDDS_SetError0("Unable to set column values--name ");
1574 SDDS_SetError0(name);
1575 SDDS_SetError(" not recognized (SDDS_SetColumn)");
1576 retval = 0;
1577 }
1578 }
1579 va_end(argptr);
1580 if (!retval)
1581 return 0;
1582
1583 if (layout->column_definition[index].type == SDDS_STRING) {
1584 if (SDDS_dataset->data[index]) {
1585 char *ptr;
1586 int64_t i;
1587 for (i = 0; i < rows; i++) {
1588 ptr = *((char **)SDDS_dataset->data[index] + i);
1589 if (ptr)
1590 free(ptr);
1591 *((char **)SDDS_dataset->data[index] + i) = NULL;
1592 }
1593 }
1594 if (!SDDS_CopyStringArray((char **)(SDDS_dataset->data[index]), (char **)data, rows)) {
1595 SDDS_SetError("Unable to set column--error copying string data (SDDS_SetColumn)");
1596 return 0;
1597 }
1598 } else
1599 memcpy(SDDS_dataset->data[index], data, rows * SDDS_type_size[layout->column_definition[index].type - 1]);
1600 return 1;
1601}
void SDDS_SetError0(char *error_text)
Internal function to record an error message in the SDDS error stack.
Definition SDDS_utils.c:395

◆ SDDS_SetColumnFlags()

epicsShareFuncSDDS int32_t SDDS_SetColumnFlags ( SDDS_DATASET * SDDS_dataset,
int32_t column_flag_value )
extern

Sets the acceptance flags for all columns in the current data table of a data set.

This function initializes the acceptance flags for each column. A non-zero flag indicates that the column is "of interest" and should be considered in subsequent operations, while a zero flag marks the column for rejection.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_flag_valueInteger value to assign to all column flags.
  • Non-zero value: Marks columns as accepted ("of interest").
  • Zero value: Marks columns as rejected.
Returns
  • 1 on successful update of column flags.
  • 0 on failure, with an error message recorded (e.g., memory allocation failure).
Note
This function overwrites any existing column flags with the specified column_flag_value. It also updates the column_order array accordingly.
See also
SDDS_GetColumnFlags, SDDS_AssertColumnFlags

Definition at line 218 of file SDDS_extract.c.

218 {
219 int64_t i;
220 /* int32_t j; */
221 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnFlags"))
222 return 0;
223 if ((!SDDS_dataset->column_flag || !SDDS_dataset->column_order) && !SDDS_AllocateColumnFlags(SDDS_dataset))
224 return 0;
225 if (!SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)column_flag_value, (int32_t)0)) {
226 SDDS_SetError("Unable to set column flags--memory filling failed (SDDS_SetColumnFlags)");
227 return (0);
228 }
229 SDDS_dataset->n_of_interest = column_flag_value ? SDDS_dataset->layout.n_columns : 0;
230 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
231 SDDS_dataset->column_order[i] = column_flag_value ? i : -1;
232 return (1);
233}

◆ SDDS_SetColumnFromDoubles()

epicsShareFuncSDDS int32_t SDDS_SetColumnFromDoubles ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
double * data,
int64_t rows,
... )
extern

Sets the values for a single data column using double-precision floating-point numbers.

This function assigns data to a specified column within the current data table of the given SDDS dataset. The column can be identified either by its index or by its name, based on the provided mode. The data provided must be in the form of double-precision floating-point numbers (double). If the target column is of a different numeric type, the function will perform the necessary type casting. For string columns, the function converts the double values to strings with appropriate formatting.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeBitwise flags that determine how the column is identified. Valid flags include:
  • SDDS_SET_BY_INDEX: Identify the column by its index.
  • SDDS_SET_BY_NAME: Identify the column by its name.

Mode Requirements:

  • Exactly one of SDDS_SET_BY_INDEX or SDDS_SET_BY_NAME must be set.

Syntax Based on Mode Combination:

  • SDDS_SET_BY_INDEX: int32_t SDDS_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows, int32_t index)
  • SDDS_SET_BY_NAME: int32_t SDDS_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows, char *name)
Parameters
dataPointer to an array of double-precision floating-point data to be assigned to the column. The array should contain at least rows elements.
rowsThe number of rows (elements) in the column to be set. Must not exceed the allocated memory for the dataset.
...Variable arguments specifying either the column index (int32_t) or column name (char *), depending on the mode.
Returns
Returns 1 on successful assignment of the column data. On failure, returns 0 and records an appropriate error message using SDDS_SetError.
Note
  • If the target column is of type SDDS_STRING, the function converts each double value to a string with a precision of up to 15 significant digits.
  • The function ensures that the number of rows in the new column matches the existing data table.
  • It is required to call SDDS_StartPage before setting column values.
See also
SDDS_SetColumnFromLongDoubles, SDDS_SetError, SDDS_GetColumnIndex, SDDS_CopyStringArray, SDDS_CastValue

Definition at line 1642 of file SDDS_dataprep.c.

1642 {
1643 va_list argptr;
1644 int64_t i;
1645 int32_t index, retval, type, size;
1646 SDDS_LAYOUT *layout;
1647 char *name;
1648
1649 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnFromDoubles"))
1650 return (0);
1651 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
1652 SDDS_SetError("Unable to set column values--unknown mode (SDDS_SetColumnFromDoubles)");
1653 return (0);
1654 }
1655 if (rows > SDDS_dataset->n_rows_allocated) {
1656 SDDS_SetError("Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumnFromDoubles)");
1657 return (0);
1658 }
1659 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_SetColumnFromDoubles"))
1660 return (0);
1661 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
1662 SDDS_SetError("Number of rows in new column unequal to number in other columns (SDDS_SetColumnFromDoubles)");
1663 return (0);
1664 }
1665 SDDS_dataset->n_rows = rows;
1666 layout = &SDDS_dataset->layout;
1667
1668 retval = 1;
1669 va_start(argptr, rows);
1670 if (mode & SDDS_SET_BY_INDEX) {
1671 index = va_arg(argptr, int32_t);
1672 if (index < 0 || index >= layout->n_columns) {
1673 SDDS_SetError("Unable to set column values--index out of range (SDDS_SetColumnFromDoubles)");
1674 retval = 0;
1675 }
1676 } else {
1677 name = va_arg(argptr, char *);
1678 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0) {
1679 SDDS_SetError("Unable to set column values--name not recognized (SDDS_SetColumnFromDoubles)");
1680 retval = 0;
1681 }
1682 }
1683 va_end(argptr);
1684 if (!retval)
1685 return 0;
1686
1687 type = layout->column_definition[index].type;
1688 if (!SDDS_NUMERIC_TYPE(type)) {
1689 if (type == SDDS_STRING) {
1690 char **stringArray;
1691 if (SDDS_dataset->data[index]) {
1692 char *ptr;
1693 int64_t i;
1694 for (i = 0; i < rows; i++) {
1695 ptr = *((char **)SDDS_dataset->data[index] + i);
1696 if (ptr)
1697 free(ptr);
1698 *((char **)SDDS_dataset->data[index] + i) = NULL;
1699 }
1700 }
1701 stringArray = (char **)malloc(sizeof(char *) * rows);
1702 for (i = 0; i < rows; i++) {
1703 stringArray[i] = (char *)malloc(sizeof(char) * 40);
1704 sprintf(stringArray[i], "%.15lg", data[i]);
1705 }
1706 if (!SDDS_CopyStringArray((char **)(SDDS_dataset->data[index]), (char **)stringArray, rows)) {
1707 SDDS_SetError("Unable to set column--error copying string data (SDDS_SetColumnFromDoubles)");
1708 return 0;
1709 }
1710 for (i = 0; i < rows; i++) {
1711 free(stringArray[i]);
1712 }
1713 free(stringArray);
1714 return 1;
1715 }
1716 SDDS_SetError("Unable to set column--source type is nonnumeric (SDDS_SetColumnFromDoubles)");
1717 return 0;
1718 }
1719
1720 size = SDDS_type_size[layout->column_definition[index].type - 1];
1721
1722 if (type == SDDS_DOUBLE) {
1723 memcpy((char *)SDDS_dataset->data[index], (char *)data, rows * size);
1724 return 1;
1725 }
1726
1727 for (i = 0; i < rows; i++)
1728 if (!SDDS_CastValue(data, i, SDDS_DOUBLE, type, (char *)(SDDS_dataset->data[index]) + i * size)) {
1729 SDDS_SetError("Unable to set column--cast error (SDDS_SetColumnFromDoubles)");
1730 return 0;
1731 }
1732
1733 return 1;
1734}

◆ SDDS_SetColumnFromFloats()

epicsShareFuncSDDS int32_t SDDS_SetColumnFromFloats ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
float * data,
int64_t rows,
... )
extern

Sets the values for a single data column using single-precision floating-point numbers.

This function assigns data to a specified column within the current data table of the given SDDS dataset. The column can be identified either by its index or by its name, based on the provided mode. The data provided must be in the form of single-precision floating-point numbers (float). If the target column is of a different numeric type, the function will perform the necessary type casting. For string columns, the function converts the float values to strings with appropriate formatting.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeBitwise flags that determine how the column is identified. Valid flags include:
  • SDDS_SET_BY_INDEX: Identify the column by its index.
  • SDDS_SET_BY_NAME: Identify the column by its name.

Mode Requirements:

  • Exactly one of SDDS_SET_BY_INDEX or SDDS_SET_BY_NAME must be set.

Syntax Based on Mode Combination:

  • SDDS_SET_BY_INDEX: int32_t SDDS_SetColumnFromFloats(SDDS_DATASET *SDDS_dataset, int32_t mode, float *data, int64_t rows, int32_t index)
  • SDDS_SET_BY_NAME: int32_t SDDS_SetColumnFromFloats(SDDS_DATASET *SDDS_dataset, int32_t mode, float *data, int64_t rows, char *name)
Parameters
dataPointer to an array of single-precision floating-point data to be assigned to the column. The array should contain at least rows elements.
rowsThe number of rows (elements) in the column to be set. Must not exceed the allocated memory for the dataset.
...Variable arguments specifying either the column index (int32_t) or column name (char *), depending on the mode.
Returns
Returns 1 on successful assignment of the column data. On failure, returns 0 and records an appropriate error message using SDDS_SetError.
Note
  • If the target column is of type SDDS_STRING, the function converts each float value to a string with a precision of up to 8 significant digits.
  • The function ensures that the number of rows in the new column matches the existing data table.
  • It is required to call SDDS_StartPage before setting column values.
See also
SDDS_SetColumnFromDoubles, SDDS_SetError, SDDS_GetColumnIndex, SDDS_CopyStringArray, SDDS_CastValue

Definition at line 1912 of file SDDS_dataprep.c.

1912 {
1913 va_list argptr;
1914 int64_t i;
1915 int32_t index, retval, type, size;
1916 SDDS_LAYOUT *layout;
1917 char *name;
1918
1919 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnFromFloats"))
1920 return (0);
1921 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
1922 SDDS_SetError("Unable to set column values--unknown mode (SDDS_SetColumnFromFloats)");
1923 return (0);
1924 }
1925 if (rows > SDDS_dataset->n_rows_allocated) {
1926 SDDS_SetError("Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumnFromFloats)");
1927 return (0);
1928 }
1929 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_SetColumnFromFloats"))
1930 return (0);
1931 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
1932 SDDS_SetError("Number of rows in new column unequal to number in other columns (SDDS_SetColumnFromFloats)");
1933 return (0);
1934 }
1935 SDDS_dataset->n_rows = rows;
1936 layout = &SDDS_dataset->layout;
1937
1938 retval = 1;
1939 va_start(argptr, rows);
1940 if (mode & SDDS_SET_BY_INDEX) {
1941 index = va_arg(argptr, int32_t);
1942 if (index < 0 || index >= layout->n_columns) {
1943 SDDS_SetError("Unable to set column values--index out of range (SDDS_SetColumnFromFloats)");
1944 retval = 0;
1945 }
1946 } else {
1947 name = va_arg(argptr, char *);
1948 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0) {
1949 SDDS_SetError("Unable to set column values--name not recognized (SDDS_SetColumnFromFloats)");
1950 retval = 0;
1951 }
1952 }
1953 va_end(argptr);
1954 if (!retval)
1955 return 0;
1956
1957 type = layout->column_definition[index].type;
1958 if (!SDDS_NUMERIC_TYPE(type)) {
1959 if (type == SDDS_STRING) {
1960 char **stringArray;
1961 if (SDDS_dataset->data[index]) {
1962 char *ptr;
1963 int64_t i;
1964 for (i = 0; i < rows; i++) {
1965 ptr = *((char **)SDDS_dataset->data[index] + i);
1966 if (ptr)
1967 free(ptr);
1968 *((char **)SDDS_dataset->data[index] + i) = NULL;
1969 }
1970 }
1971 stringArray = (char **)malloc(sizeof(char *) * rows);
1972 for (i = 0; i < rows; i++) {
1973 stringArray[i] = (char *)malloc(sizeof(char) * 40);
1974 sprintf(stringArray[i], "%.8g", data[i]);
1975 }
1976 if (!SDDS_CopyStringArray((char **)(SDDS_dataset->data[index]), (char **)stringArray, rows)) {
1977 SDDS_SetError("Unable to set column--error copying string data (SDDS_SetColumnFromFloats)");
1978 return 0;
1979 }
1980 for (i = 0; i < rows; i++) {
1981 free(stringArray[i]);
1982 }
1983 free(stringArray);
1984 return 1;
1985 }
1986 SDDS_SetError("Unable to set column--source type is nonnumeric (SDDS_SetColumnFromFloats)");
1987 return 0;
1988 }
1989
1990 size = SDDS_type_size[layout->column_definition[index].type - 1];
1991
1992 if (type == SDDS_FLOAT) {
1993 memcpy((char *)SDDS_dataset->data[index], (char *)data, rows * size);
1994 return 1;
1995 }
1996
1997 for (i = 0; i < rows; i++)
1998 if (!SDDS_CastValue(data, i, SDDS_FLOAT, type, (char *)(SDDS_dataset->data[index]) + i * size)) {
1999 SDDS_SetError("Unable to set column--cast error (SDDS_SetColumnFromFloats)");
2000 return 0;
2001 }
2002
2003 return 1;
2004}

◆ SDDS_SetColumnFromLongs()

epicsShareFuncSDDS int32_t SDDS_SetColumnFromLongs ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
int32_t * data,
int64_t rows,
... )
extern

Sets the values for a single data column using long integer numbers.

This function assigns data to a specified column within the current data table of the given SDDS dataset. The column can be identified either by its index or by its name, based on the provided mode. The data provided must be in the form of long integers (int32_t). If the target column is of a different numeric type, the function will perform the necessary type casting. For string columns, the function converts the integer values to strings with appropriate formatting.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeBitwise flags that determine how the column is identified. Valid flags include:
  • SDDS_SET_BY_INDEX: Identify the column by its index.
  • SDDS_SET_BY_NAME: Identify the column by its name.

Mode Requirements:

  • Exactly one of SDDS_SET_BY_INDEX or SDDS_SET_BY_NAME must be set.

Syntax Based on Mode Combination:

  • SDDS_SET_BY_INDEX: int32_t SDDS_SetColumnFromLongs(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t *data, int64_t rows, int32_t index)
  • SDDS_SET_BY_NAME: int32_t SDDS_SetColumnFromLongs(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t *data, int64_t rows, char *name)
Parameters
dataPointer to an array of long integer data to be assigned to the column. The array should contain at least rows elements.
rowsThe number of rows (elements) in the column to be set. Must not exceed the allocated memory for the dataset.
...Variable arguments specifying either the column index (int32_t) or column name (char *), depending on the mode.
Returns
Returns 1 on successful assignment of the column data. On failure, returns 0 and records an appropriate error message using SDDS_SetError.
Note
  • If the target column is of type SDDS_STRING, the function converts each long integer value to a string using the sprintf function with the appropriate format specifier.
  • The function ensures that the number of rows in the new column matches the existing data table.
  • It is required to call SDDS_StartPage before setting column values.
See also
SDDS_SetColumnFromDoubles, SDDS_SetError, SDDS_GetColumnIndex, SDDS_CopyStringArray, SDDS_CastValue

Definition at line 2045 of file SDDS_dataprep.c.

2045 {
2046 va_list argptr;
2047 int64_t i;
2048 int32_t index, retval, type, size;
2049 SDDS_LAYOUT *layout;
2050 char *name;
2051
2052 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnFromLongs"))
2053 return (0);
2054 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
2055 SDDS_SetError("Unable to set column values--unknown mode (SDDS_SetColumnFromLongs)");
2056 return (0);
2057 }
2058 if (rows > SDDS_dataset->n_rows_allocated) {
2059 SDDS_SetError("Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumnFromLongs)");
2060 return (0);
2061 }
2062 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_SetColumnFromLongs"))
2063 return (0);
2064 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
2065 SDDS_SetError("Number of rows in new column unequal to number in other columns (SDDS_SetColumnFromLongs)");
2066 return (0);
2067 }
2068 SDDS_dataset->n_rows = rows;
2069 layout = &SDDS_dataset->layout;
2070
2071 retval = 1;
2072 va_start(argptr, rows);
2073 if (mode & SDDS_SET_BY_INDEX) {
2074 index = va_arg(argptr, int32_t);
2075 if (index < 0 || index >= layout->n_columns) {
2076 SDDS_SetError("Unable to set column values--index out of range (SDDS_SetColumnFromLongs)");
2077 retval = 0;
2078 }
2079 } else {
2080 name = va_arg(argptr, char *);
2081 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0) {
2082 SDDS_SetError("Unable to set column values--name not recognized (SDDS_SetColumnFromLongs)");
2083 retval = 0;
2084 }
2085 }
2086 va_end(argptr);
2087 if (!retval)
2088 return 0;
2089
2090 type = layout->column_definition[index].type;
2091 if (!SDDS_NUMERIC_TYPE(type)) {
2092 if (type == SDDS_STRING) {
2093 char **stringArray;
2094 if (SDDS_dataset->data[index]) {
2095 char *ptr;
2096 int64_t i;
2097 for (i = 0; i < rows; i++) {
2098 ptr = *((char **)SDDS_dataset->data[index] + i);
2099 if (ptr)
2100 free(ptr);
2101 *((char **)SDDS_dataset->data[index] + i) = NULL;
2102 }
2103 }
2104 stringArray = (char **)malloc(sizeof(char *) * rows);
2105 for (i = 0; i < rows; i++) {
2106 stringArray[i] = (char *)malloc(sizeof(char) * 40);
2107 sprintf(stringArray[i], "%" PRId32, data[i]);
2108 }
2109 if (!SDDS_CopyStringArray((char **)(SDDS_dataset->data[index]), (char **)stringArray, rows)) {
2110 SDDS_SetError("Unable to set column--error copying string data (SDDS_SetColumnFromLongs)");
2111 return 0;
2112 }
2113 for (i = 0; i < rows; i++) {
2114 free(stringArray[i]);
2115 }
2116 free(stringArray);
2117 return 1;
2118 }
2119 SDDS_SetError("Unable to set column--source type is nonnumeric (SDDS_SetColumnFromLongs)");
2120 return 0;
2121 }
2122
2123 size = SDDS_type_size[layout->column_definition[index].type - 1];
2124
2125 if (type == SDDS_LONG) {
2126 memcpy((char *)SDDS_dataset->data[index], (char *)data, rows * size);
2127 return 1;
2128 }
2129
2130 for (i = 0; i < rows; i++)
2131 if (!SDDS_CastValue(data, i, SDDS_LONG, type, (char *)(SDDS_dataset->data[index]) + i * size)) {
2132 SDDS_SetError("Unable to set column--cast error (SDDS_SetColumnFromLongs)");
2133 return 0;
2134 }
2135
2136 return 1;
2137}

◆ SDDS_SetColumnMemoryMode()

epicsShareFuncSDDS void SDDS_SetColumnMemoryMode ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )
extern

Sets the column memory mode for the SDDS dataset.

Parameters
SDDS_datasetThe SDDS dataset to operate on.
modeThe column memory mode to set.

Definition at line 1348 of file SDDS_input.c.

1348 {
1349 SDDS_dataset->layout.data_mode.column_memory_mode = mode;
1350}

◆ SDDS_SetColumnsOfInterest()

epicsShareFuncSDDS int32_t SDDS_SetColumnsOfInterest ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Sets the acceptance flags for columns based on specified naming criteria.

This function allows modifying column acceptance flags using various methods, including specifying column names directly or using pattern matching.

Supported modes:

  • SDDS_NAME_ARRAY: Provide an array of column names to mark as "of interest".
  • SDDS_NAMES_STRING: Provide a single string containing comma-separated column names.
  • SDDS_NAME_STRINGS: Provide multiple individual column name strings, terminated by NULL.
  • SDDS_MATCH_STRING: Provide a pattern string and a logic mode to match column names.

A non-zero flag indicates that a column is "of interest", while a zero flag marks it for rejection.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeOperation mode determining how columns are selected. Possible values:
  • SDDS_NAME_ARRAY: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_NAME_ARRAY, int32_t n_entries, char **nameArray);
  • SDDS_NAMES_STRING: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_NAMES_STRING, char *names);
  • SDDS_NAME_STRINGS: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_NAME_STRINGS, char *name1, char *name2, ..., NULL);
  • SDDS_MATCH_STRING: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_MATCH_STRING, char *pattern, int32_t logic_mode);
...Variable arguments based on the selected mode:
  • SDDS_NAME_ARRAY:
    • int32_t n_entries: Number of column names in the array.
    • char **nameArray: Array of column name strings.
  • SDDS_NAMES_STRING:
    • char *names: Comma-separated string of column names.
  • SDDS_NAME_STRINGS:
    • char *name1, char *name2, ..., NULL: Individual column name strings terminated by NULL.
  • SDDS_MATCH_STRING:
    • char *pattern: Pattern string to match column names (supports wildcards).
    • int32_t logic_mode: Logic mode for matching (e.g., AND, OR).
Returns
  • 1 on successful update of column flags.
  • 0 on failure, with an error message recorded (e.g., invalid mode, memory issues, unrecognized column names).
Note
  • When using SDDS_MATCH_STRING, the pattern may include wildcards to match multiple column names.
  • Ensure that column names provided exist within the dataset to avoid errors.
See also
SDDS_SetColumnFlags, SDDS_AssertColumnFlags, SDDS_GetColumnFlags

Definition at line 432 of file SDDS_extract.c.

439{
440 va_list argptr;
441 int32_t i, j, index, n_names;
442 int32_t retval;
443 /* int32_t type; */
444 char **name, *string, *match_string, *ptr;
445 int32_t local_memory; /* (0,1,2) --> (none, pointer array, pointer array + strings) locally allocated */
446 char buffer[SDDS_MAXLINE];
447 int32_t logic;
448
449 name = NULL;
450 n_names = local_memory = logic = 0;
451
452 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnsOfInterest"))
453 return (0);
454 if ((!SDDS_dataset->column_flag || !SDDS_dataset->column_order) && !SDDS_AllocateColumnFlags(SDDS_dataset))
455 return 0;
456 va_start(argptr, mode);
457 retval = -1;
458 match_string = NULL;
459 switch (mode) {
460 case SDDS_NAME_ARRAY:
461 local_memory = 0;
462 n_names = va_arg(argptr, int32_t);
463 name = va_arg(argptr, char **);
464 break;
465 case SDDS_NAMES_STRING:
466 local_memory = 2;
467 n_names = 0;
468 name = NULL;
469 ptr = va_arg(argptr, char *);
470 SDDS_CopyString(&string, ptr);
471 while ((ptr = strchr(string, ',')))
472 *ptr = ' ';
473 while (SDDS_GetToken(string, buffer, SDDS_MAXLINE) > 0) {
474 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1))) || !SDDS_CopyString(name + n_names, buffer)) {
475 SDDS_SetError("Unable to process column selection--memory allocation failure (SDDS_SetColumnsOfInterest)");
476 retval = 0;
477 break;
478 }
479 n_names++;
480 }
481 free(string);
482 break;
483 case SDDS_NAME_STRINGS:
484 local_memory = 1;
485 n_names = 0;
486 name = NULL;
487 while ((string = va_arg(argptr, char *))) {
488 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1)))) {
489 SDDS_SetError("Unable to process column selection--memory allocation failure (SDDS_SetColumnsOfInterest)");
490 retval = 0;
491 break;
492 }
493 name[n_names++] = string;
494 }
495 break;
496 case SDDS_MATCH_STRING:
497 local_memory = 0;
498 n_names = 1;
499 if (!(string = va_arg(argptr, char *))) {
500 SDDS_SetError("Unable to process column selection--invalid matching string (SDDS_SetColumnsOfInterest)");
501 retval = 0;
502 break;
503 }
504 match_string = expand_ranges(string);
505 logic = va_arg(argptr, int32_t);
506 break;
507 default:
508 SDDS_SetError("Unable to process column selection--unknown mode (SDDS_SetColumnsOfInterest)");
509 retval = 0;
510 break;
511 }
512
513 va_end(argptr);
514 if (retval != -1)
515 return (retval);
516
517 if (n_names == 0) {
518 SDDS_SetError("Unable to process column selection--no names in call (SDDS_SetColumnsOfInterest)");
519 return (0);
520 }
521 if (!SDDS_dataset->column_order) {
522 SDDS_SetError("Unable to process column selection--'column_order' array in SDDS_DATASET is NULL (SDDS_SetColumnsOfInterest)");
523 return (0);
524 }
525
526 if (mode != SDDS_MATCH_STRING) {
527 for (i = 0; i < n_names; i++) {
528 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name[i])) < 0) {
529 sprintf(buffer, "Unable to process column selection--unrecognized column name %s seen (SDDS_SetColumnsOfInterest)", name[i]);
530 SDDS_SetError(buffer);
531 return (0);
532 }
533 for (j = 0; j < SDDS_dataset->n_of_interest; j++)
534 if (index == SDDS_dataset->column_order[j])
535 break;
536 if (j == SDDS_dataset->n_of_interest) {
537 SDDS_dataset->column_flag[index] = 1;
538 SDDS_dataset->column_order[j] = index;
539 SDDS_dataset->n_of_interest++;
540 }
541 }
542 } else {
543 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
544 if (SDDS_Logic(SDDS_dataset->column_flag[i], wild_match(SDDS_dataset->layout.column_definition[i].name, match_string), logic)) {
545#if defined(DEBUG)
546 fprintf(stderr, "logic match of %s to %s\n", SDDS_dataset->layout.column_definition[i].name, match_string);
547#endif
548 for (j = 0; j < SDDS_dataset->n_of_interest; j++)
549 if (i == SDDS_dataset->column_order[j])
550 break;
551 if (j == SDDS_dataset->n_of_interest) {
552 SDDS_dataset->column_flag[i] = 1;
553 SDDS_dataset->column_order[j] = i;
554 SDDS_dataset->n_of_interest++;
555 }
556 } else {
557#if defined(DEBUG)
558 fprintf(stderr, "no logic match of %s to %s\n", SDDS_dataset->layout.column_definition[i].name, match_string);
559#endif
560 SDDS_dataset->column_flag[i] = 0;
561 for (j = 0; j < SDDS_dataset->n_of_interest; j++)
562 if (i == SDDS_dataset->column_order[j])
563 break;
564 if (j != SDDS_dataset->n_of_interest) {
565 for (j++; j < SDDS_dataset->n_of_interest; j++)
566 SDDS_dataset->column_order[j - 1] = SDDS_dataset->column_order[j];
567 }
568 }
569 }
570 free(match_string);
571 }
572
573#if defined(DEBUG)
574 for (i = 0; i < SDDS_dataset->n_of_interest; i++)
575 fprintf(stderr, "column %" PRId32 " will be %s\n", i, SDDS_dataset->layout.column_definition[SDDS_dataset->column_order[i]].name);
576#endif
577
578 if (local_memory == 2) {
579 for (i = 0; i < n_names; i++)
580 free(name[i]);
581 }
582 if (local_memory >= 1)
583 free(name);
584
585 return (1);
586}

◆ SDDS_SetColumnUnitsConversion()

epicsShareFuncSDDS int32_t SDDS_SetColumnUnitsConversion ( SDDS_DATASET * SDDS_dataset,
char * column_name,
char * new_units,
char * old_units,
double factor )
extern

Sets unit conversions for a specified column in an SDDS dataset.

This function updates the units of the specified column within the SDDS dataset and applies a conversion factor to all its elements if the dataset has already been read (i.e., pages_read > 0). The function ensures that the new units are consistent with the old units if provided.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
column_nameA null-terminated string specifying the name of the column to update.
new_unitsA null-terminated string specifying the new units to assign to the column. This parameter must not be NULL.
old_unitsA null-terminated string specifying the expected current units of the column. If NULL, the function does not verify the existing units.
factorA double representing the conversion factor to apply to each element of the column. Each element will be multiplied by this factor.
Returns
Returns 1 on successful unit conversion and update. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the unit conversion was successfully applied.
0Indicates that an error occurred (e.g., invalid dataset, unrecognized column name, type undefined, memory allocation failure).
Note
  • The new_units parameter must not be NULL. Passing NULL will result in an error.
  • If the dataset has not been read yet (pages_read == 0), the conversion factor is stored but not applied immediately.
  • The function handles various data types, ensuring that the conversion factor is appropriately applied based on the column's type.
See also
SDDS_SetArrayUnitsConversion, SDDS_SetParameterUnitsConversion, SDDS_GetColumn

Definition at line 4788 of file SDDS_extract.c.

4788 {
4789 int32_t index, type;
4790 int64_t i;
4791 void *rawData;
4792 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnUnitsConversion"))
4793 return(0);
4794 if (new_units == NULL) {
4795 SDDS_SetError("new_units is NULL (SDDS_SetColumnUnitsConversion)");
4796 return(0);
4797 }
4798 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
4799 SDDS_SetError("Unable to get column--name is not recognized (SDDS_SetColumnUnitsConversion)");
4800 return(0);
4801 }
4802 if (!(type = SDDS_GetColumnType(SDDS_dataset, index))) {
4803 SDDS_SetError("Unable to get column--data type undefined (SDDS_SetColumnUnitsConversion)");
4804 return(0);
4805 }
4806 if (SDDS_dataset->layout.column_definition[index].units != NULL) {
4807 if (strcmp(new_units, SDDS_dataset->layout.column_definition[index].units) != 0) {
4808 if ((old_units != NULL) && (strcmp(old_units, SDDS_dataset->layout.column_definition[index].units) != 0)) {
4809 SDDS_SetError("Unexpected units value found (SDDS_SetColumnUnitsConversion)");
4810 return(0);
4811 }
4812 free(SDDS_dataset->layout.column_definition[index].units);
4813 cp_str(&(SDDS_dataset->original_layout.column_definition[index].units), new_units);
4814 cp_str(&(SDDS_dataset->layout.column_definition[index].units), new_units);
4815 }
4816 } else {
4817 cp_str(&(SDDS_dataset->original_layout.column_definition[index].units), new_units);
4818 cp_str(&(SDDS_dataset->layout.column_definition[index].units), new_units);
4819 }
4820
4821 if (SDDS_dataset->pages_read == 0) {
4822 return(1);
4823 }
4824 rawData = SDDS_dataset->data[index];
4825 switch (type) {
4826 case SDDS_LONGDOUBLE:
4827 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4828 ((long double *)rawData)[i] *= factor;
4829 }
4830 break;
4831 case SDDS_DOUBLE:
4832 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4833 ((double *)rawData)[i] *= factor;
4834 }
4835 break;
4836 case SDDS_FLOAT:
4837 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4838 ((float *)rawData)[i] *= factor;
4839 }
4840 break;
4841 case SDDS_LONG:
4842 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4843 ((int32_t *)rawData)[i] *= factor;
4844 }
4845 break;
4846 case SDDS_ULONG:
4847 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4848 ((uint32_t *)rawData)[i] *= factor;
4849 }
4850 break;
4851 case SDDS_LONG64:
4852 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4853 ((int64_t *)rawData)[i] *= factor;
4854 }
4855 break;
4856 case SDDS_ULONG64:
4857 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4858 ((uint64_t *)rawData)[i] *= factor;
4859 }
4860 break;
4861 case SDDS_SHORT:
4862 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4863 ((short *)rawData)[i] *= factor;
4864 }
4865 break;
4866 case SDDS_USHORT:
4867 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4868 ((unsigned short *)rawData)[i] *= factor;
4869 }
4870 break;
4871 }
4872 return(1);
4873}

◆ SDDS_SetDataMode()

epicsShareFuncSDDS int32_t SDDS_SetDataMode ( SDDS_DATASET * SDDS_dataset,
int32_t newmode )
extern

Sets the data mode (ASCII or Binary) for the SDDS dataset.

This function configures the data mode of the SDDS dataset to either ASCII or Binary. When setting to Binary mode with byte swapping (using -SDDS_BINARY), it adjusts the byte order based on the machine's endianness to ensure compatibility.

Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset whose data mode is to be set.
[in]newmodeThe desired data mode. Valid values are:
  • SDDS_ASCII for ASCII mode.
  • SDDS_BINARY for Binary mode.
  • -SDDS_BINARY for Binary mode with byte swapping (for compatibility with systems like the sddsendian program).
Returns
  • 1 on successful mode change.
  • 0 if the mode is invalid, if the dataset is NULL, or if the dataset has already been written to and the mode cannot be changed.
Note
  • Changing the data mode is only permitted if no data has been written to the dataset (i.e., page_number is 0 and n_rows_written is 0).
  • When using -SDDS_BINARY, the function automatically determines the appropriate byte order based on the machine's endianness.
Warning
  • Attempting to change the data mode after writing data to the dataset will result in an error.
  • Ensure that the newmode parameter is correctly specified to prevent unintended behavior.
See also
SDDS_SetError, SDDS_IsBigEndianMachine, SDDS_BINARY, SDDS_ASCII

Definition at line 4932 of file SDDS_utils.c.

4932 {
4933 if (newmode == -SDDS_BINARY) {
4934 /* will write with bytes swapped.
4935 * provided for compatibility with sddsendian program, which writes the
4936 * data itself
4937 */
4938 SDDS_dataset->layout.byteOrderDeclared = SDDS_IsBigEndianMachine() ? SDDS_LITTLEENDIAN : SDDS_BIGENDIAN;
4939 newmode = SDDS_BINARY;
4940 }
4941 if (newmode != SDDS_ASCII && newmode != SDDS_BINARY) {
4942 SDDS_SetError("Invalid data mode (SDDS_SetDataMode)");
4943 return 0;
4944 }
4945 if (newmode == SDDS_dataset->layout.data_mode.mode)
4946 return 1;
4947 if (!SDDS_dataset) {
4948 SDDS_SetError("NULL page pointer (SDDS_SetDataMode)");
4949 return 0;
4950 }
4951 if (SDDS_dataset->page_number != 0 && (SDDS_dataset->page_number > 1 || SDDS_dataset->n_rows_written != 0)) {
4952 SDDS_SetError("Can't change the mode of a file that's been written to (SDDS_SetDataMode)");
4953 return 0;
4954 }
4955 SDDS_dataset->layout.data_mode.mode = SDDS_dataset->original_layout.data_mode.mode = newmode;
4956 return 1;
4957}

◆ SDDS_SetDefaultIOBufferSize()

epicsShareFuncSDDS int32_t SDDS_SetDefaultIOBufferSize ( int32_t newValue)
extern

Sets the default I/O buffer size used for file operations.

This function updates the global defaultIOBufferSize variable, which determines the size of the I/O buffer used for file read/write operations. The initial default is SDDS_FILEBUFFER_SIZE, which is 262144 bytes.

Parameters
newValueThe new default I/O buffer size in bytes. If newValue is negative, the function returns the current buffer size without changing it. If newValue is between 0 and 128 (inclusive), it is treated as 0, effectively disabling buffering.
Returns
The previous default I/O buffer size if newValue is greater than or equal to 0; otherwise, returns the current default buffer size without changing it.

Definition at line 66 of file SDDS_binary.c.

66 {
67 int32_t previous;
68 if (newValue < 0)
69 return defaultIOBufferSize;
70 if (newValue < 128) /* arbitrary limit */
71 newValue = 0;
72 previous = defaultIOBufferSize;
73 defaultIOBufferSize = newValue;
74 return previous;
75}

◆ SDDS_SetError()

epicsShareFuncSDDS void SDDS_SetError ( char * error_text)
extern

Records an error message in the SDDS error stack.

This function appends an error message to the internal error stack. These errors can later be retrieved and displayed using SDDS_PrintErrors.

Parameters
[in]error_textThe error message to be recorded. If NULL, a warning is printed to stderr.
See also
SDDS_PrintErrors
SDDS_ClearErrors

Definition at line 379 of file SDDS_utils.c.

379 {
380 SDDS_SetError0(error_text);
381 SDDS_SetError0("\n");
382}

◆ SDDS_SetError0()

epicsShareFuncSDDS void SDDS_SetError0 ( char * error_text)
extern

Internal function to record an error message in the SDDS error stack.

This function appends an error message to the internal error stack without adding additional formatting or line breaks. It is typically called by SDDS_SetError.

Parameters
[in]error_textThe error message to be recorded. If NULL, a warning is printed to stderr.
Note
This function is intended for internal use within the SDDS library and should not be called directly by user code.
See also
SDDS_SetError

Definition at line 395 of file SDDS_utils.c.

395 {
396 if (n_errors >= n_errors_max) {
397 if (!(error_description = SDDS_Realloc(error_description, (n_errors_max += 10) * sizeof(*error_description)))) {
398 fputs("Error trying to allocate additional error description string (SDDS_SetError)\n", stderr);
399 fprintf(stderr, "Most recent error text:\n%s\n", error_text);
400 abort();
401 }
402 }
403 if (!error_text)
404 fprintf(stderr, "warning: error text is NULL (SDDS_SetError)\n");
405 else {
406 if (!SDDS_CopyString(&error_description[n_errors], error_text)) {
407 fputs("Error trying to copy additional error description text (SDDS_SetError)\n", stderr);
408 fprintf(stderr, "Most recent error text: %s\n", error_text);
409 abort();
410 }
411 n_errors++;
412 }
413}

◆ SDDS_SetMemory()

epicsShareFuncSDDS int32_t SDDS_SetMemory ( void * mem,
int64_t n_elements,
int32_t data_type,
... )
extern

Initializes a memory block with a sequence of values based on a specified data type.

This function sets a block of memory to a sequence of values, starting from a specified initial value and incrementing by a defined delta. The sequence is determined by the data_type parameter, which specifies the type of each element in the memory block. The function supports various SDDS data types and handles the initialization accordingly.

Parameters
[in,out]memPointer to the memory block to be initialized.
[in]n_elementsThe number of elements to initialize in the memory block.
[in]data_typeThe SDDS data type of each element. Must be one of the following constants:
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_LONG64
  • SDDS_ULONG64
  • SDDS_FLOAT
  • SDDS_DOUBLE
  • SDDS_LONGDOUBLE
  • SDDS_CHARACTER
[in]...Variable arguments specifying the starting value and increment value. The types of these arguments depend on the data_type:
  • For integer types (SDDS_SHORT, SDDS_USHORT, SDDS_LONG, SDDS_ULONG, SDDS_LONG64, SDDS_ULONG64):
    • First argument: initial value (int, unsigned int, int32_t, uint32_t, int64_t, uint64_t)
    • Second argument: increment value (int, unsigned int, int32_t, uint32_t, int64_t, uint64_t)
  • For floating-point types (SDDS_FLOAT, SDDS_DOUBLE, SDDS_LONGDOUBLE):
    • First argument: initial value (double for float and double, long double for SDDS_LONGDOUBLE)
    • Second argument: increment value (double for float and double, long double for SDDS_LONGDOUBLE)
  • For SDDS_CHARACTER:
    • First argument: initial value (char)
    • Second argument: increment value (short)
Returns
Returns 1 on successful memory initialization. Returns 0 if an unknown or invalid data_type is provided.
Note
The function uses variable arguments to accept the starting and increment values. The caller must ensure that the correct types are provided based on the data_type parameter.
See also
SDDS_Malloc
SDDS_Free

Definition at line 2039 of file SDDS_utils.c.

2041{
2042 va_list argptr;
2043 int32_t retval;
2044 int64_t i;
2045 short short_val, short_dval, *short_ptr;
2046 unsigned short ushort_val, ushort_dval, *ushort_ptr;
2047 int32_t long_val, long_dval, *long_ptr;
2048 uint32_t ulong_val, ulong_dval, *ulong_ptr;
2049 int64_t long64_val, long64_dval, *long64_ptr;
2050 uint64_t ulong64_val, ulong64_dval, *ulong64_ptr;
2051 float float_val, float_dval, *float_ptr;
2052 double double_val, double_dval, *double_ptr;
2053 long double longdouble_val, longdouble_dval, *longdouble_ptr;
2054 char char_val, *char_ptr;
2055
2056 retval = 1;
2057 va_start(argptr, data_type);
2058 switch (data_type) {
2059 case SDDS_SHORT:
2060 short_val = (short)va_arg(argptr, int);
2061 short_dval = (short)va_arg(argptr, int);
2062 short_ptr = (short *)mem;
2063 for (i = 0; i < n_elements; i++, short_val += short_dval)
2064 *short_ptr++ = short_val;
2065 break;
2066 case SDDS_USHORT:
2067 ushort_val = (unsigned short)va_arg(argptr, int);
2068 ushort_dval = (unsigned short)va_arg(argptr, int);
2069 ushort_ptr = (unsigned short *)mem;
2070 for (i = 0; i < n_elements; i++, ushort_val += ushort_dval)
2071 *ushort_ptr++ = ushort_val;
2072 break;
2073 case SDDS_LONG:
2074 long_val = (int32_t)va_arg(argptr, int32_t);
2075 long_dval = (int32_t)va_arg(argptr, int32_t);
2076 long_ptr = (int32_t *)mem;
2077 for (i = 0; i < n_elements; i++, long_val += long_dval)
2078 *long_ptr++ = long_val;
2079 break;
2080 case SDDS_ULONG:
2081 ulong_val = (uint32_t)va_arg(argptr, uint32_t);
2082 ulong_dval = (uint32_t)va_arg(argptr, uint32_t);
2083 ulong_ptr = (uint32_t *)mem;
2084 for (i = 0; i < n_elements; i++, ulong_val += ulong_dval)
2085 *ulong_ptr++ = ulong_val;
2086 break;
2087 case SDDS_LONG64:
2088 long64_val = (int64_t)va_arg(argptr, int64_t);
2089 long64_dval = (int64_t)va_arg(argptr, int64_t);
2090 long64_ptr = (int64_t *)mem;
2091 for (i = 0; i < n_elements; i++, long64_val += long64_dval)
2092 *long64_ptr++ = long64_val;
2093 break;
2094 case SDDS_ULONG64:
2095 ulong64_val = (uint64_t)va_arg(argptr, uint32_t);
2096 ulong64_dval = (uint64_t)va_arg(argptr, uint32_t);
2097 ulong64_ptr = (uint64_t *)mem;
2098 for (i = 0; i < n_elements; i++, ulong64_val += ulong64_dval)
2099 *ulong64_ptr++ = ulong64_val;
2100 break;
2101 case SDDS_FLOAT:
2102 float_val = (float)va_arg(argptr, double);
2103 float_dval = (float)va_arg(argptr, double);
2104 float_ptr = (float *)mem;
2105 for (i = 0; i < n_elements; i++, float_val += float_dval)
2106 *float_ptr++ = float_val;
2107 break;
2108 case SDDS_DOUBLE:
2109 double_val = (double)va_arg(argptr, double);
2110 double_dval = (double)va_arg(argptr, double);
2111 double_ptr = (double *)mem;
2112 for (i = 0; i < n_elements; i++, double_val += double_dval)
2113 *double_ptr++ = double_val;
2114 break;
2115 case SDDS_LONGDOUBLE:
2116 longdouble_val = (long double)va_arg(argptr, long double);
2117 longdouble_dval = (long double)va_arg(argptr, long double);
2118 longdouble_ptr = (long double *)mem;
2119 for (i = 0; i < n_elements; i++, longdouble_val += longdouble_dval)
2120 *longdouble_ptr++ = longdouble_val;
2121 break;
2122 case SDDS_CHARACTER:
2123 char_val = (char)va_arg(argptr, int);
2124 short_dval = (short)va_arg(argptr, int);
2125 char_ptr = (char *)mem;
2126 for (i = 0; i < n_elements; i++, char_val += short_dval)
2127 *char_ptr++ = char_val;
2128 break;
2129 default:
2130 SDDS_SetError("Unable to set memory--unknown or invalid data type (SDDS_SetMemory)");
2131 retval = 0;
2132 break;
2133 }
2134 va_end(argptr);
2135 return (retval);
2136}

◆ SDDS_SetNameValidityFlags()

epicsShareFuncSDDS int32_t SDDS_SetNameValidityFlags ( uint32_t flags)
extern

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

epicsShareFuncSDDS int32_t SDDS_SetNoRowCounts ( SDDS_DATASET * SDDS_dataset,
int32_t value )
extern

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

epicsShareFuncSDDS int32_t SDDS_SetParameter ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Sets the value of a single parameter in the current data table of an SDDS dataset.

This function assigns a value to a specified parameter in the current data table of the given SDDS dataset. It must be preceded by a call to SDDS_StartPage to initialize the table. The parameter to be set can be identified either by its index or by its name. The value can be passed either by value or by reference, depending on the specified mode.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeA bitwise combination of the following constants:
  • SDDS_SET_BY_INDEX: Identify the parameter by its index.
  • SDDS_SET_BY_NAME: Identify the parameter by its name.
  • SDDS_PASS_BY_VALUE: Pass the parameter value by value.
  • SDDS_PASS_BY_REFERENCE: Pass the parameter value by reference.

Mode Requirements:

  • Exactly one of SDDS_SET_BY_INDEX or SDDS_SET_BY_NAME must be set.
  • Exactly one of SDDS_PASS_BY_VALUE or SDDS_PASS_BY_REFERENCE must be set.

Syntax Based on Mode Combination:

  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_VALUE: int32_t SDDS_SetParameter(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t index, value)
  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetParameter(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t index, void *data)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_VALUE: int32_t SDDS_SetParameter(SDDS_DATASET *SDDS_dataset, int32_t mode, char *name, value)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetParameter(SDDS_DATASET *SDDS_dataset, int32_t mode, char *name, void *data)

Note: For parameters of type SDDS_STRING, passing by value means passing a char *, whereas passing by reference means passing a char **.

Returns
Returns 1 on successful assignment of the parameter value. On failure, returns 0 and records an appropriate error message.
See also
SDDS_StartPage, SDDS_SetError, SDDS_GetParameterIndex, SDDS_CopyString

Definition at line 533 of file SDDS_dataprep.c.

533 {
534 va_list argptr;
535 int32_t index;
536 SDDS_LAYOUT *layout;
537 char *name;
538 char s[SDDS_MAXLINE];
539
540 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetParameters"))
541 return (0);
542 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
543 SDDS_SetError("Unable to set parameter values--unknown mode (SDDS_SetParameters)");
544 return (0);
545 }
546
547 va_start(argptr, mode);
548 layout = &SDDS_dataset->layout;
549
550 /* variable arguments are pairs of (index, value), where index is a int32_t integer */
551 if (mode & SDDS_SET_BY_INDEX) {
552 if ((index = va_arg(argptr, int32_t)) == -1) {
553 SDDS_SetError("Unable to set parameter values--index is null (SDDS_SetParameter)");
554 va_end(argptr);
555 return (0);
556 }
557 if (index < 0 || index >= layout->n_parameters) {
558 SDDS_SetError("Unable to set parameter values--index out of range (SDDS_SetParameter)");
559 va_end(argptr);
560 return (0);
561 }
562 } else {
563 if ((name = va_arg(argptr, char *)) == NULL) {
564 SDDS_SetError("Unable to set parameter values--name is null (SDDS_SetParameter)");
565 va_end(argptr);
566 return (0);
567 }
568 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) < 0) {
569 sprintf(s, "Unable to set parameter values--name %s not recognized (SDDS_SetParameter)", name);
570 SDDS_SetError(s);
571 va_end(argptr);
572 return (0);
573 }
574 }
575 switch (layout->parameter_definition[index].type) {
576 case SDDS_SHORT:
577 if (mode & SDDS_PASS_BY_VALUE)
578 *((short *)SDDS_dataset->parameter[index]) = (short)va_arg(argptr, int);
579 else
580 *((short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, short *));
581 break;
582 case SDDS_USHORT:
583 if (mode & SDDS_PASS_BY_VALUE)
584 *((unsigned short *)SDDS_dataset->parameter[index]) = (unsigned short)va_arg(argptr, unsigned int);
585 else
586 *((unsigned short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, unsigned short *));
587 break;
588 case SDDS_LONG:
589 if (mode & SDDS_PASS_BY_VALUE)
590 *((int32_t *)SDDS_dataset->parameter[index]) = (int32_t)va_arg(argptr, int32_t);
591 else
592 *((int32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int32_t *));
593 break;
594 case SDDS_ULONG:
595 if (mode & SDDS_PASS_BY_VALUE)
596 *((uint32_t *)SDDS_dataset->parameter[index]) = (uint32_t)va_arg(argptr, uint32_t);
597 else
598 *((uint32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint32_t *));
599 break;
600 case SDDS_LONG64:
601 if (mode & SDDS_PASS_BY_VALUE)
602 *((int64_t *)SDDS_dataset->parameter[index]) = (int64_t)va_arg(argptr, int64_t);
603 else
604 *((int64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int64_t *));
605 break;
606 case SDDS_ULONG64:
607 if (mode & SDDS_PASS_BY_VALUE)
608 *((uint64_t *)SDDS_dataset->parameter[index]) = (uint64_t)va_arg(argptr, uint64_t);
609 else
610 *((uint64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint64_t *));
611 break;
612 case SDDS_FLOAT:
613 if (mode & SDDS_PASS_BY_VALUE)
614 *((float *)SDDS_dataset->parameter[index]) = (float)va_arg(argptr, double);
615 else
616 *((float *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, float *));
617 break;
618 case SDDS_DOUBLE:
619 if (mode & SDDS_PASS_BY_VALUE)
620 *((double *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
621 else
622 *((double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
623 break;
624 case SDDS_LONGDOUBLE:
625 if (mode & SDDS_PASS_BY_VALUE)
626 *((long double *)SDDS_dataset->parameter[index]) = va_arg(argptr, long double);
627 else
628 *((long double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, long double *));
629 break;
630 case SDDS_STRING:
631 if (*(char **)SDDS_dataset->parameter[index])
632 free(*(char **)SDDS_dataset->parameter[index]);
633 if (mode & SDDS_PASS_BY_VALUE) {
634 if (!SDDS_CopyString((char **)SDDS_dataset->parameter[index], va_arg(argptr, char *))) {
635 SDDS_SetError("Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
636 va_end(argptr);
637 return (0);
638 }
639 } else {
640 if (!SDDS_CopyString((char **)SDDS_dataset->parameter[index], *(va_arg(argptr, char **)))) {
641 SDDS_SetError("Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
642 va_end(argptr);
643 return (0);
644 }
645 }
646 break;
647 case SDDS_CHARACTER:
648 if (mode & SDDS_PASS_BY_VALUE)
649 *((char *)SDDS_dataset->parameter[index]) = (char)va_arg(argptr, int);
650 else
651 *((char *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, char *));
652 break;
653 default:
654 SDDS_SetError("Unknown data type encountered (SDDS_SetParameters)");
655 va_end(argptr);
656 return (0);
657 }
658 va_end(argptr);
659 return (1);
660}

◆ SDDS_SetParameters()

epicsShareFuncSDDS int32_t SDDS_SetParameters ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Sets the values of one or more parameters for the current data table in an SDDS dataset.

This function assigns values to parameters in the current data table of the specified SDDS dataset. It must be preceded by a call to SDDS_StartPage to initialize the table. The function can be called multiple times to set parameters for different tables, but SDDS_WriteTable should be used to write each table to disk.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeA bitwise combination of the following constants:
  • SDDS_SET_BY_INDEX: Specify parameters by their index.
  • SDDS_SET_BY_NAME: Specify parameters by their name.
  • SDDS_PASS_BY_VALUE: Pass parameter values by value.
  • SDDS_PASS_BY_REFERENCE: Pass parameter values by reference.

Exactly one of SDDS_SET_BY_INDEX or SDDS_SET_BY_NAME must be set to indicate how parameters are identified. Additionally, exactly one of SDDS_PASS_BY_VALUE or SDDS_PASS_BY_REFERENCE must be set to indicate how parameter values are provided.

The syntax for the four possible mode combinations is as follows:

  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_VALUE: int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t index1, value1, int32_t index2, value2, ..., -1)
  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t index1, void *data1, int32_t index2, void *data2, ..., -1)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_VALUE: int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode, char *name1, value1, char *name2, value2, ..., NULL)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode, char *name1, void *data1, char *name2, void *data2, ..., NULL)

Note: For parameters of type SDDS_STRING, passing by value means passing a char *, whereas passing by reference means passing a char **.

Returns
Returns 1 on success. On failure, returns 0 and records an error message.
See also
SDDS_StartPage, SDDS_WriteTable, SDDS_SetError, SDDS_GetParameterIndex, va_start, va_arg, va_end

Definition at line 369 of file SDDS_dataprep.c.

369 {
370 va_list argptr;
371 int32_t index, retval;
372 SDDS_LAYOUT *layout;
373 char *name;
374 char s[SDDS_MAXLINE];
375
376 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetParameters"))
377 return (0);
378 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
379 SDDS_SetError("Unable to set parameter values--unknown mode (SDDS_SetParameters)");
380 return (0);
381 }
382
383 va_start(argptr, mode);
384 layout = &SDDS_dataset->layout;
385
386 /* variable arguments are pairs of (index, value), where index is a int32_t integer */
387 retval = -1;
388 do {
389 if (mode & SDDS_SET_BY_INDEX) {
390 if ((index = va_arg(argptr, int32_t)) == -1) {
391 retval = 1;
392 break;
393 }
394 if (index < 0 || index >= layout->n_parameters) {
395 SDDS_SetError("Unable to set parameter values--index out of range (SDDS_SetParameters)");
396 retval = 0;
397 break;
398 }
399 } else {
400 if ((name = va_arg(argptr, char *)) == NULL) {
401 retval = 1;
402 break;
403 }
404 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) < 0) {
405 sprintf(s, "Unable to set parameter values--name %s not recognized (SDDS_SetParameters)", name);
406 SDDS_SetError(s);
407 retval = 0;
408 break;
409 }
410 }
411 switch (layout->parameter_definition[index].type) {
412 case SDDS_SHORT:
413 if (mode & SDDS_PASS_BY_VALUE)
414 *((short *)SDDS_dataset->parameter[index]) = (short)va_arg(argptr, int);
415 else
416 *((short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, short *));
417 break;
418 case SDDS_USHORT:
419 if (mode & SDDS_PASS_BY_VALUE)
420 *((unsigned short *)SDDS_dataset->parameter[index]) = (unsigned short)va_arg(argptr, unsigned int);
421 else
422 *((unsigned short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, unsigned short *));
423 break;
424 case SDDS_LONG:
425 if (mode & SDDS_PASS_BY_VALUE)
426 *((int32_t *)SDDS_dataset->parameter[index]) = (int32_t)va_arg(argptr, int32_t);
427 else
428 *((int32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int32_t *));
429 break;
430 case SDDS_ULONG:
431 if (mode & SDDS_PASS_BY_VALUE)
432 *((uint32_t *)SDDS_dataset->parameter[index]) = (uint32_t)va_arg(argptr, uint32_t);
433 else
434 *((uint32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint32_t *));
435 break;
436 case SDDS_LONG64:
437 if (mode & SDDS_PASS_BY_VALUE)
438 *((int64_t *)SDDS_dataset->parameter[index]) = (int64_t)va_arg(argptr, int64_t);
439 else
440 *((int64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int64_t *));
441 break;
442 case SDDS_ULONG64:
443 if (mode & SDDS_PASS_BY_VALUE)
444 *((uint64_t *)SDDS_dataset->parameter[index]) = (uint64_t)va_arg(argptr, uint64_t);
445 else
446 *((uint64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint64_t *));
447 break;
448 case SDDS_FLOAT:
449 if (mode & SDDS_PASS_BY_VALUE)
450 *((float *)SDDS_dataset->parameter[index]) = (float)va_arg(argptr, double);
451 else
452 *((float *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, float *));
453 break;
454 case SDDS_DOUBLE:
455 if (mode & SDDS_PASS_BY_VALUE)
456 *((double *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
457 else
458 *((double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
459 break;
460 case SDDS_LONGDOUBLE:
461 if (mode & SDDS_PASS_BY_VALUE)
462 *((long double *)SDDS_dataset->parameter[index]) = va_arg(argptr, long double);
463 else
464 *((long double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, long double *));
465 break;
466 case SDDS_STRING:
467 if (*(char **)SDDS_dataset->parameter[index])
468 free(*(char **)SDDS_dataset->parameter[index]);
469 if (mode & SDDS_PASS_BY_VALUE) {
470 if (!SDDS_CopyString((char **)SDDS_dataset->parameter[index], va_arg(argptr, char *))) {
471 SDDS_SetError("Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
472 retval = 0;
473 }
474 } else {
475 if (!SDDS_CopyString((char **)SDDS_dataset->parameter[index], *(va_arg(argptr, char **)))) {
476 SDDS_SetError("Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
477 retval = 0;
478 }
479 }
480 break;
481 case SDDS_CHARACTER:
482 if (mode & SDDS_PASS_BY_VALUE)
483 *((char *)SDDS_dataset->parameter[index]) = (char)va_arg(argptr, int);
484 else
485 *((char *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, char *));
486 break;
487 default:
488 SDDS_SetError("Unknown data type encountered (SDDS_SetParameters)");
489 retval = 0;
490 }
491 } while (retval == -1);
492 va_end(argptr);
493 return (retval);
494}

◆ SDDS_SetParametersFromDoubles()

epicsShareFuncSDDS int32_t SDDS_SetParametersFromDoubles ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Sets the values of one or more parameters in the current data table of an SDDS dataset using double-precision floating-point numbers.

This function assigns double-precision floating-point values to specified parameters in the current data table of the given SDDS dataset. It must be preceded by a call to SDDS_StartPage to initialize the table. Parameters can be identified either by their index or by their name. The values can be passed either by value or by reference, depending on the specified mode.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeA bitwise combination of the following constants:
  • SDDS_SET_BY_INDEX: Identify parameters by their indices.
  • SDDS_SET_BY_NAME: Identify parameters by their names.
  • SDDS_PASS_BY_VALUE: Pass parameter values by value.
  • SDDS_PASS_BY_REFERENCE: Pass parameter values by reference.

Mode Requirements:

  • Exactly one of SDDS_SET_BY_INDEX or SDDS_SET_BY_NAME must be set.
  • Exactly one of SDDS_PASS_BY_VALUE or SDDS_PASS_BY_REFERENCE must be set.

Syntax Based on Mode Combination:

  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_VALUE: int32_t SDDS_SetParametersFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t index, double value)
  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetParametersFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t index, double *data)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_VALUE: int32_t SDDS_SetParametersFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, char *name, double value)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetParametersFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, char *name, double *data)

Note: For parameters of type SDDS_STRING, setting values using this function is not supported and will result in an error.

Returns
Returns 1 on successful assignment of all specified parameter values. On failure, returns 0 and records an appropriate error message.
See also
SDDS_StartPage, SDDS_SetError, SDDS_GetParameterIndex

Definition at line 697 of file SDDS_dataprep.c.

697 {
698 va_list argptr;
699 int32_t index, retval;
700 SDDS_LAYOUT *layout;
701 char *name;
702 char s[SDDS_MAXLINE];
703
704 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetParametersFromDoubles"))
705 return (0);
706 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
707 SDDS_SetError("Unable to set parameter values--unknown mode (SDDS_SetParametersFromDoubles)");
708 return (0);
709 }
710
711 va_start(argptr, mode);
712 layout = &SDDS_dataset->layout;
713
714 /* variable arguments are pairs of (index, value), where index is a int32_t integer */
715 retval = -1;
716 do {
717 if (mode & SDDS_SET_BY_INDEX) {
718 if ((index = va_arg(argptr, int32_t)) == -1) {
719 retval = 1;
720 break;
721 }
722 if (index < 0 || index >= layout->n_parameters) {
723 sprintf(s, "Unable to set parameter values--index %" PRId32 " out of range [%d, %" PRId32 "] (SDDS_SetParametersFromDoubles)", index, 0, layout->n_parameters);
724 SDDS_SetError(s);
725 retval = 0;
726 break;
727 }
728 } else {
729 if ((name = va_arg(argptr, char *)) == NULL) {
730 retval = 1;
731 break;
732 }
733 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) < 0) {
734 sprintf(s, "Unable to set parameter values--name %s not recognized (SDDS_SetParametersFromDoubles)", name);
735 SDDS_SetError(s);
736 retval = 0;
737 break;
738 }
739 }
740 switch (layout->parameter_definition[index].type) {
741 case SDDS_SHORT:
742 if (mode & SDDS_PASS_BY_VALUE)
743 *((short *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
744 else
745 *((short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
746 break;
747 case SDDS_USHORT:
748 if (mode & SDDS_PASS_BY_VALUE)
749 *((unsigned short *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
750 else
751 *((unsigned short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
752 break;
753 case SDDS_LONG:
754 if (mode & SDDS_PASS_BY_VALUE)
755 *((int32_t *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
756 else
757 *((int32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
758 break;
759 case SDDS_ULONG:
760 if (mode & SDDS_PASS_BY_VALUE)
761 *((uint32_t *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
762 else
763 *((uint32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
764 break;
765 case SDDS_LONG64:
766 if (mode & SDDS_PASS_BY_VALUE)
767 *((int64_t *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
768 else
769 *((int64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
770 break;
771 case SDDS_ULONG64:
772 if (mode & SDDS_PASS_BY_VALUE)
773 *((uint64_t *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
774 else
775 *((uint64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
776 break;
777 case SDDS_FLOAT:
778 if (mode & SDDS_PASS_BY_VALUE)
779 *((float *)SDDS_dataset->parameter[index]) = (float)va_arg(argptr, double);
780 else
781 *((float *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
782 break;
783 case SDDS_DOUBLE:
784 if (mode & SDDS_PASS_BY_VALUE)
785 *((double *)SDDS_dataset->parameter[index]) = va_arg(argptr, double);
786 else
787 *((double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, double *));
788 break;
789 case SDDS_STRING:
790 case SDDS_CHARACTER:
791 SDDS_SetError("Nonnumeric data type encountered (SDDS_SetParametersFromDoubles)");
792 retval = 0;
793 break;
794 default:
795 SDDS_SetError("Unknown data type encountered (SDDS_SetParametersFromDoubles)");
796 retval = 0;
797 }
798 } while (retval == -1);
799 va_end(argptr);
800 return (retval);
801}

◆ SDDS_SetParameterUnitsConversion()

epicsShareFuncSDDS int32_t SDDS_SetParameterUnitsConversion ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
char * new_units,
char * old_units,
double factor )
extern

Sets unit conversions for a specified parameter in an SDDS dataset.

This function updates the units of the specified parameter within the SDDS dataset and applies a conversion factor to its value if the dataset has already been read (i.e., pages_read > 0). The function ensures that the new units are consistent with the old units if provided.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to update.
new_unitsA null-terminated string specifying the new units to assign to the parameter. This parameter must not be NULL.
old_unitsA null-terminated string specifying the expected current units of the parameter. If NULL, the function does not verify the existing units.
factorA double representing the conversion factor to apply to the parameter's value. The parameter's value will be multiplied by this factor.
Returns
Returns 1 on successful unit conversion and update. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the unit conversion was successfully applied.
0Indicates that an error occurred (e.g., invalid dataset, unrecognized parameter name, type undefined, memory allocation failure).
Note
  • The new_units parameter must not be NULL. Passing NULL will result in an error.
  • If the dataset has not been read yet (pages_read == 0), the conversion factor is stored but not applied immediately.
  • The function handles various data types, ensuring that the conversion factor is appropriately applied based on the parameter's type.
See also
SDDS_SetArrayUnitsConversion, SDDS_SetColumnUnitsConversion, SDDS_GetParameter

Definition at line 4903 of file SDDS_extract.c.

4903 {
4904 int32_t index, type;
4905 void *rawData;
4906 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetParameterUnitsConversion"))
4907 return(0);
4908 if (new_units == NULL) {
4909 SDDS_SetError("new_units is NULL (SDDS_SetParameterUnitsConversion)");
4910 return(0);
4911 }
4912 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
4913 SDDS_SetError("Unable to get parameter--name is not recognized (SDDS_SetParameterUnitsConversion)");
4914 return(0);
4915 }
4916 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
4917 SDDS_SetError("Unable to get parameter--data type undefined (SDDS_SetParameterUnitsConversion)");
4918 return(0);
4919 }
4920 if (SDDS_dataset->layout.parameter_definition[index].units != NULL) {
4921 if (strcmp(new_units, SDDS_dataset->layout.parameter_definition[index].units) != 0) {
4922 if ((old_units != NULL) && (strcmp(old_units, SDDS_dataset->layout.parameter_definition[index].units) != 0)) {
4923 SDDS_SetError("Unexpected units value found (SDDS_SetParameterUnitsConversion)");
4924 return(0);
4925 }
4926 /* free(SDDS_dataset->layout.parameter_definition[index].units); */
4927 cp_str(&(SDDS_dataset->layout.parameter_definition[index].units), new_units);
4928 }
4929 } else {
4930 cp_str(&(SDDS_dataset->layout.parameter_definition[index].units), new_units);
4931 }
4932
4933 if (SDDS_dataset->pages_read == 0) {
4934 return(1);
4935 }
4936 rawData = SDDS_dataset->parameter[index];
4937 switch (type) {
4938 case SDDS_LONGDOUBLE:
4939 *((long double *)rawData) *= factor;
4940 break;
4941 case SDDS_DOUBLE:
4942 *((double *)rawData) *= factor;
4943 break;
4944 case SDDS_FLOAT:
4945 *((float *)rawData) *= factor;
4946 break;
4947 case SDDS_LONG:
4948 *((int32_t *)rawData) *= factor;
4949 break;
4950 case SDDS_ULONG:
4951 *((uint32_t *)rawData) *= factor;
4952 break;
4953 case SDDS_LONG64:
4954 *((int64_t *)rawData) *= factor;
4955 break;
4956 case SDDS_ULONG64:
4957 *((uint64_t *)rawData) *= factor;
4958 break;
4959 case SDDS_SHORT:
4960 *((short *)rawData) *= factor;
4961 break;
4962 case SDDS_USHORT:
4963 *((unsigned short *)rawData) *= factor;
4964 break;
4965 }
4966 return(1);
4967}

◆ SDDS_SetReadRecoveryMode()

epicsShareFuncSDDS void SDDS_SetReadRecoveryMode ( SDDS_DATASET * SDDS_dataset,
int32_t mode )
extern

Sets the read recovery mode for an SDDS dataset.

This function configures whether read recovery is possible for the specified SDDS dataset. Enabling recovery allows the dataset to attempt to recover partial data in case of read errors.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
modeInteger flag indicating the recovery mode:
  • 0 to disable read recovery.
  • 1 to enable read recovery.

The function updates the readRecoveryPossible flag within the dataset structure based on the provided mode parameter. This flag is later checked by other functions to determine whether to attempt data recovery after encountering read errors.

Note
  • Enabling read recovery does not guarantee that all data can be recovered after an error.
  • It is recommended to enable recovery only if partial data recovery is acceptable in your application.

Definition at line 2082 of file SDDS_binary.c.

2082 {
2083 SDDS_dataset->readRecoveryPossible = mode;
2084}

◆ SDDS_SetRowCountMode()

epicsShareFuncSDDS int32_t SDDS_SetRowCountMode ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )
extern

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}

◆ SDDS_SetRowFlags()

epicsShareFuncSDDS int32_t SDDS_SetRowFlags ( SDDS_DATASET * SDDS_dataset,
int32_t row_flag_value )
extern

Sets the acceptance flags for all rows in the current data table of a data set.

This function initializes the acceptance flags for each row in the data table. A non-zero flag indicates that the row is "of interest" and should be considered in subsequent operations, while a zero flag marks the row for rejection.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
row_flag_valueInteger value to assign to all row flags.
  • Non-zero value: Marks rows as accepted ("of interest").
  • Zero value: Marks rows as rejected.
Returns
  • 1 on successful update of row flags.
  • 0 on failure, with an error message recorded.
Note
This function overwrites any existing row flags with the specified row_flag_value.
See also
SDDS_GetRowFlag, SDDS_GetRowFlags

Definition at line 46 of file SDDS_extract.c.

46 {
47 /* int32_t i; */
48 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowFlags"))
49 return (0);
50 if (!SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated, SDDS_LONG, (int32_t)row_flag_value, (int32_t)0)) {
51 SDDS_SetError("Unable to set row flags--memory filling failed (SDDS_SetRowFlags)");
52 return (0);
53 }
54 return (1);
55}

◆ SDDS_SetRowLimit()

epicsShareFuncSDDS int64_t SDDS_SetRowLimit ( int64_t limit)
extern

Sets the row limit for the SDDS dataset.

Parameters
limitThe maximum number of rows to read. If limit <= 0, the row limit is set to INT64_MAX.
Returns
The previous row limit value.

Definition at line 1232 of file SDDS_input.c.

1232 {
1233 int64_t previous;
1234 previous = SDDS_RowLimit;
1235 if (limit <= 0)
1236 SDDS_RowLimit = INT64_MAX;
1237 else
1238 SDDS_RowLimit = limit;
1239 return previous;
1240}

◆ SDDS_SetRowsOfInterest()

epicsShareFuncSDDS int64_t SDDS_SetRowsOfInterest ( SDDS_DATASET * SDDS_dataset,
char * selection_column,
int32_t mode,
... )
extern

Sets the rows of interest in an SDDS dataset based on various selection criteria.

This function marks rows in the provided SDDS dataset as "of interest" based on the specified selection criteria. It supports multiple selection modes, allowing users to specify rows by an array of names, a single string containing multiple names, a variadic list of names, or by matching a specific string with logical operations.

Calling Modes:

  • SDDS_NAME_ARRAY: Specify an array of names.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_NAME_ARRAY, int32_t n_entries, char **name);
    int64_t SDDS_SetRowsOfInterest(SDDS_DATASET *SDDS_dataset, char *selection_column, int32_t mode,...)
    Sets the rows of interest in an SDDS dataset based on various selection criteria.
  • SDDS_NAMES_STRING: Provide a single string containing multiple names separated by delimiters.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_NAMES_STRING, char *names);
  • SDDS_NAME_STRINGS: Pass multiple name strings, terminated by NULL.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_NAME_STRINGS, char *name1, char *name2, ..., NULL);
  • SDDS_MATCH_STRING: Match rows based on a single string and logical operations.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_MATCH_STRING, char *name, int32_t logic_mode);

Additionally, each of these modes has a case-insensitive variant prefixed with SDDS_CI_ (e.g., SDDS_CI_NAME_ARRAY).

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
selection_columnA null-terminated string specifying the name of the column used for row selection. This column must be of string type.
modeAn integer representing the selection mode. Supported modes include:
  • SDDS_NAME_ARRAY
  • SDDS_NAMES_STRING
  • SDDS_NAME_STRINGS
  • SDDS_MATCH_STRING
  • SDDS_CI_NAME_ARRAY
  • SDDS_CI_NAMES_STRING
  • SDDS_CI_NAME_STRINGS
  • SDDS_CI_MATCH_STRING
...Variable arguments corresponding to the selected mode:
  • SDDS_NAME_ARRAY and SDDS_CI_NAME_ARRAY:
    • int32_t n_entries: Number of names.
    • char **name: Array of name strings.
  • SDDS_NAMES_STRING and SDDS_CI_NAMES_STRING:
    • char *names: Single string containing multiple names separated by delimiters.
  • SDDS_NAME_STRINGS and SDDS_CI_NAME_STRINGS:
    • char *name1, char *name2, ..., NULL: Multiple name strings terminated by NULL.
  • SDDS_MATCH_STRING and SDDS_CI_MATCH_STRING:
    • char *name: String to match.
    • int32_t logic_mode: Logical operation mode.
Returns
On success, returns the number of rows marked as "of interest". On failure, returns -1 and sets an appropriate error message.
Return values
-1Indicates that an error occurred (e.g., invalid dataset, unrecognized selection column, memory allocation failure, unknown mode).
Non-negativeInteger representing the count of rows marked as "of interest".
Note
  • The caller must ensure that the selection_column exists and is of string type in the dataset.
  • For modes that allocate memory internally (e.g., SDDS_NAMES_STRING), the function handles memory management internally.
See also
SDDS_MatchRowsOfInterest, SDDS_FilterRowsOfInterest, SDDS_DeleteUnsetRows

Definition at line 3324 of file SDDS_extract.c.

3331{
3332 va_list argptr;
3333 int32_t retval, type, index, n_names;
3334 int64_t i, j;
3335 char **name, *string, *match_string, *ptr;
3336 int32_t local_memory; /* (0,1,2) --> (none, pointer array, pointer array + strings) locally allocated */
3337 char buffer[SDDS_MAXLINE];
3338 int32_t logic, caseSensitive;
3339 int64_t count;
3340
3341 name = NULL;
3342 n_names = local_memory = logic = 0;
3343
3344 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowsOfInterest"))
3345 return (-1);
3346 va_start(argptr, mode);
3347 retval = 1;
3348 caseSensitive = 1;
3349 match_string = NULL;
3350 switch (mode) {
3351 case SDDS_CI_NAME_ARRAY:
3352 caseSensitive = 0;
3353 case SDDS_NAME_ARRAY:
3354 local_memory = 0;
3355 n_names = va_arg(argptr, int32_t);
3356 name = va_arg(argptr, char **);
3357 break;
3358 case SDDS_CI_NAMES_STRING:
3359 caseSensitive = 0;
3360 case SDDS_NAMES_STRING:
3361 local_memory = 2;
3362 n_names = 0;
3363 name = NULL;
3364 ptr = va_arg(argptr, char *);
3365 SDDS_CopyString(&string, ptr);
3366 while (SDDS_GetToken(string, buffer, SDDS_MAXLINE) > 0) {
3367 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1))) || !SDDS_CopyString(name + n_names, buffer)) {
3368 SDDS_SetError("Unable to process row selection--memory allocation failure (SDDS_SetRowsOfInterest)");
3369 retval = -1;
3370 break;
3371 }
3372 n_names++;
3373 }
3374 free(string);
3375 break;
3376 case SDDS_CI_NAME_STRINGS:
3377 caseSensitive = 0;
3378 case SDDS_NAME_STRINGS:
3379 local_memory = 1;
3380 n_names = 0;
3381 name = NULL;
3382 while ((string = va_arg(argptr, char *))) {
3383 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1)))) {
3384 SDDS_SetError("Unable to process row selection--memory allocation failure (SDDS_SetRowsOfInterest)");
3385 retval = -1;
3386 break;
3387 }
3388 name[n_names++] = string;
3389 }
3390 break;
3391 case SDDS_CI_MATCH_STRING:
3392 caseSensitive = 0;
3393 case SDDS_MATCH_STRING:
3394 local_memory = 0;
3395 n_names = 1;
3396 if ((string = va_arg(argptr, char *)))
3397 match_string = expand_ranges(string);
3398 logic = va_arg(argptr, int32_t);
3399 if (logic & SDDS_NOCASE_COMPARE)
3400 caseSensitive = 0;
3401 break;
3402 default:
3403 SDDS_SetError("Unable to process row selection--unknown mode (SDDS_SetRowsOfInterest)");
3404 retval = -1;
3405 break;
3406 }
3407
3408 va_end(argptr);
3409 if (retval != 1)
3410 return (-1);
3411
3412 if (mode != SDDS_MATCH_STRING && mode != SDDS_CI_MATCH_STRING) {
3413 int (*stringCompare)(const char *s1, const char *s2);
3414 if (caseSensitive)
3415 stringCompare = strcmp;
3416 else
3417 stringCompare = strcmp_ci;
3418 if ((index = SDDS_GetColumnIndex(SDDS_dataset, selection_column)) < 0) {
3419 SDDS_SetError("Unable to process row selection--unrecognized selection column name (SDDS_SetRowsOfInterest)");
3420 return (-1);
3421 }
3422 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) != SDDS_STRING) {
3423 SDDS_SetError("Unable to select rows--selection column is not string type (SDDS_SetRowsOfInterest)");
3424 return (-1);
3425 }
3426 if (n_names == 0) {
3427 SDDS_SetError("Unable to process row selection--no names in call (SDDS_SetRowsOfInterest)");
3428 return (-1);
3429 }
3430 for (j = 0; j < n_names; j++) {
3431 for (i = 0; i < SDDS_dataset->n_rows; i++) {
3432 if ((*stringCompare)(*((char **)SDDS_dataset->data[index] + i), name[j]) == 0)
3433 SDDS_dataset->row_flag[i] = 1;
3434 }
3435 }
3436 } else {
3437 if (selection_column) {
3438 int (*wildMatch)(char *string, char *template);
3439 if (caseSensitive)
3440 wildMatch = wild_match;
3441 else
3442 wildMatch = wild_match_ci;
3443 if (!match_string) {
3444 SDDS_SetError("Unable to select rows--no matching string given (SDDS_SetRowsOfInterest)");
3445 return (-1);
3446 }
3447 if ((index = SDDS_GetColumnIndex(SDDS_dataset, selection_column)) < 0) {
3448 free(match_string);
3449 SDDS_SetError("Unable to process row selection--unrecognized selection column name (SDDS_SetRowsOfInterest)");
3450 return (-1);
3451 }
3452 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) != SDDS_STRING) {
3453 free(match_string);
3454 SDDS_SetError("Unable to select rows--selection column is not string type (SDDS_SetRowsOfInterest)");
3455 return (-1);
3456 }
3457 for (i = 0; i < SDDS_dataset->n_rows; i++)
3458 SDDS_dataset->row_flag[i] = SDDS_Logic(SDDS_dataset->row_flag[i], (*wildMatch)(*((char **)SDDS_dataset->data[index] + i), match_string), logic);
3459 } else {
3460 for (i = 0; i < SDDS_dataset->n_rows; i++)
3461 SDDS_dataset->row_flag[i] = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3462 }
3463 }
3464
3465 if (local_memory == 2) {
3466 for (i = 0; i < n_names; i++)
3467 free(name[i]);
3468 }
3469 if (match_string)
3470 free(match_string);
3471 if (local_memory >= 1)
3472 free(name);
3473
3474 for (i = count = 0; i < SDDS_dataset->n_rows; i++)
3475 if (SDDS_dataset->row_flag[i])
3476 count++;
3477 return (count);
3478}

◆ SDDS_SetRowValues()

epicsShareFuncSDDS int32_t SDDS_SetRowValues ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
int64_t row,
... )
extern

Sets the values of one or more columns in a specified row of the current data table of an SDDS dataset.

This function assigns values to specified columns in a particular row of the current data table within the given SDDS dataset. It must be preceded by a call to SDDS_StartPage to initialize the table. Columns can be identified either by their index or by their name. The values can be passed either by value or by reference, depending on the specified mode.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeA bitwise combination of the following constants:
  • SDDS_SET_BY_INDEX: Identify columns by their indices.
  • SDDS_SET_BY_NAME: Identify columns by their names.
  • SDDS_PASS_BY_VALUE: Pass column values by value.
  • SDDS_PASS_BY_REFERENCE: Pass column values by reference.

Mode Requirements:

  • Exactly one of SDDS_SET_BY_INDEX or SDDS_SET_BY_NAME must be set.
  • Exactly one of SDDS_PASS_BY_VALUE or SDDS_PASS_BY_REFERENCE must be set.

Syntax Based on Mode Combination:

  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_VALUE: int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row, int32_t index, value, ..., -1)
  • SDDS_SET_BY_INDEX + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row, int32_t index, void *data, ..., -1)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_VALUE: int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row, char *name, value, ..., NULL)
  • SDDS_SET_BY_NAME + SDDS_PASS_BY_REFERENCE: int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row, char *name, void *data, ..., NULL)

Note: For columns of type SDDS_STRING, passing by value means passing a char *, whereas passing by reference means passing a char **.

Parameters
rowThe row number in the data table where the column values will be set. Row numbering starts from 1.
Returns
Returns 1 on successful assignment of all specified column values. On failure, returns 0 and records an appropriate error message.
See also
SDDS_StartPage, SDDS_SetError, SDDS_GetColumnIndex, SDDS_CopyString

Definition at line 988 of file SDDS_dataprep.c.

988 {
989 va_list argptr;
990 int32_t index;
991 int32_t retval;
992 SDDS_LAYOUT *layout;
993 char *name;
994 char buffer[200];
995
996 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowValues"))
997 return (0);
998 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
999 SDDS_SetError("Unable to set column values--unknown mode (SDDS_SetRowValues)");
1000 return (0);
1001 }
1002 if (!SDDS_CheckTabularData(SDDS_dataset, "SDDS_SetRowValues"))
1003 return (0);
1004 row -= SDDS_dataset->first_row_in_mem;
1005 if (row >= SDDS_dataset->n_rows_allocated) {
1006 sprintf(buffer, "Unable to set column values--row number (%" PRId64 ") exceeds exceeds allocated memory (%" PRId64 ") (SDDS_SetRowValues)", row, SDDS_dataset->n_rows_allocated);
1007 SDDS_SetError(buffer);
1008 return (0);
1009 }
1010 if (row > SDDS_dataset->n_rows - 1)
1011 SDDS_dataset->n_rows = row + 1;
1012
1013 va_start(argptr, row);
1014 layout = &SDDS_dataset->layout;
1015
1016 /* variable arguments are pairs of (index, value), where index is a int32_t integer */
1017 retval = -1;
1018#ifdef DEBUG
1019 fprintf(stderr, "setting row %" PRId64 " (mem slot %" PRId64 ")\n", row + SDDS_dataset->first_row_in_mem, row);
1020#endif
1021 do {
1022 if (mode & SDDS_SET_BY_INDEX) {
1023 if ((index = va_arg(argptr, int32_t)) == -1) {
1024 retval = 1;
1025 break;
1026 }
1027 if (index < 0 || index >= layout->n_columns) {
1028 SDDS_SetError("Unable to set column values--index out of range (SDDS_SetRowValues)");
1029 retval = 0;
1030 break;
1031 }
1032#ifdef DEBUG
1033 fprintf(stderr, "Setting values for column #%" PRId32 "\n", index);
1034#endif
1035 } else {
1036 if ((name = va_arg(argptr, char *)) == NULL) {
1037 retval = 1;
1038 break;
1039 }
1040#ifdef DEBUG
1041 fprintf(stderr, "Setting values for column %s\n", name);
1042#endif
1043 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) < 0) {
1044 SDDS_SetError("Unable to set column values--name not recognized (SDDS_SetRowValues)");
1045 retval = 0;
1046 break;
1047 }
1048 }
1049 switch (layout->column_definition[index].type) {
1050 case SDDS_SHORT:
1051 if (mode & SDDS_PASS_BY_VALUE)
1052 *(((short *)SDDS_dataset->data[index]) + row) = (short)va_arg(argptr, int);
1053 else
1054 *(((short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, short *));
1055 break;
1056 case SDDS_USHORT:
1057 if (mode & SDDS_PASS_BY_VALUE)
1058 *(((unsigned short *)SDDS_dataset->data[index]) + row) = (unsigned short)va_arg(argptr, unsigned int);
1059 else
1060 *(((unsigned short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, unsigned short *));
1061 break;
1062 case SDDS_LONG:
1063 if (mode & SDDS_PASS_BY_VALUE)
1064 *(((int32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int32_t);
1065 else
1066 *(((int32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int32_t *));
1067 break;
1068 case SDDS_ULONG:
1069 if (mode & SDDS_PASS_BY_VALUE)
1070 *(((uint32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint32_t);
1071 else
1072 *(((uint32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint32_t *));
1073 break;
1074 case SDDS_LONG64:
1075 if (mode & SDDS_PASS_BY_VALUE)
1076 *(((int64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int64_t);
1077 else
1078 *(((int64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int64_t *));
1079 break;
1080 case SDDS_ULONG64:
1081 if (mode & SDDS_PASS_BY_VALUE)
1082 *(((uint64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint64_t);
1083 else
1084 *(((uint64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint64_t *));
1085 break;
1086 case SDDS_FLOAT:
1087 if (mode & SDDS_PASS_BY_VALUE)
1088 *(((float *)SDDS_dataset->data[index]) + row) = (float)va_arg(argptr, double);
1089 else
1090 *(((float *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, float *));
1091 break;
1092 case SDDS_DOUBLE:
1093 if (mode & SDDS_PASS_BY_VALUE)
1094 *(((double *)SDDS_dataset->data[index]) + row) = va_arg(argptr, double);
1095 else
1096 *(((double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, double *));
1097 break;
1098 case SDDS_LONGDOUBLE:
1099 if (mode & SDDS_PASS_BY_VALUE)
1100 *(((long double *)SDDS_dataset->data[index]) + row) = va_arg(argptr, long double);
1101 else
1102 *(((long double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, long double *));
1103 break;
1104 case SDDS_STRING:
1105 if (((char **)SDDS_dataset->data[index])[row]) {
1106 free(((char **)SDDS_dataset->data[index])[row]);
1107 ((char **)SDDS_dataset->data[index])[row] = NULL;
1108 }
1109 if (mode & SDDS_PASS_BY_VALUE) {
1110 if (!SDDS_CopyString((char **)SDDS_dataset->data[index] + row, va_arg(argptr, char *))) {
1111 SDDS_SetError("Unable to set string column value--allocation failure (SDDS_SetRowValues)");
1112 retval = 0;
1113 }
1114 } else {
1115 if (!SDDS_CopyString((char **)SDDS_dataset->data[index] + row, *(va_arg(argptr, char **)))) {
1116 SDDS_SetError("Unable to set string column value--allocation failure (SDDS_SetRowValues)");
1117 retval = 0;
1118 }
1119 }
1120 break;
1121 case SDDS_CHARACTER:
1122 if (mode & SDDS_PASS_BY_VALUE)
1123 *(((char *)SDDS_dataset->data[index]) + row) = (char)va_arg(argptr, int);
1124 else
1125 *(((char *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, char *));
1126 break;
1127 default:
1128 SDDS_SetError("Unknown data type encountered (SDDS_SetRowValues");
1129 retval = 0;
1130 break;
1131 }
1132 } while (retval == -1);
1133 va_end(argptr);
1134 return (retval);
1135}

◆ SDDS_SetTerminateMode()

epicsShareFuncSDDS void SDDS_SetTerminateMode ( uint32_t mode)
extern

Sets the terminate mode for the SDDS dataset.

Parameters
modeThe terminate mode to set.

Definition at line 1338 of file SDDS_input.c.

1338 {
1339 terminateMode = mode;
1340}
static int32_t terminateMode
Global variable to set the terminate mode for the SDDS dataset.

◆ SDDS_ShortenTable()

epicsShareFuncSDDS int32_t SDDS_ShortenTable ( SDDS_DATASET * SDDS_dataset,
int64_t rows )
extern

Shortens the data table in the SDDS dataset to a specified number of rows.

This function reduces the number of allocated rows in the specified SDDS dataset to the given rows count. It reallocates memory for each column's data array and the row flags, freeing existing data as necessary. All data is reset, and the number of rows is set to zero.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure whose table will be shortened.
rowsThe new number of rows to allocate in the table. If rows is less than or equal to zero, it defaults to 1.
Returns
Returns 1 on successful reallocation and initialization. On failure, returns 0 and records an error message.
See also
SDDS_Realloc, SDDS_SetMemory, SDDS_Free, SDDS_SetError

Definition at line 238 of file SDDS_dataprep.c.

238 {
239 SDDS_LAYOUT *layout;
240 int64_t i, size;
241
242 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_ShortenTable"))
243 return (0);
244 layout = &SDDS_dataset->layout;
245 if (!SDDS_dataset->data && !(SDDS_dataset->data = (void **)calloc(layout->n_columns, sizeof(*SDDS_dataset->data)))) {
246 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_ShortenTable)");
247 return (0);
248 }
249 if (rows <= 0)
250 rows = 1;
251 for (i = 0; i < layout->n_columns; i++) {
252 size = SDDS_type_size[layout->column_definition[i].type - 1];
253 if (SDDS_dataset->data[i])
254 free(SDDS_dataset->data[i]);
255 if (!(SDDS_dataset->data[i] = (void *)calloc(rows, size))) {
256 SDDS_SetError("Unable to shorten page--memory allocation failure (SDDS_ShortenTable)");
257 return (0);
258 }
259 }
260 if (SDDS_dataset->row_flag)
261 free(SDDS_dataset->row_flag);
262 if (!(SDDS_dataset->row_flag = (int32_t *)malloc(rows * sizeof(int32_t)))) {
263 SDDS_SetError("Unable to shorten page--memory allocation failure (SDDS_ShortenTable)");
264 return (0);
265 }
266 SDDS_dataset->n_rows_allocated = rows;
267 /* Shorten table is not exactly true. It is really deleting all the rows and then allocating new space.
268 if (SDDS_dataset->n_rows > rows) {
269 SDDS_dataset->n_rows = rows;
270 }
271 */
272 SDDS_dataset->n_rows = 0;
273
274 if (!SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated, SDDS_LONG, (int32_t)1, (int32_t)0) ||
275 !SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
276 !SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)0, (int32_t)1)) {
277 SDDS_SetError("Unable to shorten page--memory initialization failure (SDDS_ShortenTable)");
278 return (0);
279 }
280 return (1);
281}

◆ SDDS_SprintTypedValue()

epicsShareFuncSDDS int32_t SDDS_SprintTypedValue ( void * data,
int64_t index,
int32_t type,
const char * format,
char * buffer,
uint32_t mode )
extern

Formats a data value of a specified type into a string buffer using an optional printf format string.

This function formats a single data value from a data array into a provided buffer. It is a wrapper for SDDS_SprintTypedValueFactor with a default scaling factor of 1.0.

Parameters
[in]dataPointer to the base address of the data array containing the value to be formatted.
[in]indexThe index of the item within the data array to be formatted.
[in]typeThe data type of the value, specified by one of the SDDS constants:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
[in]format(Optional) NULL-terminated string specifying a printf format. If NULL, a default format is used based on the data type.
[out]bufferPointer to a character array where the formatted string will be stored.
[in]modeFlags controlling the formatting behavior. Valid values are:
  • 0: Default behavior.
  • SDDS_PRINT_NOQUOTES: When formatting strings, do not enclose them in quotes.
Returns
Returns 1 on success. On failure, returns 0 and records an error message.
Note
This function uses a default scaling factor of 1.0.
See also
SDDS_SprintTypedValueFactor
SDDS_SetError

Definition at line 151 of file SDDS_utils.c.

151 {
152 return SDDS_SprintTypedValueFactor(data, index, type, format, buffer, mode, 1.0);
153}
int32_t SDDS_SprintTypedValueFactor(void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode, double factor)
Reallocates memory to a new size and zero-initializes the additional space.
Definition SDDS_utils.c:186

◆ SDDS_SprintTypedValueFactor()

epicsShareFuncSDDS int32_t SDDS_SprintTypedValueFactor ( void * data,
int64_t index,
int32_t type,
const char * format,
char * buffer,
uint32_t mode,
double factor )
extern

Reallocates memory to a new size and zero-initializes the additional space.

This function extends the standard realloc functionality by zero-initializing any newly allocated memory beyond the original size. It ensures that memory is consistently reallocated and initialized across different build configurations.

Parameters
[in]dataPointer to the base address of the data array containing the value to be formatted.
[in]indexThe index of the item within the data array to be formatted.
[in]typeThe data type of the value, specified by one of the SDDS constants:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_ULONG
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_CHARACTER
  • SDDS_STRING
[in]format(Optional) NULL-terminated string specifying a printf format. If NULL, a default format is used based on the data type.
[out]bufferPointer to a character array where the formatted string will be stored.
[in]modeFlags controlling the formatting behavior. Valid values are:
  • 0: Default behavior.
  • SDDS_PRINT_NOQUOTES: When formatting strings, do not enclose them in quotes.
[in]factorScaling factor to be applied to the value before formatting. The value is multiplied by this factor.
Returns
Returns 1 on success. On failure, returns 0 and records an error message.
Note
This function handles string types by optionally enclosing them in quotes, unless SDDS_PRINT_NOQUOTES is specified in mode.
See also
SDDS_SprintTypedValue
SDDS_SetError

Definition at line 186 of file SDDS_utils.c.

186 {
187 char buffer2[SDDS_PRINT_BUFLEN], *s;
188 short printed;
189
190 if (!data) {
191 SDDS_SetError("Unable to print value--data pointer is NULL (SDDS_SprintTypedValueFactor)");
192 return (0);
193 }
194 if (!buffer) {
195 SDDS_SetError("Unable to print value--buffer pointer is NULL (SDDS_SprintTypedValueFactor)");
196 return (0);
197 }
198 switch (type) {
199 case SDDS_SHORT:
200 sprintf(buffer, format ? format : "%hd", (short)(*((short *)data + index) * (factor)));
201 break;
202 case SDDS_USHORT:
203 sprintf(buffer, format ? format : "%hu", (unsigned short)(*((unsigned short *)data + index) * (factor)));
204 break;
205 case SDDS_LONG:
206 sprintf(buffer, format ? format : "%" PRId32, (int32_t)(*((int32_t *)data + index) * (factor)));
207 break;
208 case SDDS_ULONG:
209 sprintf(buffer, format ? format : "%" PRIu32, (uint32_t)(*((uint32_t *)data + index) * (factor)));
210 break;
211 case SDDS_LONG64:
212 sprintf(buffer, format ? format : "%" PRId64, (int64_t)(*((int64_t *)data + index) * (factor)));
213 break;
214 case SDDS_ULONG64:
215 sprintf(buffer, format ? format : "%" PRIu64, (uint64_t)(*((uint64_t *)data + index) * (factor)));
216 break;
217 case SDDS_FLOAT:
218 sprintf(buffer, format ? format : "%15.8e", (float)(*((float *)data + index) * (factor)));
219 break;
220 case SDDS_DOUBLE:
221 sprintf(buffer, format ? format : "%21.15e", (double)(*((double *)data + index) * (factor)));
222 break;
223 case SDDS_LONGDOUBLE:
224 if (LDBL_DIG == 18) {
225 sprintf(buffer, format ? format : "%21.18Le", (long double)(*((long double *)data + index) * (factor)));
226 } else {
227 sprintf(buffer, format ? format : "%21.15Le", (long double)(*((long double *)data + index) * (factor)));
228 }
229 break;
230 case SDDS_STRING:
231 s = *((char **)data + index);
232 if ((int32_t)strlen(s) > SDDS_PRINT_BUFLEN - 3) {
233 SDDS_SetError("Buffer size overflow (SDDS_SprintTypedValue)");
234 return (0);
235 }
236 if (!(mode & SDDS_PRINT_NOQUOTES)) {
237 printed = 0;
238 if (!s || SDDS_StringIsBlank(s))
239 sprintf(buffer, "\"\"");
240 else if (strchr(s, '"')) {
241 strcpy(buffer2, s);
242 SDDS_EscapeQuotes(buffer2, '"');
243 if (SDDS_HasWhitespace(buffer2))
244 sprintf(buffer, "\"%s\"", buffer2);
245 else
246 strcpy(buffer, buffer2);
247 } else if (SDDS_HasWhitespace(s))
248 sprintf(buffer, "\"%s\"", s);
249 else {
250 sprintf(buffer, format ? format : "%s", s);
251 printed = 1;
252 }
253 if (!printed) {
254 sprintf(buffer2, format ? format : "%s", buffer);
255 strcpy(buffer, buffer2);
256 }
257 } else {
258 sprintf(buffer, format ? format : "%s", s);
259 }
260 break;
261 case SDDS_CHARACTER:
262 sprintf(buffer, format ? format : "%c", *((char *)data + index));
263 break;
264 default:
265 SDDS_SetError("Unable to print value--unknown data type (SDDS_SprintTypedValue)");
266 return (0);
267 }
268 return (1);
269}
void SDDS_EscapeQuotes(char *s, char quote_char)
Escapes quote characters within a string by inserting backslashes.
int32_t SDDS_HasWhitespace(char *string)
Checks if a string contains any whitespace characters.

◆ SDDS_StartPage()

epicsShareFuncSDDS int32_t SDDS_StartPage ( SDDS_DATASET * SDDS_dataset,
int64_t expected_n_rows )
extern

Initializes an SDDS_DATASET structure in preparation for inserting data into a new table.

This function prepares the specified SDDS dataset for data insertion by initializing necessary data structures and allocating memory based on the expected number of rows. It must be preceded by a call to SDDS_InitializeOutput. SDDS_StartPage can be called multiple times to begin writing additional tables within the dataset. After initializing a page, SDDS_WriteTable should be used to write the table to disk.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
expected_n_rowsThe expected number of rows in the data table. This value is used to preallocate memory for storing data values. If expected_n_rows is less than or equal to zero, it defaults to 1.
Returns
Returns 1 on successful initialization. On failure, returns 0 and records an error message.
See also
SDDS_InitializeOutput, SDDS_WriteTable, SDDS_SetError

Definition at line 64 of file SDDS_dataprep.c.

64 {
65 SDDS_LAYOUT *layout;
66 int64_t i;
67 int32_t size;
68
69 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_StartPage"))
70 return (0);
71 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
72 if (!SDDS_UpdateRowCount(SDDS_dataset))
73 return (0);
74 }
75 if (!SDDS_RestoreLayout(SDDS_dataset)) {
76 SDDS_SetError("Unable to start page--couldn't restore layout (SDDS_StartPage)");
77 return (0);
78 }
79 if (expected_n_rows <= 0)
80 expected_n_rows = 1;
81 SDDS_dataset->n_rows_written = 0;
82 SDDS_dataset->last_row_written = -1;
83 SDDS_dataset->writing_page = 0;
84 SDDS_dataset->first_row_in_mem = 0;
85 layout = &SDDS_dataset->layout;
86 if (SDDS_dataset->page_started == 0) {
87 if (layout->n_parameters) {
88 if (!(SDDS_dataset->parameter = (void **)calloc(sizeof(*SDDS_dataset->parameter), layout->n_parameters))) {
89 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
90 return (0);
91 }
92 for (i = 0; i < layout->n_parameters; i++) {
93 if (!(SDDS_dataset->parameter[i] = (void *)calloc(SDDS_type_size[layout->parameter_definition[i].type - 1], 1))) {
94 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
95 return (0);
96 }
97 }
98 }
99 if (layout->n_arrays) {
100 if (!(SDDS_dataset->array = (SDDS_ARRAY *)calloc(sizeof(*SDDS_dataset->array), layout->n_arrays))) {
101 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
102 return (0);
103 }
104 }
105 if (layout->n_columns) {
106 if (!(SDDS_dataset->data = (void **)calloc(sizeof(*SDDS_dataset->data), layout->n_columns))) {
107 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
108 return (0);
109 }
110 SDDS_dataset->row_flag = NULL;
111 if (expected_n_rows) {
112 if (!(SDDS_dataset->row_flag = (int32_t *)SDDS_Malloc(sizeof(int32_t) * expected_n_rows))) {
113 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
114 return (0);
115 }
116 for (i = 0; i < layout->n_columns; i++) {
117 if (!(SDDS_dataset->data[i] = (void *)calloc(expected_n_rows, SDDS_type_size[layout->column_definition[i].type - 1]))) {
118 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
119 return (0);
120 }
121 }
122 }
123 SDDS_dataset->n_rows_allocated = expected_n_rows;
124 if (!(SDDS_dataset->column_flag = (int32_t *)SDDS_Realloc(SDDS_dataset->column_flag, sizeof(int32_t) * layout->n_columns)) ||
125 !(SDDS_dataset->column_order = (int32_t *)SDDS_Realloc(SDDS_dataset->column_order, sizeof(int32_t) * layout->n_columns))) {
126 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
127 return (0);
128 }
129 }
130 } else if (SDDS_dataset->n_rows_allocated >= expected_n_rows && layout->n_columns) {
131 for (i = 0; i < layout->n_columns; i++) {
132 if (SDDS_dataset->data[i] && layout->column_definition[i].type == SDDS_STRING)
133 SDDS_FreeStringArray(SDDS_dataset->data[i], SDDS_dataset->n_rows_allocated);
134 }
135 } else if (SDDS_dataset->n_rows_allocated < expected_n_rows && layout->n_columns) {
136 if (!SDDS_dataset->data) {
137 if (!(SDDS_dataset->column_flag = (int32_t *)SDDS_Realloc(SDDS_dataset->column_flag, sizeof(int32_t) * layout->n_columns)) ||
138 !(SDDS_dataset->column_order = (int32_t *)SDDS_Realloc(SDDS_dataset->column_order, sizeof(int32_t) * layout->n_columns)) ||
139 !(SDDS_dataset->data = (void **)calloc(layout->n_columns, sizeof(*SDDS_dataset->data)))) {
140 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
141 return (0);
142 }
143 }
144 for (i = 0; i < layout->n_columns; i++) {
145 size = SDDS_type_size[layout->column_definition[i].type - 1];
146 if (SDDS_dataset->data[i] && layout->column_definition[i].type == SDDS_STRING)
147 SDDS_FreeStringArray(SDDS_dataset->data[i], SDDS_dataset->n_rows_allocated);
148 if (!(SDDS_dataset->data[i] = (void *)SDDS_Realloc(SDDS_dataset->data[i], expected_n_rows * size))) {
149 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
150 return (0);
151 }
152 SDDS_ZeroMemory((char *)SDDS_dataset->data[i] + size * SDDS_dataset->n_rows_allocated, size * (expected_n_rows - SDDS_dataset->n_rows_allocated));
153 }
154 if (!(SDDS_dataset->row_flag = (int32_t *)SDDS_Realloc(SDDS_dataset->row_flag, sizeof(int32_t) * expected_n_rows))) {
155 SDDS_SetError("Unable to start page--memory allocation failure (SDDS_StartPage)");
156 return (0);
157 }
158 SDDS_dataset->n_rows_allocated = expected_n_rows;
159 }
160 if (SDDS_dataset->n_rows_allocated && layout->n_columns && !SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated, SDDS_LONG, (int32_t)1, (int32_t)0)) {
161 SDDS_SetError("Unable to start page--memory initialization failure (SDDS_StartPage)");
162 return (0);
163 }
164 if (layout->n_columns && (!SDDS_SetMemory(SDDS_dataset->column_flag, layout->n_columns, SDDS_LONG, (int32_t)1, (int32_t)0) ||
165 !SDDS_SetMemory(SDDS_dataset->column_order, layout->n_columns, SDDS_LONG, (int32_t)0, (int32_t)1))) {
166 SDDS_SetError("Unable to start page--memory initialization failure (SDDS_StartPage)");
167 return (0);
168 }
169 SDDS_dataset->n_of_interest = layout->n_columns;
170 SDDS_dataset->page_number++;
171 SDDS_dataset->page_started = 1;
172 SDDS_dataset->n_rows = 0;
173 return (1);
174}
int32_t SDDS_RestoreLayout(SDDS_DATASET *SDDS_dataset)
Definition SDDS_copy.c:697
int32_t SDDS_UpdateRowCount(SDDS_DATASET *SDDS_dataset)

◆ SDDS_StringIsBlank()

epicsShareFuncSDDS int32_t SDDS_StringIsBlank ( char * s)
extern

Checks if a string is blank (contains only whitespace characters).

This function determines whether the provided NULL-terminated string s consists solely of whitespace characters. If the string is NULL or contains only whitespace, the function returns 1. If the string contains any non-whitespace characters, it returns 0.

Parameters
[in]sPointer to the NULL-terminated string to be checked.
Returns
  • Returns 1 if the string is NULL or contains only whitespace characters.
  • Returns 0 if the string contains any non-whitespace characters.
See also
isspace

Definition at line 2404 of file SDDS_utils.c.

2404 {
2405 if (!s)
2406 return 1;
2407 while (*s)
2408 if (!isspace(*s++))
2409 return (0);
2410 return (1);
2411}

◆ SDDS_SwapDouble()

void SDDS_SwapDouble ( double * data)

Swaps the endianness of a double.

This function swaps the byte order of a 64-bit double-precision floating-point number pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the double whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned double.

Definition at line 3952 of file SDDS_binary.c.

3952 {
3953 double copy;
3954 short i, j;
3955 copy = *data;
3956 for (i = 0, j = 7; i < 8; i++, j--)
3957 *(((char *)data) + i) = *(((char *)&copy) + j);
3958}

◆ SDDS_SwapEndsArrayData()

epicsShareFuncSDDS int32_t SDDS_SwapEndsArrayData ( SDDS_DATASET * SDDSin)
extern

Swaps the endianness of the array data in an SDDS dataset.

This function iterates through all arrays defined in the specified SDDS dataset and swaps the byte order of each element to match the system's native endianness. It supports various data types including short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, and long double. The function ensures that binary data is correctly interpreted on systems with different byte orders.

Parameters
[in,out]SDDSinPointer to the SDDS_DATASET structure representing the dataset whose array data endianness is to be swapped.
Returns
int32_t Always returns 1.
Return values
1The endianness of all applicable array data elements was successfully swapped.
Note
This function modifies the dataset's array data in place. It should be called only when the dataset's byte order is known to differ from the system's native byte order.

Definition at line 3741 of file SDDS_binary.c.

3741 {
3742 int32_t i, j;
3743 SDDS_LAYOUT *layout;
3744 short *sData;
3745 unsigned short *suData;
3746 int32_t *lData;
3747 uint32_t *luData;
3748 int64_t *lData64;
3749 uint64_t *luData64;
3750 float *fData;
3751 double *dData;
3752 long double *ldData;
3753
3754 layout = &SDDSin->layout;
3755
3756 for (i = 0; i < layout->n_arrays; i++) {
3757 switch (layout->array_definition[i].type) {
3758 case SDDS_SHORT:
3759 sData = SDDSin->array[i].data;
3760 for (j = 0; j < SDDSin->array[i].elements; j++)
3761 SDDS_SwapShort(sData + j);
3762 break;
3763 case SDDS_USHORT:
3764 suData = SDDSin->array[i].data;
3765 for (j = 0; j < SDDSin->array[i].elements; j++)
3766 SDDS_SwapUShort(suData + j);
3767 break;
3768 case SDDS_LONG:
3769 lData = SDDSin->array[i].data;
3770 for (j = 0; j < SDDSin->array[i].elements; j++)
3771 SDDS_SwapLong(lData + j);
3772 break;
3773 case SDDS_ULONG:
3774 luData = SDDSin->array[i].data;
3775 for (j = 0; j < SDDSin->array[i].elements; j++)
3776 SDDS_SwapULong(luData + j);
3777 break;
3778 case SDDS_LONG64:
3779 lData64 = SDDSin->array[i].data;
3780 for (j = 0; j < SDDSin->array[i].elements; j++)
3781 SDDS_SwapLong64(lData64 + j);
3782 break;
3783 case SDDS_ULONG64:
3784 luData64 = SDDSin->array[i].data;
3785 for (j = 0; j < SDDSin->array[i].elements; j++)
3786 SDDS_SwapULong64(luData64 + j);
3787 break;
3788 case SDDS_LONGDOUBLE:
3789 ldData = SDDSin->array[i].data;
3790 for (j = 0; j < SDDSin->array[i].elements; j++)
3791 SDDS_SwapLongDouble(ldData + j);
3792 break;
3793 case SDDS_DOUBLE:
3794 dData = SDDSin->array[i].data;
3795 for (j = 0; j < SDDSin->array[i].elements; j++)
3796 SDDS_SwapDouble(dData + j);
3797 break;
3798 case SDDS_FLOAT:
3799 fData = SDDSin->array[i].data;
3800 for (j = 0; j < SDDSin->array[i].elements; j++)
3801 SDDS_SwapFloat(fData + j);
3802 break;
3803 default:
3804 break;
3805 }
3806 }
3807 return (1);
3808}
void SDDS_SwapLongDouble(long double *data)
Swaps the endianness of a long double.
void SDDS_SwapULong64(uint64_t *data)
Swaps the endianness of a 64-bit unsigned integer.
void SDDS_SwapULong(uint32_t *data)
Swaps the endianness of a 32-bit unsigned integer.
void SDDS_SwapUShort(unsigned short *data)
Swaps the endianness of an unsigned short integer.
void SDDS_SwapDouble(double *data)
Swaps the endianness of a double.
void SDDS_SwapShort(short *data)
Swaps the endianness of a short integer.
void SDDS_SwapFloat(float *data)
Swaps the endianness of a float.

◆ SDDS_SwapEndsColumnData()

epicsShareFuncSDDS int32_t SDDS_SwapEndsColumnData ( SDDS_DATASET * SDDSin)
extern

Swaps the endianness of the column data in an SDDS dataset.

This function iterates through all columns in the specified SDDS dataset and swaps the byte order of each data element to match the system's native endianness. It supports various data types, including short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, and long double. The function ensures that binary data is correctly interpreted on systems with different byte orders.

Parameters
[in,out]SDDSinPointer to the SDDS_DATASET structure representing the dataset whose column data endianness is to be swapped.
Returns
int32_t Always returns 1.
Return values
1The endianness of all applicable column data elements was successfully swapped.
Note
This function modifies the dataset's column data in place. It should be called only when the dataset's byte order is known to differ from the system's native byte order. String data types are not affected by this function.

Definition at line 3576 of file SDDS_binary.c.

3576 {
3577 int32_t i, row;
3578 SDDS_LAYOUT *layout;
3579 short *sData;
3580 unsigned short *suData;
3581 int32_t *lData;
3582 uint32_t *luData;
3583 int64_t *lData64;
3584 uint64_t *luData64;
3585 float *fData;
3586 double *dData;
3587 long double *ldData;
3588
3589 layout = &SDDSin->layout;
3590 for (i = 0; i < layout->n_columns; i++) {
3591 switch (layout->column_definition[i].type) {
3592 case SDDS_SHORT:
3593 sData = SDDSin->data[i];
3594 for (row = 0; row < SDDSin->n_rows; row++)
3595 SDDS_SwapShort(sData + row);
3596 break;
3597 case SDDS_USHORT:
3598 suData = SDDSin->data[i];
3599 for (row = 0; row < SDDSin->n_rows; row++)
3600 SDDS_SwapUShort(suData + row);
3601 break;
3602 case SDDS_LONG:
3603 lData = SDDSin->data[i];
3604 for (row = 0; row < SDDSin->n_rows; row++)
3605 SDDS_SwapLong(lData + row);
3606 break;
3607 case SDDS_ULONG:
3608 luData = SDDSin->data[i];
3609 for (row = 0; row < SDDSin->n_rows; row++)
3610 SDDS_SwapULong(luData + row);
3611 break;
3612 case SDDS_LONG64:
3613 lData64 = SDDSin->data[i];
3614 for (row = 0; row < SDDSin->n_rows; row++)
3615 SDDS_SwapLong64(lData64 + row);
3616 break;
3617 case SDDS_ULONG64:
3618 luData64 = SDDSin->data[i];
3619 for (row = 0; row < SDDSin->n_rows; row++)
3620 SDDS_SwapULong64(luData64 + row);
3621 break;
3622 case SDDS_LONGDOUBLE:
3623 ldData = SDDSin->data[i];
3624 for (row = 0; row < SDDSin->n_rows; row++)
3625 SDDS_SwapLongDouble(ldData + row);
3626 break;
3627 case SDDS_DOUBLE:
3628 dData = SDDSin->data[i];
3629 for (row = 0; row < SDDSin->n_rows; row++)
3630 SDDS_SwapDouble(dData + row);
3631 break;
3632 case SDDS_FLOAT:
3633 fData = SDDSin->data[i];
3634 for (row = 0; row < SDDSin->n_rows; row++)
3635 SDDS_SwapFloat(fData + row);
3636 break;
3637 default:
3638 break;
3639 }
3640 }
3641 return (1);
3642}

◆ SDDS_SwapEndsParameterData()

epicsShareFuncSDDS int32_t SDDS_SwapEndsParameterData ( SDDS_DATASET * SDDSin)
extern

Swaps the endianness of the parameter data in an SDDS dataset.

This function iterates through all parameters in the specified SDDS dataset and swaps the byte order of each data element to match the system's native endianness. It handles various data types, including short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, and long double. Parameters with fixed values are skipped as their byte order is already consistent.

Parameters
[in,out]SDDSinPointer to the SDDS_DATASET structure representing the dataset whose parameter data endianness is to be swapped.
Returns
int32_t Always returns 1.
Return values
1The endianness of all applicable parameter data elements was successfully swapped.
Note
This function modifies the dataset's parameter data in place. It should be called only when the dataset's byte order is known to differ from the system's native byte order. String data types and parameters with fixed values are not affected by this function.

Definition at line 3662 of file SDDS_binary.c.

3662 {
3663 int32_t i;
3664 SDDS_LAYOUT *layout;
3665 short *sData;
3666 unsigned short *suData;
3667 int32_t *lData;
3668 uint32_t *luData;
3669 int64_t *lData64;
3670 uint64_t *luData64;
3671 float *fData;
3672 double *dData;
3673 long double *ldData;
3674
3675 layout = &SDDSin->layout;
3676 for (i = 0; i < layout->n_parameters; i++) {
3677 if (layout->parameter_definition[i].fixed_value) {
3678 continue;
3679 }
3680 switch (layout->parameter_definition[i].type) {
3681 case SDDS_SHORT:
3682 sData = SDDSin->parameter[i];
3683 SDDS_SwapShort(sData);
3684 break;
3685 case SDDS_USHORT:
3686 suData = SDDSin->parameter[i];
3687 SDDS_SwapUShort(suData);
3688 break;
3689 case SDDS_LONG:
3690 lData = SDDSin->parameter[i];
3691 SDDS_SwapLong(lData);
3692 break;
3693 case SDDS_ULONG:
3694 luData = SDDSin->parameter[i];
3695 SDDS_SwapULong(luData);
3696 break;
3697 case SDDS_LONG64:
3698 lData64 = SDDSin->parameter[i];
3699 SDDS_SwapLong64(lData64);
3700 break;
3701 case SDDS_ULONG64:
3702 luData64 = SDDSin->parameter[i];
3703 SDDS_SwapULong64(luData64);
3704 break;
3705 case SDDS_LONGDOUBLE:
3706 ldData = SDDSin->parameter[i];
3707 SDDS_SwapLongDouble(ldData);
3708 break;
3709 case SDDS_DOUBLE:
3710 dData = SDDSin->parameter[i];
3711 SDDS_SwapDouble(dData);
3712 break;
3713 case SDDS_FLOAT:
3714 fData = SDDSin->parameter[i];
3715 SDDS_SwapFloat(fData);
3716 break;
3717 default:
3718 break;
3719 }
3720 }
3721 return (1);
3722}

◆ SDDS_SwapFloat()

void SDDS_SwapFloat ( float * data)

Swaps the endianness of a float.

This function swaps the byte order of a 32-bit floating-point number pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the float whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned float.

Definition at line 3933 of file SDDS_binary.c.

3933 {
3934 float copy;
3935 short i, j;
3936 copy = *data;
3937 for (i = 0, j = 3; i < 4; i++, j--)
3938 *(((char *)data) + i) = *(((char *)&copy) + j);
3939}

◆ SDDS_SwapLong()

epicsShareFuncSDDS void SDDS_SwapLong ( int32_t * data)
extern

Swaps the endianness of a 32-bit integer.

This function swaps the byte order of a 32-bit integer pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the 32-bit integer whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned 32-bit integer.

Definition at line 3857 of file SDDS_binary.c.

3857 {
3858 int32_t copy;
3859 short i, j;
3860 copy = *data;
3861 for (i = 0, j = 3; i < 4; i++, j--)
3862 *(((char *)data) + i) = *(((char *)&copy) + j);
3863}

◆ SDDS_SwapLong64()

epicsShareFuncSDDS void SDDS_SwapLong64 ( int64_t * data)
extern

Swaps the endianness of a 64-bit integer.

This function swaps the byte order of a 64-bit integer pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the 64-bit integer whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned 64-bit integer.

Definition at line 3895 of file SDDS_binary.c.

3895 {
3896 int64_t copy;
3897 short i, j;
3898 copy = *data;
3899 for (i = 0, j = 7; i < 8; i++, j--)
3900 *(((char *)data) + i) = *(((char *)&copy) + j);
3901}

◆ SDDS_SwapLongDouble()

void SDDS_SwapLongDouble ( long double * data)

Swaps the endianness of a long double.

This function swaps the byte order of a long double floating-point number pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats. The function accounts for different sizes of long double based on the system's architecture.

Parameters
[in,out]dataPointer to the long double whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned long double. The size of long double may vary between different systems.

Definition at line 3972 of file SDDS_binary.c.

3972 {
3973 long double copy;
3974 short i, j;
3975 copy = *data;
3976 if (LDBL_DIG == 18) {
3977 for (i = 0, j = 11; i < 12; i++, j--)
3978 *(((char *)data) + i) = *(((char *)&copy) + j);
3979 } else {
3980 for (i = 0, j = 7; i < 8; i++, j--)
3981 *(((char *)data) + i) = *(((char *)&copy) + j);
3982 }
3983}

◆ SDDS_SwapShort()

void SDDS_SwapShort ( short * data)

Swaps the endianness of a short integer.

This function swaps the byte order of a 16-bit short integer pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the short integer whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned 16-bit short integer.

Definition at line 3821 of file SDDS_binary.c.

3821 {
3822 unsigned char c1;
3823 c1 = *((char *)data);
3824 *((char *)data) = *(((char *)data) + 1);
3825 *(((char *)data) + 1) = c1;
3826}

◆ SDDS_SwapULong()

epicsShareFuncSDDS void SDDS_SwapULong ( uint32_t * data)
extern

Swaps the endianness of a 32-bit unsigned integer.

This function swaps the byte order of a 32-bit unsigned integer pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the 32-bit unsigned integer whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned 32-bit unsigned integer.

Definition at line 3876 of file SDDS_binary.c.

3876 {
3877 uint32_t copy;
3878 short i, j;
3879 copy = *data;
3880 for (i = 0, j = 3; i < 4; i++, j--)
3881 *(((char *)data) + i) = *(((char *)&copy) + j);
3882}

◆ SDDS_SwapULong64()

epicsShareFuncSDDS void SDDS_SwapULong64 ( uint64_t * data)
extern

Swaps the endianness of a 64-bit unsigned integer.

This function swaps the byte order of a 64-bit unsigned integer pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the 64-bit unsigned integer whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned 64-bit unsigned integer.

Definition at line 3914 of file SDDS_binary.c.

3914 {
3915 uint64_t copy;
3916 short i, j;
3917 copy = *data;
3918 for (i = 0, j = 7; i < 8; i++, j--)
3919 *(((char *)data) + i) = *(((char *)&copy) + j);
3920}

◆ SDDS_SwapUShort()

void SDDS_SwapUShort ( unsigned short * data)

Swaps the endianness of an unsigned short integer.

This function swaps the byte order of a 16-bit unsigned short integer pointed to by the provided data pointer. It effectively converts the data between little-endian and big-endian formats.

Parameters
[in,out]dataPointer to the unsigned short integer whose byte order is to be swapped.
Note
The function modifies the data in place. Ensure that the pointer is valid and points to a properly aligned 16-bit unsigned short integer.

Definition at line 3839 of file SDDS_binary.c.

3839 {
3840 unsigned char c1;
3841 c1 = *((char *)data);
3842 *((char *)data) = *(((char *)data) + 1);
3843 *(((char *)data) + 1) = c1;
3844}

◆ SDDS_SyncDataSet()

epicsShareFuncSDDS int32_t SDDS_SyncDataSet ( SDDS_DATASET * SDDS_dataset)
extern

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

epicsShareFuncSDDS int32_t SDDS_Terminate ( SDDS_DATASET * SDDS_dataset)
extern

Closes an SDDS file and frees the related memory.

Parameters
SDDS_datasetA pointer to an SDDS dataset.
Returns
1 on success, 0 on error.

Definition at line 1448 of file SDDS_input.c.

1448 {
1449 SDDS_LAYOUT *layout;
1450 char **ptr;
1451 int64_t i, j;
1452 FILE *fp;
1453 char termBuffer[16384];
1454#if SDDS_MPI_IO
1455 if (SDDS_dataset->parallel_io)
1456 return SDDS_MPI_Terminate(SDDS_dataset);
1457#endif
1458 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_Terminate"))
1459 return (0);
1460 layout = &SDDS_dataset->original_layout;
1461
1462 fp = SDDS_dataset->layout.fp;
1463#if defined(zLib)
1464 if (SDDS_dataset->layout.gzipFile) {
1465 if (SDDS_dataset->layout.gzfp && layout->filename) {
1466 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
1467 if (!SDDS_UpdateRowCount(SDDS_dataset))
1468 return (0);
1469 }
1470 gzclose(SDDS_dataset->layout.gzfp);
1471 }
1472 } else {
1473#endif
1474 if (SDDS_dataset->layout.lzmaFile) {
1475 if (SDDS_dataset->layout.lzmafp && layout->filename) {
1476 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
1477 if (!SDDS_UpdateRowCount(SDDS_dataset))
1478 return (0);
1479 }
1480 lzma_close(SDDS_dataset->layout.lzmafp);
1481 }
1482 } else {
1483 if (fp && layout->filename) {
1484 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
1485 if (!SDDS_UpdateRowCount(SDDS_dataset))
1486 return (0);
1487 }
1488 if (layout->popenUsed) {
1489 while (fread(termBuffer, sizeof(*termBuffer), 16384, fp)) {
1490 }
1491#if defined(vxWorks)
1492 fprintf(stderr, "pclose is not supported in vxWorks\n");
1493 exit(1);
1494#else
1495 pclose(fp);
1496#endif
1497 } else {
1498 fclose(fp);
1499 }
1500 }
1501 }
1502#if defined(zLib)
1503 }
1504#endif
1505
1506#if DEBUG
1507 fprintf(stderr, "Freeing data for file %s\n", SDDS_dataset->layout.filename ? SDDS_dataset->layout.filename : "NULL");
1508#endif
1509
1510 if (SDDS_dataset->pagecount_offset)
1511 free(SDDS_dataset->pagecount_offset);
1512 if (SDDS_dataset->row_flag)
1513 free(SDDS_dataset->row_flag);
1514 if (SDDS_dataset->column_order)
1515 free(SDDS_dataset->column_order);
1516 if (SDDS_dataset->column_flag)
1517 free(SDDS_dataset->column_flag);
1518 if (SDDS_dataset->fBuffer.buffer)
1519 free(SDDS_dataset->fBuffer.buffer);
1520#if DEBUG
1521 fprintf(stderr, "freeing parameter data...\n");
1522#endif
1523 if (SDDS_dataset->parameter) {
1524 for (i = 0; i < layout->n_parameters; i++) {
1525 if (layout->parameter_definition[i].type == SDDS_STRING && *(char **)(SDDS_dataset->parameter[i]))
1526 free(*(char **)(SDDS_dataset->parameter[i]));
1527 if (SDDS_dataset->parameter[i])
1528 free(SDDS_dataset->parameter[i]);
1529 }
1530 free(SDDS_dataset->parameter);
1531 }
1532#if DEBUG
1533 fprintf(stderr, "freeing array data...\n");
1534#endif
1535 if (SDDS_dataset->array) {
1536 for (i = 0; i < layout->n_arrays; i++) {
1537 if (layout->array_definition[i].type == SDDS_STRING && !(terminateMode & TERMINATE_DONT_FREE_ARRAY_STRINGS)) {
1538 for (j = 0; j < SDDS_dataset->array[i].elements; j++)
1539 if (((char **)SDDS_dataset->array[i].data)[j])
1540 free(((char **)SDDS_dataset->array[i].data)[j]);
1541 }
1542 /*
1543 if (SDDS_dataset->array[i].definition->type==SDDS_STRING &&
1544 !(terminateMode&TERMINATE_DONT_FREE_ARRAY_STRINGS)) {
1545 for (j=0; j<SDDS_dataset->array[i].elements; j++)
1546 if (((char**)SDDS_dataset->array[i].data)[j])
1547 free(((char**)SDDS_dataset->array[i].data)[j]);
1548 }
1549 */
1550 if (SDDS_dataset->array[i].data)
1551 free(SDDS_dataset->array[i].data);
1552 /* should free the subpointers too, but it would be a lot of trouble for little benefit: */
1553 if (SDDS_dataset->array[i].pointer && SDDS_dataset->array[i].definition->dimensions != 1)
1554 free(SDDS_dataset->array[i].pointer);
1555 if (SDDS_dataset->array[i].dimension)
1556 free(SDDS_dataset->array[i].dimension);
1557 /* don't touch this--it's done below */
1558 if (SDDS_dataset->array[i].definition && SDDS_dataset->array[i].definition->name) {
1559 if (SDDS_dataset->array[i].definition->name != layout->array_definition[i].name)
1560 SDDS_FreeArrayDefinition(SDDS_dataset->array[i].definition);
1561 }
1562 SDDS_dataset->array[i].definition = NULL;
1563 }
1564 free(SDDS_dataset->array);
1565 }
1566#if DEBUG
1567 fprintf(stderr, "freeing tabular data...\n");
1568#endif
1569 if (SDDS_dataset->data) {
1570 for (i = 0; i < layout->n_columns; i++)
1571 if (SDDS_dataset->data[i]) {
1572 if ((SDDS_dataset->column_track_memory == NULL) || (SDDS_dataset->column_track_memory[i])) {
1573 if (layout->column_definition[i].type == SDDS_STRING && !(terminateMode & TERMINATE_DONT_FREE_TABLE_STRINGS)) {
1574 ptr = (char **)SDDS_dataset->data[i];
1575 for (j = 0; j < SDDS_dataset->n_rows_allocated; j++, ptr++)
1576 if (*ptr)
1577 free(*ptr);
1578 }
1579 free(SDDS_dataset->data[i]);
1580 }
1581 }
1582 free(SDDS_dataset->data);
1583 }
1584 if (SDDS_dataset->column_track_memory)
1585 free(SDDS_dataset->column_track_memory);
1586#if DEBUG
1587 fprintf(stderr, "freeing layout data...\n");
1588#endif
1589 if (layout->description)
1590 free(layout->description);
1591 if (layout->contents == (&SDDS_dataset->layout)->contents)
1592 (&SDDS_dataset->layout)->contents = NULL;
1593 if (layout->contents)
1594 free(layout->contents);
1595 if (layout->filename)
1596 free(layout->filename);
1597 if (layout->column_definition) {
1598 for (i = 0; i < layout->n_columns; i++) {
1599 if (layout->column_index[i])
1600 free(layout->column_index[i]);
1601 if (layout->column_definition[i].name)
1602 free(layout->column_definition[i].name);
1603 if (layout->column_definition[i].symbol)
1604 free(layout->column_definition[i].symbol);
1605 if (layout->column_definition[i].units)
1606 free(layout->column_definition[i].units);
1607 if (layout->column_definition[i].description)
1608 free(layout->column_definition[i].description);
1609 if (layout->column_definition[i].format_string)
1610 free(layout->column_definition[i].format_string);
1611 }
1612 free(layout->column_definition);
1613 free(layout->column_index);
1614 }
1615 if (layout->parameter_definition) {
1616 for (i = 0; i < layout->n_parameters; i++) {
1617 if (layout->parameter_index[i])
1618 free(layout->parameter_index[i]);
1619 if (layout->parameter_definition[i].name)
1620 free(layout->parameter_definition[i].name);
1621 if (layout->parameter_definition[i].symbol)
1622 free(layout->parameter_definition[i].symbol);
1623 if (layout->parameter_definition[i].units)
1624 free(layout->parameter_definition[i].units);
1625 if (layout->parameter_definition[i].description)
1626 free(layout->parameter_definition[i].description);
1627 if (layout->parameter_definition[i].format_string)
1628 free(layout->parameter_definition[i].format_string);
1629 if (layout->parameter_definition[i].fixed_value)
1630 free(layout->parameter_definition[i].fixed_value);
1631 }
1632 free(layout->parameter_definition);
1633 free(layout->parameter_index);
1634 }
1635 if (layout->array_definition) {
1636 for (i = 0; i < layout->n_arrays; i++) {
1637 if (layout->array_index[i])
1638 free(layout->array_index[i]);
1639 if (layout->array_definition[i].name)
1640 free(layout->array_definition[i].name);
1641 if (layout->array_definition[i].symbol)
1642 free(layout->array_definition[i].symbol);
1643 if (layout->array_definition[i].units)
1644 free(layout->array_definition[i].units);
1645 if (layout->array_definition[i].description)
1646 free(layout->array_definition[i].description);
1647 if (layout->array_definition[i].format_string)
1648 free(layout->array_definition[i].format_string);
1649 if (layout->array_definition[i].group_name)
1650 free(layout->array_definition[i].group_name);
1651 }
1652 free(layout->array_definition);
1653 free(layout->array_index);
1654 }
1655 if (layout->associate_definition) {
1656 for (i = 0; i < layout->n_associates; i++) {
1657 if (layout->associate_definition[i].name)
1658 free(layout->associate_definition[i].name);
1659 if (layout->associate_definition[i].filename)
1660 free(layout->associate_definition[i].filename);
1661 if (layout->associate_definition[i].path)
1662 free(layout->associate_definition[i].path);
1663 if (layout->associate_definition[i].description)
1664 free(layout->associate_definition[i].description);
1665 if (layout->associate_definition[i].contents)
1666 free(layout->associate_definition[i].contents);
1667 }
1668 free(layout->associate_definition);
1669 }
1670 SDDS_ZeroMemory(&SDDS_dataset->original_layout, sizeof(SDDS_LAYOUT));
1671 layout = &SDDS_dataset->layout;
1672 if (layout->contents)
1673 free(layout->contents);
1674 if (layout->column_definition)
1675 free(layout->column_definition);
1676 if (layout->array_definition)
1677 free(layout->array_definition);
1678 if (layout->associate_definition)
1679 free(layout->associate_definition);
1680 if (layout->parameter_definition)
1681 free(layout->parameter_definition);
1682 if (layout->column_index)
1683 free(layout->column_index);
1684 if (layout->parameter_index)
1685 free(layout->parameter_index);
1686 if (layout->array_index)
1687 free(layout->array_index);
1688 SDDS_ZeroMemory(&SDDS_dataset->layout, sizeof(SDDS_LAYOUT));
1689 SDDS_ZeroMemory(SDDS_dataset, sizeof(SDDS_DATASET));
1690#if DEBUG
1691 fprintf(stderr, "done\n");
1692#endif
1693 return (1);
1694}
int32_t SDDS_MPI_Terminate(SDDS_DATASET *SDDS_dataset)
Terminates the SDDS dataset by freeing all allocated resources and closing MPI files.

◆ SDDS_TransferAllArrayDefinitions()

epicsShareFuncSDDS int32_t SDDS_TransferAllArrayDefinitions ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
uint32_t mode )
extern

Transfers all array definitions from a source dataset to a target dataset.

This function defines all arrays in the target SDDS dataset to match the array definitions in the source SDDS dataset. Currently, only mode 0 is supported, which results in an error if any array already exists in the target dataset.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure representing the target dataset.
SDDS_sourcePointer to the SDDS_DATASET structure representing the source dataset.
modeFlags that determine how to handle existing arrays. Valid value:
  • 0: Error if an array already exists in the target dataset.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.
Note
Non-zero mode flags are not supported for array definitions.

Definition at line 506 of file SDDS_transfer.c.

506 {
507 SDDS_LAYOUT *source;
508 int32_t i;
509
510 if (!SDDS_CheckDataset(SDDS_target, "SDDS_TransferAllArrayDefinitions"))
511 return (0);
512 if (!SDDS_CheckDataset(SDDS_source, "SDDS_TransferAllArrayDefinitions"))
513 return (0);
514 if (mode) {
515 /* haven't done this one yet */
516 SDDS_SetError("Nonzero mode not supported for arrays (SDDS_TransferAllArrayDefinitions)");
517 return 0;
518 }
519 source = &SDDS_source->layout;
520 SDDS_DeferSavingLayout(SDDS_target, 1);
521 for (i = 0; i < source->n_arrays; i++)
522 if (SDDS_DefineArray(SDDS_target, source->array_definition[i].name, source->array_definition[i].symbol,
523 source->array_definition[i].units, source->array_definition[i].description,
524 source->array_definition[i].format_string, source->array_definition[i].type, source->array_definition[i].field_length, source->array_definition[i].dimensions, source->array_definition[i].group_name) < 0) {
525 SDDS_SetError("Unable to define array (SDDS_TransferAllArrayDefinitions)");
526 SDDS_DeferSavingLayout(SDDS_target, 0);
527 return 0;
528 }
529 SDDS_DeferSavingLayout(SDDS_target, 0);
530 return 1;
531}

◆ SDDS_TransferAllColumnDefinitions()

epicsShareFuncSDDS int32_t SDDS_TransferAllColumnDefinitions ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
uint32_t mode )
extern

Transfers all column definitions from a source dataset to a target dataset.

This function defines all columns in the target SDDS dataset to match the column definitions in the source SDDS dataset. It handles existing columns based on the specified mode.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure representing the target dataset.
SDDS_sourcePointer to the SDDS_DATASET structure representing the source dataset.
modeFlags that determine how to handle existing columns. Valid flags include:
  • 0: Error if a column already exists in the target dataset.
  • SDDS_TRANSFER_KEEPOLD: Retain existing columns in the target dataset and skip transferring conflicting columns.
  • SDDS_TRANSFER_OVERWRITE: Overwrite existing columns in the target dataset with definitions from the source dataset.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 424 of file SDDS_transfer.c.

424 {
425 SDDS_LAYOUT *target, *source;
426 int32_t i, index;
427 char messBuffer[1024];
428
429 if (!SDDS_CheckDataset(SDDS_target, "SDDS_TransferAllColumnDefinitions"))
430 return (0);
431 if (!SDDS_CheckDataset(SDDS_source, "SDDS_TransferAllColumnDefinitions"))
432 return (0);
433 if (mode & SDDS_TRANSFER_KEEPOLD && mode & SDDS_TRANSFER_OVERWRITE) {
434 SDDS_SetError("Inconsistent mode flags (SDDS_TransferAllColumnDefinitions)");
435 return 0;
436 }
437 target = &SDDS_target->layout;
438 source = &SDDS_source->layout;
439 SDDS_DeferSavingLayout(SDDS_target, 1);
440 for (i = 0; i < source->n_columns; i++)
441 if ((index = SDDS_GetColumnIndex(SDDS_target, source->column_definition[i].name)) >= 0) {
442 /* already exists */
443 if (mode & SDDS_TRANSFER_KEEPOLD)
444 continue;
445 if (!(mode & SDDS_TRANSFER_OVERWRITE)) {
446 sprintf(messBuffer, "Unable to define column %s---already exists (SDDS_TransferAllColumnDefinitions)", source->column_definition[i].name);
447 SDDS_SetError(messBuffer);
448 SDDS_DeferSavingLayout(SDDS_target, 0);
449 return 0;
450 }
451 if (source->column_definition[i].type != target->column_definition[index].type && SDDS_target->n_rows_allocated) {
452 sprintf(messBuffer, "Unable to define column %s---type mismatch and table already allocated (SDDS_TransferAllColumnDefinitions)", source->column_definition[i].name);
453 SDDS_SetError(messBuffer);
454 SDDS_DeferSavingLayout(SDDS_target, 0);
455 return 0;
456 }
457 if (!SDDS_ChangeColumnInformation(SDDS_target, "symbol",
458 &source->column_definition[i].symbol,
459 SDDS_BY_INDEX, index) ||
460 !SDDS_ChangeColumnInformation(SDDS_target, "units",
461 &source->column_definition[i].units,
462 SDDS_BY_INDEX, index) ||
463 !SDDS_ChangeColumnInformation(SDDS_target, "description",
464 &source->column_definition[i].description,
465 SDDS_BY_INDEX, index) ||
466 !SDDS_ChangeColumnInformation(SDDS_target, "format_string",
467 &source->column_definition[i].format_string,
468 SDDS_BY_INDEX, index) ||
469 !SDDS_ChangeColumnInformation(SDDS_target, "type", &source->column_definition[i].type, SDDS_BY_INDEX, index) || !SDDS_ChangeColumnInformation(SDDS_target, "field_length", &source->column_definition[i].field_length, SDDS_BY_INDEX, index)) {
470 SDDS_SetError("Unable to define column---problem with overwrite (SDDS_TransferAllColumnDefinitions)");
471 SDDS_DeferSavingLayout(SDDS_target, 0);
472 return 0;
473 }
474 target->column_definition[index].definition_mode = source->column_definition[index].definition_mode;
475 if (target->column_definition[index].type == SDDS_STRING)
476 target->column_definition[index].memory_number = SDDS_CreateRpnMemory(source->column_definition[i].name, 1);
477 else
478 target->column_definition[index].memory_number = SDDS_CreateRpnMemory(source->column_definition[i].name, 0);
479 } else {
480 if (SDDS_DefineColumn(SDDS_target, source->column_definition[i].name, source->column_definition[i].symbol,
481 source->column_definition[i].units, source->column_definition[i].description, source->column_definition[i].format_string, source->column_definition[i].type, source->column_definition[i].field_length) < 0) {
482 SDDS_SetError("Unable to define column (SDDS_TransferAllColumnDefinitions)");
483 SDDS_DeferSavingLayout(SDDS_target, 0);
484 return 0;
485 }
486 }
487 SDDS_DeferSavingLayout(SDDS_target, 0);
488 return 1;
489}

◆ SDDS_TransferAllParameterDefinitions()

epicsShareFuncSDDS int32_t SDDS_TransferAllParameterDefinitions ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
uint32_t mode )
extern

Transfers all parameter definitions from a source dataset to a target dataset.

This function defines all parameters in the target SDDS dataset to match the parameter definitions in the source SDDS dataset. It handles existing parameters based on the specified mode.

Parameters
SDDS_targetPointer to the SDDS_DATASET structure representing the target dataset.
SDDS_sourcePointer to the SDDS_DATASET structure representing the source dataset.
modeFlags that determine how to handle existing parameters. Valid flags include:
  • 0: Error if a parameter already exists in the target dataset.
  • SDDS_TRANSFER_KEEPOLD: Retain existing parameters in the target dataset and skip transferring conflicting parameters.
  • SDDS_TRANSFER_OVERWRITE: Overwrite existing parameters in the target dataset with definitions from the source dataset.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 343 of file SDDS_transfer.c.

343 {
344 SDDS_LAYOUT *target, *source;
345 int32_t i, index;
346 char messBuffer[1024];
347
348 if (!SDDS_CheckDataset(SDDS_target, "SDDS_TransferAllParameterDefinitions"))
349 return (0);
350 if (!SDDS_CheckDataset(SDDS_source, "SDDS_TransferAllParameterDefinitions"))
351 return (0);
352 if (mode & SDDS_TRANSFER_KEEPOLD && mode & SDDS_TRANSFER_OVERWRITE) {
353 SDDS_SetError("Inconsistent mode flags (SDDS_TransferAllParameterDefinitions)");
354 return 0;
355 }
356 target = &SDDS_target->layout;
357 source = &SDDS_source->layout;
358 SDDS_DeferSavingLayout(SDDS_target, 1);
359 for (i = 0; i < source->n_parameters; i++) {
360 if ((index = SDDS_GetParameterIndex(SDDS_target, source->parameter_definition[i].name)) >= 0) {
361 /* already exists */
362 if (mode & SDDS_TRANSFER_KEEPOLD)
363 continue;
364 if (!(mode & SDDS_TRANSFER_OVERWRITE)) {
365 sprintf(messBuffer, "Unable to define parameter %s---already exists (SDDS_TransferAllParameterDefinitions)", source->parameter_definition[i].name);
366 SDDS_SetError(messBuffer);
367 SDDS_DeferSavingLayout(SDDS_target, 0);
368 return 0;
369 }
370 if (!SDDS_ChangeParameterInformation(SDDS_target, "symbol",
371 &source->parameter_definition[i].symbol,
372 SDDS_BY_INDEX, index) ||
373 !SDDS_ChangeParameterInformation(SDDS_target, "units",
374 &source->parameter_definition[i].units,
375 SDDS_BY_INDEX, index) ||
376 !SDDS_ChangeParameterInformation(SDDS_target, "description",
377 &source->parameter_definition[i].description,
378 SDDS_BY_INDEX, index) ||
379 !SDDS_ChangeParameterInformation(SDDS_target, "format_string",
380 &source->parameter_definition[i].format_string,
381 SDDS_BY_INDEX, index) ||
382 !SDDS_ChangeParameterInformation(SDDS_target, "type",
383 &source->parameter_definition[i].type, SDDS_BY_INDEX, index) ||
384 (source->parameter_definition[i].fixed_value != NULL && !SDDS_ChangeParameterInformation(SDDS_target, "fixed_value", &source->parameter_definition[i].fixed_value, SDDS_BY_INDEX, index))) {
385 SDDS_SetError("Unable to define parameter---problem with overwrite (SDDS_TransferAllParameterDefinitions)");
386 SDDS_DeferSavingLayout(SDDS_target, 0);
387 return 0;
388 }
389 if (source->parameter_definition[i].fixed_value == NULL)
390 target->parameter_definition[index].fixed_value = NULL;
391 target->parameter_definition[index].definition_mode = source->parameter_definition[index].definition_mode;
392 if (target->parameter_definition[index].type == SDDS_STRING)
393 target->parameter_definition[index].memory_number = SDDS_CreateRpnMemory(source->parameter_definition[i].name, 1);
394 else
395 target->parameter_definition[index].memory_number = SDDS_CreateRpnMemory(source->parameter_definition[i].name, 0);
396 } else {
397 if (SDDS_DefineParameter(SDDS_target, source->parameter_definition[i].name,
398 source->parameter_definition[i].symbol, source->parameter_definition[i].units, source->parameter_definition[i].description, source->parameter_definition[i].format_string, source->parameter_definition[i].type, source->parameter_definition[i].fixed_value) < 0) {
399 SDDS_SetError("Unable to define parameter (SDDS_TransferAllParameterDefinitions)");
400 SDDS_DeferSavingLayout(SDDS_target, 0);
401 return 0;
402 }
403 }
404 }
405 SDDS_DeferSavingLayout(SDDS_target, 0);
406 return 1;
407}

◆ SDDS_TransferArrayDefinition()

epicsShareFuncSDDS int32_t SDDS_TransferArrayDefinition ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Transfers an array definition from a source dataset to a target dataset.

This function defines an array in the target SDDS dataset to match the definition of an array in the source SDDS dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the array in the source dataset to be transferred.
newNameThe name of the array in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 111 of file SDDS_transfer.c.

111 {
112 ARRAY_DEFINITION *ardef;
113
114 if (!name || SDDS_StringIsBlank(name)) {
115 SDDS_SetError("Unable to transfer array definition--NULL or blank name passed (SDDS_TransferArrayDefinition)");
116 return 0;
117 }
118 if (!newName)
119 newName = name;
120 if (!(ardef = SDDS_GetArrayDefinition(source, name))) {
121 SDDS_SetError("Unable to transfer array definition--unknown array named (SDDS_TransferArrayDefinition)");
122 return 0;
123 }
124 if (SDDS_GetArrayIndex(target, newName) >= 0) {
125 SDDS_SetError("Unable to transfer array definition--array already present (SDDS_TransferArrayDefinition)");
126 return 0;
127 }
128 if (SDDS_DefineArray(target, newName, ardef->symbol, ardef->units, ardef->description, ardef->format_string, ardef->type, ardef->field_length, ardef->dimensions, ardef->group_name) < 0) {
130 SDDS_SetError("Unable to transfer array definition--call to define array failed (SDDS_TransferArrayDefinition)");
131 return 0;
132 }
134 return 1;
135}

◆ SDDS_TransferAssociateDefinition()

epicsShareFuncSDDS int32_t SDDS_TransferAssociateDefinition ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Transfers an associate definition from a source dataset to a target dataset.

This function defines an associate in the target SDDS dataset to match the definition of an associate in the source SDDS dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the associate in the source dataset to be transferred.
newNameThe name of the associate in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 149 of file SDDS_transfer.c.

149 {
151
152 if (!name || SDDS_StringIsBlank(name)) {
153 SDDS_SetError("Unable to transfer associate definition--NULL or blank name passed (SDDS_TransferAssociateDefinition)");
154 return 0;
155 }
156 if (!newName)
157 newName = name;
158 if ((asdef = SDDS_GetAssociateDefinition(target, name))) {
160 SDDS_SetError("Unable to transfer associate definition--associate already present (SDDS_TransferAssociateDefinition)");
161 return 0;
162 }
163 if (!(asdef = SDDS_GetAssociateDefinition(source, newName))) {
164 SDDS_SetError("Unable to transfer associate definition--unknown associate named (SDDS_TransferAssociateDefinition)");
165 return 0;
166 }
167 if (SDDS_DefineAssociate(target, newName, asdef->filename, asdef->path, asdef->description, asdef->contents, asdef->sdds) < 0) {
169 SDDS_SetError("Unable to transfer associate definition--call to define associate failed (SDDS_TransferAssociateDefinition)");
170 return 0;
171 }
173 return 1;
174}
ASSOCIATE_DEFINITION * SDDS_GetAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified associate from the SDDS dataset.
Definition SDDS_utils.c:883
int32_t SDDS_FreeAssociateDefinition(ASSOCIATE_DEFINITION *source)
Frees memory allocated for an associate definition.
Definition SDDS_utils.c:944

◆ SDDS_TransferColumnDefinition()

epicsShareFuncSDDS int32_t SDDS_TransferColumnDefinition ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Transfers a column definition from a source dataset to a target dataset.

This function defines a column in the target SDDS dataset to match the definition of a column in the source SDDS dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the column in the source dataset to be transferred.
newNameThe name of the column in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 35 of file SDDS_transfer.c.

35 {
36 COLUMN_DEFINITION *coldef;
37
38 if (!name || SDDS_StringIsBlank(name)) {
39 SDDS_SetError("Unable to transfer column definition--NULL or blank name passed (SDDS_TransferColumnDefinition)");
40 return 0;
41 }
42 if (!newName)
43 newName = name;
44 if (!(coldef = SDDS_GetColumnDefinition(source, name))) {
45 SDDS_SetError("Unable to transfer column definition--unknown column named (SDDS_TransferColumnDefinition)");
46 return 0;
47 }
48 if (SDDS_GetColumnIndex(target, newName) >= 0) {
49 SDDS_SetError("Unable to transfer column definition--column already present (SDDS_TransferColumnDefinition)");
50 return 0;
51 }
52 if (SDDS_DefineColumn(target, newName, coldef->symbol, coldef->units, coldef->description, coldef->format_string, coldef->type, coldef->field_length) < 0) {
54 SDDS_SetError("Unable to transfer column definition--call to define column failed (SDDS_TransferColumnDefinition)");
55 return 0;
56 }
58 return 1;
59}

◆ SDDS_TransferParameterDefinition()

epicsShareFuncSDDS int32_t SDDS_TransferParameterDefinition ( SDDS_DATASET * target,
SDDS_DATASET * source,
char * name,
char * newName )
extern

Transfers a parameter definition from a source dataset to a target dataset.

This function defines a parameter in the target SDDS dataset to match the definition of a parameter in the source SDDS dataset.

Parameters
targetPointer to the SDDS_DATASET structure representing the target dataset.
sourcePointer to the SDDS_DATASET structure representing the source dataset.
nameThe name of the parameter in the source dataset to be transferred.
newNameThe name of the parameter in the target dataset. If NULL, the original name is used.
Returns
1 on success; 0 on failure. On failure, an error message is recorded.

Definition at line 73 of file SDDS_transfer.c.

73 {
75
76 if (!name || SDDS_StringIsBlank(name)) {
77 SDDS_SetError("Unable to transfer parameter definition--NULL or blank name passed (SDDS_TransferParameterDefinition)");
78 return 0;
79 }
80 if (!newName)
81 newName = name;
82 if (!(pardef = SDDS_GetParameterDefinition(source, name))) {
83 SDDS_SetError("Unable to transfer parameter definition--unknown parameter named (SDDS_TransferParameterDefinition)");
84 return 0;
85 }
86 if (SDDS_GetParameterIndex(target, newName) >= 0) {
87 SDDS_SetError("Unable to transfer parameter definition--parameter already present (SDDS_TransferParameterDefinition)");
88 return 0;
89 }
90 if (SDDS_DefineParameter(target, newName, pardef->symbol, pardef->units, pardef->description, pardef->format_string, pardef->type, NULL) < 0) {
92 SDDS_SetError("Unable to transfer parameter definition--call to define parameter failed (SDDS_TransferParameterDefinition)");
93 return 0;
94 }
96 return 1;
97}

◆ SDDS_UnescapeQuotes()

epicsShareFuncSDDS void SDDS_UnescapeQuotes ( char * s,
char quote_char )
extern

Removes escape characters from quote characters within a string.

This function scans the input string s and removes backslashes (\) that precede the specified quote_char, effectively unescaping the quotes. This is useful for processing strings that have been prepared with escaped quotes.

Parameters
[in,out]sPointer to the string in which quotes will be unescaped. The string will be modified in place.
[in]quote_charThe quote character to unescape (e.g., ").
Note
The function modifies the string s by shifting characters to remove the escape backslashes. It assumes that s is properly null-terminated.
See also
SDDS_EscapeQuotes

Definition at line 1932 of file SDDS_utils.c.

1932 {
1933 char *ptr;
1934 ptr = s;
1935 while (*ptr) {
1936 if (*ptr == quote_char && ptr != s && *(ptr - 1) == '\\')
1937 strcpy(ptr - 1, ptr);
1938 else
1939 ptr++;
1940 }
1941}

◆ SDDS_UpdatePage()

epicsShareFuncSDDS int32_t SDDS_UpdatePage ( SDDS_DATASET * SDDS_dataset,
uint32_t mode )
extern

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

epicsShareFuncSDDS int32_t SDDS_UpdateRowCount ( SDDS_DATASET * SDDS_dataset)
extern

Updates the row count in the SDDS file for fixed row count mode.

Parameters
SDDS_datasetThe SDDS dataset to update.
Returns
1 on success, 0 on error.

Definition at line 1702 of file SDDS_input.c.

1702 {
1703 FILE *fp;
1704 SDDS_FILEBUFFER *fBuffer;
1705 int64_t offset, rows;
1706 int32_t rows32;
1707 char *outputEndianess = NULL;
1708
1709 if ((SDDS_dataset->layout.gzipFile) || (SDDS_dataset->layout.lzmaFile))
1710 return (1);
1711 if (!(fp = SDDS_dataset->layout.fp)) {
1712 SDDS_SetError("Unable to update page--file pointer is NULL (SDDS_UpdateRowCount)");
1713 return (0);
1714 }
1715#if DEBUG
1716 fprintf(stderr, "Updating rowcount in file %s with pointer %p\n", SDDS_dataset->layout.filename ? SDDS_dataset->layout.filename : "NULL", fp);
1717#endif
1718 fBuffer = &SDDS_dataset->fBuffer;
1719 if (!SDDS_FlushBuffer(fp, fBuffer)) {
1720 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_UpdateRowCount)");
1721 return (0);
1722 }
1723 offset = ftell(fp);
1724 if (SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
1725 SDDS_SetError("Unable to update page--failure doing fseek (SDDS_UpdateRowCount)");
1726 return (0);
1727 }
1728 rows = SDDS_CountRowsOfInterest(SDDS_dataset) + SDDS_dataset->first_row_in_mem;
1729 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII) {
1730 fprintf(fp, "%20" PRId64 "\n", rows);
1731 } else {
1732
1733 if (rows > INT32_MAX) {
1734 // Don't go over this limit because it has a different format
1735 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateRowCount)");
1736 return (0);
1737 }
1738 rows32 = (int32_t)rows;
1739 if ((outputEndianess = getenv("SDDS_OUTPUT_ENDIANESS"))) {
1740 if (((strncmp(outputEndianess, "big", 3) == 0) && (SDDS_IsBigEndianMachine() == 0)) || ((strncmp(outputEndianess, "little", 6) == 0) && (SDDS_IsBigEndianMachine() == 1)))
1741 SDDS_SwapLong(&rows32);
1742 }
1743 if (fwrite(&rows32, sizeof(rows32), 1, fp) != 1) {
1744 SDDS_SetError("Unable to update page--failure writing number of rows (SDDS_UpdateRowCount)");
1745 return (0);
1746 }
1747 }
1748 if (SDDS_fseek(fp, offset, 0) == -1) {
1749 SDDS_SetError("Unable to update page--failure doing fseek to end of page (SDDS_UpdateRowCount)");
1750 return (0);
1751 }
1752 return (1);
1753}
int32_t SDDS_FlushBuffer(FILE *fp, SDDS_FILEBUFFER *fBuffer)
int32_t SDDS_fseek(FILE *fp, int64_t offset, int32_t dir)
Sets the file position indicator for a given file stream with retry logic.

◆ SDDS_VerifyArrayExists()

epicsShareFuncSDDS int32_t SDDS_VerifyArrayExists ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Verifies the existence of an array in the SDDS dataset based on specified criteria.

This function searches for an array within the SDDS dataset that matches the given criteria defined by the mode. It returns the index of the first matching array or -1 if no match is found.

The function supports the following modes:

  • FIND_SPECIFIED_TYPE:
    • Parameters: int32_t type, char *name
    • Description: Finds the first array with the specified type.
  • FIND_ANY_TYPE:
    • Parameters: char *name
    • Description: Finds the first array with any type.
  • FIND_NUMERIC_TYPE:
    • Parameters: char *name
    • Description: Finds the first array with a numeric type.
  • FIND_FLOATING_TYPE:
    • Parameters: char *name
    • Description: Finds the first array with a floating type.
  • FIND_INTEGER_TYPE:
    • Parameters: char *name
    • Description: Finds the first array with an integer type.
Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to be searched.
[in]modeSpecifies the mode for matching arrays. Valid modes are:
  • FIND_SPECIFIED_TYPE
  • FIND_ANY_TYPE
  • FIND_NUMERIC_TYPE
  • FIND_FLOATING_TYPE
  • FIND_INTEGER_TYPE
[in]...Variable arguments depending on mode:
  • FIND_SPECIFIED_TYPE: int32_t type, followed by char *name
  • Other Modes: char *name
Returns
  • Returns the index (int32_t) of the first matched array.
  • Returns -1 if no matching array is found.
Note
  • The caller must ensure that the variable arguments match the expected parameters for the specified mode.
Warning
  • Passing incorrect types or mismatched arguments may lead to undefined behavior.
See also
SDDS_GetArrayIndex, SDDS_CheckArray, SDDS_MatchArrays

Definition at line 5344 of file SDDS_utils.c.

5344 {
5345 int32_t index, type, thisType;
5346 va_list argptr;
5347 char *name;
5348
5349 va_start(argptr, mode);
5350 type = 0;
5351
5352 if (mode == FIND_SPECIFIED_TYPE)
5353 type = va_arg(argptr, int32_t);
5354 name = va_arg(argptr, char *);
5355 if ((index = SDDS_GetArrayIndex(SDDS_dataset, name)) >= 0) {
5356 thisType = SDDS_GetArrayType(SDDS_dataset, index);
5357 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE && SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE && SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE && SDDS_INTEGER_TYPE(thisType))) {
5358 va_end(argptr);
5359 return (index);
5360 }
5361 }
5362 va_end(argptr);
5363 return (-1);
5364}

◆ SDDS_VerifyColumnExists()

epicsShareFuncSDDS int32_t SDDS_VerifyColumnExists ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Verifies the existence of a column in the SDDS dataset based on specified criteria.

This function searches for a column within the SDDS dataset that matches the given criteria defined by the mode. It returns the index of the first matching column or -1 if no match is found.

The function supports the following modes:

  • FIND_SPECIFIED_TYPE:
    • Parameters: int32_t type, char *name
    • Description: Finds the first column with the specified type.
  • FIND_ANY_TYPE:
    • Parameters: char *name
    • Description: Finds the first column with any type.
  • FIND_NUMERIC_TYPE:
    • Parameters: char *name
    • Description: Finds the first column with a numeric type.
  • FIND_FLOATING_TYPE:
    • Parameters: char *name
    • Description: Finds the first column with a floating type.
  • FIND_INTEGER_TYPE:
    • Parameters: char *name
    • Description: Finds the first column with an integer type.
Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to be searched.
[in]modeSpecifies the mode for matching columns. Valid modes are:
  • FIND_SPECIFIED_TYPE
  • FIND_ANY_TYPE
  • FIND_NUMERIC_TYPE
  • FIND_FLOATING_TYPE
  • FIND_INTEGER_TYPE
[in]...Variable arguments depending on mode:
  • FIND_SPECIFIED_TYPE: int32_t type, followed by char *name
  • Other Modes: char *name
Returns
  • Returns the index (int32_t) of the first matched column.
  • Returns -1 if no matching column is found.
Note
  • The caller must ensure that the variable arguments match the expected parameters for the specified mode.
Warning
  • Passing incorrect types or mismatched arguments may lead to undefined behavior.
See also
SDDS_GetColumnIndex, SDDS_CheckColumn, SDDS_MatchColumns

Definition at line 5420 of file SDDS_utils.c.

5420 {
5421 int32_t index;
5422 int32_t type, thisType;
5423 va_list argptr;
5424 char *name;
5425
5426 va_start(argptr, mode);
5427 type = 0;
5428
5429 if (mode == FIND_SPECIFIED_TYPE)
5430 type = va_arg(argptr, int32_t);
5431 name = va_arg(argptr, char *);
5432 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name)) >= 0) {
5433 thisType = SDDS_GetColumnType(SDDS_dataset, index);
5434 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE && SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE && SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE && SDDS_INTEGER_TYPE(thisType))) {
5435 va_end(argptr);
5436 return (index);
5437 }
5438 }
5439 va_end(argptr);
5440 return (-1);
5441}

◆ SDDS_VerifyParameterExists()

epicsShareFuncSDDS int32_t SDDS_VerifyParameterExists ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )
extern

Verifies the existence of a parameter in the SDDS dataset based on specified criteria.

This function searches for a parameter within the SDDS dataset that matches the given criteria defined by the mode. It returns the index of the first matching parameter or -1 if no match is found.

The function supports the following modes:

  • FIND_SPECIFIED_TYPE:
    • Parameters: int32_t type, char *name
    • Description: Finds the first parameter with the specified type.
  • FIND_ANY_TYPE:
    • Parameters: char *name
    • Description: Finds the first parameter with any type.
  • FIND_NUMERIC_TYPE:
    • Parameters: char *name
    • Description: Finds the first parameter with a numeric type.
  • FIND_FLOATING_TYPE:
    • Parameters: char *name
    • Description: Finds the first parameter with a floating type.
  • FIND_INTEGER_TYPE:
    • Parameters: char *name
    • Description: Finds the first parameter with an integer type.
Parameters
[in]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to be searched.
[in]modeSpecifies the mode for matching parameters. Valid modes are:
  • FIND_SPECIFIED_TYPE
  • FIND_ANY_TYPE
  • FIND_NUMERIC_TYPE
  • FIND_FLOATING_TYPE
  • FIND_INTEGER_TYPE
[in]...Variable arguments depending on mode:
  • FIND_SPECIFIED_TYPE: int32_t type, followed by char *name
  • Other Modes: char *name
Returns
  • Returns the index (int32_t) of the first matched parameter.
  • Returns -1 if no matching parameter is found.
Note
  • The caller must ensure that the variable arguments match the expected parameters for the specified mode.
Warning
  • Passing incorrect types or mismatched arguments may lead to undefined behavior.
See also
SDDS_GetParameterIndex, SDDS_CheckParameter, SDDS_MatchParameters

Definition at line 5497 of file SDDS_utils.c.

5497 {
5498 int32_t index, type, thisType;
5499 va_list argptr;
5500 char *name;
5501
5502 va_start(argptr, mode);
5503 type = 0;
5504
5505 if (mode == FIND_SPECIFIED_TYPE)
5506 type = va_arg(argptr, int32_t);
5507 name = va_arg(argptr, char *);
5508 if ((index = SDDS_GetParameterIndex(SDDS_dataset, name)) >= 0) {
5509 thisType = SDDS_GetParameterType(SDDS_dataset, index);
5510 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE && SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE && SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE && SDDS_INTEGER_TYPE(thisType))) {
5511 va_end(argptr);
5512 return (index);
5513 }
5514 }
5515 va_end(argptr);
5516 return (-1);
5517}

◆ SDDS_VerifyPrintfFormat()

epicsShareFuncSDDS int32_t SDDS_VerifyPrintfFormat ( const char * string,
int32_t type )
extern

Verifies that a printf format string is compatible with a specified data type.

This function checks whether the provided printf format string is appropriate for the given SDDS data type. It ensures that the format specifier matches the type, preventing potential formatting errors during data output.

Parameters
[in]stringThe printf format string to be verified.
[in]typeThe data type against which the format string is verified. Must be one of the SDDS type constants:
  • SDDS_LONGDOUBLE
  • SDDS_DOUBLE
  • SDDS_FLOAT
  • SDDS_LONG
  • SDDS_LONG64
  • SDDS_ULONG
  • SDDS_ULONG64
  • SDDS_SHORT
  • SDDS_USHORT
  • SDDS_STRING
  • SDDS_CHARACTER
Returns
Returns 1 if the format string is valid for the specified type; otherwise, returns 0 and records an error message.
Note
This function does not modify the format string; it only validates its compatibility with the given type.
See also
SDDS_SetError

Definition at line 750 of file SDDS_utils.c.

750 {
751 char *percent, *s;
752 int32_t len, tmp;
753
754 s = (char *)string;
755 do {
756 if ((percent = strchr(s, '%'))) {
757 if (*(percent + 1) != '%')
758 break;
759 s = percent + 1;
760 }
761 } while (percent);
762 if (!percent || !*++percent)
763 return (0);
764
765 s = percent;
766
767 switch (type) {
768 case SDDS_LONGDOUBLE:
769 case SDDS_DOUBLE:
770 case SDDS_FLOAT:
771 if ((len = strcspn(s, "fegEG")) == strlen(s))
772 return (0);
773 if (len == 0)
774 return (1);
775 if ((tmp = strspn(s, "-+.0123456789 ")) < len)
776 return (0);
777 break;
778 case SDDS_LONG:
779 case SDDS_LONG64:
780 if ((len = strcspn(s, "d")) == strlen(s))
781 return (0);
782 /* if (*(s+len-1)!='l')
783 return(0); */
784 if (--len == 0)
785 return (1);
786 if ((tmp = strspn(s, "-+.0123456789 ")) < len)
787 return (0);
788 break;
789 case SDDS_ULONG:
790 case SDDS_ULONG64:
791 if ((len = strcspn(s, "u")) == strlen(s))
792 return (0);
793 /* if (*(s+len-1)!='l')
794 return(0); */
795 if (--len == 0)
796 return (1);
797 if ((tmp = strspn(s, "-+.0123456789 ")) < len)
798 return (0);
799 break;
800 case SDDS_SHORT:
801 if ((len = strcspn(s, "d")) == strlen(s))
802 return (0);
803 if (*(s + len - 1) != 'h')
804 return (0);
805 if (--len == 0)
806 return (1);
807 if ((tmp = strspn(s, "-+.0123456789 ")) < len)
808 return (0);
809 break;
810 case SDDS_USHORT:
811 if ((len = strcspn(s, "u")) == strlen(s))
812 return (0);
813 if (*(s + len - 1) != 'h')
814 return (0);
815 if (--len == 0)
816 return (1);
817 if ((tmp = strspn(s, "-+.0123456789 ")) < len)
818 return (0);
819 break;
820 case SDDS_STRING:
821 if ((len = strcspn(s, "s")) == strlen(s))
822 return (0);
823 if (len == 0)
824 return (1);
825 if ((tmp = strspn(s, "-0123456789")) < len)
826 return (0);
827 break;
828 case SDDS_CHARACTER:
829 if ((len = strcspn(s, "c")) == strlen(s))
830 return (0);
831 if (len != 0)
832 return (0);
833 break;
834 default:
835 return (0);
836 }
837 /* no errors found--its probably okay */
838 return (1);
839}

◆ SDDS_Warning()

epicsShareFuncSDDS void SDDS_Warning ( char * message)
extern

Prints a warning message to stderr.

This function outputs a warning message to the specified FILE stream, typically stderr. If a program name has been registered using SDDS_RegisterProgramName, it is included in the warning message.

Parameters
[in]messageThe warning message to be printed. If NULL, a default message "?" is used.
Note
This function does not record the warning as an error; it only prints the message.
See also
SDDS_RegisterProgramName

Definition at line 362 of file SDDS_utils.c.

362 {
363 if (registeredProgramName)
364 fprintf(stderr, "Warning (%s): %s\n", registeredProgramName, message ? message : "?");
365 else
366 fprintf(stderr, "Warning: %s\n", message ? message : "?");
367}

◆ SDDS_WriteBinaryString()

epicsShareFuncSDDS int32_t SDDS_WriteBinaryString ( char * string,
FILE * fp,
SDDS_FILEBUFFER * fBuffer )
extern

Writes a binary string to a file with buffering.

This function writes a binary string to the specified file by first writing the length of the string followed by the string's content to ensure proper binary formatting. If the input string is NULL, an empty string is written instead. The writing operation utilizes a buffered approach to enhance performance.

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

Definition at line 2517 of file SDDS_binary.c.

2517 {
2518 int32_t length;
2519 static char *dummy_string = "";
2520 if (!string)
2521 string = dummy_string;
2522 length = strlen(string);
2523 if (!SDDS_BufferedWrite(&length, sizeof(length), fp, fBuffer)) {
2524 SDDS_SetError("Unable to write string--error writing length");
2525 return (0);
2526 }
2527 if (length && !SDDS_BufferedWrite(string, sizeof(*string) * length, fp, fBuffer)) {
2528 SDDS_SetError("Unable to write string--error writing contents");
2529 return (0);
2530 }
2531 return (1);
2532}
int32_t SDDS_BufferedWrite(void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer)

◆ SDDS_WriteLayout()

epicsShareFuncSDDS int32_t SDDS_WriteLayout ( SDDS_DATASET * SDDS_dataset)
extern

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.

◆ SDDS_WriteNonNativeBinaryArrays()

int32_t SDDS_WriteNonNativeBinaryArrays ( SDDS_DATASET * SDDS_dataset)

Writes non-native endian binary arrays to an SDDS dataset.

This function iterates through all array definitions in the specified SDDS dataset and writes their binary data to the underlying file. It handles various data types, including short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, and long double. For string arrays, it writes each string individually, ensuring proper memory management and byte order conversion. The function supports different compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files. After writing, it swaps the endianness of the array data to match the system's native byte order.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to write to.
Returns
int32_t Returns 1 on successful writing of all arrays, or 0 if an error occurred.
Return values
1All non-native endian arrays were successfully written and byte-swapped.
0An error occurred during the write operation, such as I/O failures, memory allocation issues, or corrupted array definitions.
Note
This function modifies the dataset's array data during the write process. Ensure that the dataset is properly initialized and opened for writing before invoking this function. After writing, the dataset's state is updated to reflect the written arrays.

Definition at line 5344 of file SDDS_binary.c.

5344 {
5345 int32_t i, j, dimension, zero = 0;
5346 SDDS_LAYOUT *layout;
5347 FILE *fp;
5348 struct lzmafile *lzmafp;
5349 SDDS_FILEBUFFER *fBuffer;
5350#if defined(zLib)
5351 gzFile gzfp;
5352#endif
5353 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteNonNativeBinaryArrays"))
5354 return (0);
5355 SDDS_SwapEndsArrayData(SDDS_dataset);
5356
5357 layout = &SDDS_dataset->layout;
5358 fBuffer = &SDDS_dataset->fBuffer;
5359#if defined(zLib)
5360 if (SDDS_dataset->layout.gzipFile) {
5361 gzfp = layout->gzfp;
5362 for (i = 0; i < layout->n_arrays; i++) {
5363 if (!SDDS_dataset->array[i].dimension) {
5364 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5365 if (!SDDS_GZipBufferedWrite(&zero, sizeof(zero), gzfp, fBuffer)) {
5366 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5367 SDDS_SwapEndsArrayData(SDDS_dataset);
5368 return 0;
5369 }
5370 continue;
5371 }
5372
5373 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5374 dimension = SDDS_dataset->array[i].dimension[j];
5375 SDDS_SwapLong(&dimension);
5376 if (!SDDS_GZipBufferedWrite(&dimension, sizeof(dimension), gzfp, fBuffer)) {
5377 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5378 SDDS_SwapEndsArrayData(SDDS_dataset);
5379 return (0);
5380 }
5381 }
5382 if (layout->array_definition[i].type == SDDS_STRING) {
5383 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5384 if (!SDDS_GZipWriteNonNativeBinaryString(((char **)SDDS_dataset->array[i].data)[j], gzfp, fBuffer)) {
5385 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5386 SDDS_SwapEndsArrayData(SDDS_dataset);
5387 return (0);
5388 }
5389 }
5390 } else if (!SDDS_GZipBufferedWrite(SDDS_dataset->array[i].data, SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, gzfp, fBuffer)) {
5391 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5392 SDDS_SwapEndsArrayData(SDDS_dataset);
5393 return (0);
5394 }
5395 }
5396 } else {
5397#endif
5398 if (SDDS_dataset->layout.lzmaFile) {
5399 lzmafp = layout->lzmafp;
5400 for (i = 0; i < layout->n_arrays; i++) {
5401 if (!SDDS_dataset->array[i].dimension) {
5402 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5403 if (!SDDS_LZMABufferedWrite(&zero, sizeof(zero), lzmafp, fBuffer)) {
5404 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5405 SDDS_SwapEndsArrayData(SDDS_dataset);
5406 return 0;
5407 }
5408 continue;
5409 }
5410
5411 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5412 dimension = SDDS_dataset->array[i].dimension[j];
5413 SDDS_SwapLong(&dimension);
5414 if (!SDDS_LZMABufferedWrite(&dimension, sizeof(dimension), lzmafp, fBuffer)) {
5415 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5416 SDDS_SwapEndsArrayData(SDDS_dataset);
5417 return (0);
5418 }
5419 }
5420 if (layout->array_definition[i].type == SDDS_STRING) {
5421 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5422 if (!SDDS_LZMAWriteNonNativeBinaryString(((char **)SDDS_dataset->array[i].data)[j], lzmafp, fBuffer)) {
5423 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5424 SDDS_SwapEndsArrayData(SDDS_dataset);
5425 return (0);
5426 }
5427 }
5428 } else if (!SDDS_LZMABufferedWrite(SDDS_dataset->array[i].data, SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, lzmafp, fBuffer)) {
5429 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5430 SDDS_SwapEndsArrayData(SDDS_dataset);
5431 return (0);
5432 }
5433 }
5434 } else {
5435 fp = layout->fp;
5436 for (i = 0; i < layout->n_arrays; i++) {
5437 if (!SDDS_dataset->array[i].dimension) {
5438 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5439 if (!SDDS_BufferedWrite(&zero, sizeof(zero), fp, fBuffer)) {
5440 SDDS_SetError("Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5441 SDDS_SwapEndsArrayData(SDDS_dataset);
5442 return 0;
5443 }
5444 continue;
5445 }
5446
5447 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5448 dimension = SDDS_dataset->array[i].dimension[j];
5449 SDDS_SwapLong(&dimension);
5450 if (!SDDS_BufferedWrite(&dimension, sizeof(dimension), fp, fBuffer)) {
5451 SDDS_SetError("Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5452 SDDS_SwapEndsArrayData(SDDS_dataset);
5453 return (0);
5454 }
5455 }
5456 if (layout->array_definition[i].type == SDDS_STRING) {
5457 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5458 if (!SDDS_WriteNonNativeBinaryString(((char **)SDDS_dataset->array[i].data)[j], fp, fBuffer)) {
5459 SDDS_SetError("Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5460 SDDS_SwapEndsArrayData(SDDS_dataset);
5461 return (0);
5462 }
5463 }
5464 } else if (!SDDS_BufferedWrite(SDDS_dataset->array[i].data, SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, fp, fBuffer)) {
5465 SDDS_SetError("Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5466 SDDS_SwapEndsArrayData(SDDS_dataset);
5467 return (0);
5468 }
5469 }
5470 }
5471#if defined(zLib)
5472 }
5473#endif
5474 SDDS_SwapEndsArrayData(SDDS_dataset);
5475 return (1);
5476}
int32_t SDDS_WriteNonNativeBinaryString(char *string, FILE *fp, SDDS_FILEBUFFER *fBuffer)
Writes a non-native endian binary string to a file.
int32_t SDDS_LZMABufferedWrite(void *target, int64_t targetSize, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
int32_t SDDS_LZMAWriteNonNativeBinaryString(char *string, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
Writes a non-native endian binary string to an LZMA-compressed file.

◆ SDDS_WriteNonNativeBinaryPage()

epicsShareFuncSDDS int32_t SDDS_WriteNonNativeBinaryPage ( SDDS_DATASET * SDDS_dataset)
extern

Writes a non-native endian binary page to an SDDS dataset.

This function writes a binary page to the specified SDDS dataset, handling byte order reversal to convert between little-endian and big-endian formats. It manages various compression formats, including uncompressed, GZIP-compressed, and LZMA-compressed files. The function performs the following operations:

  • Counts the number of rows to write.
  • Writes the row count with appropriate byte order handling.
  • Writes non-native endian parameters and arrays.
  • Writes column data in either column-major or row-major format based on the dataset's configuration.
  • Flushes the buffer to ensure all data is written to the file.
Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to write to.
Returns
int32_t Returns 1 on successful writing of the binary page, or 0 if an error occurred.
Return values
1The binary page was successfully written and byte-swapped.
0An error occurred during the write operation, such as I/O failures, memory allocation issues, or corrupted dataset definitions.
Note
This function modifies the dataset's internal structures during the write process. Ensure that the dataset is properly initialized and opened for writing before invoking this function. After writing, the dataset's state is updated to reflect the newly written page.

Definition at line 4980 of file SDDS_binary.c.

4984{
4985 FILE *fp;
4986 struct lzmafile *lzmafp = NULL;
4987 int64_t i, rows, fixed_rows;
4988 int32_t min32 = INT32_MIN, rows32;
4989 SDDS_FILEBUFFER *fBuffer;
4990#if defined(zLib)
4991 gzFile gzfp = NULL;
4992#endif
4993
4994 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteNonNativeBinaryPage"))
4995 return (0);
4996 if (!(fp = SDDS_dataset->layout.fp)) {
4997 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
4998 return (0);
4999 }
5000 fBuffer = &SDDS_dataset->fBuffer;
5001
5002 if (!fBuffer->buffer) {
5003 if (!(fBuffer->buffer = fBuffer->data = SDDS_Malloc(sizeof(char) * defaultIOBufferSize))) {
5004 SDDS_SetError("Unable to do buffered read--allocation failure (SDDS_WriteNonNativeBinaryPage)");
5005 return 0;
5006 }
5007 fBuffer->bufferSize = defaultIOBufferSize;
5008 fBuffer->bytesLeft = defaultIOBufferSize;
5009 }
5010 SDDS_SwapLong(&min32);
5011
5012 rows = SDDS_CountRowsOfInterest(SDDS_dataset);
5013#if defined(zLib)
5014 if (SDDS_dataset->layout.gzipFile) {
5015 if (!(gzfp = SDDS_dataset->layout.gzfp)) {
5016 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
5017 return (0);
5018 }
5019 SDDS_dataset->rowcount_offset = gztell(gzfp);
5020 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5021 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5022 if (fixed_rows > INT32_MAX) {
5023 if (!SDDS_GZipBufferedWrite(&min32, sizeof(min32), gzfp, fBuffer)) {
5024 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5025 return (0);
5026 }
5027 SDDS_SwapLong64(&fixed_rows);
5028 if (!SDDS_GZipBufferedWrite(&fixed_rows, sizeof(fixed_rows), gzfp, fBuffer)) {
5029 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5030 return (0);
5031 }
5032 SDDS_SwapLong64(&fixed_rows);
5033 } else {
5034 rows32 = (int32_t)fixed_rows;
5035 SDDS_SwapLong(&rows32);
5036 if (!SDDS_GZipBufferedWrite(&rows32, sizeof(rows32), gzfp, fBuffer)) {
5037 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5038 return (0);
5039 }
5040 }
5041 } else {
5042 if (rows > INT32_MAX) {
5043 if (!SDDS_GZipBufferedWrite(&min32, sizeof(min32), gzfp, fBuffer)) {
5044 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5045 return (0);
5046 }
5047 SDDS_SwapLong64(&rows);
5048 if (!SDDS_GZipBufferedWrite(&rows, sizeof(rows), gzfp, fBuffer)) {
5049 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5050 return (0);
5051 }
5052 SDDS_SwapLong64(&rows);
5053 } else {
5054 rows32 = (int32_t)rows;
5055 SDDS_SwapLong(&rows32);
5056 if (!SDDS_GZipBufferedWrite(&rows32, sizeof(rows32), gzfp, fBuffer)) {
5057 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5058 return (0);
5059 }
5060 }
5061 }
5062 } else {
5063#endif
5064 if (SDDS_dataset->layout.lzmaFile) {
5065 if (!(lzmafp = SDDS_dataset->layout.lzmafp)) {
5066 SDDS_SetError("Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
5067 return (0);
5068 }
5069 SDDS_dataset->rowcount_offset = lzma_tell(lzmafp);
5070 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5071 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5072 if (fixed_rows > INT32_MAX) {
5073 if (!SDDS_LZMABufferedWrite(&min32, sizeof(min32), lzmafp, fBuffer)) {
5074 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5075 return (0);
5076 }
5077 SDDS_SwapLong64(&fixed_rows);
5078 if (!SDDS_LZMABufferedWrite(&fixed_rows, sizeof(fixed_rows), lzmafp, fBuffer)) {
5079 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5080 return (0);
5081 }
5082 SDDS_SwapLong64(&fixed_rows);
5083 } else {
5084 rows32 = (int32_t)fixed_rows;
5085 SDDS_SwapLong(&rows32);
5086 if (!SDDS_LZMABufferedWrite(&rows32, sizeof(rows32), lzmafp, fBuffer)) {
5087 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5088 return (0);
5089 }
5090 }
5091 } else {
5092 if (rows > INT32_MAX) {
5093 if (!SDDS_LZMABufferedWrite(&min32, sizeof(min32), lzmafp, fBuffer)) {
5094 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5095 return (0);
5096 }
5097 SDDS_SwapLong64(&rows);
5098 if (!SDDS_LZMABufferedWrite(&rows, sizeof(rows), lzmafp, fBuffer)) {
5099 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5100 return (0);
5101 }
5102 SDDS_SwapLong64(&rows);
5103 } else {
5104 rows32 = (int32_t)rows;
5105 SDDS_SwapLong(&rows32);
5106 if (!SDDS_LZMABufferedWrite(&rows32, sizeof(rows32), lzmafp, fBuffer)) {
5107 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5108 return (0);
5109 }
5110 }
5111 }
5112 } else {
5113 SDDS_dataset->rowcount_offset = ftell(fp);
5114 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5115 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5116 if (fixed_rows > INT32_MAX) {
5117 if (!SDDS_BufferedWrite(&min32, sizeof(min32), fp, fBuffer)) {
5118 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5119 return (0);
5120 }
5121 SDDS_SwapLong64(&fixed_rows);
5122 if (!SDDS_BufferedWrite(&fixed_rows, sizeof(fixed_rows), fp, fBuffer)) {
5123 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5124 return (0);
5125 }
5126 SDDS_SwapLong64(&fixed_rows);
5127 } else {
5128 rows32 = (int32_t)fixed_rows;
5129 SDDS_SwapLong(&rows32);
5130 if (!SDDS_BufferedWrite(&rows32, sizeof(rows32), fp, fBuffer)) {
5131 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5132 return (0);
5133 }
5134 }
5135 } else {
5136 if (rows > INT32_MAX) {
5137 if (!SDDS_BufferedWrite(&min32, sizeof(min32), fp, fBuffer)) {
5138 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5139 return (0);
5140 }
5141 SDDS_SwapLong64(&rows);
5142 if (!SDDS_BufferedWrite(&rows, sizeof(rows), fp, fBuffer)) {
5143 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5144 return (0);
5145 }
5146 SDDS_SwapLong64(&rows);
5147 } else {
5148 rows32 = (int32_t)rows;
5149 SDDS_SwapLong(&rows32);
5150 if (!SDDS_BufferedWrite(&rows32, sizeof(rows32), fp, fBuffer)) {
5151 SDDS_SetError("Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5152 return (0);
5153 }
5154 }
5155 }
5156 }
5157#if defined(zLib)
5158 }
5159#endif
5160 if (!SDDS_WriteNonNativeBinaryParameters(SDDS_dataset)) {
5161 SDDS_SetError("Unable to write page--parameter writing problem (SDDS_WriteNonNativeBinaryPage)");
5162 return 0;
5163 }
5164 if (!SDDS_WriteNonNativeBinaryArrays(SDDS_dataset)) {
5165 SDDS_SetError("Unable to write page--array writing problem (SDDS_WriteNonNativeBinaryPage)");
5166 return 0;
5167 }
5168 SDDS_SwapEndsColumnData(SDDS_dataset);
5169 if (SDDS_dataset->layout.n_columns) {
5170 if (SDDS_dataset->layout.data_mode.column_major) {
5171 if (!SDDS_WriteNonNativeBinaryColumns(SDDS_dataset)) {
5172 SDDS_SetError("Unable to write page--column writing problem (SDDS_WriteNonNativeBinaryPage)");
5173 return 0;
5174 }
5175 } else {
5176 for (i = 0; i < SDDS_dataset->n_rows; i++) {
5177 if (SDDS_dataset->row_flag[i]) {
5178 if (!SDDS_WriteNonNativeBinaryRow(SDDS_dataset, i)) {
5179 SDDS_SetError("Unable to write page--row writing problem (SDDS_WriteNonNativeBinaryPage)");
5180 return 0;
5181 }
5182 }
5183 }
5184 }
5185 }
5186 SDDS_SwapEndsColumnData(SDDS_dataset);
5187#if defined(zLib)
5188 if (SDDS_dataset->layout.gzipFile) {
5189 if (!SDDS_GZipFlushBuffer(gzfp, fBuffer)) {
5190 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5191 return 0;
5192 }
5193 } else {
5194#endif
5195 if (SDDS_dataset->layout.lzmaFile) {
5196 if (!SDDS_LZMAFlushBuffer(lzmafp, fBuffer)) {
5197 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5198 return 0;
5199 }
5200 } else {
5201 if (!SDDS_FlushBuffer(fp, fBuffer)) {
5202 SDDS_SetError("Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5203 return 0;
5204 }
5205 }
5206#if defined(zLib)
5207 }
5208#endif
5209 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
5210 SDDS_dataset->n_rows_written = rows;
5211 SDDS_dataset->writing_page = 1;
5212 return (1);
5213}
int32_t SDDS_SwapEndsColumnData(SDDS_DATASET *SDDSin)
Swaps the endianness of the column data in an SDDS dataset.
int32_t SDDS_WriteNonNativeBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row)
Writes a non-native endian binary row to an SDDS dataset.
int32_t SDDS_WriteNonNativeBinaryArrays(SDDS_DATASET *SDDS_dataset)
Writes non-native endian binary arrays to an SDDS dataset.
int32_t SDDS_WriteNonNativeBinaryColumns(SDDS_DATASET *SDDS_dataset)
Writes non-native endian binary columns of an SDDS dataset to the associated file.
int32_t SDDS_WriteNonNativeBinaryParameters(SDDS_DATASET *SDDS_dataset)
Writes non-native endian binary parameters to an SDDS dataset.
int32_t SDDS_LZMAFlushBuffer(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)

◆ SDDS_WriteNonNativeBinaryParameters()

int32_t SDDS_WriteNonNativeBinaryParameters ( SDDS_DATASET * SDDS_dataset)

Writes non-native endian binary parameters to an SDDS dataset.

This function iterates through all parameter definitions in the specified SDDS dataset and writes their binary data to the underlying file. It handles various data types, including short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, and long double. For string parameters, it writes each string individually, ensuring proper memory management and byte order conversion. Parameters with fixed values are skipped during the write process. The function supports different compression formats, including uncompressed, LZMA-compressed, and GZIP-compressed files.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to write to.
Returns
int32_t Returns 1 on successful writing of all parameters, or 0 if an error occurred.
Return values
1All non-native endian parameters were successfully written and byte-swapped.
0An error occurred during the write operation, such as I/O failures, memory allocation issues, or corrupted parameter definitions.
Note
This function modifies the dataset's parameter data during the write process. Ensure that the dataset is properly initialized and opened for writing before invoking this function. After writing, the dataset's state is updated to reflect the written parameters.

Definition at line 5236 of file SDDS_binary.c.

5236 {
5237 int32_t i;
5238 SDDS_LAYOUT *layout;
5239 FILE *fp;
5240 struct lzmafile *lzmafp;
5241 SDDS_FILEBUFFER *fBuffer;
5242#if defined(zLib)
5243 gzFile gzfp;
5244#endif
5245
5246 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteNonNativeBinaryParameters"))
5247 return (0);
5248
5249 SDDS_SwapEndsParameterData(SDDS_dataset);
5250
5251 layout = &SDDS_dataset->layout;
5252 fBuffer = &SDDS_dataset->fBuffer;
5253#if defined(zLib)
5254 if (SDDS_dataset->layout.gzipFile) {
5255 if (!(gzfp = layout->gzfp)) {
5256 SDDS_SetError("Unable to write parameters--file pointer is NULL (SDDS_WriteNonNativeBinaryParameters)");
5257 return (0);
5258 }
5259 for (i = 0; i < layout->n_parameters; i++) {
5260 if (layout->parameter_definition[i].fixed_value)
5261 continue;
5262 if (layout->parameter_definition[i].type == SDDS_STRING) {
5263 if (!SDDS_GZipWriteNonNativeBinaryString(*((char **)SDDS_dataset->parameter[i]), gzfp, fBuffer)) {
5264 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5265 SDDS_SwapEndsParameterData(SDDS_dataset);
5266 return (0);
5267 }
5268 } else if (!SDDS_GZipBufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer)) {
5269 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5270 SDDS_SwapEndsParameterData(SDDS_dataset);
5271 return (0);
5272 }
5273 }
5274 } else {
5275#endif
5276 if (SDDS_dataset->layout.lzmaFile) {
5277 if (!(lzmafp = layout->lzmafp)) {
5278 SDDS_SetError("Unable to write parameters--file pointer is NULL (SDDS_WriteNonNativeBinaryParameters)");
5279 return (0);
5280 }
5281 for (i = 0; i < layout->n_parameters; i++) {
5282 if (layout->parameter_definition[i].fixed_value)
5283 continue;
5284 if (layout->parameter_definition[i].type == SDDS_STRING) {
5285 if (!SDDS_LZMAWriteNonNativeBinaryString(*((char **)SDDS_dataset->parameter[i]), lzmafp, fBuffer)) {
5286 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5287 SDDS_SwapEndsParameterData(SDDS_dataset);
5288 return (0);
5289 }
5290 } else if (!SDDS_LZMABufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], lzmafp, fBuffer)) {
5291 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5292 SDDS_SwapEndsParameterData(SDDS_dataset);
5293 return (0);
5294 }
5295 }
5296 } else {
5297 fp = layout->fp;
5298 for (i = 0; i < layout->n_parameters; i++) {
5299 if (layout->parameter_definition[i].fixed_value)
5300 continue;
5301 if (layout->parameter_definition[i].type == SDDS_STRING) {
5302 if (!SDDS_WriteNonNativeBinaryString(*((char **)SDDS_dataset->parameter[i]), fp, fBuffer)) {
5303 SDDS_SetError("Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5304 SDDS_SwapEndsParameterData(SDDS_dataset);
5305 return (0);
5306 }
5307 } else if (!SDDS_BufferedWrite(SDDS_dataset->parameter[i], SDDS_type_size[layout->parameter_definition[i].type - 1], fp, fBuffer)) {
5308 SDDS_SetError("Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5309 SDDS_SwapEndsParameterData(SDDS_dataset);
5310 return (0);
5311 }
5312 }
5313 }
5314#if defined(zLib)
5315 }
5316#endif
5317
5318 SDDS_SwapEndsParameterData(SDDS_dataset);
5319 return (1);
5320}

◆ SDDS_WriteNonNativeBinaryRow()

int32_t SDDS_WriteNonNativeBinaryRow ( SDDS_DATASET * SDDS_dataset,
int64_t row )

Writes a non-native endian binary row to an SDDS dataset.

This function writes a single row of data to the specified SDDS dataset, handling byte order reversal to convert between little-endian and big-endian formats. It supports various compression formats, including uncompressed, GZIP-compressed, and LZMA-compressed files. The function iterates through all column definitions, writing each column's data appropriately based on its type. For string columns, it ensures proper memory management and byte order conversion by utilizing specialized string writing functions. For non-string data types, it writes the binary data directly with the correct byte ordering.

Parameters
[in,out]SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset to write to.
[in]rowThe index of the row to write to the dataset.
Returns
int32_t Returns 1 on successful writing of the binary row, or 0 if an error occurred.
Return values
1The binary row was successfully written and byte-swapped.
0An error occurred during the write operation, such as I/O failures or corrupted data.
Note
This function modifies the dataset's internal data structures during the write process. Ensure that the dataset is properly initialized and opened for writing before invoking this function. After writing, the dataset's state is updated to reflect the newly written row.

Definition at line 5499 of file SDDS_binary.c.

5499 {
5500 int64_t i, type, size;
5501 SDDS_LAYOUT *layout;
5502 FILE *fp;
5503 struct lzmafile *lzmafp;
5504 SDDS_FILEBUFFER *fBuffer;
5505#if defined(zLib)
5506 gzFile gzfp;
5507#endif
5508
5509 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_WriteNonNativeBinaryRow"))
5510 return (0);
5511 layout = &SDDS_dataset->layout;
5512 fBuffer = &SDDS_dataset->fBuffer;
5513#if defined(zLib)
5514 if (SDDS_dataset->layout.gzipFile) {
5515 gzfp = layout->gzfp;
5516 for (i = 0; i < layout->n_columns; i++) {
5517 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
5518 if (!SDDS_GZipWriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
5519 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5520 return (0);
5521 }
5522 } else {
5523 size = SDDS_type_size[type - 1];
5524 if (!SDDS_GZipBufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
5525 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5526 return (0);
5527 }
5528 }
5529 }
5530 } else {
5531#endif
5532 if (SDDS_dataset->layout.lzmaFile) {
5533 lzmafp = layout->lzmafp;
5534 for (i = 0; i < layout->n_columns; i++) {
5535 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
5536 if (!SDDS_LZMAWriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), lzmafp, fBuffer)) {
5537 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5538 return (0);
5539 }
5540 } else {
5541 size = SDDS_type_size[type - 1];
5542 if (!SDDS_LZMABufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
5543 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5544 return (0);
5545 }
5546 }
5547 }
5548 } else {
5549 fp = layout->fp;
5550 for (i = 0; i < layout->n_columns; i++) {
5551 if ((type = layout->column_definition[i].type) == SDDS_STRING) {
5552 if (!SDDS_WriteNonNativeBinaryString(*((char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
5553 SDDS_SetError("Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5554 return (0);
5555 }
5556 } else {
5557 size = SDDS_type_size[type - 1];
5558 if (!SDDS_BufferedWrite((char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
5559 SDDS_SetError("Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5560 return (0);
5561 }
5562 }
5563 }
5564 }
5565#if defined(zLib)
5566 }
5567#endif
5568 return (1);
5569}

◆ SDDS_WriteNonNativeBinaryString()

int32_t SDDS_WriteNonNativeBinaryString ( char * string,
FILE * fp,
SDDS_FILEBUFFER * fBuffer )

Writes a non-native endian binary string to a file.

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

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

Definition at line 5591 of file SDDS_binary.c.

5591 {
5592 int32_t length;
5593 static char *dummy_string = "";
5594 if (!string)
5595 string = dummy_string;
5596 length = strlen(string);
5597 SDDS_SwapLong(&length);
5598 if (!SDDS_BufferedWrite(&length, sizeof(length), fp, fBuffer)) {
5599 SDDS_SetError("Unable to write string--error writing length");
5600 return (0);
5601 }
5602 SDDS_SwapLong(&length);
5603 if (length && !SDDS_BufferedWrite(string, sizeof(*string) * length, fp, fBuffer)) {
5604 SDDS_SetError("Unable to write string--error writing contents");
5605 return (0);
5606 }
5607 return (1);
5608}

◆ SDDS_WritePage()

epicsShareFuncSDDS int32_t SDDS_WritePage ( SDDS_DATASET * SDDS_dataset)
extern

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.

◆ SDDS_WriteTypedValue()

epicsShareFuncSDDS int32_t SDDS_WriteTypedValue ( void * data,
int64_t index,
int32_t type,
char * format,
FILE * fp )
extern

Writes a typed value to an ASCII file stream.

This function writes a value of a specified SDDS data type to an ASCII file stream. The data is provided as a void pointer, and the function handles various data types by casting the pointer appropriately based on the type parameter. For string data, special characters are escaped according to SDDS conventions.

Parameters
dataPointer to the data to be written. Should be castable to the type specified by type.
indexArray index of the data to be printed; use 0 if not an array.
typeThe SDDS data type of the data variable. Possible values include SDDS_SHORT, SDDS_LONG, SDDS_FLOAT, etc.
formatOptional printf format string to use; pass NULL to use the default format for the data type.
fpThe FILE pointer to the ASCII file stream where the data will be written.
Returns
Returns 1 on success; 0 on error (e.g., if data or fp is NULL, or an unknown data type is specified).

Definition at line 57 of file SDDS_ascii.c.

57 {
58 char c, *s;
59 short hasWhitespace;
60
61 if (!data) {
62 SDDS_SetError("Unable to write value--data pointer is NULL (SDDS_WriteTypedValue)");
63 return (0);
64 }
65 if (!fp) {
66 SDDS_SetError("Unable to print value--file pointer is NULL (SDDS_WriteTypedValue)");
67 return (0);
68 }
69 switch (type) {
70 case SDDS_SHORT:
71 fprintf(fp, format ? format : "%hd", *((short *)data + index));
72 break;
73 case SDDS_USHORT:
74 fprintf(fp, format ? format : "%hu", *((unsigned short *)data + index));
75 break;
76 case SDDS_LONG:
77 fprintf(fp, format ? format : "%" PRId32, *((int32_t *)data + index));
78 break;
79 case SDDS_ULONG:
80 fprintf(fp, format ? format : "%" PRIu32, *((uint32_t *)data + index));
81 break;
82 case SDDS_LONG64:
83 fprintf(fp, format ? format : "%" PRId64, *((int64_t *)data + index));
84 break;
85 case SDDS_ULONG64:
86 fprintf(fp, format ? format : "%" PRIu64, *((uint64_t *)data + index));
87 break;
88 case SDDS_FLOAT:
89 fprintf(fp, format ? format : "%15.8e", *((float *)data + index));
90 break;
91 case SDDS_DOUBLE:
92 fprintf(fp, format ? format : "%22.15e", *((double *)data + index));
93 break;
94 case SDDS_LONGDOUBLE:
95 if (LDBL_DIG == 18) {
96 fprintf(fp, format ? format : "%22.18Le", *((long double *)data + index));
97 } else {
98 fprintf(fp, format ? format : "%22.15Le", *((long double *)data + index));
99 }
100 break;
101 case SDDS_STRING:
102 /* ignores format string */
103 s = *((char **)data + index);
104 hasWhitespace = 0;
106 fputc('"', fp);
107 hasWhitespace = 1;
108 }
109 while (s && *s) {
110 c = *s++;
111 if (c == '!')
112 fputs("\\!", fp);
113 else if (c == '\\')
114 fputs("\\\\", fp);
115 else if (c == '"')
116 fputs("\\\"", fp);
117 else if (c == ' ')
118 fputc(' ', fp); /* don't escape plain spaces */
119 else if (isspace(c) || !isprint(c))
120 fprintf(fp, "\\%03o", c);
121 else
122 fputc(c, fp);
123 }
124 if (hasWhitespace)
125 fputc('"', fp);
126 break;
127 case SDDS_CHARACTER:
128 /* ignores format string */
129 c = *((char *)data + index);
130 if (c == '!')
131 fputs("\\!", fp);
132 else if (c == '\\')
133 fputs("\\\\", fp);
134 else if (c == '"')
135 fputs("\\\"", fp);
136 else if (!c || isspace(c) || !isprint(c))
137 fprintf(fp, "\\%03o", c);
138 else
139 fputc(c, fp);
140 break;
141 default:
142 SDDS_SetError("Unable to write value--unknown data type (SDDS_WriteTypedValue)");
143 return (0);
144 }
145 return (1);
146}

◆ SDDS_ZeroMemory()

epicsShareFuncSDDS int32_t SDDS_ZeroMemory ( void * mem,
int64_t n_bytes )
extern

Sets a block of memory to zero.

This function zero-initializes a specified number of bytes in a memory block. It is a wrapper around the standard memset function, providing a convenient way to clear memory.

Parameters
[in,out]memPointer to the memory block to be zeroed.
[in]n_bytesThe number of bytes to set to zero.
Returns
Returns 1 on successful memory zeroing. Returns 0 if the input memory pointer mem is NULL.
Note
The function does not perform any bounds checking. It is the caller's responsibility to ensure that the memory block is large enough to accommodate n_bytes.
See also
memset

Definition at line 1985 of file SDDS_utils.c.

1985 {
1986 if (mem) {
1987 memset(mem, 0, n_bytes);
1988 return 1;
1989 }
1990 return 0;
1991
1992 /*
1993 char *c;
1994
1995 if (!(c = (char*)mem))
1996 return(0);
1997 while (n_bytes--)
1998 *c++ = 0;
1999 return(1);
2000 */
2001}

Variable Documentation

◆ SDDS_ArrayFieldInformation

SDDS_FIELD_INFORMATION SDDS_ArrayFieldInformation[SDDS_ARRAY_FIELDS]
extern

Field information for array definitions.

Maps each array field name to its offset within the ARRAY_DEFINITION structure, along with the corresponding data type and any associated enumeration pairs.

Definition at line 175 of file SDDS_data.c.

175 {
176 {"name", offsetof(ARRAY_DEFINITION, name), SDDS_STRING, NULL},
177 {"symbol", offsetof(ARRAY_DEFINITION, symbol), SDDS_STRING, NULL},
178 {"units", offsetof(ARRAY_DEFINITION, units), SDDS_STRING, NULL},
179 {"description", offsetof(ARRAY_DEFINITION, description), SDDS_STRING, NULL},
180 {"format_string", offsetof(ARRAY_DEFINITION, format_string), SDDS_STRING, NULL},
181 {"group_name", offsetof(ARRAY_DEFINITION, group_name), SDDS_STRING, NULL},
182 {"type", offsetof(ARRAY_DEFINITION, type), SDDS_LONG, typeEnumPair},
183 {"field_length", offsetof(ARRAY_DEFINITION, field_length), SDDS_LONG, NULL},
184 {"dimensions", offsetof(ARRAY_DEFINITION, dimensions), SDDS_LONG, NULL},
185};
SDDS_ENUM_PAIR typeEnumPair[SDDS_NUM_TYPES+1]
Enumeration pairs for data types.
Definition SDDS_data.c:139

◆ SDDS_AssociateFieldInformation

SDDS_FIELD_INFORMATION SDDS_AssociateFieldInformation[SDDS_ASSOCIATE_FIELDS]
extern

Field information for associate definitions.

Maps each associate field name to its offset within the ASSOCIATE_DEFINITION structure, along with the corresponding data type and any associated enumeration pairs.

Definition at line 225 of file SDDS_data.c.

225 {
226 {"name", offsetof(ASSOCIATE_DEFINITION, name), SDDS_STRING},
227 {"filename", offsetof(ASSOCIATE_DEFINITION, filename), SDDS_STRING},
228 {"path", offsetof(ASSOCIATE_DEFINITION, path), SDDS_STRING},
229 {"description", offsetof(ASSOCIATE_DEFINITION, description), SDDS_STRING},
230 {"contents", offsetof(ASSOCIATE_DEFINITION, contents), SDDS_STRING},
231 {"sdds", offsetof(ASSOCIATE_DEFINITION, sdds), SDDS_LONG},
232};

◆ SDDS_ColumnFieldInformation

SDDS_FIELD_INFORMATION SDDS_ColumnFieldInformation[SDDS_COLUMN_FIELDS]
extern

Field information for column definitions.

Maps each column field name to its offset within the COLUMN_DEFINITION structure, along with the corresponding data type and any associated enumeration pairs.

Definition at line 193 of file SDDS_data.c.

193 {
194 {"name", offsetof(COLUMN_DEFINITION, name), SDDS_STRING},
195 {"symbol", offsetof(COLUMN_DEFINITION, symbol), SDDS_STRING},
196 {"units", offsetof(COLUMN_DEFINITION, units), SDDS_STRING},
197 {"description", offsetof(COLUMN_DEFINITION, description), SDDS_STRING},
198 {"format_string", offsetof(COLUMN_DEFINITION, format_string), SDDS_STRING},
199 {"type", offsetof(COLUMN_DEFINITION, type), SDDS_LONG, typeEnumPair},
200 {"field_length", offsetof(COLUMN_DEFINITION, field_length), SDDS_LONG},
201};

◆ SDDS_data_mode

char* SDDS_data_mode[SDDS_NUM_DATA_MODES]
extern

Array of supported data modes.

Contains the string representations of the different data modes supported by SDDS, such as "binary" and "ascii".

Definition at line 33 of file SDDS_data.c.

33 {
34 "binary",
35 "ascii"
36};

◆ SDDS_DataFieldInformation

SDDS_FIELD_INFORMATION SDDS_DataFieldInformation[SDDS_DATA_FIELDS]
extern

Field information for data mode settings.

Maps each data mode field name to its offset within the DATA_MODE structure, along with the corresponding data type and any associated enumeration pairs.

Definition at line 159 of file SDDS_data.c.

159 {
160 {"mode", offsetof(DATA_MODE, mode), SDDS_LONG, dataModeEnumPair},
161 {"lines_per_row", offsetof(DATA_MODE, lines_per_row), SDDS_LONG, NULL},
162 {"no_row_counts", offsetof(DATA_MODE, no_row_counts), SDDS_LONG, NULL},
163 {"fixed_row_count", offsetof(DATA_MODE, fixed_row_count), SDDS_LONG, NULL},
164 {"additional_header_lines", offsetof(DATA_MODE, additional_header_lines), SDDS_LONG, NULL},
165 {"column_major_order", offsetof(DATA_MODE, column_major), SDDS_SHORT, NULL},
166 {"endian", offsetof(DATA_MODE, endian), SDDS_LONG, dataEndianEnumPair},
167};
SDDS_ENUM_PAIR dataModeEnumPair[3]
Enumeration pairs for data modes.
Definition SDDS_data.c:117
SDDS_ENUM_PAIR dataEndianEnumPair[3]
Enumeration pairs for data endianness.
Definition SDDS_data.c:128

◆ SDDS_DescriptionFieldInformation

SDDS_FIELD_INFORMATION SDDS_DescriptionFieldInformation[SDDS_DESCRIPTION_FIELDS]
extern

Field information for SDDS layout descriptions.

Maps each description field name to its offset within the SDDS_LAYOUT structure, along with the corresponding data type and any associated enumeration pairs.

Definition at line 107 of file SDDS_data.c.

107 {
108 {"text", offsetof(SDDS_LAYOUT, description), SDDS_STRING, NULL},
109 {"contents", offsetof(SDDS_LAYOUT, contents), SDDS_STRING, NULL},
110};

◆ SDDS_IncludeFieldInformation

SDDS_FIELD_INFORMATION SDDS_IncludeFieldInformation[SDDS_INCLUDE_FIELDS]
extern

Field information for include directives.

Maps each include field name to its offset within the INCLUDE_DEFINITION structure, along with the corresponding data type.

Definition at line 240 of file SDDS_data.c.

240 {
241 {"filename", 0, SDDS_STRING},
242};

◆ SDDS_ParameterFieldInformation

SDDS_FIELD_INFORMATION SDDS_ParameterFieldInformation[SDDS_PARAMETER_FIELDS]
extern

Field information for parameter definitions.

Maps each parameter field name to its offset within the PARAMETER_DEFINITION structure, along with the corresponding data type and any associated enumeration pairs.

Definition at line 209 of file SDDS_data.c.

209 {
210 {"name", offsetof(PARAMETER_DEFINITION, name), SDDS_STRING},
211 {"symbol", offsetof(PARAMETER_DEFINITION, symbol), SDDS_STRING},
212 {"units", offsetof(PARAMETER_DEFINITION, units), SDDS_STRING},
213 {"description", offsetof(PARAMETER_DEFINITION, description), SDDS_STRING},
214 {"format_string", offsetof(PARAMETER_DEFINITION, format_string), SDDS_STRING},
215 {"type", offsetof(PARAMETER_DEFINITION, type), SDDS_LONG, typeEnumPair},
216 {"fixed_value", offsetof(PARAMETER_DEFINITION, fixed_value), SDDS_STRING},
217};

◆ SDDS_type_name

epicsShareExtern char* SDDS_type_name[SDDS_NUM_TYPES]

Definition at line 153 of file SDDS.h.

◆ SDDS_type_size

epicsShareExtern int32_t SDDS_type_size[SDDS_NUM_TYPES]

Definition at line 154 of file SDDS.h.