diff options
author | Thomas White <taw@physics.org> | 2010-11-18 16:59:52 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:06 +0100 |
commit | 1db9f3c620f1849a24ad5e6c78fede5b57550d91 (patch) | |
tree | 281ca8c82bd555d5e759425ab18eee6eb9fabc4c | |
parent | 387de365a9ce243f5e1afd0b6ed529ddce41e16b (diff) |
facetron: Stop iterating when converged
-rw-r--r-- | src/facetron.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/facetron.c b/src/facetron.c index d04facf4..70a3baaa 100644 --- a/src/facetron.c +++ b/src/facetron.c @@ -37,8 +37,8 @@ #include "beam-parameters.h" -/* Number of iterations of NLSq to do for each image per macrocycle. */ -#define NUM_CYCLES (1) +/* Maximum number of iterations of NLSq to do for each image per macrocycle. */ +#define MAX_CYCLES (100) /* Refineable parameters */ enum { @@ -256,7 +256,7 @@ static void refine_image(int mytask, void *tasks) struct hdfile *hdfile; struct cpeak *spots; int n, i; - double dev; + double dev, last_dev; hdfile = hdfile_open(image->filename); if ( hdfile == NULL ) { @@ -275,10 +275,14 @@ static void refine_image(int mytask, void *tasks) } spots = find_intersections(image, image->indexed_cell, &n, 0); - for ( i=0; i<NUM_CYCLES; i++ ) { + dev = +INFINITY; + i = 0; + do { + last_dev = dev; dev = iterate(image, pargs->i_full, pargs->sym, spots, n); STATUS("Iteration %2i: mean dev = %5.2f\n", i, dev); - } + i++; + } while ( (fabs(last_dev - dev) > 1.0) || (i == MAX_CYCLES) ); mean_partial_dev(image, spots, n, pargs->sym, pargs->i_full, pargs->graph); |