72 {
74 char *inputfile = NULL, *outputfile = NULL, **column;
75 long i, i_arg;
76 long page_number, no_warnings = 0, set_page_number;
77 int64_t allocated_rows;
78 int32_t columns;
79 SCANNED_ARG *s_arg;
80 char s[SDDS_MAXLINE];
81 unsigned long pipe_flags = 0, major_order_flag;
82 long buffer[16];
83 short column_major_order = -1;
84
85
87
88
90 if (argc < 2)
92
93
94 for (i_arg = 1; i_arg < argc; i_arg++) {
95 if (s_arg[i_arg].arg_type == OPTION) {
96
97 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
98 case SET_MAJOR_ORDER:
99 major_order_flag = 0;
100 s_arg[i_arg].n_items -= 1;
101 if (s_arg[i_arg].n_items > 0 &&
102 (!
scanItemList(&major_order_flag, s_arg[i_arg].list + 1,
103 &s_arg[i_arg].n_items, 0,
104 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
105 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER,
106 NULL)))
107 SDDS_Bomb(
"invalid -majorOrder syntax/values");
108 if (major_order_flag & SDDS_COLUMN_MAJOR_ORDER)
109 column_major_order = 1;
110 else if (major_order_flag & SDDS_ROW_MAJOR_ORDER)
111 column_major_order = 0;
112 break;
113 case SET_PIPE:
115 &pipe_flags))
117 break;
118 case SET_NOWARNINGS:
119 no_warnings = 1;
120 break;
121 default:
122 fprintf(stderr, "error: unknown switch: %s\n", s_arg[i_arg].list[0]);
123 exit(1);
124 break;
125 }
126 } else {
127
128 if (inputfile == NULL)
129 inputfile = s_arg[i_arg].list[0];
130 else if (outputfile == NULL)
131 outputfile = s_arg[i_arg].list[0];
132 else
134 }
135 }
136
137
138 processFilenames(
"sddscollapse", &inputfile, &outputfile, pipe_flags, no_warnings, NULL);
139
140
143 exit(1);
144 }
145
146
148 NULL, NULL, outputfile)) {
150 exit(1);
151 }
152
153
154 if (column_major_order != -1)
155 SDDS_output.layout.data_mode.column_major = column_major_order;
156 else
157 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
158
159
162 exit(1);
163 }
164
165
166 for (i = 0; i < columns; i++) {
169 exit(1);
170 }
171 }
172
173
174 sprintf(s, "corresponding page number of %s for this row",
175 inputfile ? inputfile : "stdin");
180 exit(1);
181 }
182 set_page_number = 1;
183 } else {
184 set_page_number = 0;
185 }
186
187
191 exit(1);
192 }
193
194
196
197 if (page_number > allocated_rows) {
200 exit(1);
201 }
202 allocated_rows += ROW_INCREMENT;
203 }
204
205
206 for (i = 0; i < columns; i++) {
209 exit(1);
210 }
212 SDDS_SET_BY_NAME | SDDS_PASS_BY_REFERENCE,
213 page_number - 1, column[i], buffer, NULL)) {
215 exit(1);
216 }
217 }
218
219
220 if (set_page_number &&
222 SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
223 page_number - 1, "PageNumber", page_number, NULL)) {
225 exit(1);
226 }
227 }
228
229
230 for (i = 0; i < columns; i++)
231 free(column[i]);
232 free(column);
233
234
237 exit(1);
238 }
239 if (page_number == 0) {
241 exit(1);
242 }
245 exit(1);
246 }
247 return 0;
248}
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.