aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw27@cam.ac.uk>2009-03-19 12:07:53 +0000
committerThomas White <taw27@cam.ac.uk>2009-03-19 12:07:53 +0000
commitdc76f055cefcfc70f97f4c5520e65eec7e662fcf (patch)
tree7577d9b8fa27326e8db20818abd8c9944c2da6cc
parent899919470fe997388b195b005b31dd29d7d2c06d (diff)
Send a random selection of reflections to DirAx if more than 1,000 are present
-rw-r--r--src/dirax.c67
1 files changed, 62 insertions, 5 deletions
diff --git a/src/dirax.c b/src/dirax.c
index 2924380..7c79412 100644
--- a/src/dirax.c
+++ b/src/dirax.c
@@ -365,12 +365,59 @@ void dirax_rerun(ControlContext *ctx)
ctx->dirax_step = 7;
}
+
+static void dirax_send_random_selection(ReflectionList *r, int n, FILE *fh)
+{
+ char *used;
+ int i;
+
+ used = malloc(n*sizeof(char));
+
+ for ( i=0; i<n; i++ ) {
+ used[i] = '-';
+ }
+
+ for ( i=0; i<1000; i++ ) {
+
+ Reflection *ref;
+ int done;
+ int j;
+ long long int ra;
+
+ done = 0;
+ while ( !done ) {
+ ra = ((long long int)random() * (long long int)n);
+ ra /= RAND_MAX;
+ if ( used[ra] == 'U' ) {
+ printf("%lli - already used\n", ra);
+ } else {
+ done = 1;
+ }
+ }
+ printf("Selected reflection %lli\n", ra);
+
+ /* Dig out the correct reflection. A little faffy
+ * because of the linked list */
+ ref = r->reflections;
+ for ( j=0; j<ra; j++ ) {
+ ref = ref->next;
+ }
+ fprintf(fh, "%10f %10f %10f %8f\n",
+ ref->x/1e10, ref->y/1e10,
+ ref->z/1e10, ref->intensity);
+ used[ra] = 'U';
+
+ }
+}
+
+
void dirax_invoke(ControlContext *ctx)
{
FILE *fh;
Reflection *ref;
unsigned int opts;
int saved_stderr;
+ int n;
if ( ctx->dirax ) {
dirax_rerun(ctx);
@@ -386,11 +433,21 @@ void dirax_invoke(ControlContext *ctx)
}
fprintf(fh, "%f\n", 0.5); /* Lie about the wavelength. DirAx can't
* handle the truth. */
- ref = ctx->reflectionlist->reflections;
- while ( ref ) {
- fprintf(fh, "%10f %10f %10f %8f\n", ref->x/1e10, ref->y/1e10,
- ref->z/1e10, ref->intensity);
- ref = ref->next;
+
+ n = ctx->reflectionlist->n_reflections;
+ printf("DX: There are %i reflections - ", n);
+ if ( n > 1000 ) {
+ printf("sending a random selection to DirAx\n");
+ dirax_send_random_selection(ctx->reflectionlist, n, fh);
+ } else {
+ printf("sending them all to DirAx\n");
+ ref = ctx->reflectionlist->reflections;
+ while ( ref ) {
+ fprintf(fh, "%10f %10f %10f %8f\n",
+ ref->x/1e10, ref->y/1e10,
+ ref->z/1e10, ref->intensity);
+ ref = ref->next;
+ }
}
fclose(fh);