aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-11-19 13:16:56 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:06 +0100
commit37abb8746a6217e7d0420617c91f55ecfe636938 (patch)
treef0a92dcaba1187ab102142cd57bc1a3761650773 /src
parent3e7254d1787f296795860899a6a4862a73e6b28e (diff)
facetron: Fix initial refinement stuff
Diffstat (limited to 'src')
-rw-r--r--src/facetron.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/facetron.c b/src/facetron.c
index 70a3baaa..55543c8e 100644
--- a/src/facetron.c
+++ b/src/facetron.c
@@ -164,18 +164,19 @@ static double mean_partial_dev(struct image *image, struct cpeak *spots, int n,
static double iterate(struct image *image, double *i_full, const char *sym,
- struct cpeak *spots, int n)
+ struct cpeak **pspots, int *n)
{
gsl_matrix *M;
gsl_vector *v;
gsl_vector *shifts;
int h, param;
+ struct cpeak *spots = *pspots;
- M = gsl_matrix_alloc(NUM_PARAMS, NUM_PARAMS);
- v = gsl_vector_alloc(NUM_PARAMS);
+ M = gsl_matrix_calloc(NUM_PARAMS, NUM_PARAMS);
+ v = gsl_vector_calloc(NUM_PARAMS);
/* Construct the equations, one per reflection in this image */
- for ( h=0; h<n; h++ ) {
+ for ( h=0; h<*n; h++ ) {
signed int hind, kind, lind;
signed int ha, ka, la;
@@ -241,9 +242,14 @@ static double iterate(struct image *image, double *i_full, const char *sym,
}
STATUS("New OSF = %f\n", image->osf);
+ gsl_matrix_free(M);
+ gsl_vector_free(v);
+ gsl_vector_free(shifts);
+
free(spots);
- spots = find_intersections(image, image->indexed_cell, &n, 0);
- return mean_partial_dev(image, spots, n, sym, i_full, NULL);
+ spots = find_intersections(image, image->indexed_cell, n, 0);
+ *pspots = spots;
+ return mean_partial_dev(image, spots, *n, sym, i_full, NULL);
}
@@ -279,7 +285,7 @@ static void refine_image(int mytask, void *tasks)
i = 0;
do {
last_dev = dev;
- dev = iterate(image, pargs->i_full, pargs->sym, spots, n);
+ 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) );
@@ -289,6 +295,7 @@ static void refine_image(int mytask, void *tasks)
free(image->data);
if ( image->flags != NULL ) free(image->flags);
hdfile_close(hdfile);
+ free(spots);
/* Muppet proofing */
image->data = NULL;