aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/image.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-05-03 11:25:24 +0200
committerThomas White <taw@physics.org>2017-05-03 11:27:08 +0200
commit0ed8246becde25ee82afb80139103b42a20374c3 (patch)
tree7cfcdbcd9952faae964defda68aaef0fdc3a198a /libcrystfel/src/image.c
parent00f8d418534b30e71fd925487c0284560e90b2b2 (diff)
Detect CBF files, interface bits
Diffstat (limited to 'libcrystfel/src/image.c')
-rw-r--r--libcrystfel/src/image.c70
1 files changed, 61 insertions, 9 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 ) {