aboutsummaryrefslogtreecommitdiff
path: root/src/stream.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-02-12 12:40:21 -0800
committerThomas White <taw@physics.org>2012-02-22 15:27:14 +0100
commitad522bed9dbe10716e598ff1de6ff2453d934cd5 (patch)
tree078004f8ee578da3d35ba9345717799a12d68b0d /src/stream.c
parent3b4aa01a4fc53b0467c81e1cdea5b8bf103256ff (diff)
Fix stream handling
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c125
1 files changed, 21 insertions, 104 deletions
diff --git a/src/stream.c b/src/stream.c
index d6a91be9..69d64bae 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -42,44 +42,6 @@ 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;
@@ -87,11 +49,6 @@ 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");
@@ -116,89 +73,49 @@ static UnitCell *read_orientation_matrix(FILE *fh)
}
-static UnitCell *read_orientation_matrix_rick(FILE *fh)
-{
- float a, b, c;
- struct rvec as, bs, cs;
- UnitCell *cell;
- char line[1024];
-
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "%f %f %f", &a, &b, &c) != 3 ) {
- ERROR("Couldn't read a-star\n");
- return NULL;
- }
- as.u = a*1e10; bs.u = b*1e10; cs.u = c*1e10;
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "%f %f %f", &a, &b, &c) != 3 ) {
- ERROR("Couldn't read b-star\n");
- return NULL;
- }
- as.v = a*1e10; bs.v = b*1e10; cs.v = c*1e10;
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "%f %f %f", &a, &b, &c) != 3 ) {
- ERROR("Couldn't read c-star\n");
- return NULL;
- }
- as.w = -a*1e10; bs.w = -b*1e10; cs.w = -c*1e10;
- cell = cell_new_from_axes(as, bs, cs);
-
- return cell;
-}
-
-
int find_chunk(FILE *fh, UnitCell **cell, char **filename, double *ev)
{
char line[1024];
char *rval = NULL;
+ int have_ev = 0;
+ int have_cell = 0;
do {
+ long pos = ftell(fh);
+
rval = fgets(line, 1023, fh);
if ( rval == NULL ) continue;
chomp(line);
- if ( strncmp(line, "photon_energy_eV = ", 19) == 0 ) {
- *ev = atof(line+19);
- }
-
- /* Look for the first line of a chunk */
- if ( (strncmp(line, "Reflections from indexing", 25) != 0)
- && (strncmp(line, "## h5FilePath:", 14) != 0 ) ) {
- continue;
- }
-
- /* Read in "Tom Mode"? */
if ( strncmp(line, "Reflections from indexing", 25) == 0 ) {
*filename = strdup(line+29);
- *cell = read_orientation_matrix(fh);
+ *cell = NULL;
+ *ev = 0.0;
+ have_cell = 0;
+ have_ev = 0;
}
- /* Read in "Rick Mode"? */
- if ( strncmp(line, "## h5FilePath:", 14) == 0 ) {
-
- /* Filename is on next line */
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
- chomp(line);
- *filename = strdup(line);
- /* Look for the start of the orientation matrix */
- do {
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
- } while ( strncmp(line, "## A:", 5) != 0 );
- *cell = read_orientation_matrix_rick(fh);
+ if ( strncmp(line, "astar = ", 8) == 0 ) {
+ fseek(fh, pos, 0);
+ *cell = read_orientation_matrix(fh);
+ have_cell = 1;
}
- if ( *cell == NULL ) {
- STATUS("Got filename but no cell for %s\n", *filename);
- continue;
+ if ( strncmp(line, "photon_energy_eV = ", 19) == 0 ) {
+ *ev = atof(line+19);
+ have_ev = 1;
}
- return 0;
+ if ( strlen(line) == 0 ) {
+ if ( have_cell && have_ev ) {
+ fseek(fh, pos, 0);
+ return 0;
+ }
+ }
} while ( rval != NULL );