diff options
Diffstat (limited to 'src/dirax.c')
-rw-r--r-- | src/dirax.c | 67 |
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); |