126 {
127 int iArg;
128 SCANNED_ARG *scanned = NULL;
129 char *input = NULL, *output = NULL, *boundaryInput = NULL;
130 char *xColumn = NULL, *yColumn = NULL, *bxColumn = NULL, *byColumn = NULL;
131 char *insideColumn = "InsideSum";
133 int32_t *keep;
134 long keepCode = KEEP_ALL;
135 long readCode, keepSeen = 0;
136 int64_t i;
137 unsigned long pipeFlags = 0;
138
140 argc =
scanargs(&scanned, argc, argv);
141 if (argc < 3)
143
144 for (iArg = 1; iArg < argc; iArg++) {
145 if (scanned[iArg].arg_type == OPTION) {
146
147 switch (
match_string(scanned[iArg].list[0], option, N_OPTIONS, 0)) {
148 case SET_COLUMNS:
149 if (xColumn || yColumn)
150 SDDS_Bomb(
"only one -columns option may be given");
151 if (scanned[iArg].n_items != 3)
153 xColumn = scanned[iArg].list[1];
154 yColumn = scanned[iArg].list[2];
155 break;
156 case SET_BOUNDARY:
157 if (boundaryInput)
158 SDDS_Bomb(
"only one -boundary option may be given");
159 if (scanned[iArg].n_items != 4)
161 boundaryInput = scanned[iArg].list[1];
162 bxColumn = scanned[iArg].list[2];
163 byColumn = scanned[iArg].list[3];
164 break;
165 case SET_INSIDE_COLUMN:
166 if (scanned[iArg].n_items != 2)
167 SDDS_Bomb(
"invalid -insideColumn syntax");
168 insideColumn = scanned[iArg].list[1];
169 break;
170 case SET_KEEP:
171 if (keepSeen)
172 SDDS_Bomb(
"only one -keep option may be given");
173 if (scanned[iArg].n_items != 2)
175 if ((keepCode =
match_string(scanned[iArg].list[1], keepOption, N_KEEP_OPTIONS, 0)) < 0)
176 SDDS_Bomb(
"invalid -keep value. Supply 'all', 'inside', or 'outside' or a unique abbreviation");
177 break;
178 case SET_PIPE:
179 if (!
processPipeOption(scanned[iArg].list + 1, scanned[iArg].n_items - 1, &pipeFlags))
181 break;
182 case SET_THREADS:
183 if (scanned[iArg].n_items != 2 ||
184 sscanf(scanned[iArg].list[1], "%d", &threads) != 1 || threads < 1)
186 break;
187 default:
188 fprintf(stderr, "error: unknown/ambiguous option: %s\n", scanned[iArg].list[0]);
189 exit(1);
190 break;
191 }
192 } else {
193 if (!input)
194 input = scanned[iArg].list[0];
195 else if (!output)
196 output = scanned[iArg].list[0];
197 else
199 }
200 }
201
202 processFilenames(
"sddsinsideboundaries", &input, &output, pipeFlags, 0, NULL);
203 if (!pipeFlags && strcmp(input, output) == 0)
204 SDDS_Bomb(
"can't use same file for input and output");
205
206 if (!boundaryInput || !bxColumn || !byColumn)
207 SDDS_Bomb(
"-boundaries option must be given");
208 if ((nBoundaries = read_boundary_data(boundaryInput, bxColumn, byColumn, &xBoundary, &yBoundary, &nValues)) <= 0)
209 SDDS_Bomb(
"No valid data in boundary data file");
210
214
216 SDDS_Bomb(
"-xColumn is not present or not numeric");
218 SDDS_Bomb(
"-yColumn is not present or not numeric");
219
222
225
226 insideSumData = NULL;
227 keep = NULL;
228 xData = yData = NULL;
229 omp_set_num_threads(threads);
230
239 }
240 insideSumData = calloc(rows, sizeof(*insideSumData));
241 keep = calloc(rows, sizeof(*keep));
242
243#pragma omp parallel for
244 for (i = 0; i < rows; i++) {
245 insideSumData[i] = compute_inside_sum(xData[i], yData[i], xBoundary, yBoundary, nValues, nBoundaries);
246 switch (keepCode) {
247 case KEEP_INSIDE:
248 keep[i] = insideSumData[i];
249 break;
250 case KEEP_OUTSIDE:
251 keep[i] = insideSumData[i] == 0;
252 break;
253 default:
254 keep[i] = 1;
255 break;
256 }
257 }
258 if (!
SDDS_SetColumn(&SDDSout, SDDS_SET_BY_NAME, insideSumData, rows, insideColumn) ||
262 free(keep);
263 free(insideSumData);
264 free(xData);
265 free(yData);
266 }
269 return 0;
270}
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_DefineColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length)
Defines a data column within the SDDS dataset.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_CheckColumn(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a column exists in the SDDS dataset with the specified name, units, and type.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
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.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric 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)