diff options
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/stream.c | 53 | ||||
-rw-r--r-- | libcrystfel/src/stream.h | 31 |
2 files changed, 69 insertions, 15 deletions
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index 54d4597e..a0d849a8 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -489,7 +489,7 @@ static int find_start_of_chunk(FILE *fh) } -void read_crystal(Stream *st, struct image *image) +static void read_crystal(Stream *st, struct image *image, StreamReadFlags srf) { char line[1024]; char *rval = NULL; @@ -524,22 +524,30 @@ void read_crystal(Stream *st, struct image *image) if ( rval == NULL ) break; chomp(line); - if ( sscanf(line, "astar = %f %f %f", &u, &v, &w) == 3 ) { + if ( (srf & STREAM_READ_UNITCELL) + && (sscanf(line, "astar = %f %f %f", &u, &v, &w) == 3) ) + { as.u = u*1e9; as.v = v*1e9; as.w = w*1e9; have_as = 1; } - if ( sscanf(line, "bstar = %f %f %f", &u, &v, &w) == 3 ) { + if ( (srf & STREAM_READ_UNITCELL) + && (sscanf(line, "bstar = %f %f %f", &u, &v, &w) == 3) ) + { bs.u = u*1e9; bs.v = v*1e9; bs.w = w*1e9; have_bs = 1; } - if ( sscanf(line, "cstar = %f %f %f", &u, &v, &w) == 3 ) { + if ( (srf & STREAM_READ_UNITCELL) + && (sscanf(line, "cstar = %f %f %f", &u, &v, &w) == 3) ) + { cs.u = u*1e9; cs.v = v*1e9; cs.w = w*1e9; have_cs = 1; } - if ( sscanf(line, "centering = %c", &c) == 1 ) { + if ( (srf & STREAM_READ_UNITCELL) + && (sscanf(line, "centering = %c", &c) == 1) ) + { if ( !have_cen ) { centering = c; have_cen = 1; @@ -548,7 +556,9 @@ void read_crystal(Stream *st, struct image *image) } } - if ( sscanf(line, "unique_axis = %c", &c) == 1 ) { + if ( (srf & STREAM_READ_UNITCELL) + && (sscanf(line, "unique_axis = %c", &c) == 1) ) + { if ( !have_ua ) { unique_axis = c; have_ua = 1; @@ -557,7 +567,9 @@ void read_crystal(Stream *st, struct image *image) } } - if ( strncmp(line, "lattice_type = ", 15) == 0 ) { + if ( (srf & STREAM_READ_UNITCELL) + && (strncmp(line, "lattice_type = ", 15) == 0) ) + { if ( !have_latt ) { lattice_type = lattice_from_str(line+15); have_latt = 1; @@ -580,7 +592,9 @@ void read_crystal(Stream *st, struct image *image) crystal_set_profile_radius(cr, rad*1e9); } - if ( strcmp(line, REFLECTION_START_MARKER) == 0 ) { + if ( (strcmp(line, REFLECTION_START_MARKER) == 0) + && (srf & STREAM_READ_REFLECTIONS) ) + { RefList *reflist; @@ -649,7 +663,7 @@ void read_crystal(Stream *st, struct image *image) /* Read the next chunk from a stream and fill in 'image' */ -int read_chunk(Stream *st, struct image *image) +int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf) { char line[1024]; char *rval = NULL; @@ -663,6 +677,10 @@ int read_chunk(Stream *st, struct image *image) image->crystals = NULL; image->n_crystals = 0; + if ( (srf & STREAM_READ_REFLECTIONS) || (srf & STREAM_READ_UNITCELL) ) { + srf |= STREAM_READ_CRYSTALS; + } + do { float div, bw; @@ -726,15 +744,18 @@ int read_chunk(Stream *st, struct image *image) } } - if ( strcmp(line, PEAK_LIST_START_MARKER) == 0 ) { + if ( (srf & STREAM_READ_PEAKS) + && (strcmp(line, PEAK_LIST_START_MARKER) == 0) ) { if ( read_peaks(st->fh, image) ) { ERROR("Failed while reading peaks\n"); return 1; } } - if ( strcmp(line, CRYSTAL_START_MARKER) == 0 ) { - read_crystal(st, image); + if ( (srf & STREAM_READ_CRYSTALS) + && (strcmp(line, CRYSTAL_START_MARKER) == 0) ) + { + read_crystal(st, image, srf); } /* A chunk must have at least a filename and a wavelength, @@ -756,6 +777,14 @@ int read_chunk(Stream *st, struct image *image) } +int read_chunk(Stream *st, struct image *image) +{ + return read_chunk_2(st, image, STREAM_READ_UNITCELL + | STREAM_READ_REFLECTIONS + | STREAM_READ_PEAKS); +} + + void write_stream_header(FILE *ofh, int argc, char *argv[]) { int i; diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h index 08e680bc..9f852c60 100644 --- a/libcrystfel/src/stream.h +++ b/libcrystfel/src/stream.h @@ -3,11 +3,11 @@ * * Stream tools * - * Copyright © 2013 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2013-2014 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * * Authors: - * 2010-2013 Thomas White <taw@physics.org> + * 2010-2014 Thomas White <taw@physics.org> * 2011 Andrew Aquila * * This file is part of CrystFEL. @@ -50,12 +50,37 @@ struct hdfile; typedef struct _stream Stream; +/** + * StreamReadFlags: + * @STREAM_READ_UNITCELL: Read the unit cell + * @STREAM_READ_REFLECTIONS: Read the integrated reflections + * @STREAM_READ_PEAKS: Read the peak search results + * @STREAM_READ_CRYSTALS: Read the general information about crystals + * + * A bitfield of things that can be read from a stream. Use this (and + * read_chunk_2()) to read the stream faster if you don't need the entire + * contents of the stream. + * + * Using either or both of @STREAM_READ_REFLECTIONS and @STREAM_READ_UNITCELL + * implies @STREAM_READ_CRYSTALS. + **/ +typedef enum { + + STREAM_READ_UNITCELL = 1, + STREAM_READ_REFLECTIONS = 2, + STREAM_READ_PEAKS = 4, + STREAM_READ_CRYSTALS = 8, + +} StreamReadFlags; + + extern Stream *open_stream_for_read(const char *filename); extern Stream *open_stream_for_write(const char *filename); extern Stream *open_stream_fd_for_write(int fd); extern void close_stream(Stream *st); extern int read_chunk(Stream *st, struct image *image); +extern int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf); extern void write_chunk(Stream *st, struct image *image, struct hdfile *hdfile, int include_peaks, int include_reflections); |