diff options
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 |