26#include "mdb_thread.h"
33int lockf(
int filedes,
int function, off_t size);
67int32_t
SDDS_PrintTypedValue(
void *data, int64_t index, int32_t type,
char *format, FILE *fp, uint32_t mode) {
68 char buffer[SDDS_PRINT_BUFLEN], *s;
71 SDDS_SetError(
"Unable to print value--data pointer is NULL (SDDS_PrintTypedValue)");
75 SDDS_SetError(
"Unable to print value--file pointer is NULL (SDDS_PrintTypedValue)");
80 fprintf(fp, format ? format :
"%hd", *((
short *)data + index));
83 fprintf(fp, format ? format :
"%hu", *((
unsigned short *)data + index));
86 fprintf(fp, format ? format :
"%" PRId32, *((int32_t *)data + index));
89 fprintf(fp, format ? format :
"%" PRIu32, *((uint32_t *)data + index));
92 fprintf(fp, format ? format :
"%" PRId64, *((int64_t *)data + index));
95 fprintf(fp, format ? format :
"%" PRIu64, *((uint64_t *)data + index));
98 fprintf(fp, format ? format :
"%15.8e", *((
float *)data + index));
101 fprintf(fp, format ? format :
"%21.15e", *((
double *)data + index));
104 if (LDBL_DIG == 18) {
105 fprintf(fp, format ? format :
"%21.18Le", *((
long double *)data + index));
107 fprintf(fp, format ? format :
"%21.15Le", *((
long double *)data + index));
111 s = *((
char **)data + index);
112 if ((int32_t)strlen(s) > SDDS_PRINT_BUFLEN - 3) {
113 SDDS_SetError(
"Buffer size overflow (SDDS_PrintTypedValue)");
120 fprintf(fp, format ? format :
"%c", *((
char *)data + index));
123 SDDS_SetError(
"Unable to print value--unknown data type (SDDS_PrintTypedValue)");
161int32_t
SDDS_SprintTypedValue(
void *data, int64_t index, int32_t type,
const char *format,
char *buffer, uint32_t mode) {
197 char buffer2[SDDS_PRINT_BUFLEN], *s;
201 SDDS_SetError(
"Unable to print value--data pointer is NULL (SDDS_SprintTypedValueFactor)");
205 SDDS_SetError(
"Unable to print value--buffer pointer is NULL (SDDS_SprintTypedValueFactor)");
210 sprintf(buffer, format ? format :
"%hd", (
short)(*((
short *)data + index) * (factor)));
213 sprintf(buffer, format ? format :
"%hu", (
unsigned short)(*((
unsigned short *)data + index) * (factor)));
216 sprintf(buffer, format ? format :
"%" PRId32, (int32_t)(*((int32_t *)data + index) * (factor)));
219 sprintf(buffer, format ? format :
"%" PRIu32, (uint32_t)(*((uint32_t *)data + index) * (factor)));
222 sprintf(buffer, format ? format :
"%" PRId64, (int64_t)(*((int64_t *)data + index) * (factor)));
225 sprintf(buffer, format ? format :
"%" PRIu64, (uint64_t)(*((uint64_t *)data + index) * (factor)));
228 sprintf(buffer, format ? format :
"%15.8e", (
float)(*((
float *)data + index) * (factor)));
231 sprintf(buffer, format ? format :
"%21.15e", (
double)(*((
double *)data + index) * (factor)));
234 if (LDBL_DIG == 18) {
235 sprintf(buffer, format ? format :
"%21.18Le", (
long double)(*((
long double *)data + index) * (factor)));
237 sprintf(buffer, format ? format :
"%21.15Le", (
long double)(*((
long double *)data + index) * (factor)));
241 s = *((
char **)data + index);
242 if ((int32_t)strlen(s) > SDDS_PRINT_BUFLEN - 3) {
243 SDDS_SetError(
"Buffer size overflow (SDDS_SprintTypedValue)");
246 if (!(mode & SDDS_PRINT_NOQUOTES)) {
249 sprintf(buffer,
"\"\"");
250 else if (strchr(s,
'"')) {
254 sprintf(buffer,
"\"%s\"", buffer2);
256 strcpy(buffer, buffer2);
258 sprintf(buffer,
"\"%s\"", s);
260 sprintf(buffer, format ? format :
"%s", s);
264 sprintf(buffer2, format ? format :
"%s", buffer);
265 strcpy(buffer, buffer2);
268 sprintf(buffer, format ? format :
"%s", s);
272 sprintf(buffer, format ? format :
"%c", *((
char *)data + index));
275 SDDS_SetError(
"Unable to print value--unknown data type (SDDS_SprintTypedValue)");
281static MDB_THREAD_LOCAL int32_t n_errors = 0;
282static MDB_THREAD_LOCAL int32_t n_errors_max = 0;
283static MDB_THREAD_LOCAL
char **error_description = NULL;
284static MDB_THREAD_LOCK registeredProgramNameLock = MDB_THREAD_LOCK_INITIALIZER;
285static char *registeredProgramName = NULL;
287static char *SDDS_DuplicateProgramName(
const char *name) {
291 if (!(copy = malloc(strlen(name) + 1)))
297static char *SDDS_GetRegisteredProgramNameCopy(
void) {
299 mdb_thread_lock(®isteredProgramNameLock);
300 if (registeredProgramName)
301 copy = SDDS_DuplicateProgramName(registeredProgramName);
302 mdb_thread_unlock(®isteredProgramNameLock);
319 char *newProgramName = NULL;
322 if (!(newProgramName = SDDS_DuplicateProgramName(name)))
325 mdb_thread_lock(®isteredProgramNameLock);
326 free(registeredProgramName);
327 registeredProgramName = newProgramName;
328 mdb_thread_unlock(®isteredProgramNameLock);
356 if (error_description) {
357 for (i=0; i<n_errors; i++) {
358 free(error_description[i]);
359 error_description[i] = NULL;
362 free(error_description);
363 error_description = NULL;
381 char *programName = SDDS_GetRegisteredProgramNameCopy();
383 fprintf(stderr,
"Error (%s): %s\n", programName, message ? message :
"?");
385 fprintf(stderr,
"Error: %s\n", message ? message :
"?");
403 char *programName = SDDS_GetRegisteredProgramNameCopy();
405 fprintf(stderr,
"Warning (%s): %s\n", programName, message ? message :
"?");
407 fprintf(stderr,
"Warning: %s\n", message ? message :
"?");
438 if (n_errors >= n_errors_max) {
439 if (!(error_description =
SDDS_Realloc(error_description, (n_errors_max += 10) *
sizeof(*error_description)))) {
440 fputs(
"Error trying to allocate additional error description string (SDDS_SetError)\n", stderr);
441 fprintf(stderr,
"Most recent error text:\n%s\n", error_text);
446 fprintf(stderr,
"warning: error text is NULL (SDDS_SetError)\n");
449 fputs(
"Error trying to copy additional error description text (SDDS_SetError)\n", stderr);
450 fprintf(stderr,
"Most recent error text: %s\n", error_text);
484 if (mode & SDDS_VERBOSE_PrintErrors)
488 programName = SDDS_GetRegisteredProgramNameCopy();
490 fprintf(fp,
"Error for %s:\n", programName);
492 fputs(
"Error:\n", fp);
494 if (!error_description)
495 fprintf(stderr,
"warning: internal error: error_description pointer is unexpectedly NULL\n");
497 for (i = 0; i < depth; i++) {
498 if (!error_description[i])
499 fprintf(stderr,
"warning: internal error: error_description[%" PRId32
"] is unexpectedly NULL\n", i);
501 fprintf(fp,
"%s", error_description[i]);
505 if (mode & SDDS_EXIT_PrintErrors)
537 if (mode & SDDS_ALL_GetErrorMessages)
541 if (!(message = (
char **)
SDDS_Malloc(
sizeof(*message) * depth)))
543 for (i = 0; i < depth; i++)
545 if (!error_description) {
546 fprintf(stderr,
"warning: internal error: error_description pointer is unexpectedly NULL (SDDS_GetErrorMessages)\n");
550 for (i = depth - 1; i >= 0; i--) {
551 if (!error_description[i]) {
552 fprintf(stderr,
"internal error: error_description[%" PRId32
"] is unexpectedly NULL (SDDS_GetErrorMessages)\n", i);
553 for (j = 0; j < depth; j++)
559 fprintf(stderr,
"unable to copy error message text (SDDS_GetErrorMessages)\n");
560 for (j = 0; j < depth; j++)
572static MDB_THREAD_LOCK AutoCheckModeLock = MDB_THREAD_LOCK_INITIALIZER;
573static uint32_t AutoCheckMode = 0x0000UL;
575static uint32_t SDDS_GetLockedAutoCheckMode(
void) {
577 mdb_thread_lock(&AutoCheckModeLock);
578 mode = AutoCheckMode;
579 mdb_thread_unlock(&AutoCheckModeLock);
599 mdb_thread_lock(&AutoCheckModeLock);
600 oldMode = AutoCheckMode;
601 AutoCheckMode = newMode;
602 mdb_thread_unlock(&AutoCheckModeLock);
621 sprintf(buffer,
"NULL SDDS_DATASET pointer passed to %s", caller);
646 if (!(SDDS_GetLockedAutoCheckMode() & TABULAR_DATA_CHECKS))
648 if (SDDS_dataset->layout.n_columns && (!SDDS_dataset->row_flag || !SDDS_dataset->data)) {
649 sprintf(buffer,
"tabular data is invalid in %s (columns but no row flags or data array)", caller);
653 if (SDDS_dataset->layout.n_columns == 0 && SDDS_dataset->n_rows) {
654 sprintf(buffer,
"tabular data is invalid in %s (no columns present but nonzero row count)", caller);
658 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
659 if (!SDDS_dataset->data[i]) {
660 sprintf(buffer,
"tabular data is invalid in %s (null data pointer for column %" PRId64
")", caller, i);
688 return calloc(nelem, elem_size);
753 return (realloc(old_ptr, new_size));
783 new_ptr = calloc(new_size, 1);
785 new_ptr = realloc(old_ptr, new_size);
786 memset((
char *)new_ptr + old_size, 0, new_size - old_size);
822 if ((percent = strchr(s,
'%'))) {
823 if (*(percent + 1) !=
'%')
828 if (!percent || !*++percent)
837 if ((len = strcspn(s,
"fegEG")) == strlen(s))
841 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
846 if ((len = strcspn(s,
"d")) == strlen(s))
852 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
857 if ((len = strcspn(s,
"u")) == strlen(s))
863 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
867 if ((len = strcspn(s,
"d")) == strlen(s))
869 if (*(s + len - 1) !=
'h')
873 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
877 if ((len = strcspn(s,
"u")) == strlen(s))
879 if (*(s + len - 1) !=
'h')
883 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
887 if ((len = strcspn(s,
"s")) == strlen(s))
891 if ((tmp = strspn(s,
"-0123456789")) < len)
895 if ((len = strcspn(s,
"c")) == strlen(s))
926 if (!(*target =
SDDS_Malloc(
sizeof(**target) * (strlen(source) + 1))))
928 strcpy(*target, source);
955 SDDS_SetError(
"Unable to get associate definition--name is NULL (SDDS_GetAssociateDefinition)");
958 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
959 if (strcmp(SDDS_dataset->layout.associate_definition[i].name, name) == 0) {
961 SDDS_SetError(
"Unable to get associate definition--copy failure (SDDS_GetAssociateDefinition)");
988 return (*target = NULL);
992 (*target)->sdds = source->sdds;
1014 if (!source->filename)
1016 free(source->filename);
1019 if (source->description)
1020 free(source->description);
1021 if (source->contents)
1022 free(source->contents);
1050 SDDS_SetError(
"Unable to get column definition--name is NULL (SDDS_GetColumnDefinition)");
1056 SDDS_SetError(
"Unable to get column definition--copy failure (SDDS_GetColumnDefinition)");
1082 return (*target = NULL);
1087 (*target)->type = source->type;
1088 (*target)->field_length = source->field_length;
1089 (*target)->definition_mode = source->definition_mode;
1090 (*target)->memory_number = source->memory_number;
1109 if (!source || !source->name)
1113 free(source->symbol);
1115 free(source->units);
1116 if (source->description)
1117 free(source->description);
1118 if (source->format_string)
1119 free(source->format_string);
1147 SDDS_SetError(
"Unable to get parameter definition--name is NULL (SDDS_GetParameterDefinition)");
1153 SDDS_SetError(
"Unable to get parameter definition--copy failure (SDDS_GetParameterDefinition)");
1179 return (*target = NULL);
1185 (*target)->type = source->type;
1186 (*target)->definition_mode = source->definition_mode;
1187 (*target)->memory_number = source->memory_number;
1206 if (!source || !source->name)
1210 free(source->symbol);
1212 free(source->units);
1213 if (source->description)
1214 free(source->description);
1215 if (source->format_string)
1216 free(source->format_string);
1217 if (source->fixed_value)
1218 free(source->fixed_value);
1246 SDDS_SetError(
"Unable to get array definition--name is NULL (SDDS_GetArrayDefinition)");
1252 SDDS_SetError(
"Unable to get array definition--copy failure (SDDS_GetArrayDefinition)");
1278 return (*target = NULL);
1284 (*target)->type = source->type;
1285 (*target)->field_length = source->field_length;
1286 (*target)->dimensions = source->dimensions;
1310 free(source->symbol);
1312 free(source->units);
1313 if (source->description)
1314 free(source->description);
1315 if (source->format_string)
1316 free(source->format_string);
1317 if (source->group_name)
1318 free(source->group_name);
1382 SDDS_SetError(
"Unable to get column index--name is NULL (SDDS_GetColumnIndex)");
1388 return SDDS_dataset->layout.column_index[i]->index;
1411 SDDS_SetError(
"Unable to get parameter index--name is NULL (SDDS_GetParameterIndex)");
1417 return SDDS_dataset->layout.parameter_index[i]->index;
1440 SDDS_SetError(
"Unable to get array index--name is NULL (SDDS_GetArrayIndex)");
1446 return SDDS_dataset->layout.array_index[i]->index;
1467 SDDS_SetError(
"Unable to get associate index--name is NULL (SDDS_GetAssociateIndex)");
1470 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
1471 if (strcmp(SDDS_dataset->layout.associate_definition[i].name, name) == 0)
1492 if (isspace(*
string))
1518 while (fgets(s, slen, fp)) {
1519 if (s[0] != skip_char) {
1522 }
else if (s[1] ==
'#') {
1549 int32_t spaceLeft, length, newLine;
1550 char *sInsert, *fgetsReturn;
1555 while ((fgetsReturn = fgets(sInsert, spaceLeft, fp))) {
1556 if (newLine && sInsert[0] ==
'!')
1559 length = strlen(sInsert);
1560 if (sInsert[length - 1] !=
'\n' && !feof(fp)) {
1565 sInsert = *s + strlen(*s);
1595 while (lzma_gets(s, slen, lzmafp)) {
1596 if (s[0] != skip_char) {
1599 }
else if (s[1] ==
'#') {
1627 int32_t spaceLeft, length, newLine;
1628 char *sInsert, *fgetsReturn;
1633 while ((fgetsReturn = lzma_gets(sInsert, spaceLeft, lzmafp))) {
1634 if (newLine && sInsert[0] ==
'!')
1637 length = strlen(sInsert);
1638 if (sInsert[length - 1] !=
'\n' && !lzma_eof(lzmafp)) {
1643 sInsert = *s + strlen(*s);
1673char *fgetsGZipSkipComments(
SDDS_DATASET *SDDS_dataset,
char *s, int32_t slen, gzFile gzfp,
char skip_char ) {
1674 while (gzgets(gzfp, s, slen)) {
1675 if (s[0] != skip_char) {
1678 }
else if (s[1] ==
'#') {
1705char *fgetsGZipSkipCommentsResize(
SDDS_DATASET *SDDS_dataset,
char **s, int32_t *slen, gzFile gzfp,
char skip_char ) {
1706 int32_t spaceLeft, length, newLine;
1707 char *sInsert, *fgetsReturn;
1712 while ((fgetsReturn = gzgets(gzfp, sInsert, spaceLeft))) {
1713 if (newLine && sInsert[0] ==
'!')
1716 length = strlen(sInsert);
1717 if (sInsert[length - 1] !=
'\n' && !gzeof(gzfp)) {
1722 sInsert = *s + strlen(*s);
1747 int32_t length, hasNewline;
1755 if (s[length - 1] ==
'\n')
1760 if (*(s + 1) ==
'#')
1767 if ((*s ==
'"') && (s == s0 || *(s - 1) !=
'\\')) {
1768 while (*++s && (*s !=
'"' || *(s - 1) ==
'\\'))
1776 if (s != s0 && *(s - 1) ==
'\\')
1807 char *ptr0, *ptr1, *escptr, *temp;
1825 if (*s ==
'\\' && *(s + 1) ==
'\\') {
1830 }
while (*s && (*s !=
'"' || (*(s - 1) ==
'\\' && (s - 1) != escptr)));
1839 if (*s ==
'"' && *(s - 1) !=
'\\') {
1840 while (*++s && !(*s ==
'"' && *(s - 1) !=
'\\'))
1843 }
while (*s && !isspace(*s));
1846 if ((int32_t)(s - ptr1) >= buflen)
1848 strncpy(buffer, ptr1, s - ptr1);
1849 buffer[s - ptr1] = 0;
1852 temp = malloc(
sizeof(
char) * (strlen(s) + 1));
1858 return ((int32_t)(s - ptr1));
1878int32_t
SDDS_GetToken2(
char *s,
char **st, int32_t *strlength,
char *buffer, int32_t buflen) {
1879 char *ptr0, *ptr1, *escptr;
1897 if (*s ==
'\\' && *(s + 1) ==
'\\') {
1902 }
while (*s && (*s !=
'"' || (*(s - 1) ==
'\\' && (s - 1) != escptr)));
1911 if (*s ==
'"' && *(s - 1) !=
'\\') {
1912 while (*++s && !(*s ==
'"' && *(s - 1) !=
'\\'))
1915 }
while (*s && !isspace(*s));
1918 if ((int32_t)(s - ptr1) >= buflen)
1920 strncpy(buffer, ptr1, s - ptr1);
1921 buffer[s - ptr1] = 0;
1925 *strlength -= s - ptr0;
1928 return ((int32_t)(s - ptr1));
1947 if (!
string || (i = strlen(
string)) > length)
1969 char *buffer = NULL;
1972 buffer =
trealloc(buffer,
sizeof(*buffer) * (4 * (strlen(s) + 1)));
1976 if (*ptr == quote_char && (ptr == s || *(ptr - 1) !=
'\\'))
2002 if (*ptr == quote_char && ptr != s && *(ptr - 1) ==
'\\')
2003 strcpy(ptr - 1, ptr);
2025 if (*
string == cc && (
string == s0 || *(
string - 1) !=
'\\')) {
2026 ptr =
string + strlen(
string) + 1;
2027 while (ptr !=
string) {
2053 memset(mem, 0, n_bytes);
2111 short short_val, short_dval, *short_ptr;
2112 unsigned short ushort_val, ushort_dval, *ushort_ptr;
2113 int32_t long_val, long_dval, *long_ptr;
2114 uint32_t ulong_val, ulong_dval, *ulong_ptr;
2115 int64_t long64_val, long64_dval, *long64_ptr;
2116 uint64_t ulong64_val, ulong64_dval, *ulong64_ptr;
2117 float float_val, float_dval, *float_ptr;
2118 double double_val, double_dval, *double_ptr;
2119 long double longdouble_val, longdouble_dval, *longdouble_ptr;
2120 char char_val, *char_ptr;
2123 va_start(argptr, data_type);
2124 switch (data_type) {
2126 short_val = (short)va_arg(argptr,
int);
2127 short_dval = (short)va_arg(argptr,
int);
2128 short_ptr = (
short *)mem;
2129 for (i = 0; i < n_elements; i++, short_val += short_dval)
2130 *short_ptr++ = short_val;
2133 ushort_val = (
unsigned short)va_arg(argptr,
int);
2134 ushort_dval = (
unsigned short)va_arg(argptr,
int);
2135 ushort_ptr = (
unsigned short *)mem;
2136 for (i = 0; i < n_elements; i++, ushort_val += ushort_dval)
2137 *ushort_ptr++ = ushort_val;
2140 long_val = (int32_t)va_arg(argptr, int32_t);
2141 long_dval = (int32_t)va_arg(argptr, int32_t);
2142 long_ptr = (int32_t *)mem;
2143 for (i = 0; i < n_elements; i++, long_val += long_dval)
2144 *long_ptr++ = long_val;
2147 ulong_val = (uint32_t)va_arg(argptr, uint32_t);
2148 ulong_dval = (uint32_t)va_arg(argptr, uint32_t);
2149 ulong_ptr = (uint32_t *)mem;
2150 for (i = 0; i < n_elements; i++, ulong_val += ulong_dval)
2151 *ulong_ptr++ = ulong_val;
2154 long64_val = (int64_t)va_arg(argptr, int64_t);
2155 long64_dval = (int64_t)va_arg(argptr, int64_t);
2156 long64_ptr = (int64_t *)mem;
2157 for (i = 0; i < n_elements; i++, long64_val += long64_dval)
2158 *long64_ptr++ = long64_val;
2161 ulong64_val = (uint64_t)va_arg(argptr, uint32_t);
2162 ulong64_dval = (uint64_t)va_arg(argptr, uint32_t);
2163 ulong64_ptr = (uint64_t *)mem;
2164 for (i = 0; i < n_elements; i++, ulong64_val += ulong64_dval)
2165 *ulong64_ptr++ = ulong64_val;
2168 float_val = (float)va_arg(argptr,
double);
2169 float_dval = (float)va_arg(argptr,
double);
2170 float_ptr = (
float *)mem;
2171 for (i = 0; i < n_elements; i++, float_val += float_dval)
2172 *float_ptr++ = float_val;
2175 double_val = (double)va_arg(argptr,
double);
2176 double_dval = (double)va_arg(argptr,
double);
2177 double_ptr = (
double *)mem;
2178 for (i = 0; i < n_elements; i++, double_val += double_dval)
2179 *double_ptr++ = double_val;
2182 longdouble_val = (
long double)va_arg(argptr,
long double);
2183 longdouble_dval = (
long double)va_arg(argptr,
long double);
2184 longdouble_ptr = (
long double *)mem;
2185 for (i = 0; i < n_elements; i++, longdouble_val += longdouble_dval)
2186 *longdouble_ptr++ = longdouble_val;
2189 char_val = (char)va_arg(argptr,
int);
2190 short_dval = (short)va_arg(argptr,
int);
2191 char_ptr = (
char *)mem;
2192 for (i = 0; i < n_elements; i++, char_val += short_dval)
2193 *char_ptr++ = char_val;
2196 SDDS_SetError(
"Unable to set memory--unknown or invalid data type (SDDS_SetMemory)");
2222 if (index < 0 || index >= SDDS_dataset->layout.n_columns) {
2223 SDDS_SetError(
"Unable to get column type--column index is out of range (SDDS_GetColumnType)");
2226 return (SDDS_dataset->layout.column_definition[index].type);
2246 if ((index =
SDDS_GetColumnIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_columns) {
2247 SDDS_SetError(
"Unable to get column type--column index is out of range (SDDS_GetNamedColumnType)");
2250 return (SDDS_dataset->layout.column_definition[index].type);
2271 if (index < 0 || index >= SDDS_dataset->layout.n_arrays) {
2272 SDDS_SetError(
"Unable to get array type--array index is out of range (SDDS_GetArrayType)");
2275 return (SDDS_dataset->layout.array_definition[index].type);
2295 if ((index =
SDDS_GetArrayIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_arrays) {
2296 SDDS_SetError(
"Unable to get array type--array index is out of range (SDDS_GetNamedArrayType)");
2299 return (SDDS_dataset->layout.array_definition[index].type);
2320 if (index < 0 || index >= SDDS_dataset->layout.n_parameters) {
2321 SDDS_SetError(
"Unable to get parameter type--parameter index is out of range (SDDS_GetParameterType)");
2324 return (SDDS_dataset->layout.parameter_definition[index].type);
2344 if ((index =
SDDS_GetParameterIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_parameters) {
2345 SDDS_SetError(
"Unable to get parameter type--parameter index is out of range (SDDS_GetNamedParameterType)");
2348 return (SDDS_dataset->layout.parameter_definition[index].type);
2448 while (isspace(*ptr))
2452 ptr = s + strlen(s) - 1;
2453 while (isspace(*ptr))
2498 if (!SDDS_dataset->column_flag)
2500 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2501 if (SDDS_dataset->column_flag[i] && strcmp(name, SDDS_dataset->layout.column_definition[i].name) == 0)
2532 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_columns))) {
2533 SDDS_SetError(
"Unable to get column names--allocation failure (SDDS_GetColumnNames)");
2536 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2537 if (!SDDS_dataset->column_flag || SDDS_dataset->column_flag[i]) {
2538 if (!
SDDS_CopyString(name + *number, SDDS_dataset->layout.column_definition[i].name)) {
2572 *number = SDDS_dataset->layout.n_parameters;
2573 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_parameters))) {
2574 SDDS_SetError(
"Unable to get parameter names--allocation failure (SDDS_GetParameterNames)");
2577 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++) {
2578 if (!
SDDS_CopyString(name + i, SDDS_dataset->layout.parameter_definition[i].name)) {
2610 *number = SDDS_dataset->layout.n_arrays;
2611 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_arrays))) {
2612 SDDS_SetError(
"Unable to get array names--allocation failure (SDDS_GetArrayNames)");
2615 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++) {
2616 if (!
SDDS_CopyString(name + i, SDDS_dataset->layout.array_definition[i].name)) {
2648 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_associates))) {
2649 SDDS_SetError(
"Unable to get associate names--allocation failure (SDDS_GetAssociateNames)");
2652 *number = SDDS_dataset->layout.n_associates;
2653 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
2654 if (!
SDDS_CopyString(name + i, SDDS_dataset->layout.associate_definition[i].name)) {
2694void *
SDDS_CastValue(
void *data, int64_t index, int32_t data_type, int32_t desired_type,
void *memory) {
2695 long long integer_value;
2696 long double fp_value;
2699 if (data_type == desired_type) {
2703 switch (data_type) {
2705 integer_value = *((
short *)data + index);
2706 fp_value = integer_value;
2709 integer_value = *((
unsigned short *)data + index);
2710 fp_value = integer_value;
2713 integer_value = *((int32_t *)data + index);
2714 fp_value = integer_value;
2717 integer_value = *((uint32_t *)data + index);
2718 fp_value = integer_value;
2721 integer_value = *((int64_t *)data + index);
2722 fp_value = integer_value;
2725 integer_value = *((uint64_t *)data + index);
2726 fp_value = integer_value;
2729 integer_value = *((
unsigned char *)data + index);
2730 fp_value = integer_value;
2733 fp_value = *((
float *)data + index);
2734 integer_value = fp_value;
2737 fp_value = *((
double *)data + index);
2738 integer_value = fp_value;
2741 fp_value = *((
long double *)data + index);
2742 integer_value = fp_value;
2747 switch (desired_type) {
2749 *((
char *)memory) = integer_value;
2752 *((
short *)memory) = integer_value;
2755 *((
unsigned short *)memory) = integer_value;
2758 *((int32_t *)memory) = integer_value;
2761 *((uint32_t *)memory) = integer_value;
2764 *((int64_t *)memory) = integer_value;
2767 *((uint64_t *)memory) = integer_value;
2770 *((
float *)memory) = fp_value;
2773 *((
double *)memory) = fp_value;
2776 *((
long double *)memory) = fp_value;
2779 SDDS_SetError(
"The impossible has happened (SDDS_CastValue)");
2809 if (!(data = (
void **)
SDDS_Malloc(
sizeof(*data) * dim1)))
2811 for (i = 0; i < dim1; i++)
2812 if (!(data[i] = (
void *)calloc(dim2, size)))
2836 if (array->definition) {
2837 if ((array->definition->type ==
SDDS_STRING) && (array->data)) {
2838 char **str = (
char **)array->data;
2839 for (i = 0; i < array->elements; i++) {
2846 if (array->definition && array->pointer)
2850 array->pointer = array->data = NULL;
2851 if (array->dimension)
2852 free(array->dimension);
2853 if (array->definition)
2855 array->definition = NULL;
2878 for (i = 0; i < dim1; i++)
2904 if (!source || !target)
2906 while (n_strings--) {
2935 for (i = 0; i < strings; i++)
2968 int32_t i, elements;
2969 static MDB_THREAD_LOCAL int32_t depth = 0;
2975 sprintf(s,
"Unable to make pointer array--NULL data array (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
2980 if (!dimension || !dimensions) {
2981 sprintf(s,
"Unable to make pointer array--NULL or zero-length dimension array (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
2987 sprintf(s,
"Unable to make pointer array--invalid data size (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
2992 if (dimensions == 1) {
2997 for (i = 0; i < dimensions - 1; i++)
2998 elements *= dimension[i];
2999 if (!(pointer = (
void **)
SDDS_Malloc(
sizeof(
void *) * elements))) {
3000 sprintf(s,
"Unable to make pointer array--allocation failure (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
3005 for (i = 0; i < elements; i++)
3006 pointer[i] = (
char *)data + i * size * dimension[dimensions - 1];
3050 SDDS_SetError(
"Unable to make pointer array--NULL data array (SDDS_MakePointerArray)");
3053 if (!dimension || !dimensions) {
3054 SDDS_SetError(
"Unable to make pointer array--NULL or zero-length dimension array (SDDS_MakePointerArray)");
3058 SDDS_SetError(
"Unable to make pointer array--unknown data type (SDDS_MakePointerArray)");
3061 for (i = 0; i < dimensions; i++)
3062 if (dimension[i] <= 0) {
3063 SDDS_SetError(
"Unable to make pointer array--number of elements invalid (SDDS_MakePointerArray)");
3066 if (dimensions == 1)
3092 if (!data || !dimension || !dimensions)
3094 if (dimensions > 1) {
3122 int32_t type, index;
3127 type = SDDS_dataset->layout.parameter_definition[index].type;
3129 SDDS_SetError(
"Unable to apply factor to non-numeric parameter (SDDS_ApplyFactorToParameter)");
3132 if (!SDDS_dataset->parameter) {
3133 SDDS_SetError(
"Unable to apply factor to parameter--no parameter data array (SDDS_ApplyFactorToParameter)");
3136 if (!(data = SDDS_dataset->parameter[index])) {
3137 SDDS_SetError(
"Unable to apply factor to parameter--no data array (SDDS_ApplyFactorToParameter)");
3142 *((
short *)data) *= factor;
3145 *((
unsigned short *)data) *= factor;
3148 *((int32_t *)data) *= factor;
3151 *((uint32_t *)data) *= factor;
3154 *((int64_t *)data) *= factor;
3157 *((uint64_t *)data) *= factor;
3160 *((
char *)data) *= factor;
3163 *((
float *)data) *= factor;
3166 *((
double *)data) *= factor;
3169 *((
long double *)data) *= factor;
3199 int32_t type, index;
3205 type = SDDS_dataset->layout.column_definition[index].type;
3207 SDDS_SetError(
"Unable to apply factor to non-numeric column (SDDS_ApplyFactorToColumn)");
3210 data = SDDS_dataset->data[index];
3211 for (i = 0; i < SDDS_dataset->n_rows; i++) {
3214 *((
short *)data + i) *= factor;
3217 *((
unsigned short *)data + i) *= factor;
3220 *((int32_t *)data + i) *= factor;
3223 *((uint32_t *)data + i) *= factor;
3226 *((int64_t *)data + i) *= factor;
3229 *((uint64_t *)data + i) *= factor;
3232 *((
char *)data + i) *= factor;
3235 *((
float *)data + i) *= factor;
3238 *((
double *)data + i) *= factor;
3241 *((
long double *)data + i) *= factor;
3268 ptr = s + strlen(s);
3299 if (!SDDS_dataset) {
3300 SDDS_SetError(
"NULL SDDS_DATASET passed (SDDS_ForceInactive)");
3303 SDDS_dataset->layout.fp = NULL;
3326 if (!SDDS_dataset) {
3330 if (!SDDS_dataset->layout.fp)
3358#if defined(F_TEST) && ALLOW_FILE_LOCKING
3360 if (!(fp = fopen(filename,
"rb")))
3362 if (lockf(fileno(fp), F_TEST, 0) == -1) {
3402#if defined(F_TEST) && ALLOW_FILE_LOCKING
3404 if (lockf(fileno(fp), F_TEST, 0) == -1) {
3405 sprintf(s,
"Unable to access file %s--file is locked (%s)", filename, caller);
3409 if (lockf(fileno(fp), F_TLOCK, 0) == -1) {
3410 sprintf(s,
"Unable to establish lock on file %s (%s)", filename, caller);
3449 fprintf(stderr,
"Unable to break into locked file\n");
3453 int i = 1000, j = 0;
3457 if (strlen(filename) > 500) {
3458 fprintf(stderr,
"Unable to break into locked file\n");
3463 for (i = 1000; i < 1020; i++) {
3464 sprintf(buffer,
"%s.bl%d", filename, i);
3465 if ((fp = fopen(buffer,
"r"))) {
3475 fprintf(stderr,
"Unable to break into locked file\n");
3481 sprintf(buffer,
"cp -p %s %s.bl%d", filename, filename, j);
3482 if (system(buffer) == -1) {
3483 fprintf(stderr,
"Unable to break into locked file\n");
3488 sprintf(buffer,
"mv -f %s.bl%d %s", filename, j, filename);
3489 if (system(buffer) == -1) {
3490 fprintf(stderr,
"Unable to break into locked file\n");
3568 static MDB_THREAD_LOCAL int32_t flags = 0;
3569 static MDB_THREAD_LOCAL int32_t *flag = NULL;
3570 char **name, *string, *
match_string, *ptr, *exclude_string;
3572 int32_t retval, requiredType;
3573 int32_t i, j, n_names, index, matches;
3574 int32_t local_memory;
3575 char buffer[SDDS_MAXLINE];
3580 n_names = requiredType = local_memory = logic = 0;
3589 va_start(argptr, typeMode);
3590 if (typeMode == FIND_SPECIFIED_TYPE)
3591 requiredType = va_arg(argptr, int32_t);
3592 switch (matchMode) {
3593 case SDDS_NAME_ARRAY:
3595 n_names = va_arg(argptr, int32_t);
3596 name = va_arg(argptr,
char **);
3598 case SDDS_NAMES_STRING:
3602 ptr = va_arg(argptr,
char *);
3604 while ((ptr = strchr(
string,
',')))
3608 SDDS_SetError(
"Unable to process column selection--memory allocation failure (SDDS_MatchColumns)");
3616 case SDDS_NAME_STRINGS:
3620 while ((
string = va_arg(argptr,
char *))) {
3621 if (!(name =
SDDS_Realloc(name,
sizeof(*name) * (n_names + 1)))) {
3622 SDDS_SetError(
"Unable to process column selection--memory allocation failure (SDDS_MatchColumns)");
3626 name[n_names++] = string;
3629 case SDDS_MATCH_STRING:
3632 if (!(
string = va_arg(argptr,
char *))) {
3633 SDDS_SetError(
"Unable to process column selection--invalid matching string (SDDS_MatchColumns)");
3638 logic = va_arg(argptr, int32_t);
3640 case SDDS_MATCH_EXCLUDE_STRING:
3643 if (!(
string = va_arg(argptr,
char *))) {
3644 SDDS_SetError(
"Unable to process column selection--invalid matching string (SDDS_MatchColumns)");
3649 if (!(
string = va_arg(argptr,
char *))) {
3650 SDDS_SetError(
"Unable to process column exclusion--invalid matching string (SDDS_MatchColumns)");
3655 logic = va_arg(argptr, int32_t);
3658 SDDS_SetError(
"Unable to process column selection--unknown match mode (SDDS_MatchColumns)");
3667 SDDS_SetError(
"Unable to process column selection--no names in call (SDDS_MatchColumns)");
3671 if (SDDS_dataset->layout.n_columns != flags) {
3672 flags = SDDS_dataset->layout.n_columns;
3677 if (!(flag = (int32_t *)calloc(flags,
sizeof(*flag)))) {
3678 SDDS_SetError(
"Memory allocation failure (SDDS_MatchColumns)");
3683 if (flags && (matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING))
3684 memset(flag, 0,
sizeof(*flag) * flags);
3686 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
3687 for (i = 0; i < n_names; i++) {
3692 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
3694 if (exclude_string != NULL) {
3695 if (
SDDS_Logic(flag[i],
wild_match(SDDS_dataset->layout.column_definition[i].name, exclude_string), logic))
3704 fprintf(stderr,
"no logic match of %s to %s\n", SDDS_dataset->layout.column_definition[i].name,
match_string);
3713 free(exclude_string);
3715 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3716 fprintf(stderr,
"flag[%" PRId32
"] = %" PRId32
" : %s\n", i, flag[i], SDDS_dataset->layout.column_definition[i].name);
3719 if (local_memory == 2) {
3720 for (i = 0; i < n_names; i++)
3723 if (local_memory >= 1)
3727 case FIND_SPECIFIED_TYPE:
3728 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3729 if (SDDS_dataset->layout.column_definition[i].type != requiredType)
3732 case FIND_NUMERIC_TYPE:
3733 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3737 case FIND_FLOATING_TYPE:
3738 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3742 case FIND_INTEGER_TYPE:
3743 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3751 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3753 fprintf(stderr,
"column %s matched\n", SDDS_dataset->layout.column_definition[i].name);
3756 for (i = matches = 0; i < SDDS_dataset->layout.n_columns; i++) {
3760 if (!matches || !nameReturn)
3762 if (!((*nameReturn) = (
char **)
SDDS_Malloc(matches *
sizeof(**nameReturn)))) {
3763 SDDS_SetError(
"Memory allocation failure (SDDS_MatchColumns)");
3766 for (i = j = 0; i < SDDS_dataset->layout.n_columns; i++) {
3768 if (!
SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.column_definition[i].name)) {
3849 static MDB_THREAD_LOCAL int32_t flags = 0, *flag = NULL;
3850 char **name, *string, *
match_string, *ptr, *exclude_string;
3852 int32_t i, j, index, n_names, retval, requiredType, matches;
3854 int32_t local_memory;
3855 char buffer[SDDS_MAXLINE];
3860 n_names = requiredType = local_memory = logic = 0;
3869 va_start(argptr, typeMode);
3870 if (typeMode == FIND_SPECIFIED_TYPE)
3871 requiredType = va_arg(argptr, int32_t);
3872 switch (matchMode) {
3873 case SDDS_NAME_ARRAY:
3875 n_names = va_arg(argptr, int32_t);
3876 name = va_arg(argptr,
char **);
3878 case SDDS_NAMES_STRING:
3882 ptr = va_arg(argptr,
char *);
3884 while ((ptr = strchr(
string,
',')))
3888 SDDS_SetError(
"Unable to process parameter selection--memory allocation failure (SDDS_MatchParameters)");
3896 case SDDS_NAME_STRINGS:
3900 while ((
string = va_arg(argptr,
char *))) {
3901 if (!(name =
SDDS_Realloc(name,
sizeof(*name) * (n_names + 1)))) {
3902 SDDS_SetError(
"Unable to process parameter selection--memory allocation failure (SDDS_MatchParameters)");
3906 name[n_names++] = string;
3909 case SDDS_MATCH_STRING:
3912 if (!(
string = va_arg(argptr,
char *))) {
3913 SDDS_SetError(
"Unable to process parameter selection--invalid matching string (SDDS_MatchParameters)");
3918 logic = va_arg(argptr, int32_t);
3920 case SDDS_MATCH_EXCLUDE_STRING:
3923 if (!(
string = va_arg(argptr,
char *))) {
3924 SDDS_SetError(
"Unable to process parameter selection--invalid matching string (SDDS_MatchParameters)");
3929 if (!(
string = va_arg(argptr,
char *))) {
3930 SDDS_SetError(
"Unable to process parameter exclusion--invalid matching string (SDDS_MatchParameters)");
3935 logic = va_arg(argptr, int32_t);
3938 SDDS_SetError(
"Unable to process parameter selection--unknown match mode (SDDS_MatchParameters)");
3947 SDDS_SetError(
"Unable to process parameter selection--no names in call (SDDS_MatchParameters)");
3951 if (SDDS_dataset->layout.n_parameters != flags) {
3952 flags = SDDS_dataset->layout.n_parameters;
3957 if (!(flag = (int32_t *)calloc(flags,
sizeof(*flag)))) {
3958 SDDS_SetError(
"Memory allocation failure (SDDS_MatchParameters)");
3963 if (flags && (matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING))
3964 memset(flag, 0,
sizeof(*flag) * flags);
3966 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
3967 for (i = 0; i < n_names; i++) {
3972 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++) {
3974 if (exclude_string != NULL) {
3975 if (
SDDS_Logic(flag[i],
wild_match(SDDS_dataset->layout.parameter_definition[i].name, exclude_string), logic))
3984 fprintf(stderr,
"no logic match of %s to %s\n", SDDS_dataset->layout.parameter_definition[i].name,
match_string);
3993 free(exclude_string);
3995 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3996 fprintf(stderr,
"flag[%" PRId32
"] = %" PRId32
" : %s\n", i, flag[i], SDDS_dataset->layout.parameter_definition[i].name);
3999 if (local_memory == 2) {
4000 for (i = 0; i < n_names; i++)
4003 if (local_memory >= 1)
4007 case FIND_SPECIFIED_TYPE:
4008 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
4009 if (SDDS_dataset->layout.parameter_definition[i].type != requiredType)
4012 case FIND_NUMERIC_TYPE:
4013 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
4017 case FIND_FLOATING_TYPE:
4018 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
4022 case FIND_INTEGER_TYPE:
4023 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
4031 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
4033 fprintf(stderr,
"parameter %s matched\n", SDDS_dataset->layout.parameter_definition[i].name);
4036 for (i = matches = 0; i < SDDS_dataset->layout.n_parameters; i++) {
4040 if (!matches || !nameReturn)
4042 if (!((*nameReturn) = (
char **)
SDDS_Malloc(matches *
sizeof(**nameReturn)))) {
4043 SDDS_SetError(
"Memory allocation failure (SDDS_MatchParameters)");
4046 for (i = j = 0; i < SDDS_dataset->layout.n_parameters; i++) {
4048 if (!
SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.parameter_definition[i].name)) {
4049 SDDS_SetError(
"String copy failure (SDDS_MatchParameters)");
4130 static MDB_THREAD_LOCAL int32_t flags = 0, *flag = NULL;
4131 char **name, *string, *
match_string, *ptr, *exclude_string;
4133 int32_t i, j, index, n_names, retval, requiredType, matches;
4135 int32_t local_memory;
4136 char buffer[SDDS_MAXLINE];
4141 n_names = requiredType = local_memory = logic = 0;
4150 va_start(argptr, typeMode);
4151 if (typeMode == FIND_SPECIFIED_TYPE)
4152 requiredType = va_arg(argptr, int32_t);
4153 switch (matchMode) {
4154 case SDDS_NAME_ARRAY:
4156 n_names = va_arg(argptr, int32_t);
4157 name = va_arg(argptr,
char **);
4159 case SDDS_NAMES_STRING:
4163 ptr = va_arg(argptr,
char *);
4165 while ((ptr = strchr(
string,
',')))
4169 SDDS_SetError(
"Unable to process array selection--memory allocation failure (SDDS_MatchArrays)");
4177 case SDDS_NAME_STRINGS:
4181 while ((
string = va_arg(argptr,
char *))) {
4182 if (!(name =
SDDS_Realloc(name,
sizeof(*name) * (n_names + 1)))) {
4183 SDDS_SetError(
"Unable to process array selection--memory allocation failure (SDDS_MatchArrays)");
4187 name[n_names++] = string;
4190 case SDDS_MATCH_STRING:
4193 if (!(
string = va_arg(argptr,
char *))) {
4194 SDDS_SetError(
"Unable to process array selection--invalid matching string (SDDS_MatchArrays)");
4199 logic = va_arg(argptr, int32_t);
4201 case SDDS_MATCH_EXCLUDE_STRING:
4204 if (!(
string = va_arg(argptr,
char *))) {
4205 SDDS_SetError(
"Unable to process array selection--invalid matching string (SDDS_MatchArrays)");
4210 if (!(
string = va_arg(argptr,
char *))) {
4211 SDDS_SetError(
"Unable to process array exclusion--invalid matching string (SDDS_MatchArrays)");
4216 logic = va_arg(argptr, int32_t);
4219 SDDS_SetError(
"Unable to process array selection--unknown match mode (SDDS_MatchArrays)");
4228 SDDS_SetError(
"Unable to process array selection--no names in call (SDDS_MatchArrays)");
4232 if (SDDS_dataset->layout.n_arrays != flags) {
4233 flags = SDDS_dataset->layout.n_arrays;
4238 if (!(flag = (int32_t *)calloc(flags,
sizeof(*flag)))) {
4239 SDDS_SetError(
"Memory allocation failure (SDDS_MatchArrays)");
4244 if (flags && (matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING))
4245 memset(flag, 0,
sizeof(*flag) * flags);
4247 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
4248 for (i = 0; i < n_names; i++) {
4253 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4255 if (exclude_string != NULL) {
4256 if (
SDDS_Logic(flag[i],
wild_match(SDDS_dataset->layout.array_definition[i].name, exclude_string), logic))
4265 fprintf(stderr,
"no logic match of %s to %s\n", SDDS_dataset->layout.array_definition[i].name,
match_string);
4274 free(exclude_string);
4276 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4277 fprintf(stderr,
"flag[%" PRId32
"] = %" PRId32
" : %s\n", i, flag[i], SDDS_dataset->layout.array_definition[i].name);
4280 if (local_memory == 2) {
4281 for (i = 0; i < n_names; i++)
4284 if (local_memory >= 1)
4288 case FIND_SPECIFIED_TYPE:
4289 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4290 if (SDDS_dataset->layout.array_definition[i].type != requiredType)
4293 case FIND_NUMERIC_TYPE:
4294 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4298 case FIND_FLOATING_TYPE:
4299 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4303 case FIND_INTEGER_TYPE:
4304 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4312 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4314 fprintf(stderr,
"array %s matched\n", SDDS_dataset->layout.array_definition[i].name);
4317 for (i = matches = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4321 if (!matches || !nameReturn)
4323 if (!((*nameReturn) = (
char **)
SDDS_Malloc(matches *
sizeof(**nameReturn)))) {
4324 SDDS_SetError(
"Memory allocation failure (SDDS_MatchArrays)");
4327 for (i = j = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4329 if (!
SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.array_definition[i].name)) {
4402 int32_t error, type, thisType;
4404 char *name, *buffer;
4406 va_start(argptr, mode);
4410 if (mode == FIND_SPECIFIED_TYPE)
4411 type = va_arg(argptr, int32_t);
4412 while ((name = va_arg(argptr,
char *))) {
4415 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
4417 SDDS_SetError(
"unable to return string from SDDS_FindColumn");
4489 int32_t index, error, type, thisType;
4491 char *name, *buffer;
4493 va_start(argptr, mode);
4497 if (mode == FIND_SPECIFIED_TYPE)
4498 type = va_arg(argptr, int32_t);
4499 while ((name = va_arg(argptr,
char *))) {
4502 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
4504 SDDS_SetError(
"unable to return string from SDDS_FindParameter");
4576 int32_t index, error, type, thisType;
4578 char *name, *buffer;
4580 va_start(argptr, mode);
4584 if (mode == FIND_SPECIFIED_TYPE)
4585 type = va_arg(argptr, int32_t);
4586 while ((name = va_arg(argptr,
char *))) {
4589 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
4591 SDDS_SetError(
"unable to return string from SDDS_FindArray");
4650 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_NONEXISTENT));
4653 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4660 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4664 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4669 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4673 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4678 return SDDS_CHECK_OKAY;
4681 SDDS_SetError(
"units field of column has wrong data type!");
4682 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4686 return (SDDS_CHECK_OKAY);
4687 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGUNITS));
4689 if (strcmp(units, units1) == 0) {
4691 return (SDDS_CHECK_OKAY);
4694 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGUNITS));
4741 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_NONEXISTENT));
4744 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4751 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4755 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4759 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4762 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4767 return (SDDS_CHECK_OKAY);
4770 SDDS_SetError(
"units field of parameter has wrong data type!");
4771 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4775 return (SDDS_CHECK_OKAY);
4776 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGUNITS));
4778 if (strcmp(units, units1) == 0) {
4780 return (SDDS_CHECK_OKAY);
4783 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGUNITS));
4830 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_NONEXISTENT));
4833 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4840 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4844 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4848 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4851 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4856 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4860 return (SDDS_CHECK_OKAY);
4864 return (SDDS_CHECK_OKAY);
4865 return (SDDS_CHECK_OKAY);
4867 if (strcmp(units, units1) == 0) {
4869 return (SDDS_CHECK_OKAY);
4872 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGUNITS));
4914int32_t
SDDS_PrintCheckText(FILE *fp,
char *name,
char *units, int32_t type,
char *class_name, int32_t error_code) {
4916 const char *programNameText;
4918 if (!fp || !name || !class_name)
4919 return (error_code);
4920 programName = SDDS_GetRegisteredProgramNameCopy();
4921 programNameText = programName ? programName :
"?";
4922 switch (error_code) {
4923 case SDDS_CHECK_OKAY:
4925 case SDDS_CHECK_NONEXISTENT:
4926 fprintf(fp,
"Problem with %s %s: nonexistent (%s)\n", class_name, name, programNameText);
4928 case SDDS_CHECK_WRONGTYPE:
4930 fprintf(fp,
"Problem with %s %s: wrong data type--expected %s (%s)\n", class_name, name,
SDDS_type_name[type - 1], programNameText);
4932 fprintf(fp,
"Problem with %s %s: wrong data type--expected numeric data (%s)\n", class_name, name, programNameText);
4934 fprintf(fp,
"Problem with %s %s: wrong data type--expected floating point data (%s)\n", class_name, name, programNameText);
4936 fprintf(fp,
"Problem with %s %s: wrong data type--expected integer data (%s)\n", class_name, name, programNameText);
4938 fprintf(fp,
"Problem with %s %s: invalid data type code seen---may be a programming error (%s)\n", class_name, name, programNameText);
4940 case SDDS_CHECK_WRONGUNITS:
4941 fprintf(fp,
"Problem with %s %s: wrong units--expected %s (%s)\n", class_name, name, units ? units :
"none", programNameText);
4944 fprintf(stderr,
"Problem with call to SDDS_PrintCheckText--invalid error code (%s)\n", programNameText);
4946 return (SDDS_CHECK_OKAY);
4949 return (error_code);
4982 layout = &SDDS_dataset->layout;
4983 orig_layout = &SDDS_dataset->original_layout;
4984 for (i = 0; i < layout->n_parameters; i++) {
4985 if (layout->parameter_definition[i].fixed_value)
4986 free(layout->parameter_definition[i].fixed_value);
4987 if (orig_layout->parameter_definition[i].fixed_value && (!layout->parameter_definition[i].fixed_value || orig_layout->parameter_definition[i].fixed_value != layout->parameter_definition[i].fixed_value))
4988 free(orig_layout->parameter_definition[i].fixed_value);
4989 orig_layout->parameter_definition[i].fixed_value = NULL;
4990 layout->parameter_definition[i].fixed_value = NULL;
5024 if (!SDDS_dataset) {
5028 if (newmode == -SDDS_BINARY) {
5034 newmode = SDDS_BINARY;
5036 if (newmode != SDDS_ASCII && newmode != SDDS_BINARY) {
5040 if (newmode == SDDS_dataset->layout.data_mode.mode)
5042 if (SDDS_dataset->page_number != 0 && (SDDS_dataset->page_number > 1 || SDDS_dataset->n_rows_written != 0)) {
5043 SDDS_SetError(
"Can't change the mode of a file that's been written to (SDDS_SetDataMode)");
5046 SDDS_dataset->layout.data_mode.mode = SDDS_dataset->original_layout.data_mode.mode = newmode;
5073 SDDS_SetError(
"passed size is not equal to expected size for SDDS_DATASET structure");
5074 sprintf(buffer,
"Passed size is %" PRId32
", library size is %" PRId32
"\n", size, (int32_t)
sizeof(
SDDS_DATASET));
5101 return page->layout.n_columns;
5124 return page->layout.n_parameters;
5147 return page->layout.n_arrays;
5243 if (*s >=
'0' && *s <=
'9') {
5246 while (++count <= 3 && *s >=
'0' && *s <=
'9')
5247 *ptr = 8 * (*ptr) + *s++ -
'0';
5259#define COMMENT_COMMANDS 3
5260static const char *
const commentCommandName[COMMENT_COMMANDS] = {
5266static const uint32_t commentCommandFlag[COMMENT_COMMANDS] = {
5267 SDDS_BIGENDIAN_SEEN,
5268 SDDS_LITTLEENDIAN_SEEN,
5269 SDDS_FIXED_ROWCOUNT_SEEN,
5293 return SDDS_dataset->layout.commentFlags;
5313 SDDS_dataset->layout.commentFlags = 0;
5343 char buffer[SDDS_MAXLINE];
5345 if (SDDS_dataset == NULL)
5348 for (i = 0; i < COMMENT_COMMANDS; i++) {
5349 if (strcmp(buffer, commentCommandName[i]) == 0) {
5350 SDDS_dataset->layout.commentFlags |= commentCommandFlag[i];
5436 int32_t index, type, thisType;
5440 va_start(argptr, mode);
5443 if (mode == FIND_SPECIFIED_TYPE)
5444 type = va_arg(argptr, int32_t);
5445 name = va_arg(argptr,
char *);
5448 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
5513 int32_t type, thisType;
5517 va_start(argptr, mode);
5520 if (mode == FIND_SPECIFIED_TYPE)
5521 type = va_arg(argptr, int32_t);
5522 name = va_arg(argptr,
char *);
5525 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
5589 int32_t index, type, thisType;
5593 va_start(argptr, mode);
5596 if (mode == FIND_SPECIFIED_TYPE)
5597 type = va_arg(argptr, int32_t);
5598 name = va_arg(argptr,
char *);
5601 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
5648 char **name, **selectedName, *ptr = NULL;
5649 int32_t names0 = 0, selected = 0, i, j;
5650 int32_t names32 = 0;
5652 name = selectedName = NULL;
5654 case SDDS_MATCH_COLUMN:
5656 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5658 case SDDS_MATCH_PARAMETER:
5660 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5663 case SDDS_MATCH_ARRAY:
5665 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5669 SDDS_Bomb(
"Invalid match type provided.");
5672 for (i = 0; i < matches; i++) {
5675 for (j = 0; j < names0; j++) {
5677 selectedName =
SDDS_Realloc(selectedName,
sizeof(*selectedName) * (selected + 1));
5684 if (
match_string(matchName[i], name, names0, EXACT_MATCH) < 0) {
5685 fprintf(stderr,
"%s not found in input file.\n", matchName[i]);
5688 selectedName =
SDDS_Realloc(selectedName,
sizeof(*selectedName) * (selected + 1));
5697 return selectedName;
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
int32_t SDDS_GetArrayInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified array in the SDDS dataset.
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.
int32_t SDDS_GetColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified column in the SDDS dataset.
Internal definitions and function declarations for SDDS with LZMA support.
int32_t SDDS_VerifyParameterExists(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Verifies the existence of a parameter in the SDDS dataset based on specified criteria.
void SDDS_FreeArray(SDDS_ARRAY *array)
Frees memory allocated for an SDDS array structure.
int32_t SDDS_CheckArray(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if an array exists in the SDDS dataset with the specified name, units, and type.
int32_t SDDS_FileIsLocked(const char *filename)
Determines if a specified file is locked.
int32_t SDDS_GetNamedArrayType(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the data type of an array in the SDDS dataset by its name.
int32_t SDDS_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
void SDDS_SetError0(char *error_text)
Internal function to record an error message in the SDDS error stack.
uint32_t SDDS_SetAutoCheckMode(uint32_t newMode)
Sets the automatic check mode for SDDS dataset validation.
void SDDS_InterpretEscapes(char *s)
Interprets and converts escape sequences in a string.
int32_t SDDS_GetNamedColumnType(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the data type of a column in the SDDS dataset by its name.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
void SDDS_FreeMatrix(void **ptr, int64_t dim1)
Frees memory allocated for a two-dimensional matrix.
int32_t SDDS_VerifyArrayExists(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Verifies the existence of an array in the SDDS dataset based on specified criteria.
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
int32_t SDDS_GetNamedParameterType(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the data type of a parameter in the SDDS dataset by its name.
int32_t SDDS_IsActive(SDDS_DATASET *SDDS_dataset)
Checks whether an SDDS dataset is currently active.
ASSOCIATE_DEFINITION * SDDS_GetAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified associate from the SDDS dataset.
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.
int32_t SDDS_SetDataMode(SDDS_DATASET *SDDS_dataset, int32_t newmode)
Sets the data mode (ASCII or Binary) for the SDDS dataset.
int SDDS_CompareIndexedNames(const void *s1, const void *s2)
Compares two SORTED_INDEX structures by their name fields.
ARRAY_DEFINITION * SDDS_GetArrayDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified array from the SDDS dataset.
int32_t SDDS_VerifyPrintfFormat(const char *string, int32_t type)
Verifies that a printf format string is compatible with a specified data type.
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.
char * SDDS_FindArray(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Finds the first array in the SDDS dataset that matches the specified criteria.
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
char ** getMatchingSDDSNames(SDDS_DATASET *dataset, char **matchName, int32_t matches, int32_t *names, short type)
Retrieves an array of matching SDDS entity names based on specified criteria.
PARAMETER_DEFINITION * SDDS_GetParameterDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified parameter from the SDDS dataset.
int32_t SDDS_BreakIntoLockedFile(char *filename)
Attempts to override a locked file by creating a temporary copy.
int32_t SDDS_ParameterCount(SDDS_DATASET *page)
Retrieves the number of parameters in the SDDS dataset.
int32_t SDDS_FreeParameterDefinition(PARAMETER_DEFINITION *source)
Frees memory allocated for a parameter definition.
void * SDDS_Recalloc(void *old_ptr, size_t old_size, size_t new_size)
Reallocates memory to a new size and zero-initializes the additional space.
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_SprintTypedValue(void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode)
Formats a data value of a specified type into a string buffer using an optional printf format string.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
int32_t SDDS_MatchParameters(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves parameter names from an SDDS dataset based on specified criteria.
char * fgetsSkipComments(SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, FILE *fp, char skip_char)
Reads a line from a file while skipping comment lines.
int SDDS_CompareIndexedNamesPtr(const void *s1, const void *s2)
Compares two pointers to SORTED_INDEX structures by their name fields.
void * SDDS_CastValue(void *data, int64_t index, int32_t data_type, int32_t desired_type, void *memory)
Casts a value from one SDDS data type to another.
void * SDDS_MakePointerArrayRecursively(void *data, int32_t size, int32_t dimensions, int32_t *dimension)
Recursively creates a multi-dimensional pointer array from a contiguous data block.
int32_t SDDS_SetMemory(void *mem, int64_t n_elements, int32_t data_type,...)
Initializes a memory block with a sequence of values based on a specified data type.
int32_t SDDS_ColumnCount(SDDS_DATASET *page)
Retrieves the number of columns in the SDDS dataset.
char ** SDDS_GetAssociateNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all associates in the SDDS dataset.
int32_t SDDS_SprintTypedValueFactor(void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode, double factor)
Reallocates memory to a new size and zero-initializes the additional space.
char * SDDS_GetTypeName(int32_t type)
Retrieves the name of a specified SDDS data type as a string.
int32_t SDDS_CheckColumn(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a column exists in the SDDS dataset with the specified name, units, and type.
char * fgetsLZMASkipCommentsResize(SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, struct lzmafile *lzmafp, char skip_char)
Reads a line from a LZMA-compressed file with dynamic buffer resizing while skipping comment lines.
void * SDDS_AllocateMatrix(int32_t size, int64_t dim1, int64_t dim2)
Allocates a two-dimensional matrix with zero-initialized elements.
void SDDS_EscapeQuotes(char *s, char quote_char)
Escapes quote characters within a string by inserting backslashes.
char * fgetsLZMASkipComments(SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, struct lzmafile *lzmafp, char skip_char)
Reads a line from a LZMA-compressed file while skipping comment lines.
ASSOCIATE_DEFINITION * SDDS_CopyAssociateDefinition(ASSOCIATE_DEFINITION **target, ASSOCIATE_DEFINITION *source)
Creates a copy of an associate definition.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
int32_t SDDS_ColumnIsOfInterest(SDDS_DATASET *SDDS_dataset, char *name)
Determines if a specified column is marked as of interest in the dataset.
int32_t SDDS_GetArrayType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of an array in the SDDS dataset by its index.
void SDDS_CutOutComments(SDDS_DATASET *SDDS_dataset, char *s, char cc)
Removes comments from a string based on a specified comment character.
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
char * SDDS_FindParameter(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Finds the first parameter in the SDDS dataset that matches the specified criteria.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
char ** SDDS_GetErrorMessages(int32_t *number, int32_t mode)
Retrieves recorded error messages from the SDDS error stack.
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
void SDDS_EscapeCommentCharacters(char *string, char cc)
Escapes comment characters within a string by inserting backslashes.
int32_t SDDS_DeleteParameterFixedValues(SDDS_DATASET *SDDS_dataset)
Deletes fixed values from all parameters in the SDDS dataset.
void SDDS_ClearErrors()
Clears all recorded error messages from the SDDS error stack.
int32_t SDDS_ApplyFactorToColumn(SDDS_DATASET *SDDS_dataset, char *name, double factor)
Applies a scaling factor to all elements of a specific column in the SDDS dataset.
void SDDS_FreePointerArray(void **data, int32_t dimensions, int32_t *dimension)
Frees a multi-dimensional pointer array created by SDDS_MakePointerArray.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
int32_t SDDS_NumberOfErrors()
Retrieves the number of errors recorded by SDDS library routines.
int32_t SDDS_IdentifyType(char *typeName)
Identifies the SDDS data type based on its string name.
int32_t SDDS_ArrayCount(SDDS_DATASET *page)
Retrieves the number of arrays in the SDDS dataset.
int32_t SDDS_GetTypeSize(int32_t type)
Retrieves the size in bytes of a specified SDDS data type.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_LockFile(FILE *fp, const char *filename, const char *caller)
Attempts to lock a specified file.
int32_t SDDS_ApplyFactorToParameter(SDDS_DATASET *SDDS_dataset, char *name, double factor)
Applies a scaling factor to a specific parameter in the SDDS dataset.
int32_t SDDS_GetToken(char *s, char *buffer, int32_t buflen)
Extracts the next token from a string, handling quoted substrings and escape characters.
char * SDDS_FindColumn(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Finds the first column in the SDDS dataset that matches the specified criteria.
int32_t SDDS_CheckDatasetStructureSize(int32_t size)
Verifies that the size of the SDDS_DATASET structure matches the expected size.
int32_t SDDS_MatchColumns(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves column names from an SDDS dataset based on specified criteria.
ARRAY_DEFINITION * SDDS_CopyArrayDefinition(ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
Creates a copy of an array definition.
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.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
int32_t SDDS_CheckParameter(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a parameter exists in the SDDS dataset with the specified name, units, and type.
int32_t SDDS_PrintCheckText(FILE *fp, char *name, char *units, int32_t type, char *class_name, int32_t error_code)
Prints detailed error messages related to SDDS entity checks.
int32_t SDDS_ForceInactive(SDDS_DATASET *SDDS_dataset)
Marks an SDDS dataset as inactive.
int32_t SDDS_GetAssociateIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named associate in the SDDS dataset.
int32_t SDDS_VerifyColumnExists(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Verifies the existence of a column in the SDDS dataset based on specified criteria.
char ** SDDS_GetArrayNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all arrays in the SDDS dataset.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
int32_t SDDS_CheckTabularData(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the consistency of tabular data within an SDDS dataset.
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
int32_t SDDS_GetToken2(char *s, char **st, int32_t *strlength, char *buffer, int32_t buflen)
Extracts the next token from a string, handling quoted substrings and escape characters,...
uint32_t SDDS_GetSpecialCommentsModes(SDDS_DATASET *SDDS_dataset)
Retrieves the current special comments modes set in the SDDS dataset.
void SDDS_EscapeNewlines(char *s)
Escapes newline characters in a string by replacing them with "\\n".
int32_t SDDS_FreeAssociateDefinition(ASSOCIATE_DEFINITION *source)
Frees memory allocated for an associate definition.
void SDDS_UnescapeQuotes(char *s, char quote_char)
Removes escape characters from quote characters within a string.
int32_t SDDS_PrintTypedValue(void *data, int64_t index, int32_t type, char *format, FILE *fp, uint32_t mode)
Prints a data value of a specified type using an optional printf format string.
void SDDS_ResetSpecialCommentsModes(SDDS_DATASET *SDDS_dataset)
Resets the special comments modes in the SDDS dataset.
COLUMN_DEFINITION * SDDS_CopyColumnDefinition(COLUMN_DEFINITION **target, COLUMN_DEFINITION *source)
Creates a copy of a column definition.
char * fgetsSkipCommentsResize(SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, FILE *fp, char skip_char)
Reads a line from a file with dynamic buffer resizing while skipping comment lines.
void SDDS_ParseSpecialComments(SDDS_DATASET *SDDS_dataset, char *s)
Parses and processes special comment commands within the SDDS dataset.
void SDDS_Free(void *mem)
Free memory previously allocated by SDDS_Malloc.
void SDDS_RemovePadding(char *s)
Removes leading and trailing whitespace from a string.
int32_t SDDS_PadToLength(char *string, int32_t length)
Pads a string with spaces to reach a specified length.
int32_t SDDS_HasWhitespace(char *string)
Checks if a string contains any whitespace characters.
void SDDS_Warning(char *message)
Prints a warning message to stderr.
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.
int32_t SDDS_FreeColumnDefinition(COLUMN_DEFINITION *source)
Frees memory allocated for a column definition.
PARAMETER_DEFINITION * SDDS_CopyParameterDefinition(PARAMETER_DEFINITION **target, PARAMETER_DEFINITION *source)
Creates a copy of a parameter definition.
COLUMN_DEFINITION * SDDS_GetColumnDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified column from the SDDS dataset.
void * SDDS_Calloc(size_t nelem, size_t elem_size)
Allocates zero-initialized memory for an array of elements.
SDDS_DATASET * SDDS_CreateEmptyDataset(void)
Creates an empty SDDS dataset.
int32_t SDDS_MatchArrays(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves array names from an SDDS dataset based on specified criteria.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_INTEGER_TYPE(type)
Checks if the given type identifier corresponds to an integer type.
#define SDDS_VALID_TYPE(type)
Validates whether the given type identifier is within the defined range of SDDS types.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_FLOATING_TYPE(type)
Checks if the given type identifier corresponds to a floating-point type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_ANY_FLOATING_TYPE
Special identifier used by SDDS_Check*() routines to accept any floating-point type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
#define SDDS_ANY_INTEGER_TYPE
Special identifier used by SDDS_Check*() routines to accept any integer type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
long binaryIndexSearch(void **array, long members, void *key, int(*compare)(const void *c1, const void *c2), long bracket)
Searches for a key in a sorted array of pointers using binary search.
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.
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.
int has_wildcards(char *template)
Check if a template string contains any wildcard characters.
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.