aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcrystfel/src/hdf5-file.c20
-rw-r--r--libcrystfel/src/hdf5-file.h4
-rw-r--r--src/dw-hdfsee.c74
-rw-r--r--src/dw-hdfsee.h1
-rw-r--r--src/process_image.c16
5 files changed, 47 insertions, 68 deletions
diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c
index fa5c127d..297f78ac 100644
--- a/libcrystfel/src/hdf5-file.c
+++ b/libcrystfel/src/hdf5-file.c
@@ -845,13 +845,13 @@ static int unpack_panels(struct image *image, struct detector *det)
}
-int hdf5_read(struct hdfile *f, struct image *image, const char* element, int satcorr)
+int hdf5_read(const char *filename, struct image *image, const char* element, int satcorr)
{
- return hdf5_read2(f, image, element, satcorr, 0);
+ return hdf5_read2(filename, image, element, satcorr, 0);
}
-int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int satcorr, int override_data_and_mask)
+int hdf5_read2(const char *filename, struct image *image, const char* element, int satcorr, int override_data_and_mask)
{
herr_t r;
float *buf;
@@ -863,7 +863,7 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
int no_mask_loaded;
int pi;
hid_t mask_dh = NULL;
-
+ struct hdfile *f;
if ( image->det == NULL ) {
ERROR("Geometry not available\n");
@@ -898,6 +898,11 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
curr_ss = 0;
no_mask_loaded = 1;
+ f = hdfile_open(filename);
+ if ( f == NULL ) {
+ return 1;
+ }
+
for ( pi=0; pi<image->det->n_panels; pi++ ) {
int data_width, data_height;
@@ -925,6 +930,7 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
if ( fail ) {
ERROR("Couldn't select path for panel %s\n",
p->name);
+ hdfile_close(f);
return 1;
}
@@ -938,6 +944,7 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
ERROR("Panel name: %s. Data size: %i,%i. Geometry size: %i,%i\n",
p->name, data_width, data_height,
p->w, p->h);
+ hdfile_close(f);
return 1;
}
@@ -952,6 +959,7 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
ERROR("Error selecting file dataspace for panel %s\n",
p->name);
free(buf);
+ hdfile_close(f);
return 1;
}
@@ -968,6 +976,7 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
ERROR("Error selecting memory dataspace for panel %s\n",
p->name);
free(buf);
+ hdfile_close(f);
return 1;
}
r = H5Dread(f->dh, H5T_NATIVE_FLOAT, memspace, dataspace,
@@ -976,6 +985,7 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
ERROR("Couldn't read data for panel %s\n",
p->name);
free(buf);
+ hdfile_close(f);
return 1;
}
H5Dclose(f->dh);
@@ -1049,11 +1059,13 @@ int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int s
"for %s.\n",
image->lambda, image->beam->photon_energy,
image->filename);
+ hdfile_close(f);
return 1;
}
}
+ hdfile_close(f);
return 0;
}
diff --git a/libcrystfel/src/hdf5-file.h b/libcrystfel/src/hdf5-file.h
index 2e24a039..7aa76982 100644
--- a/libcrystfel/src/hdf5-file.h
+++ b/libcrystfel/src/hdf5-file.h
@@ -51,9 +51,9 @@ extern int hdf5_write(const char *filename, const void *data,
extern int hdf5_write_image(const char *filename, struct image *image, char *element);
-extern int hdf5_read(struct hdfile *f, struct image *image, const char *element, int satcorr);
+extern int hdf5_read(const char *filename, struct image *image, const char *element, int satcorr);
-extern int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int satcorr, int override_data_and_mask);
+extern int hdf5_read2(const char *filename, struct image *image, const char* element, int satcorr, int override_data_and_mask);
extern struct hdfile *hdfile_open(const char *filename);
extern int hdfile_set_image(struct hdfile *f, const char *path);
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;
}