diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dw-hdfsee.c | 74 | ||||
-rw-r--r-- | src/dw-hdfsee.h | 1 | ||||
-rw-r--r-- | src/process_image.c | 16 |
3 files changed, 29 insertions, 62 deletions
diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 17c547b8..399436c0 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -71,9 +71,6 @@ static void displaywindow_error(DisplayWindow *dw, const char *message) /* Window closed - clean up */ static gint displaywindow_closed(GtkWidget *window, DisplayWindow *dw) { - if ( dw->hdfile != NULL ) { - hdfile_close(dw->hdfile); - } if ( dw->surf != NULL ) cairo_surface_destroy(dw->surf); @@ -699,10 +696,6 @@ static gint displaywindow_set_binning(GtkWidget *widget, DisplayWindow *dw) return 0; } - if ( dw->hdfile == NULL ) { - return 0; - } - bd = malloc(sizeof(BinningDialog)); if ( bd == NULL ) return 0; dw->binning_dialog = bd; @@ -827,10 +820,6 @@ static gint displaywindow_set_boostint(GtkWidget *widget, DisplayWindow *dw) return 0; } - if ( dw->hdfile == NULL ) { - return 0; - } - bd = malloc(sizeof(BoostIntDialog)); if ( bd == NULL ) return 0; dw->boostint_dialog = bd; @@ -942,10 +931,6 @@ static gint displaywindow_set_ringradius(GtkWidget *widget, DisplayWindow *dw) return 0; } - if ( dw->hdfile == NULL ) { - return 0; - } - rd = malloc(sizeof(RingRadiusDialog)); if ( rd == NULL ) return 0; dw->ringradius_dialog = rd; @@ -1490,10 +1475,6 @@ static gint displaywindow_show_numbers(GtkWidget *widget, DisplayWindow *dw) return 0; } - if ( dw->hdfile == NULL ) { - return 0; - } - nw = malloc(sizeof(struct numberswindow)); if ( nw == NULL ) return 0; dw->numbers_window = nw; @@ -1774,7 +1755,7 @@ struct newhdf { char name[1024]; }; -static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh) +static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh, const char *filename) { gboolean a; int fail; @@ -1783,9 +1764,9 @@ static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh) a = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(nh->widget)); if ( !a ) return 0; - fail = hdf5_read2(nh->dw->hdfile, nh->dw->image, nh->name, 0, 1); + fail = hdf5_read2(filename, nh->dw->image, nh->name, 0, 1); if ( fail ) { - ERROR("Coun't load image"); + ERROR("Couldn't load image"); return 1; } @@ -1806,8 +1787,6 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile, GtkWidget *ms; int n, i; - if ( hdfile == NULL ) return NULL; - names = hdfile_read_group(hdfile, &n, group, &is_group, &is_image); if ( n == 0 ) return NULL; @@ -1896,22 +1875,30 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile, } -static GtkWidget *displaywindow_createhdfmenus(struct hdfile *hdfile, +static GtkWidget *displaywindow_createhdfmenus(const char *filename, DisplayWindow *dw, const char *selectme) { GSList *rg = NULL; + GtkWidget *w; + struct hdfile *hdfile; - return displaywindow_addhdfgroup(hdfile, "/", dw, &rg, selectme); + hdfile = hdfile_open(filename); + if ( hdfile == NULL ) { + return NULL; + } + w = displaywindow_addhdfgroup(hdfile, "/", dw, &rg, selectme); + hdfile_close(hdfile); + return w; } -static int displaywindow_update_menus(DisplayWindow *dw, const char *selectme) +static int displaywindow_update_menus(DisplayWindow *dw, const char * filename, const char *selectme) { GtkWidget *ms; GtkWidget *w; - ms = displaywindow_createhdfmenus(dw->hdfile, dw, selectme); + ms = displaywindow_createhdfmenus(filename , dw, selectme); if ( ms == NULL ) return 1; @@ -2422,34 +2409,11 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, dw->image->beam = get_beam_parameters(beam); } - if ( (dw->image->beam != NULL) && (dw->hdfile != NULL) ) { - fill_in_beam_parameters(dw->image->beam, dw->hdfile); - } - dw->image->det = det_geom; - /* TODO: Move the opening of the file in hd5_read. - * Currently not possible because the file handle - * must be stored in dw */ - - /* Open the file, if any */ - if ( filename != NULL ) { - - dw->hdfile = hdfile_open(filename); - if ( dw->hdfile == NULL ) { - free(dw); - return NULL; - } else { - dw->image->filename = strdup(filename); - check = hdf5_read(dw->hdfile, dw->image, element, 0); - if (check) { - ERROR("Couldn't load file\n"); - free(dw); - return NULL; - } - } - - } else { + check = hdf5_read(filename, dw->image, element, 0); + if (check) { + ERROR("Couldn't load file\n"); free(dw); return NULL; } @@ -2518,7 +2482,7 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, g_signal_connect(GTK_OBJECT(dw->drawingarea), "key-press-event", G_CALLBACK(displaywindow_keypress), dw); - displaywindow_update_menus(dw, element); + displaywindow_update_menus(dw, filename, element); dw->not_ready_yet = 0; return dw; diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h index 1ca4b73f..1d17f85b 100644 --- a/src/dw-hdfsee.h +++ b/src/dw-hdfsee.h @@ -89,7 +89,6 @@ typedef struct { int not_ready_yet; - struct hdfile *hdfile; struct image *image; /* Dialog boxes */ diff --git a/src/process_image.c b/src/process_image.c index c64f21b8..ec0a7e81 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -57,11 +57,11 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, float *data_for_measurement; size_t data_size; int check; - struct hdfile *hdfile; struct image image; int i; int r; char *rn; + struct hdfile *hdfile; image.features = NULL; image.data = NULL; @@ -74,13 +74,9 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, image.crystals = NULL; image.n_crystals = 0; - hdfile = hdfile_open(image.filename); - if ( hdfile == NULL ) return; - - check = hdf5_read(hdfile, &image, iargs->element, 1); + check = hdf5_read(image.filename, &image, iargs->element, 1); if ( check ) { - hdfile_close(hdfile); return; } @@ -100,6 +96,12 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, mark_resolution_range_as_bad(&image, iargs->highres, +INFINITY); + hdfile = hdfile_open(image.filename); + if ( hdfile == NULL ) { + ERROR("Couldn't open file %s.\n", image.filename); + return; + } + switch ( iargs->peaks ) { case PEAK_HDF5: @@ -140,6 +142,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, if ( r ) { ERROR("Failed to chdir to temporary folder: %s\n", strerror(errno)); + hdfile_close(hdfile); return; } @@ -149,6 +152,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, r = chdir(rn); if ( r ) { ERROR("Failed to chdir: %s\n", strerror(errno)); + hdfile_close(hdfile); return; } |