120 {
122 long i_arg;
123 SCANNED_ARG *s_arg;
125 char *input = NULL, *output = NULL, *colPrefix = NULL, *background = NULL;
126 long profileType = 1, noWarnings = 0, tmpfile_used = 0, method = 0;
127 unsigned long pipeFlags = 0;
128 int64_t rows, bg_rows, j;
129 long i, validColumns = 0, bg_validColumns = 0;
130 int32_t *type = NULL, *bg_type = NULL;
131
132 int64_t rowStart = 1, rowEnd = 0;
133 long columnStart = 1, columnEnd = 0;
134
135 long *colIndex, *bg_colIndex;
136 double *colIndex2, *bg_colIndex2;
137
139 argc =
scanargs(&s_arg, argc, argv);
140
141 if (argc < 3)
143
144 for (i_arg = 1; i_arg < argc; i_arg++) {
145 if (s_arg[i_arg].arg_type == OPTION) {
146 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
147 case SET_PROFILETYPE:
148 if (s_arg[i_arg].n_items != 2)
149 SDDS_Bomb(
"invalid -profileType syntax");
150 if (strcmp("x", s_arg[i_arg].list[1]) == 0)
151 profileType = 1;
152 if (strcmp("y", s_arg[i_arg].list[1]) == 0)
153 profileType = 2;
154 break;
155 case SET_COLPREFIX:
156 if (s_arg[i_arg].n_items != 2)
157 SDDS_Bomb(
"invalid -columnPrefix syntax");
158 colPrefix = s_arg[i_arg].list[1];
159 break;
160 case SET_METHOD:
161 if (s_arg[i_arg].n_items != 2)
163 if ((strncasecmp("centralLine", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0) ||
164 (strncasecmp("centerLine", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0))
165 method = 1;
166 if (strncasecmp("integrated", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
167 method = 2;
168 if (strncasecmp("averaged", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
169 method = 3;
170 if (strncasecmp("peak", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
171 method = 4;
172 break;
173 case SET_AREAOFINTEREST:
174 if (s_arg[i_arg].n_items != 5)
175 SDDS_Bomb(
"invalid -areaOfInterest syntax");
176 if (sscanf(s_arg[i_arg].list[1], "%" SCNd64, &rowStart) != 1 || rowStart <= 0)
177 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
178 if (sscanf(s_arg[i_arg].list[2], "%" SCNd64, &rowEnd) != 1 || rowEnd <= 0)
179 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
180 if (sscanf(s_arg[i_arg].list[3], "%ld", &columnStart) != 1 || columnStart <= 0)
181 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
182 if (sscanf(s_arg[i_arg].list[4], "%ld", &columnEnd) != 1 || columnEnd <= 0)
183 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
184 break;
185 case SET_BACKGROUND:
186 if (s_arg[i_arg].n_items != 2)
188 background = s_arg[i_arg].list[1];
189 break;
190 case SET_PIPE:
191 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
193 break;
194 default:
195 fprintf(stderr, "error: unknown switch: %s\n", s_arg[i_arg].list[0]);
196 exit(EXIT_FAILURE);
197 break;
198 }
199 } else {
200 if (input == NULL)
201 input = s_arg[i_arg].list[0];
202 else if (output == NULL)
203 output = s_arg[i_arg].list[0];
204 else
206 }
207 }
208
209 if (colPrefix == NULL) {
210 fprintf(stderr, "error: missing columnPrefix\n");
211 exit(EXIT_FAILURE);
212 }
213
214 processFilenames(
"sddsimageprofiles", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
215
216
217 rows = GetData(&SDDS_orig, input, &data, &type, &colIndex, &colIndex2, colPrefix, &validColumns);
218
219 if (rows < 0) {
220 fprintf(stderr, "error: no rows in image file\n");
221 exit(EXIT_FAILURE);
222 }
223
224 if (background != NULL) {
225
226 bg_rows = GetData(&SDDS_bg, background, &bg_data, &bg_type, &bg_colIndex, &bg_colIndex2, colPrefix, &bg_validColumns);
227 if (rows != bg_rows) {
228 fprintf(stderr, "error: background has a different number of rows\n");
229 exit(EXIT_FAILURE);
230 }
231 if (validColumns != bg_validColumns) {
232 fprintf(stderr, "error: background has a different number of columns\n");
233 exit(EXIT_FAILURE);
234 }
235
236 for (i = 0; i < validColumns; i++) {
237 if (type[colIndex[i]] != bg_type[bg_colIndex[i]]) {
238 fprintf(stderr, "error: column types don't match with background image\n");
239 exit(EXIT_FAILURE);
240 }
241 if (colIndex2[i] != bg_colIndex2[i]) {
242 fprintf(stderr, "error: image rows don't match with background image\n");
243 exit(EXIT_FAILURE);
244 }
245 switch (type[colIndex[i]]) {
247 for (j = 0; j < rows; j++)
248 data[colIndex[i]].shortData[j] -= bg_data[bg_colIndex[i]].shortData[j];
249 break;
251 for (j = 0; j < rows; j++)
252 data[colIndex[i]].ushortData[j] -= bg_data[bg_colIndex[i]].ushortData[j];
253 break;
255 for (j = 0; j < rows; j++)
256 data[colIndex[i]].longData[j] -= bg_data[bg_colIndex[i]].longData[j];
257 break;
259 for (j = 0; j < rows; j++)
260 data[colIndex[i]].ulongData[j] -= bg_data[bg_colIndex[i]].ulongData[j];
261 break;
263 for (j = 0; j < rows; j++)
264 data[colIndex[i]].long64Data[j] -= bg_data[bg_colIndex[i]].long64Data[j];
265 break;
267 for (j = 0; j < rows; j++)
268 data[colIndex[i]].ulong64Data[j] -= bg_data[bg_colIndex[i]].ulong64Data[j];
269 break;
271 for (j = 0; j < rows; j++)
272 data[colIndex[i]].floatData[j] -= bg_data[bg_colIndex[i]].floatData[j];
273 break;
275 for (j = 0; j < rows; j++)
276 data[colIndex[i]].doubleData[j] -= bg_data[bg_colIndex[i]].doubleData[j];
277 break;
278 default:
279 continue;
280 }
281 }
282 }
283
284
287 exit(EXIT_FAILURE);
288 }
289
290 if (profileType == 1) {
293 exit(EXIT_FAILURE);
294 }
297 exit(EXIT_FAILURE);
298 }
301 exit(EXIT_FAILURE);
302 }
303 } else {
306 exit(EXIT_FAILURE);
307 }
310 exit(EXIT_FAILURE);
311 }
314 exit(EXIT_FAILURE);
315 }
316 }
319 exit(EXIT_FAILURE);
320 }
321
322 if ((rowEnd > rows) || (rowEnd < rowStart))
323 rowEnd = rows;
324
325 if ((columnEnd > validColumns) || (columnEnd < columnStart))
326 columnEnd = validColumns;
327
328 if (profileType == 1) {
329 xImageProfile(data, type, rows, &SDDS_dataset, method, rowStart - 1, rowEnd, columnStart - 1, columnEnd, colIndex, colIndex2);
330 } else {
331 yImageProfile(data, type, rows, &SDDS_dataset, method, rowStart - 1, rowEnd, columnStart - 1, columnEnd, colIndex, colIndex2);
332 }
333
334
337 exit(EXIT_FAILURE);
338 }
339
340 for (i = 0; i < validColumns; i++) {
341 switch (type[colIndex[i]]) {
343 free(data[colIndex[i]].shortData);
344 break;
346 free(data[colIndex[i]].ushortData);
347 break;
349 free(data[colIndex[i]].longData);
350 break;
352 free(data[colIndex[i]].ulongData);
353 break;
355 free(data[colIndex[i]].long64Data);
356 break;
358 free(data[colIndex[i]].ulong64Data);
359 break;
361 free(data[colIndex[i]].floatData);
362 break;
364 free(data[colIndex[i]].doubleData);
365 break;
366 default:
367 continue;
368 }
369 }
370 free(data);
371 free(type);
372 if (background != NULL) {
373 for (i = 0; i < validColumns; i++) {
374 switch (bg_type[bg_colIndex[i]]) {
376 free(bg_data[bg_colIndex[i]].shortData);
377 break;
379 free(bg_data[bg_colIndex[i]].ushortData);
380 break;
382 free(bg_data[bg_colIndex[i]].longData);
383 break;
385 free(bg_data[bg_colIndex[i]].ulongData);
386 break;
388 free(bg_data[bg_colIndex[i]].long64Data);
389 break;
391 free(bg_data[bg_colIndex[i]].ulong64Data);
392 break;
394 free(bg_data[bg_colIndex[i]].floatData);
395 break;
397 free(bg_data[bg_colIndex[i]].doubleData);
398 break;
399 default:
400 continue;
401 }
402 }
403 free(bg_data);
404 free(bg_type);
405 }
406
407 return EXIT_SUCCESS;
408}
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
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_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
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_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)