aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2013-07-24 16:47:21 +0200
committerThomas White <taw@physics.org>2013-07-24 16:47:21 +0200
commit0bb8df9b6a54db5da84d9fc9c26efcf5974fc89b (patch)
tree937cfe2c1e95324e52e474edbc219b0330a4cc78
parent863b0ddea31ff8dc0d789f2806c6a311d826a152 (diff)
Iteration over reflection list should include other reflections with same asymmetric indices
This fixes a >2 year old bug in the reflection list, and a bug in tests/list_check.c which allowed it to go undetected for so long. The main situation where it would have caused problems is when asymmetric_indices() was called on a reflection list containing symmetrically equivalent reflections. The only core CrystFEL program which does this is partialator. compare_hkl uses asymmetric_indices(), but the reflections are already guaranteed to be asymmetric by that point (because check_list_symmetry() has been called).
-rw-r--r--libcrystfel/src/reflist.c26
-rw-r--r--tests/list_check.c11
2 files changed, 29 insertions, 8 deletions
diff --git a/libcrystfel/src/reflist.c b/libcrystfel/src/reflist.c
index b3b9f85b..a450d8fa 100644
--- a/libcrystfel/src/reflist.c
+++ b/libcrystfel/src/reflist.c
@@ -992,12 +992,20 @@ Reflection *first_refl(RefList *list, RefListIterator **piter)
**/
Reflection *next_refl(Reflection *refl, RefListIterator *iter)
{
- int returned = 1;
+ /* Are there more reflections with the same indices? */
+ if ( refl->next != NULL ) {
+ return refl->next;
+ } else {
- do {
+ /* No, so rewind back to the head of the list */
+ while ( refl->prev != NULL ) {
+ refl = refl->prev;
+ }
+
+ }
- if ( returned ) refl = refl->child[1];
- returned = 0;
+ refl = refl->child[1];
+ do {
if ( refl != NULL ) {
@@ -1041,13 +1049,21 @@ static int recursive_depth(Reflection *refl)
static int recursive_count(Reflection *refl)
{
int count_left, count_right;
+ Reflection *probe;
+ int n_this = 1;
if ( refl == NULL ) return 0;
+ probe = refl;
+ while ( probe->next != NULL ) {
+ probe = probe->next;
+ n_this++;
+ }
+
count_left = recursive_count(refl->child[0]);
count_right = recursive_count(refl->child[1]);
- return 1 + count_left + count_right;
+ return n_this + count_left + count_right;
}
diff --git a/tests/list_check.c b/tests/list_check.c
index b1b8814d..9656dd1a 100644
--- a/tests/list_check.c
+++ b/tests/list_check.c
@@ -3,7 +3,11 @@
*
* Unit test for the reflection list module
*
- * Copyright © 2012 Thomas White <taw@physics.org>
+ * Copyright © 2012-2013 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
+ *
+ * Authors:
+ * 2011-2013 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*
@@ -99,8 +103,8 @@ static int test_lists(int num_items)
}
- printf("num_reflections is %i, tree depth is %i\n",
- num_reflections(list), tree_depth(list));
+ printf("Created %i items, num_reflections is %i, tree depth is %i\n",
+ num_items, num_reflections(list), tree_depth(list));
/* Iterate over the list and check we find everything */
int count = 0;
@@ -118,6 +122,7 @@ static int test_lists(int num_items)
&& (check[i].l == l)
&& (check[i].found == 0) ) {
check[i].found = 1;
+ break;
}
}