From dcdce375c16c709161d57cbae551feb7b842db34 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Mar 2021 12:00:22 +0100 Subject: FromFile indexer: Option processing This give FromFile its own private command-lien option processing, like the other indexers. It removes the ability to auto-generate the solution filename, but I don't think there's a way to do that without breaking abstractions. --- libcrystfel/src/index.c | 12 +++-- libcrystfel/src/index.h | 7 ++- libcrystfel/src/indexers/fromfile.c | 96 ++++++++++++++++++++++++++++++------- libcrystfel/src/indexers/fromfile.h | 18 ++----- src/gui_index.c | 4 +- src/indexamajig.c | 7 ++- 6 files changed, 104 insertions(+), 40 deletions(-) diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index f9001968..0ce9e2a2 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -208,7 +208,7 @@ static void *prepare_method(IndexingMethod *m, UnitCell *cell, struct pinkIndexer_options* pinkIndexer_opts, struct felix_options *felix_opts, struct taketwo_options *taketwo_opts, - char *filename) + struct fromfile_options *fromfile_opts) { char *str; IndexingMethod in = *m; @@ -237,7 +237,7 @@ static void *prepare_method(IndexingMethod *m, UnitCell *cell, break; case INDEXING_FILE : - priv = fromfile_prepare(filename, cell); + priv = fromfile_prepare(m, fromfile_opts); break; case INDEXING_FELIX : @@ -336,7 +336,7 @@ IndexingPrivate *setup_indexing(const char *method_list, struct xgandalf_options *xgandalf_opts, struct pinkIndexer_options *pinkIndexer_opts, struct felix_options *felix_opts, - char *filename) + struct fromfile_options *fromfile_opts) { IndexingPrivate *ipriv; IndexingMethod *methods; @@ -406,7 +406,7 @@ IndexingPrivate *setup_indexing(const char *method_list, pinkIndexer_opts, felix_opts, ttopts, - filename); + fromfile_opts); if ( ipriv->engine_private[i] == NULL ) return NULL; @@ -1213,10 +1213,12 @@ char *detect_indexing_methods(UnitCell *cell) void default_method_options(TakeTwoOptions **ttopts, XGandalfOptions **xgandalf_opts, PinkIndexerOptions **pinkIndexer_opts, - FelixOptions **felix_opts) + FelixOptions **felix_opts, + FromFileOptions **fromfile_opts) { taketwo_default_options(ttopts); xgandalf_default_options(xgandalf_opts); pinkIndexer_default_options(pinkIndexer_opts); felix_default_options(felix_opts); + fromfile_default_options(fromfile_opts); } diff --git a/libcrystfel/src/index.h b/libcrystfel/src/index.h index 5cee29b2..88b9b67e 100644 --- a/libcrystfel/src/index.h +++ b/libcrystfel/src/index.h @@ -152,16 +152,19 @@ typedef struct felix_options FelixOptions; typedef struct taketwo_options TakeTwoOptions; typedef struct xgandalf_options XGandalfOptions; typedef struct pinkIndexer_options PinkIndexerOptions; +typedef struct fromfile_options FromFileOptions; extern struct argp felix_argp; extern struct argp pinkIndexer_argp; extern struct argp taketwo_argp; extern struct argp xgandalf_argp; +extern struct argp fromfile_argp; extern void default_method_options(TakeTwoOptions **ttopts, XGandalfOptions **xgandalf_opts, PinkIndexerOptions **pinkIndexer_opts, - FelixOptions **felix_opts); + FelixOptions **felix_opts, + FromFileOptions **fromfile_opts); extern IndexingPrivate *setup_indexing(const char *methods, UnitCell *cell, @@ -173,7 +176,7 @@ extern IndexingPrivate *setup_indexing(const char *methods, struct xgandalf_options *xgandalf_opts, struct pinkIndexer_options *pinkIndexer_opts, struct felix_options *felix_opts, - char *filename); + struct fromfile_options *fromfile_opts); extern const IndexingMethod *indexing_methods(IndexingPrivate *p, int *n); diff --git a/libcrystfel/src/indexers/fromfile.c b/libcrystfel/src/indexers/fromfile.c index 73cee547..400683ae 100644 --- a/libcrystfel/src/indexers/fromfile.c +++ b/libcrystfel/src/indexers/fromfile.c @@ -5,6 +5,7 @@ * * Authors: * 2020 Pascal Hogan-Lamarre + * 2021 Thomas White * * This file is part of CrystFEL. * @@ -30,6 +31,7 @@ #include #include #include +#include #include "image.h" #include "uthash.h" @@ -45,6 +47,12 @@ #define NKEYS_PER_LINE 2 +struct fromfile_options +{ + char *filename; +}; + + struct fromfile_keys { char filename[100]; @@ -162,7 +170,7 @@ char *read_unknown_string(FILE *fh) } -void *fromfile_prepare(char *solution_filename, UnitCell *cell) +void *fromfile_prepare(IndexingMethod *indm, struct fromfile_options *opts) { FILE *fh; int nlines; @@ -177,27 +185,15 @@ void *fromfile_prepare(char *solution_filename, UnitCell *cell) struct fromfile_entries *item = NULL; float params[NPARAMS_PER_LINE]; - /* Assembling solution file name from input file name*/ - char *path_to_sol; - size_t path_len; - char *core_name = strtok(solution_filename, "."); - char *extension = ".sol"; - path_len = sizeof(core_name) + sizeof(extension) + sizeof("../"); - path_to_sol = realloc(NULL, sizeof(char)*path_len); - strcpy(path_to_sol, "../"); - strcat(path_to_sol, core_name); - strcat(path_to_sol, extension); - - fh = fopen(path_to_sol, "r"); - + fh = fopen(opts->filename, "r"); if ( fh == NULL ) { - ERROR("%s not found by fromfile_prepare\n", path_to_sol); - return 0; + ERROR("%s not found by fromfile_prepare\n", opts->filename); + return NULL; } else { - STATUS("Found solution file %s\n", path_to_sol); + STATUS("Found solution file %s\n", opts->filename); } - nlines = ncrystals_in_sol(path_to_sol); + nlines = ncrystals_in_sol(opts->filename); /* Total crystal parameters in solution file */ nparams_in_solution = nlines*NPARAMS_PER_LINE; /* Total entries in solution file */ @@ -375,3 +371,67 @@ void fromfile_cleanup(void *mpriv) free(dp); } + + +static void fromfile_show_help() +{ + printf("Parameters for 'fromfile' indexing:\n" +" --fromfile-input-file\n" +" Filename of indexing solution file\n" +); +} + + +int fromfile_default_options(FromFileOptions **opts_ptr) +{ + FromFileOptions *opts; + opts = malloc(sizeof(struct fromfile_options)); + if ( opts == NULL ) return ENOMEM; + opts->filename = NULL; + *opts_ptr = opts; + return 0; +} + + +static error_t fromfile_parse_arg(int key, char *arg, + struct argp_state *state) +{ + struct fromfile_options **opts_ptr = state->input; + int r; + + switch ( key ) { + + case ARGP_KEY_INIT : + r = fromfile_default_options(opts_ptr); + if ( r ) return r; + break; + + case 1 : + fromfile_show_help(); + return EINVAL; + + case 2 : + (*opts_ptr)->filename = strdup(arg); + break; + + default : + return ARGP_ERR_UNKNOWN; + + } + + return 0; +} + + +static struct argp_option fromfile_options[] = { + + {"help-fromfile", 1, NULL, OPTION_NO_USAGE, + "Show options for 'from file' indexing", 99}, + + {"fromfile-input-file", 2, "filename", OPTION_HIDDEN, NULL}, + {0} +}; + + +struct argp fromfile_argp = { fromfile_options, fromfile_parse_arg, + NULL, NULL, NULL, NULL, NULL }; diff --git a/libcrystfel/src/indexers/fromfile.h b/libcrystfel/src/indexers/fromfile.h index deb7b105..ba7e1ee4 100644 --- a/libcrystfel/src/indexers/fromfile.h +++ b/libcrystfel/src/indexers/fromfile.h @@ -5,6 +5,7 @@ * * Authors: * 2020 Pascal Hogan-Lamarre + * 2021 Thomas White * * This file is part of CrystFEL. * @@ -26,23 +27,14 @@ #ifndef FROMFILE_H #define FROMFILE_H -struct fromfile_keys; -struct fromfile_entries; -struct fromfile_private; +#include #include "image.h" -#include "cell.h" -#include "uthash.h" - -extern void print_struct(struct fromfile_entries *sol_hash); - -extern void full_print_struct(struct fromfile_entries *sol_hash); - -extern void *fromfile_prepare(char *solution_filename, UnitCell *cell); +extern int fromfile_default_options(FromFileOptions **opts_ptr); +extern void *fromfile_prepare(IndexingMethod *indm, + struct fromfile_options *opts); extern int fromfile_index(struct image *image, void *mpriv, int crystal_number); - extern void fromfile_cleanup(void *mpriv); - #endif /* FROMFILE_H */ diff --git a/src/gui_index.c b/src/gui_index.c index 85a9f9c3..145d0f1e 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -486,6 +486,7 @@ static void run_indexing_once(struct crystfelproject *proj) XGandalfOptions *xgandalf_opts; PinkIndexerOptions *pinkIndexer_opts; FelixOptions *felix_opts; + FromFileOptions *fromfile_opts; char *old_cwd; char *tmpdir; int r; @@ -514,7 +515,8 @@ static void run_indexing_once(struct crystfelproject *proj) default_method_options(&taketwoopts, &xgandalf_opts, &pinkIndexer_opts, - &felix_opts); + &felix_opts, + &fromfile_opts); ipriv = setup_indexing(methods, cell, proj->indexing_params.tols, diff --git a/src/indexamajig.c b/src/indexamajig.c index 7f73cef6..d5d3d31a 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -97,6 +97,7 @@ struct indexamajig_arguments FelixOptions **felix_opts_ptr; XGandalfOptions **xgandalf_opts_ptr; PinkIndexerOptions **pinkindexer_opts_ptr; + FromFileOptions **fromfile_opts_ptr; }; @@ -135,6 +136,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) state->child_inputs[1] = args->felix_opts_ptr; state->child_inputs[2] = args->xgandalf_opts_ptr; state->child_inputs[3] = args->pinkindexer_opts_ptr; + state->child_inputs[4] = args->fromfile_opts_ptr; break; case 'h' : @@ -601,6 +603,7 @@ int main(int argc, char *argv[]) FelixOptions *felix_opts = NULL; XGandalfOptions *xgandalf_opts = NULL; PinkIndexerOptions *pinkindexer_opts = NULL; + FromFileOptions *fromfile_opts = NULL; double wl_from_dt; /* Defaults for "top level" arguments */ @@ -628,6 +631,7 @@ int main(int argc, char *argv[]) args.felix_opts_ptr = &felix_opts; args.xgandalf_opts_ptr = &xgandalf_opts; args.pinkindexer_opts_ptr = &pinkindexer_opts; + args.fromfile_opts_ptr = &fromfile_opts; /* Defaults for process_image arguments */ args.iargs.cell = NULL; @@ -818,6 +822,7 @@ int main(int argc, char *argv[]) {&felix_argp, 0, NULL, -2}, {&xgandalf_argp, 0, NULL, -2}, {&pinkIndexer_argp, 0, NULL, -2}, + {&fromfile_argp, 0, NULL, -2}, {0} }; @@ -996,7 +1001,7 @@ int main(int argc, char *argv[]) xgandalf_opts, pinkindexer_opts, felix_opts, - args.filename); + fromfile_opts); free(args.filename); -- cgit v1.2.3