117 {
119 long nPoly, iPoly, iInput;
120 int64_t row, rows;
121 int iArg;
122 char *input, *output;
123 unsigned long pipeFlags;
124 SCANNED_ARG *scanned;
126 double *outputData;
127
129 argc =
scanargs(&scanned, argc, argv);
130 if (argc < 3) {
132 }
133
134 outputData = NULL;
135 input = output = NULL;
136 pipeFlags = 0;
138 nPoly = 0;
139
140 for (iArg = 1; iArg < argc; iArg++) {
141 if (scanned[iArg].arg_type == OPTION) {
142
143 switch (
match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
144 case CLO_EVALUATE:
150 }
151
152 scanned[iArg].n_items -= 1;
154 scanned[iArg].list + 1,
155 &scanned[iArg].n_items,
156 0,
158 "output",
SDDS_STRING, &(
poly[nPoly].outputColumn), 1, POLY_OUTPUT_SEEN,
159 "coefficients",
SDDS_STRING, &(
poly[nPoly].coefColumn), 1, POLY_COEF_SEEN,
170 NULL) ||
171 !(
poly[nPoly].flags & POLY_FILE_SEEN) ||
172 !(
poly[nPoly].flags & POLY_OUTPUT_SEEN) ||
173 !(
poly[nPoly].flags & POLY_COEF_SEEN) ||
174 !(
poly[nPoly].flags & POLY_IN0_SEEN) ||
175 !(
poly[nPoly].flags & POLY_OUT0_SEEN)) {
177 }
178 nPoly++;
179 break;
180
181 case CLO_PIPE:
183 scanned[iArg].n_items - 1,
184 &pipeFlags)) {
186 }
187 break;
188
189 default:
190 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
191 exit(EXIT_FAILURE);
192 break;
193 }
194 } else {
195 if (!input) {
196 input = scanned[iArg].list[0];
197 } else if (!output) {
198 output = scanned[iArg].list[0];
199 } else {
201 }
202 }
203 }
204
206
207 if (nPoly == 0) {
208 SDDS_Bomb(
"give at least one -evaluate option");
209 }
210
213 }
214
217 }
218
219 for (iPoly = 0; iPoly < nPoly; iPoly++) {
220 initializePolynomial(&
poly[iPoly], &SDDSin, &SDDSout);
221 }
222
225 }
226
231 }
232
233 outputData =
SDDS_Realloc(outputData,
sizeof(*outputData) * rows);
234 if (!outputData) {
236 }
237
238 for (iPoly = 0; iPoly < nPoly; iPoly++) {
239 for (iInput = 0; iInput <
poly[iPoly].nInputs; iInput++) {
240 poly[iPoly].inputData[iInput] =
242 if (!
poly[iPoly].inputData[iInput]) {
244 }
245 }
246
247 for (row = 0; row < rows; row++) {
248 for (iInput = 0; iInput <
poly[iPoly].nInputs; iInput++) {
249 poly[iPoly].input[iInput] =
poly[iPoly].inputData[iInput][row];
250 }
251 outputData[row] = evaluatePoly(
poly[iPoly].coef,
255 poly[iPoly].nInputs);
256 }
257
258 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_NAME, outputData, rows,
poly[iPoly].outputColumn)) {
260 }
261 }
262
265 }
266 }
267
268 free(outputData);
269
272 exit(EXIT_FAILURE);
273 }
274
277 exit(EXIT_FAILURE);
278 }
279
281 FreePolynormialMemory(
poly, nPoly);
283
284 return EXIT_SUCCESS;
285}
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.