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

This file contains routines for getting pointers to SDDS objects like columns and parameters. More...

#include "SDDS.h"
#include "SDDS_internal.h"
#include "mdb.h"

Go to the source code of this file.

Functions

int32_t SDDS_SetRowFlags (SDDS_DATASET *SDDS_dataset, int32_t row_flag_value)
 Sets the acceptance flags for all rows in the current data table of a data set.
 
int32_t SDDS_GetRowFlag (SDDS_DATASET *SDDS_dataset, int64_t row)
 Retrieves the acceptance flag of a specific row in the current data table.
 
int32_t SDDS_GetRowFlags (SDDS_DATASET *SDDS_dataset, int32_t *flag, int64_t rows)
 Retrieves the acceptance flags for all rows in the current data table.
 
int32_t SDDS_AssertRowFlags (SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
 Sets acceptance flags for rows based on specified criteria.
 
int32_t SDDS_SetColumnFlags (SDDS_DATASET *SDDS_dataset, int32_t column_flag_value)
 Sets the acceptance flags for all columns in the current data table of a data set.
 
int32_t SDDS_AssertColumnFlags (SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
 Sets acceptance flags for columns based on specified criteria.
 
int32_t SDDS_CountColumnsOfInterest (SDDS_DATASET *SDDS_dataset)
 Counts the number of columns marked as "of interest" in the current data table.
 
int64_t SDDS_CountRowsOfInterest (SDDS_DATASET *SDDS_dataset)
 Counts the number of rows marked as "of interest" in the current data table.
 
int32_t SDDS_SetColumnsOfInterest (SDDS_DATASET *SDDS_dataset, int32_t mode,...)
 Sets the acceptance flags for columns based on specified naming criteria.
 
void * SDDS_GetColumn (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves a copy of the data for a specified column, including only rows marked as "of interest".
 
void * SDDS_GetInternalColumn (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves an internal pointer to the data of a specified column, including all rows.
 
long double * SDDS_GetColumnInLongDoubles (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of long doubles, considering only rows marked as "of interest".
 
double * SDDS_GetColumnInDoubles (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of doubles, considering only rows marked as "of interest".
 
float * SDDS_GetColumnInFloats (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of floats, considering only rows marked as "of interest".
 
int32_t * SDDS_GetColumnInLong (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of 32-bit integers, considering only rows marked as "of interest".
 
short * SDDS_GetColumnInShort (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified numerical column as an array of short integers, considering only rows marked as "of interest".
 
char ** SDDS_GetColumnInString (SDDS_DATASET *SDDS_dataset, char *column_name)
 Retrieves the data of a specified column as an array of strings, considering only rows marked as "of interest".
 
void * SDDS_GetNumericColumn (SDDS_DATASET *SDDS_dataset, char *column_name, int32_t desiredType)
 Retrieves the data of a specified numerical column as an array of a desired numerical type, considering only rows marked as "of interest".
 
int64_t SDDS_GetSelectedRowIndex (SDDS_DATASET *SDDS_dataset, int64_t srow_index)
 Retrieves the actual row index corresponding to a selected row position within the current data table.
 
void * SDDS_GetValue (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t srow_index, void *memory)
 Retrieves the value from a specified column and selected row, optionally storing it in provided memory.
 
double SDDS_GetValueAsDouble (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t srow_index)
 Retrieves the value from a specified column and selected row, casting it to a double.
 
double SDDS_GetValueByIndexAsDouble (SDDS_DATASET *SDDS_dataset, int32_t column_index, int64_t srow_index)
 Retrieves the value from a specified column and selected row, casting it to a double.
 
void * SDDS_GetValueByIndex (SDDS_DATASET *SDDS_dataset, int32_t column_index, int64_t srow_index, void *memory)
 Retrieves the value from a specified column and selected row, optionally storing it in provided memory.
 
void * SDDS_GetValueByAbsIndex (SDDS_DATASET *SDDS_dataset, int32_t column_index, int64_t row_index, void *memory)
 Retrieves the value from a specified column and absolute row index, optionally storing it in provided memory.
 
int32_t SDDS_GetRowType (SDDS_DATASET *SDDS_dataset)
 Determines the data type of the rows based on selected columns in the current data table.
 
void * SDDS_GetRow (SDDS_DATASET *SDDS_dataset, int64_t srow_index, void *memory)
 Retrieves the data of a specific selected row as an array, considering only columns marked as "of interest".
 
void * SDDS_GetMatrixOfRows (SDDS_DATASET *SDDS_dataset, int64_t *n_rows)
 Retrieves all rows marked as "of interest" as a matrix (array of row arrays).
 
void * SDDS_GetCastMatrixOfRows (SDDS_DATASET *SDDS_dataset, int64_t *n_rows, int32_t sddsType)
 Retrieves all rows marked as "of interest" as a matrix, casting each value to a specified numerical type.
 
int32_t SDDS_GetParameters (SDDS_DATASET *SDDS_dataset,...)
 Retrieves multiple parameter values from the current data table of a data set.
 
void * SDDS_GetParameter (SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
 Retrieves the value of a specified parameter from the current data table of a data set.
 
void * SDDS_GetParameterByIndex (SDDS_DATASET *SDDS_dataset, int32_t index, void *memory)
 Retrieves the value of a specified parameter by its index from the current data table of a data set.
 
int32_t * SDDS_GetParameterAsLong (SDDS_DATASET *SDDS_dataset, char *parameter_name, int32_t *memory)
 Retrieves the value of a specified parameter as a 32-bit integer from the current data table of a data set.
 
int64_t * SDDS_GetParameterAsLong64 (SDDS_DATASET *SDDS_dataset, char *parameter_name, int64_t *memory)
 Retrieves the value of a specified parameter as a 64-bit integer from the current data table of an SDDS dataset.
 
long double * SDDS_GetParameterAsLongDouble (SDDS_DATASET *SDDS_dataset, char *parameter_name, long double *memory)
 Retrieves the value of a specified parameter as a long double from the current data table of an SDDS dataset.
 
double * SDDS_GetParameterAsDouble (SDDS_DATASET *SDDS_dataset, char *parameter_name, double *memory)
 Retrieves the value of a specified parameter as a double from the current data table of an SDDS dataset.
 
char * SDDS_GetParameterAsString (SDDS_DATASET *SDDS_dataset, char *parameter_name, char **memory)
 Retrieves the value of a specified parameter as a string from the current data table of an SDDS dataset.
 
char * SDDS_GetParameterAsFormattedString (SDDS_DATASET *SDDS_dataset, char *parameter_name, char **memory, char *suppliedformat)
 Retrieves the value of a specified parameter as a formatted string from the current data table of an SDDS dataset.
 
void * SDDS_GetFixedValueParameter (SDDS_DATASET *SDDS_dataset, char *parameter_name, void *memory)
 Retrieves the fixed value of a specified parameter from an SDDS dataset.
 
void * SDDS_GetMatrixFromColumn (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t dimension1, int64_t dimension2, int32_t mode)
 Extracts a matrix from a specified column in the current data table of an SDDS dataset.
 
void * SDDS_GetDoubleMatrixFromColumn (SDDS_DATASET *SDDS_dataset, char *column_name, int64_t dimension1, int64_t dimension2, int32_t mode)
 Extracts a matrix of doubles from a specified column in the current data table of an SDDS dataset.
 
int64_t SDDS_SetRowsOfInterest (SDDS_DATASET *SDDS_dataset, char *selection_column, int32_t mode,...)
 Sets the rows of interest in an SDDS dataset based on various selection criteria.
 
int64_t SDDS_MatchRowsOfInterest (SDDS_DATASET *SDDS_dataset, char *selection_column, char *label_to_match, int32_t logic)
 Matches and marks rows of interest in an SDDS dataset based on label matching.
 
int64_t SDDS_FilterRowsOfInterest (SDDS_DATASET *SDDS_dataset, char *filter_column, double lower_limit, double upper_limit, int32_t logic)
 Filters rows of interest in an SDDS dataset based on numeric ranges in a specified column.
 
int64_t SDDS_FilterRowsByNumScan (SDDS_DATASET *SDDS_dataset, char *filter_column, uint32_t mode)
 Filters rows of interest in an SDDS dataset based on numeric scanning of a specified column.
 
int32_t SDDS_DeleteUnsetRows (SDDS_DATASET *SDDS_dataset)
 Deletes rows from an SDDS dataset that are not marked as "of interest".
 
int32_t SDDS_TransferRow (SDDS_DATASET *SDDS_dataset, int64_t target, int64_t source)
 Transfers data from a source row to a target row within an SDDS dataset.
 
int32_t SDDS_DeleteColumn (SDDS_DATASET *SDDS_dataset, char *column_name)
 Deletes a specified column from an SDDS dataset.
 
int32_t SDDS_DeleteUnsetColumns (SDDS_DATASET *SDDS_dataset)
 Deletes all columns from an SDDS dataset that are not marked as "of interest".
 
int32_t SDDS_CopyColumn (SDDS_DATASET *SDDS_dataset, int32_t target, int32_t source)
 Copies data from a source column to a target column within an SDDS dataset.
 
int32_t SDDS_DeleteParameter (SDDS_DATASET *SDDS_dataset, char *parameter_name)
 Deletes a specified parameter from an SDDS dataset.
 
int32_t SDDS_CopyParameter (SDDS_DATASET *SDDS_dataset, int32_t target, int32_t source)
 Copies a parameter from a source index to a target index within an SDDS dataset.
 
int32_t SDDS_ItemInsideWindow (void *data, int64_t index, int32_t type, double lower_limit, double upper_limit)
 Checks whether a data item is within a specified numeric window.
 
int32_t SDDS_Logic (int32_t previous, int32_t match, uint32_t logic)
 Applies logical operations to determine the new state of a row flag based on previous and current match conditions.
 
SDDS_ARRAYSDDS_GetArray (SDDS_DATASET *SDDS_dataset, char *array_name, SDDS_ARRAY *memory)
 Retrieves an array from the current data table of an SDDS dataset.
 
char ** SDDS_GetArrayInString (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t *values)
 Retrieves an array from the current data table of an SDDS dataset and converts its elements to strings.
 
double * SDDS_GetArrayInDoubles (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t *values)
 Retrieves an array from the current data table of an SDDS dataset and converts its elements to doubles.
 
int32_t * SDDS_GetArrayInLong (SDDS_DATASET *SDDS_dataset, char *array_name, int32_t *values)
 Retrieves an array from the current data table of an SDDS dataset and converts its elements to 32-bit integers.
 
int32_t SDDS_GetDescription (SDDS_DATASET *SDDS_dataset, char **text, char **contents)
 Retrieves the text and contents descriptions from an SDDS dataset.
 
int32_t SDDS_SetArrayUnitsConversion (SDDS_DATASET *SDDS_dataset, char *array_name, char *new_units, char *old_units, double factor)
 Sets unit conversions for a specified array in an SDDS dataset.
 
int32_t SDDS_SetColumnUnitsConversion (SDDS_DATASET *SDDS_dataset, char *column_name, char *new_units, char *old_units, double factor)
 Sets unit conversions for a specified column in an SDDS dataset.
 
int32_t SDDS_SetParameterUnitsConversion (SDDS_DATASET *SDDS_dataset, char *parameter_name, char *new_units, char *old_units, double factor)
 Sets unit conversions for a specified parameter in an SDDS dataset.
 

Detailed Description

This file contains routines for getting pointers to SDDS objects like columns and parameters.

This file provides functions for extracting data in the Self-Describing Data Sets (SDDS) format.

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_extract.c.

Function Documentation

◆ SDDS_AssertColumnFlags()

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

Sets acceptance flags for columns based on specified criteria.

This function allows setting column flags in two modes:

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

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

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

Definition at line 273 of file SDDS_extract.c.

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

◆ SDDS_AssertRowFlags()

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

Sets acceptance flags for rows based on specified criteria.

This function allows setting row flags in two modes:

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

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

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

Definition at line 148 of file SDDS_extract.c.

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

◆ SDDS_CopyColumn()

int32_t SDDS_CopyColumn ( SDDS_DATASET * SDDS_dataset,
int32_t target,
int32_t source )

Copies data from a source column to a target column within an SDDS dataset.

This function duplicates the data from the specified source column to the target column in the provided SDDS dataset. It handles both string and non-string data types appropriately, ensuring that memory is managed correctly for string entries.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
targetThe index of the target column where data will be copied to.
sourceThe index of the source column from which data will be copied.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the column copy was successful.
0Indicates that an error occurred (e.g., invalid dataset, out-of-range indices, memory allocation failure, string copy failure).
Note
  • Both target and source must be valid column indices within the dataset.
  • The function does not handle the allocation of new columns; it assumes that the target column already exists.
See also
SDDS_DeleteColumn, SDDS_DeleteUnsetColumns, SDDS_TransferRow

Definition at line 3928 of file SDDS_extract.c.

3928 {
3929 COLUMN_DEFINITION *cd_target, *cd_source;
3930 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_CopyColumn"))
3931 return (0);
3932 if (target < 0 || source < 0 || target >= SDDS_dataset->layout.n_columns || source >= SDDS_dataset->layout.n_columns) {
3933 SDDS_SetError("Unable to copy column--target or source index out of range (SDDS_CopyColumn");
3934 return (0);
3935 }
3936 cd_target = SDDS_dataset->layout.column_definition + target;
3937 cd_source = SDDS_dataset->layout.column_definition + source;
3938 SDDS_dataset->column_flag[target] = SDDS_dataset->column_flag[source];
3939 if (SDDS_dataset->n_rows_allocated) {
3940 if (cd_target->type != cd_source->type) {
3941 if (!(SDDS_dataset->data[target] = SDDS_Realloc(SDDS_dataset->data[target], SDDS_type_size[cd_source->type - 1] * SDDS_dataset->n_rows_allocated))) {
3942 SDDS_SetError("Unable to copy column--memory allocation failure (SDDS_CopyColumn)");
3943 return (0);
3944 }
3945 }
3946 if (cd_source->type != SDDS_STRING)
3947 memcpy(SDDS_dataset->data[target], SDDS_dataset->data[source], SDDS_type_size[cd_source->type - 1] * SDDS_dataset->n_rows);
3948 else if (!SDDS_CopyStringArray(SDDS_dataset->data[target], SDDS_dataset->data[source], SDDS_dataset->n_rows)) {
3949 SDDS_SetError("Unable to copy column--string copy failure (SDDS_CopyColumn)");
3950 return (0);
3951 }
3952 }
3953 memcpy((char *)cd_target, (char *)cd_source, sizeof(*cd_target));
3954 return (1);
3955}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85

◆ SDDS_CopyParameter()

int32_t SDDS_CopyParameter ( SDDS_DATASET * SDDS_dataset,
int32_t target,
int32_t source )

Copies a parameter from a source index to a target index within an SDDS dataset.

This function duplicates the parameter data from the source index to the target index in the provided SDDS dataset. It handles both string and non-string data types appropriately, ensuring that memory is managed correctly for string entries.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
targetThe index of the target parameter where data will be copied to.
sourceThe index of the source parameter from which data will be copied.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the parameter copy was successful.
0Indicates that an error occurred (e.g., invalid dataset, out-of-range indices, memory allocation failure, string copy failure).
Note
  • Both target and source must be valid parameter indices within the dataset.
  • The function assumes that the target parameter already exists and is intended to be overwritten.
See also
SDDS_DeleteParameter, SDDS_CopyArray

Definition at line 4017 of file SDDS_extract.c.

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

◆ SDDS_CountColumnsOfInterest()

int32_t SDDS_CountColumnsOfInterest ( SDDS_DATASET * SDDS_dataset)

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

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

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

Definition at line 342 of file SDDS_extract.c.

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

◆ SDDS_CountRowsOfInterest()

int64_t SDDS_CountRowsOfInterest ( SDDS_DATASET * SDDS_dataset)

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

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

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

Definition at line 364 of file SDDS_extract.c.

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

◆ SDDS_DeleteColumn()

int32_t SDDS_DeleteColumn ( SDDS_DATASET * SDDS_dataset,
char * column_name )

Deletes a specified column from an SDDS dataset.

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

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

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

Definition at line 3845 of file SDDS_extract.c.

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

◆ SDDS_DeleteParameter()

int32_t SDDS_DeleteParameter ( SDDS_DATASET * SDDS_dataset,
char * parameter_name )

Deletes a specified parameter from an SDDS dataset.

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

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

Definition at line 3978 of file SDDS_extract.c.

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

◆ SDDS_DeleteUnsetColumns()

int32_t SDDS_DeleteUnsetColumns ( SDDS_DATASET * SDDS_dataset)

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

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

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

Definition at line 3893 of file SDDS_extract.c.

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

◆ SDDS_DeleteUnsetRows()

int32_t SDDS_DeleteUnsetRows ( SDDS_DATASET * SDDS_dataset)

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

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

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

Definition at line 3760 of file SDDS_extract.c.

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

◆ SDDS_FilterRowsByNumScan()

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

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

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

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

Definition at line 3697 of file SDDS_extract.c.

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

◆ SDDS_FilterRowsOfInterest()

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

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

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

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

Definition at line 3628 of file SDDS_extract.c.

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

◆ SDDS_GetArray()

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

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

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

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

Definition at line 4209 of file SDDS_extract.c.

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

◆ SDDS_GetArrayInDoubles()

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

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

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

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

Definition at line 4413 of file SDDS_extract.c.

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

◆ SDDS_GetArrayInLong()

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

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

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

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

Definition at line 4518 of file SDDS_extract.c.

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

◆ SDDS_GetArrayInString()

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

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

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

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

Definition at line 4291 of file SDDS_extract.c.

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

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

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

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

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

Definition at line 2343 of file SDDS_extract.c.

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

◆ SDDS_GetColumn()

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

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

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

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

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

Definition at line 611 of file SDDS_extract.c.

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

◆ SDDS_GetColumnInDoubles()

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

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

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

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

Definition at line 872 of file SDDS_extract.c.

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

◆ SDDS_GetColumnInFloats()

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

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

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

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

Definition at line 1014 of file SDDS_extract.c.

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

◆ SDDS_GetColumnInLong()

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

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

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

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

Definition at line 1157 of file SDDS_extract.c.

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

◆ SDDS_GetColumnInLongDoubles()

long double * SDDS_GetColumnInLongDoubles ( SDDS_DATASET * SDDS_dataset,
char * column_name )

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

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

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

Definition at line 730 of file SDDS_extract.c.

730 {
731 int32_t size, type, index;
732 int64_t i, j, n_rows;
733 long double *data;
734 void *rawData;
735
736 j = 0;
737
738 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetColumnInLongDoubles"))
739 return (NULL);
740 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
741 SDDS_SetError("Unable to get column--name is not recognized (SDDS_GetColumnInLongDoubles)");
742 return (NULL);
743 }
744 if ((n_rows = SDDS_CountRowsOfInterest(SDDS_dataset)) <= 0) {
745 SDDS_SetError("Unable to get column--no rows left (SDDS_GetColumnInLongDoubles)");
746 return (NULL);
747 }
748 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) <= 0 || (size = SDDS_GetTypeSize(type)) <= 0 || (!SDDS_NUMERIC_TYPE(type) && type != SDDS_CHARACTER)) {
749 SDDS_SetError("Unable to get column--data size or type undefined or non-numeric (SDDS_GetColumnInLongDoubles)");
750 return (NULL);
751 }
752 if (!(data = (long double *)SDDS_Malloc(sizeof(long double) * n_rows))) {
753 SDDS_SetError("Unable to get column--memory allocation failure (SDDS_GetColumnInLongDoubles)");
754 return (NULL);
755 }
756 rawData = SDDS_dataset->data[index];
757 switch (type) {
758 case SDDS_LONGDOUBLE:
759 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
760 if (SDDS_dataset->row_flag[i])
761 data[j++] = ((long double *)rawData)[i];
762 }
763 break;
764 case SDDS_DOUBLE:
765 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
766 if (SDDS_dataset->row_flag[i])
767 data[j++] = ((double *)rawData)[i];
768 }
769 break;
770 case SDDS_FLOAT:
771 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
772 if (SDDS_dataset->row_flag[i])
773 data[j++] = ((float *)rawData)[i];
774 }
775 break;
776 case SDDS_LONG:
777 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
778 if (SDDS_dataset->row_flag[i])
779 data[j++] = ((int32_t *)rawData)[i];
780 }
781 break;
782 case SDDS_ULONG:
783 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
784 if (SDDS_dataset->row_flag[i])
785 data[j++] = ((uint32_t *)rawData)[i];
786 }
787 break;
788 case SDDS_LONG64:
789 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
790 if (SDDS_dataset->row_flag[i])
791 data[j++] = ((int64_t *)rawData)[i];
792 }
793 break;
794 case SDDS_ULONG64:
795 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
796 if (SDDS_dataset->row_flag[i])
797 data[j++] = ((uint64_t *)rawData)[i];
798 }
799 break;
800 case SDDS_SHORT:
801 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
802 if (SDDS_dataset->row_flag[i])
803 data[j++] = ((short *)rawData)[i];
804 }
805 break;
806 case SDDS_USHORT:
807 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
808 if (SDDS_dataset->row_flag[i])
809 data[j++] = ((unsigned short *)rawData)[i];
810 }
811 break;
812 case SDDS_CHARACTER:
813 for (i = j = 0; i < SDDS_dataset->n_rows; i++) {
814 if (SDDS_dataset->row_flag[i])
815 data[j++] = ((char *)rawData)[i];
816 }
817 break;
818 }
819 if (j != n_rows) {
820 SDDS_SetError("Unable to get column--row number mismatch (SDDS_GetColumnInLongDoubles)");
821 return (NULL);
822 }
823 if (SDDS_GetColumnMemoryMode(SDDS_dataset) == DONT_TRACK_COLUMN_MEMORY_AFTER_ACCESS) {
824 SDDS_dataset->column_track_memory[index] = 0;
825 //Free internal copy now under the assumption that the program will not ask for it again.
826 if (type == SDDS_STRING) {
827 if (0) {
828 //FIX this. It currently causes a memory error in SDDS_ScanData2 with multipage files
829 char **ptr = (char **)SDDS_dataset->data[index];
830 for (i = 0; i < SDDS_dataset->n_rows_allocated; i++, ptr++)
831 if (*ptr)
832 free(*ptr);
833 free(SDDS_dataset->data[index]);
834 SDDS_dataset->data[index] = NULL;
835 }
836 } else {
837 free(SDDS_dataset->data[index]);
838 SDDS_dataset->data[index] = NULL;
839 }
840 }
841 return (data);
842}

