diff options
author | Valerio Mariani <valerio.mariani@desy.de> | 2014-07-10 16:35:50 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2014-07-21 15:31:58 +0200 |
commit | 282dee197bce06f9d37655c1775f53f6646e2e5d (patch) | |
tree | cef8f4803f75b4e78dd77202da3fe479dbc66014 /libcrystfel/src/stream.c | |
parent | 0508fc381cda5a3ead7069624ae5036183eee840 (diff) |
Copy geometry file into stream
Diffstat (limited to 'libcrystfel/src/stream.c')
-rw-r--r-- | libcrystfel/src/stream.c | 65 |
1 files changed, 62 insertions, 3 deletions
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,11 +911,36 @@ 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 * @@ -985,6 +1013,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 * |