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/indexers/fromfile.c | 96 ++++++++++++++++++++++++++++++------- libcrystfel/src/indexers/fromfile.h | 18 ++----- 2 files changed, 83 insertions(+), 31 deletions(-) (limited to 'libcrystfel/src/indexers') 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 */ -- cgit v1.2.3