◆ SDDS_GetColumnInShort()

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

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

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

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

Definition at line 1298 of file SDDS_extract.c.

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

◆ SDDS_GetColumnInString()

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

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

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

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

Definition at line 1439 of file SDDS_extract.c.

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

◆ SDDS_GetDescription()

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

Retrieves the text and contents descriptions from an SDDS dataset.

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

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

Definition at line 4626 of file SDDS_extract.c.

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

◆ SDDS_GetDoubleMatrixFromColumn()

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

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

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

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

Definition at line 3214 of file SDDS_extract.c.

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

◆ SDDS_GetFixedValueParameter()

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

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

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

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

Definition at line 3084 of file SDDS_extract.c.

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

◆ SDDS_GetInternalColumn()

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

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

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

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

Definition at line 688 of file SDDS_extract.c.

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

◆ SDDS_GetMatrixFromColumn()

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

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

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

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

Definition at line 3142 of file SDDS_extract.c.

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

◆ SDDS_GetMatrixOfRows()

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

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

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

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

Definition at line 2266 of file SDDS_extract.c.

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

◆ SDDS_GetNumericColumn()

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

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

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

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

Definition at line 1617 of file SDDS_extract.c.

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

◆ SDDS_GetParameter()

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

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

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

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

Definition at line 2481 of file SDDS_extract.c.

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

