From da5e9537d64b58e502cfdfcfbfdc161383d33bc8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 1 Mar 2021 15:28:45 +0100 Subject: Local BE: Write a script and run it This easily gives us the stdout.log and stderr.log needed for monitoring the job. --- src/gui_backend_local.c | 65 ++++++++++++++++++++++++++++--------------------- src/gui_index.c | 39 +++++++++++++++++++++++++++++ src/gui_index.h | 8 ++++++ 3 files changed, 84 insertions(+), 28 deletions(-) diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c index 3cb24e27..f1778c43 100644 --- a/src/gui_backend_local.c +++ b/src/gui_backend_local.c @@ -499,10 +499,10 @@ static void *run_indexing(const char *job_title, struct local_indexing_opts *opts = opts_priv; struct local_job *job; char n_thread_str[64]; - char **args; char **streams; - int i; GFile *workdir; + GFile *sc_gfile; + gchar *sc_filename; GFile *stderr_gfile; workdir = make_job_folder(job_title, job_notes); @@ -518,37 +518,46 @@ static void *run_indexing(const char *job_title, } snprintf(n_thread_str, 63, "%i", opts->n_processes); - args = indexamajig_command_line(proj->geom_filename, - n_thread_str, - "files.lst", - "crystfel.stream", - &proj->peak_search_params, - &proj->indexing_params); - - i = 0; - while ( args[i] != NULL ) { - STATUS("%s ", args[i++]); + sc_gfile = g_file_get_child(workdir, "run_indexamajig.sh"); + sc_filename = g_file_get_path(sc_gfile); + g_object_unref(sc_gfile); + if ( sc_filename == NULL ) return NULL; + if ( !write_indexamajig_script(sc_filename, + proj->geom_filename, + n_thread_str, + "files.lst", + "crystfel.stream", + &proj->peak_search_params, + &proj->indexing_params) ) + { + char *args[3]; + args[0] = "sh"; + args[1] = sc_filename; + args[2] = NULL; + job = start_local_job(args, job_title, workdir, + proj, GUI_JOB_INDEXING); + } else { + job = NULL; } - STATUS("\n"); - job = start_local_job(args, job_title, workdir, proj, GUI_JOB_INDEXING); - if ( job == NULL ) return NULL; + if ( job != NULL ) { - /* Indexing-specific job data */ - job->n_frames = proj->n_frames; + /* Indexing-specific job data */ + job->n_frames = proj->n_frames; - stderr_gfile = g_file_get_child(workdir, "stderr.log"); - job->stderr_filename = g_file_get_path(stderr_gfile); - g_object_unref(stderr_gfile); + stderr_gfile = g_file_get_child(workdir, "stderr.log"); + job->stderr_filename = g_file_get_path(stderr_gfile); + g_object_unref(stderr_gfile); - streams = malloc(sizeof(char *)); - if ( streams != NULL ) { - GFile *stream_gfile = g_file_get_child(job->workdir, - "crystfel.stream"); - streams[0] = g_file_get_path(stream_gfile); - g_object_unref(stream_gfile); - add_indexing_result(proj, strdup(job_title), - streams, 1); + streams = malloc(sizeof(char *)); + if ( streams != NULL ) { + GFile *stream_gfile = g_file_get_child(job->workdir, + "crystfel.stream"); + streams[0] = g_file_get_path(stream_gfile); + g_object_unref(stream_gfile); + add_indexing_result(proj, strdup(job_title), + streams, 1); + } } return job; diff --git a/src/gui_index.c b/src/gui_index.c index 75bc233f..4862ab72 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -815,3 +815,42 @@ int read_number_processed(const char *filename) return n_proc; } + + +int write_indexamajig_script(const char *script_filename, + const char *geom_filename, + const char *n_thread_str, + const char *files_list, + const char *stream_filename, + struct peak_params *peak_search_params, + struct index_params *indexing_params) +{ + FILE *fh; + int i; + char **cmdline; + + cmdline = indexamajig_command_line(geom_filename, + n_thread_str, + files_list, + stream_filename, + peak_search_params, + indexing_params); + if ( cmdline == NULL ) return 1; + + fh = fopen(script_filename, "w"); + if ( fh == NULL ) return 1; + + fprintf(fh, "#!/bin/sh\n"); + + i = 0; + while ( cmdline[i] != NULL ) { + fprintf(fh, "%s ", cmdline[i]); + free(cmdline[i]); + i++; + }; + free(cmdline); + fprintf(fh, ">stdout.log 2>stderr.log\n"); + + fclose(fh); + return 0; +} diff --git a/src/gui_index.h b/src/gui_index.h index 7b2c6e19..4a1ef1e9 100644 --- a/src/gui_index.h +++ b/src/gui_index.h @@ -50,4 +50,12 @@ extern char **indexamajig_command_line(const char *geom_filename, extern int read_number_processed(const char *filename); +extern int write_indexamajig_script(const char *script_filename, + const char *geom_filename, + const char *n_thread_str, + const char *files_list, + const char *stream_filename, + struct peak_params *peak_search_params, + struct index_params *indexing_params); + #endif -- cgit v1.2.3