From 282dee197bce06f9d37655c1775f53f6646e2e5d Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Thu, 10 Jul 2014 16:35:50 +0200 Subject: Copy geometry file into stream --- libcrystfel/src/stream.c | 65 +++++++++++++++++++++++++++++++++++++++++++++--- libcrystfel/src/stream.h | 7 +++++- 2 files changed, 68 insertions(+), 4 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index 13b9065d..fcb3bb21 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -875,18 +875,21 @@ Stream *open_stream_fd_for_write(int fd) /** - * open_stream_for_write + * open_stream_for_write_2 * @filename: Filename of new stream * * Creates a new stream with name @filename, and adds the stream format - * and version headers. + * and version header, plus a verbatim copy of the geometry file * * You may want to follow this with a call to write_command() to record the * command line. * * Returns: a %Stream, or NULL on failure. */ -Stream *open_stream_for_write(const char *filename) +Stream *open_stream_for_write_2(const char *filename, + const char* geom_filename, int argc, + char *argv[]) + { Stream *st; @@ -908,10 +911,35 @@ Stream *open_stream_for_write(const char *filename) fprintf(st->fh, "Generated by CrystFEL "CRYSTFEL_VERSIONSTRING"\n"); fflush(st->fh); + if ( (argc > 0) && (argv != NULL) ) { + write_command(st, argc, argv); + } + if ( geom_filename != NULL ) { + write_geometry_file(st, geom_filename); + } + return st; } +/** + * open_stream_for_write + * @filename: Filename of new stream + * + * Creates a new stream with name @filename, and adds the stream format + * and version headers. + * + * You may want to follow this with a call to write_command() to record the + * command line. + * + * Returns: a %Stream, or NULL on failure. + */ +Stream *open_stream_for_write(const char *filename) +{ + return open_stream_for_write_2(filename, NULL, 0, NULL); +} + + /** * get_stream_fd * @st: A %Stream @@ -984,6 +1012,37 @@ void write_command(Stream *st, int argc, char *argv[]) } +/** + * write_geometry_file + * @st: A %Stream + * @geom_filename: geomtry file name + * + * Writes the content of the geometry file to @st. This should usually be + * called immediately after write_command(). + */ +void write_geometry_file(Stream *st, const char *geom_filename) { + + char line[2014]; + FILE *geom_fh; + char *rval; + + geom_fh = fopen(geom_filename, "r"); + if ( geom_fh == NULL ) { + ERROR("Failed to read detector geometry from " + "'%s'\n", geom_filename); + return; + } + fprintf(st->fh, GEOM_START_MARKER"\n"); + + do { + rval = fgets(line, 1023, geom_fh); + fprintf(st->fh, line); + } while ( rval != NULL ); + fprintf(st->fh, GEOM_END_MARKER"\n"); + fflush(st->fh); +} + + /** * rewind_stream: * @st: A %Stream diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h index d7108439..1c2e57c6 100644 --- a/libcrystfel/src/stream.h +++ b/libcrystfel/src/stream.h @@ -38,6 +38,8 @@ struct image; struct hdfile; +#define GEOM_START_MARKER "----- Begin geometry file -----" +#define GEOM_END_MARKER "----- End geometry file -----" #define CHUNK_START_MARKER "----- Begin chunk -----" #define CHUNK_END_MARKER "----- End chunk -----" #define PEAK_LIST_START_MARKER "Peaks from peak search" @@ -79,6 +81,9 @@ extern "C" { extern Stream *open_stream_for_read(const char *filename); extern Stream *open_stream_for_write(const char *filename); +extern Stream *open_stream_for_write_2(const char *filename, + const char* geom_filename, int argc, + char *argv[]); extern Stream *open_stream_fd_for_write(int fd); extern int get_stream_fd(Stream *st); extern void close_stream(Stream *st); @@ -89,7 +94,7 @@ extern void write_chunk(Stream *st, struct image *image, struct hdfile *hdfile, int include_peaks, int include_reflections); extern void write_command(Stream *st, int argc, char *argv[]); - +extern void write_geometry_file(Stream *st, const char *geom_filename); extern int rewind_stream(Stream *st); extern int is_stream(const char *filename); -- cgit v1.2.3