◆ SDDS_GetParameterAsDouble()

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

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

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

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

Definition at line 2782 of file SDDS_extract.c.

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

◆ SDDS_GetParameterAsFormattedString()

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

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

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

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

Definition at line 2935 of file SDDS_extract.c.

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

◆ SDDS_GetParameterAsLong()

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

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

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

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

Definition at line 2615 of file SDDS_extract.c.

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

◆ SDDS_GetParameterAsLong64()

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

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

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

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

Definition at line 2671 of file SDDS_extract.c.

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

◆ SDDS_GetParameterAsLongDouble()

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

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

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

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

Definition at line 2727 of file SDDS_extract.c.

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

◆ SDDS_GetParameterAsString()

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

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

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

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

Definition at line 2838 of file SDDS_extract.c.

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

◆ SDDS_GetParameterByIndex()

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

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

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

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

Definition at line 2554 of file SDDS_extract.c.

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

◆ SDDS_GetParameters()

int32_t SDDS_GetParameters ( SDDS_DATASET * SDDS_dataset,
... )

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

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

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

Definition at line 2420 of file SDDS_extract.c.

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

◆ SDDS_GetRow()

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

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

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

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

Definition at line 2201 of file SDDS_extract.c.

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

◆ SDDS_GetRowFlag()

int32_t SDDS_GetRowFlag ( SDDS_DATASET * SDDS_dataset,
int64_t row )

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

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

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

Definition at line 71 of file SDDS_extract.c.

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

◆ SDDS_GetRowFlags()

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

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

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

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

Definition at line 97 of file SDDS_extract.c.

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

◆ SDDS_GetRowType()

int32_t SDDS_GetRowType ( SDDS_DATASET * SDDS_dataset)

Determines the data type of the rows based on selected columns in the current data table.

This function iterates through all columns marked as "of interest" and verifies that they share the same data type. If all selected columns have a consistent data type, that type is returned. If there is a mismatch in data types among the selected columns, an error is recorded.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
Returns
  • Integer representing the data type (as defined by SDDS constants) if all selected columns have the same data type.
  • 0 on failure (e.g., invalid dataset, no columns selected, inconsistent data types among selected columns). In this case, an error message is recorded internally.
Warning
  • Ensure that at least one column is marked as "of interest" before calling this function to avoid unexpected results.
