From a3502ba4676583980286468391295ec4d80c28ca Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Feb 2021 10:15:28 +0100 Subject: GUI: Actually run ambigator (local backend only) --- src/gui_ambi.c | 28 ++++++++++++++++++++++++---- src/gui_backend_local.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gui_ambi.c b/src/gui_ambi.c index 8d315b00..38df49c9 100644 --- a/src/gui_ambi.c +++ b/src/gui_ambi.c @@ -136,6 +136,13 @@ static void ambi_response_sig(GtkWidget *dialog, gint resp, win->proj->ambi_params.operator = get_str(win->operator); win->proj->ambi_params.use_operator = get_bool(win->use_operator); + /* "Minimum resolution" should be the bigger number */ + if ( win->proj->ambi_params.res_min < win->proj->ambi_params.res_max ) { + double tmp = win->proj->ambi_params.res_min; + win->proj->ambi_params.res_min = win->proj->ambi_params.res_max; + win->proj->ambi_params.res_max = tmp; + } + backend_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(win->backend_combo)); if ( backend_idx < 0 ) return; @@ -472,19 +479,32 @@ int write_ambigator_script(const char *filename, for ( i=0; in_streams; i++ ) { fprintf(fh, "%s \\\n", input->streams[i]); } + fprintf(fh, " > ambigator-input.stream\n"); exe_path = get_crystfel_exe("ambigator"); if ( exe_path == NULL ) return 1; - fprintf(fh, "| %s - \\\n", exe_path); + fprintf(fh, "%s ambigator-input.stream \\\n", exe_path); fprintf(fh, " -j %s", n_thread_str); fprintf(fh, " -o %s", out_stream); fprintf(fh, " -y %s", params->sym); -// if ( params->source_sym != NULL ) { -// fprintf(fh, " -w %s", params->source_sym); -// } + if ( params->use_operator ) { + fprintf(fh, " --operator=%s", params->operator); + } else { + fprintf(fh, " -w %s", params->source_sym); + } + + if ( params->use_res ) { + fprintf(fh, " --lowres=%f", params->res_min); + fprintf(fh, " --highres=%f", params->res_max); + } + + if ( params->use_ncorr ) { + fprintf(fh, " --ncorr=%i", params->ncorr); + } fprintf(fh, " --iterations=%i", params->niter); + fprintf(fh, " --fg-graph=fg.dat\n"); fclose(fh); return 0; diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c index 21d12aad..26eda1ed 100644 --- a/src/gui_backend_local.c +++ b/src/gui_backend_local.c @@ -458,7 +458,29 @@ static gboolean merge_readable(GIOChannel *source, GIOCondition cond, static gboolean ambi_readable(GIOChannel *source, GIOCondition cond, void *vp) { - /* FIXME: Implementation */ + GIOStatus r; + GError *err = NULL; + struct local_job *job = vp; + gchar *line; + + r = g_io_channel_read_line(source, &line, NULL, NULL, &err); + if ( r == G_IO_STATUS_EOF ) { + STATUS("End of output.\n"); + return FALSE; + } + if ( r != G_IO_STATUS_NORMAL ) { + if ( job->pid != 0 ) { + STATUS("Read error?\n"); + } else { + STATUS("End of output (merge exited)\n"); + } + return FALSE; + } + + /* FIXME: Calculate the fraction complete */ + job->frac_complete = 0.5; + + g_free(line); return TRUE; } @@ -486,16 +508,17 @@ static void *run_ambi(const char *job_title, g_object_unref(stream_gfile); snprintf(n_thread_str, 64, "%i", opts->n_threads); - sc_gfile = g_file_get_child(workdir, "run_merge.sh"); + sc_gfile = g_file_get_child(workdir, "run_ambigator.sh"); sc_filename = g_file_get_path(sc_gfile); g_object_unref(sc_gfile); if ( sc_filename == NULL ) return NULL; if ( !write_ambigator_script(sc_filename, input, n_thread_str, &proj->ambi_params, stream_str) ) { - char *args[2]; - args[0] = "run_ambigator.sh"; - args[1] = NULL; + char *args[3]; + args[0] = "sh"; + args[1] = sc_filename; + args[2] = NULL; job = start_local_job(args, job_title, workdir, proj, ambi_readable); } else { -- cgit v1.2.3