148 {
150 SCANNED_ARG *s_arg;
151 char *inputfile, *outputfile;
152 long tmpfile_used, noWarnings, i, i_arg;
153 CAST_NAME column_cast, parameter_cast, array_cast;
154 CAST_REQUEST *col_request, *par_request, *array_request;
155 long col_requests, par_requests, array_requests, rows;
156 unsigned long pipeFlags, majorOrderFlag;
157 short columnMajorOrder = -1;
158
159 column_cast.n = parameter_cast.n = array_cast.n = 0;
160 column_cast.name = column_cast.new_type = NULL;
161 column_cast.index = parameter_cast.index = array_cast.index = 0;
162 parameter_cast.name = parameter_cast.new_type = NULL;
163 array_cast.name = array_cast.new_type = NULL;
164 col_request = par_request = array_request = NULL;
165 col_requests = par_requests = array_requests = rows = 0;
166
168 argc =
scanargs(&s_arg, argc, argv);
169 if (argc < 3)
171
172 inputfile = outputfile = NULL;
173 noWarnings = tmpfile_used = pipeFlags = 0;
174
175 for (i_arg = 1; i_arg < argc; i_arg++) {
176 if (s_arg[i_arg].arg_type == OPTION) {
178 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
179 case SET_MAJOR_ORDER:
180 majorOrderFlag = 0;
181 s_arg[i_arg].n_items -= 1;
182 if (s_arg[i_arg].n_items > 0 &&
183 (!
scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
184 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
185 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
186 SDDS_Bomb(
"invalid -majorOrder syntax/values");
187 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
188 columnMajorOrder = 1;
189 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
190 columnMajorOrder = 0;
191 break;
192 case SET_NOWARNINGS:
193 noWarnings = 1;
194 break;
195 case SET_PIPE:
196 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
198 break;
199 case SET_CAST:
200 if (s_arg[i_arg].n_items < 4)
202 if (
match_string(s_arg[i_arg].list[4], types, TYPES, MATCH_WHOLE_STRING) < 0) {
203 SDDS_Bomb(
"The new type to cast has to be a numeric type!");
204 }
205 switch (
match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
206 case COLUMN_MODE:
207 col_request =
SDDS_Realloc(col_request,
sizeof(*col_request) * (col_requests + 1));
208 col_request[col_requests].match_string = s_arg[i_arg].list[2];
209 col_request[col_requests].type_string = s_arg[i_arg].list[3];
210 col_request[col_requests].new_type = s_arg[i_arg].list[4];
211 col_requests++;
212 break;
213 case PARAMETER_MODE:
214 par_request =
SDDS_Realloc(par_request,
sizeof(*par_request) * (par_requests + 1));
215 par_request[par_requests].match_string = s_arg[i_arg].list[2];
216 par_request[par_requests].type_string = s_arg[i_arg].list[3];
217 par_request[par_requests].new_type = s_arg[i_arg].list[4];
218 par_requests++;
219 break;
220 case ARRAY_MODE:
221 array_request =
SDDS_Realloc(array_request,
sizeof(*array_request) * (array_requests + 1));
222 array_request[array_requests].match_string = s_arg[i_arg].list[2];
223 array_request[array_requests].type_string = s_arg[i_arg].list[3];
224 array_request[array_requests].new_type = s_arg[i_arg].list[4];
225 array_requests++;
226 break;
227 default:
229 break;
230 }
231 break;
232 default:
234 break;
235 }
236 } else {
237 if (inputfile == NULL)
238 inputfile = s_arg[i_arg].list[0];
239 else if (outputfile == NULL)
240 outputfile = s_arg[i_arg].list[0];
241 else {
242 fprintf(stderr, "Error: Too many filenames provided (sddscast).\n");
243 exit(EXIT_FAILURE);
244 }
245 }
246 }
247
248 processFilenames(
"sddscast", &inputfile, &outputfile, pipeFlags, noWarnings, &tmpfile_used);
249
252 exit(EXIT_FAILURE);
253 }
256 exit(EXIT_FAILURE);
257 }
258 if (columnMajorOrder != -1)
259 SDDS_output.layout.data_mode.column_major = columnMajorOrder;
260 else
261 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
262
263 process_cast_columns(&SDDS_input, &column_cast, col_request, col_requests, noWarnings);
264 process_cast_parameters(&SDDS_input, ¶meter_cast, par_request, par_requests, noWarnings);
265 process_cast_arrays(&SDDS_input, &array_cast, array_request, array_requests, noWarnings);
266
267 for (i = 0; i < column_cast.n; i++) {
268 if (!
SDDS_ChangeColumnInformation(&SDDS_output,
"type", column_cast.new_type[i], SDDS_PASS_BY_STRING | SDDS_SET_BY_NAME, column_cast.name[i])) {
270 exit(EXIT_FAILURE);
271 }
272 }
273 for (i = 0; i < parameter_cast.n; i++) {
274 if (!
SDDS_ChangeParameterInformation(&SDDS_output,
"type", parameter_cast.new_type[i], SDDS_PASS_BY_STRING | SDDS_SET_BY_NAME, parameter_cast.name[i])) {
276 exit(EXIT_FAILURE);
277 }
278 }
279
280 for (i = 0; i < array_cast.n; i++) {
281 if (!
SDDS_ChangeArrayInformation(&SDDS_output,
"type", array_cast.new_type[i], SDDS_PASS_BY_STRING | SDDS_SET_BY_NAME, array_cast.name[i])) {
283 exit(EXIT_FAILURE);
284 }
285 }
286
289
293 exit(EXIT_FAILURE);
294 }
295 }
296
299 exit(EXIT_FAILURE);
300 }
301
303 exit(EXIT_FAILURE);
304
305
306 cleanUpCast(&column_cast);
307 cleanUpCast(¶meter_cast);
308 cleanUpCast(&array_cast);
309 if (array_request)
310 free(array_request);
311 if (par_request)
312 free(par_request);
313 if (col_request)
314 free(col_request);
315
317 return EXIT_SUCCESS;
318}
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_ChangeParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a parameter definition within the SDDS dataset.
int32_t SDDS_ChangeArrayInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in an array definition within the SDDS dataset.
int32_t SDDS_ChangeColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a column definition within the SDDS 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.
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.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
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 replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
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)
void free_scanargs(SCANNED_ARG **scanned, int argc)
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.