From 82ac8b4ec60e47e09f33cf925d452810d590b0a5 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 7 Mar 2013 10:38:18 +0100 Subject: check_hkl: Add --nshells --- src/check_hkl.c | 123 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 31 deletions(-) (limited to 'src/check_hkl.c') diff --git a/src/check_hkl.c b/src/check_hkl.c index f82855ab..5aa9874d 100644 --- a/src/check_hkl.c +++ b/src/check_hkl.c @@ -3,11 +3,11 @@ * * Characterise reflection lists * - * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2012-2013 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * * Authors: - * 2010-2012 Thomas White + * 2010-2013 Thomas White * * This file is part of CrystFEL. * @@ -46,10 +46,6 @@ #include "cell-utils.h" -/* Number of bins for plot of resolution shells */ -#define NBINS (10) - - static void show_help(const char *s) { printf("Syntax: %s [options] \n\n", s); @@ -62,23 +58,24 @@ static void show_help(const char *s) " --rmin= Fix lower resolution limit for resolution shells. (m^-1).\n" " --rmax= Fix upper resolution limit for resolution shells. (m^-1).\n" " --sigma-cutoff= Discard reflections with I/sigma(I) < n.\n" +" --nshells= Use resolution shells.\n" "\n"); } static void plot_shells(RefList *list, UnitCell *cell, const SymOpList *sym, - double rmin_fix, double rmax_fix) + double rmin_fix, double rmax_fix, int nshells) { - int possible[NBINS]; - unsigned int measurements[NBINS]; - unsigned int measured[NBINS]; - unsigned int snr_measured[NBINS]; + int *possible; + unsigned int *measurements; + unsigned int *measured; + unsigned int *snr_measured; double total_vol, vol_per_shell; - double rmins[NBINS]; - double rmaxs[NBINS]; - double snr[NBINS]; - double mean[NBINS]; - double var[NBINS]; + double *rmins; + double *rmaxs; + double *snr; + double *mean; + double *var; double rmin, rmax; signed int h, k, l; int i; @@ -96,13 +93,47 @@ static void plot_shells(RefList *list, UnitCell *cell, const SymOpList *sym, double bsx, bsy, bsz; double csx, csy, csz; + possible = malloc(nshells*sizeof(int)); + measurements = malloc(nshells*sizeof(unsigned int)); + measured = malloc(nshells*sizeof(unsigned int)); + snr_measured = malloc(nshells*sizeof(unsigned int)); + if ( (possible == NULL) || (measurements == NULL) + || (measured == NULL) || (snr_measured == NULL) ) { + ERROR("Couldn't allocate memory.\n"); + free(possible); + free(measurements); + free(measured); + free(snr_measured); + return; + } + + rmins = malloc(nshells*sizeof(double)); + rmaxs = malloc(nshells*sizeof(double)); + snr = malloc(nshells*sizeof(double)); + mean = malloc(nshells*sizeof(double)); + var = malloc(nshells*sizeof(double)); + if ( (rmins == NULL) || (rmaxs == NULL) || (snr == NULL) + || (mean == NULL) || (var == NULL) ) { + ERROR("Couldn't allocate memory.\n"); + free(possible); + free(measurements); + free(measured); + free(snr_measured); + free(rmins); + free(rmaxs); + free(snr); + free(mean); + free(var); + return; + } + fh = fopen("shells.dat", "w"); if ( fh == NULL ) { ERROR("Couldn't open 'shells.dat'\n"); return; } - for ( i=0; i 0.0 ) rmax = rmax_fix; total_vol = pow(rmax, 3.0) - pow(rmin, 3.0); - vol_per_shell = total_vol / NBINS; + vol_per_shell = total_vol / nshells; rmins[0] = rmin; - for ( i=1; irmins[i]) && (d<=rmaxs[i]) ) { bin = i; break; @@ -200,13 +234,17 @@ static void plot_shells(RefList *list, UnitCell *cell, const SymOpList *sym, int j; get_indices(refl, &h, &k, &l); + if ( forbidden_reflection(cell, h, k, l) ) continue; + if ( h % 2 ) continue; + if ( k % 2 ) continue; + if ( l % 2 ) continue; d = resolution(cell, h, k, l) * 2.0; val = get_intensity(refl); esd = get_esd_intensity(refl); bin = -1; - for ( j=0; jrmins[j]) && (d<=rmaxs[j]) ) { bin = j; break; @@ -221,7 +259,7 @@ static void plot_shells(RefList *list, UnitCell *cell, const SymOpList *sym, } - for ( i=0; irmins[j]) && (d<=rmaxs[j]) ) { bin = j; break; @@ -287,7 +329,7 @@ static void plot_shells(RefList *list, UnitCell *cell, const SymOpList *sym, fprintf(fh, "1/d centre # refs Possible Compl " "Meas Red SNR Std dev Mean d(A)\n"); - for ( i=0; i