aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-08-20 18:33:05 +0200
committerThomas White <taw@physics.org>2018-08-30 17:18:54 +0200
commit4919e35f8bccabc11e16c190fffac600194a444b (patch)
treefcf83554e6dbb894073e8f2240f06580455a3646 /src
parentd562542027bced0be31e1aa4e04e6dcb132f1b3e (diff)
Save contribution information during merge
Diffstat (limited to 'src')
-rw-r--r--src/merge.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/merge.c b/src/merge.c
index 14460953..9e577224 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -88,6 +88,17 @@ static void *create_merge_job(void *vqargs)
}
+static int alloc_contribs(struct reflection_contributions *c)
+{
+ c->contribs = realloc(c->contribs, c->max_contrib*sizeof(Reflection *));
+ c->contrib_crystals = realloc(c->contrib_crystals,
+ c->max_contrib*sizeof(Crystal *));
+ if ( c->contribs == NULL ) return 1;
+ if ( c->contrib_crystals == NULL ) return 1;
+ return 0;
+}
+
+
/* Find reflection hkl in 'list', creating it if it's not there, under
* protection of 'lock' and returning a locked reflection */
static Reflection *get_locked_reflection(RefList *list, pthread_rwlock_t *lock,
@@ -108,12 +119,31 @@ static Reflection *get_locked_reflection(RefList *list, pthread_rwlock_t *lock,
* So, we must check again */
f = find_refl(list, h, k, l);
if ( f == NULL ) {
+
+ struct reflection_contributions *c;
+
f = add_refl(list, h, k, l);
lock_reflection(f);
pthread_rwlock_unlock(lock);
set_intensity(f, 0.0);
set_temp1(f, 0.0);
set_temp2(f, 0.0);
+
+ c = malloc(sizeof(struct reflection_contributions));
+ if ( c != NULL ) {
+ c->n_contrib = 0;
+ c->max_contrib = 32;
+ c->contribs = NULL;
+ c->contrib_crystals = NULL;
+ if ( alloc_contribs(c) ) {
+ set_contributions(f, NULL);
+ } else {
+ set_contributions(f, c);
+ }
+ } else {
+ set_contributions(f, NULL);
+ }
+
} else {
/* Someone else created it */
lock_reflection(f);
@@ -158,6 +188,7 @@ static void run_merge_job(void *vwargs, int cookie)
signed int h, k, l;
double mean, sumweight, M2, temp, delta, R;
double corr, res, w;
+ struct reflection_contributions *c;
if ( get_partiality(refl) < MIN_PART_MERGE ) continue;
@@ -209,6 +240,18 @@ static void run_merge_job(void *vwargs, int cookie)
set_temp2(f, M2 + sumweight * delta * R);
set_temp1(f, temp);
set_redundancy(f, get_redundancy(f)+1);
+
+ /* Record this contribution */
+ c = get_contributions(f);
+ if ( c != NULL ) {
+ c->contribs[c->n_contrib] = refl;
+ c->contrib_crystals[c->n_contrib++] = cr;
+ if ( c->n_contrib == c->max_contrib ) {
+ c->max_contrib += 64;
+ alloc_contribs(c);
+ }
+ } /* else, too bad! */
+
unlock_reflection(f);
wargs->n_reflections++;