aboutsummaryrefslogtreecommitdiff
path: root/src/detector.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-02-26 23:41:40 +0100
committerThomas White <taw@physics.org>2010-02-27 10:51:20 +0100
commit6b345bb3ab13139cff8ca5b7fdc551110eaaddea (patch)
treefb582246cb5086964b14a11c32411373b5b80790 /src/detector.c
parentd9d216421ce1a6e692cbd06e7b1aab02d26faf84 (diff)
Fix type conversions to avoid trouble with overflows etc.
Diffstat (limited to 'src/detector.c')
-rw-r--r--src/detector.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/detector.c b/src/detector.c
index 2a4c6d10..f66ad525 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -74,14 +74,17 @@ void record_image(struct image *image, int do_poisson)
for ( x=0; x<image->width; x++ ) {
for ( y=0; y<image->height; y++ ) {
- int counts;
+ double counts;
double cf;
double intensity, sa;
double pix_area, Lsq;
double dsq, proj_area;
struct panel *p;
- intensity = image->data[x + image->width*y];
+ intensity = (double)image->data[x + image->width*y];
+ if ( isinf(intensity) ) {
+ ERROR("Infinity at %i,%i\n", x, y);
+ }
p = find_panel(&image->det, x, y);
@@ -102,13 +105,20 @@ void record_image(struct image *image, int do_poisson)
if ( do_poisson ) {
counts = poisson_noise(intensity * ph_per_e * sa * DQE);
} else {
- double rounded;
cf = intensity * ph_per_e * sa * DQE;
- rounded = rint(cf);
- counts = (int)rounded;
+ counts = rint(cf);
+ if ( counts < 0.0 ) {
+ ERROR("Negative at %i,%i %f\n", x, y, counts);
+ }
}
image->data[x + image->width*y] = counts * DETECTOR_GAIN;
+ if ( isinf(image->data[x+image->width*y]) ) {
+ ERROR("Processed infinity at %i,%i\n", x, y);
+ }
+ if ( image->data[x+image->width*y] < 0.0 ) {
+ ERROR("Processed negative at %i,%i %f\n", x, y, counts);
+ }
}
progress_bar(x, image->width-1, "Post-processing");