Note
  • This function is useful for operations that require uniform data types across all selected columns.
See also

Definition at line 2149 of file SDDS_extract.c.

2149 {
2150 int64_t i;
2151 int32_t type;
2152 type = -1;
2153 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_GetRowType"))
2154 return (0);
2155 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2156 if (!SDDS_dataset->column_flag[i])
2157 continue;
2158 if (type == -1)
2159 type = SDDS_dataset->layout.column_definition[i].type;
2160 else if (type != SDDS_dataset->layout.column_definition[i].type) {
2161 SDDS_SetError("Unable to get row type--inconsistent data type for selected columns (SDDS_GetRowType)");
2162 return (0);
2163 }
2164 }
2165 return (type);
2166}

◆ SDDS_GetSelectedRowIndex()

int64_t SDDS_GetSelectedRowIndex ( SDDS_DATASET * SDDS_dataset,
int64_t srow_index )

Retrieves the actual row index corresponding to a selected row position within the current data table.

This function maps a selected row index (i.e., the position among rows marked as "of interest") to its corresponding actual row index within the dataset's data table.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
srow_indexZero-based index representing the position of the selected row among all rows marked as "of interest".
Returns
  • Non-negative integer representing the actual row index within the dataset's data table.
  • -1 if an error occurs (e.g., invalid dataset, tabular data not present, srow_index out of range).
Warning
  • Ensure that srow_index is within the valid range [0, SDDS_CountRowsOfInterest(SDDS_dataset) - 1] to avoid out-of-range errors.
Note
  • This function is useful when iterating over selected rows and needing to access their actual positions within the dataset.
See also

Definition at line 1701 of file SDDS_extract.c.

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

◆ SDDS_GetValue()

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

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

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

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

Definition at line 1754 of file SDDS_extract.c.

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

◆ SDDS_GetValueAsDouble()

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

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

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

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

Definition at line 1821 of file SDDS_extract.c.

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

◆ SDDS_GetValueByAbsIndex()

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

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

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

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

Definition at line 2090 of file SDDS_extract.c.

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

◆ SDDS_GetValueByIndex()

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

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

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

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

Definition at line 2014 of file SDDS_extract.c.

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

◆ SDDS_GetValueByIndexAsDouble()

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

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

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

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

Definition at line 1914 of file SDDS_extract.c.

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

◆ SDDS_ItemInsideWindow()

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

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

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

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

Definition at line 4077 of file SDDS_extract.c.

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

◆ SDDS_Logic()

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

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

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

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

Definition at line 4165 of file SDDS_extract.c.

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

◆ SDDS_MatchRowsOfInterest()

int64_t SDDS_MatchRowsOfInterest ( SDDS_DATASET * SDDS_dataset,
char * selection_column,
char * label_to_match,
int32_t logic )

Matches and marks rows of interest in an SDDS dataset based on label matching.

This function marks rows in the provided SDDS dataset as "of interest" by matching labels in a specified column against a target label. It supports both direct and indirect matching, as well as case-sensitive and case-insensitive comparisons, based on the provided logic flags.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
selection_columnA null-terminated string specifying the name of the column used for label matching. This column must be of string or character type.
label_to_matchA null-terminated string specifying the label to match against the entries in the selection column. If logic includes SDDS_INDIRECT_MATCH, this parameter is treated as the name of another column used for indirect matching.
logicAn integer representing logical operation flags. Supported flags include:
  • SDDS_NOCASE_COMPARE: Perform case-insensitive comparison.
  • SDDS_INDIRECT_MATCH: Use indirect matching via another column.
Returns
On success, returns the number of rows marked as "of interest". On failure, returns -1 and sets an appropriate error message.
Return values
-1Indicates that an error occurred (e.g., invalid dataset, unrecognized selection column, type mismatch, unrecognized indirect column).
Non-negativeInteger representing the count of rows marked as "of interest".
Note
  • The selection column must exist and be of string or character type.
  • If using indirect matching (SDDS_INDIRECT_MATCH), the indirect column must exist and be of the same type as the selection column.
See also
SDDS_SetRowsOfInterest, SDDS_FilterRowsOfInterest, SDDS_DeleteUnsetRows

Definition at line 3506 of file SDDS_extract.c.

3506 {
3507 int32_t match, type, index, indirect_index;
3508 int64_t i, count;
3509 char *match_string;
3510#ifndef tolower
3511# if !defined(_MINGW)
3512 int tolower(int c);
3513# endif
3514#endif
3515
3516 index = type = indirect_index = 0;
3517
3518 match_string = NULL;
3519 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_MatchRowsOfInterest"))
3520 return (-1);
3521 if (selection_column) {
3522 if ((index = SDDS_GetColumnIndex(SDDS_dataset, selection_column)) < 0) {
3523 SDDS_SetError("Unable to select rows--column name is unrecognized (SDDS_MatchRowsOfInterest)");
3524 return (-1);
3525 }
3526 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) != SDDS_STRING && type != SDDS_CHARACTER) {
3527 SDDS_SetError("Unable to select rows--selection column is not a string (SDDS_MatchRowsOfInterest)");
3528 return (-1);
3529 }
3530 if (!label_to_match) {
3531 SDDS_SetError("Unable to select rows--selection label is NULL (SDDS_MatchRowsOfInterest)");
3532 return (-1);
3533 }
3534 if (!(logic & SDDS_INDIRECT_MATCH))
3535 match_string = expand_ranges(label_to_match);
3536 else {
3537 if ((indirect_index = SDDS_GetColumnIndex(SDDS_dataset, label_to_match)) < 0) {
3538 SDDS_SetError("Unable to select rows--indirect column name is unrecognized (SDDS_MatchRowsOfInterest)");
3539 return (-1);
3540 }
3541 if (SDDS_GetColumnType(SDDS_dataset, indirect_index) != type) {
3542 SDDS_SetError("Unable to select rows--indirect column is not same type as main column (SDDS_MatchRowsOfInterest)");
3543 return (-1);
3544 }
3545 }
3546 }
3547 if (type == SDDS_STRING) {
3548 int (*stringCompare)(const char *s, const char *t);
3549 int (*wildMatch)(char *s, char *t);
3550 if (logic & SDDS_NOCASE_COMPARE) {
3551 stringCompare = strcmp_ci;
3552 wildMatch = wild_match_ci;
3553 } else {
3554 stringCompare = strcmp;
3555 wildMatch = wild_match;
3556 }
3557 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3558 if (selection_column)
3559 match = SDDS_Logic(SDDS_dataset->row_flag[i], (logic & SDDS_INDIRECT_MATCH ? (*stringCompare)(*((char **)SDDS_dataset->data[index] + i), *((char **)SDDS_dataset->data[indirect_index] + i)) == 0 : (*wildMatch)(*((char **)SDDS_dataset->data[index] + i), match_string)), logic);
3560 else
3561 match = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3562 if ((SDDS_dataset->row_flag[i] = match))
3563 count++;
3564 }
3565 } else {
3566 char c1, c2;
3567 c2 = 0;
3568 if (!(logic & SDDS_INDIRECT_MATCH))
3569 c2 = *match_string;
3570 if (logic & SDDS_NOCASE_COMPARE) {
3571 c2 = tolower(c2);
3572 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3573 c1 = tolower(*((char *)SDDS_dataset->data[index] + i));
3574 if (selection_column)
3575 match = SDDS_Logic(SDDS_dataset->row_flag[i], logic & SDDS_INDIRECT_MATCH ? c1 == tolower(*((char *)SDDS_dataset->data[indirect_index] + i)) : c1 == c2, logic);
3576 else
3577 match = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3578 if ((SDDS_dataset->row_flag[i] = match))
3579 count++;
3580 }
3581 } else {
3582 for (i = count = 0; i < SDDS_dataset->n_rows; i++) {
3583 c1 = *((char *)SDDS_dataset->data[index] + i);
3584 if (selection_column)
3585 match = SDDS_Logic(SDDS_dataset->row_flag[i], logic & SDDS_INDIRECT_MATCH ? c1 == *((char *)SDDS_dataset->data[indirect_index] + i) : c1 == c2, logic);
3586 else
3587 match = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3588 if ((SDDS_dataset->row_flag[i] = match))
3589 count++;
3590 }
3591 }
3592 }
3593 if (match_string)
3594 free(match_string);
3595 return (count);
3596}
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...
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int wild_match_ci(char *string, char *template)
Determine whether one string is a case-insensitive wildcard match for another.
Definition wild_match.c:220
int strcmp_ci(const char *s, const char *t)
Compare two strings case-insensitively.
Definition wild_match.c:396
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
Definition wild_match.c:429
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
Definition wild_match.c:49

◆ SDDS_SetArrayUnitsConversion()

