static RefList *read_stream_reflections_2_3(FILE *fh, struct detector *det) { char *rval = NULL; int first = 1; RefList *out; out = reflist_new(); do { char line[1024]; signed int h, k, l; float intensity, sigma, fs, ss, pk, bg; char pn[32]; int r; Reflection *refl; rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; chomp(line); if ( strcmp(line, REFLECTION_END_MARKER) == 0 ) return out; r = sscanf(line, "%i %i %i %f %f %f %f %f %f %s", &h, &k, &l, &intensity, &sigma, &pk, &bg, &fs, &ss, pn); if ( (r != 10) && (!first) ) { reflist_free(out); return NULL; } first = 0; if ( r == 10 ) { struct panel *p; refl = add_refl(out, h, k, l); set_intensity(refl, intensity); if ( det != NULL ) { double write_fs, write_ss; p = find_panel_by_name(det,pn); write_fs = fs - p->orig_min_fs + p->min_fs; write_ss = ss - p->orig_min_ss + p->min_ss; set_detector_pos(refl, write_fs, write_ss); } set_esd_intensity(refl, sigma); set_peak(refl, pk); set_mean_bg(refl, bg); set_redundancy(refl, 1); } } while ( rval != NULL ); /* Got read error of some kind before finding PEAK_LIST_END_MARKER */ return NULL; }
static RefList *read_stream_reflections_2_1(FILE *fh) { char *rval = NULL; int first = 1; RefList *out; out = reflist_new(); do { char line[1024]; signed int h, k, l; float intensity, sigma, fs, ss; char phs[1024]; int cts; int r; Reflection *refl; rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; chomp(line); if ( strcmp(line, REFLECTION_END_MARKER) == 0 ) return out; r = sscanf(line, "%i %i %i %f %s %f %i %f %f", &h, &k, &l, &intensity, phs, &sigma, &cts, &fs, &ss); if ( (r != 9) && (!first) ) { reflist_free(out); return NULL; } first = 0; if ( r == 9 ) { double ph; char *v; refl = add_refl(out, h, k, l); set_intensity(refl, intensity); set_detector_pos(refl, 0.0, fs, ss); set_esd_intensity(refl, sigma); set_redundancy(refl, cts); ph = strtod(phs, &v); if ( v != phs ) set_phase(refl, deg2rad(ph)); } } while ( rval != NULL ); /* Got read error of some kind before finding PEAK_LIST_END_MARKER */ return NULL; }
static RefList *read_stream_reflections(FILE *fh) { char *rval = NULL; int first = 1; RefList *out; out = reflist_new(); do { char line[1024]; signed int h, k, l; float intensity, sigma, fs, ss, pk, bg; int r; Reflection *refl; rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; chomp(line); if ( strcmp(line, REFLECTION_END_MARKER) == 0 ) return out; r = sscanf(line, "%i %i %i %f %f %f %f %f %f", &h, &k, &l, &intensity, &sigma, &pk, &bg, &fs, &ss); if ( (r != 9) && (!first) ) { reflist_free(out); return NULL; } first = 0; if ( r == 9 ) { refl = add_refl(out, h, k, l); set_intensity(refl, intensity); set_detector_pos(refl, 0.0, fs, ss); set_esd_intensity(refl, sigma); set_redundancy(refl, 1); set_peak(refl, pk); set_mean_bg(refl, bg); } } while ( rval != NULL ); /* Got read error of some kind before finding PEAK_LIST_END_MARKER */ return NULL; }
static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, UnitCell *cell, double rmin, double rmax, SymOpList *amb) { Reflection *refl; RefListIterator *iter; RefList *asym; struct flist *f; int n; asym = reflist_new(); if ( asym == NULL ) return NULL; for ( refl = first_refl(in, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; signed int ha, ka, la; Reflection *cr; double res; get_indices(refl, &h, &k, &l); if ( cell == NULL ) { ERROR("Can't calculate resolution cutoff - no cell\n"); } else { res = 2.0*resolution(cell, h, k, l); if ( res < rmin ) continue; if ( res > rmax ) continue; } get_asymm(sym, h, k, l, &ha, &ka, &la); if ( amb != NULL ) { signed int hr, kr, lr; signed int hra, kra, lra; get_equiv(amb, NULL, 0, ha, ka, la, &hr, &kr, &lr); get_asymm(sym, hr, kr, lr, &hra, &kra, &lra); /* Skip twin-proof reflections */ if ( (ha==hra) && (ka==kra) && (la==lra) ) { //STATUS("%i %i %i is twin proof\n", h, k, l); continue; } } cr = find_refl(asym, ha, ka, la); if ( cr == NULL ) { cr = add_refl(asym, ha, ka, la); assert(cr != NULL); copy_data(cr, refl); } else { const double i = get_intensity(cr); const int r = get_redundancy(cr); set_intensity(cr, (r*i + get_intensity(refl))/(r+1)); set_redundancy(cr, r+1); } } f = malloc(sizeof(struct flist)); if ( f == NULL ) { ERROR("Failed to allocate flist\n"); return NULL; } n = num_reflections(asym); f->s = malloc(n*sizeof(unsigned int)); f->s_reidx = malloc(n*sizeof(unsigned int)); f->i = malloc(n*sizeof(float)); f->i_reidx = malloc(n*sizeof(float)); if ( (f->s == NULL) || (f->i == NULL) || (f->s_reidx == NULL) || (f->i_reidx == NULL) ) { ERROR("Failed to allocate flist\n"); return NULL; } f->n = 0; for ( refl = first_refl(asym, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; get_indices(refl, &h, &k, &l); f->s[f->n] = SERIAL(h, k, l); f->i[f->n] = get_intensity(refl); f->n++; } assert(f->n == n); if ( amb != NULL ) { RefList *reidx = reflist_new(); if ( reidx == NULL ) return NULL; for ( refl = first_refl(asym, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; signed int hr, kr, lr; signed int hra, kra, lra; Reflection *cr; get_indices(refl, &h, &k, &l); get_equiv(amb, NULL, 0, h, k, l, &hr, &kr, &lr); get_asymm(sym, hr, kr, lr, &hra, &kra, &lra); cr = add_refl(reidx, hra, kra, lra); copy_data(cr, refl); } n = 0; for ( refl = first_refl(reidx, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; get_indices(refl, &h, &k, &l); f->s_reidx[n] = SERIAL(h, k, l); f->i_reidx[n++] = get_intensity(refl); } reflist_free(reidx); } reflist_free(asym); return f; }