diff options
author | Thomas White <taw@physics.org> | 2021-03-01 15:28:45 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-03-01 15:28:45 +0100 |
commit | da5e9537d64b58e502cfdfcfbfdc161383d33bc8 (patch) | |
tree | 2f364ea3d18a81c80d6e0e495a3e703b1ea20813 | |
parent | 04f7ec271ce14ab23b38ff005d9fbb61c4f9f6a5 (diff) |
Local BE: Write a script and run it
This easily gives us the stdout.log and stderr.log needed for monitoring
the job.
-rw-r--r-- | src/gui_backend_local.c | 65 | ||||
-rw-r--r-- | src/gui_index.c | 39 | ||||
-rw-r--r-- | 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 |