aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel/src/stream.c')
-rw-r--r--libcrystfel/src/stream.c86
1 files changed, 83 insertions, 3 deletions
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 0f4dcd6b..9d97ff98 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -64,6 +64,7 @@ struct _stream
int major_version;
int minor_version;
+ char *audit_info;
long long int ln;
@@ -1334,6 +1335,64 @@ void write_stream_header(FILE *ofh, int argc, char *argv[])
}
+char *stream_audit_info(Stream *st)
+{
+ if ( st->audit_info == NULL ) return NULL;
+ return strdup(st->audit_info);
+}
+
+
+static void read_audit_lines(Stream *st)
+{
+ int done = 0;
+ size_t len = 0;
+ int first = 1;
+
+ st->audit_info = malloc(4096);
+ if ( st->audit_info == NULL ) {
+ ERROR("Failed to allocate memory for audit information\n");
+ return;
+ }
+
+ /* Read lines from stream until one of them starts with "-----",
+ * then rewind to the start of that line */
+ do {
+
+ char line[1024];
+ char *rval;
+ long pos;
+
+ pos = ftell(st->fh);
+
+ rval = fgets(line, 1023, st->fh);
+ if ( rval == NULL ) {
+ ERROR("Failed to read stream audit info.\n");
+ close_stream(st);
+ return;
+ }
+
+ if ( strncmp(line, "-----", 5) == 0 ) {
+ fseek(st->fh, pos, SEEK_SET);
+ done = 1;
+ } else {
+ chomp(line);
+ len += strlen(line);
+ if ( len > 4090 ) {
+ ERROR("Too much audit information.\n");
+ return;
+ } else {
+ if ( !first ) {
+ strcat(st->audit_info, "\n");
+ }
+ first = 0;
+ strcat(st->audit_info, line);
+ }
+ }
+
+ } while ( !done );
+}
+
+
Stream *open_stream_for_read(const char *filename)
{
Stream *st;
@@ -1341,6 +1400,7 @@ Stream *open_stream_for_read(const char *filename)
st = malloc(sizeof(struct _stream));
if ( st == NULL ) return NULL;
st->old_indexers = 0;
+ st->audit_info = NULL;
if ( strcmp(filename, "-") == 0 ) {
st->fh = stdin;
@@ -1383,6 +1443,8 @@ Stream *open_stream_for_read(const char *filename)
st->ln = 1;
+ read_audit_lines(st);
+
return st;
}
@@ -1408,6 +1470,7 @@ Stream *open_stream_fd_for_write(int fd)
st = malloc(sizeof(struct _stream));
if ( st == NULL ) return NULL;
st->old_indexers = 0;
+ st->audit_info = NULL;
st->fh = fdopen(fd, "w");
if ( st->fh == NULL ) {
@@ -1435,12 +1498,13 @@ static void write_cell_to_stream(Stream *st, UnitCell *cell)
/**
- * open_stream_for_write_3
+ * open_stream_for_write_4
* @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
+ * @indm_str: The list of indexing methods
*
* 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
@@ -1448,9 +1512,9 @@ static void write_cell_to_stream(Stream *st, UnitCell *cell)
*
* Returns: a %Stream, or NULL on failure.
*/
-Stream *open_stream_for_write_3(const char *filename,
+Stream *open_stream_for_write_4(const char *filename,
const char *geom_filename, UnitCell *cell,
- int argc, char *argv[])
+ int argc, char *argv[], const char *indm_str)
{
Stream *st;
@@ -1458,6 +1522,7 @@ Stream *open_stream_for_write_3(const char *filename,
st = malloc(sizeof(struct _stream));
if ( st == NULL ) return NULL;
st->old_indexers = 0;
+ st->audit_info = NULL;
st->fh = fopen(filename, "w");
if ( st->fh == NULL ) {
@@ -1477,6 +1542,10 @@ Stream *open_stream_for_write_3(const char *filename,
if ( (argc > 0) && (argv != NULL) ) {
write_command(st, argc, argv);
}
+
+ if ( indm_str != NULL ) {
+ fprintf(st->fh, "Indexing methods selected: %s\n", indm_str);
+ }
if ( geom_filename != NULL ) {
write_geometry_file(st, geom_filename);
}
@@ -1488,6 +1557,15 @@ Stream *open_stream_for_write_3(const char *filename,
}
+Stream *open_stream_for_write_3(const char *filename,
+ const char *geom_filename, UnitCell *cell,
+ int argc, char *argv[])
+{
+ return open_stream_for_write_4(filename, geom_filename, cell,
+ argc, argv, NULL);
+}
+
+
/**
* open_stream_for_write_2
* @filename: Filename of new stream
@@ -1510,6 +1588,7 @@ Stream *open_stream_for_write_2(const char *filename,
st = malloc(sizeof(struct _stream));
if ( st == NULL ) return NULL;
st->old_indexers = 0;
+ st->audit_info = NULL;
st->fh = fopen(filename, "w");
if ( st->fh == NULL ) {
@@ -1576,6 +1655,7 @@ int get_stream_fd(Stream *st)
void close_stream(Stream *st)
{
+ free(st->audit_info);
fclose(st->fh);
free(st);
}