60 SET_ANNOUNCE_OPENINGS,
65static char *option[N_OPTIONS] = {
74static const char *usage =
75 "sdds2mpl [<SDDSfilename>]\n"
77 " [-rootname=<string>]\n"
78 " -output={column|parameter},<x-name>,<y-name>[,{<sy-name>|<sx-name>,<sy-name>}]...\n"
79 " [-labelParameters=<name>[=<format>]...]\n"
81 " [-announceOpenings]\n"
82 "Any number of -output specifications may be given.\n\n"
83 "sdds2mpl extracts data from an SDDS file into MPL-format files.\n"
84 "Program by Michael Borland. ("__DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
86int main(
int argc,
char **argv) {
89 long label_parameters = 0;
92 char *inputfile = NULL;
93 char *rootname = NULL;
99 long page_number, separate_pages = 0;
100 long announce_openings = 0;
105 long data_present = 0;
106 unsigned long pipe_flags = 0;
108 argc =
scanargs(&s_arg, argc, argv);
110 fputs(usage, stderr);
114 for (i_arg = 1; i_arg < argc; i_arg++) {
115 if (s_arg[i_arg].arg_type == OPTION) {
117 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
119 if (s_arg[i_arg].n_items != 2)
121 rootname = s_arg[i_arg].list[1];
124 if (s_arg[i_arg].n_items < 4 || s_arg[i_arg].n_items > 6)
126 output =
trealloc(output,
sizeof(*output) * (outputs + 1));
127 if (!(output[outputs] = process_output_request(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, outputs ? output[outputs - 1] : NULL)))
131 case SET_SEPARATE_PAGES:
134 case SET_LABEL_PARAMETERS:
135 if (s_arg[i_arg].n_items < 2)
136 SDDS_Bomb(
"Invalid -labelparameters syntax");
137 label_parameter =
trealloc(label_parameter,
sizeof(*label_parameter) * (label_parameters + s_arg[i_arg].n_items));
138 for (i = 1; i < s_arg[i_arg].n_items; i++)
139 scan_label_parameter(label_parameter + i - 1, s_arg[i_arg].list[i]);
140 label_parameters += s_arg[i_arg].n_items - 1;
142 case SET_ANNOUNCE_OPENINGS:
143 announce_openings = 1;
146 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipe_flags))
155 inputfile = s_arg[i_arg].list[0];
161 if (!inputfile && !(pipe_flags & USE_STDIN))
166 SDDS_Bomb(
"You must give a rootname if you don't give an input filename");
168 if ((ptr = strrchr(rootname,
'.')))
173 SDDS_Bomb(
"No output specifications given");
180 for (i = 0; i < outputs; i++) {
181 if (!output[i]->parameter_output) {
186 fprintf(stderr,
"Error: unrecognized column name given\n");
195 fprintf(stderr,
"Error: unrecognized parameter name given\n");
209 fprintf(stderr,
"Warning: no rows selected for page %" PRId32
"\n", sdds_dataset.page_number);
213 for (i = 0; i < outputs; i++) {
214 if (!output[i]->fp) {
215 if (separate_pages && !output[i]->parameter_output)
216 snprintf(filename,
sizeof(filename),
"%s_%03ld_%s_%s.out", rootname, output[i]->counter++, output[i]->item[0], output[i]->item[1]);
218 snprintf(filename,
sizeof(filename),
"%s_%s_%s.out", rootname, output[i]->item[0], output[i]->item[1]);
219 set_up_output(filename, output[i], label_parameter, label_parameters, separate_pages, announce_openings, &sdds_dataset);
221 if (!output[i]->parameter_output) {
223 data[2] = data[3] = NULL;
224 if (!(data[0] =
SDDS_GetColumn(&sdds_dataset, output[i]->item[0])) ||
226 (output[i]->columns > 2 && !(data[2] =
SDDS_GetColumn(&sdds_dataset, output[i]->item[2]))) ||
227 (output[i]->columns > 3 && !(data[3] =
SDDS_GetColumn(&sdds_dataset, output[i]->item[3])))) {
231 for (int64_t j = 0; j < n_rows; j++) {
232 for (
long k = 0; k < output[i]->columns; k++) {
233 SDDS_PrintTypedValue((
char *)data[k], j, coldef[k]->type, coldef[k]->format_string, output[i]->fp, 0);
234 if (k < output[i]->columns - 1)
235 fputc(
' ', output[i]->fp);
237 fputc(
'\n', output[i]->fp);
239 output[i]->points += n_rows;
240 for (
long k = 0; k < output[i]->columns; k++) {
245 for (
long k = 0; k < output[i]->columns; k++) {
251 output[i]->points += 1;
252 for (
long k = 0; k < output[i]->columns; k++) {
253 SDDS_PrintTypedValue((
char *)¶m[k], 0, pardef[k]->type, pardef[k]->format_string, output[i]->fp, 0);
254 if (k < output[i]->columns - 1)
255 fputc(
' ', output[i]->fp);
257 fputc(
'\n', output[i]->fp);
259 if (separate_pages && !output[i]->parameter_output) {
260 fclose(output[i]->fp);
261 output[i]->fp = NULL;
262 output[i]->points = 0;
267 if (page_number == 0) {
271 if (page_number == -1 && !data_present) {
276 fprintf(stderr,
"Error: input data file is empty\n");
280 for (i = 0; i < outputs; i++) {
282 fclose(output[i]->fp);
285 for (i = 0; i < outputs; i++) {
286 if (!separate_pages || output[i]->parameter_output) {
287 snprintf(filename,
sizeof(filename),
"%s_%s_%s.out", rootname, output[i]->item[0], output[i]->item[1]);
288 fixcount(filename, output[i]->points);
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter 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.
int32_t SDDS_NumberOfErrors()
Retrieves the number of errors recorded by SDDS library routines.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
int32_t SDDS_PrintTypedValue(void *data, int64_t index, int32_t type, char *format, FILE *fp, uint32_t mode)
Prints a data value of a specified type using an optional printf format string.
Header file for routines used by SDDS command-line applications.
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
int fixcount(char *filename, long n_points)
Updates the data point count in a specified file.
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)