46 SET_ANNOUNCE_OPENINGS,
51static char *option[N_OPTIONS] = {
60static const char *usage =
61 "sdds2mpl [-pipe[=input]] [<SDDSfilename>] [-rootname=<string>]\n"
62 "-output={column|parameter},<x-name>,<y-name>[,{<sy-name>|<sx-name>,<sy-name>}]...\n"
63 "[-labelParameters=<name>[=<format>]...] [-separatePages] [-announceOpenings]\n\n"
64 "Any number of -output specifications may be given.\n\n"
65 "sdds2mpl extracts data from an SDDS file into MPL-format files.\n"
66 "Program by Michael Borland. ("__DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
68int main(
int argc,
char **argv) {
71 long label_parameters = 0;
74 char *inputfile = NULL;
75 char *rootname = NULL;
81 long page_number, separate_pages = 0;
82 long announce_openings = 0;
87 long data_present = 0;
88 unsigned long pipe_flags = 0;
96 for (i_arg = 1; i_arg < argc; i_arg++) {
97 if (s_arg[i_arg].arg_type == OPTION) {
99 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
101 if (s_arg[i_arg].n_items != 2)
103 rootname = s_arg[i_arg].list[1];
106 if (s_arg[i_arg].n_items < 4 || s_arg[i_arg].n_items > 6)
108 output =
trealloc(output,
sizeof(*output) * (outputs + 1));
109 if (!(output[outputs] = process_output_request(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, outputs ? output[outputs - 1] : NULL)))
113 case SET_SEPARATE_PAGES:
116 case SET_LABEL_PARAMETERS:
117 if (s_arg[i_arg].n_items < 2)
118 SDDS_Bomb(
"Invalid -labelparameters syntax");
119 label_parameter =
trealloc(label_parameter,
sizeof(*label_parameter) * (label_parameters + s_arg[i_arg].n_items));
120 for (i = 1; i < s_arg[i_arg].n_items; i++)
121 scan_label_parameter(label_parameter + i - 1, s_arg[i_arg].list[i]);
122 label_parameters += s_arg[i_arg].n_items - 1;
124 case SET_ANNOUNCE_OPENINGS:
125 announce_openings = 1;
128 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipe_flags))
137 inputfile = s_arg[i_arg].list[0];
143 if (!inputfile && !(pipe_flags & USE_STDIN))
148 SDDS_Bomb(
"You must give a rootname if you don't give an input filename");
150 if ((ptr = strrchr(rootname,
'.')))
155 SDDS_Bomb(
"No output specifications given");
162 for (i = 0; i < outputs; i++) {
163 if (!output[i]->parameter_output) {
168 fprintf(stderr,
"Error: unrecognized column name given\n");
177 fprintf(stderr,
"Error: unrecognized parameter name given\n");
191 fprintf(stderr,
"Warning: no rows selected for page %" PRId32
"\n", sdds_dataset.page_number);
195 for (i = 0; i < outputs; i++) {
196 if (!output[i]->fp) {
197 if (separate_pages && !output[i]->parameter_output)
198 snprintf(filename,
sizeof(filename),
"%s_%03ld_%s_%s.out", rootname, output[i]->counter++, output[i]->item[0], output[i]->item[1]);
200 snprintf(filename,
sizeof(filename),
"%s_%s_%s.out", rootname, output[i]->item[0], output[i]->item[1]);
201 set_up_output(filename, output[i], label_parameter, label_parameters, separate_pages, announce_openings, &sdds_dataset);
203 if (!output[i]->parameter_output) {
205 data[2] = data[3] = NULL;
206 if (!(data[0] =
SDDS_GetColumn(&sdds_dataset, output[i]->item[0])) ||
208 (output[i]->columns > 2 && !(data[2] =
SDDS_GetColumn(&sdds_dataset, output[i]->item[2]))) ||
209 (output[i]->columns > 3 && !(data[3] =
SDDS_GetColumn(&sdds_dataset, output[i]->item[3])))) {
213 for (int64_t j = 0; j < n_rows; j++) {
214 for (
long k = 0; k < output[i]->columns; k++) {
215 SDDS_PrintTypedValue((
char *)data[k], j, coldef[k]->type, coldef[k]->format_string, output[i]->fp, 0);
216 if (k < output[i]->columns - 1)
217 fputc(
' ', output[i]->fp);
219 fputc(
'\n', output[i]->fp);
221 output[i]->points += n_rows;
222 for (
long k = 0; k < output[i]->columns; k++) {
227 for (
long k = 0; k < output[i]->columns; k++) {
233 output[i]->points += 1;
234 for (
long k = 0; k < output[i]->columns; k++) {
235 SDDS_PrintTypedValue((
char *)¶m[k], 0, pardef[k]->type, pardef[k]->format_string, output[i]->fp, 0);
236 if (k < output[i]->columns - 1)
237 fputc(
' ', output[i]->fp);
239 fputc(
'\n', output[i]->fp);
241 if (separate_pages && !output[i]->parameter_output) {
242 fclose(output[i]->fp);
243 output[i]->fp = NULL;
244 output[i]->points = 0;
249 if (page_number == 0) {
253 if (page_number == -1 && !data_present) {
258 fprintf(stderr,
"Error: input data file is empty\n");
262 for (i = 0; i < outputs; i++) {
264 fclose(output[i]->fp);
267 for (i = 0; i < outputs; i++) {
268 if (!separate_pages || output[i]->parameter_output) {
269 snprintf(filename,
sizeof(filename),
"%s_%s_%s.out", rootname, output[i]->item[0], output[i]->item[1]);
270 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.
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)