aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2013-02-19 14:35:00 +0100
committerThomas White <taw@physics.org>2013-02-19 14:35:00 +0100
commitb6f9a2f6b7efe10b7d2746e907210d9248ffe9fe (patch)
tree6d1cb4e99426eb3b569b0f2943f1c3cb02defedd
parent8eb104ce1ee5a7acb46dfb8ea18c6cc08ed7b11b (diff)
Tidy up etc
-rw-r--r--libcrystfel/src/xds.c144
1 files changed, 68 insertions, 76 deletions
diff --git a/libcrystfel/src/xds.c b/libcrystfel/src/xds.c
index 4034a8e4..84cf828a 100644
--- a/libcrystfel/src/xds.c
+++ b/libcrystfel/src/xds.c
@@ -253,25 +253,30 @@ static int read_cell(const char *filename, struct image *image,
do {
rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) return 0;
} while ( strcmp(line, " # COORDINATES OF REC. BASIS VECTOR"
" LENGTH 1/LENGTH\n") != 0 );
/* Free line after chunk */
rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) return 0;
rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) return 0;
memcpy(asx, line+7, 10); asx[10] = '\0';
memcpy(asy, line+17, 10); asy[10] = '\0';
memcpy(asz, line+27, 10); asz[10] = '\0';
rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) return 0;
memcpy(bsx, line+7, 10); bsx[10] = '\0';
memcpy(bsy, line+17, 10); bsy[10] = '\0';
memcpy(bsz, line+27, 10); bsz[10] = '\0';
rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) return 0;
memcpy(csx, line+7, 10); csx[10] = '\0';
memcpy(csy, line+17, 10); csy[10] = '\0';
@@ -377,64 +382,6 @@ static void write_spot(struct image *image, const char *filename)
}
-static char *write_inp(struct image *image, struct xds_private *xp)
-{
- FILE *fh;
- char *filename;
- const char *spacegroup_for_lattice;
- double a, b, c, al, be, ga;
-
- filename = malloc(1024);
- if ( filename == NULL ) return NULL;
-
- snprintf(filename, 1023, "XDS.INP");
-
- fh = fopen(filename, "w");
- if ( !fh ) {
- ERROR("Couldn't open temporary file '%s'\n", filename);
- free(filename);
- return NULL;
- }
-
- fprintf(fh, "JOB= IDXREF\n");
- fprintf(fh, "ORGX= 1500\n");
- fprintf(fh, "ORGY= 1500\n");
- fprintf(fh, "DETECTOR_DISTANCE= 99.00\n"); //IMPORTANT
- fprintf(fh, "OSCILLATION_RANGE= 0.300\n");
- fprintf(fh, "X-RAY_WAVELENGTH= %.6f\n", image->lambda*1e10);
- fprintf(fh, "NAME_TEMPLATE_OF_DATA_FRAMES=/home/ins_ssad_1_???.img \n");
- fprintf(fh, "DATA_RANGE=1 1\n");
- fprintf(fh, "SPOT_RANGE=1 1\n");
- //symm = spacegroup_for_lattice(xds->xp->template);
- fprintf(fh, "SPACE_GROUP_NUMBER= %s\n", spacegroup_for_lattice);
- cell_get_parameters(xp->cell, &a, &b, &c, &al, &be, &ga);
- fprintf(fh, "UNIT_CELL_CONSTANTS= %.6f %.6f %.6f %.6f %.6f %.6f P\n",
- a*1e10, b*1e10, c*1e10,rad2deg(al), rad2deg(be), rad2deg(ga));
- //fprintf(fh, "SPACE_GROUP_NUMBER= 0\n");
- //fprintf(fh, "UNIT_CELL_CONSTANTS= 0 0 0 0 0 0\n");
- fprintf(fh, "NX= 3000\n");
- fprintf(fh, "NY= 3000\n");
- fprintf(fh, "QX= 0.07\n");
- fprintf(fh, "QY= 0.07\n");
- fprintf(fh, "INDEX_ORIGIN=0 0 0\n");
- fprintf(fh, "DIRECTION_OF_DETECTOR_X-AXIS=1 0 0\n");
- fprintf(fh, "DIRECTION_OF_DETECTOR_Y-AXIS=0 1 0\n");
- fprintf(fh, "INCIDENT_BEAM_DIRECTION=0 0 1\n");
- fprintf(fh, "ROTATION_AXIS=0 1 0\n");
- fprintf(fh, "DETECTOR= CSPAD\n");
- fprintf(fh, "MINIMUM_VALID_PIXEL_VALUE= 1\n");
- fprintf(fh, "OVERLOAD= 200000000\n");
- fprintf(fh, "INDEX_ERROR= 0.4\n");
- //fprintf(fh, "INDEX_QUALITY= 0.5\n");
- //fprintf(fh, "REFINE(IDXREF)= ALL\n");
- //fprintf(fh, "MINIMUM_NUMBER_OF_PIXELS_IN_A_SPOT= 1\n");
- //fprintf(fh, "MAXIMUM_ERROR_OF_SPOT_POSITION= 20.0\n");
-
- fclose(fh);
-
- return filename;
-}
-
/* Turn what we know about the unit cell into something which we can give to
* XDS to make it give us only indexing results compatible with the cell. */
static const char *spacegroup_for_lattice(UnitCell *cell)
@@ -453,21 +400,20 @@ static const char *spacegroup_for_lattice(UnitCell *cell)
break;
case L_MONOCLINIC :
- if ( centering != 'P' )
+ if ( centering != 'P' )
{
g = "3";
- } else
- {
+ } else {
g = "5";
}
break;
case L_ORTHORHOMBIC :
if ( centering != 'P' ) {
- g = "16";}
- else if ( centering != 'C' ) {
- g = "20";}
- else if ( centering != 'F' ) {
+ g = "16";
+ } else if ( centering != 'C' ) {
+ g = "20";
+ } else if ( centering != 'F' ) {
g = "22";
} else {
g = "23";
@@ -477,9 +423,7 @@ static const char *spacegroup_for_lattice(UnitCell *cell)
case L_TETRAGONAL :
if ( centering != 'P' ) {
g = "75";
- }
- else
- {
+ } else {
g = "79";
}
break;
@@ -489,7 +433,7 @@ static const char *spacegroup_for_lattice(UnitCell *cell)
g = "143";
} else {
g = "146";
- }
+ }
break;
case L_HEXAGONAL :
@@ -499,19 +443,70 @@ static const char *spacegroup_for_lattice(UnitCell *cell)
case L_CUBIC :
if ( centering != 'P' ) {
g = "195";
- }
- else if ( centering != 'F' ) {
+ } else if ( centering != 'F' ) {
g = "196";
} else {
g = "197";
}
break;
- }
+ }
assert(g != NULL);
return g;
}
+
+static int write_inp(struct image *image, struct xds_private *xp)
+{
+ FILE *fh;
+ double a, b, c, al, be, ga;
+
+ fh = fopen("XDS.INP", "w");
+ if ( !fh ) {
+ ERROR("Couldn't open XDS.INP\n");
+ return 1;
+ }
+
+ fprintf(fh, "JOB= IDXREF\n");
+ fprintf(fh, "ORGX= 1500\n");
+ fprintf(fh, "ORGY= 1500\n");
+ fprintf(fh, "DETECTOR_DISTANCE= 99.00\n"); //IMPORTANT
+ fprintf(fh, "OSCILLATION_RANGE= 0.300\n");
+ fprintf(fh, "X-RAY_WAVELENGTH= %.6f\n", image->lambda*1e10);
+ fprintf(fh, "NAME_TEMPLATE_OF_DATA_FRAMES=/home/ins_ssad_1_???.img \n");
+ fprintf(fh, "DATA_RANGE=1 1\n");
+ fprintf(fh, "SPOT_RANGE=1 1\n");
+ fprintf(fh, "SPACE_GROUP_NUMBER= %s\n",
+ spacegroup_for_lattice(xp->cell));
+ cell_get_parameters(xp->cell, &a, &b, &c, &al, &be, &ga);
+ fprintf(fh, "UNIT_CELL_CONSTANTS= %.6f %.6f %.6f %.6f %.6f %.6f P\n",
+ a*1e10, b*1e10, c*1e10,rad2deg(al), rad2deg(be), rad2deg(ga));
+ //fprintf(fh, "SPACE_GROUP_NUMBER= 0\n");
+ //fprintf(fh, "UNIT_CELL_CONSTANTS= 0 0 0 0 0 0\n");
+ fprintf(fh, "NX= 3000\n");
+ fprintf(fh, "NY= 3000\n");
+ fprintf(fh, "QX= 0.07\n");
+ fprintf(fh, "QY= 0.07\n");
+ fprintf(fh, "INDEX_ORIGIN=0 0 0\n");
+ fprintf(fh, "DIRECTION_OF_DETECTOR_X-AXIS=1 0 0\n");
+ fprintf(fh, "DIRECTION_OF_DETECTOR_Y-AXIS=0 1 0\n");
+ fprintf(fh, "INCIDENT_BEAM_DIRECTION=0 0 1\n");
+ fprintf(fh, "ROTATION_AXIS=0 1 0\n");
+ fprintf(fh, "DETECTOR= CSPAD\n");
+ fprintf(fh, "MINIMUM_VALID_PIXEL_VALUE= 1\n");
+ fprintf(fh, "OVERLOAD= 200000000\n");
+ fprintf(fh, "INDEX_ERROR= 0.4\n");
+ //fprintf(fh, "INDEX_QUALITY= 0.5\n");
+ //fprintf(fh, "REFINE(IDXREF)= ALL\n");
+ //fprintf(fh, "MINIMUM_NUMBER_OF_PIXELS_IN_A_SPOT= 1\n");
+ //fprintf(fh, "MAXIMUM_ERROR_OF_SPOT_POSITION= 20.0\n");
+
+ fclose(fh);
+
+ return 0;
+}
+
+
int run_xds(struct image *image, IndexingPrivate *priv)
{
unsigned int opts;
@@ -519,7 +514,6 @@ int run_xds(struct image *image, IndexingPrivate *priv)
int rval;
int n;
struct xds_data *xds;
- char *inp_filename;
struct xds_private *xp = (struct xds_private *)priv;
xds = malloc(sizeof(struct xds_data));
@@ -530,9 +524,7 @@ int run_xds(struct image *image, IndexingPrivate *priv)
xds->target_cell = xp->cell;
- write_inp(image, xp);
-
- if ( inp_filename == NULL ) {
+ if ( write_inp(image, xp) ) {
ERROR("Failed to write XDS.INP file for XDS.\n");
return 0;
}