int32_t SDDS_SetArrayUnitsConversion ( SDDS_DATASET * SDDS_dataset,
char * array_name,
char * new_units,
char * old_units,
double factor )

Sets unit conversions for a specified array in an SDDS dataset.

This function updates the units of the specified array within the SDDS dataset and applies a conversion factor to all its elements if the dataset has already been read (i.e., pages_read > 0). The function ensures that the new units are consistent with the old units if provided.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
array_nameA null-terminated string specifying the name of the array to update.
new_unitsA null-terminated string specifying the new units to assign to the array. This parameter must not be NULL.
old_unitsA null-terminated string specifying the expected current units of the array. If NULL, the function does not verify the existing units.
factorA double representing the conversion factor to apply to each element of the array. Each element will be multiplied by this factor.
Returns
Returns 1 on successful unit conversion and update. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the unit conversion was successfully applied.
0Indicates that an error occurred (e.g., invalid dataset, unrecognized array name, type undefined, memory allocation failure).
Note
  • The new_units parameter must not be NULL. Passing NULL will result in an error.
  • If the dataset has not been read yet (pages_read == 0), the conversion factor is stored but not applied immediately.
  • The function handles various data types, ensuring that the conversion factor is appropriately applied based on the array's type.
See also
SDDS_SetColumnUnitsConversion, SDDS_SetParameterUnitsConversion, SDDS_GetArray

Definition at line 4675 of file SDDS_extract.c.

4675 {
4676 int32_t index, type;
4677 int64_t i;
4678 void *rawData;
4679 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetArrayUnitsConversion"))
4680 return(0);
4681 if (new_units == NULL) {
4682 SDDS_SetError("new_units is NULL (SDDS_SetArrayUnitsConversion)");
4683 return(0);
4684 }
4685 if ((index = SDDS_GetArrayIndex(SDDS_dataset, array_name)) < 0) {
4686 SDDS_SetError("Unable to get array--name is not recognized (SDDS_SetArrayUnitsConversion)");
4687 return(0);
4688 }
4689 if (!(type = SDDS_GetArrayType(SDDS_dataset, index))) {
4690 SDDS_SetError("Unable to get array--data type undefined (SDDS_SetArrayUnitsConversion)");
4691 return(0);
4692 }
4693 if (SDDS_dataset->layout.array_definition[index].units != NULL) {
4694 if (strcmp(new_units, SDDS_dataset->layout.array_definition[index].units) != 0) {
4695 if ((old_units != NULL) && (strcmp(old_units, SDDS_dataset->layout.array_definition[index].units) != 0)) {
4696 SDDS_SetError("Unexpected units value found (SDDS_SetArrayUnitsConversion)");
4697 return(0);
4698 }
4699 /* free(SDDS_dataset->layout.array_definition[index].units); */
4700 cp_str(&(SDDS_dataset->layout.array_definition[index].units), new_units);
4701 }
4702 } else {
4703 cp_str(&(SDDS_dataset->layout.array_definition[index].units), new_units);
4704 }
4705
4706 if (SDDS_dataset->pages_read == 0) {
4707 return(1);
4708 }
4709 rawData = SDDS_dataset->array[index].data;
4710 switch (type) {
4711 case SDDS_LONGDOUBLE:
4712 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4713 ((long double *)rawData)[i] *= factor;
4714 }
4715 break;
4716 case SDDS_DOUBLE:
4717 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4718 ((double *)rawData)[i] *= factor;
4719 }
4720 break;
4721 case SDDS_FLOAT:
4722 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4723 ((float *)rawData)[i] *= factor;
4724 }
4725 break;
4726 case SDDS_LONG:
4727 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4728 ((int32_t *)rawData)[i] *= factor;
4729 }
4730 break;
4731 case SDDS_ULONG:
4732 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4733 ((uint32_t *)rawData)[i] *= factor;
4734 }
4735 break;
4736 case SDDS_LONG64:
4737 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4738 ((int64_t *)rawData)[i] *= factor;
4739 }
4740 break;
4741 case SDDS_ULONG64:
4742 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4743 ((uint64_t *)rawData)[i] *= factor;
4744 }
4745 break;
4746 case SDDS_SHORT:
4747 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4748 ((short *)rawData)[i] *= factor;
4749 }
4750 break;
4751 case SDDS_USHORT:
4752 for (i = 0; i < SDDS_dataset->array[index].elements; i++) {
4753 ((unsigned short *)rawData)[i] *= factor;
4754 }
4755 break;
4756 }
4757 return(1);
4758}
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.
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
Definition cp_str.c:28

◆ SDDS_SetColumnFlags()

int32_t SDDS_SetColumnFlags ( SDDS_DATASET * SDDS_dataset,
int32_t column_flag_value )

Sets the acceptance flags for all columns in the current data table of a data set.

This function initializes the acceptance flags for each column. A non-zero flag indicates that the column is "of interest" and should be considered in subsequent operations, while a zero flag marks the column for rejection.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
column_flag_valueInteger value to assign to all column flags.
  • Non-zero value: Marks columns as accepted ("of interest").
  • Zero value: Marks columns as rejected.
Returns
  • 1 on successful update of column flags.
  • 0 on failure, with an error message recorded (e.g., memory allocation failure).
Note
This function overwrites any existing column flags with the specified column_flag_value. It also updates the column_order array accordingly.
See also
SDDS_GetColumnFlags, SDDS_AssertColumnFlags

Definition at line 218 of file SDDS_extract.c.

218 {
219 int64_t i;
220 /* int32_t j; */
221 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnFlags"))
222 return 0;
223 if ((!SDDS_dataset->column_flag || !SDDS_dataset->column_order) && !SDDS_AllocateColumnFlags(SDDS_dataset))
224 return 0;
225 if (!SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns, SDDS_LONG, (int32_t)column_flag_value, (int32_t)0)) {
226 SDDS_SetError("Unable to set column flags--memory filling failed (SDDS_SetColumnFlags)");
227 return (0);
228 }
229 SDDS_dataset->n_of_interest = column_flag_value ? SDDS_dataset->layout.n_columns : 0;
230 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
231 SDDS_dataset->column_order[i] = column_flag_value ? i : -1;
232 return (1);
233}
int32_t SDDS_SetMemory(void *mem, int64_t n_elements, int32_t data_type,...)
Initializes a memory block with a sequence of values based on a specified data type.

◆ SDDS_SetColumnsOfInterest()

int32_t SDDS_SetColumnsOfInterest ( SDDS_DATASET * SDDS_dataset,
int32_t mode,
... )

Sets the acceptance flags for columns based on specified naming criteria.

This function allows modifying column acceptance flags using various methods, including specifying column names directly or using pattern matching.

Supported modes:

  • SDDS_NAME_ARRAY: Provide an array of column names to mark as "of interest".
  • SDDS_NAMES_STRING: Provide a single string containing comma-separated column names.
  • SDDS_NAME_STRINGS: Provide multiple individual column name strings, terminated by NULL.
  • SDDS_MATCH_STRING: Provide a pattern string and a logic mode to match column names.

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

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
modeOperation mode determining how columns are selected. Possible values:
  • SDDS_NAME_ARRAY: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_NAME_ARRAY, int32_t n_entries, char **nameArray);
  • SDDS_NAMES_STRING: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_NAMES_STRING, char *names);
  • SDDS_NAME_STRINGS: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_NAME_STRINGS, char *name1, char *name2, ..., NULL);
  • SDDS_MATCH_STRING: c SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, SDDS_MATCH_STRING, char *pattern, int32_t logic_mode);
...Variable arguments based on the selected mode:
  • SDDS_NAME_ARRAY:
    • int32_t n_entries: Number of column names in the array.
    • char **nameArray: Array of column name strings.
  • SDDS_NAMES_STRING:
    • char *names: Comma-separated string of column names.
  • SDDS_NAME_STRINGS:
    • char *name1, char *name2, ..., NULL: Individual column name strings terminated by NULL.
  • SDDS_MATCH_STRING:
    • char *pattern: Pattern string to match column names (supports wildcards).
    • int32_t logic_mode: Logic mode for matching (e.g., AND, OR).
Returns
  • 1 on successful update of column flags.
  • 0 on failure, with an error message recorded (e.g., invalid mode, memory issues, unrecognized column names).
Note
  • When using SDDS_MATCH_STRING, the pattern may include wildcards to match multiple column names.
  • Ensure that column names provided exist within the dataset to avoid errors.
See also
SDDS_SetColumnFlags, SDDS_AssertColumnFlags, SDDS_GetColumnFlags

Definition at line 432 of file SDDS_extract.c.

