35#include "match_string.h"
61 SDDS_SetError(
"Unable to process description--namelist text pointer is NULL (SDDS_ProcessDescription)");
64 switch (SDDS_dataset->layout.version) {
76 SDDS_SetError(
"Unable to process description--protocol version number is invalid (SDDS_ProcessDescription)");
92 SDDS_SetError(
"Unable to process column definition--namelist text pointer NULL (SDDS1_ProcessColumnDefinition)");
95 switch (SDDS_dataset->layout.version) {
107 SDDS_SetError(
"Unable to process column definition--protocol version number is invalid (SDDS_ProcessColumnDefinition)");
123 SDDS_SetError(
"Unable to process parameter definition--namelist text pointer NULL (SDDS_ProcessParameterDefinition)");
126 switch (SDDS_dataset->layout.version) {
138 SDDS_SetError(
"Unable to process parameter definition--protocol version number is invalid (SDDS_ProcessParameterDefinition)");
154 SDDS_SetError(
"Unable to process parameter definition--namelist text pointer NULL (SDDS_ProcessIncludeCommand)");
157 switch (SDDS_dataset->layout.version) {
169 SDDS_SetError(
"Unable to process parameter definition--protocol version number is invalid (SDDS_ProcessIncludeCommand)");
185 SDDS_SetError(
"Unable to process associate definition--namelist text pointer NULL (SDDS_ProcessAssociateDefinition)");
188 switch (SDDS_dataset->layout.version) {
200 SDDS_SetError(
"Unable to process associate definition--protocol version number is invalid (SDDS_ProcessAssociateDefinition)");
216 SDDS_SetError(
"Unable to process data mode--namelist text pointer is NULL (SDDS_ProcessDataMode)");
219 switch (SDDS_dataset->layout.version) {
231 SDDS_SetError(
"Unable to process data mode--protocol version number is invalid (SDDS_ProcessDataMode)");
247 SDDS_SetError(
"Unable to process array definition--namelist text pointer NULL (SDDS_ProcessArrayDefinition)");
250 switch (SDDS_dataset->layout.version) {
262 SDDS_SetError(
"Unable to process array definition--protocol version number is invalid (SDDS_ProcessArrayDefinition)");
292 if (!(ptr1 = strchr(s,
'&')) || !(ptr2 = strchr(ptr1,
' '))) {
297 if (strcmp(ptr1,
"&column") != 0) {
303 SDDS_dataset->layout.column_definition[SDDS_dataset->layout.n_columns - 1].definition_mode = mode;
332 if (!(ptr1 = strchr(s,
'&')) || !(ptr2 = strchr(ptr1,
' '))) {
337 if (strcmp(ptr1,
"¶meter") != 0) {
343 SDDS_dataset->layout.parameter_definition[SDDS_dataset->layout.n_parameters - 1].definition_mode = mode;
371 if (!(ptr1 = strchr(s,
'&')) || !(ptr2 = strchr(ptr1,
' '))) {
376 if (strcmp(ptr1,
"&array") != 0) {
410 if (!(ptr1 = strchr(s,
'&')) || !(ptr2 = strchr(ptr1,
' '))) {
415 if (strcmp(ptr1,
"&associate") != 0) {
448 *tag = *value = NULL;
449 while (*ptr ==
' ' || *ptr ==
',' || *ptr ==
'\t')
455 while (*ptr && *ptr !=
' ' && *ptr !=
'\t' && *ptr !=
'=')
460 while (*ptr ==
' ' || *ptr ==
'\t')
462 if (*ptr++ !=
'=' || !*ptr) {
463 sprintf(buffer,
"Namelist error: Field name %s ends string", *tag);
470 while (*ptr ==
' ' || *ptr ==
'\t')
473 sprintf(buffer,
"Namelist error: Field name %s ends string", *tag);
478 sprintf(buffer,
"Namelist error: Field name is blank");
483 if (*ptr ==
'"' && *(ptr - 1) !=
'\\') {
485 if (*ptr ==
'"' && *(ptr - 1) !=
'\\') {
491 while (*ptr && !(*ptr ==
'"' && *(ptr - 1) !=
'\\'))
493 if (*ptr ==
'"' && *(ptr - 1) !=
'\\')
497 while (*ptr !=
' ' && *ptr !=
',' && *ptr !=
'\t' && *ptr)
519 if ((length = strlen(s)) >= 4) {
520 ptr = s + length - 4;
522 if (*ptr ==
'&' && (ptr == s || *(ptr - 1) !=
'\\') && strncmp(ptr,
"&end", 4) == 0 && !
SDDS_IsQuoted(s, ptr,
'"')) {
536 while (*s && *s !=
' ')
552 for (i = 0; i < fieldInfos; i++) {
553 if (strcmp(tag, fieldInfo[i].name) == 0)
567 while (enumPair->name) {
568 if (strcmp(value, enumPair->name) == 0)
569 return enumPair->value;
589 char buffer[1024], *ptr, *tag, *value;
590 int32_t index, longValue;
597 sprintf(buffer,
"Unrecognized namelist tag given: %s", tag);
601 if (fieldInfo[index].enumPair) {
602 if (fieldInfo[index].type !=
SDDS_LONG) {
603 fprintf(stderr,
"SDDS_ParseNamelist: namelist setup problem---get expert help!\n");
607 if ((longValue =
SDDS_MatchEnum(value, fieldInfo[index].enumPair)) < 0) {
608 sprintf(buffer,
"Unrecognized value given for %s: %s", tag, value);
612 *((int32_t *)((
char *)data + fieldInfo[index].offset)) = longValue;
614 switch (fieldInfo[index].type) {
616 if (!(
SDDS_CopyString((
char **)((
char *)data + fieldInfo[index].offset), value))) {
622 *((
char *)data + fieldInfo[index].offset) = *value;
625 if (!sscanf(value,
"%hd", (
short *)((
char *)data + fieldInfo[index].offset))) {
631 if (!sscanf(value,
"%hu", (
unsigned short *)((
char *)data + fieldInfo[index].offset))) {
632 SDDS_SetError(
"Problem scanning unsigned short value for namelist");
637 if (!sscanf(value,
"%" SCNd32, (int32_t *)((
char *)data + fieldInfo[index].offset))) {
638 SDDS_SetError(
"Problem scanning int32_t value for namelist");
643 if (!sscanf(value,
"%" SCNu32, (uint32_t *)((
char *)data + fieldInfo[index].offset))) {
644 SDDS_SetError(
"Problem scanning uint32_t value for namelist");
649 if (!sscanf(value,
"%" SCNd64, (int64_t *)((
char *)data + fieldInfo[index].offset))) {
650 SDDS_SetError(
"Problem scanning int64_t value for namelist");
655 if (!sscanf(value,
"%" SCNu64, (uint64_t *)((
char *)data + fieldInfo[index].offset))) {
656 SDDS_SetError(
"Problem scanning uint64_t value for namelist");
661 if (!sscanf(value,
"%Lf", (
long double *)((
char *)data + fieldInfo[index].offset))) {
662 SDDS_SetError(
"Problem scanning long double value for namelist");
667 if (!sscanf(value,
"%lf", (
double *)((
char *)data + fieldInfo[index].offset))) {
673 if (!sscanf(value,
"%f", (
float *)((
char *)data + fieldInfo[index].offset))) {
679 SDDS_SetError(
"Internal error: unknown field information type");
704 SDDS_dataset->layout.description = NULL;
705 SDDS_dataset->layout.contents = NULL;
712 fprintf(stderr,
"Description scanned: description=>%s<, contents = >%s<\n", SDDS_dataset->layout.description, SDDS_dataset->layout.contents);
734 colDef.name = colDef.symbol = colDef.units = colDef.description = colDef.format_string = NULL;
736 colDef.field_length = 0;
742 code =
SDDS_DefineColumn(SDDS_dataset, colDef.name, colDef.symbol, colDef.units, colDef.description, colDef.format_string, colDef.type, colDef.field_length);
749 if (colDef.description)
750 free(colDef.description);
751 if (colDef.format_string)
752 free(colDef.format_string);
755 SDDS_SetError(
"Unable to process column definition--call to define column failed (SDDS1_ProcessColumnDefinition)");
778 paramDef.name = paramDef.symbol = paramDef.units = paramDef.description = paramDef.format_string = paramDef.fixed_value = NULL;
785 code =
SDDS_DefineParameter(SDDS_dataset, paramDef.name, paramDef.symbol, paramDef.units, paramDef.description, paramDef.format_string, paramDef.type, paramDef.fixed_value);
789 free(paramDef.symbol);
791 free(paramDef.units);
792 if (paramDef.description)
793 free(paramDef.description);
794 if (paramDef.format_string)
795 free(paramDef.format_string);
798 SDDS_SetError(
"Unable to process parameter definition--call to define parameter failed (SDDS1_ProcessParameterDefinition)");
827 if (!filename || !(fp = fopen(filename,
"r"))) {
828 SDDS_SetError(
"Unable to process include command--invalid/nonexistent file (SDDS1_ProcessIncludeCommand)");
851 assocDef.name = assocDef.filename = assocDef.path = assocDef.description = assocDef.contents = NULL;
858 code =
SDDS_DefineAssociate(SDDS_dataset, assocDef.name, assocDef.filename, assocDef.path, assocDef.description, assocDef.contents, assocDef.sdds);
860 SDDS_SetError(
"Unable to process associate definition--call to define associate failed (SDDS1_ProcessAssociateDefinition)");
881 dataMode = &(SDDS_dataset->layout.data_mode);
883 dataMode->endian = 0;
884 dataMode->lines_per_row = 1;
885 dataMode->no_row_counts = dataMode->additional_header_lines = 0;
886 dataMode->fixed_row_count = 0;
887 dataMode->column_major = 0;
892 if (dataMode->mode == 0) {
893 SDDS_SetError(
"Problem with data namelist: mode not given.");
896 if (dataMode->mode == SDDS_ASCII && dataMode->lines_per_row < 0) {
897 SDDS_SetError(
"Unable to process data mode--lines_per_row is invalid (SDDS1_ProcessDataMode)");
920 arrayDef.name = arrayDef.symbol = arrayDef.units = arrayDef.description = arrayDef.format_string = arrayDef.group_name = NULL;
922 arrayDef.field_length = 0;
923 arrayDef.dimensions = 1;
929 code =
SDDS_DefineArray(SDDS_dataset, arrayDef.name, arrayDef.symbol, arrayDef.units, arrayDef.description, arrayDef.format_string, arrayDef.type, arrayDef.field_length, arrayDef.dimensions, arrayDef.group_name);
933 free(arrayDef.symbol);
935 free(arrayDef.units);
936 if (arrayDef.description)
937 free(arrayDef.description);
938 if (arrayDef.format_string)
939 free(arrayDef.format_string);
940 if (arrayDef.group_name)
941 free(arrayDef.group_name);
944 SDDS_SetError(
"Unable to process array definition--call to define array failed (SDDS1_ProcessArrayDefinition)");
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
SDDS_FIELD_INFORMATION SDDS_AssociateFieldInformation[SDDS_ASSOCIATE_FIELDS]
Field information for associate definitions.
SDDS_FIELD_INFORMATION SDDS_ArrayFieldInformation[SDDS_ARRAY_FIELDS]
Field information for array definitions.
SDDS_FIELD_INFORMATION SDDS_ColumnFieldInformation[SDDS_COLUMN_FIELDS]
Field information for column definitions.
SDDS_FIELD_INFORMATION SDDS_DescriptionFieldInformation[SDDS_DESCRIPTION_FIELDS]
Field information for SDDS layout descriptions.
SDDS_FIELD_INFORMATION SDDS_ParameterFieldInformation[SDDS_PARAMETER_FIELDS]
Field information for parameter definitions.
SDDS_FIELD_INFORMATION SDDS_IncludeFieldInformation[SDDS_INCLUDE_FIELDS]
Field information for include directives.
SDDS_FIELD_INFORMATION SDDS_DataFieldInformation[SDDS_DATA_FIELDS]
Field information for data mode settings.
Internal definitions and function declarations for SDDS with LZMA support.
int32_t SDDS_DefineAssociate(SDDS_DATASET *SDDS_dataset, const char *name, const char *filename, const char *path, const char *description, const char *contents, int32_t sdds)
Defines an associate for the SDDS dataset.
int32_t SDDS_DefineArray(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length, int32_t dimensions, const char *group_name)
Defines a data array within the SDDS dataset.
int32_t SDDS_DefineColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length)
Defines a data column within the SDDS dataset.
int32_t SDDS_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
int32_t SDDS_ProcessParameterString(SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
Process a parameter definition string.
int32_t SDDS1_ProcessArrayDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines an array within an SDDS dataset.
int32_t SDDS_ProcessAssociateString(SDDS_DATASET *SDDS_dataset, char *string)
Process an associate definition string.
int32_t SDDS_ProcessArrayDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the array definition section of the SDDS dataset.
int32_t SDDS_ProcessParameterDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the parameter definition section of the SDDS dataset.
int32_t SDDS_ProcessColumnString(SDDS_DATASET *SDDS_dataset, char *string, int32_t mode)
Process a column definition string.
int32_t SDDS1_ProcessAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines an associate within an SDDS dataset.
int32_t SDDS_ProcessAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the associate definition section of the SDDS dataset.
FILE * SDDS1_ProcessIncludeCommand(SDDS_DATASET *SDDS_dataset, char *s)
Processes an include command by opening the specified file.
int32_t SDDS1_ProcessDataMode(SDDS_DATASET *SDDS_dataset, char *s)
Processes and sets the data mode for an SDDS dataset.
FILE * SDDS_ProcessIncludeCommand(SDDS_DATASET *SDDS_dataset, char *s)
Process the include command within the SDDS dataset.
int32_t SDDS_ProcessDataMode(SDDS_DATASET *SDDS_dataset, char *s)
Process the data mode section of the SDDS dataset.
int32_t SDDS_MatchEnum(char *value, SDDS_ENUM_PAIR *enumPair)
Match an enumeration string to its corresponding value.
char * SDDS_GetTagValuePair(char *ptr, char **tag, char **value)
Retrieve a tag-value pair from the input string.
char * SDDS_PrepareToParseTagValuePairs(char *s)
Prepare the string for parsing tag-value pairs.
int32_t SDDS_ProcessDescription(SDDS_DATASET *SDDS_dataset, char *s)
Process the description section of the SDDS dataset.
int32_t SDDS_FindFieldIndex(char *tag, SDDS_FIELD_INFORMATION *fieldInfo, int32_t fieldInfos)
Find the index of a field based on its tag.
int32_t SDDS1_ProcessDescription(SDDS_DATASET *SDDS_dataset, char *s)
Process the description section for SDDS protocol version 1.
int32_t SDDS1_ProcessParameterDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines a parameter within an SDDS dataset.
int32_t SDDS_ParseNamelist(void *data, SDDS_FIELD_INFORMATION *fieldInfo, int32_t fieldInfos, char *s)
Parse a namelist string and populate the corresponding data structure.
int32_t SDDS_ProcessArrayString(SDDS_DATASET *SDDS_dataset, char *string)
Process an array definition string.
int32_t SDDS_ProcessColumnDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the column definition section of the SDDS dataset.
int32_t SDDS1_ProcessColumnDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Processes and defines a column within an SDDS dataset.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#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_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.