diff options
author | Thomas White <taw@physics.org> | 2017-10-18 10:23:05 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2017-10-18 10:23:05 +0200 |
commit | 7f708ef255f068ef9e91941ac3a0a3d0e04e5ff8 (patch) | |
tree | e9298ce158cf2688b7a3af5892aa4f2ea7d379ec | |
parent | f15f4b792826c917f258c2e6195f6994d3450754 (diff) |
Add probe functions to indexing methods
-rw-r--r-- | libcrystfel/src/asdf.c | 6 | ||||
-rw-r--r-- | libcrystfel/src/asdf.h | 8 | ||||
-rw-r--r-- | libcrystfel/src/dirax.c | 43 | ||||
-rw-r--r-- | libcrystfel/src/dirax.h | 1 | ||||
-rw-r--r-- | libcrystfel/src/felix.c | 47 | ||||
-rw-r--r-- | libcrystfel/src/felix.h | 2 | ||||
-rw-r--r-- | libcrystfel/src/mosflm.c | 68 | ||||
-rw-r--r-- | libcrystfel/src/mosflm.h | 1 | ||||
-rw-r--r-- | libcrystfel/src/xds.c | 51 | ||||
-rw-r--r-- | libcrystfel/src/xds.h | 2 |
10 files changed, 229 insertions, 0 deletions
diff --git a/libcrystfel/src/asdf.c b/libcrystfel/src/asdf.c index 869d9256..9dc5f9d5 100644 --- a/libcrystfel/src/asdf.c +++ b/libcrystfel/src/asdf.c @@ -1188,3 +1188,9 @@ void asdf_cleanup(void *pp) fftw_vars_free(p->fftw); free(p); } + + +const char *asdf_probe(UnitCell *cell) +{ + return "asdf"; +} diff --git a/libcrystfel/src/asdf.h b/libcrystfel/src/asdf.h index 7f110960..896f65a8 100644 --- a/libcrystfel/src/asdf.h +++ b/libcrystfel/src/asdf.h @@ -46,6 +46,7 @@ extern "C" { extern int run_asdf(struct image *image, void *ipriv); extern void *asdf_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *asdf_probe(UnitCell *cell); extern void asdf_cleanup(void *pp); @@ -65,6 +66,13 @@ void *asdf_prepare(IndexingMethod *indm, UnitCell *cell) return NULL; } + +const char *asdf_probe(UnitCell *cell) +{ + return NULL; +} + + void asdf_cleanup(void *pp) { } diff --git a/libcrystfel/src/dirax.c b/libcrystfel/src/dirax.c index f781d7e2..1dacd021 100644 --- a/libcrystfel/src/dirax.c +++ b/libcrystfel/src/dirax.c @@ -623,3 +623,46 @@ void dirax_cleanup(void *pp) p = (struct dirax_private *)pp; free(p); } + + +const char *dirax_probe(UnitCell *cell) +{ + pid_t pid; + int pty; + int status; + FILE *fh; + char line[1024]; + int ok = 0; + + pid = forkpty(&pty, NULL, NULL, NULL); + if ( pid == -1 ) { + return NULL; + } + if ( pid == 0 ) { + + /* Child process: invoke DirAx */ + struct termios t; + + /* Turn echo off */ + tcgetattr(STDIN_FILENO, &t); + t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + + execlp("dirax", "dirax", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + fgets(line, 1024, fh); + if ( strncmp(line, "dirax", 5) == 0 ) { + ok = 1; + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( ok ) return "dirax"; + return NULL; +} diff --git a/libcrystfel/src/dirax.h b/libcrystfel/src/dirax.h index db03abf8..dce27c57 100644 --- a/libcrystfel/src/dirax.h +++ b/libcrystfel/src/dirax.h @@ -42,6 +42,7 @@ extern "C" { extern int run_dirax(struct image *image, void *ipriv); extern void *dirax_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *dirax_probe(UnitCell *cell); extern void dirax_cleanup(void *pp); diff --git a/libcrystfel/src/felix.c b/libcrystfel/src/felix.c index 973b0513..5036ff74 100644 --- a/libcrystfel/src/felix.c +++ b/libcrystfel/src/felix.c @@ -716,3 +716,50 @@ void felix_cleanup(IndexingPrivate *pp) free(p->readhkl_file); free(p); } + + +const char *felix_probe(UnitCell *cell) +{ + pid_t pid; + int pty; + int status; + FILE *fh; + char line[1024]; + int ok = 0; + + if ( !cell_has_parameters(cell) ) { + return NULL; + } + + pid = forkpty(&pty, NULL, NULL, NULL); + if ( pid == -1 ) { + return NULL; + } + if ( pid == 0 ) { + + /* Child process: invoke DirAx */ + struct termios t; + + /* Turn echo off */ + tcgetattr(STDIN_FILENO, &t); + t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + + execlp("Felix", "Felix", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + fgets(line, 1024, fh); + if ( strncmp(line, "Felix", 5) == 0 ) { + ok = 1; + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( ok ) return "felix"; + return NULL; +} diff --git a/libcrystfel/src/felix.h b/libcrystfel/src/felix.h index 40568d37..61b1d352 100644 --- a/libcrystfel/src/felix.h +++ b/libcrystfel/src/felix.h @@ -39,6 +39,8 @@ extern void *felix_prepare(IndexingMethod *indm, UnitCell *cell, const char *options); +extern const char *felix_probe(UnitCell *cell); + extern void felix_cleanup(IndexingPrivate *pp); extern int felix_index(struct image *image, IndexingPrivate *p); diff --git a/libcrystfel/src/mosflm.c b/libcrystfel/src/mosflm.c index 4cf21103..d4034e86 100644 --- a/libcrystfel/src/mosflm.c +++ b/libcrystfel/src/mosflm.c @@ -841,3 +841,71 @@ 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; + fgets(line, 1024, fh); + pos = strstr(line, "Mosflm version "); + if ( pos != NULL ) { + char *vers = pos+15; + ok = 1; + chop_word(vers); + } + } + + 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"; +} diff --git a/libcrystfel/src/mosflm.h b/libcrystfel/src/mosflm.h index cd7804a8..9339b856 100644 --- a/libcrystfel/src/mosflm.h +++ b/libcrystfel/src/mosflm.h @@ -44,6 +44,7 @@ extern "C" { extern int run_mosflm(struct image *image, void *ipriv); extern void *mosflm_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *mosflm_probe(UnitCell *cell); extern void mosflm_cleanup(void *pp); diff --git a/libcrystfel/src/xds.c b/libcrystfel/src/xds.c index ba053d2f..a234d1e0 100644 --- a/libcrystfel/src/xds.c +++ b/libcrystfel/src/xds.c @@ -637,3 +637,54 @@ void xds_cleanup(void *pp) xp = (struct xds_private *)pp; free(xp); } + + +const char *xds_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("xds", "xds", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + + for ( l=0; l<10; l++ ) { + char *pos; + fgets(line, 1024, fh); + pos = strstr(line, "** XDS **"); + if ( pos != NULL ) { + ok = 1; + } + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( !ok ) return NULL; + + if ( cell_has_parameters(cell) ) return "xds-cell-latt"; + return "xds-nocell-nolatt"; +} diff --git a/libcrystfel/src/xds.h b/libcrystfel/src/xds.h index 8777df10..c89b615c 100644 --- a/libcrystfel/src/xds.h +++ b/libcrystfel/src/xds.h @@ -46,6 +46,8 @@ extern int run_xds(struct image *image, void *ipriv); extern void *xds_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *xds_probe(UnitCell *cell); + extern void xds_cleanup(void *pp); #ifdef __cplusplus |