From fb6ea76376f45bb8cb5183652586d0c0fa134e17 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 14 Feb 2011 17:31:32 -0800 Subject: calibrate_detector: Add --split option --- src/calibrate_detector.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'src/calibrate_detector.c') diff --git a/src/calibrate_detector.c b/src/calibrate_detector.c index 25e9850c..78872bad 100644 --- a/src/calibrate_detector.c +++ b/src/calibrate_detector.c @@ -30,17 +30,63 @@ static void show_help(const char *s) { - printf("Syntax: %s [options] \n\n", s); + printf("Syntax: %s [options] -i \n\n", s); printf( -"Plot a powder pattern as a 1D graph using the detector geometry.\n" +"Optimise detector geometry.\n" "\n" " -h, --help Display this help message.\n" " -g. --geometry= Get detector geometry from file.\n" " -i, --input= Input filename.\n" +" --split Break up input file into panels according to\n" +" the detector geometry description.\n" "\n"); } +static void split_image(struct image *image) +{ + int i; + const struct detector *det = image->det; + + for ( i=0; in_panels; i++ ) { + + int x, y; + struct panel *p; + float *data; + int width, height; + char filename[1024]; + + p = &det->panels[i]; + + width = 1 + p->max_x - p->min_x; + height = 1 + p->max_y - p->min_y; + data = malloc(width*height*sizeof(float)); + snprintf(filename, 1023, "%s-%i.h5", image->filename, i); + + STATUS("Panel %i, %i by %i pixels -> %s\n", i, width, height, + filename); + + for ( x=0; xmin_x; + im_y = y+p->min_y; + + data[x+width*y] = image->data[im_x+image->width*im_y]; + + } + } + + hdf5_write(filename, data, width, height, H5T_NATIVE_FLOAT); + + free(data); + + } +} + + int main(int argc, char *argv[]) { int c; @@ -49,12 +95,14 @@ int main(int argc, char *argv[]) struct hdfile *hdfile; char *filename = NULL; char *geometry = NULL; + int split = 0; /* Long options */ const struct option longopts[] = { {"help", 0, NULL, 'h'}, {"input", 1, NULL, 'i'}, {"geometry", 1, NULL, 'g'}, + {"split", 0, &split, 1}, {0, 0, NULL, 0} }; @@ -87,6 +135,7 @@ int main(int argc, char *argv[]) ERROR("You must specify the input filename with -i\n"); return 1; } + image.filename = filename; if ( geometry == NULL ) { ERROR("You need to specify a geometry file with --geometry\n"); @@ -104,6 +153,11 @@ int main(int argc, char *argv[]) hdfile_set_image(hdfile, "/data/data"); hdf5_read(hdfile, &image, 1, 2000.0); + if ( split ) { + split_image(&image); + exit(0); + } + for ( x=0; x