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

This file provides miscellaneous functions for interacting with SDDS objects. More...

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

Go to the source code of this file.

Macros

#define COMMENT_COMMANDS   3
 

Functions

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.
 
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.
 
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.
 
void SDDS_RegisterProgramName (const char *name)
 Registers the executable program name for use in error messages.
 
int32_t SDDS_NumberOfErrors ()
 Retrieves the number of errors recorded by SDDS library routines.
 
void SDDS_ClearErrors ()
 Clears all recorded error messages from the SDDS error stack.
 
void SDDS_Bomb (char *message)
 Terminates the program after printing an error message and recorded errors.
 
void SDDS_Warning (char *message)
 Prints a warning message to stderr.
 
void SDDS_SetError (char *error_text)
 Records an error message in the SDDS error stack.
 
void SDDS_SetError0 (char *error_text)
 Internal function to record an error message in the SDDS error stack.
 
void SDDS_PrintErrors (FILE *fp, int32_t mode)
 Prints recorded error messages to a specified file stream.
 
char ** SDDS_GetErrorMessages (int32_t *number, int32_t mode)
 Retrieves recorded error messages from the SDDS error stack.
 
uint32_t SDDS_SetAutoCheckMode (uint32_t newMode)
 Sets the automatic check mode for SDDS dataset validation.
 
int32_t SDDS_CheckDataset (SDDS_DATASET *SDDS_dataset, const char *caller)
 Validates the SDDS dataset pointer.
 
int32_t SDDS_CheckTabularData (SDDS_DATASET *SDDS_dataset, const char *caller)
 Validates the consistency of tabular data within an SDDS dataset.
 
void * SDDS_Calloc (size_t nelem, size_t elem_size)
 Allocates zero-initialized memory for an array of elements.
 
void * SDDS_Malloc (size_t size)
 Allocates memory of a specified size.
 
void SDDS_Free (void *mem)
 Free memory previously allocated by SDDS_Malloc.
 
void * SDDS_Realloc (void *old_ptr, size_t new_size)
 Reallocates memory to a new size.
 
void * SDDS_Recalloc (void *old_ptr, size_t old_size, size_t new_size)
 Reallocates memory to a new size and zero-initializes the additional space.
 
int32_t SDDS_VerifyPrintfFormat (const char *string, int32_t type)
 Verifies that a printf format string is compatible with a specified data type.
 
int32_t SDDS_CopyString (char **target, const char *source)
 Copies a source string to a target string with memory allocation.
 
ASSOCIATE_DEFINITIONSDDS_GetAssociateDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified associate from the SDDS dataset.
 
ASSOCIATE_DEFINITIONSDDS_CopyAssociateDefinition (ASSOCIATE_DEFINITION **target, ASSOCIATE_DEFINITION *source)
 Creates a copy of an associate definition.
 
int32_t SDDS_FreeAssociateDefinition (ASSOCIATE_DEFINITION *source)
 Frees memory allocated for an associate definition.
 
COLUMN_DEFINITIONSDDS_GetColumnDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified column from the SDDS dataset.
 
COLUMN_DEFINITIONSDDS_CopyColumnDefinition (COLUMN_DEFINITION **target, COLUMN_DEFINITION *source)
 Creates a copy of a column definition.
 
int32_t SDDS_FreeColumnDefinition (COLUMN_DEFINITION *source)
 Frees memory allocated for a column definition.
 
PARAMETER_DEFINITIONSDDS_GetParameterDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified parameter from the SDDS dataset.
 
PARAMETER_DEFINITIONSDDS_CopyParameterDefinition (PARAMETER_DEFINITION **target, PARAMETER_DEFINITION *source)
 Creates a copy of a parameter definition.
 
int32_t SDDS_FreeParameterDefinition (PARAMETER_DEFINITION *source)
 Frees memory allocated for a parameter definition.
 
