aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorValerio Mariani <valerio.mariani@desy.de>2014-03-31 17:34:15 +0200
committerThomas White <taw@physics.org>2014-09-05 18:03:55 +0200
commit4a36677bacc10e5fbd5905ea9751f1a6603250f7 (patch)
tree038a504bf242f997b77b0b5042d11cd831582b8d /libcrystfel
parentf5513fcb51d0d027bb7d5e1e2db95fae480c3a86 (diff)
Moved opening of file inside hdf5_read function for better encapsulation
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/hdf5-file.c20
-rw-r--r--libcrystfel/src/hdf5-file.h4
2 files changed, 18 insertions, 6 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);