From e3fa832cd31d5dab91426b88d405b810e41cf98f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 28 Jun 2018 14:37:46 +0200 Subject: Tidy up files created by Mosflm and Felix during probe --- libcrystfel/src/felix.c | 32 +++++++++++++++++++++++++++++--- libcrystfel/src/mosflm.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) (limited to 'libcrystfel') 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 - * 2015 Kenneth Beyerlein + * 2015-2018 Thomas White + * 2015 Kenneth Beyerlein * * This file is part of CrystFEL. * @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -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 - * 2010-2016 Thomas White + * 2010-2018 Thomas White * 2014 Takanori Nakane * * This file is part of CrystFEL. @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -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"; -- cgit v1.2.3