aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcrystfel/src/stream.c65
-rw-r--r--libcrystfel/src/stream.h7
-rw-r--r--src/indexamajig.c6
-rw-r--r--src/partial_sim.c4
4 files changed, 72 insertions, 10 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);
diff --git a/src/indexamajig.c b/src/indexamajig.c
index d75e24be..fcf97dd4 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -197,6 +197,7 @@ int main(int argc, char *argv[])
char *int_str = NULL;
char *tempdir = NULL;
char *int_diag = NULL;
+ char *geom_filename = NULL;
/* Defaults */
iargs.cell = NULL;
@@ -335,6 +336,7 @@ int main(int argc, char *argv[])
break;
case 'g' :
+ geom_filename = optarg;
iargs.det = get_detector_geometry(optarg);
if ( iargs.det == NULL ) {
ERROR("Failed to read detector geometry from "
@@ -654,15 +656,13 @@ int main(int argc, char *argv[])
}
- st = open_stream_for_write(outfile);
+ st = open_stream_for_write_2(outfile, geom_filename, argc, argv);
if ( st == NULL ) {
ERROR("Failed to open stream '%s'\n", outfile);
return 1;
}
free(outfile);
- write_command(st, argc, argv);
-
/* Prepare the indexer */
if ( indm != NULL ) {
ipriv = prepare_indexing(indm, iargs.cell, iargs.det,
diff --git a/src/partial_sim.c b/src/partial_sim.c
index 862eadef..a113532b 100644
--- a/src/partial_sim.c
+++ b/src/partial_sim.c
@@ -689,15 +689,13 @@ int main(int argc, char *argv[])
ERROR("You must give a filename for the output.\n");
return 1;
}
- stream = open_stream_for_write(output_file);
+ stream = open_stream_for_write_2(output_file, geomfile, argc, argv);
if ( stream == NULL ) {
ERROR("Couldn't open output file '%s'\n", output_file);
return 1;
}
free(output_file);
- write_command(stream, argc, argv);
-
image.det = det;
image.width = det->max_fs + 1;
image.height = det->max_ss + 1;