aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorValerio Mariani <valerio.mariani@desy.de>2014-07-10 16:35:50 +0200
committerThomas White <taw@physics.org>2014-07-21 15:31:58 +0200
commit282dee197bce06f9d37655c1775f53f6646e2e5d (patch)
treecef8f4803f75b4e78dd77202da3fe479dbc66014 /libcrystfel/src
parent0508fc381cda5a3ead7069624ae5036183eee840 (diff)
Copy geometry file into stream
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/stream.c65
-rw-r--r--libcrystfel/src/stream.h7
2 files changed, 68 insertions, 4 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
*
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);