ARRAY_DEFINITIONSDDS_GetArrayDefinition (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the definition of a specified array from the SDDS dataset.
 
ARRAY_DEFINITIONSDDS_CopyArrayDefinition (ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
 Creates a copy of an array definition.
 
int32_t SDDS_FreeArrayDefinition (ARRAY_DEFINITION *source)
 Frees memory allocated for an array definition.
 
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.
 
int32_t SDDS_GetColumnIndex (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the index of a named column 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_GetArrayIndex (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the index of a named array in the SDDS dataset.
 
int32_t SDDS_GetAssociateIndex (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the index of a named associate in the SDDS dataset.
 
int32_t SDDS_HasWhitespace (char *string)
 Checks if a string contains any whitespace characters.
 
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.
 
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.
 
char * fgetsLZMASkipComments (SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, struct lzmafile *lzmafp, char skip_char)
 Reads a line from a LZMA-compressed file while skipping comment lines.
 
char * fgetsLZMASkipCommentsResize (SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, struct lzmafile *lzmafp, char skip_char)
 Reads a line from a LZMA-compressed file with dynamic buffer resizing while skipping comment lines.
 
void SDDS_CutOutComments (SDDS_DATASET *SDDS_dataset, char *s, char cc)
 Removes comments from a string based on a specified comment character.
 
int32_t SDDS_GetToken (char *s, char *buffer, int32_t buflen)
 Extracts the next token from a string, handling quoted substrings and escape characters.
 
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.
 
int32_t SDDS_PadToLength (char *string, int32_t length)
 Pads a string with spaces to reach a specified length.
 
void SDDS_EscapeQuotes (char *s, char quote_char)
 Escapes quote characters within a string by inserting backslashes.
 
void SDDS_UnescapeQuotes (char *s, char quote_char)
 Removes escape characters from quote characters within a string.
 
void SDDS_EscapeCommentCharacters (char *string, char cc)
 Escapes comment characters within a string by inserting backslashes.
 
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.
 
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.
 
int32_t SDDS_GetNamedColumnType (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the data type of a column in the SDDS dataset by its name.
 
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_GetNamedArrayType (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the data type of an array in the SDDS dataset by its name.
 
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.
 
int32_t SDDS_GetNamedParameterType (SDDS_DATASET *SDDS_dataset, char *name)
 Retrieves the data type of a parameter in the SDDS dataset by its name.
 
int32_t SDDS_GetTypeSize (int32_t type)
 Retrieves the size in bytes of a specified SDDS data type.
 
char * SDDS_GetTypeName (int32_t type)
 Retrieves the name of a specified SDDS data type as a string.
 
int32_t SDDS_IdentifyType (char *typeName)
 Identifies the SDDS data type based on its string name.
 
void SDDS_RemovePadding (char *s)
 Removes leading and trailing whitespace from a string.
 
int32_t SDDS_StringIsBlank (char *s)
 Checks if a string is blank (contains only whitespace characters).
 
int32_t SDDS_ColumnIsOfInterest (SDDS_DATASET *SDDS_dataset, char *name)
 Determines if a specified column is marked as of interest in the dataset.
 
char ** SDDS_GetColumnNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all columns in the SDDS dataset.
 
char ** SDDS_GetParameterNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all parameters in the SDDS dataset.
 
char ** SDDS_GetArrayNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all arrays in the SDDS dataset.
 
char ** SDDS_GetAssociateNames (SDDS_DATASET *SDDS_dataset, int32_t *number)
 Retrieves the names of all associates in the SDDS dataset.
 
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.
 
void * SDDS_AllocateMatrix (int32_t size, int64_t dim1, int64_t dim2)
 Allocates a two-dimensional matrix with zero-initialized elements.
 
void SDDS_FreeArray (SDDS_ARRAY *array)
 Frees memory allocated for an SDDS array structure.
 
void SDDS_FreeMatrix (void **ptr, int64_t dim1)
 Frees memory allocated for a two-dimensional matrix.
 
int32_t SDDS_CopyStringArray (char **target, char **source, int64_t n_strings)
 Copies an array of strings from source to target.
 
int32_t SDDS_FreeStringArray (char **string, int64_t strings)
 Frees an array of strings by deallocating each individual string.
 
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.
 
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.
 
void SDDS_FreePointerArray (void **data, int32_t dimensions, int32_t *dimension)
 Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.
 
int32_t SDDS_ApplyFactorToParameter (SDDS_DATASET *SDDS_dataset, char *name, double factor)
 Applies a scaling factor to a specific parameter in the SDDS dataset.
 
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.
 
void SDDS_EscapeNewlines (char *s)
 Escapes newline characters in a string by replacing them with "\\n".
 
int32_t SDDS_ForceInactive (SDDS_DATASET *SDDS_dataset)
 Marks an SDDS dataset as inactive.
 
int32_t SDDS_IsActive (SDDS_DATASET *SDDS_dataset)
 Checks whether an SDDS dataset is currently active.
 
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.
 
int32_t SDDS_BreakIntoLockedFile (char *filename)
 Attempts to override a locked file by creating a temporary copy.
 
int32_t SDDS_MatchColumns (SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
 Matches and retrieves column names from an SDDS dataset based on specified criteria.
 
int32_t SDDS_MatchParameters (SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
 Matches and retrieves parameter names from an SDDS dataset based on specified criteria.
 
int32_t SDDS_MatchArrays (SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
 Matches and retrieves array names from an SDDS dataset based on specified criteria.
 
char * SDDS_FindColumn (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Finds the first column in the SDDS dataset that matches the specified criteria.
 
char * SDDS_FindParameter (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Finds the first parameter in the SDDS dataset that matches the specified criteria.
 
char * SDDS_FindArray (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Finds the first array in the SDDS dataset that matches the specified criteria.
 
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.
 
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.
 
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.
 
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.
 
int32_t SDDS_DeleteParameterFixedValues (SDDS_DATASET *SDDS_dataset)
 Deletes fixed values from all parameters in the SDDS dataset.
 
int32_t SDDS_SetDataMode (SDDS_DATASET *SDDS_dataset, int32_t newmode)
 Sets the data mode (ASCII or Binary) for the SDDS dataset.
 
int32_t SDDS_CheckDatasetStructureSize (int32_t size)
 Verifies that the size of the SDDS_DATASET structure matches the expected size.
 
int32_t SDDS_ColumnCount (SDDS_DATASET *page)
 Retrieves the number of columns in the SDDS dataset.
 
int32_t SDDS_ParameterCount (SDDS_DATASET *page)
 Retrieves the number of parameters in the SDDS dataset.
 
int32_t SDDS_ArrayCount (SDDS_DATASET *page)
 Retrieves the number of arrays in the SDDS dataset.
 
void SDDS_InterpretEscapes (char *s)
 Interprets and converts escape sequences in a string.
 
uint32_t SDDS_GetSpecialCommentsModes (SDDS_DATASET *SDDS_dataset)
 Retrieves the current special comments modes set in the SDDS dataset.
 
void SDDS_ResetSpecialCommentsModes (SDDS_DATASET *SDDS_dataset)
 Resets the special comments modes in the SDDS dataset.
 
void SDDS_ParseSpecialComments (SDDS_DATASET *SDDS_dataset, char *s)
 Parses and processes special comment commands within the SDDS dataset.
 
int32_t SDDS_IsBigEndianMachine ()
 Determines whether the current machine uses big-endian byte ordering.
 
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.
 
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.
 
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.
 
char ** getMatchingSDDSNames (SDDS_DATASET *dataset, char **matchName, int32_t matches, int32_t *names, short type)
 Retrieves an array of matching SDDS entity names based on specified criteria.
 
SDDS_DATASETSDDS_CreateEmptyDataset (void)
 Creates an empty SDDS dataset.
 

Variables

static int32_t n_errors = 0
 
static int32_t n_errors_max = 0
 
static char ** error_description = NULL
 
static char * registeredProgramName = NULL
 
static uint32_t AutoCheckMode = 0x0000UL
 
static char * commentCommandName [COMMENT_COMMANDS]
 
static uint32_t commentCommandFlag [COMMENT_COMMANDS]
 

Detailed Description

This file provides miscellaneous functions for interacting with SDDS objects.

This file provides miscellaneous functions for interacting with SDDS objects.

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

Definition in file SDDS_utils.c.

Macro Definition Documentation

◆ COMMENT_COMMANDS

#define COMMENT_COMMANDS   3

Definition at line 5168 of file SDDS_utils.c.

Function Documentation

◆ fgetsLZMASkipComments()

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

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

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

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

Definition at line 1528 of file SDDS_utils.c.

1528 {
1529 while (lzma_gets(s, slen, lzmafp)) {
1530 if (s[0] != skip_char) {
1531 SDDS_CutOutComments(SDDS_dataset, s, skip_char);
1532 return (s);
1533 } else if (s[1] == '#') {
1534 SDDS_ParseSpecialComments(SDDS_dataset, s + 2);
1535 }
1536 }
1537 return (NULL);
1538}
void SDDS_CutOutComments(SDDS_DATASET *SDDS_dataset, char *s, char cc)
Removes comments from a string based on a specified comment character.
void SDDS_ParseSpecialComments(SDDS_DATASET *SDDS_dataset, char *s)
Parses and processes special comment commands within the SDDS dataset.

◆ fgetsLZMASkipCommentsResize()

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

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

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

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

Definition at line 1560 of file SDDS_utils.c.

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

◆ fgetsSkipComments()

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.

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}

◆ fgetsSkipCommentsResize()

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.

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}

◆ getMatchingSDDSNames()

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

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

◆ SDDS_AllocateMatrix()

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

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

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.

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}
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
#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()

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

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}
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.

◆ SDDS_ArrayCount()

int32_t SDDS_ArrayCount ( SDDS_DATASET * page)

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

void SDDS_Bomb ( char * message)

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

int32_t SDDS_BreakIntoLockedFile ( char * filename)

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

void * SDDS_Calloc ( size_t nelem,
size_t elem_size )

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

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.

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}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85

◆ SDDS_CheckArray()

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.

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_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
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()

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.

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

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

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

int32_t SDDS_CheckDatasetStructureSize ( int32_t size)

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

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.

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

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

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

void SDDS_ClearErrors ( void )

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

int32_t SDDS_ColumnCount ( SDDS_DATASET * page)

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

int32_t SDDS_ColumnIsOfInterest ( SDDS_DATASET * SDDS_dataset,
char * name )

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}
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552

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

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

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

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

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

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

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

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

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

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

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

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

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

SDDS_DATASET * SDDS_CreateEmptyDataset ( void )

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

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

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}

◆ SDDS_DeleteParameterFixedValues()

int32_t SDDS_DeleteParameterFixedValues ( SDDS_DATASET * SDDS_dataset)

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}
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
Definition SDDS_copy.c:615

◆ SDDS_EscapeCommentCharacters()

void SDDS_EscapeCommentCharacters ( char * string,
char cc )

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

void SDDS_EscapeNewlines ( char * s)

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

void SDDS_EscapeQuotes ( char * s,
char quote_char )

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}

◆ SDDS_FileIsLocked()

int32_t SDDS_FileIsLocked ( const char * filename)

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

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

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

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

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

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

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

int32_t SDDS_ForceInactive ( SDDS_DATASET * SDDS_dataset)

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

void SDDS_Free ( void * mem)

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

void SDDS_FreeArray ( SDDS_ARRAY * array)

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}
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.
void SDDS_FreePointerArray(void **data, int32_t dimensions, int32_t *dimension)
Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.

◆ SDDS_FreeArrayDefinition()

int32_t SDDS_FreeArrayDefinition ( ARRAY_DEFINITION * source)

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}
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.

◆ SDDS_FreeAssociateDefinition()

int32_t SDDS_FreeAssociateDefinition ( ASSOCIATE_DEFINITION * source)

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

int32_t SDDS_FreeColumnDefinition ( COLUMN_DEFINITION * source)

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

void SDDS_FreeMatrix ( void ** ptr,
int64_t dim1 )

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

int32_t SDDS_FreeParameterDefinition ( PARAMETER_DEFINITION * source)

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

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

Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.

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

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

Definition at line 3012 of file SDDS_utils.c.

3016{
3017 if (!data || !dimension || !dimensions)
3018 return;
3019 if (dimensions > 1) {
3020 SDDS_FreePointerArray((void **)(data[0]), dimensions - 1, dimension + 1);
3021 free(data);
3022 }
3023}

◆ SDDS_FreeStringArray()

int32_t SDDS_FreeStringArray ( char ** string,
int64_t strings )

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

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

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}
ARRAY_DEFINITION * SDDS_CopyArrayDefinition(ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
Creates a copy of an array definition.

◆ SDDS_GetArrayIndex()

int32_t SDDS_GetArrayIndex ( SDDS_DATASET * SDDS_dataset,
char * name )

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}
int SDDS_CompareIndexedNames(const void *s1, const void *s2)
Compares two SORTED_INDEX structures by their name fields.

◆ SDDS_GetArrayNames()

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

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

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.

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

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

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

int32_t SDDS_GetAssociateIndex ( SDDS_DATASET * SDDS_dataset,
char * name )

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

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

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

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

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

int32_t SDDS_GetColumnIndex ( SDDS_DATASET * SDDS_dataset,
char * name )

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

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

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

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.

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

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

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

int32_t SDDS_GetNamedArrayType ( SDDS_DATASET * SDDS_dataset,
char * name )

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

int32_t SDDS_GetNamedColumnType ( SDDS_DATASET * SDDS_dataset,
char * name )

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

int32_t SDDS_GetNamedParameterType ( SDDS_DATASET * SDDS_dataset,
char * name )

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

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

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

int32_t SDDS_GetParameterIndex ( SDDS_DATASET * SDDS_dataset,
char * name )

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

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

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

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.

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

uint32_t SDDS_GetSpecialCommentsModes ( SDDS_DATASET * SDDS_dataset)

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

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

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

Definition at line 5201 of file SDDS_utils.c.

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

◆ SDDS_GetToken()

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

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

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.

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

char * SDDS_GetTypeName ( int32_t type)

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

int32_t SDDS_GetTypeSize ( int32_t type)

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

int32_t SDDS_HasWhitespace ( char * string)

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

int32_t SDDS_IdentifyType ( char * typeName)

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}
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
Definition SDDStypes.h:97

