62 {
64 char *inputfile = NULL, *outputfile = NULL, **column;
65 long i, i_arg;
66 long page_number, no_warnings = 0, set_page_number;
67 int64_t allocated_rows;
68 int32_t columns;
69 SCANNED_ARG *s_arg;
70 char s[SDDS_MAXLINE];
71 unsigned long pipe_flags = 0, major_order_flag;
72 long buffer[16];
73 short column_major_order = -1;
74
75
77
78
80 if (argc < 2)
82
83
84 for (i_arg = 1; i_arg < argc; i_arg++) {
85 if (s_arg[i_arg].arg_type == OPTION) {
86
87 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
88 case SET_MAJOR_ORDER:
89 major_order_flag = 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,
96 NULL)))
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;
102 break;
103 case SET_PIPE:
105 &pipe_flags))
107 break;
108 case SET_NOWARNINGS:
109 no_warnings = 1;
110 break;
111 default:
112 fprintf(stderr, "error: unknown switch: %s\n", s_arg[i_arg].list[0]);
113 exit(1);
114 break;
115 }
116 } else {
117
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];
122 else
124 }
125 }
126
127
128 processFilenames(
"sddscollapse", &inputfile, &outputfile, pipe_flags, no_warnings, NULL);
129
130
133 exit(1);
134 }
135
136
138 NULL, NULL, outputfile)) {
140 exit(1);
141 }
142
143
144 if (column_major_order != -1)
145 SDDS_output.layout.data_mode.column_major = column_major_order;
146 else
147 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
148
149
152 exit(1);
153 }
154
155
156 for (i = 0; i < columns; i++) {
159 exit(1);
160 }
161 }
162
163
164 sprintf(s, "corresponding page number of %s for this row",
165 inputfile ? inputfile : "stdin");
170 exit(1);
171 }
172 set_page_number = 1;
173 } else {
174 set_page_number = 0;
175 }
176
177
181 exit(1);
182 }
183
184
186
187 if (page_number > allocated_rows) {
190 exit(1);
191 }
192 allocated_rows += ROW_INCREMENT;
193 }
194
195
196 for (i = 0; i < columns; i++) {
199 exit(1);
200 }
202 SDDS_SET_BY_NAME | SDDS_PASS_BY_REFERENCE,
203 page_number - 1, column[i], buffer, NULL)) {
205 exit(1);
206 }
207 }
208
209
210 if (set_page_number &&
212 SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
213 page_number - 1, "PageNumber", page_number, NULL)) {
215 exit(1);
216 }
217 }
218
219
220 for (i = 0; i < columns; i++)
221 free(column[i]);
222 free(column);
223
224
227 exit(1);
228 }
229 if (page_number == 0) {
231 exit(1);
232 }
235 exit(1);
236 }
237 return 0;
238}
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.