52#define BACKGROUND_AUTO 0x0001UL
53#define BACKGROUND_KEEP_NEGATIVE 0x0002UL
54#define AUTO_BACKGROUND_BINS 256
67char *option[N_OPTIONS] = {
68 "pipe",
"profileType",
"columnPrefix",
69 "method",
"areaOfInterest",
"background"};
72 "sddsimageprofiles [<inputfile>] [<outputfile>]\n"
73 " [-pipe=[input][,output]]\n"
74 " -columnPrefix=<prefix>\n"
75 " [-profileType={x|y}]\n"
76 " [-method={centerLine|integrated|averaged|peak}]\n"
77 " [-background=<filename>|auto[,halfwidth=<value>][,keepNegative]]\n"
78 " [-areaOfInterest=<rowStart>,<rowEnd>,<columnStart>,<columnEnd>]\n"
80 " -pipe=[input][,output] Specify input and/or output via pipe.\n"
81 " -columnPrefix=<prefix> Set the column prefix.\n"
82 " -profileType={x|y} Choose profile type: 'x' or 'y'.\n"
83 " -method={centerLine|integrated|averaged|peak} Select the method for profile analysis.\n"
84 " -background=<filename> Specify a background image file.\n"
85 " -background=auto[,halfwidth=<value>][,keepNegative] Estimate background from the image, subtract it\n"
86 " before profiling, and clip negatives unless\n"
87 " keepNegative is given.\n"
88 " -areaOfInterest=<rowStart>,<rowEnd>,<columnStart>,<columnEnd> Define the area of interest.\n\n"
89 "Program by Robert Soliday. (\"" __DATE__
" " __TIME__
"\", SVN revision: " SVN_VERSION
")\n\n"
91 " If this option is not specified, it is a real profile.\n"
92 " If centerLine is specified, it will find the row with the\n"
93 " greatest integrated profile and display that line only.\n"
94 " If integrated is specified, it will sum all the profiles\n"
95 " together. If averaged is specified, it will divide the sum\n"
96 " of all the profiles by the number of profiles. If peak is\n"
97 " specified, it will find the peak point and display the profile\n"
102 unsigned short *ushortData;
106 uint64_t *ulong64Data;
112 long method, int64_t x1, int64_t x2,
long y1,
long y2,
long *colIndex,
double *colIndex2);
115 long method, int64_t x1, int64_t x2,
long y1,
long y2,
long *colIndex,
double *colIndex2);
117int64_t xPeakLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2);
119long yPeakLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2);
121int64_t xCenterLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2);
123long yCenterLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2);
126 double **colIndex2,
char *colPrefix,
long *validColumns);
128double getImageValue(
const IMAGE_DATA *data, int32_t type, int64_t row);
130void convertImageDataToDouble(
IMAGE_DATA *data, int32_t *type, int64_t rows,
long *colIndex,
long validColumns);
132double estimateBackgroundLevel(
IMAGE_DATA *data, int32_t *type, int64_t rows,
long *colIndex,
long validColumns,
133 long backgroundHalfWidth);
135void subtractBackgroundLevel(
IMAGE_DATA *data, int32_t *type, int64_t rows,
long *colIndex,
long validColumns,
136 double backgroundLevel,
long clipNegative);
138int main(
int argc,
char **argv) {
143 char *input = NULL, *output = NULL, *colPrefix = NULL, *background = NULL;
144 long profileType = 1, noWarnings = 0, tmpfile_used = 0, method = 0;
145 unsigned long pipeFlags = 0;
146 unsigned long backgroundFlags = 0;
147 int64_t rows, bg_rows, j;
148 long i, validColumns = 0, bg_validColumns = 0;
149 int32_t *type = NULL, *bg_type = NULL;
150 long backgroundHalfWidth = 1;
151 double backgroundLevel = 0;
153 int64_t rowStart = 1, rowEnd = 0;
154 long columnStart = 1, columnEnd = 0;
156 long *colIndex, *bg_colIndex;
157 double *colIndex2, *bg_colIndex2;
160 argc =
scanargs(&s_arg, argc, argv);
165 for (i_arg = 1; i_arg < argc; i_arg++) {
166 if (s_arg[i_arg].arg_type == OPTION) {
167 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
168 case SET_PROFILETYPE:
169 if (s_arg[i_arg].n_items != 2)
170 SDDS_Bomb(
"invalid -profileType syntax");
171 if (strcmp(
"x", s_arg[i_arg].list[1]) == 0)
173 if (strcmp(
"y", s_arg[i_arg].list[1]) == 0)
177 if (s_arg[i_arg].n_items != 2)
178 SDDS_Bomb(
"invalid -columnPrefix syntax");
179 colPrefix = s_arg[i_arg].list[1];
182 if (s_arg[i_arg].n_items != 2)
184 if ((strncasecmp(
"centralLine", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0) ||
185 (strncasecmp(
"centerLine", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0))
187 if (strncasecmp(
"integrated", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
189 if (strncasecmp(
"averaged", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
191 if (strncasecmp(
"peak", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) == 0)
194 case SET_AREAOFINTEREST:
195 if (s_arg[i_arg].n_items != 5)
196 SDDS_Bomb(
"invalid -areaOfInterest syntax");
197 if (sscanf(s_arg[i_arg].list[1],
"%" SCNd64, &rowStart) != 1 || rowStart <= 0)
198 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
199 if (sscanf(s_arg[i_arg].list[2],
"%" SCNd64, &rowEnd) != 1 || rowEnd <= 0)
200 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
201 if (sscanf(s_arg[i_arg].list[3],
"%ld", &columnStart) != 1 || columnStart <= 0)
202 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
203 if (sscanf(s_arg[i_arg].list[4],
"%ld", &columnEnd) != 1 || columnEnd <= 0)
204 SDDS_Bomb(
"invalid -areaOfInterest syntax or value");
207 if (s_arg[i_arg].n_items < 2)
209 if (strcasecmp(s_arg[i_arg].list[1],
"auto") == 0) {
211 items = s_arg[i_arg].n_items - 1;
212 if (!
scanItemList(&backgroundFlags, s_arg[i_arg].list + 1, &items, 0,
213 "auto", -1, NULL, 0, BACKGROUND_AUTO,
214 "halfwidth",
SDDS_LONG, &backgroundHalfWidth, 1, 0,
215 "keepNegative", -1, NULL, 0, BACKGROUND_KEEP_NEGATIVE, NULL) ||
216 !(backgroundFlags & BACKGROUND_AUTO) ||
217 backgroundHalfWidth < 0)
218 SDDS_Bomb(
"invalid -background syntax/values");
220 if (s_arg[i_arg].n_items != 2)
222 background = s_arg[i_arg].list[1];
226 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
230 fprintf(stderr,
"error: unknown switch: %s\n", s_arg[i_arg].list[0]);
236 input = s_arg[i_arg].list[0];
237 else if (output == NULL)
238 output = s_arg[i_arg].list[0];
244 if (colPrefix == NULL) {
245 fprintf(stderr,
"error: missing columnPrefix\n");
249 processFilenames(
"sddsimageprofiles", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
252 rows = GetData(&SDDS_orig, input, &data, &type, &colIndex, &colIndex2, colPrefix, &validColumns);
255 fprintf(stderr,
"error: no rows in image file\n");
259 if (background != NULL) {
261 bg_rows = GetData(&SDDS_bg, background, &bg_data, &bg_type, &bg_colIndex, &bg_colIndex2, colPrefix, &bg_validColumns);
262 if (rows != bg_rows) {
263 fprintf(stderr,
"error: background has a different number of rows\n");
266 if (validColumns != bg_validColumns) {
267 fprintf(stderr,
"error: background has a different number of columns\n");
271 for (i = 0; i < validColumns; i++) {
272 if (type[colIndex[i]] != bg_type[bg_colIndex[i]]) {
273 fprintf(stderr,
"error: column types don't match with background image\n");
276 if (colIndex2[i] != bg_colIndex2[i]) {
277 fprintf(stderr,
"error: image rows don't match with background image\n");
280 switch (type[colIndex[i]]) {
282 for (j = 0; j < rows; j++)
283 data[colIndex[i]].shortData[j] -= bg_data[bg_colIndex[i]].shortData[j];
286 for (j = 0; j < rows; j++)
287 data[colIndex[i]].ushortData[j] -= bg_data[bg_colIndex[i]].ushortData[j];
290 for (j = 0; j < rows; j++)
291 data[colIndex[i]].longData[j] -= bg_data[bg_colIndex[i]].longData[j];
294 for (j = 0; j < rows; j++)
295 data[colIndex[i]].ulongData[j] -= bg_data[bg_colIndex[i]].ulongData[j];
298 for (j = 0; j < rows; j++)
299 data[colIndex[i]].long64Data[j] -= bg_data[bg_colIndex[i]].long64Data[j];
302 for (j = 0; j < rows; j++)
303 data[colIndex[i]].ulong64Data[j] -= bg_data[bg_colIndex[i]].ulong64Data[j];
306 for (j = 0; j < rows; j++)
307 data[colIndex[i]].floatData[j] -= bg_data[bg_colIndex[i]].floatData[j];
310 for (j = 0; j < rows; j++)
311 data[colIndex[i]].doubleData[j] -= bg_data[bg_colIndex[i]].doubleData[j];
319 if (backgroundFlags & BACKGROUND_AUTO) {
320 convertImageDataToDouble(data, type, rows, colIndex, validColumns);
321 backgroundLevel = estimateBackgroundLevel(data, type, rows, colIndex, validColumns, backgroundHalfWidth);
322 if (!(pipeFlags & USE_STDOUT))
323 printf(
"Background level subtracted: %.15g\n", backgroundLevel);
324 subtractBackgroundLevel(data, type, rows, colIndex, validColumns, backgroundLevel,
325 !(backgroundFlags & BACKGROUND_KEEP_NEGATIVE));
334 if (profileType == 1) {
366 if ((rowEnd > rows) || (rowEnd < rowStart))
369 if ((columnEnd > validColumns) || (columnEnd < columnStart))
370 columnEnd = validColumns;
372 if (profileType == 1) {
373 xImageProfile(data, type, rows, &SDDS_dataset, method, rowStart - 1, rowEnd, columnStart - 1, columnEnd, colIndex, colIndex2);
375 yImageProfile(data, type, rows, &SDDS_dataset, method, rowStart - 1, rowEnd, columnStart - 1, columnEnd, colIndex, colIndex2);
384 for (i = 0; i < validColumns; i++) {
385 switch (type[colIndex[i]]) {
387 free(data[colIndex[i]].shortData);
390 free(data[colIndex[i]].ushortData);
393 free(data[colIndex[i]].longData);
396 free(data[colIndex[i]].ulongData);
399 free(data[colIndex[i]].long64Data);
402 free(data[colIndex[i]].ulong64Data);
405 free(data[colIndex[i]].floatData);
408 free(data[colIndex[i]].doubleData);
416 if (background != NULL) {
417 for (i = 0; i < validColumns; i++) {
418 switch (bg_type[bg_colIndex[i]]) {
420 free(bg_data[bg_colIndex[i]].shortData);
423 free(bg_data[bg_colIndex[i]].ushortData);
426 free(bg_data[bg_colIndex[i]].longData);
429 free(bg_data[bg_colIndex[i]].ulongData);
432 free(bg_data[bg_colIndex[i]].long64Data);
435 free(bg_data[bg_colIndex[i]].ulong64Data);
438 free(bg_data[bg_colIndex[i]].floatData);
441 free(bg_data[bg_colIndex[i]].doubleData);
454double getImageValue(
const IMAGE_DATA *data, int32_t type, int64_t row) {
457 return data->shortData[row];
459 return data->ushortData[row];
461 return data->longData[row];
463 return data->ulongData[row];
465 return (
double)data->long64Data[row];
467 return (
double)data->ulong64Data[row];
469 return data->floatData[row];
471 return data->doubleData[row];
477void convertImageDataToDouble(
IMAGE_DATA *data, int32_t *type, int64_t rows,
long *colIndex,
long validColumns) {
482 for (i = 0; i < validColumns; i++) {
483 column = colIndex[i];
486 if (!(doubleData = malloc(
sizeof(*doubleData) * rows)))
488 for (row = 0; row < rows; row++)
489 doubleData[row] = getImageValue(data + column, type[column], row);
490 switch (type[column]) {
492 free(data[column].shortData);
495 free(data[column].ushortData);
498 free(data[column].longData);
501 free(data[column].ulongData);
504 free(data[column].long64Data);
507 free(data[column].ulong64Data);
510 free(data[column].floatData);
515 data[column].doubleData = doubleData;
520double estimateBackgroundLevel(
IMAGE_DATA *data, int32_t *type, int64_t rows,
long *colIndex,
long validColumns,
521 long backgroundHalfWidth) {
522 double minValue, maxValue, binWidth, backgroundLevel, value;
524 int64_t row, pixelCount = 0;
525 long i, bin, modeBin = 0;
527 int64_t backgroundPixels = 0, maxCount = 0;
531 for (i = 0; i < validColumns; i++) {
532 for (row = 0; row < rows; row++) {
533 value = getImageValue(data + colIndex[i], type[colIndex[i]], row);
534 if (value < minValue)
536 if (value > maxValue)
543 if (minValue == maxValue)
546 if (!(histogram = calloc(AUTO_BACKGROUND_BINS,
sizeof(*histogram))))
548 binWidth = (maxValue - minValue) / AUTO_BACKGROUND_BINS;
554 for (i = 0; i < validColumns; i++) {
555 for (row = 0; row < rows; row++) {
556 value = getImageValue(data + colIndex[i], type[colIndex[i]], row);
557 bin = (long)((value - minValue) / binWidth);
560 else if (bin >= AUTO_BACKGROUND_BINS)
561 bin = AUTO_BACKGROUND_BINS - 1;
566 for (bin = 0; bin < AUTO_BACKGROUND_BINS; bin++) {
567 if (histogram[bin] > maxCount) {
568 maxCount = histogram[bin];
573 for (i = 0; i < validColumns; i++) {
574 for (row = 0; row < rows; row++) {
575 value = getImageValue(data + colIndex[i], type[colIndex[i]], row);
576 bin = (long)((value - minValue) / binWidth);
579 else if (bin >= AUTO_BACKGROUND_BINS)
580 bin = AUTO_BACKGROUND_BINS - 1;
581 if (bin >= modeBin - backgroundHalfWidth && bin <= modeBin + backgroundHalfWidth) {
589 if (backgroundPixels)
590 backgroundLevel = sum / backgroundPixels;
592 backgroundLevel = minValue + (modeBin + 0.5) * binWidth;
594 return backgroundLevel;
597void subtractBackgroundLevel(
IMAGE_DATA *data, int32_t *type, int64_t rows,
long *colIndex,
long validColumns,
598 double backgroundLevel,
long clipNegative) {
603 for (i = 0; i < validColumns; i++) {
604 column = colIndex[i];
607 for (row = 0; row < rows; row++) {
608 value = data[column].doubleData[row] - backgroundLevel;
609 if (clipNegative && value < 0)
611 data[column].doubleData[row] = value;
617 int64_t x1, int64_t x2,
long y1,
long y2,
long *colIndex,
double *colIndex2) {
625 index = malloc(
sizeof(int64_t) * rows);
626 values = malloc(
sizeof(
double) * rows);
629 for (i = x1; i < x2; i++) {
630 switch (type[colIndex[y1]]) {
632 val = data[colIndex[y1]].shortData[i];
635 val = data[colIndex[y1]].ushortData[i];
638 val = data[colIndex[y1]].longData[i];
641 val = data[colIndex[y1]].ulongData[i];
644 val = data[colIndex[y1]].long64Data[i];
647 val = data[colIndex[y1]].ulong64Data[i];
650 val = data[colIndex[y1]].floatData[i];
653 val = data[colIndex[y1]].doubleData[i];
656 for (j = y1 + 1; j < y2; j++) {
657 switch (type[colIndex[j]]) {
659 if (val < data[colIndex[j]].shortData[i])
660 val = data[colIndex[j]].shortData[i];
663 if (val < data[colIndex[j]].ushortData[i])
664 val = data[colIndex[j]].ushortData[i];
667 if (val < data[colIndex[j]].longData[i])
668 val = data[colIndex[j]].longData[i];
671 if (val < data[colIndex[j]].ulongData[i])
672 val = data[colIndex[j]].ulongData[i];
675 if (val < data[colIndex[j]].long64Data[i])
676 val = data[colIndex[j]].long64Data[i];
679 if (val < data[colIndex[j]].ulong64Data[i])
680 val = data[colIndex[j]].ulong64Data[i];
683 if (val < data[colIndex[j]].floatData[i])
684 val = data[colIndex[j]].floatData[i];
687 if (val < data[colIndex[j]].doubleData[i])
688 val = data[colIndex[j]].doubleData[i];
696 }
else if ((method == 1) || (method == 4)) {
698 center = yPeakLine(data, type, colIndex, x1, x2, y1, y2);
700 center = yCenterLine(data, type, colIndex, x1, x2, y1, y2);
702 for (i = x1; i < x2; i++) {
703 switch (type[colIndex[center]]) {
705 val = data[colIndex[center]].shortData[i];
708 val = data[colIndex[center]].ushortData[i];
711 val = data[colIndex[center]].longData[i];
714 val = data[colIndex[center]].ulongData[i];
717 val = data[colIndex[center]].long64Data[i];
720 val = data[colIndex[center]].ulong64Data[i];
723 val = data[colIndex[center]].floatData[i];
726 val = data[colIndex[center]].doubleData[i];
733 }
else if ((method == 2) || (method == 3)) {
734 for (i = x1; i < x2; i++) {
736 for (j = y1; j < y2; j++) {
737 switch (type[colIndex[j]]) {
739 val += data[colIndex[j]].shortData[i];
742 val += data[colIndex[j]].ushortData[i];
745 val += data[colIndex[j]].longData[i];
748 val += data[colIndex[j]].ulongData[i];
751 val += data[colIndex[j]].long64Data[i];
754 val += data[colIndex[j]].ulong64Data[i];
757 val += data[colIndex[j]].floatData[i];
760 val += data[colIndex[j]].doubleData[i];
768 values[k] = val / (y2 - y1);
777 sprintf(value,
"(%" PRId64
",%ld) x (%" PRId64
",%ld)", x1 + 1, y1 + 1, x2, y2);
778 if (
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
"Zone", value, NULL) != 1) {
782 if (
SDDS_SetColumn(SDDS_dataset, SDDS_SET_BY_NAME, index, k,
"x", NULL) != 1) {
786 if (
SDDS_SetColumn(SDDS_dataset, SDDS_SET_BY_NAME, values, k,
"y", NULL) != 1) {
800 int64_t x1, int64_t x2,
long y1,
long y2,
long *colIndex,
double *colIndex2) {
810 index = malloc(
sizeof(
double) * (y2 - y1));
811 values = malloc(
sizeof(
double) * (y2 - y1));
814 for (i = y1; i < y2; i++) {
815 switch (type[colIndex[i]]) {
817 val = data[colIndex[i]].shortData[x1];
820 val = data[colIndex[i]].ushortData[x1];
823 val = data[colIndex[i]].longData[x1];
826 val = data[colIndex[i]].ulongData[x1];
829 val = data[colIndex[i]].long64Data[x1];
832 val = data[colIndex[i]].ulong64Data[x1];
835 val = data[colIndex[i]].floatData[x1];
838 val = data[colIndex[i]].doubleData[x1];
843 for (j = x1 + 1; j < x2; j++) {
844 switch (type[colIndex[i]]) {
846 if (val < data[colIndex[i]].shortData[j]) {
847 val = data[colIndex[i]].shortData[j];
851 if (val < data[colIndex[i]].ushortData[j]) {
852 val = data[colIndex[i]].ushortData[j];
856 if (val < data[colIndex[i]].longData[j]) {
857 val = data[colIndex[i]].longData[j];
861 if (val < data[colIndex[i]].ulongData[j]) {
862 val = data[colIndex[i]].ulongData[j];
866 if (val < data[colIndex[i]].long64Data[j]) {
867 val = data[colIndex[i]].long64Data[j];
871 if (val < data[colIndex[i]].ulong64Data[j]) {
872 val = data[colIndex[i]].ulong64Data[j];
876 if (val < data[colIndex[i]].floatData[j]) {
877 val = data[colIndex[i]].floatData[j];
881 if (val < data[colIndex[i]].doubleData[j]) {
882 val = data[colIndex[i]].doubleData[j];
889 index[k] = colIndex2[i];
893 }
else if ((method == 1) || (method == 4)) {
895 center = xPeakLine(data, type, colIndex, x1, x2, y1, y2);
897 center = xCenterLine(data, type, colIndex, x1, x2, y1, y2);
899 for (i = y1; i < y2; i++) {
900 switch (type[colIndex[i]]) {
902 val = data[colIndex[i]].shortData[center];
905 val = data[colIndex[i]].ushortData[center];
908 val = data[colIndex[i]].longData[center];
911 val = data[colIndex[i]].ulongData[center];
914 val = data[colIndex[i]].long64Data[center];
917 val = data[colIndex[i]].ulong64Data[center];
920 val = data[colIndex[i]].floatData[center];
923 val = data[colIndex[i]].doubleData[center];
928 index[k] = colIndex2[i];
932 }
else if ((method == 2) || (method == 3)) {
933 for (i = y1; i < y2; i++) {
935 switch (type[colIndex[i]]) {
937 for (j = x1; j < x2; j++)
938 val += data[colIndex[i]].shortData[j];
941 for (j = x1; j < x2; j++)
942 val += data[colIndex[i]].ushortData[j];
945 for (j = x1; j < x2; j++)
946 val += data[colIndex[i]].longData[j];
949 for (j = x1; j < x2; j++)
950 val += data[colIndex[i]].ulongData[j];
953 for (j = x1; j < x2; j++)
954 val += data[colIndex[i]].long64Data[j];
957 for (j = x1; j < x2; j++)
958 val += data[colIndex[i]].ulong64Data[j];
961 for (j = x1; j < x2; j++)
962 val += data[colIndex[i]].floatData[j];
965 for (j = x1; j < x2; j++)
966 val += data[colIndex[i]].doubleData[j];
971 index[k] = colIndex2[i];
975 values[k] = val / (x2 - x1);
984 sprintf(value,
"(%" PRId64
",%ld) x (%" PRId64
",%ld)", x1 + 1, y1 + 1, x2, y2);
985 if (
SDDS_SetParameters(SDDS_dataset, SDDS_SET_BY_NAME | SDDS_PASS_BY_VALUE,
"Zone", value, NULL) != 1) {
989 if (
SDDS_SetColumn(SDDS_dataset, SDDS_SET_BY_NAME, index, k,
"y", NULL) != 1) {
993 if (
SDDS_SetColumn(SDDS_dataset, SDDS_SET_BY_NAME, values, k,
"x", NULL) != 1) {
1006int64_t xPeakLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2) {
1008 double maxValue = 0;
1012 switch (type[colIndex[y1]]) {
1014 maxValue = data[colIndex[y1]].shortData[x1];
1017 maxValue = data[colIndex[y1]].ushortData[x1];
1020 maxValue = data[colIndex[y1]].longData[x1];
1023 maxValue = data[colIndex[y1]].ulongData[x1];
1026 maxValue = data[colIndex[y1]].long64Data[x1];
1029 maxValue = data[colIndex[y1]].ulong64Data[x1];
1032 maxValue = data[colIndex[y1]].floatData[x1];
1035 maxValue = data[colIndex[y1]].doubleData[x1];
1038 for (i = y1; i < y2; i++) {
1039 for (j = x1; j < x2; j++) {
1040 switch (type[colIndex[i]]) {
1042 if (maxValue < data[colIndex[i]].shortData[j]) {
1043 maxValue = data[colIndex[i]].shortData[j];
1048 if (maxValue < data[colIndex[i]].ushortData[j]) {
1049 maxValue = data[colIndex[i]].ushortData[j];
1054 if (maxValue < data[colIndex[i]].longData[j]) {
1055 maxValue = data[colIndex[i]].longData[j];
1060 if (maxValue < data[colIndex[i]].ulongData[j]) {
1061 maxValue = data[colIndex[i]].ulongData[j];
1066 if (maxValue < data[colIndex[i]].long64Data[j]) {
1067 maxValue = data[colIndex[i]].long64Data[j];
1072 if (maxValue < data[colIndex[i]].ulong64Data[j]) {
1073 maxValue = data[colIndex[i]].ulong64Data[j];
1078 if (maxValue < data[colIndex[i]].floatData[j]) {
1079 maxValue = data[colIndex[i]].floatData[j];
1084 if (maxValue < data[colIndex[i]].doubleData[j]) {
1085 maxValue = data[colIndex[i]].doubleData[j];
1095long yPeakLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2) {
1098 double maxValue = 0;
1102 switch (type[colIndex[y1]]) {
1104 maxValue = data[colIndex[y1]].shortData[x1];
1107 maxValue = data[colIndex[y1]].ushortData[x1];
1110 maxValue = data[colIndex[y1]].longData[x1];
1113 maxValue = data[colIndex[y1]].ulongData[x1];
1116 maxValue = data[colIndex[y1]].long64Data[x1];
1119 maxValue = data[colIndex[y1]].ulong64Data[x1];
1122 maxValue = data[colIndex[y1]].floatData[x1];
1125 maxValue = data[colIndex[y1]].doubleData[x1];
1128 for (i = y1; i < y2; i++) {
1129 for (j = x1; j < x2; j++) {
1130 switch (type[colIndex[i]]) {
1132 if (maxValue < data[colIndex[i]].shortData[j]) {
1133 maxValue = data[colIndex[i]].shortData[j];
1138 if (maxValue < data[colIndex[i]].ushortData[j]) {
1139 maxValue = data[colIndex[i]].ushortData[j];
1144 if (maxValue < data[colIndex[i]].longData[j]) {
1145 maxValue = data[colIndex[i]].longData[j];
1150 if (maxValue < data[colIndex[i]].ulongData[j]) {
1151 maxValue = data[colIndex[i]].ulongData[j];
1156 if (maxValue < data[colIndex[i]].long64Data[j]) {
1157 maxValue = data[colIndex[i]].long64Data[j];
1162 if (maxValue < data[colIndex[i]].ulong64Data[j]) {
1163 maxValue = data[colIndex[i]].ulong64Data[j];
1168 if (maxValue < data[colIndex[i]].floatData[j]) {
1169 maxValue = data[colIndex[i]].floatData[j];
1174 if (maxValue < data[colIndex[i]].doubleData[j]) {
1175 maxValue = data[colIndex[i]].doubleData[j];
1185int64_t xCenterLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2) {
1186 int64_t i, j, start = 1;
1187 double val = 0, maxValue = 0;
1190 for (i = x1; i < x2; i++) {
1192 for (j = y1; j < y2; j++) {
1193 switch (type[colIndex[j]]) {
1195 val += data[colIndex[j]].shortData[i];
1198 val += data[colIndex[j]].ushortData[i];
1201 val += data[colIndex[j]].longData[i];
1204 val += data[colIndex[j]].ulongData[i];
1207 val += data[colIndex[j]].long64Data[i];
1210 val += data[colIndex[j]].ulong64Data[i];
1213 val += data[colIndex[j]].floatData[i];
1216 val += data[colIndex[j]].doubleData[i];
1225 if (val > maxValue) {
1234long yCenterLine(
IMAGE_DATA *data, int32_t *type,
long *colIndex, int64_t x1, int64_t x2,
long y1,
long y2) {
1237 double val, maxValue = 0;
1240 for (i = y1; i < y2; i++) {
1242 for (j = x1; j < x2; j++)
1243 switch (type[colIndex[i]]) {
1245 val += data[colIndex[i]].shortData[j];
1248 val += data[colIndex[i]].ushortData[j];
1251 val += data[colIndex[i]].longData[j];
1254 val += data[colIndex[i]].ulongData[j];
1257 val += data[colIndex[i]].long64Data[j];
1260 val += data[colIndex[i]].ulong64Data[j];
1263 val += data[colIndex[i]].floatData[j];
1266 val += data[colIndex[i]].doubleData[j];
1276 if (val > maxValue) {
1286 double **colIndex2,
char *colPrefix,
long *validColumns) {
1290 int32_t orig_column_names;
1291 char **orig_column_name;
1306 *data = malloc(
sizeof(
IMAGE_DATA) * orig_column_names);
1307 *type = malloc(
sizeof(int32_t) * orig_column_names);
1316 rows = SDDS_RowCount(SDDS_orig);
1317 *colIndex = malloc(
sizeof(
long) * orig_column_names);
1318 *colIndex2 = malloc(
sizeof(
double) * orig_column_names);
1321 for (i = 0; i < orig_column_names; i++) {
1323 if ((*type)[i] == 0) {
1328 switch ((*type)[i]) {
1330 (*data)[i].shortData =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1333 (*data)[i].ushortData =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1336 (*data)[i].longData =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1339 (*data)[i].ulongData =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1342 (*data)[i].long64Data =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1345 (*data)[i].ulong64Data =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1348 (*data)[i].floatData =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1351 (*data)[i].doubleData =
SDDS_GetColumn(SDDS_orig, orig_column_name[i]);
1356 if (strncmp(colPrefix, orig_column_name[i], strlen(colPrefix)) != 0) {
1359 (*colIndex)[*validColumns] = i;
1368 if (*validColumns == 0) {
1369 fprintf(stderr,
"error: no valid columns in image file\n");
1373 for (i = 0; i < *validColumns; i++) {
1374 (*colIndex2)[i] = atof(orig_column_name[(*colIndex)[i]] + strlen(colPrefix));
1377 for (i = 0; i < *validColumns; i++) {
1378 for (j = i + 1; j < *validColumns; j++) {
1379 if ((*colIndex2)[j] < (*colIndex2)[i]) {
1380 temp = (*colIndex)[i];
1381 temp2 = (*colIndex2)[i];
1382 (*colIndex)[i] = (*colIndex)[j];
1383 (*colIndex2)[i] = (*colIndex2)[j];
1384 (*colIndex)[j] = temp;
1385 (*colIndex2)[j] = temp2;
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
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_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_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_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.
int32_t SDDS_GetNamedColumnType(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the data type of a column in the SDDS dataset by its name.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
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_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer 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)
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.