aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorValerio Mariani <valerio.mariani@desy.de>2014-11-10 14:26:45 +0100
committerThomas White <taw@physics.org>2014-11-10 18:59:34 +0100
commite3135a2154b1aa1c137664030972a09e50b7f1d8 (patch)
treed29d9afc83084411065b0219c3b0c43af551d53d /libcrystfel
parent44fa1b1c46f9cd52fb0f0842a09b1d499e3cf08c (diff)
Copy and Replace when saving geometry
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/detector.c77
-rw-r--r--libcrystfel/src/detector.h4
-rw-r--r--libcrystfel/src/stream.c3
3 files changed, 44 insertions, 40 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index 9533e264..39a84b6c 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -1604,60 +1604,61 @@ void get_pixel_extents(struct detector *det,
}
-int write_detector_geometry(const char *filename, struct detector *det)
+int write_detector_geometry(const char* geometry_filename,
+ const char *output_filename, struct detector *det)
{
- struct panel *p;
- int pi;
+ FILE *ifh;
FILE *fh;
- if ( filename == NULL ) return 2;
+ if ( geometry_filename == NULL ) return 2;
+ if ( output_filename == NULL ) return 2;
if ( det->n_panels < 1 ) return 3;
- fh = fopen(filename, "w");
- if ( fh == NULL ) return 1;
+ ifh = fopen(geometry_filename, "r");
+ if ( ifh == NULL ) return 1;
- for ( pi=0; pi<det->n_panels; pi++) {
+ fh = fopen(output_filename, "w");
+ if ( fh == NULL ) return 1;
- p = &(det->panels[pi]);
+ do {
- if ( p == NULL ) return 4;
+ char *rval;
+ char line[1024];
+ int n_bits;
+ char **bits;
+ int i;
+ struct panel *p;
- if ( pi > 0 ) fprintf(fh, "\n");
+ rval = fgets(line, 1023, ifh);
+ if ( rval == NULL ) break;
- fprintf(fh, "%s/min_fs = %d\n", p->name, p->min_fs);
- fprintf(fh, "%s/min_ss = %d\n", p->name, p->min_ss);
- fprintf(fh, "%s/max_fs = %d\n", p->name, p->max_fs);
- fprintf(fh, "%s/max_ss = %d\n", p->name, p->max_ss);
- fprintf(fh, "%s/badrow_direction = %C\n", p->name, p->badrow);
- fprintf(fh, "%s/res = %g\n", p->name, p->res);
- fprintf(fh, "%s/clen = %s\n", p->name, p->clen_from);
- fprintf(fh, "%s/fs = %+fx %+fy\n", p->name, p->fsx, p->fsy);
- fprintf(fh, "%s/ss = %+fx %+fy\n", p->name, p->ssx, p->ssy);
- fprintf(fh, "%s/corner_x = %g\n", p->name, p->cnx);
- fprintf(fh, "%s/corner_y = %g\n", p->name, p->cny);
- fprintf(fh, "%s/adu_per_eV = %g\n", p->name, p->adu_per_eV);
- fprintf(fh, "%s/max_adu = %g\n", p->name, p->max_adu);
+ n_bits = assplode(line, "/", &bits, ASSPLODE_NONE);
- if ( p->no_index ) {
- fprintf(fh, "%s/no_index = 1\n", p->name);
- } /* else don't clutter up the file */
+ if ( n_bits < 2 || n_bits > 2 ) {
+ for ( i=0; i<n_bits; i++ ) free(bits[i]);
+ fputs(line, fh);
+ } else {
+ p = find_panel_by_name(det, bits[0]);
+
+ if ( strncmp(bits[1], "fs = ", 5) == 0) {
+ fprintf(fh, "%s/fs = %+fx %+fy\n", p->name, p->fsx, p->fsy);
+ } else if ( strncmp(bits[1], "ss = ", 5) == 0) {
+ fprintf(fh, "%s/ss = %+fx %+fy\n", p->name, p->ssx, p->ssy);
+ } else if ( strncmp(bits[1], "corner_x = ", 11) == 0) {
+ fprintf(fh, "%s/corner_x = %g\n", p->name, p->cnx);
+ } else if ( strncmp(bits[1], "corner_y = ", 11) == 0) {
+ fprintf(fh, "%s/corner_y = %g\n", p->name, p->cny);
+ } else {
+ fputs(line, fh);
+ }
- if ( p->rigid_group != NULL ) {
- fprintf(fh, "%s/rigid_group = %s\n",
- p->name, p->rigid_group->name);
- }
+ for ( i=0; i<n_bits; i++ ) free(bits[i]);
- if ( p->data != NULL ) {
- fprintf(fh, "%s/data = %s\n",
- p->name, p->data);
}
- if ( p->mask != NULL ) {
- fprintf(fh, "%s/mask = %s\n",
- p->name, p->mask);
- }
+ } while ( 1 );
- }
+ fclose(ifh);
fclose(fh);
return 0;
diff --git a/libcrystfel/src/detector.h b/libcrystfel/src/detector.h
index 1cd4c607..2cec61c2 100644
--- a/libcrystfel/src/detector.h
+++ b/libcrystfel/src/detector.h
@@ -221,7 +221,9 @@ extern double smallest_q(struct image *image);
extern struct panel *find_panel_by_name(struct detector *det, const char *name);
-extern int write_detector_geometry(const char *filename, struct detector *det);
+extern int write_detector_geometry(const char* geometry_filename,
+ const char *output_filename, struct detector *det);
+
extern void mark_resolution_range_as_bad(struct image *image,
double min, double max);
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 07568024..988570bc 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -266,7 +266,8 @@ static RefList *read_stream_reflections_2_3(FILE *fh, struct detector *det)
double ph;
char *v;
struct panel *p;
- float write_fs, write_ss;
+ float write_fs = 0;
+ float write_ss = 0;
refl = add_refl(out, h, k, l);
set_intensity(refl, intensity);