◆ SDDS_InterpretEscapes()

void SDDS_InterpretEscapes ( char * s)

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

int32_t SDDS_IsActive ( SDDS_DATASET * SDDS_dataset)

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

int32_t SDDS_IsBigEndianMachine ( )

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

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

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

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.

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

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.

This internal function is used to build a multi-dimensional pointer array by recursively allocating pointer layers based on the specified dimensions. It maps the contiguous data block to the pointer structure, facilitating easy access to multi-dimensional data.

Parameters
[in]dataPointer to the data block or intermediate pointer array.
[in]sizeThe size in bytes of each element in the current dimension.
[in]dimensionsThe number of remaining dimensions to process.
[in]dimensionAn array specifying the size of each remaining dimension.
Returns
  • Returns a pointer to the next layer of the pointer array on success.
  • Returns NULL if the input data is NULL, the dimension array is invalid, the size is non-positive, or memory allocation fails.
Note
  • This function maintains a static depth variable to track recursion depth for error reporting.
  • It is intended for internal use within the SDDS library and should not be called directly by user code.
See also
SDDS_MakePointerArray
SDDS_SetError
SDDS_Malloc
SDDS_type_size

Definition at line 2900 of file SDDS_utils.c.

2900 {
2901 void **pointer;
2902 int32_t i, elements;
2903 static int32_t depth = 0;
2904 static char s[200];
2905
2906 depth += 1;
2907 if (!data) {
2908 sprintf(s, "Unable to make pointer array--NULL data array (SDDS_MakePointerArrayRecursively, recursion %" PRId32 ")", depth);
2909 SDDS_SetError(s);
2910 return (NULL);
2911 }
2912 if (!dimension || !dimensions) {
2913 sprintf(s, "Unable to make pointer array--NULL or zero-length dimension array (SDDS_MakePointerArrayRecursively, recursion %" PRId32 ")", depth);
2914 SDDS_SetError(s);
2915 return (NULL);
2916 }
2917 if (size <= 0) {
2918 sprintf(s, "Unable to make pointer array--invalid data size (SDDS_MakePointerArrayRecursively, recursion %" PRId32 ")", depth);
2919 SDDS_SetError(s);
2920 return (NULL);
2921 }
2922 if (dimensions == 1) {
2923 depth -= 1;
2924 return (data);
2925 }
2926 elements = 1;
2927 for (i = 0; i < dimensions - 1; i++)
2928 elements *= dimension[i];
2929 if (!(pointer = (void **)SDDS_Malloc(sizeof(void *) * elements))) {
2930 sprintf(s, "Unable to make pointer array--allocation failure (SDDS_MakePointerArrayRecursively, recursion %" PRId32 ")", depth);
2931 SDDS_SetError(s);
2932 return (NULL);
2933 }
2934 for (i = 0; i < elements; i++)
2935 pointer[i] = (char *)data + i * size * dimension[dimensions - 1];
2936 return (SDDS_MakePointerArrayRecursively(pointer, sizeof(*pointer), dimensions - 1, dimension));
2937}

