diff options
author | Thomas White <taw@physics.org> | 2017-05-03 11:25:24 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2017-05-03 11:27:08 +0200 |
commit | 0ed8246becde25ee82afb80139103b42a20374c3 (patch) | |
tree | 7cfcdbcd9952faae964defda68aaef0fdc3a198a | |
parent | 00f8d418534b30e71fd925487c0284560e90b2b2 (diff) |
Detect CBF files, interface bits
-rw-r--r-- | libcrystfel/src/image.c | 70 | ||||
-rw-r--r-- | libcrystfel/src/image.h | 19 |
2 files changed, 76 insertions, 13 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 5aa2f9c3..29e5d5e1 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -32,6 +32,7 @@ #include <math.h> #include <stdio.h> #include <hdf5.h> +#include <cbflib/cbf.h> #include "image.h" #include "utils.h" @@ -379,14 +380,25 @@ void add_imagefile_field(struct imagefile_field_list *copyme, const char *name) } -/****************************** Image files ***********************************/ +/******************************* CBF files ************************************/ -enum imagefile_type +static int read_cbf(struct imagefile *f, struct image *image) { - IMAGEFILE_HDF5, - IMAGEFILE_CBF -}; + cbf_handle cbfh; + + if ( cbf_make_handle(&cbfh) ) { + ERROR("Failed to allocate CBF handle\n"); + return 1; + } + + ERROR("Mock CBF read\n"); + + cbf_free_handle(cbfh); + return 0; +} + +/****************************** Image files ***********************************/ struct imagefile { @@ -395,6 +407,25 @@ struct imagefile }; +static signed int is_cbf_file(const char *filename) +{ + FILE *fh; + char line[1024]; + + fh = fopen(filename, "r"); + if ( fh == NULL ) return -1; + + if ( fgets(line, 1024, fh) == NULL ) return -1; + fclose(fh); + + if ( strstr(line, "CBF") == NULL ) { + return 0; + } + + return 1; +} + + struct imagefile *imagefile_open(const char *filename) { struct imagefile *f; @@ -413,10 +444,9 @@ struct imagefile *imagefile_open(const char *filename) return NULL; } - } else { + } else if ( is_cbf_file(filename) > 0 ) { - STATUS("Mock CBF check\n"); - return NULL; + f->type = IMAGEFILE_CBF; } @@ -429,13 +459,35 @@ int imagefile_read(struct imagefile *f, struct image *image, { if ( f->type == IMAGEFILE_HDF5 ) { return hdf5_read2(f->hdfile, image, event, 0); + } else if ( f->type == IMAGEFILE_CBF ) { + return read_cbf(f, image); + } else { + ERROR("Unknown file type %i\n", f->type); + return 1; + } +} + + +/* Read a simple file, no multi-event, no prior geometry etc, and + * generate a geometry for it */ +int imagefile_read_simple(struct imagefile *f, struct image *image) +{ + if ( f->type == IMAGEFILE_HDF5 ) { + return hdf5_read(f->hdfile, image, NULL, 0); } else { - STATUS("Mock CBF read\n"); + STATUS("Mock CBF simple read\n"); return 0; } } +enum imagefile_type imagefile_get_type(struct imagefile *f) +{ + assert(f != NULL); + return f->type; +} + + struct hdfile *imagefile_get_hdfile(struct imagefile *f) { if ( f->type != IMAGEFILE_HDF5 ) { diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h index f310a09b..ead5cd4d 100644 --- a/libcrystfel/src/image.h +++ b/libcrystfel/src/image.h @@ -90,6 +90,15 @@ struct imagefeature { const char *name; }; + +/* An enum representing the image file formats we can handle */ +enum imagefile_type +{ + IMAGEFILE_HDF5, + IMAGEFILE_CBF +}; + + /* An opaque type representing a list of image features */ typedef struct _imagefeaturelist ImageFeatureList; @@ -238,13 +247,15 @@ extern void free_all_crystals(struct image *image); /* Image files */ extern struct imagefile *imagefile_open(const char *filename); -extern int imagefile_read(struct imagefile *imfile, struct image *image, +extern int imagefile_read(struct imagefile *f, struct image *image, struct event *event); -extern struct hdfile *imagefile_get_hdfile(struct imagefile *imfile); -extern void imagefile_copy_fields(struct imagefile *imfile, +extern int imagefile_read_simple(struct imagefile *f, struct image *image); +extern struct hdfile *imagefile_get_hdfile(struct imagefile *f); +extern enum imagefile_type imagefile_get_type(struct imagefile *f); +extern void imagefile_copy_fields(struct imagefile *f, const struct imagefile_field_list *copyme, FILE *fh, struct event *ev); -extern void imagefile_close(struct imagefile *imfile); +extern void imagefile_close(struct imagefile *f); /* Field lists */ extern struct imagefile_field_list *new_imagefile_field_list(void); |