439{
440 va_list argptr;
441 int32_t i, j, index, n_names;
442 int32_t retval;
443 /* int32_t type; */
444 char **name, *string, *match_string, *ptr;
445 int32_t local_memory; /* (0,1,2) --> (none, pointer array, pointer array + strings) locally allocated */
446 char buffer[SDDS_MAXLINE];
447 int32_t logic;
448
449 name = NULL;
450 n_names = local_memory = logic = 0;
451
452 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnsOfInterest"))
453 return (0);
454 if ((!SDDS_dataset->column_flag || !SDDS_dataset->column_order) && !SDDS_AllocateColumnFlags(SDDS_dataset))
455 return 0;
456 va_start(argptr, mode);
457 retval = -1;
458 match_string = NULL;
459 switch (mode) {
460 case SDDS_NAME_ARRAY:
461 local_memory = 0;
462 n_names = va_arg(argptr, int32_t);
463 name = va_arg(argptr, char **);
464 break;
465 case SDDS_NAMES_STRING:
466 local_memory = 2;
467 n_names = 0;
468 name = NULL;
469 ptr = va_arg(argptr, char *);
470 SDDS_CopyString(&string, ptr);
471 while ((ptr = strchr(string, ',')))
472 *ptr = ' ';
473 while (SDDS_GetToken(string, buffer, SDDS_MAXLINE) > 0) {
474 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1))) || !SDDS_CopyString(name + n_names, buffer)) {
475 SDDS_SetError("Unable to process column selection--memory allocation failure (SDDS_SetColumnsOfInterest)");
476 retval = 0;
477 break;
478 }
479 n_names++;
480 }
481 free(string);
482 break;
483 case SDDS_NAME_STRINGS:
484 local_memory = 1;
485 n_names = 0;
486 name = NULL;
487 while ((string = va_arg(argptr, char *))) {
488 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1)))) {
489 SDDS_SetError("Unable to process column selection--memory allocation failure (SDDS_SetColumnsOfInterest)");
490 retval = 0;
491 break;
492 }
493 name[n_names++] = string;
494 }
495 break;
496 case SDDS_MATCH_STRING:
497 local_memory = 0;
498 n_names = 1;
499 if (!(string = va_arg(argptr, char *))) {
500 SDDS_SetError("Unable to process column selection--invalid matching string (SDDS_SetColumnsOfInterest)");
501 retval = 0;
502 break;
503 }
504 match_string = expand_ranges(string);
505 logic = va_arg(argptr, int32_t);
506 break;
507 default:
508 SDDS_SetError("Unable to process column selection--unknown mode (SDDS_SetColumnsOfInterest)");
509 retval = 0;
510 break;
511 }
512
513 va_end(argptr);
514 if (retval != -1)
515 return (retval);
516
517 if (n_names == 0) {
518 SDDS_SetError("Unable to process column selection--no names in call (SDDS_SetColumnsOfInterest)");
519 return (0);
520 }
521 if (!SDDS_dataset->column_order) {
522 SDDS_SetError("Unable to process column selection--'column_order' array in SDDS_DATASET is NULL (SDDS_SetColumnsOfInterest)");
523 return (0);
524 }
525
526 if (mode != SDDS_MATCH_STRING) {
527 for (i = 0; i < n_names; i++) {
528 if ((index = SDDS_GetColumnIndex(SDDS_dataset, name[i])) < 0) {
529 sprintf(buffer, "Unable to process column selection--unrecognized column name %s seen (SDDS_SetColumnsOfInterest)", name[i]);
530 SDDS_SetError(buffer);
531 return (0);
532 }
533 for (j = 0; j < SDDS_dataset->n_of_interest; j++)
534 if (index == SDDS_dataset->column_order[j])
535 break;
536 if (j == SDDS_dataset->n_of_interest) {
537 SDDS_dataset->column_flag[index] = 1;
538 SDDS_dataset->column_order[j] = index;
539 SDDS_dataset->n_of_interest++;
540 }
541 }
542 } else {
543 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
544 if (SDDS_Logic(SDDS_dataset->column_flag[i], wild_match(SDDS_dataset->layout.column_definition[i].name, match_string), logic)) {
545#if defined(DEBUG)
546 fprintf(stderr, "logic match of %s to %s\n", SDDS_dataset->layout.column_definition[i].name, match_string);
547#endif
548 for (j = 0; j < SDDS_dataset->n_of_interest; j++)
549 if (i == SDDS_dataset->column_order[j])
550 break;
551 if (j == SDDS_dataset->n_of_interest) {
552 SDDS_dataset->column_flag[i] = 1;
553 SDDS_dataset->column_order[j] = i;
554 SDDS_dataset->n_of_interest++;
555 }
556 } else {
557#if defined(DEBUG)
558 fprintf(stderr, "no logic match of %s to %s\n", SDDS_dataset->layout.column_definition[i].name, match_string);
559#endif
560 SDDS_dataset->column_flag[i] = 0;
561 for (j = 0; j < SDDS_dataset->n_of_interest; j++)
562 if (i == SDDS_dataset->column_order[j])
563 break;
564 if (j != SDDS_dataset->n_of_interest) {
565 for (j++; j < SDDS_dataset->n_of_interest; j++)
566 SDDS_dataset->column_order[j - 1] = SDDS_dataset->column_order[j];
567 }
568 }
569 }
570 free(match_string);
571 }
572
573#if defined(DEBUG)
574 for (i = 0; i < SDDS_dataset->n_of_interest; i++)
575 fprintf(stderr, "column %" PRId32 " will be %s\n", i, SDDS_dataset->layout.column_definition[SDDS_dataset->column_order[i]].name);
576#endif
577
578 if (local_memory == 2) {
579 for (i = 0; i < n_names; i++)
580 free(name[i]);
581 }
582 if (local_memory >= 1)
583 free(name);
584
585 return (1);
586}
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_SetColumnUnitsConversion()

int32_t SDDS_SetColumnUnitsConversion ( SDDS_DATASET * SDDS_dataset,
char * column_name,
char * new_units,
char * old_units,
double factor )

Sets unit conversions for a specified column in an SDDS dataset.

This function updates the units of the specified column within the SDDS dataset and applies a conversion factor to all its elements if the dataset has already been read (i.e., pages_read > 0). The function ensures that the new units are consistent with the old units if provided.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
column_nameA null-terminated string specifying the name of the column to update.
new_unitsA null-terminated string specifying the new units to assign to the column. This parameter must not be NULL.
old_unitsA null-terminated string specifying the expected current units of the column. If NULL, the function does not verify the existing units.
factorA double representing the conversion factor to apply to each element of the column. Each element will be multiplied by this factor.
Returns
Returns 1 on successful unit conversion and update. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the unit conversion was successfully applied.
0Indicates that an error occurred (e.g., invalid dataset, unrecognized column name, type undefined, memory allocation failure).
Note
  • The new_units parameter must not be NULL. Passing NULL will result in an error.
  • If the dataset has not been read yet (pages_read == 0), the conversion factor is stored but not applied immediately.
  • The function handles various data types, ensuring that the conversion factor is appropriately applied based on the column's type.
See also
SDDS_SetArrayUnitsConversion, SDDS_SetParameterUnitsConversion, SDDS_GetColumn

Definition at line 4788 of file SDDS_extract.c.

4788 {
4789 int32_t index, type;
4790 int64_t i;
4791 void *rawData;
4792 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetColumnUnitsConversion"))
4793 return(0);
4794 if (new_units == NULL) {
4795 SDDS_SetError("new_units is NULL (SDDS_SetColumnUnitsConversion)");
4796 return(0);
4797 }
4798 if ((index = SDDS_GetColumnIndex(SDDS_dataset, column_name)) < 0) {
4799 SDDS_SetError("Unable to get column--name is not recognized (SDDS_SetColumnUnitsConversion)");
4800 return(0);
4801 }
4802 if (!(type = SDDS_GetColumnType(SDDS_dataset, index))) {
4803 SDDS_SetError("Unable to get column--data type undefined (SDDS_SetColumnUnitsConversion)");
4804 return(0);
4805 }
4806 if (SDDS_dataset->layout.column_definition[index].units != NULL) {
4807 if (strcmp(new_units, SDDS_dataset->layout.column_definition[index].units) != 0) {
4808 if ((old_units != NULL) && (strcmp(old_units, SDDS_dataset->layout.column_definition[index].units) != 0)) {
4809 SDDS_SetError("Unexpected units value found (SDDS_SetColumnUnitsConversion)");
4810 return(0);
4811 }
4812 free(SDDS_dataset->layout.column_definition[index].units);
4813 cp_str(&(SDDS_dataset->original_layout.column_definition[index].units), new_units);
4814 cp_str(&(SDDS_dataset->layout.column_definition[index].units), new_units);
4815 }
4816 } else {
4817 cp_str(&(SDDS_dataset->original_layout.column_definition[index].units), new_units);
4818 cp_str(&(SDDS_dataset->layout.column_definition[index].units), new_units);
4819 }
4820
4821 if (SDDS_dataset->pages_read == 0) {
4822 return(1);
4823 }
4824 rawData = SDDS_dataset->data[index];
4825 switch (type) {
4826 case SDDS_LONGDOUBLE:
4827 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4828 ((long double *)rawData)[i] *= factor;
4829 }
4830 break;
4831 case SDDS_DOUBLE:
4832 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4833 ((double *)rawData)[i] *= factor;
4834 }
4835 break;
4836 case SDDS_FLOAT:
4837 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4838 ((float *)rawData)[i] *= factor;
4839 }
4840 break;
4841 case SDDS_LONG:
4842 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4843 ((int32_t *)rawData)[i] *= factor;
4844 }
4845 break;
4846 case SDDS_ULONG:
4847 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4848 ((uint32_t *)rawData)[i] *= factor;
4849 }
4850 break;
4851 case SDDS_LONG64:
4852 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4853 ((int64_t *)rawData)[i] *= factor;
4854 }
4855 break;
4856 case SDDS_ULONG64:
4857 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4858 ((uint64_t *)rawData)[i] *= factor;
4859 }
4860 break;
4861 case SDDS_SHORT:
4862 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4863 ((short *)rawData)[i] *= factor;
4864 }
4865 break;
4866 case SDDS_USHORT:
4867 for (i = 0; i < SDDS_dataset->n_rows; i++) {
4868 ((unsigned short *)rawData)[i] *= factor;
4869 }
4870 break;
4871 }
4872 return(1);
4873}

