diff options
-rw-r--r-- | src/gui_backend_local.c | 29 | ||||
-rw-r--r-- | src/gui_backend_slurm.c | 18 | ||||
-rw-r--r-- | src/gui_import.c | 13 | ||||
-rw-r--r-- | src/gui_project.c | 59 | ||||
-rw-r--r-- | src/gui_project.h | 6 |
5 files changed, 79 insertions, 46 deletions
diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c index 0afa894b..97bb9d7a 100644 --- a/src/gui_backend_local.c +++ b/src/gui_backend_local.c @@ -419,11 +419,7 @@ static void *run_ambi(const char *job_title, } if ( job != NULL ) { - char **streams = malloc(sizeof(char *)); - if ( streams != NULL ) { - streams[0] = stream_str; - add_indexing_result(proj, strdup(job_title), streams, 1); - } + add_indexing_result(proj, job_title, &stream_str, 1); } g_object_unref(workdir); @@ -495,7 +491,10 @@ static void *run_merging(const char *job_title, hkl2 = g_file_get_path(hkl_gfile); g_object_unref(hkl_gfile); - add_merge_result(proj, strdup(job_title), hkl, hkl1, hkl2); + add_merge_result(proj, job_title, hkl, hkl1, hkl2); + g_free(hkl); + g_free(hkl1); + g_free(hkl2); } g_object_unref(workdir); @@ -511,7 +510,6 @@ 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 **streams; GFile *workdir; GFile *sc_gfile; gchar *sc_filename; @@ -555,6 +553,8 @@ static void *run_indexing(const char *job_title, if ( job != NULL ) { + char *stream_fn; + /* Indexing-specific job data */ job->n_frames = proj->n_frames; @@ -562,15 +562,12 @@ static void *run_indexing(const char *job_title, 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); - } + GFile *stream_gfile = g_file_get_child(job->workdir, + "crystfel.stream"); + stream_fn = g_file_get_path(stream_gfile); + g_object_unref(stream_gfile); + add_indexing_result(proj, job_title, &stream_fn, 1); + g_free(stream_fn); } g_object_unref(workdir); diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c index 1da344ce..173ee65e 100644 --- a/src/gui_backend_slurm.c +++ b/src/gui_backend_slurm.c @@ -662,9 +662,14 @@ static void *run_indexing(const char *job_title, if ( job != NULL ) { job->n_frames = proj->n_frames; job->n_blocks = n_blocks; - add_indexing_result(proj, strdup(job_title), streams, n_blocks); + add_indexing_result(proj, job_title, streams, n_blocks); } + for ( i=0; i<n_blocks; i++ ) { + free(streams[i]); + } + free(streams); + g_object_unref(workdir); return job; @@ -871,11 +876,7 @@ static void *run_ambi(const char *job_title, g_free(sc_filename); if ( job != NULL ) { - char **streams = malloc(sizeof(char *)); - if ( streams != NULL ) { - streams[0] = stream_str; - add_indexing_result(proj, strdup(job_title), streams, 1); - } + add_indexing_result(proj, job_title, &stream_str, 1); } g_object_unref(workdir); @@ -943,7 +944,10 @@ static void *run_merging(const char *job_title, hkl2 = g_file_get_path(hkl_gfile); g_object_unref(hkl_gfile); - add_merge_result(proj, strdup(job_title), hkl, hkl1, hkl2); + add_merge_result(proj, job_title, hkl, hkl1, hkl2); + g_free(hkl); + g_free(hkl1); + g_free(hkl2); } g_object_unref(workdir); diff --git a/src/gui_import.c b/src/gui_import.c index 4328cacf..3e432075 100644 --- a/src/gui_import.c +++ b/src/gui_import.c @@ -249,7 +249,7 @@ int load_stream(struct crystfelproject *proj, char *stream_filename) Stream *st; DataTemplate *dtempl; const char *geom_str; - char **streams; + char *result_name; st = stream_open_for_read(stream_filename); if ( st == NULL ) return 1; @@ -280,13 +280,10 @@ int load_stream(struct crystfelproject *proj, char *stream_filename) proj->stream_filename = stream_filename; stream_close(st); - streams = malloc(sizeof(char *)); - if ( streams != NULL ) { - char *result_name = safe_basename(stream_filename); - streams[0] = strdup(stream_filename); - add_indexing_result(proj, result_name, streams, 1); - select_result(proj, result_name); - } + result_name = safe_basename(stream_filename); + add_indexing_result(proj, result_name, &stream_filename, 1); + select_result(proj, result_name); + free(result_name); return 0; } diff --git a/src/gui_project.c b/src/gui_project.c index f2efc71b..614a7a31 100644 --- a/src/gui_project.c +++ b/src/gui_project.c @@ -681,11 +681,11 @@ static void read_parameters(FILE *fh, struct crystfelproject *proj) static void add_result(struct crystfelproject *proj, - char *results_name, + const char *results_name, char **streams, int n_streams, int selected, - char *hkl, char *hkl1, char *hkl2) + const char *hkl, const char *hkl1, const char *hkl2) { if ( (n_streams > 0) && (hkl == NULL) ) { add_indexing_result(proj, results_name, @@ -730,6 +730,8 @@ static void read_results(FILE *fh, struct crystfelproject *proj) if ( strncmp(line, "Result ", 7) == 0 ) { + int i; + if ( !first ) { add_result(proj, results_name, streams, n_streams, selected, @@ -737,6 +739,15 @@ static void read_results(FILE *fh, struct crystfelproject *proj) } first = 0; + free(hkl); + free(hkl1); + free(hkl2); + for ( i=0; i<n_streams; i++ ) { + free(streams[i]); + } + free(streams); + free(results_name); + n_streams = 0; selected = 0; streams = NULL; @@ -771,9 +782,18 @@ static void read_results(FILE *fh, struct crystfelproject *proj) if ( strcmp(line, "-----") == 0 ) { if ( !first ) { + int i; add_result(proj, results_name, streams, n_streams, selected, hkl, hkl1, hkl2); + free(hkl); + free(hkl1); + free(hkl2); + for ( i=0; i<n_streams; i++ ) { + free(streams[i]); + } + free(streams); + free(results_name); } break; } @@ -1236,9 +1256,23 @@ int default_project(struct crystfelproject *proj) } -/* Assumes ownership of "name" and "streams" */ +static char *relative_path(struct crystfelproject *proj, const char *fn) +{ + GFile *pwd = g_file_new_for_path("."); + GFile *fn_gfile = g_file_new_for_path(fn); + char *rel = g_file_get_relative_path(pwd, fn_gfile); + if ( rel == NULL ) { + ERROR("Can't make relative path for '%s'\n", fn); + return NULL; + } + g_object_unref(pwd); + g_object_unref(fn_gfile); + return rel; +} + + int add_indexing_result(struct crystfelproject *proj, - char *name, + const char *name, char **streams, int n_streams) { @@ -1249,13 +1283,14 @@ int add_indexing_result(struct crystfelproject *proj, (proj->n_results+1)*sizeof(struct gui_indexing_result)); if ( new_results == NULL ) return 1; - new_results[proj->n_results].name = name; - new_results[proj->n_results].streams = streams; + new_results[proj->n_results].name = strdup(name); + new_results[proj->n_results].streams = malloc(n_streams*sizeof(char *)); new_results[proj->n_results].n_streams = n_streams; new_results[proj->n_results].indices = malloc(n_streams*sizeof(StreamIndex *)); for ( i=0; i<n_streams; i++ ) { new_results[proj->n_results].indices[i] = NULL; + new_results[proj->n_results].streams[i] = relative_path(proj, streams[i]); } proj->results = new_results; @@ -1268,8 +1303,8 @@ int add_indexing_result(struct crystfelproject *proj, } -int add_merge_result(struct crystfelproject *proj, char *name, - char *hkl, char *hkl1, char *hkl2) +int add_merge_result(struct crystfelproject *proj, const char *name, + const char *hkl, const char *hkl1, const char *hkl2) { struct gui_merge_result *new_results; @@ -1277,10 +1312,10 @@ int add_merge_result(struct crystfelproject *proj, char *name, (proj->n_merge_results+1)*sizeof(struct gui_merge_result)); if ( new_results == NULL ) return 1; - new_results[proj->n_merge_results].name = name; - new_results[proj->n_merge_results].hkl = hkl; - new_results[proj->n_merge_results].hkl1 = hkl1; - new_results[proj->n_merge_results].hkl2 = hkl2; + new_results[proj->n_merge_results].name = strdup(name); + new_results[proj->n_merge_results].hkl = relative_path(proj, hkl); + new_results[proj->n_merge_results].hkl1 = relative_path(proj, hkl1); + new_results[proj->n_merge_results].hkl2 = relative_path(proj, hkl2); proj->merge_results = new_results; proj->n_merge_results++; diff --git a/src/gui_project.h b/src/gui_project.h index 2617c2d8..183c9e75 100644 --- a/src/gui_project.h +++ b/src/gui_project.h @@ -355,7 +355,7 @@ extern void clear_project_files(struct crystfelproject *proj); extern void clear_indexing_results(struct crystfelproject *proj); extern int add_indexing_result(struct crystfelproject *proj, - char *name, + const char *name, char **streams, int n_streams); @@ -370,8 +370,8 @@ extern void update_result_index(struct gui_indexing_result *result); extern struct gui_indexing_result *find_indexing_result_by_name(struct crystfelproject *proj, const char *name); -extern int add_merge_result(struct crystfelproject *proj, char *name, - char *hkl, char *hkl1, char *hkl2); +extern int add_merge_result(struct crystfelproject *proj, const char *name, + const char *hkl, const char *hkl1, const char *hkl2); extern struct gui_merge_result *find_merge_result_by_name(struct crystfelproject *proj, const char *name); |