43char *option[N_OPTIONS] =
52 "sddscollapse [<SDDSinputfile>] [<SDDSoutputfile>]\n"
53 "[-pipe=[input][,output]] [-majorOrder=row|column] \n"
55 "sddscollapse reads data pages from a SDDS file and writes a new SDDS file \n"
56 "containing a single data page. This data page contains the parameters, \n"
57 "with each parameter forming a column of the tabular data.\n\n"
58 "Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
60#define ROW_INCREMENT 100
62int main(
int argc,
char **argv) {
64 char *inputfile = NULL, *outputfile = NULL, **column;
66 long page_number, no_warnings = 0, set_page_number;
67 int64_t allocated_rows;
71 unsigned long pipe_flags = 0, major_order_flag;
73 short column_major_order = -1;
84 for (i_arg = 1; i_arg < argc; i_arg++) {
85 if (s_arg[i_arg].arg_type == OPTION) {
87 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
90 s_arg[i_arg].n_items -= 1;
91 if (s_arg[i_arg].n_items > 0 &&
93 &s_arg[i_arg].n_items, 0,
94 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
95 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER,
97 SDDS_Bomb(
"invalid -majorOrder syntax/values");
98 if (major_order_flag & SDDS_COLUMN_MAJOR_ORDER)
99 column_major_order = 1;
100 else if (major_order_flag & SDDS_ROW_MAJOR_ORDER)
101 column_major_order = 0;
112 fprintf(stderr,
"error: unknown switch: %s\n", s_arg[i_arg].list[0]);
118 if (inputfile == NULL)
119 inputfile = s_arg[i_arg].list[0];
120 else if (outputfile == NULL)
121 outputfile = s_arg[i_arg].list[0];
128 processFilenames(
"sddscollapse", &inputfile, &outputfile, pipe_flags, no_warnings, NULL);
138 NULL, NULL, outputfile)) {
144 if (column_major_order != -1)
145 SDDS_output.layout.data_mode.column_major = column_major_order;
147 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
156 for (i = 0; i < columns; i++) {
164 sprintf(s,
"corresponding page number of %s for this row",
165 inputfile ? inputfile :
"stdin");
187 if (page_number > allocated_rows) {
192 allocated_rows += ROW_INCREMENT;
196 for (i = 0; i < columns; i++) {
202 SDDS_SET_BY_NAME | SDDS_PASS_BY_REFERENCE,
203 page_number - 1, column[i], buffer, NULL)) {
210 if (set_page_number &&
212 SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
213 page_number - 1,
"PageNumber", page_number, NULL)) {
220 for (i = 0; i < columns; i++)
229 if (page_number == 0) {
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
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_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
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.
int32_t SDDS_DefineColumnLikeParameter(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Defines a column in the target dataset based on a parameter definition from the source dataset.
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters in the SDDS dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
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.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
#define SDDS_LONG
Identifier for the signed 32-bit integer 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.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
long scanItemList(unsigned long *flags, char **item, long *items, unsigned long mode,...)
Scans a list of items and assigns values based on provided keywords and types.
OptionType
Enumeration for command-line options.