◆ SDDS_SetParameterUnitsConversion()

int32_t SDDS_SetParameterUnitsConversion ( SDDS_DATASET * SDDS_dataset,
char * parameter_name,
char * new_units,
char * old_units,
double factor )

Sets unit conversions for a specified parameter in an SDDS dataset.

This function updates the units of the specified parameter within the SDDS dataset and applies a conversion factor to its value if the dataset has already been read (i.e., pages_read > 0). The function ensures that the new units are consistent with the old units if provided.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
parameter_nameA null-terminated string specifying the name of the parameter to update.
new_unitsA null-terminated string specifying the new units to assign to the parameter. This parameter must not be NULL.
old_unitsA null-terminated string specifying the expected current units of the parameter. If NULL, the function does not verify the existing units.
factorA double representing the conversion factor to apply to the parameter's value. The parameter's value will be multiplied by this factor.
Returns
Returns 1 on successful unit conversion and update. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the unit conversion was successfully applied.
0Indicates that an error occurred (e.g., invalid dataset, unrecognized parameter name, type undefined, memory allocation failure).
Note
  • The new_units parameter must not be NULL. Passing NULL will result in an error.
  • If the dataset has not been read yet (pages_read == 0), the conversion factor is stored but not applied immediately.
  • The function handles various data types, ensuring that the conversion factor is appropriately applied based on the parameter's type.
See also
SDDS_SetArrayUnitsConversion, SDDS_SetColumnUnitsConversion, SDDS_GetParameter

Definition at line 4903 of file SDDS_extract.c.

4903 {
4904 int32_t index, type;
4905 void *rawData;
4906 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetParameterUnitsConversion"))
4907 return(0);
4908 if (new_units == NULL) {
4909 SDDS_SetError("new_units is NULL (SDDS_SetParameterUnitsConversion)");
4910 return(0);
4911 }
4912 if ((index = SDDS_GetParameterIndex(SDDS_dataset, parameter_name)) < 0) {
4913 SDDS_SetError("Unable to get parameter--name is not recognized (SDDS_SetParameterUnitsConversion)");
4914 return(0);
4915 }
4916 if (!(type = SDDS_GetParameterType(SDDS_dataset, index))) {
4917 SDDS_SetError("Unable to get parameter--data type undefined (SDDS_SetParameterUnitsConversion)");
4918 return(0);
4919 }
4920 if (SDDS_dataset->layout.parameter_definition[index].units != NULL) {
4921 if (strcmp(new_units, SDDS_dataset->layout.parameter_definition[index].units) != 0) {
4922 if ((old_units != NULL) && (strcmp(old_units, SDDS_dataset->layout.parameter_definition[index].units) != 0)) {
4923 SDDS_SetError("Unexpected units value found (SDDS_SetParameterUnitsConversion)");
4924 return(0);
4925 }
4926 /* free(SDDS_dataset->layout.parameter_definition[index].units); */
4927 cp_str(&(SDDS_dataset->layout.parameter_definition[index].units), new_units);
4928 }
4929 } else {
4930 cp_str(&(SDDS_dataset->layout.parameter_definition[index].units), new_units);
4931 }
4932
4933 if (SDDS_dataset->pages_read == 0) {
4934 return(1);
4935 }
4936 rawData = SDDS_dataset->parameter[index];
4937 switch (type) {
4938 case SDDS_LONGDOUBLE:
4939 *((long double *)rawData) *= factor;
4940 break;
4941 case SDDS_DOUBLE:
4942 *((double *)rawData) *= factor;
4943 break;
4944 case SDDS_FLOAT:
4945 *((float *)rawData) *= factor;
4946 break;
4947 case SDDS_LONG:
4948 *((int32_t *)rawData) *= factor;
4949 break;
4950 case SDDS_ULONG:
4951 *((uint32_t *)rawData) *= factor;
4952 break;
4953 case SDDS_LONG64:
4954 *((int64_t *)rawData) *= factor;
4955 break;
4956 case SDDS_ULONG64:
4957 *((uint64_t *)rawData) *= factor;
4958 break;
4959 case SDDS_SHORT:
4960 *((short *)rawData) *= factor;
4961 break;
4962 case SDDS_USHORT:
4963 *((unsigned short *)rawData) *= factor;
4964 break;
4965 }
4966 return(1);
4967}

◆ SDDS_SetRowFlags()

int32_t SDDS_SetRowFlags ( SDDS_DATASET * SDDS_dataset,
int32_t row_flag_value )

Sets the acceptance flags for all rows in the current data table of a data set.

This function initializes the acceptance flags for each row in the data table. A non-zero flag indicates that the row is "of interest" and should be considered in subsequent operations, while a zero flag marks the row for rejection.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the data set.
row_flag_valueInteger value to assign to all row flags.
  • Non-zero value: Marks rows as accepted ("of interest").
  • Zero value: Marks rows as rejected.
Returns
  • 1 on successful update of row flags.
  • 0 on failure, with an error message recorded.
Note
This function overwrites any existing row flags with the specified row_flag_value.
See also
SDDS_GetRowFlag, SDDS_GetRowFlags

Definition at line 46 of file SDDS_extract.c.

46 {
47 /* int32_t i; */
48 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowFlags"))
49 return (0);
50 if (!SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated, SDDS_LONG, (int32_t)row_flag_value, (int32_t)0)) {
51 SDDS_SetError("Unable to set row flags--memory filling failed (SDDS_SetRowFlags)");
52 return (0);
53 }
54 return (1);
55}

◆ SDDS_SetRowsOfInterest()

int64_t SDDS_SetRowsOfInterest ( SDDS_DATASET * SDDS_dataset,
char * selection_column,
int32_t mode,
... )

Sets the rows of interest in an SDDS dataset based on various selection criteria.

This function marks rows in the provided SDDS dataset as "of interest" based on the specified selection criteria. It supports multiple selection modes, allowing users to specify rows by an array of names, a single string containing multiple names, a variadic list of names, or by matching a specific string with logical operations.

Calling Modes:

  • SDDS_NAME_ARRAY: Specify an array of names.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_NAME_ARRAY, int32_t n_entries, char **name);
    int64_t SDDS_SetRowsOfInterest(SDDS_DATASET *SDDS_dataset, char *selection_column, int32_t mode,...)
    Sets the rows of interest in an SDDS dataset based on various selection criteria.
  • SDDS_NAMES_STRING: Provide a single string containing multiple names separated by delimiters.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_NAMES_STRING, char *names);
  • SDDS_NAME_STRINGS: Pass multiple name strings, terminated by NULL.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_NAME_STRINGS, char *name1, char *name2, ..., NULL);
  • SDDS_MATCH_STRING: Match rows based on a single string and logical operations.
    SDDS_SetRowsOfInterest(&SDDS_dataset, selection_column, SDDS_MATCH_STRING, char *name, int32_t logic_mode);

Additionally, each of these modes has a case-insensitive variant prefixed with SDDS_CI_ (e.g., SDDS_CI_NAME_ARRAY).

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
selection_columnA null-terminated string specifying the name of the column used for row selection. This column must be of string type.
modeAn integer representing the selection mode. Supported modes include:
  • SDDS_NAME_ARRAY
  • SDDS_NAMES_STRING
  • SDDS_NAME_STRINGS
  • SDDS_MATCH_STRING
  • SDDS_CI_NAME_ARRAY
  • SDDS_CI_NAMES_STRING
  • SDDS_CI_NAME_STRINGS
  • SDDS_CI_MATCH_STRING
