aboutsummaryrefslogtreecommitdiff
path: root/src/stream.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-02-02 21:26:02 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:12 +0100
commit7d746322e9c108c51c4a8d6d04390338438c2fb0 (patch)
tree895aac81328a88d590b6c8aa4164dec6358754ac /src/stream.c
parentdff453f01aa4f45b1c89349123b81ca9286439a0 (diff)
Fix stream reading
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/stream.c b/src/stream.c
index b56c20ce..a3fb24c2 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -42,6 +42,44 @@ int count_patterns(FILE *fh)
}
+static int find_cell(FILE *fh)
+{
+ int done = 0;
+ int found = 0;
+
+ do {
+
+ long pos;
+ char *rval;
+ float u, v, w;
+ char line[1024];
+
+ pos = ftell(fh);
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) {
+ STATUS("Read error in find_cell()\n");
+ done = 1;
+ }
+
+ chomp(line);
+
+ if ( strncmp(line, "Reflections from indexing", 25) == 0 ) {
+ done = 1;
+ }
+
+ if ( sscanf(line, "astar = %f %f %f", &u, &v, &w) == 3 ) {
+ fseek(fh, pos, SEEK_SET);
+ done = 1;
+ found = 1;
+ }
+
+ } while ( !done );
+
+ return found;
+}
+
+
static UnitCell *read_orientation_matrix(FILE *fh)
{
float u, v, w;
@@ -49,6 +87,11 @@ static UnitCell *read_orientation_matrix(FILE *fh)
UnitCell *cell;
char line[1024];
+ if ( find_cell(fh) == 0 ) {
+ ERROR("Couldn't find orientation matrix.\n");
+ return NULL;
+ }
+
if ( fgets(line, 1023, fh) == NULL ) return NULL;
if ( sscanf(line, "astar = %f %f %f", &u, &v, &w) != 3 ) {
ERROR("Couldn't read a-star\n");
@@ -128,11 +171,6 @@ int find_chunk(FILE *fh, UnitCell **cell, char **filename)
if ( strncmp(line, "Reflections from indexing", 25) == 0 ) {
*filename = strdup(line+29);
- /* Skip two lines */
- for ( i=0; i<2; i++ ) {
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
- }
*cell = read_orientation_matrix(fh);
}