aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentd9d216421ce1a6e692cbd06e7b1aab02d26faf84 (diff)
Fix type conversions to avoid trouble with overflows etc.
Diffstat (limited to 'src')
-rw-r--r--src/detector.c20
-rw-r--r--src/diffraction-gpu.c6
-rw-r--r--src/pattern_sim.c3
3 files changed, 24 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");
diff --git a/src/diffraction-gpu.c b/src/diffraction-gpu.c
index a2d1c47a..851ed70c 100644
--- a/src/diffraction-gpu.c
+++ b/src/diffraction-gpu.c
@@ -239,6 +239,12 @@ void get_diffraction_gpu(struct gpu_context *gctx, struct image *image,
float val, tt;
val = diff_ptr[x + image->width*y];
+ if ( isinf(val) ) {
+ ERROR("Extracting infinity at %i,%i\n", x, y);
+ }
+ if ( val < 0.0 ) {
+ ERROR("Extracting negative at %i,%i\n", x, y);
+ }
tt = tt_ptr[x + image->width*y];
image->data[x + image->width*y] = val;
diff --git a/src/pattern_sim.c b/src/pattern_sim.c
index 91100426..59e5adb5 100644
--- a/src/pattern_sim.c
+++ b/src/pattern_sim.c
@@ -307,6 +307,9 @@ int main(int argc, char *argv[])
for ( x=0; x<image.width; x++ ) {
for ( y=0; y<image.height; y++ ) {
powder[x+w*y] += image.data[x+w*y];
+ if ( image.data[x+w*y] < 0 ) {
+ STATUS("Negative! %f %i %i\n", image.data[x+w*y], x, y);
+ }
}
}