From 6d2b7ca98aa869080a94bed36be0c066521d6ba4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 8 Apr 2009 19:54:20 +0100 Subject: reflections.c: remove check for duplicates, whitespace --- src/reflections.c | 89 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/src/reflections.c b/src/reflections.c index a589231..8235391 100644 --- a/src/reflections.c +++ b/src/reflections.c @@ -32,9 +32,9 @@ static void reflectionlist_init(ReflectionList *reflectionlist) { ReflectionList *reflectionlist_new() { ReflectionList *reflectionlist = malloc(sizeof(ReflectionList)); - + reflectionlist_init(reflectionlist); - + return reflectionlist; } @@ -44,10 +44,10 @@ void reflectionlist_clear_markers(ReflectionList *reflectionlist) { Reflection *reflection = reflectionlist->reflections; Reflection *prev = NULL; int del = 0; - + while ( reflection ) { Reflection *next = reflection->next; - + if ( (reflection->type == REFLECTION_MARKER) || (reflection->type == REFLECTION_GENERATED) || (reflection->type == REFLECTION_VECTOR_MARKER_1) || (reflection->type == REFLECTION_VECTOR_MARKER_2) || (reflection->type == REFLECTION_VECTOR_MARKER_3) ) { @@ -61,14 +61,14 @@ void reflectionlist_clear_markers(ReflectionList *reflectionlist) { } else { prev = reflection; } - + reflection = next; - + }; - + reflectionlist->n_reflections -= del; reflectionlist->last_reflection = prev; - + } void reflectionlist_clear(ReflectionList *reflectionlist) { @@ -78,7 +78,7 @@ void reflectionlist_clear(ReflectionList *reflectionlist) { free(reflection); reflection = next; }; - + reflectionlist_init(reflectionlist); } @@ -92,18 +92,20 @@ Reflection *reflection_add(ReflectionList *reflectionlist, double x, double y, d Reflection *new_reflection; Reflection *nearest; - + if ( reflectionlist->list_capped ) return NULL; - + if ( reflectionlist->n_reflections > 1e7 ) { fprintf(stderr, "More than 10 million reflections on list. I think this is silly.\n"); fprintf(stderr, "No further reflections will be stored. Go and fix the peak detection.\n"); reflectionlist->list_capped = 1; } - - nearest = reflectionlist_find_nearest_type(reflectionlist, x, y, z, type); - if ( nearest && distance3d(x, y, z, nearest->x, nearest->y, nearest->z) < 0.1e9 ) return NULL; - + +// nearest = reflectionlist_find_nearest_type(reflectionlist, x, y, z, type); +// if ( nearest && distance3d(x, y, z, nearest->x, nearest->y, nearest->z) < 0.1e9 ) { +// printf("Too close\n"); +// return NULL; +//} new_reflection = malloc(sizeof(Reflection)); new_reflection->next = NULL; new_reflection->x = x; @@ -112,7 +114,7 @@ Reflection *reflection_add(ReflectionList *reflectionlist, double x, double y, d new_reflection->intensity = intensity; new_reflection->type = type; new_reflection->found = 0; - + if ( reflectionlist->last_reflection ) { reflectionlist->last_reflection->next = new_reflection; reflectionlist->last_reflection = new_reflection; @@ -121,16 +123,16 @@ Reflection *reflection_add(ReflectionList *reflectionlist, double x, double y, d reflectionlist->last_reflection = new_reflection; } reflectionlist->n_reflections++; - + return new_reflection; - + } double reflectionlist_largest_g(ReflectionList *reflectionlist) { double max = 0.0; Reflection *reflection; - + reflection = reflectionlist->reflections; while ( reflection ) { if ( reflection->type == REFLECTION_NORMAL ) { @@ -140,7 +142,7 @@ double reflectionlist_largest_g(ReflectionList *reflectionlist) { } reflection = reflection->next; }; - + return max; } @@ -150,7 +152,7 @@ Reflection *reflectionlist_find_nearest(ReflectionList *reflectionlist, double x double max = +INFINITY; Reflection *reflection; Reflection *best = NULL; - + reflection = reflectionlist->reflections; while ( reflection ) { if ( reflection->type == REFLECTION_NORMAL ) { @@ -163,7 +165,7 @@ Reflection *reflectionlist_find_nearest(ReflectionList *reflectionlist, double x } reflection = reflection->next; }; - + return best; } @@ -174,7 +176,7 @@ Reflection *reflectionlist_find_nearest_longer_unknown(ReflectionList *reflectio double max = +INFINITY; Reflection *reflection; Reflection *best = NULL; - + reflection = reflectionlist->reflections; while ( reflection ) { if ( (reflection->type == REFLECTION_NORMAL) && (!reflection->found) ) { @@ -187,7 +189,7 @@ Reflection *reflectionlist_find_nearest_longer_unknown(ReflectionList *reflectio } reflection = reflection->next; }; - + return best; } @@ -198,7 +200,7 @@ Reflection *reflectionlist_find_nearest_type(ReflectionList *reflectionlist, dou double max = +INFINITY; Reflection *reflection; Reflection *best = NULL; - + reflection = reflectionlist->reflections; while ( reflection ) { if ( reflection->type == type ) { @@ -211,7 +213,7 @@ Reflection *reflectionlist_find_nearest_type(ReflectionList *reflectionlist, dou } reflection = reflection->next; }; - + return best; } @@ -223,9 +225,9 @@ ReflectionList *reflection_list_from_cell(Basis *basis) { double max_res; signed int h, k, l; int max_order_a, max_order_b, max_order_c; - + ordered = reflectionlist_new(); - + max_res = 21e9; do { max_order_a = max_res/modulus(basis->a.x, basis->a.y, basis->a.z); @@ -234,20 +236,20 @@ ReflectionList *reflection_list_from_cell(Basis *basis) { max_res -= 1e9; } while ( (max_order_a * max_order_b * max_order_c * 8) > 1e4 ); printf("Selected maximum resolution %8.5f nm^-1\n", max_res/1e9); - + for ( h=-max_order_a; h<=max_order_a; h++ ) { for ( k=-max_order_b; k<=max_order_b; k++ ) { for ( l=-max_order_c; l<=max_order_c; l++ ) { double x, y, z; - + /* Test mode */ //if ( h != 0 ) continue; - + x = h*basis->a.x + k*basis->b.x + l*basis->c.x; y = h*basis->a.y + k*basis->b.y + l*basis->c.y; z = h*basis->a.z + k*basis->b.z + l*basis->c.z; - + if ( ( x*x + y*y + z*z ) <= max_res*max_res ) { Reflection *ref; ref = reflection_add(ordered, x, y, z, 1.0, REFLECTION_GENERATED); @@ -259,11 +261,11 @@ ReflectionList *reflection_list_from_cell(Basis *basis) { reflection_add(ordered, x, y, z, 1.0, REFLECTION_GENERATED); } } - + } } } - + return ordered; } @@ -271,19 +273,19 @@ ReflectionList *reflection_list_from_cell(Basis *basis) { void reflection_list_from_new_cell(ReflectionList *ordered, Basis *basis) { Reflection *ref; - + ref = ordered->reflections; - + while ( ref ) { - + signed int h, k, l; - + h = ref->h; k = ref->k; l = ref->l; - + ref->x = h*basis->a.x + k*basis->b.x + l*basis->c.x; ref->y = h*basis->a.y + k*basis->b.y + l*basis->c.y; ref->z = h*basis->a.z + k*basis->b.z + l*basis->c.z; - + ref = ref->next; } @@ -296,7 +298,7 @@ int reflection_is_easy(Reflection *reflection) { if ( reflection->h ) return !(reflection->k || reflection->l); if ( reflection->k ) return !(reflection->h || reflection->l); if ( reflection->l ) return !(reflection->h || reflection->k); - + return 0; /* 000 */ } @@ -304,7 +306,7 @@ int reflection_is_easy(Reflection *reflection) { Reflection *reflectionlist_find(ReflectionList *reflectionlist, signed int h, signed int k, signed int l) { Reflection *reflection; - + reflection = reflectionlist->reflections; while ( reflection ) { if ( (reflection->h==h) && (reflection->k==k) && (reflection->l==l) ) { @@ -312,8 +314,7 @@ Reflection *reflectionlist_find(ReflectionList *reflectionlist, signed int h, si } reflection = reflection->next; }; - + return NULL; } - -- cgit v1.2.3