aboutsummaryrefslogtreecommitdiff
path: root/src/facetron.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-09-13 10:54:34 +0200
committerThomas White <taw@physics.org>2012-02-22 15:26:57 +0100
commit4a235243ee6838b2745d9b3e8999d29fa76c394a (patch)
tree6440b10da74abba99edeaa2dcc72bf440bc39c68 /src/facetron.c
parentfcee934f899225e8e65aec86dea5106b7133c1a5 (diff)
facetron: Add options
Diffstat (limited to 'src/facetron.c')
-rw-r--r--src/facetron.c167
1 files changed, 46 insertions, 121 deletions
diff --git a/src/facetron.c b/src/facetron.c
index 42589526..c7c22e30 100644
--- a/src/facetron.c
+++ b/src/facetron.c
@@ -39,7 +39,10 @@ static void show_help(const char *s)
"\n"
" -i, --input=<filename> Specify the name of the input stream.\n"
" Can be '-' for stdin.\n"
-" -g. --geometry=<file> Get detector geometry from file.\n"
+" -g. --geometry=<file> Get detector geometry from file.\n"
+" -x, --prefix=<p> Prefix filenames from input file with <p>.\n"
+" --basename Remove the directory parts of the filenames.\n"
+" --no-check-prefix Don't attempt to correct the --prefix.\n"
);
}
@@ -113,122 +116,28 @@ static int find_chunk(FILE *fh, UnitCell **cell, char **filename)
}
-static void get_trial_cell(UnitCell *out, UnitCell *in, int i, double step)
+static char *twiddle_filename(char *filename, int config_basename,
+ const char *prefix)
{
- double asx, asy, asz;
- double bsx, bsy, bsz;
- double csx, csy, csz;
-
- cell_get_reciprocal(in, &asx, &asy, &asz, &bsx, &bsy, &bsz,
- &csx, &csy, &csz);
-
- switch ( i ) {
- case 0 : asx += step; break;
- case 1 : asx -= step; break;
- case 2 : asy += step; break;
- case 3 : asy -= step; break;
- case 4 : asz += step; break;
- case 5 : asz -= step; break;
- case 6 : bsx += step; break;
- case 7 : bsx -= step; break;
- case 8 : bsy += step; break;
- case 9 : bsy -= step; break;
- case 10 : bsz += step; break;
- case 11 : bsz -= step; break;
- case 12 : csx += step; break;
- case 13 : csx -= step; break;
- case 14 : csy += step; break;
- case 15 : csy -= step; break;
- case 16 : csz += step; break;
- case 17 : csz -= step; break;
- default : break;
+ char *f3;
+ size_t len;
+
+ if ( config_basename ) {
+ char *f2;
+ /* Happy with either the GNU or non-GNU versions of basename()
+ * here. Because _GNU_SOURCE is defined in configure.ac, we
+ * should have the GNU version. */
+ f2 = strdup(basename(filename));
+ free(filename);
+ filename = f2;
}
- cell_set_reciprocal(out, asx, asy, asz, bsx, bsy, bsz, csx, csy, csz);
-}
-
-
-static void try_refine(struct image *image, UnitCell *cell,
- double da, double dw, double step)
-{
- struct reflhit *hits;
- int np;
- double itot;
- UnitCell *trial_cell;
- int did_something;
-
- trial_cell = cell_new();
-
- hits = find_intersections(image, cell, da, dw, &np, 0);
- itot = integrate_all(image, hits, np);
- STATUS("%f\n", itot);
-
- do {
-
- int i;
-
- did_something = 0;
-
- for ( i=0; i<18; i++ ) {
-
- struct reflhit *trial_hits;
- double trial_itot;
-
- get_trial_cell(trial_cell, cell, i, step);
-
- trial_hits = find_intersections(image, trial_cell,
- da, dw, &np, 0);
- trial_itot = integrate_all(image, hits, np);
-
- if ( trial_itot > itot ) {
-
- double asx, asy, asz;
- double bsx, bsy, bsz;
- double csx, csy, csz;
-
- cell_get_reciprocal(trial_cell, &asx, &asy,
- &asz, &bsx, &bsy, &bsz,
- &csx, &csy, &csz);
- cell_set_reciprocal(cell, asx, asy, asz, bsx,
- bsy, bsz, csx, csy, csz);
-
- itot = trial_itot;
- free(hits);
- hits = trial_hits;
-
- did_something = 1;
+ len = strlen(prefix)+strlen(filename)+1;
+ f3 = malloc(len);
+ snprintf(f3, len, "%s%s", prefix, filename);
- } else {
-
- free(trial_hits);
-
- }
- }
-
- } while ( did_something );
-
- free(trial_cell);
-}
-
-
-/* Predict peaks */
-static void pre_refine(struct image *image, UnitCell *cell,
- double *da, double *dw)
-{
- double asx, asy, asz;
- double bsx, bsy, bsz;
- double csx, csy, csz;
- double istep, step;
-
- /* Start by changing parameters by 1% */
- cell_get_reciprocal(cell, &asx, &asy,
- &asz, &bsx, &bsy, &bsz,
- &csx, &csy, &csz);
- istep = (asx+asy+asz+bsx+bsy+bsz+csx+csy+csz)/900.0;
-
- for ( step=istep; step>istep/100.0; step-=istep/100.0 ) {
- try_refine(image, cell, *da, *dw, step);
- }
+ free(filename);
+ return f3;
}
@@ -241,17 +150,23 @@ int main(int argc, char *argv[])
char *filename;
struct detector *det;
char *geometry = NULL;
+ char *prefix = NULL;
+ int config_basename = 0;
+ int config_checkprefix = 1;
/* Long options */
const struct option longopts[] = {
{"help", 0, NULL, 'h'},
{"input", 1, NULL, 'i'},
{"geometry", 1, NULL, 'g'},
+ {"prefix", 1, NULL, 'x'},
+ {"basename", 0, &config_basename, 1},
+ {"no-check-prefix", 0, &config_checkprefix, 0},
{0, 0, NULL, 0}
};
/* Short options */
- while ((c = getopt_long(argc, argv, "hi:g:", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "hi:g:x:", longopts, NULL)) != -1) {
switch (c) {
case 'h' :
@@ -266,6 +181,10 @@ int main(int argc, char *argv[])
geometry = strdup(optarg);
break;
+ case 'x' :
+ prefix = strdup(optarg);
+ break;
+
case 0 :
break;
@@ -287,6 +206,14 @@ int main(int argc, char *argv[])
return ENOENT;
}
+ if ( prefix == NULL ) {
+ prefix = strdup("");
+ } else {
+ if ( config_checkprefix ) {
+ prefix = check_prefix(prefix);
+ }
+ }
+
det = get_detector_geometry(geometry);
if ( det == NULL ) {
ERROR("Failed to read detector geometry from '%s'\n", geometry);
@@ -299,9 +226,11 @@ int main(int argc, char *argv[])
struct image image;
struct hdfile *hdfile;
- double da, dw;
+ struct reflhit *hits;
int np;
+ filename = twiddle_filename(filename, config_basename, prefix);
+
STATUS("Integrating intensities from '%s'\n", filename);
image.det = det;
@@ -316,12 +245,7 @@ int main(int argc, char *argv[])
hdf5_read(hdfile, &image, 0);
- da = 5.0e-3; /* Initial divergence */
- dw = 3.0/100.0; /* Initial bandwidth */
-
- pre_refine(&image, cell, &da, &dw);
-
- find_intersections(&image, cell, da, dw, &np, 1);
+ hits = find_intersections(&image, cell, 5.0e-3, 0.0001, &np, 1);
hdfile_close(hdfile);
cell_free(cell);
@@ -334,6 +258,7 @@ int main(int argc, char *argv[])
free(det->panels);
free(det);
fclose(fh);
+ free(prefix);
return 0;
}