aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/facetron.c224
1 files changed, 100 insertions, 124 deletions
diff --git a/src/facetron.c b/src/facetron.c
index 7da96153..d2c0edd7 100644
--- a/src/facetron.c
+++ b/src/facetron.c
@@ -44,7 +44,7 @@ struct process_args
UnitCell *cell;
struct detector *det;
- char *sym;
+ const char *sym;
};
@@ -211,122 +211,14 @@ static int find_chunk(FILE *fh, UnitCell **cell, char **filename)
}
-static void add_to_mean(UnitCell *cell, double *ast, double *bst, double *cst,
- double *alst, double *best, double *gast)
+static void optimise_all(int nthreads, struct detector *det, const char *sym,
+ FILE *fh, int config_basename, const char *prefix)
{
- double asx, asy, asz;
- double bsx, bsy, bsz;
- double csx, csy, csz;
-
- cell_get_reciprocal(cell, &asx, &asy, &asz, &bsx, &bsy, &bsz,
- &csx, &csy, &csz);
- *ast += modulus(asx, asy, asz);
- *bst += modulus(bsx, bsy, bsz);
- *cst += modulus(csx, csy, csz);
- *alst += angle_between(bsx, bsy, bsz, csx, csy, csz);
- *best += angle_between(asx, asy, asz, csx, csy, csz);
- *gast += angle_between(asx, asy, asz, bsx, bsy, bsz);
-}
-
-
-int main(int argc, char *argv[])
-{
- int c;
- char *infile = NULL;
- char *geomfile = NULL;
- FILE *fh;
- int rval;
- int n_images;
- char *prefix = NULL;
- int nthreads = 1;
pthread_t workers[MAX_THREADS];
struct process_args *worker_args[MAX_THREADS];
int worker_active[MAX_THREADS];
- int config_basename = 0;
- int config_checkprefix = 1;
- struct detector *det;
int i;
- char *sym = NULL;
- double as, bs, cs, als, bes, gas;
-
- /* 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:x:j:",
- longopts, NULL)) != -1) {
-
- switch (c) {
- case 'h' :
- show_help(argv[0]);
- return 0;
-
- case 'i' :
- infile = strdup(optarg);
- break;
-
- case 'g' :
- geomfile = strdup(optarg);
- break;
-
- case 'x' :
- prefix = strdup(optarg);
- break;
-
- case 'j' :
- nthreads = atoi(optarg);
- break;
-
- case 0 :
- break;
-
- default :
- return 1;
- }
-
- }
-
-
- if ( infile == NULL ) {
- infile = strdup("-");
- }
- if ( strcmp(infile, "-") == 0 ) {
- fh = stdin;
- } else {
- fh = fopen(infile, "r");
- }
- if ( fh == NULL ) {
- ERROR("Failed to open input file '%s'\n", infile);
- return 1;
- }
- free(infile);
-
- if ( prefix == NULL ) {
- prefix = strdup("");
- } else {
- if ( config_checkprefix ) {
- prefix = check_prefix(prefix);
- }
- }
-
- det = get_detector_geometry(geomfile);
- if ( det == NULL ) {
- ERROR("Failed to read detector geometry from '%s'\n", geomfile);
- return 1;
- }
- free(geomfile);
-
- sym = strdup("6/mmm"); /* FIXME: Should be on command line */
-
- as = 0.0; bs = 0.0; cs = 0.0; als = 0.0; bes = 0.0; gas = 0.0;
+ int rval;
/* Initialise worker arguments */
for ( i=0; i<nthreads; i++ ) {
@@ -340,8 +232,6 @@ int main(int argc, char *argv[])
}
- n_images = 0;
-
/* Start threads off */
for ( i=0; i<nthreads; i++ ) {
@@ -356,7 +246,6 @@ int main(int argc, char *argv[])
/* Get the next filename */
rval = find_chunk(fh, &cell, &filename);
if ( rval == 1 ) break;
- add_to_mean(cell, &as, &bs, &cs, &als, &bes, &gas);
if ( config_basename ) {
char *tmp;
tmp = basename(filename);
@@ -368,8 +257,6 @@ int main(int argc, char *argv[])
pargs->cell = cell;
free(filename);
- n_images++;
-
pthread_mutex_lock(&pargs->control_mutex);
pargs->done = 0;
pargs->start = 1;
@@ -414,7 +301,6 @@ int main(int argc, char *argv[])
/* Get the next filename */
rval = find_chunk(fh, &cell, &filename);
if ( rval == 1 ) break;
- add_to_mean(cell, &as, &bs, &cs, &als, &bes, &gas);
if ( config_basename ) {
char *tmp;
tmp = basename(filename);
@@ -426,10 +312,6 @@ int main(int argc, char *argv[])
pargs->cell = cell;
free(filename);
- n_images++;
-
- STATUS("Done %i images\n", n_images);
-
/* Wake the thread up ... */
pthread_mutex_lock(&pargs->control_mutex);
pargs->done = 0;
@@ -460,10 +342,104 @@ int main(int argc, char *argv[])
}
}
+}
- fclose(fh);
- STATUS("There were %i images.\n", n_images);
+int main(int argc, char *argv[])
+{
+ int c;
+ char *infile = NULL;
+ char *geomfile = NULL;
+ FILE *fh;
+ char *prefix = NULL;
+ int nthreads = 1;
+ int config_basename = 0;
+ int config_checkprefix = 1;
+ struct detector *det;
+ char *sym = NULL;
+
+ /* 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:x:j:",
+ longopts, NULL)) != -1) {
+
+ switch (c) {
+ case 'h' :
+ show_help(argv[0]);
+ return 0;
+
+ case 'i' :
+ infile = strdup(optarg);
+ break;
+
+ case 'g' :
+ geomfile = strdup(optarg);
+ break;
+
+ case 'x' :
+ prefix = strdup(optarg);
+ break;
+
+ case 'j' :
+ nthreads = atoi(optarg);
+ break;
+
+ case 0 :
+ break;
+
+ default :
+ return 1;
+ }
+
+ }
+
+ if ( infile == NULL ) {
+ infile = strdup("-");
+ }
+ if ( strcmp(infile, "-") == 0 ) {
+ fh = stdin;
+ } else {
+ fh = fopen(infile, "r");
+ }
+ if ( fh == NULL ) {
+ ERROR("Failed to open input file '%s'\n", infile);
+ return 1;
+ }
+ free(infile);
+
+ if ( prefix == NULL ) {
+ prefix = strdup("");
+ } else {
+ if ( config_checkprefix ) {
+ prefix = check_prefix(prefix);
+ }
+ }
+
+ det = get_detector_geometry(geomfile);
+ if ( det == NULL ) {
+ ERROR("Failed to read detector geometry from '%s'\n", geomfile);
+ return 1;
+ }
+ free(geomfile);
+
+ sym = strdup("6/mmm"); /* FIXME: Should be on command line */
+
+ rewind(fh);
+ optimise_all(nthreads, det, sym, fh, config_basename, prefix);
+
+ fclose(fh);
+ free(sym);
+ free(prefix);
return 0;
}