aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt15
-rw-r--r--libcrystfel/CMakeLists.txt13
-rw-r--r--src/gui_backend_local.c141
3 files changed, 155 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a724af52..0ddee846 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,19 @@ else ()
message(STATUS "ZMQ not found.")
endif ()
+# Find out where forkpty() is declared
+set(CMAKE_REQUIRED_LIBRARIES "-lutil")
+check_symbol_exists(forkpty "pty.h" HAVE_FORKPTY_PTY_H)
+check_symbol_exists(forkpty "util.h" HAVE_FORKPTY_UTIL_H)
+unset(CMAKE_REQUIRED_LIBRARIES)
+if(HAVE_FORKPTY_PTY_H)
+ message(STATUS "Found forkpty() in pty.h")
+elseif(HAVE_FORKPTY_UTIL_H)
+ message(STATUS "Found forkpty() in util.h")
+else()
+ message(SEND_ERROR "Couldn't find forkpty()")
+endif()
+
pkg_search_module(GTK gtk+-3.0)
if (NOT GTK_FOUND)
@@ -376,7 +389,7 @@ if (GTK_FOUND)
add_executable(crystfel ${CRYSTFEL_GUI_SOURCES})
target_include_directories(crystfel PRIVATE ${COMMON_INCLUDES} ${GTK_INCLUDE_DIRS})
- target_link_libraries(crystfel ${COMMON_LIBRARIES} ${GTK_LIBRARIES})
+ target_link_libraries(crystfel ${COMMON_LIBRARIES} util ${GTK_LIBRARIES})
list(APPEND CRYSTFEL_EXECUTABLES crystfel)
diff --git a/libcrystfel/CMakeLists.txt b/libcrystfel/CMakeLists.txt
index 1e30bf81..06e7dfa3 100644
--- a/libcrystfel/CMakeLists.txt
+++ b/libcrystfel/CMakeLists.txt
@@ -21,19 +21,6 @@ set(CMAKE_REQUIRED_LIBRARIES "-lz")
check_symbol_exists(gzbuffer "zlib.h" HAVE_GZBUFFER)
unset(CMAKE_REQUIRED_LIBRARIES)
-# Find out where forkpty() is declared
-set(CMAKE_REQUIRED_LIBRARIES "-lutil")
-check_symbol_exists(forkpty "pty.h" HAVE_FORKPTY_PTY_H)
-check_symbol_exists(forkpty "util.h" HAVE_FORKPTY_UTIL_H)
-unset(CMAKE_REQUIRED_LIBRARIES)
-if(HAVE_FORKPTY_PTY_H)
- message(STATUS "Found forkpty() in pty.h")
-elseif(HAVE_FORKPTY_UTIL_H)
- message(STATUS "Found forkpty() in util.h")
-else()
- message(SEND_ERROR "Couldn't find forkpty()")
-endif()
-
configure_file(config.h.cmake.in config.h)
bison_target(symopp src/symop.y ${CMAKE_CURRENT_BINARY_DIR}/symop-parse.c COMPILE_FLAGS --report=all)
diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c
index b3ba8657..c811a655 100644
--- a/src/gui_backend_local.c
+++ b/src/gui_backend_local.c
@@ -26,13 +26,154 @@
*
*/
+#include <pty.h>
+#include <glib.h>
#include "crystfel_gui.h"
+
+static gboolean index_readable(GIOChannel *source, GIOCondition cond,
+ void *vp)
+{
+ GIOStatus r;
+ GError *err = NULL;
+ struct crystfelproject *proj = vp;
+ gchar *line;
+
+ r = g_io_channel_read_line(source, &line, NULL, NULL, &err);
+ if ( r == G_IO_STATUS_EOF ) {
+ STATUS("End of output.\n");
+ return FALSE;
+ }
+ if ( r != G_IO_STATUS_NORMAL ) {
+ STATUS("Read error?\n");
+ return FALSE;
+ }
+ STATUS("Got line '%s'\n", line);
+
+ g_free(line);
+
+ return TRUE;
+}
+
+
+static int write_file_list(struct crystfelproject *proj)
+{
+ FILE *fh;
+ int i;
+
+ fh = fopen("files.lst", "w");
+ if ( fh == NULL ) return 1;
+
+ for ( i=0; i<proj->n_frames; i++ ) {
+ fprintf(fh, "%s", proj->filenames[i]);
+ if ( proj->events[i] != NULL ) {
+ fprintf(fh, " %s\n", proj->events[i]);
+ } else {
+ fprintf(fh, "\n");
+ }
+ }
+
+ fclose(fh);
+
+ return 0;
+}
+
+
+static void add_arg(char **args, int pos, const char *label,
+ float val)
+{
+ char *str;
+
+ str = malloc(64);
+ if ( str == NULL ) return;
+
+ snprintf(str, 63, "--%s=%f", label, val);
+ args[pos] = str;
+}
+
+
static int run_unitcell(struct crystfelproject *proj,
const char *algo)
{
+ pid_t pid;
+ int pty;
+ GIOChannel *ioch;
+ char *args[64];
+ char index_str[64];
+ char peaks_str[64];
+ int n_args;
+
STATUS("run unit cell with '%s'!\n", algo);
+
+ if ( write_file_list(proj) ) {
+ STATUS("Failed to write list\n");
+ return 1;
+ }
+
+ strcpy(index_str, "--indexing=");
+ strncat(index_str, algo, 50);
+
+ strcpy(peaks_str, "--peaks=");
+ strncat(peaks_str,
+ str_peaksearch(proj->peak_search_params.method), 50);
+
+ args[0] = "indexamajig";
+ args[1] = "-i";
+ args[2] = "files.lst";
+ args[3] = "-g";
+ args[4] = proj->geom_filename;
+ args[5] = "-o";
+ args[6] = "test.stream";
+ args[7] = index_str;
+ args[8] = "--no-check-cell";
+ args[9] = "-j";
+ args[10] = "1";
+ args[11] = "--integration=none";
+ args[12] = peaks_str;
+ n_args = 13;
+
+ if ( proj->peak_search_params.method == PEAK_ZAEF ) {
+ add_arg(args, n_args++, "threshold",
+ proj->peak_search_params.threshold);
+ add_arg(args, n_args++, "min-squared-gradient",
+ proj->peak_search_params.min_sq_gradient);
+ add_arg(args, n_args++, "min-snr",
+ proj->peak_search_params.min_snr);
+ }
+
+ args[n_args] = NULL;
+
+ int i;
+ for ( i=0; i<n_args; i++ ) {
+ STATUS("%s ", args[i]);
+ }
+ STATUS("\n");
+
+ pid = forkpty(&pty, NULL, NULL, NULL);
+ if ( pid == -1 ) return 1;
+
+ if ( pid == 0 ) {
+
+ /* Child process */
+ struct termios t;
+
+ /* Turn echo off */
+ tcgetattr(STDIN_FILENO, &t);
+ t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
+ tcsetattr(STDIN_FILENO, TCSANOW, &t);
+
+ execvp("indexamajig", args);
+ _exit(1);
+
+ }
+
+ ioch = g_io_channel_unix_new(pty);
+ g_io_add_watch(ioch, G_IO_IN | G_IO_ERR | G_IO_HUP,
+ index_readable, proj);
+
+ /* FIXME: waitpid() on SIGCHLD */
+
return 0;
}