From 9a5b52cd6cbc9ed9bb391a71c3eb724bd19322f0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 30 Nov 2020 17:29:52 +0100 Subject: Add merging_command_line() --- src/gui_merge.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui_merge.h | 4 ++ 2 files changed, 172 insertions(+) (limited to 'src') diff --git a/src/gui_merge.c b/src/gui_merge.c index 6d0afe35..95444880 100644 --- a/src/gui_merge.c +++ b/src/gui_merge.c @@ -360,3 +360,171 @@ gint merge_sig(GtkWidget *widget, struct crystfelproject *proj) return FALSE; } + + +static GSList *append_arg_str(GSList *args, + const char *label, + const char *val) +{ + size_t len; + char *str; + + len = strlen(label)+strlen(val)+4; + str = malloc(len); + if ( str == NULL ) return args; + snprintf(str, 63, "--%s=%s", label, val); + + return g_slist_append(args, str); +} + + +static GSList *append_arg_int(GSList *args, + const char *label, + int val) +{ + char *str = malloc(64); + if ( str == NULL ) return args; + snprintf(str, 63, "--%s=%i", label, val); + return g_slist_append(args, str); +} + + +static GSList *append_arg_float(GSList *args, + const char *label, + float val) +{ + char *str = malloc(64); + if ( str == NULL ) return args; + snprintf(str, 63, "--%s=%f", label, val); + return g_slist_append(args, str); +} + + +static GSList *process_hkl_command_line(struct gui_result *input, + struct merging_params *params) +{ + GSList *args = NULL; + char *exe_path; + + exe_path = get_crystfel_exe("process_hkl"); + if ( exe_path == NULL ) return NULL; + args = g_slist_append(args, exe_path); + + /* FIXME: For each stream */ + args = append_arg_str(args, "input", input->streams[0]); + + args = append_arg_str(args, "symmetry", params->symmetry); + + if ( params->scale ) { + args = g_slist_append(args, strdup("--scale")); + } + + args = append_arg_str(args, "polarisation", + params->polarisation); + + args = append_arg_int(args, "min-measurements", + params->min_measurements); + + args = append_arg_float(args, "max-adu", params->max_adu); + + args = append_arg_float(args, "min-res", params->min_res); + + args = append_arg_float(args, "push-res", params->push_res); + + return args; +} + + +static GSList *partialator_command_line(const char *n_thread_str, + struct gui_result *input, + struct merging_params *params) +{ + GSList *args = NULL; + char *exe_path; + + exe_path = get_crystfel_exe("partialator"); + if ( exe_path == NULL ) return NULL; + args = g_slist_append(args, exe_path); + + /* FIXME: For each stream */ + args = append_arg_str(args, "input", input->streams[0]); + + args = append_arg_str(args, "symmetry", params->symmetry); + + if ( params->twin_sym != NULL ) { + args = g_slist_append(args, "-w"); + args = g_slist_append(args, strdup(params->twin_sym)); + } + + if ( params->custom_split != NULL ) { + args = append_arg_str(args, "custom-split", + params->custom_split); + } + + if ( !params->scale ) { + args = g_slist_append(args, "--no-scale"); + } + + if ( !params->bscale ) { + args = g_slist_append(args, "--no-bscale"); + } + + if ( !params->postref ) { + args = g_slist_append(args, "--no-pr"); + } + + if ( !params->deltacchalf ) { + args = g_slist_append(args, "no-deltacchalf"); + } + + args = append_arg_int(args, "iterations", params->niter); + + args = append_arg_str(args, "polarisation", + params->polarisation); + + args = append_arg_int(args, "min-measurements", + params->min_measurements); + + args = append_arg_float(args, "max-adu", params->max_adu); + + args = append_arg_float(args, "min-res", params->min_res); + + args = append_arg_float(args, "push-res", params->push_res); + + return args; +} + + +char **merging_command_line(const char *n_thread_str, + struct gui_result *input, + struct merging_params *params) +{ + GSList *args; + char **arg_strings; + GSList *args2; + int i, n; + + if ( strcmp(params->model, "process_hkl") == 0 ) { + args = process_hkl_command_line(input, params); + } else { + args = partialator_command_line(n_thread_str, + input, + params); + } + + if ( args == NULL ) return NULL; + + n = g_slist_length(args); + arg_strings = malloc((n+1)*sizeof(char *)); + if ( arg_strings == NULL ) return NULL; + + args2 = args; + for ( i=0; idata; + args2 = args2->next; + } + arg_strings[n] = NULL; + g_slist_free(args); + + return arg_strings; +} diff --git a/src/gui_merge.h b/src/gui_merge.h index 6d8b6a50..474eccc1 100644 --- a/src/gui_merge.h +++ b/src/gui_merge.h @@ -36,4 +36,8 @@ extern gint merge_sig(GtkWidget *widget, struct crystfelproject *proj); +extern char **merging_command_line(const char *n_thread_str, + struct gui_result *input, + struct merging_params *params); + #endif -- cgit v1.2.3