aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-09-24 16:38:49 +0200
committerThomas White <taw@physics.org>2020-09-24 16:38:49 +0200
commit7e5803210455dacd0fc0c760c03648f67b312313 (patch)
treec879b3e6721a6324717e4e990b2119103c22b700
parentb98605e59db59aa889d471bab19157522cad7341 (diff)
cell_explorer: Accept multiple streams on command line
-rw-r--r--src/cell_explorer.c178
1 files changed, 100 insertions, 78 deletions
diff --git a/src/cell_explorer.c b/src/cell_explorer.c
index 7d1ca068..922cd714 100644
--- a/src/cell_explorer.c
+++ b/src/cell_explorer.c
@@ -1928,75 +1928,19 @@ static void indexing_method_list(CellWindow *w, GtkWidget *vbox)
}
-int main(int argc, char *argv[])
+static int add_stream(CellWindow *w, const char *stream_filename,
+ int *pmax_cells, int *pn_total_chunks)
{
- int c;
Stream *st;
- int max_cells = 0;
- char *stream_filename;
- GtkWidget *box, *vbox;
- char title[1024];
- char *bn;
- CellWindow w;
int n_chunks = 0;
- int i;
-
- /* Long options */
- const struct option longopts[] = {
- {"help", 0, NULL, 'h'},
- {"version", 0, NULL, 1 },
- {0, 0, NULL, 0}
- };
-
- /* Short options */
- while ((c = getopt_long(argc, argv, "h",
- longopts, NULL)) != -1) {
-
- switch (c) {
-
- case 'h' :
- show_help(argv[0]);
- return 0;
-
- case 1 :
- printf("CrystFEL: %s\n",
- crystfel_version_string());
- printf("%s\n",
- crystfel_licence_string());
- return 0;
-
- default :
- return 1;
-
- }
-
- }
-
- /* This isn't great, but necessary to make the command-line UI and file
- * formats consistent with the other programs, which all use the C
- * locale. Better would be to have all the programs call
- * setlocale(LC_ALL, "") and use the C locale temporarily when reading
- * or writing a stream, reflection file, geometry file etc. */
- gtk_disable_setlocale();
-
- gtk_init(&argc, &argv);
+ int max_cells = *pmax_cells;
- if ( argc != (optind+1) ) {
- fprintf(stderr, "Please provide exactly one stream filename.\n");
- return 1;
- }
- stream_filename = strdup(argv[optind]);
st = stream_open_for_read(stream_filename);
if ( st == NULL ) {
- fprintf(stderr, "Failed to open '%s'\n", stream_filename);
+ fprintf(stderr, "Failed to open '%s'\n",
+ stream_filename);
return 1;
}
-
- gsl_set_error_handler_off();
-
- w.cells = NULL;
- w.indms = NULL;
- w.n_cells = 0;
do {
struct image *image;
@@ -2011,14 +1955,14 @@ int main(int argc, char *argv[])
cr = image->crystals[i];
- if ( w.n_cells == max_cells ) {
+ if ( w->n_cells == max_cells ) {
UnitCell **cells_new;
IndexingMethod *indms_new;
size_t nsz;
nsz = (max_cells+1024)*sizeof(UnitCell *);
- cells_new = realloc(w.cells, nsz);
+ cells_new = realloc(w->cells, nsz);
if ( cells_new == NULL ) {
fprintf(stderr, "Failed to allocate "
"memory for cells.\n");
@@ -2026,7 +1970,7 @@ int main(int argc, char *argv[])
}
nsz = (max_cells+1024)*sizeof(IndexingMethod);
- indms_new = realloc(w.indms, nsz);
+ indms_new = realloc(w->indms, nsz);
if ( indms_new == NULL ) {
fprintf(stderr, "Failed to allocate "
"memory for methods.\n");
@@ -2034,32 +1978,30 @@ int main(int argc, char *argv[])
}
max_cells += 1024;
- w.cells = cells_new;
- w.indms = indms_new;
+ *pmax_cells = max_cells;
+ w->cells = cells_new;
+ w->indms = indms_new;
}
- w.cells[w.n_cells] = cell_new_from_cell(crystal_get_cell(cr));
- if ( !right_handed(w.cells[w.n_cells]) ) {
+ w->cells[w->n_cells] = cell_new_from_cell(crystal_get_cell(cr));
+ if ( !right_handed(w->cells[w->n_cells]) ) {
ERROR("WARNING: Left-handed cell encountered\n");
}
- w.indms[w.n_cells] = image->indexed_by;
- w.n_cells++;
+ w->indms[w->n_cells] = image->indexed_by;
+ w->n_cells++;
}
n_chunks++;
if ( n_chunks % 1000 == 0 ) {
- fprintf(stderr, "Loaded %i cells from %i chunks\r",
- w.n_cells, n_chunks);
+ fprintf(stderr, "%s: Loaded %i cells from %i chunks\r",
+ stream_filename, w->n_cells, n_chunks);
}
image_free(image);
} while ( 1 );
- fprintf(stderr, "Loaded %i cells from %i chunks\n", w.n_cells, n_chunks);
-
- fprintf(stderr, "\n");
if ( stream_has_old_indexers(st) ) {
ERROR("----- Notice -----\n");
@@ -2072,8 +2014,89 @@ int main(int argc, char *argv[])
ERROR("To simplify matters, it's best to re-run indexamajig.\n");
ERROR("------------------\n");
}
+
stream_close(st);
+ *pn_total_chunks = n_chunks;
+ return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+ int c;
+ int max_cells = 0;
+ int n_chunks = 0;
+ GtkWidget *box, *vbox;
+ char title[1024];
+ CellWindow w;
+ int i;
+ char *name_for_title;
+
+ /* Long options */
+ const struct option longopts[] = {
+ {"help", 0, NULL, 'h'},
+ {"version", 0, NULL, 1 },
+ {0, 0, NULL, 0}
+ };
+
+ /* Short options */
+ while ((c = getopt_long(argc, argv, "h",
+ longopts, NULL)) != -1) {
+
+ switch (c) {
+
+ case 'h' :
+ show_help(argv[0]);
+ return 0;
+
+ case 1 :
+ printf("CrystFEL: %s\n",
+ crystfel_version_string());
+ printf("%s\n",
+ crystfel_licence_string());
+ return 0;
+
+ default :
+ return 1;
+
+ }
+
+ }
+
+ /* This isn't great, but necessary to make the command-line UI and file
+ * formats consistent with the other programs, which all use the C
+ * locale. Better would be to have all the programs call
+ * setlocale(LC_ALL, "") and use the C locale temporarily when reading
+ * or writing a stream, reflection file, geometry file etc. */
+ gtk_disable_setlocale();
+
+ gtk_init(&argc, &argv);
+
+ if ( argc < optind ) {
+ fprintf(stderr, "Please provide at least one stream filename.\n");
+ return 1;
+ }
+
+ name_for_title = safe_basename(argv[optind]);
+
+ gsl_set_error_handler_off();
+
+ w.cells = NULL;
+ w.indms = NULL;
+ w.n_cells = 0;
+
+ while ( optind < argc ) {
+ if ( add_stream(&w, argv[optind++],
+ &max_cells, &n_chunks) )
+ {
+ return 1;
+ }
+ }
+
+ fprintf(stderr, "Loaded %i cells from %i total chunks\n",
+ w.n_cells, n_chunks);
+
w.cols_on[0] = 1;
for ( i=1; i<8; i++ ) w.cols_on[i] = 2;
@@ -2096,9 +2119,8 @@ int main(int argc, char *argv[])
reset_axes(w.hist_ga);
w.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- bn = safe_basename(stream_filename);
- snprintf(title, 1023, "%s - Unit Cell Explorer", bn);
- free(bn);
+ snprintf(title, 1023, "%s - Unit Cell Explorer",
+ name_for_title);
gtk_window_set_title(GTK_WINDOW(w.window), title);
g_signal_connect(G_OBJECT(w.window), "destroy", G_CALLBACK(destroy_sig),
&w);