From ece683eb7b2a01b6cb82f849fe2759b5dcc626e2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 16 Feb 2012 15:41:27 +0100 Subject: process_hkl: Histogram improvements from Lorenzo --- src/process_hkl.c | 84 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/process_hkl.c b/src/process_hkl.c index f94ad4b8..ac2e567e 100644 --- a/src/process_hkl.c +++ b/src/process_hkl.c @@ -32,8 +32,7 @@ #include "image.h" -/* Number of divisions for intensity histograms */ -#define NBINS (50) + static void show_help(const char *s) @@ -63,6 +62,8 @@ static void show_help(const char *s) " the default.\n" " -g, --histogram= Calculate the histogram of measurements for this\n" " reflection.\n" +" -z, --hist-parameters Set the range for the histogram and the number of\n" +" = bins. \n" "\n" " --scale Scale each pattern for best fit with the current\n" " model.\n" @@ -75,13 +76,13 @@ static void show_help(const char *s) } -static void plot_histogram(double *vals, int n) +static void plot_histogram(double *vals, int n, float hist_min, float hist_max, int nbins) { int i; double max = -INFINITY; double min = +INFINITY; double step; - int histo[NBINS]; + int histo[nbins]; FILE *fh; fh = fopen("histogram.dat", "w"); @@ -90,26 +91,33 @@ static void plot_histogram(double *vals, int n) return; } - for ( i=0; i max ) max = vals[i]; - if ( vals[i] < min ) min = vals[i]; + if ( hist_min == hist_max ) { + for ( i=0; i max ) max = vals[i]; + if ( vals[i] < min ) min = vals[i]; + } + } else { + min = hist_min; + max = hist_max; } - STATUS("%f %f\n", min, max); + STATUS("min max nbins: \n %f %f %i\n", min, max, nbins); min--; max++; - for ( i=0; i min) && (vals[i] < max) ) { + bin = (vals[i]-min)/step; + histo[bin]++; + } } - for ( i=0; i= space_for_hist) ) { - ERROR("Histogram array was too small!\n"); - } - - if ( hist_vals != NULL ) { - STATUS("%i %i %i was seen %i times.\n", hist_h, hist_k, hist_l, - hist_i); - plot_histogram(hist_vals, hist_i); - } STATUS("Extra pass to calculate ESDs...\n"); rewind(fh); merge_all(fh, model, config_maxonly, config_scale, 0, config_startafter, config_stopafter, sym, n_total_patterns, - NULL, 0, 0, 0, NULL, 2); + hist_vals, hist_h, hist_k, hist_l, &hist_i, 2); if ( ferror(fh) ) { ERROR("Stream read error.\n"); return 1; } + if ( space_for_hist && (hist_i >= space_for_hist) ) { + ERROR("Histogram array was too small!\n"); + } + + if ( hist_vals != NULL ) { + STATUS("%i %i %i was seen %i times.\n", hist_h, hist_k, hist_l, + hist_i); + plot_histogram(hist_vals, hist_i, hist_min, hist_max, + hist_nbins); + } + write_reflist(output, model, cell); fclose(fh); + free(sym); reflist_free(model); free(output); -- cgit v1.2.3