◆ SDDS_Malloc()

void * SDDS_Malloc ( size_t size)

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

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

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

int32_t SDDS_MatchColumns ( SDDS_DATASET * SDDS_dataset,
char *** nameReturn,
int32_t matchMode,
int32_t typeMode,
... )

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

int32_t SDDS_MatchParameters ( SDDS_DATASET * SDDS_dataset,
char *** nameReturn,
int32_t matchMode,
int32_t typeMode,
... )

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

int32_t SDDS_NumberOfErrors ( void )

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

int32_t SDDS_PadToLength ( char * string,
int32_t length )

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

int32_t SDDS_ParameterCount ( SDDS_DATASET * page)

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

void SDDS_ParseSpecialComments ( SDDS_DATASET * SDDS_dataset,
char * s )

Parses and processes special comment commands within the SDDS dataset.

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

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

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

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

Definition at line 5251 of file SDDS_utils.c.

5251 {
5252 char buffer[SDDS_MAXLINE];
5253 int32_t i;
5254 if (SDDS_dataset == NULL)
5255 return;
5256 while (SDDS_GetToken(s, buffer, SDDS_MAXLINE) > 0) {
5257 for (i = 0; i < COMMENT_COMMANDS; i++) {
5258 if (strcmp(buffer, commentCommandName[i]) == 0) {
5259 SDDS_dataset->layout.commentFlags |= commentCommandFlag[i];
5260 break;
5261 }
5262 }
5263 }
5264}

