aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-04-28 17:15:13 +0200
committerThomas White <taw@physics.org>2017-05-02 12:03:12 +0200
commitcb6389ae61e8f7e279ea16f8ab1a94969d6c0dc9 (patch)
treef4c0cd181bf503e1d69488e66d929458139ed779 /libcrystfel/src
parent8fbfaf71b1efef4bfdb40ce85200e772e82e9773 (diff)
Skeleton image file API
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/image.c129
-rw-r--r--libcrystfel/src/image.h19
-rw-r--r--libcrystfel/src/stream.h3
3 files changed, 144 insertions, 7 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 2cc0d792..f322cbdd 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -299,3 +299,132 @@ void free_all_crystals(struct image *image)
free(image->crystals);
image->n_crystals = 0;
}
+
+
+/**************************** Image field lists *******************************/
+
+struct imagefile_field_list
+{
+ char **fields;
+ int n_fields;
+ int max_fields;
+};
+
+
+struct imagefile_field_list *new_imagefile_field_list()
+{
+ struct imagefile_field_list *n;
+
+ n = calloc(1, sizeof(struct imagefile_field_list));
+ if ( n == NULL ) return NULL;
+
+ n->max_fields = 32;
+ n->fields = malloc(n->max_fields*sizeof(char *));
+ if ( n->fields == NULL ) {
+ free(n);
+ return NULL;
+ }
+
+ return n;
+}
+
+
+void free_imagefile_field_list(struct imagefile_field_list *n)
+{
+ int i;
+ for ( i=0; i<n->n_fields; i++ ) {
+ free(n->fields[i]);
+ }
+ free(n->fields);
+ free(n);
+}
+
+
+void add_imagefile_field(struct imagefile_field_list *copyme, const char *name)
+{
+ int i;
+
+ /* Already on the list? Don't re-add if so. */
+ for ( i=0; i<copyme->n_fields; i++ ) {
+ if ( strcmp(copyme->fields[i], name) == 0 ) return;
+ }
+
+ /* Need more space? */
+ if ( copyme->n_fields == copyme->max_fields ) {
+
+ char **nfields;
+ int nmax = copyme->max_fields + 32;
+
+ nfields = realloc(copyme->fields, nmax*sizeof(char *));
+ if ( nfields == NULL ) {
+ ERROR("Failed to allocate space for new HDF5 field.\n");
+ return;
+ }
+
+ copyme->max_fields = nmax;
+ copyme->fields = nfields;
+
+ }
+
+ copyme->fields[copyme->n_fields] = strdup(name);
+ if ( copyme->fields[copyme->n_fields] == NULL ) {
+ ERROR("Failed to add field for copying '%s'\n", name);
+ return;
+ }
+
+ copyme->n_fields++;
+}
+
+
+/****************************** Image files ***********************************/
+
+struct imagefile *imagefile_open(const char *filename)
+{
+}
+
+
+int imagefile_read(struct imagefile *imfile, struct image *image,
+ struct event *event)
+{
+}
+
+
+struct hdfile *imagefile_get_hdfile(struct imagefile *imfile)
+{
+}
+
+
+void imagefile_copy_fields(struct imagefile *f,
+ const struct imagefile_field_list *copyme,
+ FILE *fh, struct event *ev)
+{
+ int i;
+
+ if ( copyme == NULL ) return;
+
+ for ( i=0; i<copyme->n_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);
+ } else {
+ fprintf(fh, "hdf5/%s = %s\n", field, val);
+ }
+
+ free(val);
+#endif
+
+ }
+}
+
+
+void imagefile_close(struct imagefile *imfile)
+{
+}
diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h
index 2ed7140f..f310a09b 100644
--- a/libcrystfel/src/image.h
+++ b/libcrystfel/src/image.h
@@ -123,7 +123,7 @@ struct beam_params
* struct detector *det;
* struct beam_params *beam;
* char *filename;
- * const struct copy_hdf5_field *copyme;
+ * const struct imagefile_field_list *copyme;
*
* int id;
*
@@ -155,8 +155,8 @@ struct beam_params
* returned by the low-level indexing system. <structfield>n_crystals</structfield>
* is the number of crystals which were found in the image.
*
- * <structfield>copyme</structfield> represents a list of HDF5 fields to copy
- * to the output stream.
+ * <structfield>copyme</structfield> represents a list of fields in the image
+ * file (e.g. HDF5 fields or CBF headers) to copy to the output stream.
**/
struct image;
@@ -174,7 +174,7 @@ struct image {
struct beam_params *beam; /* The nominal beam parameters */
char *filename;
struct event *event;
- const struct copy_hdf5_field *copyme;
+ const struct imagefile_field_list *copyme;
struct stuff_from_stream *stuff_from_stream;
double avg_clen; /* Average camera length extracted
@@ -242,10 +242,17 @@ extern int imagefile_read(struct imagefile *imfile, struct image *image,
struct event *event);
extern struct hdfile *imagefile_get_hdfile(struct imagefile *imfile);
extern void imagefile_copy_fields(struct imagefile *imfile,
- struct copy_hdf5_file *copyme, FILE *fh,
- struct event *ev);
+ const struct imagefile_field_list *copyme,
+ FILE *fh, struct event *ev);
extern void imagefile_close(struct imagefile *imfile);
+/* Field lists */
+extern struct imagefile_field_list *new_imagefile_field_list(void);
+extern void free_imagefile_field_list(struct imagefile_field_list *f);
+
+extern void add_imagefile_field(struct imagefile_field_list *copyme,
+ const char *name);
+
#ifdef __cplusplus
}
#endif
diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h
index a95c7df0..764e3e36 100644
--- a/libcrystfel/src/stream.h
+++ b/libcrystfel/src/stream.h
@@ -39,6 +39,7 @@
struct image;
struct hdfile;
struct event;
+struct imagefile;
#include "cell.h"
#define GEOM_START_MARKER "----- Begin geometry file -----"
@@ -106,7 +107,7 @@ extern int read_chunk(Stream *st, struct image *image);
extern int read_chunk_2(Stream *st, struct image *image,
StreamReadFlags srf);
-extern int write_chunk(Stream *st, struct image *image, struct hdfile *hdfile,
+extern int write_chunk(Stream *st, struct image *image, struct imagefile *imfile,
int include_peaks, int include_reflections,
struct event *ev);