From 9b168c16fd09407b2713af3dd72d983f16eec08e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 2 May 2017 11:58:35 +0200 Subject: HDF5 reading under new API --- libcrystfel/src/image.c | 83 ++++++++++++++++++++++++++++++++++++++++++------- src/dw-hdfsee.c | 2 +- 2 files changed, 72 insertions(+), 13 deletions(-) diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index f322cbdd..5aa2f9c3 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -31,9 +31,12 @@ #include #include #include +#include #include "image.h" #include "utils.h" +#include "events.h" +#include "hdf5-file.h" /** * SECTION:image @@ -378,19 +381,69 @@ void add_imagefile_field(struct imagefile_field_list *copyme, const char *name) /****************************** Image files ***********************************/ +enum imagefile_type +{ + IMAGEFILE_HDF5, + IMAGEFILE_CBF +}; + + +struct imagefile +{ + enum imagefile_type type; + struct hdfile *hdfile; +}; + + struct imagefile *imagefile_open(const char *filename) { + struct imagefile *f; + + f = malloc(sizeof(struct imagefile)); + if ( f == NULL ) return NULL; + + if ( H5Fis_hdf5(filename) > 0 ) { + + /* This is an HDF5, pass through to HDF5 layer */ + f->type = IMAGEFILE_HDF5; + f->hdfile = hdfile_open(filename); + + if ( f->hdfile == NULL ) { + free(f); + return NULL; + } + + } else { + + STATUS("Mock CBF check\n"); + return NULL; + + } + + return f; } -int imagefile_read(struct imagefile *imfile, struct image *image, - struct event *event) +int imagefile_read(struct imagefile *f, struct image *image, + struct event *event) { + if ( f->type == IMAGEFILE_HDF5 ) { + return hdf5_read2(f->hdfile, image, event, 0); + } else { + STATUS("Mock CBF read\n"); + return 0; + } } -struct hdfile *imagefile_get_hdfile(struct imagefile *imfile) +struct hdfile *imagefile_get_hdfile(struct imagefile *f) { + if ( f->type != IMAGEFILE_HDF5 ) { + ERROR("Not an HDF5 file!\n"); + return NULL; + } + + return f->hdfile; } @@ -404,27 +457,33 @@ void imagefile_copy_fields(struct imagefile *f, for ( i=0; in_fields; i++ ) { -#warning FIXME Implement imagefile field copying -#if 0 char *val; char *field; field = copyme->fields[i]; - val = hdfile_get_string_value(f, field, ev); - if ( field[0] == '/' ) { - fprintf(fh, "hdf5%s = %s\n", field, val); + if ( f->type == IMAGEFILE_HDF5 ) { + val = hdfile_get_string_value(f->hdfile, field, ev); + if ( field[0] == '/' ) { + fprintf(fh, "hdf5%s = %s\n", field, val); + } else { + fprintf(fh, "hdf5/%s = %s\n", field, val); + } + free(val); + } else { - fprintf(fh, "hdf5/%s = %s\n", field, val); + STATUS("Mock CBF variable\n"); + fprintf(fh, "cbf/%s = %s\n", field, "(FIXME)"); } - free(val); -#endif } } -void imagefile_close(struct imagefile *imfile) +void imagefile_close(struct imagefile *f) { + if ( f->type == IMAGEFILE_HDF5 ) { + hdfile_close(f->hdfile); + } } diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 87c23f4e..7f647727 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1047,7 +1047,7 @@ static gint displaywindow_set_newevent(GtkWidget *widget, DisplayWindow *dw) } if ( dw->hdfile == NULL ) { - return 0; + return 0; } ed = malloc(sizeof(EventDialog)); -- cgit v1.2.3