...Variable arguments corresponding to the selected mode:
  • SDDS_NAME_ARRAY and SDDS_CI_NAME_ARRAY:
    • int32_t n_entries: Number of names.
    • char **name: Array of name strings.
  • SDDS_NAMES_STRING and SDDS_CI_NAMES_STRING:
    • char *names: Single string containing multiple names separated by delimiters.
  • SDDS_NAME_STRINGS and SDDS_CI_NAME_STRINGS:
    • char *name1, char *name2, ..., NULL: Multiple name strings terminated by NULL.
  • SDDS_MATCH_STRING and SDDS_CI_MATCH_STRING:
    • char *name: String to match.
    • int32_t logic_mode: Logical operation mode.
Returns
On success, returns the number of rows marked as "of interest". On failure, returns -1 and sets an appropriate error message.
Return values
-1Indicates that an error occurred (e.g., invalid dataset, unrecognized selection column, memory allocation failure, unknown mode).
Non-negativeInteger representing the count of rows marked as "of interest".
Note
  • The caller must ensure that the selection_column exists and is of string type in the dataset.
  • For modes that allocate memory internally (e.g., SDDS_NAMES_STRING), the function handles memory management internally.
See also
SDDS_MatchRowsOfInterest, SDDS_FilterRowsOfInterest, SDDS_DeleteUnsetRows

Definition at line 3324 of file SDDS_extract.c.

3331{
3332 va_list argptr;
3333 int32_t retval, type, index, n_names;
3334 int64_t i, j;
3335 char **name, *string, *match_string, *ptr;
3336 int32_t local_memory; /* (0,1,2) --> (none, pointer array, pointer array + strings) locally allocated */
3337 char buffer[SDDS_MAXLINE];
3338 int32_t logic, caseSensitive;
3339 int64_t count;
3340
3341 name = NULL;
3342 n_names = local_memory = logic = 0;
3343
3344 if (!SDDS_CheckDataset(SDDS_dataset, "SDDS_SetRowsOfInterest"))
3345 return (-1);
3346 va_start(argptr, mode);
3347 retval = 1;
3348 caseSensitive = 1;
3349 match_string = NULL;
3350 switch (mode) {
3351 case SDDS_CI_NAME_ARRAY:
3352 caseSensitive = 0;
3353 case SDDS_NAME_ARRAY:
3354 local_memory = 0;
3355 n_names = va_arg(argptr, int32_t);
3356 name = va_arg(argptr, char **);
3357 break;
3358 case SDDS_CI_NAMES_STRING:
3359 caseSensitive = 0;
3360 case SDDS_NAMES_STRING:
3361 local_memory = 2;
3362 n_names = 0;
3363 name = NULL;
3364 ptr = va_arg(argptr, char *);
3365 SDDS_CopyString(&string, ptr);
3366 while (SDDS_GetToken(string, buffer, SDDS_MAXLINE) > 0) {
3367 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1))) || !SDDS_CopyString(name + n_names, buffer)) {
3368 SDDS_SetError("Unable to process row selection--memory allocation failure (SDDS_SetRowsOfInterest)");
3369 retval = -1;
3370 break;
3371 }
3372 n_names++;
3373 }
3374 free(string);
3375 break;
3376 case SDDS_CI_NAME_STRINGS:
3377 caseSensitive = 0;
3378 case SDDS_NAME_STRINGS:
3379 local_memory = 1;
3380 n_names = 0;
3381 name = NULL;
3382 while ((string = va_arg(argptr, char *))) {
3383 if (!(name = SDDS_Realloc(name, sizeof(*name) * (n_names + 1)))) {
3384 SDDS_SetError("Unable to process row selection--memory allocation failure (SDDS_SetRowsOfInterest)");
3385 retval = -1;
3386 break;
3387 }
3388 name[n_names++] = string;
3389 }
3390 break;
3391 case SDDS_CI_MATCH_STRING:
3392 caseSensitive = 0;
3393 case SDDS_MATCH_STRING:
3394 local_memory = 0;
3395 n_names = 1;
3396 if ((string = va_arg(argptr, char *)))
3397 match_string = expand_ranges(string);
3398 logic = va_arg(argptr, int32_t);
3399 if (logic & SDDS_NOCASE_COMPARE)
3400 caseSensitive = 0;
3401 break;
3402 default:
3403 SDDS_SetError("Unable to process row selection--unknown mode (SDDS_SetRowsOfInterest)");
3404 retval = -1;
3405 break;
3406 }
3407
3408 va_end(argptr);
3409 if (retval != 1)
3410 return (-1);
3411
3412 if (mode != SDDS_MATCH_STRING && mode != SDDS_CI_MATCH_STRING) {
3413 int (*stringCompare)(const char *s1, const char *s2);
3414 if (caseSensitive)
3415 stringCompare = strcmp;
3416 else
3417 stringCompare = strcmp_ci;
3418 if ((index = SDDS_GetColumnIndex(SDDS_dataset, selection_column)) < 0) {
3419 SDDS_SetError("Unable to process row selection--unrecognized selection column name (SDDS_SetRowsOfInterest)");
3420 return (-1);
3421 }
3422 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) != SDDS_STRING) {
3423 SDDS_SetError("Unable to select rows--selection column is not string type (SDDS_SetRowsOfInterest)");
3424 return (-1);
3425 }
3426 if (n_names == 0) {
3427 SDDS_SetError("Unable to process row selection--no names in call (SDDS_SetRowsOfInterest)");
3428 return (-1);
3429 }
3430 for (j = 0; j < n_names; j++) {
3431 for (i = 0; i < SDDS_dataset->n_rows; i++) {
3432 if ((*stringCompare)(*((char **)SDDS_dataset->data[index] + i), name[j]) == 0)
3433 SDDS_dataset->row_flag[i] = 1;
3434 }
3435 }
3436 } else {
3437 if (selection_column) {
3438 int (*wildMatch)(char *string, char *template);
3439 if (caseSensitive)
3440 wildMatch = wild_match;
3441 else
3442 wildMatch = wild_match_ci;
3443 if (!match_string) {
3444 SDDS_SetError("Unable to select rows--no matching string given (SDDS_SetRowsOfInterest)");
3445 return (-1);
3446 }
3447 if ((index = SDDS_GetColumnIndex(SDDS_dataset, selection_column)) < 0) {
3448 free(match_string);
3449 SDDS_SetError("Unable to process row selection--unrecognized selection column name (SDDS_SetRowsOfInterest)");
3450 return (-1);
3451 }
3452 if ((type = SDDS_GetColumnType(SDDS_dataset, index)) != SDDS_STRING) {
3453 free(match_string);
3454 SDDS_SetError("Unable to select rows--selection column is not string type (SDDS_SetRowsOfInterest)");
3455 return (-1);
3456 }
3457 for (i = 0; i < SDDS_dataset->n_rows; i++)
3458 SDDS_dataset->row_flag[i] = SDDS_Logic(SDDS_dataset->row_flag[i], (*wildMatch)(*((char **)SDDS_dataset->data[index] + i), match_string), logic);
3459 } else {
3460 for (i = 0; i < SDDS_dataset->n_rows; i++)
3461 SDDS_dataset->row_flag[i] = SDDS_Logic(SDDS_dataset->row_flag[i], 0, logic & ~(SDDS_AND | SDDS_OR));
3462 }
3463 }
3464
3465 if (local_memory == 2) {
3466 for (i = 0; i < n_names; i++)
3467 free(name[i]);
3468 }
3469 if (match_string)
3470 free(match_string);
3471 if (local_memory >= 1)
3472 free(name);
3473
3474 for (i = count = 0; i < SDDS_dataset->n_rows; i++)
3475 if (SDDS_dataset->row_flag[i])
3476 count++;
3477 return (count);
3478}

◆ SDDS_TransferRow()

int32_t SDDS_TransferRow ( SDDS_DATASET * SDDS_dataset,
int64_t target,
int64_t source )

Transfers data from a source row to a target row within an SDDS dataset.

This function copies all column data from the specified source row to the target row in the provided SDDS dataset. It handles both string and non-string data types appropriately, ensuring that memory is managed correctly for string entries.

Parameters
SDDS_datasetPointer to the SDDS_DATASET structure representing the dataset.
targetThe index of the target row where data will be copied to.
sourceThe index of the source row from which data will be copied.
Returns
On success, returns 1. On failure, returns 0 and sets an appropriate error message.
Return values
1Indicates that the row transfer was successful.
0Indicates that an error occurred (e.g., invalid dataset, out-of-range indices, memory allocation failure, string copy failure).
Note
  • Both target and source must be valid row indices within the dataset.
  • The function does not allocate or deallocate rows; it only copies data between existing rows.
See also
SDDS_DeleteUnsetRows, SDDS_CopyColumn

Definition at line 3802 of file SDDS_extract.c.

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