◆ SDDS_PrintCheckText()

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.

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

void SDDS_PrintErrors ( FILE * fp,
int32_t mode )

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

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.

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

void * SDDS_Realloc ( void * old_ptr,
size_t new_size )

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

void * SDDS_Recalloc ( void * old_ptr,
size_t old_size,
size_t new_size )

Reallocates memory to a new size and zero-initializes the additional space.

This function reallocates a memory block to a new size, similar to the standard realloc function. Additionally, it ensures that any newly allocated memory beyond the original size is set to zero. This is particularly useful when extending memory blocks to avoid uninitialized memory usage.

Parameters
[in]old_ptrPointer to the original memory block. If NULL, the function behaves like SDDS_Calloc.
[in]old_sizeSize in bytes of the original memory block.
[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.
Note
After reallocation, the memory from old_size to new_size bytes is set to zero. If old_ptr is NULL, the function allocates memory initialized to zero.
See also
SDDS_Malloc
SDDS_Calloc
SDDS_Free

Definition at line 707 of file SDDS_utils.c.

707 {
708 /* this is required because some realloc's don't behave properly when asked to return a
709 * pointer to 0 memory. They return NULL.
710 * Also, need to clear the memory (in this version).
711 */
712 void *new_ptr;
713 if (new_size <= 0)
714 new_size = 4;
715 /* this is required because some realloc's don't behave properly when given a NULL pointer */
716 if (!old_ptr)
717 new_ptr = calloc(new_size, 1);
718 else {
719 new_ptr = realloc(old_ptr, new_size);
720 memset((char *)new_ptr + old_size, 0, new_size - old_size);
721 }
722 return new_ptr;
723}

◆ SDDS_RegisterProgramName()

void SDDS_RegisterProgramName ( const char * name)

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

void SDDS_RemovePadding ( char * s)

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

void SDDS_ResetSpecialCommentsModes ( SDDS_DATASET * SDDS_dataset)

Resets the special comments modes in the SDDS dataset.

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

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

Definition at line 5221 of file SDDS_utils.c.

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

◆ SDDS_SetAutoCheckMode()

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

int32_t SDDS_SetDataMode ( SDDS_DATASET * SDDS_dataset,
int32_t newmode )

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}
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.

