diff options
author | Valerio Mariani <valerio.mariani@desy.de> | 2014-11-10 14:26:45 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2014-11-10 18:59:34 +0100 |
commit | e3135a2154b1aa1c137664030972a09e50b7f1d8 (patch) | |
tree | d29d9afc83084411065b0219c3b0c43af551d53d | |
parent | 44fa1b1c46f9cd52fb0f0842a09b1d499e3cf08c (diff) |
Copy and Replace when saving geometry
-rw-r--r-- | libcrystfel/src/detector.c | 77 | ||||
-rw-r--r-- | libcrystfel/src/detector.h | 4 | ||||
-rw-r--r-- | libcrystfel/src/stream.c | 3 | ||||
-rw-r--r-- | src/dw-hdfsee.c | 19 | ||||
-rw-r--r-- | src/dw-hdfsee.h | 8 | ||||
-rw-r--r-- | src/hdfsee.c | 9 |
6 files changed, 68 insertions, 52 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); diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index f4655d0a..e9b6ee86 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1176,7 +1176,7 @@ static gint displaywindow_about(GtkWidget *widget, DisplayWindow *dw) static int save_geometry_file(DisplayWindow *dw) { GtkWidget *d; - gchar * filename; + gchar * output_filename; int w; d = gtk_file_chooser_dialog_new("Save Detector Geometry", @@ -1187,10 +1187,11 @@ static int save_geometry_file(DisplayWindow *dw) NULL); gtk_dialog_run (GTK_DIALOG (d)); - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (d)); - w = write_detector_geometry(filename, dw->image->det); + output_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (d)); + w = write_detector_geometry(dw->geom_filename, output_filename, + dw->image->det); gtk_widget_destroy(d); - g_free(filename); + g_free(output_filename); return w; } @@ -2429,7 +2430,8 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, } -DisplayWindow *displaywindow_open(char *filename, const char *peaks, +DisplayWindow *displaywindow_open(char *filename, char *geom_filename, + const char *peaks, double boost, int binning, int noisefilter, int calibmode, int colscale, const char *element, @@ -2479,6 +2481,7 @@ DisplayWindow *displaywindow_open(char *filename, const char *peaks, dw->multi_event = 0; dw->curr_event = 0; dw->ev_list = NULL; + dw->geom_filename = strdup(geom_filename); dw->image->det = det_geom; dw->image->beam = beam; @@ -2488,6 +2491,7 @@ DisplayWindow *displaywindow_open(char *filename, const char *peaks, dw->hdfile = hdfile_open(filename); if ( dw->hdfile == NULL ) { ERROR("Couldn't open file: %s\n", filename); + free(dw->geom_filename); free(dw); return NULL; } @@ -2502,6 +2506,7 @@ DisplayWindow *displaywindow_open(char *filename, const char *peaks, if ( dw->ev_list == NULL ) { ERROR("Error while parsing file structure\n"); free_event_list(dw->ev_list); + free(dw->geom_filename); free(dw); return NULL; } @@ -2509,6 +2514,7 @@ DisplayWindow *displaywindow_open(char *filename, const char *peaks, ERROR("Multi-event geometry file but no events found " "in data file\n"); free_event_list(dw->ev_list); + free(dw->geom_filename); free(dw); return NULL; } else { @@ -2532,8 +2538,9 @@ DisplayWindow *displaywindow_open(char *filename, const char *peaks, } if ( check ) { ERROR("Couldn't load file\n"); - free(dw); + free(dw->geom_filename); hdfile_close(dw->hdfile); + free(dw->geom_filename); return NULL; } diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h index fc16594d..14c17287 100644 --- a/src/dw-hdfsee.h +++ b/src/dw-hdfsee.h @@ -90,11 +90,13 @@ typedef struct { int not_ready_yet; - struct detector* simple_geom; + struct detector* simple_geom; - struct hdfile *hdfile; + struct hdfile *hdfile; struct image *image; + char *geom_filename; + /* Dialog boxes */ BinningDialog *binning_dialog; BoostIntDialog *boostint_dialog; @@ -137,7 +139,7 @@ typedef struct { } DisplayWindow; /* Open an image display window showing the given filename, or NULL */ -extern DisplayWindow *displaywindow_open(char *filename, +extern DisplayWindow *displaywindow_open(char *filename, char *geom_filename, const char *peaks, double boost, int binning, int noisefilter, int calibmode, diff --git a/src/hdfsee.c b/src/hdfsee.c index cc35b6e0..cdf4ae92 100644 --- a/src/hdfsee.c +++ b/src/hdfsee.c @@ -117,6 +117,7 @@ int main(int argc, char *argv[]) size_t i; int nfiles; char *peaks = NULL; + char *geom_filename = NULL; double boost = 1.0; int binning = 2; int config_noisefilter = 0; @@ -213,7 +214,9 @@ int main(int argc, char *argv[]) break; case 'g' : - det_geom = get_detector_geometry(optarg, &cbeam); + geom_filename = strdup(optarg); + det_geom = get_detector_geometry(geom_filename, &cbeam); + if ( det_geom == NULL ) { ERROR("Failed to read detector geometry from '%s'\n", optarg); @@ -293,8 +296,8 @@ int main(int argc, char *argv[]) free(cscale); for ( i=0; i<nfiles; i++ ) { - main_window_list[i] = displaywindow_open(argv[optind+i], peaks, - boost, binning, + main_window_list[i] = displaywindow_open(argv[optind+i], geom_filename, + peaks, boost, binning, config_noisefilter, config_calibmode, colscale, element, |