diff options
author | Thomas White <taw@physics.org> | 2015-11-27 13:05:33 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2015-11-27 13:18:29 +0100 |
commit | 6fc80febf119f9f3183c918f3137a396cbe06e40 (patch) | |
tree | 9b0aa1c9eb5ad43aba38d8513efe5d4daf6b61c2 /libcrystfel/src/stream.c | |
parent | e81e335daf509166fc234c8835203a80d5b21e0d (diff) |
indexamajig: Write target unit cell into stream
Diffstat (limited to 'libcrystfel/src/stream.c')
-rw-r--r-- | libcrystfel/src/stream.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index c5ab6626..43fd273c 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -1390,6 +1390,71 @@ Stream *open_stream_fd_for_write(int fd) } +static void write_cell_to_stream(Stream *st, UnitCell *cell) +{ + fprintf(st->fh, CELL_START_MARKER"\n"); + write_cell(cell, st->fh); + fprintf(st->fh, "; Please note: this is the target unit cell.\n"); + fprintf(st->fh, "; The actual unit cells produced by indexing " + "depend on many other factors.\n"); + fprintf(st->fh, CELL_END_MARKER"\n"); + fflush(st->fh); +} + + +/** + * open_stream_for_write_3 + * @filename: Filename of new stream + * @geom_filename: The geometry filename to copy + * @cell: A %UnitCell to write into the stream + * @argc: The number of arguments to the program + * @argv: The arguments to the program + * + * Creates a new stream with name @filename, and adds the stream format + * and version header, plus a verbatim copy of the geometry file and the unit + * cell in CrystFEL format. + * + * Returns: a %Stream, or NULL on failure. + */ +Stream *open_stream_for_write_3(const char *filename, + const char *geom_filename, UnitCell *cell, + int argc, char *argv[]) + +{ + Stream *st; + + st = malloc(sizeof(struct _stream)); + if ( st == NULL ) return NULL; + + st->fh = fopen(filename, "w"); + if ( st->fh == NULL ) { + ERROR("Failed to open stream.\n"); + free(st); + return NULL; + } + + st->major_version = LATEST_MAJOR_VERSION; + st->minor_version = LATEST_MINOR_VERSION; + + fprintf(st->fh, "CrystFEL stream format %i.%i\n", + st->major_version, st->minor_version); + 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); + } + if ( cell != NULL ) { + write_cell_to_stream(st, cell); + } + + return st; +} + + /** * open_stream_for_write_2 * @filename: Filename of new stream |