◆ SDDS_SetError()

void SDDS_SetError ( char * error_text)

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}
void SDDS_SetError0(char *error_text)
Internal function to record an error message in the SDDS error stack.
Definition SDDS_utils.c:395

◆ SDDS_SetError0()

void SDDS_SetError0 ( char * error_text)

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

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.

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

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.

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

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.

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

int32_t SDDS_StringIsBlank ( char * s)

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

void SDDS_UnescapeQuotes ( char * s,
char quote_char )

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

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.

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

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.

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

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.

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

int32_t SDDS_VerifyPrintfFormat ( const char * string,
int32_t type )

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

void SDDS_Warning ( char * message)

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

int32_t SDDS_ZeroMemory ( void * mem,
int64_t n_bytes )

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

◆ AutoCheckMode

uint32_t AutoCheckMode = 0x0000UL
static

Definition at line 517 of file SDDS_utils.c.

◆ commentCommandFlag

uint32_t commentCommandFlag[COMMENT_COMMANDS]
static
Initial value:
= {
SDDS_BIGENDIAN_SEEN,
SDDS_LITTLEENDIAN_SEEN,
SDDS_FIXED_ROWCOUNT_SEEN,
}

Definition at line 5175 of file SDDS_utils.c.

5175 {
5176 SDDS_BIGENDIAN_SEEN,
5177 SDDS_LITTLEENDIAN_SEEN,
5178 SDDS_FIXED_ROWCOUNT_SEEN,
5179};

◆ commentCommandName

char* commentCommandName[COMMENT_COMMANDS]
static
Initial value:
= {
"big-endian",
"little-endian",
"fixed-rowcount",
}

Definition at line 5169 of file SDDS_utils.c.

5169 {
5170 "big-endian",
5171 "little-endian",
5172 "fixed-rowcount",
5173};

◆ error_description

char** error_description = NULL
static

Definition at line 273 of file SDDS_utils.c.

◆ n_errors

int32_t n_errors = 0
static

Definition at line 271 of file SDDS_utils.c.

◆ n_errors_max

int32_t n_errors_max = 0
static

Definition at line 272 of file SDDS_utils.c.

◆ registeredProgramName

char* registeredProgramName = NULL
static

Definition at line 274 of file SDDS_utils.c.