aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-09-02 15:41:23 +0200
committerThomas White <taw@physics.org>2020-09-02 15:41:23 +0200
commit7ced186f57f39e0edfa245408bc22c348108367e (patch)
tree54dff9e22bfb4c632c85f6cd89616555d4ef241f
parentdbe2734d875f9dec5a3b28b9619eb5eeb9446121 (diff)
Store list of results for GUI
-rw-r--r--src/gui_project.c178
-rw-r--r--src/gui_project.h15
2 files changed, 163 insertions, 30 deletions
diff --git a/src/gui_project.c b/src/gui_project.c
index a641eee5..df9c0c29 100644
--- a/src/gui_project.c
+++ b/src/gui_project.c
@@ -362,17 +362,25 @@ void add_file_to_project(struct crystfelproject *proj,
}
-int load_project(struct crystfelproject *proj)
+static char **add_stream(char *new_stream,
+ char **streams,
+ int *pn_streams)
{
- FILE *fh;
- char line[1024];
- char *rval;
- int image_list_mode = 0;
+ int i = *pn_streams;
+ char **new_streams = realloc(streams,
+ (i+1)*sizeof(struct gui_result));
+ if ( new_streams == NULL ) return streams;
+
+ new_streams[i] = new_stream;
+ *pn_streams = i+1;
+ return new_streams;
+}
- fh = fopen("crystfel.project", "r");
- if ( fh == NULL ) return 1;
- default_project(proj);
+static void read_parameters(FILE *fh, struct crystfelproject *proj)
+{
+ char *rval;
+ char line[1024];
do {
@@ -380,29 +388,10 @@ int load_project(struct crystfelproject *proj)
rval = fgets(line, 1023, fh);
if ( rval == NULL ) break;
-
chomp(line);
-
if ( line[0] == '\0' ) continue;
- if ( image_list_mode ) {
- char *ev = NULL;
- size_t n = strlen(line)-1;
- for ( ; n>0; n-- ) {
- if ( line[n] == ' ' ) {
- line[n] = '\0';
- ev = &line[n+1];
- break;
- }
- }
- add_file_to_project(proj, line, ev);
- continue;
- }
-
- if ( strcmp(line, "-----") == 0 ) {
- image_list_mode = 1;
- continue;
- }
+ if ( strcmp(line, "-----") == 0 ) break;
sp = strchr(line, ' ');
if ( sp == NULL ) {
@@ -410,12 +399,106 @@ int load_project(struct crystfelproject *proj)
"file: '%s'\n", line);
continue;
}
-
sp[0] = '\0';
-
handle_var(line, sp+1, proj);
} while ( rval != NULL );
+}
+
+
+static void read_results(FILE *fh, struct crystfelproject *proj)
+{
+ char *rval;
+ char line[1024];
+ char **streams = NULL;
+ int n_streams = 0;
+ char *results_name = NULL;
+
+ do {
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) break;
+ chomp(line);
+ if ( line[0] == '\0' ) continue;
+
+ if ( strncmp(line, "Result ", 7) == 0 ) {
+
+ if ( n_streams > 0 ) {
+ add_result(proj,
+ results_name,
+ streams,
+ n_streams);
+ }
+
+ n_streams = 0;
+ streams = NULL;
+ results_name = strdup(line+7);
+ }
+
+ if ( strncmp(line, " Stream ", 10) == 0 ) {
+ streams = add_stream(strdup(line+10),
+ streams,
+ &n_streams);
+ }
+
+ if ( strcmp(line, "-----") == 0 ) {
+
+ if ( n_streams > 0 ) {
+ add_result(proj,
+ results_name,
+ streams,
+ n_streams);
+ }
+
+ break;
+
+ }
+
+ } while ( rval != NULL );
+}
+
+
+static void read_frames(FILE *fh, struct crystfelproject *proj)
+{
+ char *rval;
+ char line[1024];
+
+ do {
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) break;
+
+ chomp(line);
+
+ if ( line[0] == '\0' ) continue;
+
+ char *ev = NULL;
+ size_t n = strlen(line)-1;
+ for ( ; n>0; n-- ) {
+ if ( line[n] == ' ' ) {
+ line[n] = '\0';
+ ev = &line[n+1];
+ break;
+ }
+ }
+ add_file_to_project(proj, line, ev);
+
+ } while ( rval != NULL );
+}
+
+
+int load_project(struct crystfelproject *proj)
+{
+ FILE *fh;
+
+ fh = fopen("crystfel.project", "r");
+ if ( fh == NULL ) return 1;
+
+ default_project(proj);
+
+ read_parameters(fh, proj);
+ read_results(fh, proj);
+ read_frames(fh, proj);
fclose(fh);
@@ -524,6 +607,16 @@ int save_project(struct crystfelproject *proj)
fprintf(fh, "show_refls %i\n", proj->show_refls);
fprintf(fh, "-----\n");
+ for ( i=0; i<proj->n_results; i++ ) {
+ int j;
+ fprintf(fh, "Result %s\n", proj->results[i].name);
+ for ( j=0; j<proj->results[i].n_streams; j++ ) {
+ fprintf(fh, " Stream %s\n",
+ proj->results[i].streams[j]);
+ }
+ }
+
+ fprintf(fh, "-----\n");
if ( proj->stream == NULL ) {
for ( i=0; i<proj->n_frames; i++ ) {
if ( proj->events[i] != NULL ) {
@@ -619,4 +712,29 @@ void default_project(struct crystfelproject *proj)
proj->indexing_params.integration_method = strdup("rings");
proj->indexing_params.overpredict = 0;
proj->indexing_params.push_res = INFINITY;
+
+ proj->results = NULL;
+ proj->n_results = 0;
+}
+
+
+/* Assumes ownership of "name" and "streams" */
+int add_result(struct crystfelproject *proj,
+ char *name,
+ char **streams,
+ int n_streams)
+{
+ struct gui_result *new_results;
+
+ new_results = realloc(proj->results,
+ (proj->n_results+1)*sizeof(struct gui_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].n_streams = n_streams;
+ proj->results = new_results;
+ proj->n_results++;
+
+ return 0;
}
diff --git a/src/gui_project.h b/src/gui_project.h
index 34aa6f61..458ff547 100644
--- a/src/gui_project.h
+++ b/src/gui_project.h
@@ -136,6 +136,13 @@ struct gui_task
void *job_priv;
};
+struct gui_result
+{
+ char *name;
+ char **streams;
+ int n_streams;
+};
+
struct crystfelproject {
GtkWidget *window;
@@ -186,6 +193,9 @@ struct crystfelproject {
struct gui_task tasks[MAX_RUNNING_TASKS];
int n_running_tasks;
+
+ struct gui_result *results;
+ int n_results;
};
extern enum match_type_id decode_matchtype(const char *type_id);
@@ -204,4 +214,9 @@ extern void add_file_to_project(struct crystfelproject *proj,
extern void clear_project_files(struct crystfelproject *proj);
+extern int add_result(struct crystfelproject *proj,
+ char *name,
+ char **streams,
+ int n_streams);
+
#endif