diff options
author | Thomas White <taw@bitwiz.org.uk> | 2010-09-20 14:53:18 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:26:59 +0100 |
commit | 909ed05f196a52b84f254b102dc15e38dee0500a (patch) | |
tree | 78df5952627679be16d32bd551ce7ff7ea7e1174 | |
parent | fc64b1074c476a60d9e1745523d1ae7a7478bb9c (diff) |
facetron: Split out core work
-rw-r--r-- | src/facetron.c | 224 |
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; } |