112 {
114 long nPoly, iPoly, iInput;
115 int64_t row, rows;
116 int iArg;
117 char *input, *output;
118 unsigned long pipeFlags;
119 SCANNED_ARG *scanned;
121 double *outputData;
122
124 argc =
scanargs(&scanned, argc, argv);
125 if (argc < 3) {
127 }
128
129 outputData = NULL;
130 input = output = NULL;
131 pipeFlags = 0;
133 nPoly = 0;
134
135 for (iArg = 1; iArg < argc; iArg++) {
136 if (scanned[iArg].arg_type == OPTION) {
137
138 switch (
match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
139 case CLO_EVALUATE:
145 }
146
147 scanned[iArg].n_items -= 1;
149 scanned[iArg].list + 1,
150 &scanned[iArg].n_items,
151 0,
153 "output",
SDDS_STRING, &(
poly[nPoly].outputColumn), 1, POLY_OUTPUT_SEEN,
154 "coefficients",
SDDS_STRING, &(
poly[nPoly].coefColumn), 1, POLY_COEF_SEEN,
165 NULL) ||
166 !(
poly[nPoly].flags & POLY_FILE_SEEN) ||
167 !(
poly[nPoly].flags & POLY_OUTPUT_SEEN) ||
168 !(
poly[nPoly].flags & POLY_COEF_SEEN) ||
169 !(
poly[nPoly].flags & POLY_IN0_SEEN) ||
170 !(
poly[nPoly].flags & POLY_OUT0_SEEN)) {
172 }
173 nPoly++;
174 break;
175
176 case CLO_PIPE:
178 scanned[iArg].n_items - 1,
179 &pipeFlags)) {
181 }
182 break;
183
184 default:
185 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
186 exit(EXIT_FAILURE);
187 break;
188 }
189 } else {
190 if (!input) {
191 input = scanned[iArg].list[0];
192 } else if (!output) {
193 output = scanned[iArg].list[0];
194 } else {
196 }
197 }
198 }
199
201
202 if (nPoly == 0) {
203 SDDS_Bomb(
"give at least one -evaluate option");
204 }
205
208 }
209
212 }
213
214 for (iPoly = 0; iPoly < nPoly; iPoly++) {
215 initializePolynomial(&
poly[iPoly], &SDDSin, &SDDSout);
216 }
217
220 }
221
226 }
227
228 outputData =
SDDS_Realloc(outputData,
sizeof(*outputData) * rows);
229 if (!outputData) {
231 }
232
233 for (iPoly = 0; iPoly < nPoly; iPoly++) {
234 for (iInput = 0; iInput <
poly[iPoly].nInputs; iInput++) {
235 poly[iPoly].inputData[iInput] =
237 if (!
poly[iPoly].inputData[iInput]) {
239 }
240 }
241
242 for (row = 0; row < rows; row++) {
243 for (iInput = 0; iInput <
poly[iPoly].nInputs; iInput++) {
244 poly[iPoly].input[iInput] =
poly[iPoly].inputData[iInput][row];
245 }
246 outputData[row] = evaluatePoly(
poly[iPoly].coef,
250 poly[iPoly].nInputs);
251 }
252
253 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_NAME, outputData, rows,
poly[iPoly].outputColumn)) {
255 }
256 }
257
260 }
261 }
262
263 free(outputData);
264
267 exit(EXIT_FAILURE);
268 }
269
272 exit(EXIT_FAILURE);
273 }
274
276 FreePolynormialMemory(
poly, nPoly);
278
279 return EXIT_SUCCESS;
280}
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_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an 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_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_STRING
Identifier for the string 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)
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.