aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-06-28 14:37:46 +0200
committerThomas White <taw@physics.org>2018-06-28 14:38:12 +0200
commite3fa832cd31d5dab91426b88d405b810e41cf98f (patch)
treedd811a21cd6966c94cfbe842ed1fe5783ae65092 /libcrystfel/src
parent960e33e15dacb42e107100900ccd4c23ca9d5fa6 (diff)
Tidy up files created by Mosflm and Felix during probe
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/felix.c32
-rw-r--r--libcrystfel/src/mosflm.c31
2 files changed, 58 insertions, 5 deletions
diff --git a/libcrystfel/src/felix.c b/libcrystfel/src/felix.c
index f87892c7..b0cb605d 100644
--- a/libcrystfel/src/felix.c
+++ b/libcrystfel/src/felix.c
@@ -3,12 +3,12 @@
*
* Invoke Felix for multi-crystal autoindexing.
*
- * Copyright © 2015-2017 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2015-2018 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2015 Thomas White <taw@physics.org>
- * 2015 Kenneth Beyerlein <kenneth.beyerlein@desy.de>
+ * 2015-2018 Thomas White <taw@physics.org>
+ * 2015 Kenneth Beyerlein <kenneth.beyerlein@desy.de>
*
* This file is part of CrystFEL.
*
@@ -38,6 +38,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
@@ -713,6 +714,20 @@ void felix_cleanup(IndexingPrivate *pp)
}
+static int file_exists(const char *filename)
+{
+ struct stat s;
+
+ if ( stat(filename, &s) != 0 ) {
+ if ( errno == ENOENT ) return 0;
+ ERROR("Failed to check for %s.\n", filename);
+ exit(1);
+ }
+
+ return 1;
+}
+
+
const char *felix_probe(UnitCell *cell)
{
pid_t pid;
@@ -726,6 +741,15 @@ const char *felix_probe(UnitCell *cell)
return NULL;
}
+ /* Felix will write gmon.out when we test it, which we are
+ * are going to delete afterwards. Better check the file doesn't exist
+ * first, in case it was important. */
+ if ( file_exists("gmon.out") ) {
+ ERROR("Please move or delete gmon.out from the working "
+ "directory first.\n");
+ exit(1);
+ }
+
pid = forkpty(&pty, NULL, NULL, NULL);
if ( pid == -1 ) {
return NULL;
@@ -758,6 +782,8 @@ const char *felix_probe(UnitCell *cell)
close(pty);
waitpid(pid, &status, 0);
+ unlink("gmon.out");
+
if ( ok ) return "felix";
return NULL;
}
diff --git a/libcrystfel/src/mosflm.c b/libcrystfel/src/mosflm.c
index 36eeb35d..9dc99162 100644
--- a/libcrystfel/src/mosflm.c
+++ b/libcrystfel/src/mosflm.c
@@ -3,13 +3,13 @@
*
* Invoke the DPS auto-indexing algorithm through MOSFLM
*
- * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2018 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
* Copyright © 2012 Richard Kirian
*
* Authors:
* 2010 Richard Kirian <rkirian@asu.edu>
- * 2010-2016 Thomas White <taw@physics.org>
+ * 2010-2018 Thomas White <taw@physics.org>
* 2014 Takanori Nakane <nakane.t@gmail.com>
*
* This file is part of CrystFEL.
@@ -65,6 +65,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
@@ -874,6 +875,20 @@ static void chop_word(char *s)
}
+static int file_exists(const char *filename)
+{
+ struct stat s;
+
+ if ( stat(filename, &s) != 0 ) {
+ if ( errno == ENOENT ) return 0;
+ ERROR("Failed to check for %s.\n", filename);
+ exit(1);
+ }
+
+ return 1;
+}
+
+
const char *mosflm_probe(UnitCell *cell)
{
pid_t pid;
@@ -884,6 +899,15 @@ const char *mosflm_probe(UnitCell *cell)
int ok = 0;
int l;
+ /* Mosflm will write mosflm.lp and SUMMARY when we test it, which we are
+ * are going to delete afterwards. Better check they don't exist first,
+ * in case they were important. */
+ if ( file_exists("mosflm.lp") || file_exists("SUMMARY") ) {
+ ERROR("Please move or delete mosflm.lp and SUMMARY from the "
+ "working directory first.\n");
+ exit(1);
+ }
+
pid = forkpty(&pty, NULL, NULL, NULL);
if ( pid == -1 ) {
return NULL;
@@ -923,6 +947,9 @@ const char *mosflm_probe(UnitCell *cell)
close(pty);
waitpid(pid, &status, 0);
+ unlink("mosflm.lp");
+ unlink("SUMMARY");
+
if ( !ok ) return NULL;
if ( cell_has_parameters(cell) ) return "mosflm-cell-nolatt,mosflm-latt-nocell";