62static char *option[N_OPTIONS] = {
70 "sddsexpand [-pipe=[input][,output]] [<SDDSinputfile>] [<SDDSoutputfile>]\n"
71 "[-noWarnings] [-majorOrder=row|column] \n\n"
72 "sddsexpand is the partial inverse of sddscollapse.\n"
73 "All columns of the input file are turned into parameters in the output file.\n"
74 "For each row of each page in the input file, sddsexpand emits a new page\n"
75 "with parameter values equal to the column values for that page and row.\n\n"
76 "Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
78#define ROW_INCREMENT 100
88int main(
int argc,
char **argv) {
90 char *inputfile = NULL, *outputfile = NULL;
92 long i, no_warnings = 0;
94 unsigned long pipe_flags = 0, major_order_flag;
96 SourceData *column_source = NULL, *parameter_source = NULL;
97 int32_t column_sources, parameter_sources;
100 short column_major_order = -1;
106 argc =
scanargs(&s_arg, argc, argv);
111 for (
int i_arg = 1; i_arg < argc; i_arg++) {
112 if (s_arg[i_arg].arg_type == OPTION) {
114 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
115 case SET_MAJOR_ORDER:
116 major_order_flag = 0;
117 s_arg[i_arg].n_items--;
118 if (s_arg[i_arg].n_items > 0 && (!
scanItemList(&major_order_flag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
119 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
120 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL))) {
121 SDDS_Bomb(
"invalid -majorOrder syntax/values");
123 column_major_order = (major_order_flag & SDDS_COLUMN_MAJOR_ORDER) ? 1 : 0;
126 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipe_flags))
133 fprintf(stderr,
"error: unknown switch: %s\n", s_arg[i_arg].list[0]);
139 inputfile = s_arg[i_arg].list[0];
140 else if (!outputfile)
141 outputfile = s_arg[i_arg].list[0];
148 processFilenames(
"sddsexpand", &inputfile, &outputfile, pipe_flags, no_warnings, NULL);
156 SDDS_output.layout.data_mode.column_major = (column_major_order != -1) ? column_major_order : SDDS_input.layout.data_mode.column_major;
160 !(column_source =
SDDS_Malloc(
sizeof(*column_source) * column_sources))) {
165 for (i = 0; i < column_sources; i++) {
166 column_source[i].name = name[i];
176 !(parameter_source =
SDDS_Malloc(
sizeof(*parameter_source) * parameter_sources))) {
181 for (i = 0; i < parameter_sources; i++) {
182 parameter_source[i].name = name[i];
185 fprintf(stderr,
"Warning (sddsexpand): name %s used for parameter and column in input file. Column data used.\n", parameter_source[i].name);
186 parameter_source[i].do_copy = 0;
189 parameter_source[i].do_copy = 1;
199 !(data =
SDDS_Malloc(
sizeof(*data) * column_sources))) {
205 if ((rows = SDDS_RowCount(&SDDS_input)) < 0)
209 for (i = 0; i < column_sources; i++) {
216 for (irow = 0; irow < rows; irow++) {
222 for (i = 0; i < parameter_sources; i++) {
223 if (!parameter_source[i].do_copy)
226 !
SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, parameter_source[i].index, buffer, -1)) {
232 for (i = 0; i < column_sources; i++) {
233 if (!
SDDS_SetParameters(&SDDS_output, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, column_source[i].index, (((
char *)data[i]) + irow * column_source[i].size), -1)) {
253 free(parameter_source);
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
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_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_DefineParameterLikeColumn(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Defines a parameter in the target dataset based on a column definition from the source dataset.
int32_t SDDS_TransferParameterDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a parameter definition from a source dataset to a target dataset.
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.
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.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
int32_t SDDS_GetTypeSize(int32_t type)
Retrieves the size in bytes of a specified SDDS data type.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
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.