From 6d379bfdc3b6c48e3f7bc6a6d39ef7c55c1f6b74 Mon Sep 17 00:00:00 2001 From: taw27 Date: Wed, 31 Oct 2007 17:38:50 +0000 Subject: Arithmetic fixes git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@188 bf6ca9ba-c028-0410-8290-897cf20841d1 --- src/refine.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/refine.c b/src/refine.c index 01c4bcb..14eba42 100644 --- a/src/refine.c +++ b/src/refine.c @@ -146,21 +146,21 @@ static void refine_fit_image(Basis *cell, ImageRecord *image, ReflectionList *ce } if ( shared & INDEX_A ) { - double w = h / (h+k+l); + double w = abs(h) / (abs(h)+abs(k)+abs(l)); cd.a.x += w*dx / h; cd.a.y += w*dy / h; cd.a.z += w*dz / h; n_a++; } if ( shared & INDEX_B ) { - double w = k / (h+k+l); + double w = abs(k) / (abs(h)+abs(k)+abs(l)); cd.b.x += w*dx / k; cd.b.y += w*dy / k; cd.b.z += w*dz / k; n_b++; } if ( shared & INDEX_C ) { - double w = l / (h+k+l); + double w = abs(l) / (abs(h)+abs(k)+abs(l)); cd.c.x += w*dx / l; cd.c.y += w*dy / l; cd.c.z += w*dz / l; @@ -171,9 +171,15 @@ static void refine_fit_image(Basis *cell, ImageRecord *image, ReflectionList *ce image_feature_list_free(rflist); - cd.a.x /= n_a; cd.a.y /= n_a; cd.a.z /= n_a; - cd.b.x /= n_b; cd.b.y /= n_b; cd.b.z /= n_b; - cd.c.x /= n_c; cd.c.y /= n_c; cd.c.z /= n_c; + if ( n_a ) { + cd.a.x /= n_a; cd.a.y /= n_a; cd.a.z /= n_a; + } + if ( n_b ) { + cd.b.x /= n_b; cd.b.y /= n_b; cd.b.z /= n_b; + } + if ( n_c ) { + cd.c.x /= n_c; cd.c.y /= n_c; cd.c.z /= n_c; + } printf("Total distortion(a) = %+8e %+8e %+8e\n", cd.a.x, cd.a.y, cd.a.z); printf("Total distortion(b) = %+8e %+8e %+8e\n", cd.b.x, cd.b.y, cd.b.z); -- cgit v1.2.3