From 4ef558e6c6b1bf7be1a28b945834f8c5fcb65dd0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 1 Apr 2010 11:56:11 +0200 Subject: indexamajig: Move pattern processing to a separate function --- src/indexamajig.c | 237 +++++++++++++++++++++++++++++------------------------- 1 file changed, 128 insertions(+), 109 deletions(-) diff --git a/src/indexamajig.c b/src/indexamajig.c index 4d3c213c..c32657d9 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -170,6 +170,127 @@ static void simulate_and_write(struct image *simage, struct gpu_context **gctx, } +static int process_pattern(const char *filename, UnitCell *cell, + int config_cmfilter, int config_noisefilter, + int config_writedrx, int config_dumpfound, + int config_verbose, int config_alternate, + int config_nearbragg, int config_gpu, + int config_simulate, int config_nomatch, + IndexingMethod indm, double *intensities, + unsigned int *counts, struct gpu_context *gctx) +{ + struct hdfile *hdfile; + struct image image; + struct image *simage; + float *data_for_measurement; + size_t data_size; + + image.features = NULL; + image.data = NULL; + image.indexed_cell = NULL; + + #include "geometry-lcls.tmp" + + STATUS("Processing '%s'\n", filename); + + hdfile = hdfile_open(filename); + if ( hdfile == NULL ) { + return 0; + } else if ( hdfile_set_first_image(hdfile, "/") ) { + ERROR("Couldn't select path\n"); + return 0; + } + + hdf5_read(hdfile, &image); + + if ( config_cmfilter ) { + filter_cm(&image); + } + + /* Take snapshot of image after CM subtraction but before + * the aggressive noise filter. */ + data_size = image.width*image.height*sizeof(float); + data_for_measurement = malloc(data_size); + + if ( config_noisefilter ) { + filter_noise(&image, data_for_measurement); + } else { + + int x, y; + + for ( x=0; xdata = data_for_measurement; + output_intensities(simage, image.indexed_cell); + simage->data = NULL; + } + + /* Simulate if requested */ + if ( config_simulate ) { + if ( config_gpu ) { + simulate_and_write(simage, &gctx, intensities, + counts, cell); + } else { + simulate_and_write(simage, NULL, intensities, + counts, cell); + } + } + + /* Finished with alternate image */ + if ( simage->twotheta != NULL ) free(simage->twotheta); + if ( simage->data != NULL ) free(simage->data); + free(simage); + + /* Only free cell if found */ + free(image.indexed_cell); + +done: + free(image.data); + free(image.det.panels); + image_feature_list_free(image.features); + free(data_for_measurement); + hdfile_close(hdfile); + H5close(); + + if ( image.indexed_cell == NULL ) return 0; + return 1; +} + + int main(int argc, char *argv[]) { int c; @@ -192,7 +313,6 @@ int main(int argc, char *argv[]) int config_alternate = 0; IndexingMethod indm; char *indm_str = NULL; - struct image image; UnitCell *cell; double *intensities = NULL; char *intfile = NULL; @@ -326,123 +446,22 @@ int main(int argc, char *argv[]) do { char line[1024]; - struct hdfile *hdfile; - struct image *simage; - float *data_for_measurement; - size_t data_size; char prefixed[1024]; rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; chomp(line); - - image.features = NULL; - image.data = NULL; - image.indexed_cell = NULL; - - #include "geometry-lcls.tmp" - snprintf(prefixed, 1023, "%s%s", prefix, line); - STATUS("Processing '%s'\n", prefixed); - n_images++; - hdfile = hdfile_open(prefixed); - if ( hdfile == NULL ) { - continue; - } else if ( hdfile_set_first_image(hdfile, "/") ) { - ERROR("Couldn't select path\n"); - continue; - } - - hdf5_read(hdfile, &image); - - if ( config_cmfilter ) { - filter_cm(&image); - } - - /* Take snapshot of image after CM subtraction but before - * the aggressive noise filter. */ - data_size = image.width*image.height*sizeof(float); - data_for_measurement = malloc(data_size); - - if ( config_noisefilter ) { - filter_noise(&image, data_for_measurement); - } else { - - int x, y; - - for ( x=0; xdata = data_for_measurement; - output_intensities(simage, image.indexed_cell); - simage->data = NULL; - } - - /* Simulate if requested */ - if ( config_simulate ) { - if ( config_gpu ) { - simulate_and_write(simage, &gctx, intensities, - counts, cell); - } else { - simulate_and_write(simage, NULL, intensities, - counts, cell); - } - } - - /* Finished with alternate image */ - if ( simage->twotheta != NULL ) free(simage->twotheta); - if ( simage->data != NULL ) free(simage->data); - free(simage); - - /* Only free cell if found */ - free(image.indexed_cell); - -done: - free(image.data); - free(image.det.panels); - image_feature_list_free(image.features); - free(data_for_measurement); - hdfile_close(hdfile); - H5close(); + n_hits += process_pattern(line, cell, config_cmfilter, + config_noisefilter, + config_writedrx, config_dumpfound, + config_verbose, config_alternate, + config_nearbragg, config_gpu, + config_simulate, config_nomatch, indm, + intensities, counts, gctx); } while ( rval != NULL ); -- cgit v1.2.3