aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/mosflm.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel/src/mosflm.c')
-rw-r--r--libcrystfel/src/mosflm.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/libcrystfel/src/mosflm.c b/libcrystfel/src/mosflm.c
index 4cf21103..7ebf6e19 100644
--- a/libcrystfel/src/mosflm.c
+++ b/libcrystfel/src/mosflm.c
@@ -821,6 +821,12 @@ void *mosflm_prepare(IndexingMethod *indm, UnitCell *cell)
{
struct mosflm_private *mp;
+ if ( mosflm_probe(cell) == NULL ) {
+ ERROR("Mosflm does not appear to run properly.\n");
+ ERROR("Please check your Mosflm installation.\n");
+ return NULL;
+ }
+
/* Flags that MOSFLM knows about */
*indm &= INDEXING_METHOD_MASK
| INDEXING_USE_LATTICE_TYPE | INDEXING_USE_CELL_PARAMETERS;
@@ -841,3 +847,75 @@ void mosflm_cleanup(void *pp)
p = (struct mosflm_private *)pp;
free(p);
}
+
+
+static void chop_word(char *s)
+{
+ int i;
+ size_t l = strlen(s);
+ for ( i=0; i<l; i++ ) {
+ if ( s[i] == ' ' ) {
+ s[i] = '\0';
+ return;
+ }
+ }
+}
+
+
+const char *mosflm_probe(UnitCell *cell)
+{
+ pid_t pid;
+ int pty;
+ int status;
+ FILE *fh;
+ char line[1024];
+ int ok = 0;
+ int l;
+
+ pid = forkpty(&pty, NULL, NULL, NULL);
+ if ( pid == -1 ) {
+ return NULL;
+ }
+ 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);
+
+ execlp("mosflm", "mosflm", (char *)NULL);
+ execlp("ipmosflm", "ipmosflm", (char *)NULL);
+ _exit(1);
+
+ }
+
+ fh = fdopen(pty, "r");
+
+ for ( l=0; l<10; l++ ) {
+ char *pos;
+ if ( fgets(line, 1024, fh) == NULL ) {
+ ERROR("Failed to probe for Mosflm\n");
+ } else {
+ pos = strstr(line, "Mosflm version ");
+ if ( pos != NULL ) {
+ char *vers = pos+15;
+ ok = 1;
+ chop_word(vers);
+ /* FIXME: Set capabilities based on version */
+ }
+ }
+ }
+
+ fclose(fh);
+ close(pty);
+ waitpid(pid, &status, 0);
+
+ if ( !ok ) return NULL;
+
+ if ( cell_has_parameters(cell) ) return "mosflm-cell-nolatt,mosflm-latt-nocell";
+ if ( cell != NULL ) return "mosflm-latt-nocell";
+ return "mosflm-nolatt-nocell";
+}