aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-12-22 11:46:09 +0100
committerThomas White <taw@physics.org>2024-01-30 10:35:03 +0100
commit9cb19d72dffdb5c1b802ba14c971a21e8ca2982d (patch)
treeddf08e889bc0bad61f8b0666f1eebc24f11e5e87 /libcrystfel
parentc572a2cabca0339e633eb6ca98fbf0a3bed53497 (diff)
Add data_template_write_to_fh and stream_write_data_template
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/datatemplate.c19
-rw-r--r--libcrystfel/src/datatemplate.h2
-rw-r--r--libcrystfel/src/stream.c22
-rw-r--r--libcrystfel/src/stream.h2
4 files changed, 37 insertions, 8 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index e480779c..c11ec89d 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -2304,14 +2304,10 @@ static const char *str_dim(int dim)
}
-int data_template_write_to_file(const DataTemplate *dtempl, const char *filename)
+int data_template_write_to_fh(const DataTemplate *dtempl, FILE *fh)
{
- FILE *fh;
int i;
- fh = fopen(filename, "w");
- if ( fh == NULL ) return 1;
-
/* Basic top-level parameters */
switch ( dtempl->wavelength_unit ) {
@@ -2643,11 +2639,22 @@ int data_template_write_to_file(const DataTemplate *dtempl, const char *filename
fprintf(fh, "\n");
}
- fclose(fh);
return 0;
}
+int data_template_write_to_file(const DataTemplate *dtempl, const char *filename)
+{
+ FILE *fh;
+ int r;
+ fh = fopen(filename, "w");
+ if ( fh == NULL ) return 1;
+ r = data_template_write_to_fh(dtempl, fh);
+ fclose(fh);
+ return r;
+}
+
+
static void add_group_info(struct dg_group_info *ginfo, int *ppos,
struct panel_group_template *group,
int serial, int level, int c_mul)
diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h
index 07f2387d..419d73b8 100644
--- a/libcrystfel/src/datatemplate.h
+++ b/libcrystfel/src/datatemplate.h
@@ -103,6 +103,8 @@ extern int data_template_rotate_group(DataTemplate *dtempl,
const char *group_name,
double ang, char axis);
+extern int data_template_write_to_fh(const DataTemplate *dtempl, FILE *fh);
+
extern int data_template_write_to_file(const DataTemplate *dtempl,
const char *filename);
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 0273c69b..e767b59f 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -1253,8 +1253,26 @@ void stream_write_indexing_methods(Stream *st, const char *indm_str)
* \param st A \ref Stream
* \param geom_filename geomtry file name
*
- * Writes the content of the geometry file to \p st. This should usually be
- * called immediately after \ref write_command.
+ * Writes the content of the geometry file to \p st. This (or
+ * \ref stream_write_geometry_file) should usually be called immediately after
+ * \ref write_command.
+ */
+void stream_write_data_template(Stream *st, const DataTemplate *dtempl)
+{
+ fprintf(st->fh, STREAM_GEOM_START_MARKER"\n");
+ data_template_write_to_fh(dtempl, st->fh);
+ fprintf(st->fh, STREAM_GEOM_END_MARKER"\n");
+ fflush(st->fh);
+}
+
+
+/**
+ * \param st A \ref Stream
+ * \param geom_filename geomtry file name
+ *
+ * Writes the content of the geometry file to \p st. This (or
+ * \ref stream_write_data_template) should usually be called immediately after
+ * \ref write_command.
*/
void stream_write_geometry_file(Stream *st, const char *geom_filename)
{
diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h
index 115d9918..beb620c7 100644
--- a/libcrystfel/src/stream.h
+++ b/libcrystfel/src/stream.h
@@ -95,6 +95,8 @@ extern Stream *stream_open_fd_for_write(int fd,
extern void stream_close(Stream *st);
/* Writing things to stream header */
+extern void stream_write_data_template(Stream *st,
+ const DataTemplate *dtempl);
extern void stream_write_geometry_file(Stream *st,
const char *geom_filename);
extern void stream_write_target_cell(Stream *st,