From 46dcc94ec094d061724930c85944af7ea6dfb0f8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 10 Oct 2013 17:56:06 +0200 Subject: indexamajig: Add --temp-dir --- src/process_image.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/process_image.c') diff --git a/src/process_image.c b/src/process_image.c index 6d214c33..0e8eedbc 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "utils.h" #include "hdf5-file.h" @@ -50,7 +51,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, - Stream *st, int cookie) + Stream *st, int cookie, const char *tmpdir) { float *data_for_measurement; size_t data_size; @@ -58,27 +59,21 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, struct hdfile *hdfile; struct image image; int i; - char filename[1024]; - - /* Prefix to jump out of temporary folder */ - if ( pargs->filename[0] != '/' ) { - snprintf(filename, 1023, "../../%s", pargs->filename); - } else { - snprintf(filename, 1023, "%s", pargs->filename); - } + int r; + char *rn; image.features = NULL; image.data = NULL; image.flags = NULL; image.copyme = iargs->copyme; image.id = cookie; - image.filename = pargs->filename; /* Relative to top level */ + image.filename = pargs->filename; image.beam = iargs->beam; image.det = iargs->det; image.crystals = NULL; image.n_crystals = 0; - hdfile = hdfile_open(filename); /* Relative to temporary folder */ + hdfile = hdfile_open(image.filename); if ( hdfile == NULL ) return; if ( iargs->element != NULL ) { @@ -151,9 +146,24 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, free(image.data); image.data = data_for_measurement; + rn = get_current_dir_name(); + + r = chdir(tmpdir); + if ( r ) { + ERROR("Failed to chdir to temporary folder: %s\n", + strerror(errno)); + return; + } + /* Index the pattern */ index_pattern(&image, iargs->indm, iargs->ipriv); + r = chdir(rn); + if ( r ) { + ERROR("Failed to chdir: %s\n", strerror(errno)); + return; + } + pargs->n_crystals = image.n_crystals; /* Default beam parameters */ -- cgit v1.2.3