aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-02-11 12:01:31 +0100
committerThomas White <taw@physics.org>2015-02-12 11:47:07 +0100
commite22c8ae67ab6af53d21984ff3c602529f2770526 (patch)
treeb221b5f9a751f4cfd4adecde42cc7c8475dbf40f
parent830c204bbcade4e46068901cb05f10bb9db55021 (diff)
Introduce 'list_events'
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am4
-rw-r--r--doc/man/list_events.15
-rw-r--r--src/list_events.c196
4 files changed, 203 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index e51180d9..eb05b3a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,6 +37,7 @@ src/cell_explorer
src/ambigator
src/whirligig
src/geoptimiser
+src/list_events
src/.dirstamp
*~
doc/reference/libcrystfel/*
diff --git a/Makefile.am b/Makefile.am
index 3aca82ed..95938c10 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,7 @@ ACLOCAL_AMFLAGS = -I m4
bin_PROGRAMS = src/pattern_sim src/process_hkl src/get_hkl src/indexamajig \
src/compare_hkl src/partialator src/check_hkl src/partial_sim \
- src/ambigator src/geoptimiser src/whirligig
+ src/ambigator src/geoptimiser src/whirligig src/list_events
noinst_PROGRAMS = tests/list_check tests/integration_check \
tests/pr_p_gradient_check tests/symmetry_check \
@@ -68,6 +68,8 @@ endif
src_process_hkl_SOURCES = src/process_hkl.c
+src_list_events_SOURCES = src/list_events.c
+
src_indexamajig_SOURCES = src/indexamajig.c src/im-sandbox.c src/process_image.c
if BUILD_HDFSEE
diff --git a/doc/man/list_events.1 b/doc/man/list_events.1
index d1e080e3..900288f6 100644
--- a/doc/man/list_events.1
+++ b/doc/man/list_events.1
@@ -1,7 +1,8 @@
.\"
.\" list_events man page
.\"
-.\" Copyright © 2015 Thomas White <taw@physics.org>
+.\" Copyright © 2015 Deutsches Elektronen-Synchrotron DESY,
+.\" a research centre of the Helmholtz Association.
.\"
.\" Part of CrystFEL - crystallography with a FEL
.\"
@@ -16,7 +17,7 @@ list_events \- generate event lists
\fBlist_events --help\fI
.SH DESCRIPTION
-list_events expands a list of filenames, where each file contains events in a multi-event format (e.g. the CXI format, http://www.cxidb.org/), into a list of individual events.
+list_events expands a list of filenames, where each file contains events in a multi-event format (e.g. the CXI format, http://www.cxidb.org/), into a list of individual events. This might be useful if you need to sort or filter the event list prior to processing, rather than just processing all events.
.SH OPTIONS
diff --git a/src/list_events.c b/src/list_events.c
new file mode 100644
index 00000000..fedb228b
--- /dev/null
+++ b/src/list_events.c
@@ -0,0 +1,196 @@
+/*
+ * list_events.c
+ *
+ * Generate event lists
+ *
+ * Copyright © 2015 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
+ *
+ * Authors:
+ * 2015 Thomas White <taw@physics.org>
+ *
+ * This file is part of CrystFEL.
+ *
+ * CrystFEL is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CrystFEL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CrystFEL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+
+#include "version.h"
+#include "utils.h"
+#include "detector.h"
+#include "hdf5-file.h"
+
+
+static void show_help(const char *s)
+{
+ printf("Syntax: %s [options] -i files.lst -o events.lst "
+ "-g geometry.geom\n\n", s);
+ printf(
+"Generate event lists.\n"
+"\n"
+" -h, --help Display this help message.\n"
+" --version Print CrystFEL version number and exit.\n"
+"\n"
+" -i, --input=<file> Input filename (list of multi-event filenames).\n"
+" -g, --geometry=<file> Get data layout from geometry file.\n"
+" -o, --output=<file> Output filename (list of events).\n"
+);
+}
+
+
+int main(int argc, char *argv[])
+{
+ int c;
+ char *input = NULL;
+ char *output = NULL;
+ char *geom = NULL;
+ char *rval;
+ FILE *ifh;
+ FILE *ofh;
+ struct detector *det;
+ struct beam_params beam;
+
+ /* Long options */
+ const struct option longopts[] = {
+ {"help", 0, NULL, 'h'},
+ {"version", 0, NULL, 2 },
+ {"input", 1, NULL, 'i'},
+ {"geometry", 1, NULL, 'g'},
+ {"output", 1, NULL, 'o'},
+ {0, 0, NULL, 0}
+ };
+
+ /* Short options */
+ while ((c = getopt_long(argc, argv, "hi:g:o:",
+ longopts, NULL)) != -1) {
+
+ switch (c) {
+
+ case 'h' :
+ show_help(argv[0]);
+ return 0;
+
+ case 2 :
+ printf("CrystFEL: " CRYSTFEL_VERSIONSTRING "\n");
+ printf(CRYSTFEL_BOILERPLATE"\n");
+ return 0;
+
+ case 'o' :
+ output = strdup(optarg);
+ break;
+
+ case 'i' :
+ input = strdup(optarg);
+ break;
+
+ case 'g' :
+ geom = strdup(optarg);
+ break;
+
+ case 0 :
+ break;
+
+ case '?' :
+ break;
+
+ default :
+ ERROR("Unhandled option '%c'\n", c);
+ break;
+
+ }
+
+ }
+
+ if ( (input == NULL) || (output == NULL) || (geom == NULL) ) {
+ ERROR("You must specify at least the input, output and geometry"
+ " filenames.\n");
+ return 1;
+ }
+
+ ifh = fopen(input, "r");
+ if ( ifh == NULL ) {
+ ERROR("Couldn't open '%s'\n", input);
+ return 1;
+ }
+
+ ofh = fopen(output, "w");
+ if ( ofh == NULL ) {
+ ERROR("Couldn't open '%s'\n", output);
+ return 1;
+ }
+
+ det = get_detector_geometry(geom, &beam);
+ if ( det == NULL ) {
+ ERROR("Failed to read '%s'\n", geom);
+ return 1;
+ }
+
+ if ( (det->path_dim == 0) && (det->dim_dim == 0) ) {
+ ERROR("This does not look like a multi-event geometry file.\n");
+ ERROR("Are you sure you need to use list_events instead of "
+ "just 'find' or 'ls'?\n");
+ return 1;
+ }
+
+ do {
+
+ char filename[1024];
+ int i;
+
+ rval = fgets(filename, 1024, ifh);
+ if ( rval != NULL ) {
+
+ struct event_list *evlist;
+ struct hdfile *hdfile;
+
+ chomp(filename);
+
+ hdfile = hdfile_open(filename);
+ if ( hdfile == NULL ) {
+ ERROR("Failed to open '%s'\n", filename);
+ ERROR("Aborting creation of event list.\n");
+ return 1;
+ }
+
+ evlist = fill_event_list(hdfile, det);
+
+ for ( i=0; i<evlist->num_events; i++ ) {
+ char *str = get_event_string(evlist->events[i]);
+ fprintf(ofh, "%s %s\n", filename, str);
+ free(str);
+ }
+
+ STATUS("%i events found in %s\n", evlist->num_events,
+ filename);
+
+ free_event_list(evlist);
+ hdfile_close(hdfile);
+ }
+
+ } while ( rval != NULL );
+
+ return 0;
+}