From dd34a78a67eb884eb91df9813361acf6acb562d1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 2 Dec 2020 15:41:49 +0100 Subject: process_hkl: Work with multiple input streams --- src/process_hkl.c | 180 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 137 insertions(+), 43 deletions(-) (limited to 'src/process_hkl.c') diff --git a/src/process_hkl.c b/src/process_hkl.c index 440ad3ee..f638ea3e 100644 --- a/src/process_hkl.c +++ b/src/process_hkl.c @@ -397,33 +397,25 @@ static void display_progress(int n_images, int n_crystals, int n_crystals_used) } -static int merge_all(Stream *st, - RefList *model, RefList *reference, - const SymOpList *sym, - double **hist_vals, signed int hist_h, - signed int hist_k, signed int hist_l, - int *hist_i, struct polarisation p, - int min_measurements, - double min_snr, double max_adu, - int start_after, int stop_after, double min_res, - double push_res, double min_cc, int do_scale, - int flag_even_odd, char *stat_output) +static int merge_stream(Stream *st, + RefList *model, RefList *reference, + const SymOpList *sym, + double **hist_vals, signed int hist_h, + signed int hist_k, signed int hist_l, + int *hist_i, struct polarisation p, + int min_measurements, + double min_snr, double max_adu, + int start_after, int stop_after, double min_res, + double push_res, double min_cc, int do_scale, + int flag_even_odd, char *stat_output, + int *pn_images, int *pn_crystals, + int *pn_crystals_used, int *pn_crystals_seen, + FILE *stat) { - int n_images = 0; - int n_crystals = 0; - int n_crystals_used = 0; - Reflection *refl; - RefListIterator *iter; - int n_crystals_seen = 0; - FILE *stat = NULL; - - if ( stat_output != NULL ) { - stat = fopen(stat_output, "w"); - if ( stat == NULL ) { - ERROR("Failed to open statistics output file %s\n", - stat_output); - } - } + int n_images = *pn_images; + int n_crystals = *pn_crystals; + int n_crystals_used = *pn_crystals_used; + int n_crystals_seen = *pn_crystals_seen; do { @@ -469,6 +461,65 @@ static int merge_all(Stream *st, } while ( 1 ); + *pn_images = n_images; + *pn_crystals = n_crystals; + *pn_crystals_seen = n_crystals_seen; + *pn_crystals_used = n_crystals_used; + return 0; +} + + +struct stream_list +{ + int n; + int max_n; + const char **filenames; + Stream **streams; +}; + + +static int merge_all(struct stream_list *streams, + RefList *model, RefList *reference, + const SymOpList *sym, + double **hist_vals, signed int hist_h, + signed int hist_k, signed int hist_l, + int *hist_i, struct polarisation p, + int min_measurements, + double min_snr, double max_adu, + int start_after, int stop_after, double min_res, + double push_res, double min_cc, int do_scale, + int flag_even_odd, char *stat_output) +{ + Reflection *refl; + RefListIterator *iter; + int i; + int n_images = 0; + int n_crystals = 0; + int n_crystals_used = 0; + int n_crystals_seen = 0; + FILE *stat = NULL; + + if ( stat_output != NULL ) { + stat = fopen(stat_output, "w"); + if ( stat == NULL ) { + ERROR("Failed to open statistics output file %s\n", + stat_output); + } + } + + for ( i=0; in; i++ ) { + if ( merge_stream(streams->streams[i], + model, reference, sym, + hist_vals, hist_h, hist_k, hist_l, hist_i, + p, min_measurements, min_snr, max_adu, + start_after, stop_after, min_res, + push_res, min_cc, do_scale, + flag_even_odd, stat_output, + &n_images, &n_crystals, &n_crystals_used, + &n_crystals_seen, stat) ) return 1; + } + + for ( refl = first_refl(model, &iter); refl != NULL; refl = next_refl(refl, iter) ) @@ -494,13 +545,45 @@ static int merge_all(Stream *st, } +static int add_stream(const char *filename, struct stream_list *list) +{ + if ( list->n == list->max_n ) { + const char **new_filenames = realloc(list->filenames, + (list->n+16)*sizeof(const char *)); + Stream **new_streams = realloc(list->streams, + (list->n+16)*sizeof(Stream *)); + if ( (new_filenames == NULL) || (new_streams == NULL) ) return 1; + list->max_n += 16; + list->filenames = new_filenames; + list->streams = new_streams; + } + + list->filenames[list->n] = filename; + list->streams[list->n] = NULL; + list->n++; + return 0; +} + + +static int rewind_all_streams(struct stream_list *stream_list) +{ + int i; + + for ( i=0; in; i++ ) { + if ( stream_rewind(stream_list->streams[i]) ) { + return 1; + } + } + return 0; +} + + int main(int argc, char *argv[]) { int c; - char *filename = NULL; + int i; char *output = NULL; char *stat_output = NULL; - Stream *st; RefList *model; int config_scale = 0; int config_evenonly = 0; @@ -531,6 +614,10 @@ int main(int argc, char *argv[]) double min_cc = -INFINITY; int twopass = 0; char *audit_info; + struct stream_list stream_list = {.n = 0, + .max_n = 0, + .filenames = NULL, + .streams = NULL}; /* Long options */ const struct option longopts[] = { @@ -572,7 +659,7 @@ int main(int argc, char *argv[]) return 0; case 'i' : - filename = strdup(optarg); + add_stream(optarg, &stream_list); break; case 'o' : @@ -706,8 +793,12 @@ int main(int argc, char *argv[]) } - if ( filename == NULL ) { - ERROR("Please specify filename using the -i option\n"); + while ( optind < argc ) { + add_stream(argv[optind++], &stream_list); + } + + if ( stream_list.n == 0 ) { + ERROR("Please give at least one input stream filename.\n"); return 1; } @@ -720,11 +811,13 @@ int main(int argc, char *argv[]) sym = get_pointgroup(sym_str); free(sym_str); - /* Open the data stream */ - st = stream_open_for_read(filename); - if ( st == NULL ) { - ERROR("Failed to open stream.\n"); - return 1; + /* Open all the data streams */ + for ( i=0; i