diff options
author | Thomas White <taw@physics.org> | 2020-08-04 15:25:19 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2020-08-04 15:25:19 +0200 |
commit | 43b71428b68e94d22c2c5f9e8a25b1b46bc04a4c (patch) | |
tree | 435b99f1a487c6144d7ec74a60cd5c3f0a784215 /libcrystfel/src/datatemplate.c | |
parent | a09f8c4cd9c4abe04b99129af07e51fdc5dad4b1 (diff) |
Add image_create_for_simulation()
...and factorise common code
Diffstat (limited to 'libcrystfel/src/datatemplate.c')
-rw-r--r-- | libcrystfel/src/datatemplate.c | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index 5941109e..43313441 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1383,107 +1383,6 @@ void data_template_add_copy_header(DataTemplate *dt, } -static double unit_string_to_unit(const char *str) -{ - if ( strcmp(str, "mm") == 0 ) return 1e-3; - if ( strcmp(str, "m") == 0 ) return 1.0; - ERROR("Invalid length unit '%s'\n", str); - return NAN; -} - - -static double dt_get_length(const char *from) -{ - double units; - char *sp; - char *fromcpy; - double val; - char *rval; - - if ( from == NULL ) return NAN; - - fromcpy = strdup(from); - if ( fromcpy == NULL ) return NAN; - - sp = strchr(fromcpy, ' '); - if ( sp == NULL ) { - units = 1.0e-3; - } else { - units = unit_string_to_unit(sp+1); - } - - sp[0] = '\0'; - val = strtod(fromcpy, &rval); - if ( !( (*rval == '\0') && (rval != fromcpy)) ) { - ERROR("Invalid length value: %s\n", fromcpy); - free(fromcpy); - return NAN; - } - - return val * units; -} - - -/* If possible, i.e. if there are no references to image headers in - * 'dt', generate a detgeom structure from it. - * - * NB This is probably not the function you're looking for! - * The detgeom structure should normally come from loading an image, - * reading a stream or similar. This function should only be used - * when there is really no data involved, e.g. in make_pixelmap. - */ -struct detgeom *data_template_to_detgeom(const DataTemplate *dt) -{ - struct detgeom *detgeom; - int i; - - if ( dt == NULL ) return NULL; - - detgeom = malloc(sizeof(struct detgeom)); - if ( detgeom == NULL ) return NULL; - - detgeom->panels = malloc(dt->n_panels*sizeof(struct detgeom_panel)); - if ( detgeom->panels == NULL ) return NULL; - - detgeom->n_panels = dt->n_panels; - - for ( i=0; i<dt->n_panels; i++ ) { - - detgeom->panels[i].name = safe_strdup(dt->panels[i].name); - - detgeom->panels[i].pixel_pitch = dt->panels[i].pixel_pitch; - - /* NB cnx,cny are in pixels, cnz is in m */ - detgeom->panels[i].cnx = dt->panels[i].cnx; - detgeom->panels[i].cny = dt->panels[i].cny; - detgeom->panels[i].cnz = dt_get_length(dt->panels[i].cnz_from); - - /* Apply offset (in m) and then convert cnz from - * m to pixels */ - detgeom->panels[i].cnz += dt->panels[i].cnz_offset; - detgeom->panels[i].cnz /= detgeom->panels[i].pixel_pitch; - - detgeom->panels[i].max_adu = dt->panels[i].max_adu; - detgeom->panels[i].adu_per_photon = 1.0; /* FIXME ! */ - - detgeom->panels[i].w = dt->panels[i].orig_max_fs - - dt->panels[i].orig_min_fs + 1; - detgeom->panels[i].h = dt->panels[i].orig_max_ss - - dt->panels[i].orig_min_ss + 1; - - detgeom->panels[i].fsx = dt->panels[i].fsx; - detgeom->panels[i].fsy = dt->panels[i].fsy; - detgeom->panels[i].fsz = dt->panels[i].fsz; - detgeom->panels[i].ssx = dt->panels[i].ssx; - detgeom->panels[i].ssy = dt->panels[i].ssy; - detgeom->panels[i].ssz = dt->panels[i].ssz; - - } - - return detgeom; -} - - static int dt_num_placeholders(const struct panel_template *p) { int i; |