47char *option[N_OPTIONS] = {
52 "Usage: col2sdds <inputfile> <outputfile> [-fixMplNames]\n"
54 " -fixMplNames Remove '$' characters from auxiliary and column names.\n"
55 "Link date: " __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
"\n";
57int main(
int argc,
char **argv) {
59 char *input = NULL, *output = NULL;
61 long i_arg, i, j, k, len;
65 char **aux_symbol = NULL;
69 argc =
scanargs(&scanned, argc, argv);
71 fprintf(stderr,
"%s", USAGE);
75 for (i_arg = 1; i_arg < argc; i_arg++) {
76 if (scanned[i_arg].arg_type == OPTION) {
77 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
82 fprintf(stderr,
"Invalid option: %s\n%s", scanned[i_arg].list[0], USAGE);
87 input = scanned[i_arg].list[0];
89 output = scanned[i_arg].list[0];
91 fprintf(stderr,
"Too many file names provided.\n%s", USAGE);
98 fprintf(stderr,
"Error: Input file not specified.\n%s", USAGE);
103 fprintf(stderr,
"Error: Output file not specified.\n%s", USAGE);
107 if (
get_mc_table(&mcTable, input, GMCT_WARNINGS) == 0) {
108 fprintf(stderr,
"Unable to open input file: %s\n", input);
113 aux_symbol = malloc(
sizeof(
char *) * mcTable.n_auxiliaries);
115 fprintf(stderr,
"Memory allocation failed for auxiliary symbols.\n");
119 for (i = 0; i < mcTable.n_auxiliaries; i++) {
120 len = strlen(mcTable.aux_name[i]);
121 aux_symbol[i] = malloc(
sizeof(
char) * (len + 1));
122 if (!aux_symbol[i]) {
123 fprintf(stderr,
"Memory allocation failed for auxiliary symbol %ld.\n", i);
127 for (j = 0; j < len; j++) {
128 if (mcTable.aux_name[i][j] !=
'$') {
129 buffer[k++] = mcTable.aux_name[i][j];
133 strcpy(aux_symbol[i], buffer);
136 symbol = malloc(
sizeof(
char *) * mcTable.n_cols);
138 fprintf(stderr,
"Memory allocation failed for column symbols.\n");
142 for (i = 0; i < mcTable.n_cols; i++) {
143 len = strlen(mcTable.name[i]);
144 symbol[i] = malloc(
sizeof(
char) * (len + 1));
146 fprintf(stderr,
"Memory allocation failed for column symbol %ld.\n", i);
150 for (j = 0; j < len; j++) {
151 if (mcTable.name[i][j] !=
'$') {
152 buffer[k++] = mcTable.name[i][j];
156 strcpy(symbol[i], buffer);
165 for (i = 0; i < mcTable.n_auxiliaries; i++) {
166 const char *paramName = fixMplNames ? aux_symbol[i] : mcTable.aux_name[i];
167 const char *paramDesc = mcTable.aux_description[i];
168 const char *paramUnit = mcTable.aux_unit[i];
169 double *paramValue = &(mcTable.aux_value[i]);
174 fprintf(stderr,
"Try rerunning with the -fixMplNames option.\n");
180 for (i = 0; i < mcTable.n_cols; i++) {
181 const char *colName = fixMplNames ? symbol[i] : mcTable.name[i];
182 const char *colDesc = mcTable.description[i];
183 const char *colUnit = mcTable.unit[i];
184 const char *colFormat = mcTable.format[i];
189 fprintf(stderr,
"Try rerunning with the -fixMplNames option.\n");
205 if (SDDS_StartTable(&SDDS_table, mcTable.n_rows) != 1) {
210 for (i = 0; i < mcTable.n_cols; i++) {
217 if (SDDS_WriteTable(&SDDS_table) != 1) {
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows,...)
Sets the values for a single data column using double-precision floating-point numbers.
int32_t SDDS_DefineParameter1(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, void *fixed_value)
Defines a data parameter with a fixed numerical value.
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output 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_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
#define SDDS_DOUBLE
Identifier for the double data type.
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.
long get_mc_table(MC_TABLE *table, char *file, long flags)
Reads a multi-column table from a file.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)