103 {
104 int iArg, iColumn, verbose;
105 char *input, *output;
106 unsigned long pipeFlags;
107 SCANNED_ARG *scanned;
110 long nColumns;
111 double *data;
112 int64_t rows;
113 short makeParameters;
114 double min, max;
115 int64_t points;
116
118 argc =
scanargs(&scanned, argc, argv);
119 if (argc < 3)
121
122 nColumns = 0;
123 column = NULL;
124 input = output = NULL;
125 pipeFlags = 0;
126 verbose = 0;
127 makeParameters = 0;
128
129 for (iArg = 1; iArg < argc; iArg++) {
130 if (scanned[iArg].arg_type == OPTION) {
131
132 switch (
match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
133 case CLO_COLUMN:
134 column =
SDDS_Realloc(column,
sizeof(*column) * (nColumns + 1));
135 column[nColumns].name = scanned[iArg].list[1];
136 column[nColumns].maximumBins = -1;
137 column[nColumns].binFactor = 10;
138 column[nColumns].deltaGuess = -1;
139 column[nColumns].flags = COLUMN_BIN_FACTOR;
140 column[nColumns].adjustFactor = 0.9;
141 scanned[iArg].n_items -= 2;
142 if (scanned[iArg].n_items) {
143 if (!
scanItemList(&(column[nColumns].flags), scanned[iArg].list + 2, &scanned[iArg].n_items, 0,
144 "maximumbins",
SDDS_LONG, &(column[nColumns].maximumBins), 1, COLUMN_MAXIMUM_BINS,
145 "binfactor",
SDDS_LONG, &(column[nColumns].binFactor), 1, COLUMN_BIN_FACTOR,
146 "deltaguess",
SDDS_DOUBLE, &(column[nColumns].deltaGuess), 1, COLUMN_DELTA_GUESS,
147 "adjustfactor",
SDDS_DOUBLE, &(column[nColumns].adjustFactor), 1, COLUMN_ADJUST_FACTOR,
148 NULL)) {
150 }
151 if (column[nColumns].flags & COLUMN_ADJUST_FACTOR) {
152 if (column[nColumns].adjustFactor <= 0 || column[nColumns].adjustFactor >= 1)
153 SDDS_Bomb(
"invalid -column syntax. adjustFactor must be (0,1)");
154 }
155 if (column[nColumns].flags & COLUMN_DELTA_GUESS) {
156 if (column[nColumns].flags & ~(COLUMN_DELTA_GUESS | COLUMN_ADJUST_FACTOR))
157 SDDS_Bomb(
"invalid -column syntax. Can't combine deltaGuess with other options.");
158 if (column[nColumns].deltaGuess <= 0)
159 SDDS_Bomb(
"invalid -column syntax. deltaGuess<=0.");
160 } else {
161 if (column[nColumns].flags & COLUMN_BIN_FACTOR && column[nColumns].flags & COLUMN_MAXIMUM_BINS)
162 SDDS_Bomb(
"invalid -column syntax. Can't give minimumBins and maximumBins with binFactor");
163 if (!(column[nColumns].flags & COLUMN_BIN_FACTOR) && !(column[nColumns].flags & COLUMN_MAXIMUM_BINS))
164 SDDS_Bomb(
"invalid -column syntax. Give maximumBins or binFactor");
165 if (column[nColumns].flags & COLUMN_BIN_FACTOR && column[nColumns].binFactor < 1)
166 SDDS_Bomb(
"invalid -column syntax. binFactor<1");
167 }
168 }
169 nColumns++;
170 break;
171 case CLO_PIPE:
172 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
174 break;
175 case CLO_VERBOSE:
176 verbose = 1;
177 break;
178 case CLO_MAKE_PARAMETERS:
179 makeParameters = 1;
180 break;
181 default:
182 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
183 exit(EXIT_FAILURE);
184 break;
185 }
186 } else {
187 if (!input)
188 input = scanned[iArg].list[0];
189 else if (!output)
190 output = scanned[iArg].list[0];
191 else
193 }
194 }
195
197
200
203 if (makeParameters)
204 AddParameterDefinitions(&SDDSout, &SDDSin, column, nColumns);
207
212 for (iColumn = 0; iColumn < nColumns; iColumn++) {
215 SnapDataToGrid(data, rows, column + iColumn, verbose, &min, &max, &points);
218 if (makeParameters)
219 StoreGridParameters(&SDDSout, column[iColumn].name, min, max, points);
220 free(data);
221 }
224 }
225
228 exit(EXIT_FAILURE);
229 }
232 exit(EXIT_FAILURE);
233 }
234
235 return EXIT_SUCCESS;
236}
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_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows,...)
Sets the values for a single data column using double-precision floating-point numbers.
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_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 * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_DOUBLE
Identifier for the double 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.