106 {
108 long i_arg;
109 SCANNED_ARG *s_arg;
111 char *input = NULL, *output = NULL, *colPrefix = NULL, *background = NULL;
112 long profileType = 1, noWarnings = 0, tmpfile_used = 0, method = 0;
113 unsigned long pipeFlags = 0;
114 int64_t rows, bg_rows, j;
115 long i, validColumns = 0, bg_validColumns = 0;
116 int32_t *type = NULL, *bg_type = NULL;
117
118 int64_t rowStart = 1, rowEnd = 0;
119 long columnStart = 1, columnEnd = 0;
120
121 long *colIndex, *bg_colIndex;
122 double *colIndex2, *bg_colIndex2;
123
125 argc =
scanargs(&s_arg, argc, argv);
126
127 if (argc < 3)
129
130 for (i_arg = 1; i_arg < argc; i_arg++) {
131 if (s_arg[i_arg].arg_type == OPTION) {
132 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
133 case SET_PROFILETYPE:
134 if (s_arg[i_arg].n_items != 2)
135 SDDS_Bomb(
"invalid -profileType syntax");
136 if (strcmp("x", s_arg[i_arg].list[1]) == 0)
137 profileType = 1;
138 if (strcmp("y", s_arg[i_arg].list[1]) == 0)
139 profileType = 2;
140 break;
141 case SET_COLPREFIX:
142 if (s_arg[i_arg].n_items != 2)
143 SDDS_Bomb(
"invalid -columnPrefix syntax");
144 colPrefix = s_arg[i_arg].list[1];
145 break;
146 case SET_METHOD:
147 if (s_arg[i_arg].n_items != 2)
149 if ((strncasecmp("centralLine", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0) ||
150 (strncasecmp("centerLine", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0))
151 method = 1;
152 if (strncasecmp("integrated", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
153 method = 2;
154 if (strncasecmp("averaged", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
155 method = 3;
156 if (strncasecmp("peak", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
157 method = 4;
158 break;
159 case SET_AREAOFINTEREST:
160 if (s_arg[i_arg].n_items != 5)
161 SDDS_Bomb(
"invalid -areaOfInterest syntax");
162 if (sscanf(s_arg[i_arg].list[1], "%" SCNd64, &rowStart) != 1 || rowStart <= 0)
163 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
164 if (sscanf(s_arg[i_arg].list[2], "%" SCNd64, &rowEnd) != 1 || rowEnd <= 0)
165 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
166 if (sscanf(s_arg[i_arg].list[3], "%ld", &columnStart) != 1 || columnStart <= 0)
167 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
168 if (sscanf(s_arg[i_arg].list[4], "%ld", &columnEnd) != 1 || columnEnd <= 0)
169 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
170 break;
171 case SET_BACKGROUND:
172 if (s_arg[i_arg].n_items != 2)
174 background = s_arg[i_arg].list[1];
175 break;
176 case SET_PIPE:
177 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
179 break;
180 default:
181 fprintf(stderr, "error: unknown switch: %s\n", s_arg[i_arg].list[0]);
182 exit(EXIT_FAILURE);
183 break;
184 }
185 } else {
186 if (input == NULL)
187 input = s_arg[i_arg].list[0];
188 else if (output == NULL)
189 output = s_arg[i_arg].list[0];
190 else
192 }
193 }
194
195 if (colPrefix == NULL) {
196 fprintf(stderr, "error: missing columnPrefix\n");
197 exit(EXIT_FAILURE);
198 }
199
200 processFilenames(
"sddsimageprofiles", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
201
202
203 rows = GetData(&SDDS_orig, input, &data, &type, &colIndex, &colIndex2, colPrefix, &validColumns);
204
205 if (rows < 0) {
206 fprintf(stderr, "error: no rows in image file\n");
207 exit(EXIT_FAILURE);
208 }
209
210 if (background != NULL) {
211
212 bg_rows = GetData(&SDDS_bg, background, &bg_data, &bg_type, &bg_colIndex, &bg_colIndex2, colPrefix, &bg_validColumns);
213 if (rows != bg_rows) {
214 fprintf(stderr, "error: background has a different number of rows\n");
215 exit(EXIT_FAILURE);
216 }
217 if (validColumns != bg_validColumns) {
218 fprintf(stderr, "error: background has a different number of columns\n");
219 exit(EXIT_FAILURE);
220 }
221
222 for (i = 0; i < validColumns; i++) {
223 if (type[colIndex[i]] != bg_type[bg_colIndex[i]]) {
224 fprintf(stderr, "error: column types don't match with background image\n");
225 exit(EXIT_FAILURE);
226 }
227 if (colIndex2[i] != bg_colIndex2[i]) {
228 fprintf(stderr, "error: image rows don't match with background image\n");
229 exit(EXIT_FAILURE);
230 }
231 switch (type[colIndex[i]]) {
233 for (j = 0; j < rows; j++)
234 data[colIndex[i]].shortData[j] -= bg_data[bg_colIndex[i]].shortData[j];
235 break;
237 for (j = 0; j < rows; j++)
238 data[colIndex[i]].ushortData[j] -= bg_data[bg_colIndex[i]].ushortData[j];
239 break;
241 for (j = 0; j < rows; j++)
242 data[colIndex[i]].longData[j] -= bg_data[bg_colIndex[i]].longData[j];
243 break;
245 for (j = 0; j < rows; j++)
246 data[colIndex[i]].ulongData[j] -= bg_data[bg_colIndex[i]].ulongData[j];
247 break;
249 for (j = 0; j < rows; j++)
250 data[colIndex[i]].long64Data[j] -= bg_data[bg_colIndex[i]].long64Data[j];
251 break;
253 for (j = 0; j < rows; j++)
254 data[colIndex[i]].ulong64Data[j] -= bg_data[bg_colIndex[i]].ulong64Data[j];
255 break;
257 for (j = 0; j < rows; j++)
258 data[colIndex[i]].floatData[j] -= bg_data[bg_colIndex[i]].floatData[j];
259 break;
261 for (j = 0; j < rows; j++)
262 data[colIndex[i]].doubleData[j] -= bg_data[bg_colIndex[i]].doubleData[j];
263 break;
264 default:
265 continue;
266 }
267 }
268 }
269
270
273 exit(EXIT_FAILURE);
274 }
275
276 if (profileType == 1) {
279 exit(EXIT_FAILURE);
280 }
283 exit(EXIT_FAILURE);
284 }
287 exit(EXIT_FAILURE);
288 }
289 } else {
292 exit(EXIT_FAILURE);
293 }
296 exit(EXIT_FAILURE);
297 }
300 exit(EXIT_FAILURE);
301 }
302 }
305 exit(EXIT_FAILURE);
306 }
307
308 if ((rowEnd > rows) || (rowEnd < rowStart))
309 rowEnd = rows;
310
311 if ((columnEnd > validColumns) || (columnEnd < columnStart))
312 columnEnd = validColumns;
313
314 if (profileType == 1) {
315 xImageProfile(data, type, rows, &SDDS_dataset, method, rowStart - 1, rowEnd, columnStart - 1, columnEnd, colIndex, colIndex2);
316 } else {
317 yImageProfile(data, type, rows, &SDDS_dataset, method, rowStart - 1, rowEnd, columnStart - 1, columnEnd, colIndex, colIndex2);
318 }
319
320
323 exit(EXIT_FAILURE);
324 }
325
326 for (i = 0; i < validColumns; i++) {
327 switch (type[colIndex[i]]) {
329 free(data[colIndex[i]].shortData);
330 break;
332 free(data[colIndex[i]].ushortData);
333 break;
335 free(data[colIndex[i]].longData);
336 break;
338 free(data[colIndex[i]].ulongData);
339 break;
341 free(data[colIndex[i]].long64Data);
342 break;
344 free(data[colIndex[i]].ulong64Data);
345 break;
347 free(data[colIndex[i]].floatData);
348 break;
350 free(data[colIndex[i]].doubleData);
351 break;
352 default:
353 continue;
354 }
355 }
356 free(data);
357 free(type);
358 if (background != NULL) {
359 for (i = 0; i < validColumns; i++) {
360 switch (bg_type[bg_colIndex[i]]) {
362 free(bg_data[bg_colIndex[i]].shortData);
363 break;
365 free(bg_data[bg_colIndex[i]].ushortData);
366 break;
368 free(bg_data[bg_colIndex[i]].longData);
369 break;
371 free(bg_data[bg_colIndex[i]].ulongData);
372 break;
374 free(bg_data[bg_colIndex[i]].long64Data);
375 break;
377 free(bg_data[bg_colIndex[i]].ulong64Data);
378 break;
380 free(bg_data[bg_colIndex[i]].floatData);
381 break;
383 free(bg_data[bg_colIndex[i]].doubleData);
384 break;
385 default:
386 continue;
387 }
388 }
389 free(bg_data);
390 free(bg_type);
391 }
392
393 return EXIT_SUCCESS;
394}
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)