27int lockf(
int filedes,
int function, off_t size);
59int32_t
SDDS_PrintTypedValue(
void *data, int64_t index, int32_t type,
char *format, FILE *fp, uint32_t mode) {
60 char buffer[SDDS_PRINT_BUFLEN], *s;
63 SDDS_SetError(
"Unable to print value--data pointer is NULL (SDDS_PrintTypedValue)");
67 SDDS_SetError(
"Unable to print value--file pointer is NULL (SDDS_PrintTypedValue)");
72 fprintf(fp, format ? format :
"%hd", *((
short *)data + index));
75 fprintf(fp, format ? format :
"%hu", *((
unsigned short *)data + index));
78 fprintf(fp, format ? format :
"%" PRId32, *((int32_t *)data + index));
81 fprintf(fp, format ? format :
"%" PRIu32, *((uint32_t *)data + index));
84 fprintf(fp, format ? format :
"%" PRId64, *((int64_t *)data + index));
87 fprintf(fp, format ? format :
"%" PRIu64, *((uint64_t *)data + index));
90 fprintf(fp, format ? format :
"%15.8e", *((
float *)data + index));
93 fprintf(fp, format ? format :
"%21.15e", *((
double *)data + index));
97 fprintf(fp, format ? format :
"%21.18Le", *((
long double *)data + index));
99 fprintf(fp, format ? format :
"%21.15Le", *((
long double *)data + index));
103 s = *((
char **)data + index);
104 if ((int32_t)strlen(s) > SDDS_PRINT_BUFLEN - 3) {
105 SDDS_SetError(
"Buffer size overflow (SDDS_PrintTypedValue)");
112 fprintf(fp, format ? format :
"%c", *((
char *)data + index));
115 SDDS_SetError(
"Unable to print value--unknown data type (SDDS_PrintTypedValue)");
151int32_t
SDDS_SprintTypedValue(
void *data, int64_t index, int32_t type,
const char *format,
char *buffer, uint32_t mode) {
187 char buffer2[SDDS_PRINT_BUFLEN], *s;
191 SDDS_SetError(
"Unable to print value--data pointer is NULL (SDDS_SprintTypedValueFactor)");
195 SDDS_SetError(
"Unable to print value--buffer pointer is NULL (SDDS_SprintTypedValueFactor)");
200 sprintf(buffer, format ? format :
"%hd", (
short)(*((
short *)data + index) * (factor)));
203 sprintf(buffer, format ? format :
"%hu", (
unsigned short)(*((
unsigned short *)data + index) * (factor)));
206 sprintf(buffer, format ? format :
"%" PRId32, (int32_t)(*((int32_t *)data + index) * (factor)));
209 sprintf(buffer, format ? format :
"%" PRIu32, (uint32_t)(*((uint32_t *)data + index) * (factor)));
212 sprintf(buffer, format ? format :
"%" PRId64, (int64_t)(*((int64_t *)data + index) * (factor)));
215 sprintf(buffer, format ? format :
"%" PRIu64, (uint64_t)(*((uint64_t *)data + index) * (factor)));
218 sprintf(buffer, format ? format :
"%15.8e", (
float)(*((
float *)data + index) * (factor)));
221 sprintf(buffer, format ? format :
"%21.15e", (
double)(*((
double *)data + index) * (factor)));
224 if (LDBL_DIG == 18) {
225 sprintf(buffer, format ? format :
"%21.18Le", (
long double)(*((
long double *)data + index) * (factor)));
227 sprintf(buffer, format ? format :
"%21.15Le", (
long double)(*((
long double *)data + index) * (factor)));
231 s = *((
char **)data + index);
232 if ((int32_t)strlen(s) > SDDS_PRINT_BUFLEN - 3) {
233 SDDS_SetError(
"Buffer size overflow (SDDS_SprintTypedValue)");
236 if (!(mode & SDDS_PRINT_NOQUOTES)) {
239 sprintf(buffer,
"\"\"");
240 else if (strchr(s,
'"')) {
244 sprintf(buffer,
"\"%s\"", buffer2);
246 strcpy(buffer, buffer2);
248 sprintf(buffer,
"\"%s\"", s);
250 sprintf(buffer, format ? format :
"%s", s);
254 sprintf(buffer2, format ? format :
"%s", buffer);
255 strcpy(buffer, buffer2);
258 sprintf(buffer, format ? format :
"%s", s);
262 sprintf(buffer, format ? format :
"%c", *((
char *)data + index));
265 SDDS_SetError(
"Unable to print value--unknown data type (SDDS_SprintTypedValue)");
271static int32_t n_errors = 0;
272static int32_t n_errors_max = 0;
273static char **error_description = NULL;
274static char *registeredProgramName = NULL;
292 registeredProgramName = NULL;
320 for (i=0; i<n_errors; i++) {
321 free(error_description[i]);
322 error_description[i] = NULL;
324 free(error_description);
325 error_description = NULL;
343 if (registeredProgramName)
344 fprintf(stderr,
"Error (%s): %s\n", registeredProgramName, message ? message :
"?");
346 fprintf(stderr,
"Error: %s\n", message ? message :
"?");
363 if (registeredProgramName)
364 fprintf(stderr,
"Warning (%s): %s\n", registeredProgramName, message ? message :
"?");
366 fprintf(stderr,
"Warning: %s\n", message ? message :
"?");
396 if (n_errors >= n_errors_max) {
397 if (!(error_description =
SDDS_Realloc(error_description, (n_errors_max += 10) *
sizeof(*error_description)))) {
398 fputs(
"Error trying to allocate additional error description string (SDDS_SetError)\n", stderr);
399 fprintf(stderr,
"Most recent error text:\n%s\n", error_text);
404 fprintf(stderr,
"warning: error text is NULL (SDDS_SetError)\n");
407 fputs(
"Error trying to copy additional error description text (SDDS_SetError)\n", stderr);
408 fprintf(stderr,
"Most recent error text: %s\n", error_text);
441 if (mode & SDDS_VERBOSE_PrintErrors)
445 if (registeredProgramName)
446 fprintf(fp,
"Error for %s:\n", registeredProgramName);
448 fputs(
"Error:\n", fp);
449 if (!error_description)
450 fprintf(stderr,
"warning: internal error: error_description pointer is unexpectedly NULL\n");
452 for (i = 0; i < depth; i++) {
453 if (!error_description[i])
454 fprintf(stderr,
"warning: internal error: error_description[%" PRId32
"] is unexpectedly NULL\n", i);
455 fprintf(fp,
"%s", error_description[i]);
459 if (mode & SDDS_EXIT_PrintErrors)
491 if (mode & SDDS_ALL_GetErrorMessages)
495 if (!(message = (
char **)
SDDS_Malloc(
sizeof(*message) * depth)))
497 if (!error_description) {
498 fprintf(stderr,
"warning: internal error: error_description pointer is unexpectedly NULL (SDDS_GetErrorMessages)\n");
501 for (i = depth - 1; i >= 0; i--) {
502 if (!error_description[i]) {
503 fprintf(stderr,
"internal error: error_description[%" PRId32
"] is unexpectedly NULL (SDDS_GetErrorMessages)\n", i);
507 fprintf(stderr,
"unable to copy error message text (SDDS_GetErrorMessages)\n");
517static uint32_t AutoCheckMode = 0x0000UL;
535 oldMode = AutoCheckMode;
536 AutoCheckMode = newMode;
555 sprintf(buffer,
"NULL SDDS_DATASET pointer passed to %s", caller);
580 if (!(AutoCheckMode & TABULAR_DATA_CHECKS))
582 if (SDDS_dataset->layout.n_columns && (!SDDS_dataset->row_flag || !SDDS_dataset->data)) {
583 sprintf(buffer,
"tabular data is invalid in %s (columns but no row flags or data array)", caller);
587 if (SDDS_dataset->layout.n_columns == 0 && SDDS_dataset->n_rows) {
588 sprintf(buffer,
"tabular data is invalid in %s (no columns present but nonzero row count)", caller);
592 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
593 if (!SDDS_dataset->data[i]) {
594 sprintf(buffer,
"tabular data is invalid in %s (null data pointer for column %" PRId64
")", caller, i);
622 return calloc(nelem, elem_size);
687 return (realloc(old_ptr, new_size));
717 new_ptr = calloc(new_size, 1);
719 new_ptr = realloc(old_ptr, new_size);
720 memset((
char *)new_ptr + old_size, 0, new_size - old_size);
756 if ((percent = strchr(s,
'%'))) {
757 if (*(percent + 1) !=
'%')
762 if (!percent || !*++percent)
771 if ((len = strcspn(s,
"fegEG")) == strlen(s))
775 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
780 if ((len = strcspn(s,
"d")) == strlen(s))
786 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
791 if ((len = strcspn(s,
"u")) == strlen(s))
797 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
801 if ((len = strcspn(s,
"d")) == strlen(s))
803 if (*(s + len - 1) !=
'h')
807 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
811 if ((len = strcspn(s,
"u")) == strlen(s))
813 if (*(s + len - 1) !=
'h')
817 if ((tmp = strspn(s,
"-+.0123456789 ")) < len)
821 if ((len = strcspn(s,
"s")) == strlen(s))
825 if ((tmp = strspn(s,
"-0123456789")) < len)
829 if ((len = strcspn(s,
"c")) == strlen(s))
860 if (!(*target =
SDDS_Malloc(
sizeof(**target) * (strlen(source) + 1))))
862 strcpy(*target, source);
889 SDDS_SetError(
"Unable to get associate definition--name is NULL (SDDS_GetAssociateDefinition)");
892 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
893 if (strcmp(SDDS_dataset->layout.associate_definition[i].name, name) == 0) {
895 SDDS_SetError(
"Unable to get associate definition--copy failure (SDDS_GetAssociateDefinition)");
922 return (*target = NULL);
926 (*target)->sdds = source->sdds;
948 if (!source->filename)
950 free(source->filename);
953 if (source->description)
954 free(source->description);
955 if (source->contents)
956 free(source->contents);
984 SDDS_SetError(
"Unable to get column definition--name is NULL (SDDS_GetColumnDefinition)");
990 SDDS_SetError(
"Unable to get column definition--copy failure (SDDS_GetColumnDefinition)");
1016 return (*target = NULL);
1021 (*target)->type = source->type;
1022 (*target)->field_length = source->field_length;
1023 (*target)->definition_mode = source->definition_mode;
1024 (*target)->memory_number = source->memory_number;
1043 if (!source || !source->name)
1047 free(source->symbol);
1049 free(source->units);
1050 if (source->description)
1051 free(source->description);
1052 if (source->format_string)
1053 free(source->format_string);
1081 SDDS_SetError(
"Unable to get parameter definition--name is NULL (SDDS_GetParameterDefinition)");
1087 SDDS_SetError(
"Unable to get parameter definition--copy failure (SDDS_GetParameterDefinition)");
1113 return (*target = NULL);
1119 (*target)->type = source->type;
1120 (*target)->definition_mode = source->definition_mode;
1121 (*target)->memory_number = source->memory_number;
1140 if (!source || !source->name)
1144 free(source->symbol);
1146 free(source->units);
1147 if (source->description)
1148 free(source->description);
1149 if (source->format_string)
1150 free(source->format_string);
1151 if (source->fixed_value)
1152 free(source->fixed_value);
1180 SDDS_SetError(
"Unable to get array definition--name is NULL (SDDS_GetArrayDefinition)");
1186 SDDS_SetError(
"Unable to get array definition--copy failure (SDDS_GetArrayDefinition)");
1212 return (*target = NULL);
1218 (*target)->type = source->type;
1219 (*target)->field_length = source->field_length;
1220 (*target)->dimensions = source->dimensions;
1244 free(source->symbol);
1246 free(source->units);
1247 if (source->description)
1248 free(source->description);
1249 if (source->format_string)
1250 free(source->format_string);
1251 if (source->group_name)
1252 free(source->group_name);
1316 SDDS_SetError(
"Unable to get column index--name is NULL (SDDS_GetColumnIndex)");
1320 if ((i = binaryIndexSearch((
void **)SDDS_dataset->layout.column_index, SDDS_dataset->layout.n_columns, &key,
SDDS_CompareIndexedNames, 0)) < 0)
1322 return SDDS_dataset->layout.column_index[i]->index;
1345 SDDS_SetError(
"Unable to get parameter index--name is NULL (SDDS_GetParameterIndex)");
1349 if ((i = binaryIndexSearch((
void **)SDDS_dataset->layout.parameter_index, SDDS_dataset->layout.n_parameters, &key,
SDDS_CompareIndexedNames, 0)) < 0)
1351 return SDDS_dataset->layout.parameter_index[i]->index;
1374 SDDS_SetError(
"Unable to get array index--name is NULL (SDDS_GetArrayIndex)");
1378 if ((i = binaryIndexSearch((
void **)SDDS_dataset->layout.array_index, SDDS_dataset->layout.n_arrays, &key,
SDDS_CompareIndexedNames, 0)) < 0)
1380 return SDDS_dataset->layout.array_index[i]->index;
1401 SDDS_SetError(
"Unable to get associate index--name is NULL (SDDS_GetAssociateIndex)");
1404 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
1405 if (strcmp(SDDS_dataset->layout.associate_definition[i].name, name) == 0)
1426 if (isspace(*
string))
1452 while (fgets(s, slen, fp)) {
1453 if (s[0] != skip_char) {
1456 }
else if (s[1] ==
'#') {
1483 int32_t spaceLeft, length, newLine;
1484 char *sInsert, *fgetsReturn;
1489 while ((fgetsReturn = fgets(sInsert, spaceLeft, fp))) {
1490 if (newLine && sInsert[0] ==
'!')
1493 length = strlen(sInsert);
1494 if (sInsert[length - 1] !=
'\n' && !feof(fp)) {
1499 sInsert = *s + strlen(*s);
1529 while (lzma_gets(s, slen, lzmafp)) {
1530 if (s[0] != skip_char) {
1533 }
else if (s[1] ==
'#') {
1561 int32_t spaceLeft, length, newLine;
1562 char *sInsert, *fgetsReturn;
1567 while ((fgetsReturn = lzma_gets(sInsert, spaceLeft, lzmafp))) {
1568 if (newLine && sInsert[0] ==
'!')
1571 length = strlen(sInsert);
1572 if (sInsert[length - 1] !=
'\n' && !lzma_eof(lzmafp)) {
1577 sInsert = *s + strlen(*s);
1607char *fgetsGZipSkipComments(
SDDS_DATASET *SDDS_dataset,
char *s, int32_t slen, gzFile gzfp,
char skip_char ) {
1608 while (gzgets(gzfp, s, slen)) {
1609 if (s[0] != skip_char) {
1612 }
else if (s[1] ==
'#') {
1639char *fgetsGZipSkipCommentsResize(
SDDS_DATASET *SDDS_dataset,
char **s, int32_t *slen, gzFile gzfp,
char skip_char ) {
1640 int32_t spaceLeft, length, newLine;
1641 char *sInsert, *fgetsReturn;
1646 while ((fgetsReturn = gzgets(gzfp, sInsert, spaceLeft))) {
1647 if (newLine && sInsert[0] ==
'!')
1650 length = strlen(sInsert);
1651 if (sInsert[length - 1] !=
'\n' && !gzeof(gzfp)) {
1656 sInsert = *s + strlen(*s);
1681 int32_t length, hasNewline;
1689 if (s[length - 1] ==
'\n')
1694 if (*(s + 1) ==
'#')
1701 if ((*s ==
'"') && (s == s0 || *(s - 1) !=
'\\')) {
1702 while (*++s && (*s !=
'"' || *(s - 1) ==
'\\'))
1710 if (s != s0 && *(s - 1) ==
'\\')
1711 strcpy_ss(s - 1, s);
1741 char *ptr0, *ptr1, *escptr, *temp;
1759 if (*s ==
'\\' && *(s + 1) ==
'\\') {
1764 }
while (*s && (*s !=
'"' || (*(s - 1) ==
'\\' && (s - 1) != escptr)));
1773 if (*s ==
'"' && *(s - 1) !=
'\\') {
1774 while (*++s && !(*s ==
'"' && *(s - 1) !=
'\\'))
1777 }
while (*s && !isspace(*s));
1780 if ((int32_t)(s - ptr1) >= buflen)
1782 strncpy(buffer, ptr1, s - ptr1);
1783 buffer[s - ptr1] = 0;
1786 temp = malloc(
sizeof(
char) * (strlen(s) + 1));
1792 return ((int32_t)(s - ptr1));
1812int32_t
SDDS_GetToken2(
char *s,
char **st, int32_t *strlength,
char *buffer, int32_t buflen) {
1813 char *ptr0, *ptr1, *escptr;
1831 if (*s ==
'\\' && *(s + 1) ==
'\\') {
1836 }
while (*s && (*s !=
'"' || (*(s - 1) ==
'\\' && (s - 1) != escptr)));
1845 if (*s ==
'"' && *(s - 1) !=
'\\') {
1846 while (*++s && !(*s ==
'"' && *(s - 1) !=
'\\'))
1849 }
while (*s && !isspace(*s));
1852 if ((int32_t)(s - ptr1) >= buflen)
1854 strncpy(buffer, ptr1, s - ptr1);
1855 buffer[s - ptr1] = 0;
1859 *strlength -= s - ptr0;
1862 return ((int32_t)(s - ptr1));
1881 if (!
string || (i = strlen(
string)) > length)
1903 char *buffer = NULL;
1906 buffer = trealloc(buffer,
sizeof(*buffer) * (4 * (strlen(s) + 1)));
1910 if (*ptr == quote_char && (ptr == s || *(ptr - 1) !=
'\\'))
1936 if (*ptr == quote_char && ptr != s && *(ptr - 1) ==
'\\')
1937 strcpy(ptr - 1, ptr);
1959 if (*
string == cc && (
string == s0 || *(
string - 1) !=
'\\')) {
1960 ptr =
string + strlen(
string) + 1;
1961 while (ptr !=
string) {
1987 memset(mem, 0, n_bytes);
2045 short short_val, short_dval, *short_ptr;
2046 unsigned short ushort_val, ushort_dval, *ushort_ptr;
2047 int32_t long_val, long_dval, *long_ptr;
2048 uint32_t ulong_val, ulong_dval, *ulong_ptr;
2049 int64_t long64_val, long64_dval, *long64_ptr;
2050 uint64_t ulong64_val, ulong64_dval, *ulong64_ptr;
2051 float float_val, float_dval, *float_ptr;
2052 double double_val, double_dval, *double_ptr;
2053 long double longdouble_val, longdouble_dval, *longdouble_ptr;
2054 char char_val, *char_ptr;
2057 va_start(argptr, data_type);
2058 switch (data_type) {
2060 short_val = (short)va_arg(argptr,
int);
2061 short_dval = (short)va_arg(argptr,
int);
2062 short_ptr = (
short *)mem;
2063 for (i = 0; i < n_elements; i++, short_val += short_dval)
2064 *short_ptr++ = short_val;
2067 ushort_val = (
unsigned short)va_arg(argptr,
int);
2068 ushort_dval = (
unsigned short)va_arg(argptr,
int);
2069 ushort_ptr = (
unsigned short *)mem;
2070 for (i = 0; i < n_elements; i++, ushort_val += ushort_dval)
2071 *ushort_ptr++ = ushort_val;
2074 long_val = (int32_t)va_arg(argptr, int32_t);
2075 long_dval = (int32_t)va_arg(argptr, int32_t);
2076 long_ptr = (int32_t *)mem;
2077 for (i = 0; i < n_elements; i++, long_val += long_dval)
2078 *long_ptr++ = long_val;
2081 ulong_val = (uint32_t)va_arg(argptr, uint32_t);
2082 ulong_dval = (uint32_t)va_arg(argptr, uint32_t);
2083 ulong_ptr = (uint32_t *)mem;
2084 for (i = 0; i < n_elements; i++, ulong_val += ulong_dval)
2085 *ulong_ptr++ = ulong_val;
2088 long64_val = (int64_t)va_arg(argptr, int64_t);
2089 long64_dval = (int64_t)va_arg(argptr, int64_t);
2090 long64_ptr = (int64_t *)mem;
2091 for (i = 0; i < n_elements; i++, long64_val += long64_dval)
2092 *long64_ptr++ = long64_val;
2095 ulong64_val = (uint64_t)va_arg(argptr, uint32_t);
2096 ulong64_dval = (uint64_t)va_arg(argptr, uint32_t);
2097 ulong64_ptr = (uint64_t *)mem;
2098 for (i = 0; i < n_elements; i++, ulong64_val += ulong64_dval)
2099 *ulong64_ptr++ = ulong64_val;
2102 float_val = (float)va_arg(argptr,
double);
2103 float_dval = (float)va_arg(argptr,
double);
2104 float_ptr = (
float *)mem;
2105 for (i = 0; i < n_elements; i++, float_val += float_dval)
2106 *float_ptr++ = float_val;
2109 double_val = (double)va_arg(argptr,
double);
2110 double_dval = (double)va_arg(argptr,
double);
2111 double_ptr = (
double *)mem;
2112 for (i = 0; i < n_elements; i++, double_val += double_dval)
2113 *double_ptr++ = double_val;
2116 longdouble_val = (
long double)va_arg(argptr,
long double);
2117 longdouble_dval = (
long double)va_arg(argptr,
long double);
2118 longdouble_ptr = (
long double *)mem;
2119 for (i = 0; i < n_elements; i++, longdouble_val += longdouble_dval)
2120 *longdouble_ptr++ = longdouble_val;
2123 char_val = (char)va_arg(argptr,
int);
2124 short_dval = (short)va_arg(argptr,
int);
2125 char_ptr = (
char *)mem;
2126 for (i = 0; i < n_elements; i++, char_val += short_dval)
2127 *char_ptr++ = char_val;
2130 SDDS_SetError(
"Unable to set memory--unknown or invalid data type (SDDS_SetMemory)");
2156 if (index < 0 || index >= SDDS_dataset->layout.n_columns) {
2157 SDDS_SetError(
"Unable to get column type--column index is out of range (SDDS_GetColumnType)");
2160 return (SDDS_dataset->layout.column_definition[index].type);
2180 if ((index =
SDDS_GetColumnIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_columns) {
2181 SDDS_SetError(
"Unable to get column type--column index is out of range (SDDS_GetNamedColumnType)");
2184 return (SDDS_dataset->layout.column_definition[index].type);
2205 if (index < 0 || index >= SDDS_dataset->layout.n_arrays) {
2206 SDDS_SetError(
"Unable to get array type--array index is out of range (SDDS_GetArrayType)");
2209 return (SDDS_dataset->layout.array_definition[index].type);
2229 if ((index =
SDDS_GetArrayIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_arrays) {
2230 SDDS_SetError(
"Unable to get array type--array index is out of range (SDDS_GetNamedArrayType)");
2233 return (SDDS_dataset->layout.array_definition[index].type);
2254 if (index < 0 || index >= SDDS_dataset->layout.n_parameters) {
2255 SDDS_SetError(
"Unable to get parameter type--parameter index is out of range (SDDS_GetParameterType)");
2258 return (SDDS_dataset->layout.parameter_definition[index].type);
2278 if ((index =
SDDS_GetParameterIndex(SDDS_dataset, name)) < 0 || index >= SDDS_dataset->layout.n_parameters) {
2279 SDDS_SetError(
"Unable to get parameter type--parameter index is out of range (SDDS_GetNamedParameterType)");
2282 return (SDDS_dataset->layout.parameter_definition[index].type);
2382 while (isspace(*ptr))
2386 ptr = s + strlen(s) - 1;
2387 while (isspace(*ptr))
2432 if (!SDDS_dataset->column_flag)
2434 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2435 if (SDDS_dataset->column_flag[i] && strcmp(name, SDDS_dataset->layout.column_definition[i].name) == 0)
2466 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_columns))) {
2467 SDDS_SetError(
"Unable to get column names--allocation failure (SDDS_GetColumnNames)");
2470 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2471 if (!SDDS_dataset->column_flag || SDDS_dataset->column_flag[i]) {
2472 if (!
SDDS_CopyString(name + *number, SDDS_dataset->layout.column_definition[i].name)) {
2506 *number = SDDS_dataset->layout.n_parameters;
2507 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_parameters))) {
2508 SDDS_SetError(
"Unable to get parameter names--allocation failure (SDDS_GetParameterNames)");
2511 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++) {
2512 if (!
SDDS_CopyString(name + i, SDDS_dataset->layout.parameter_definition[i].name)) {
2544 *number = SDDS_dataset->layout.n_arrays;
2545 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_arrays))) {
2546 SDDS_SetError(
"Unable to get array names--allocation failure (SDDS_GetArrayNames)");
2549 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++) {
2550 if (!
SDDS_CopyString(name + i, SDDS_dataset->layout.array_definition[i].name)) {
2582 if (!(name = (
char **)
SDDS_Malloc(
sizeof(*name) * SDDS_dataset->layout.n_associates))) {
2583 SDDS_SetError(
"Unable to get associate names--allocation failure (SDDS_GetAssociateNames)");
2586 *number = SDDS_dataset->layout.n_associates;
2587 for (i = 0; i < SDDS_dataset->layout.n_associates; i++) {
2588 if (!
SDDS_CopyString(name + i, SDDS_dataset->layout.associate_definition[i].name)) {
2628void *
SDDS_CastValue(
void *data, int64_t index, int32_t data_type, int32_t desired_type,
void *memory) {
2629 long long integer_value;
2630 long double fp_value;
2633 if (data_type == desired_type) {
2637 switch (data_type) {
2639 integer_value = *((
short *)data + index);
2640 fp_value = integer_value;
2643 integer_value = *((
unsigned short *)data + index);
2644 fp_value = integer_value;
2647 integer_value = *((int32_t *)data + index);
2648 fp_value = integer_value;
2651 integer_value = *((uint32_t *)data + index);
2652 fp_value = integer_value;
2655 integer_value = *((int64_t *)data + index);
2656 fp_value = integer_value;
2659 integer_value = *((uint64_t *)data + index);
2660 fp_value = integer_value;
2663 integer_value = *((
unsigned char *)data + index);
2664 fp_value = integer_value;
2667 fp_value = *((
float *)data + index);
2668 integer_value = fp_value;
2671 fp_value = *((
double *)data + index);
2672 integer_value = fp_value;
2675 fp_value = *((
long double *)data + index);
2676 integer_value = fp_value;
2681 switch (desired_type) {
2683 *((
char *)memory) = integer_value;
2686 *((
short *)memory) = integer_value;
2689 *((
unsigned short *)memory) = integer_value;
2692 *((int32_t *)memory) = integer_value;
2695 *((uint32_t *)memory) = integer_value;
2698 *((int64_t *)memory) = integer_value;
2701 *((uint64_t *)memory) = integer_value;
2704 *((
float *)memory) = fp_value;
2707 *((
double *)memory) = fp_value;
2710 *((
long double *)memory) = fp_value;
2713 SDDS_SetError(
"The impossible has happened (SDDS_CastValue)");
2743 if (!(data = (
void **)
SDDS_Malloc(
sizeof(*data) * dim1)))
2745 for (i = 0; i < dim1; i++)
2746 if (!(data[i] = (
void *)calloc(dim2, size)))
2770 if (array->definition) {
2771 if ((array->definition->type ==
SDDS_STRING) && (array->data)) {
2772 char **str = (
char **)array->data;
2773 for (i = 0; i < array->elements; i++) {
2780 if (array->definition && array->pointer)
2784 array->pointer = array->data = NULL;
2785 if (array->dimension)
2786 free(array->dimension);
2787 if (array->definition)
2789 array->definition = NULL;
2812 for (i = 0; i < dim1; i++)
2838 if (!source || !target)
2840 while (n_strings--) {
2869 for (i = 0; i < strings; i++)
2902 int32_t i, elements;
2903 static int32_t depth = 0;
2908 sprintf(s,
"Unable to make pointer array--NULL data array (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
2912 if (!dimension || !dimensions) {
2913 sprintf(s,
"Unable to make pointer array--NULL or zero-length dimension array (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
2918 sprintf(s,
"Unable to make pointer array--invalid data size (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
2922 if (dimensions == 1) {
2927 for (i = 0; i < dimensions - 1; i++)
2928 elements *= dimension[i];
2929 if (!(pointer = (
void **)
SDDS_Malloc(
sizeof(
void *) * elements))) {
2930 sprintf(s,
"Unable to make pointer array--allocation failure (SDDS_MakePointerArrayRecursively, recursion %" PRId32
")", depth);
2934 for (i = 0; i < elements; i++)
2935 pointer[i] = (
char *)data + i * size * dimension[dimensions - 1];
2975 SDDS_SetError(
"Unable to make pointer array--NULL data array (SDDS_MakePointerArray)");
2978 if (!dimension || !dimensions) {
2979 SDDS_SetError(
"Unable to make pointer array--NULL or zero-length dimension array (SDDS_MakePointerArray)");
2983 SDDS_SetError(
"Unable to make pointer array--unknown data type (SDDS_MakePointerArray)");
2986 for (i = 0; i < dimensions; i++)
2987 if (dimension[i] <= 0) {
2988 SDDS_SetError(
"Unable to make pointer array--number of elements invalid (SDDS_MakePointerArray)");
2991 if (dimensions == 1)
3017 if (!data || !dimension || !dimensions)
3019 if (dimensions > 1) {
3047 int32_t type, index;
3052 type = SDDS_dataset->layout.parameter_definition[index].type;
3054 SDDS_SetError(
"Unable to apply factor to non-numeric parameter (SDDS_ApplyFactorToParameter)");
3057 if (!SDDS_dataset->parameter) {
3058 SDDS_SetError(
"Unable to apply factor to parameter--no parameter data array (SDDS_ApplyFactorToParameter)");
3061 if (!(data = SDDS_dataset->parameter[index])) {
3062 SDDS_SetError(
"Unable to apply factor to parameter--no data array (SDDS_ApplyFactorToParameter)");
3067 *((
short *)data) *= factor;
3070 *((
unsigned short *)data) *= factor;
3073 *((int32_t *)data) *= factor;
3076 *((uint32_t *)data) *= factor;
3079 *((int64_t *)data) *= factor;
3082 *((uint64_t *)data) *= factor;
3085 *((
char *)data) *= factor;
3088 *((
float *)data) *= factor;
3091 *((
double *)data) *= factor;
3094 *((
long double *)data) *= factor;
3124 int32_t type, index;
3130 type = SDDS_dataset->layout.column_definition[index].type;
3132 SDDS_SetError(
"Unable to apply factor to non-numeric column (SDDS_ApplyFactorToColumn)");
3135 data = SDDS_dataset->data[index];
3136 for (i = 0; i < SDDS_dataset->n_rows; i++) {
3139 *((
short *)data + i) *= factor;
3142 *((
unsigned short *)data + i) *= factor;
3145 *((int32_t *)data + i) *= factor;
3148 *((uint32_t *)data + i) *= factor;
3151 *((int64_t *)data + i) *= factor;
3154 *((uint64_t *)data + i) *= factor;
3157 *((
char *)data + i) *= factor;
3160 *((
float *)data + i) *= factor;
3163 *((
double *)data + i) *= factor;
3166 *((
long double *)data + i) *= factor;
3193 ptr = s + strlen(s);
3224 if (!SDDS_dataset) {
3225 SDDS_SetError(
"NULL SDDS_DATASET passed (SDDS_ForceInactive)");
3228 SDDS_dataset->layout.fp = NULL;
3251 if (!SDDS_dataset) {
3255 if (!SDDS_dataset->layout.fp)
3283#if defined(F_TEST) && ALLOW_FILE_LOCKING
3285 if (!(fp = fopen(filename,
"rb")))
3287 if (lockf(fileno(fp), F_TEST, 0) == -1) {
3327#if defined(F_TEST) && ALLOW_FILE_LOCKING
3329 if (lockf(fileno(fp), F_TEST, 0) == -1) {
3330 sprintf(s,
"Unable to access file %s--file is locked (%s)", filename, caller);
3334 if (lockf(fileno(fp), F_TLOCK, 0) == -1) {
3335 sprintf(s,
"Unable to establish lock on file %s (%s)", filename, caller);
3374 fprintf(stderr,
"Unable to break into locked file\n");
3378 int i = 1000, j = 0;
3382 if (strlen(filename) > 500) {
3383 fprintf(stderr,
"Unable to break into locked file\n");
3388 for (i = 1000; i < 1020; i++) {
3389 sprintf(buffer,
"%s.bl%d", filename, i);
3390 if ((fp = fopen(buffer,
"r"))) {
3400 fprintf(stderr,
"Unable to break into locked file\n");
3406 sprintf(buffer,
"cp -p %s %s.bl%d", filename, filename, j);
3407 if (system(buffer) == -1) {
3408 fprintf(stderr,
"Unable to break into locked file\n");
3413 sprintf(buffer,
"mv -f %s.bl%d %s", filename, j, filename);
3414 if (system(buffer) == -1) {
3415 fprintf(stderr,
"Unable to break into locked file\n");
3493 static int32_t flags = 0;
3494 static int32_t *flag = NULL;
3495 char **name, *string, *match_string, *ptr, *exclude_string;
3497 int32_t retval, requiredType;
3498 int32_t i, j, n_names, index, matches;
3499 int32_t local_memory;
3500 char buffer[SDDS_MAXLINE];
3504 match_string = exclude_string = NULL;
3505 n_names = requiredType = local_memory = logic = 0;
3514 va_start(argptr, typeMode);
3515 if (typeMode == FIND_SPECIFIED_TYPE)
3516 requiredType = va_arg(argptr, int32_t);
3517 switch (matchMode) {
3518 case SDDS_NAME_ARRAY:
3520 n_names = va_arg(argptr, int32_t);
3521 name = va_arg(argptr,
char **);
3523 case SDDS_NAMES_STRING:
3527 ptr = va_arg(argptr,
char *);
3529 while ((ptr = strchr(
string,
',')))
3533 SDDS_SetError(
"Unable to process column selection--memory allocation failure (SDDS_MatchColumns)");
3541 case SDDS_NAME_STRINGS:
3545 while ((
string = va_arg(argptr,
char *))) {
3546 if (!(name =
SDDS_Realloc(name,
sizeof(*name) * (n_names + 1)))) {
3547 SDDS_SetError(
"Unable to process column selection--memory allocation failure (SDDS_MatchColumns)");
3551 name[n_names++] = string;
3554 case SDDS_MATCH_STRING:
3557 if (!(
string = va_arg(argptr,
char *))) {
3558 SDDS_SetError(
"Unable to process column selection--invalid matching string (SDDS_MatchColumns)");
3562 match_string = expand_ranges(
string);
3563 logic = va_arg(argptr, int32_t);
3565 case SDDS_MATCH_EXCLUDE_STRING:
3568 if (!(
string = va_arg(argptr,
char *))) {
3569 SDDS_SetError(
"Unable to process column selection--invalid matching string (SDDS_MatchColumns)");
3573 match_string = expand_ranges(
string);
3574 if (!(
string = va_arg(argptr,
char *))) {
3575 SDDS_SetError(
"Unable to process column exclusion--invalid matching string (SDDS_MatchColumns)");
3579 exclude_string = expand_ranges(
string);
3580 logic = va_arg(argptr, int32_t);
3583 SDDS_SetError(
"Unable to process column selection--unknown match mode (SDDS_MatchColumns)");
3592 SDDS_SetError(
"Unable to process column selection--no names in call (SDDS_MatchColumns)");
3596 if (SDDS_dataset->layout.n_columns != flags) {
3597 flags = SDDS_dataset->layout.n_columns;
3600 if (!(flag = (int32_t *)calloc(flags,
sizeof(*flag)))) {
3601 SDDS_SetError(
"Memory allocation failure (SDDS_MatchColumns)");
3606 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
3607 for (i = 0; i < n_names; i++) {
3614 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
3615 if (
SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.column_definition[i].name, match_string), logic)) {
3616 if (exclude_string != NULL) {
3617 if (
SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.column_definition[i].name, exclude_string), logic))
3626 fprintf(stderr,
"no logic match of %s to %s\n", SDDS_dataset->layout.column_definition[i].name, match_string);
3635 free(exclude_string);
3637 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3638 fprintf(stderr,
"flag[%" PRId32
"] = %" PRId32
" : %s\n", i, flag[i], SDDS_dataset->layout.column_definition[i].name);
3641 if (local_memory == 2) {
3642 for (i = 0; i < n_names; i++)
3645 if (local_memory >= 1)
3649 case FIND_SPECIFIED_TYPE:
3650 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3651 if (SDDS_dataset->layout.column_definition[i].type != requiredType)
3654 case FIND_NUMERIC_TYPE:
3655 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3659 case FIND_FLOATING_TYPE:
3660 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3664 case FIND_INTEGER_TYPE:
3665 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3673 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
3675 fprintf(stderr,
"column %s matched\n", SDDS_dataset->layout.column_definition[i].name);
3678 for (i = matches = 0; i < SDDS_dataset->layout.n_columns; i++) {
3682 if (!matches || !nameReturn)
3684 if (!((*nameReturn) = (
char **)
SDDS_Malloc(matches *
sizeof(**nameReturn)))) {
3685 SDDS_SetError(
"Memory allocation failure (SDDS_MatchColumns)");
3688 for (i = j = 0; i < SDDS_dataset->layout.n_columns; i++) {
3690 if (!
SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.column_definition[i].name)) {
3771 static int32_t flags = 0, *flag = NULL;
3772 char **name, *string, *match_string, *ptr, *exclude_string;
3774 int32_t i, j, index, n_names, retval, requiredType, matches;
3776 int32_t local_memory;
3777 char buffer[SDDS_MAXLINE];
3781 match_string = exclude_string = NULL;
3782 n_names = requiredType = local_memory = logic = 0;
3791 va_start(argptr, typeMode);
3792 if (typeMode == FIND_SPECIFIED_TYPE)
3793 requiredType = va_arg(argptr, int32_t);
3794 switch (matchMode) {
3795 case SDDS_NAME_ARRAY:
3797 n_names = va_arg(argptr, int32_t);
3798 name = va_arg(argptr,
char **);
3800 case SDDS_NAMES_STRING:
3804 ptr = va_arg(argptr,
char *);
3806 while ((ptr = strchr(
string,
',')))
3810 SDDS_SetError(
"Unable to process parameter selection--memory allocation failure (SDDS_MatchParameters)");
3818 case SDDS_NAME_STRINGS:
3822 while ((
string = va_arg(argptr,
char *))) {
3823 if (!(name =
SDDS_Realloc(name,
sizeof(*name) * (n_names + 1)))) {
3824 SDDS_SetError(
"Unable to process parameter selection--memory allocation failure (SDDS_MatchParameters)");
3828 name[n_names++] = string;
3831 case SDDS_MATCH_STRING:
3834 if (!(
string = va_arg(argptr,
char *))) {
3835 SDDS_SetError(
"Unable to process parameter selection--invalid matching string (SDDS_MatchParameters)");
3839 match_string = expand_ranges(
string);
3840 logic = va_arg(argptr, int32_t);
3842 case SDDS_MATCH_EXCLUDE_STRING:
3845 if (!(
string = va_arg(argptr,
char *))) {
3846 SDDS_SetError(
"Unable to process parameter selection--invalid matching string (SDDS_MatchParameters)");
3850 match_string = expand_ranges(
string);
3851 if (!(
string = va_arg(argptr,
char *))) {
3852 SDDS_SetError(
"Unable to process parameter exclusion--invalid matching string (SDDS_MatchParameters)");
3856 exclude_string = expand_ranges(
string);
3857 logic = va_arg(argptr, int32_t);
3860 SDDS_SetError(
"Unable to process parameter selection--unknown match mode (SDDS_MatchParameters)");
3869 SDDS_SetError(
"Unable to process parameter selection--no names in call (SDDS_MatchParameters)");
3873 if (SDDS_dataset->layout.n_parameters != flags) {
3874 flags = SDDS_dataset->layout.n_parameters;
3877 if (!(flag = (int32_t *)calloc(flags,
sizeof(*flag)))) {
3878 SDDS_SetError(
"Memory allocation failure (SDDS_MatchParameters)");
3883 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
3884 for (i = 0; i < n_names; i++) {
3891 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++) {
3892 if (
SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.parameter_definition[i].name, match_string), logic)) {
3893 if (exclude_string != NULL) {
3894 if (
SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.parameter_definition[i].name, exclude_string), logic))
3903 fprintf(stderr,
"no logic match of %s to %s\n", SDDS_dataset->layout.parameter_definition[i].name, match_string);
3912 free(exclude_string);
3914 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3915 fprintf(stderr,
"flag[%" PRId32
"] = %" PRId32
" : %s\n", i, flag[i], SDDS_dataset->layout.parameter_definition[i].name);
3918 if (local_memory == 2) {
3919 for (i = 0; i < n_names; i++)
3922 if (local_memory >= 1)
3926 case FIND_SPECIFIED_TYPE:
3927 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3928 if (SDDS_dataset->layout.parameter_definition[i].type != requiredType)
3931 case FIND_NUMERIC_TYPE:
3932 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3936 case FIND_FLOATING_TYPE:
3937 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3941 case FIND_INTEGER_TYPE:
3942 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3950 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
3952 fprintf(stderr,
"parameter %s matched\n", SDDS_dataset->layout.parameter_definition[i].name);
3955 for (i = matches = 0; i < SDDS_dataset->layout.n_parameters; i++) {
3959 if (!matches || !nameReturn)
3961 if (!((*nameReturn) = (
char **)
SDDS_Malloc(matches *
sizeof(**nameReturn)))) {
3962 SDDS_SetError(
"Memory allocation failure (SDDS_MatchParameters)");
3965 for (i = j = 0; i < SDDS_dataset->layout.n_parameters; i++) {
3967 if (!
SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.parameter_definition[i].name)) {
3968 SDDS_SetError(
"String copy failure (SDDS_MatchParameters)");
4049 static int32_t flags = 0, *flag = NULL;
4050 char **name, *string, *match_string, *ptr, *exclude_string;
4052 int32_t i, j, index, n_names, retval, requiredType, matches;
4054 int32_t local_memory;
4055 char buffer[SDDS_MAXLINE];
4059 match_string = exclude_string = NULL;
4060 n_names = requiredType = local_memory = logic = 0;
4069 va_start(argptr, typeMode);
4070 if (typeMode == FIND_SPECIFIED_TYPE)
4071 requiredType = va_arg(argptr, int32_t);
4072 switch (matchMode) {
4073 case SDDS_NAME_ARRAY:
4075 n_names = va_arg(argptr, int32_t);
4076 name = va_arg(argptr,
char **);
4078 case SDDS_NAMES_STRING:
4082 ptr = va_arg(argptr,
char *);
4084 while ((ptr = strchr(
string,
',')))
4088 SDDS_SetError(
"Unable to process array selection--memory allocation failure (SDDS_MatchArrays)");
4096 case SDDS_NAME_STRINGS:
4100 while ((
string = va_arg(argptr,
char *))) {
4101 if (!(name =
SDDS_Realloc(name,
sizeof(*name) * (n_names + 1)))) {
4102 SDDS_SetError(
"Unable to process array selection--memory allocation failure (SDDS_MatchArrays)");
4106 name[n_names++] = string;
4109 case SDDS_MATCH_STRING:
4112 if (!(
string = va_arg(argptr,
char *))) {
4113 SDDS_SetError(
"Unable to process array selection--invalid matching string (SDDS_MatchArrays)");
4117 match_string = expand_ranges(
string);
4118 logic = va_arg(argptr, int32_t);
4120 case SDDS_MATCH_EXCLUDE_STRING:
4123 if (!(
string = va_arg(argptr,
char *))) {
4124 SDDS_SetError(
"Unable to process array selection--invalid matching string (SDDS_MatchArrays)");
4128 match_string = expand_ranges(
string);
4129 if (!(
string = va_arg(argptr,
char *))) {
4130 SDDS_SetError(
"Unable to process array exclusion--invalid matching string (SDDS_MatchArrays)");
4134 exclude_string = expand_ranges(
string);
4135 logic = va_arg(argptr, int32_t);
4138 SDDS_SetError(
"Unable to process array selection--unknown match mode (SDDS_MatchArrays)");
4147 SDDS_SetError(
"Unable to process array selection--no names in call (SDDS_MatchArrays)");
4151 if (SDDS_dataset->layout.n_arrays != flags) {
4152 flags = SDDS_dataset->layout.n_arrays;
4155 if (!(flag = (int32_t *)calloc(flags,
sizeof(*flag)))) {
4156 SDDS_SetError(
"Memory allocation failure (SDDS_MatchArrays)");
4161 if ((matchMode != SDDS_MATCH_STRING) && (matchMode != SDDS_MATCH_EXCLUDE_STRING)) {
4162 for (i = 0; i < n_names; i++) {
4169 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4170 if (
SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.array_definition[i].name, match_string), logic)) {
4171 if (exclude_string != NULL) {
4172 if (
SDDS_Logic(flag[i], wild_match(SDDS_dataset->layout.array_definition[i].name, exclude_string), logic))
4181 fprintf(stderr,
"no logic match of %s to %s\n", SDDS_dataset->layout.array_definition[i].name, match_string);
4190 free(exclude_string);
4192 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4193 fprintf(stderr,
"flag[%" PRId32
"] = %" PRId32
" : %s\n", i, flag[i], SDDS_dataset->layout.array_definition[i].name);
4196 if (local_memory == 2) {
4197 for (i = 0; i < n_names; i++)
4200 if (local_memory >= 1)
4204 case FIND_SPECIFIED_TYPE:
4205 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4206 if (SDDS_dataset->layout.array_definition[i].type != requiredType)
4209 case FIND_NUMERIC_TYPE:
4210 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4214 case FIND_FLOATING_TYPE:
4215 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4219 case FIND_INTEGER_TYPE:
4220 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4228 for (i = 0; i < SDDS_dataset->layout.n_arrays; i++)
4230 fprintf(stderr,
"array %s matched\n", SDDS_dataset->layout.array_definition[i].name);
4233 for (i = matches = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4237 if (!matches || !nameReturn)
4239 if (!((*nameReturn) = (
char **)
SDDS_Malloc(matches *
sizeof(**nameReturn)))) {
4240 SDDS_SetError(
"Memory allocation failure (SDDS_MatchArrays)");
4243 for (i = j = 0; i < SDDS_dataset->layout.n_arrays; i++) {
4245 if (!
SDDS_CopyString((*nameReturn) + j, SDDS_dataset->layout.array_definition[i].name)) {
4318 int32_t error, type, thisType;
4320 char *name, *buffer;
4322 va_start(argptr, mode);
4326 if (mode == FIND_SPECIFIED_TYPE)
4327 type = va_arg(argptr, int32_t);
4328 while ((name = va_arg(argptr,
char *))) {
4331 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
4333 SDDS_SetError(
"unable to return string from SDDS_FindColumn");
4405 int32_t index, error, type, thisType;
4407 char *name, *buffer;
4409 va_start(argptr, mode);
4413 if (mode == FIND_SPECIFIED_TYPE)
4414 type = va_arg(argptr, int32_t);
4415 while ((name = va_arg(argptr,
char *))) {
4418 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
4420 SDDS_SetError(
"unable to return string from SDDS_FindParameter");
4492 int32_t index, error, type, thisType;
4494 char *name, *buffer;
4496 va_start(argptr, mode);
4500 if (mode == FIND_SPECIFIED_TYPE)
4501 type = va_arg(argptr, int32_t);
4502 while ((name = va_arg(argptr,
char *))) {
4505 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
4507 SDDS_SetError(
"unable to return string from SDDS_FindArray");
4566 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_NONEXISTENT));
4569 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4576 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4580 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4585 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4589 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGTYPE));
4594 return SDDS_CHECK_OKAY;
4597 SDDS_SetError(
"units field of column has wrong data type!");
4598 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4602 return (SDDS_CHECK_OKAY);
4603 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGUNITS));
4605 if (strcmp(units, units1) == 0) {
4607 return (SDDS_CHECK_OKAY);
4610 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"column", SDDS_CHECK_WRONGUNITS));
4657 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_NONEXISTENT));
4660 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4667 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4671 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4675 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4678 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGTYPE));
4683 return (SDDS_CHECK_OKAY);
4686 SDDS_SetError(
"units field of parameter has wrong data type!");
4687 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4691 return (SDDS_CHECK_OKAY);
4692 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGUNITS));
4694 if (strcmp(units, units1) == 0) {
4696 return (SDDS_CHECK_OKAY);
4699 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"parameter", SDDS_CHECK_WRONGUNITS));
4746 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_NONEXISTENT));
4749 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4756 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4760 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4764 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4767 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGTYPE));
4772 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
4776 return (SDDS_CHECK_OKAY);
4780 return (SDDS_CHECK_OKAY);
4781 return (SDDS_CHECK_OKAY);
4783 if (strcmp(units, units1) == 0) {
4785 return (SDDS_CHECK_OKAY);
4788 return (
SDDS_PrintCheckText(fp_message, name, units, type,
"array", SDDS_CHECK_WRONGUNITS));
4830int32_t
SDDS_PrintCheckText(FILE *fp,
char *name,
char *units, int32_t type,
char *class_name, int32_t error_code) {
4831 if (!fp || !name || !class_name)
4832 return (error_code);
4833 switch (error_code) {
4834 case SDDS_CHECK_OKAY:
4836 case SDDS_CHECK_NONEXISTENT:
4837 fprintf(fp,
"Problem with %s %s: nonexistent (%s)\n", class_name, name, registeredProgramName ? registeredProgramName :
"?");
4839 case SDDS_CHECK_WRONGTYPE:
4841 fprintf(fp,
"Problem with %s %s: wrong data type--expected %s (%s)\n", class_name, name,
SDDS_type_name[type - 1], registeredProgramName ? registeredProgramName :
"?");
4843 fprintf(fp,
"Problem with %s %s: wrong data type--expected numeric data (%s)\n", class_name, name, registeredProgramName ? registeredProgramName :
"?");
4845 fprintf(fp,
"Problem with %s %s: wrong data type--expected floating point data (%s)\n", class_name, name, registeredProgramName ? registeredProgramName :
"?");
4847 fprintf(fp,
"Problem with %s %s: wrong data type--expected integer data (%s)\n", class_name, name, registeredProgramName ? registeredProgramName :
"?");
4849 fprintf(fp,
"Problem with %s %s: invalid data type code seen---may be a programming error (%s)\n", class_name, name, registeredProgramName ? registeredProgramName :
"?");
4851 case SDDS_CHECK_WRONGUNITS:
4852 fprintf(fp,
"Problem with %s %s: wrong units--expected %s (%s)\n", class_name, name, units ? units :
"none", registeredProgramName ? registeredProgramName :
"?");
4855 fprintf(stderr,
"Problem with call to SDDS_PrintCheckText--invalid error code (%s)\n", registeredProgramName ? registeredProgramName :
"?");
4856 return (SDDS_CHECK_OKAY);
4858 return (error_code);
4891 layout = &SDDS_dataset->layout;
4892 orig_layout = &SDDS_dataset->original_layout;
4893 for (i = 0; i < layout->n_parameters; i++) {
4894 if (layout->parameter_definition[i].fixed_value)
4895 free(layout->parameter_definition[i].fixed_value);
4896 if (orig_layout->parameter_definition[i].fixed_value && (!layout->parameter_definition[i].fixed_value || orig_layout->parameter_definition[i].fixed_value != layout->parameter_definition[i].fixed_value))
4897 free(orig_layout->parameter_definition[i].fixed_value);
4898 orig_layout->parameter_definition[i].fixed_value = NULL;
4899 layout->parameter_definition[i].fixed_value = NULL;
4933 if (newmode == -SDDS_BINARY) {
4939 newmode = SDDS_BINARY;
4941 if (newmode != SDDS_ASCII && newmode != SDDS_BINARY) {
4945 if (newmode == SDDS_dataset->layout.data_mode.mode)
4947 if (!SDDS_dataset) {
4951 if (SDDS_dataset->page_number != 0 && (SDDS_dataset->page_number > 1 || SDDS_dataset->n_rows_written != 0)) {
4952 SDDS_SetError(
"Can't change the mode of a file that's been written to (SDDS_SetDataMode)");
4955 SDDS_dataset->layout.data_mode.mode = SDDS_dataset->original_layout.data_mode.mode = newmode;
4982 SDDS_SetError(
"passed size is not equal to expected size for SDDS_DATASET structure");
4983 sprintf(buffer,
"Passed size is %" PRId32
", library size is %" PRId32
"\n", size, (int32_t)
sizeof(
SDDS_DATASET));
5010 return page->layout.n_columns;
5033 return page->layout.n_parameters;
5056 return page->layout.n_arrays;
5152 if (*s >=
'0' && *s <=
'9') {
5155 while (++count <= 3 && *s >=
'0' && *s <=
'9')
5156 *ptr = 8 * (*ptr) + *s++ -
'0';
5168#define COMMENT_COMMANDS 3
5169static char *commentCommandName[COMMENT_COMMANDS] = {
5175static uint32_t commentCommandFlag[COMMENT_COMMANDS] = {
5176 SDDS_BIGENDIAN_SEEN,
5177 SDDS_LITTLEENDIAN_SEEN,
5178 SDDS_FIXED_ROWCOUNT_SEEN,
5202 return SDDS_dataset->layout.commentFlags;
5222 SDDS_dataset->layout.commentFlags = 0;
5252 char buffer[SDDS_MAXLINE];
5254 if (SDDS_dataset == NULL)
5257 for (i = 0; i < COMMENT_COMMANDS; i++) {
5258 if (strcmp(buffer, commentCommandName[i]) == 0) {
5259 SDDS_dataset->layout.commentFlags |= commentCommandFlag[i];
5345 int32_t index, type, thisType;
5349 va_start(argptr, mode);
5352 if (mode == FIND_SPECIFIED_TYPE)
5353 type = va_arg(argptr, int32_t);
5354 name = va_arg(argptr,
char *);
5357 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
5422 int32_t type, thisType;
5426 va_start(argptr, mode);
5429 if (mode == FIND_SPECIFIED_TYPE)
5430 type = va_arg(argptr, int32_t);
5431 name = va_arg(argptr,
char *);
5434 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
5498 int32_t index, type, thisType;
5502 va_start(argptr, mode);
5505 if (mode == FIND_SPECIFIED_TYPE)
5506 type = va_arg(argptr, int32_t);
5507 name = va_arg(argptr,
char *);
5510 if (mode == FIND_ANY_TYPE || (mode == FIND_SPECIFIED_TYPE && thisType == type) || (mode == FIND_NUMERIC_TYPE &&
SDDS_NUMERIC_TYPE(thisType)) || (mode == FIND_FLOATING_TYPE &&
SDDS_FLOATING_TYPE(thisType)) || (mode == FIND_INTEGER_TYPE &&
SDDS_INTEGER_TYPE(thisType))) {
5557 char **name, **selectedName, *ptr = NULL;
5558 int32_t names0 = 0, selected = 0, i, j;
5559 int32_t names32 = 0;
5561 name = selectedName = NULL;
5563 case SDDS_MATCH_COLUMN:
5565 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5567 case SDDS_MATCH_PARAMETER:
5569 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5572 case SDDS_MATCH_ARRAY:
5574 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
5578 SDDS_Bomb(
"Invalid match type provided.");
5581 for (i = 0; i < matches; i++) {
5582 if (has_wildcards(matchName[i])) {
5583 ptr = expand_ranges(matchName[i]);
5584 for (j = 0; j < names0; j++) {
5585 if (wild_match(name[j], ptr)) {
5586 selectedName =
SDDS_Realloc(selectedName,
sizeof(*selectedName) * (selected + 1));
5593 if (match_string(matchName[i], name, names0, EXACT_MATCH) < 0) {
5594 fprintf(stderr,
"%s not found in input file.\n", matchName[i]);
5597 selectedName =
SDDS_Realloc(selectedName,
sizeof(*selectedName) * (selected + 1));
5606 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.