From 88cd2cfd80838dd57cf607ac0fa752665cae4c14 Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Mon, 26 Jan 2015 16:34:46 +0100 Subject: Keep hold of HDF5 fields which came from the stream --- libcrystfel/src/image.h | 1 + libcrystfel/src/stream.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ libcrystfel/src/stream.h | 9 ++++++++ 3 files changed, 67 insertions(+) (limited to 'libcrystfel') diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h index e196d052..10e83905 100644 --- a/libcrystfel/src/image.h +++ b/libcrystfel/src/image.h @@ -180,6 +180,7 @@ struct image { char *filename; struct event *event; const struct copy_hdf5_field *copyme; + struct stuff_from_stream *stuff_from_stream; int id; /* ID number of the thread * handling this image */ diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index 2a352baf..3eb1d783 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -1066,6 +1066,7 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf) image->crystals = NULL; image->n_crystals = 0; image->event = NULL; + image->stuff_from_stream = NULL; if ( (srf & STREAM_READ_REFLECTIONS) || (srf & STREAM_READ_UNITCELL) ) { srf |= STREAM_READ_CRYSTALS; @@ -1147,6 +1148,37 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf) } } + if (strncmp(line, "hdf5", 3) == 0 ) { + + char **new_fields; + + if ( image->stuff_from_stream == NULL ) { + image->stuff_from_stream = + malloc(sizeof(struct stuff_from_stream)); + if ( image->stuff_from_stream == NULL) { + ERROR("Failed reading hdf5 entries from " + "stream\n"); + return 1; + } + image->stuff_from_stream->fields = NULL; + image->stuff_from_stream->n_fields = 0; + } + + new_fields = realloc(image->stuff_from_stream->fields, + (1+image->stuff_from_stream->n_fields)* + sizeof(char *)); + if ( new_fields == NULL ) { + ERROR("Failed reading hdf5 entries from stream\n"); + return 1; + } + image->stuff_from_stream->fields = new_fields; + image->stuff_from_stream->fields[image->stuff_from_stream->n_fields] + = strdup(line); + image->stuff_from_stream->n_fields++; + + } + + if ( (srf & STREAM_READ_PEAKS) && strcmp(line, PEAK_LIST_START_MARKER) == 0 ) { @@ -1480,3 +1512,28 @@ int rewind_stream(Stream *st) { return fseek(st->fh, 0, SEEK_SET); } + + + +double extract_f_from_stuff(const char *field_name, + struct stuff_from_stream* stuff) +{ + int i; + + char field_name_plus_equal[256]; + sprintf(field_name_plus_equal, "hdf5%s = ", field_name); + + + + for ( i=0; in_fields; i++ ) { + + if ( strncmp(stuff->fields[i], field_name_plus_equal, + strlen(field_name_plus_equal)) == 0 ) { + return atoi(stuff->fields[i]+ + strlen(field_name_plus_equal)); + } + } + + ERROR("Failed to recovery camera length from stream file\n"); + return -1; +} diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h index 43e45923..afa9acda 100644 --- a/libcrystfel/src/stream.h +++ b/libcrystfel/src/stream.h @@ -77,6 +77,12 @@ typedef enum { } StreamReadFlags; +struct stuff_from_stream +{ + char **fields; + int n_fields; +}; + #ifdef __cplusplus extern "C" { #endif @@ -103,6 +109,9 @@ extern void write_geometry_file(Stream *st, const char *geom_filename); extern int rewind_stream(Stream *st); extern int is_stream(const char *filename); +extern double extract_f_from_stuff(const char *field_name, + struct stuff_from_stream* stuff); + #ifdef __cplusplus } #endif -- cgit v1.2.3