15#define SET_FIXMPLNAMES 0
18char *option[N_OPTIONS] = {
21char *USAGE =
"col2sdds <inputfile> <outputfile> [-fixMplNames]\n\
22Link date: " __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
"\n";
24int main(
int argc,
char **argv) {
26 char *input = NULL, *output = NULL;
28 long i_arg, i, j, k, len;
32 char **aux_symbol = NULL;
36 argc =
scanargs(&scanned, argc, argv);
39 for (i_arg = 1; i_arg < argc; i_arg++) {
40 if (scanned[i_arg].arg_type == OPTION) {
41 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
46 fprintf(stderr,
"Invalid option seen\n%s", USAGE);
51 input = scanned[i_arg].list[0];
53 output = scanned[i_arg].list[0];
55 fprintf(stderr,
"Too many file names\n%s", USAGE);
61 fprintf(stderr,
"Input file not seen\n%s", USAGE);
65 fprintf(stderr,
"Output file not seen\n%s", USAGE);
70 fprintf(stderr,
"Unable to open %s\n", input);
75 aux_symbol = malloc(
sizeof(
char *) * mcTable.n_auxiliaries);
76 for (i = 0; i < mcTable.n_auxiliaries; i++) {
77 len = strlen(mcTable.aux_name[i]);
78 aux_symbol[i] = malloc(
sizeof(
char) * (len + 1));
82 if (mcTable.aux_name[i][j] ==
'$') {
85 buffer[k] = mcTable.aux_name[i][j];
91 sprintf(aux_symbol[i],
"%s", buffer);
94 symbol = malloc(
sizeof(
char *) * mcTable.n_cols);
95 for (i = 0; i < mcTable.n_cols; i++) {
96 len = strlen(mcTable.name[i]);
97 symbol[i] = malloc(
sizeof(
char) * (len + 1));
101 if (mcTable.name[i][j] ==
'$') {
104 buffer[k] = mcTable.name[i][j];
110 sprintf(symbol[i],
"%s", buffer);
118 for (i = 0; i < mcTable.n_auxiliaries; i++) {
120 if (
SDDS_DefineParameter1(&SDDS_table, aux_symbol[i], mcTable.aux_name[i], mcTable.aux_unit[i], mcTable.aux_description[i], NULL,
SDDS_DOUBLE, &(mcTable.aux_value[i])) == -1) {
125 if (
SDDS_DefineParameter1(&SDDS_table, mcTable.aux_name[i], NULL, mcTable.aux_unit[i], mcTable.aux_description[i], NULL,
SDDS_DOUBLE, &(mcTable.aux_value[i])) == -1) {
127 fprintf(stderr,
"Try rerunning with the -fixMplNames option\n");
132 for (i = 0; i < mcTable.n_cols; i++) {
134 if (
SDDS_DefineColumn(&SDDS_table, symbol[i], mcTable.name[i], mcTable.unit[i], mcTable.description[i], mcTable.format[i],
SDDS_DOUBLE, 0) == -1) {
139 if (
SDDS_DefineColumn(&SDDS_table, mcTable.name[i], NULL, mcTable.unit[i], mcTable.description[i], mcTable.format[i],
SDDS_DOUBLE, 0) == -1) {
141 fprintf(stderr,
"Try rerunning with the -fixMplNames option\n");
156 if (SDDS_StartTable(&SDDS_table, mcTable.n_rows) != 1) {
160 for (i = 0; i < mcTable.n_cols; i++) {
166 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.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
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)