diff options
Diffstat (limited to 'libcrystfel/src/integration.c')
-rw-r--r-- | libcrystfel/src/integration.c | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c index 8b05efe7..d2c06db7 100644 --- a/libcrystfel/src/integration.c +++ b/libcrystfel/src/integration.c @@ -393,7 +393,7 @@ static int alloc_boxes(struct intcontext *ic, int new_max_boxes) { struct peak_box *boxes_new; - boxes_new = realloc(ic->boxes, sizeof(struct peak_box)*new_max_boxes); + boxes_new = cfrealloc(ic->boxes, sizeof(struct peak_box)*new_max_boxes); if ( boxes_new == NULL ) return 1; ic->boxes = boxes_new; @@ -467,7 +467,7 @@ struct intcontext *intcontext_new(struct image *image, int i; struct intcontext *ic; - ic = malloc(sizeof(struct intcontext)); + ic = cfmalloc(sizeof(struct intcontext)); if ( ic == NULL ) return NULL; ic->halfw = ir_out; @@ -481,36 +481,36 @@ struct intcontext *intcontext_new(struct image *image, ic->int_diag = INTDIAG_NONE; ic->w = 2*ic->halfw + 1; - ic->bm = malloc(ic->w * ic->w * sizeof(enum boxmask_val)); + ic->bm = cfmalloc(ic->w * ic->w * sizeof(enum boxmask_val)); if ( ic->bm == NULL ) { ERROR("Failed to allocate box mask.\n"); - free(ic); + cffree(ic); return NULL; } /* How many reference profiles? */ ic->n_reference_profiles = 1; - ic->reference_profiles = calloc(ic->n_reference_profiles, - sizeof(double *)); + ic->reference_profiles = cfcalloc(ic->n_reference_profiles, + sizeof(double *)); if ( ic->reference_profiles == NULL ) { - free(ic); + cffree(ic); return NULL; } - ic->reference_den = calloc(ic->n_reference_profiles, sizeof(double *)); + ic->reference_den = cfcalloc(ic->n_reference_profiles, sizeof(double *)); if ( ic->reference_den == NULL ) { - free(ic); + cffree(ic); return NULL; } - ic->n_profiles_in_reference = calloc(ic->n_reference_profiles, - sizeof(int)); + ic->n_profiles_in_reference = cfcalloc(ic->n_reference_profiles, + sizeof(int)); if ( ic->n_profiles_in_reference == NULL ) { - free(ic); + cffree(ic); return NULL; } for ( i=0; i<ic->n_reference_profiles; i++ ) { - ic->reference_profiles[i] = malloc(ic->w*ic->w*sizeof(double)); + ic->reference_profiles[i] = cfmalloc(ic->w*ic->w*sizeof(double)); if ( ic->reference_profiles[i] == NULL ) return NULL; - ic->reference_den[i] = malloc(ic->w*ic->w*sizeof(double)); + ic->reference_den[i] = cfmalloc(ic->w*ic->w*sizeof(double)); if ( ic->reference_den[i] == NULL ) return NULL; } zero_profiles(ic); @@ -519,7 +519,7 @@ struct intcontext *intcontext_new(struct image *image, ic->n_boxes = 0; ic->max_boxes = 0; if ( alloc_boxes(ic, 32) ) { - free(ic); + cffree(ic); return NULL; } @@ -534,20 +534,20 @@ void intcontext_free(struct intcontext *ic) int i; for ( i=0; i<ic->n_boxes; i++ ) { - free(ic->boxes[i].bm); + cffree(ic->boxes[i].bm); gsl_matrix_free(ic->boxes[i].bgm); } - free(ic->boxes); + cffree(ic->boxes); for ( i=0; i<ic->n_reference_profiles; i++ ) { - free(ic->reference_profiles[i]); - free(ic->reference_den[i]); - } - free(ic->reference_profiles); - free(ic->reference_den); - free(ic->n_profiles_in_reference); - free(ic->bm); - free(ic); + cffree(ic->reference_profiles[i]); + cffree(ic->reference_den[i]); + } + cffree(ic->reference_profiles); + cffree(ic->reference_den); + cffree(ic->n_profiles_in_reference); + cffree(ic->bm); + cffree(ic); } @@ -604,7 +604,7 @@ static void delete_box(struct intcontext *ic, struct peak_box *bx) return; } - free(bx->bm); + cffree(bx->bm); gsl_matrix_free(bx->bgm); memmove(&ic->boxes[i], &ic->boxes[i+1], @@ -803,7 +803,7 @@ static int check_box(struct intcontext *ic, struct peak_box *bx, int *sat) if ( sat != NULL ) *sat = 0; - bx->bm = malloc(ic->w*ic->w*sizeof(enum boxmask_val)); + bx->bm = cfmalloc(ic->w*ic->w*sizeof(enum boxmask_val)); if ( bx->bm == NULL ) { ERROR("Failed to allocate box mask\n"); return 1; @@ -980,7 +980,7 @@ static int center_and_check_box(struct intcontext *ic, struct peak_box *bx, t_offs_fs += ifs; t_offs_ss += iss; - free(bx->bm); + cffree(bx->bm); if ( check_box(ic, bx, sat) ) { return 1; } @@ -1342,17 +1342,16 @@ static void setup_profile_boxes(struct intcontext *ic, RefList *list) void integrate_prof2d(IntegrationMethod meth, - Crystal *cr, struct image *image, IntDiag int_diag, + Crystal *cr, RefList *list, + struct image *image, IntDiag int_diag, signed int idh, signed int idk, signed int idl, double ir_inn, double ir_mid, double ir_out, pthread_mutex_t *term_lock, int **masks) { - RefList *list; UnitCell *cell; struct intcontext *ic; int i; - list = crystal_get_reflections(cr); cell = crystal_get_cell(cr); ic = intcontext_new(image, cell, meth, @@ -1515,7 +1514,7 @@ static double estimate_resolution(Crystal *cr, struct image *image) UnitCell *cell; - acc = malloc(max_acc*sizeof(double)); + acc = cfmalloc(max_acc*sizeof(double)); if ( acc == NULL ) { ERROR("Allocation failed during estimate_resolution!\n"); return INFINITY; @@ -1577,7 +1576,7 @@ static double estimate_resolution(Crystal *cr, struct image *image) if ( n_acc < 3 ) { STATUS("WARNING: Too few peaks to estimate resolution.\n"); - free(acc); + cffree(acc); return 0.0; } @@ -1587,18 +1586,18 @@ static double estimate_resolution(Crystal *cr, struct image *image) if ( n < 2 ) n = 2; max_res = acc[(n_acc-1)-n]; - free(acc); + cffree(acc); return max_res; } static void integrate_rings(IntegrationMethod meth, - Crystal *cr, struct image *image, IntDiag int_diag, + Crystal *cr, RefList *list, + struct image *image, IntDiag int_diag, signed int idh, signed int idk, signed int idl, double ir_inn, double ir_mid, double ir_out, pthread_mutex_t *term_lock, int **masks) { - RefList *list; Reflection *refl; RefListIterator *iter; UnitCell *cell; @@ -1606,7 +1605,6 @@ static void integrate_rings(IntegrationMethod meth, int n_rej = 0; int n_refl = 0; - list = crystal_get_reflections(cr); cell = crystal_get_cell(cr); ic = intcontext_new(image, cell, meth, @@ -1653,23 +1651,21 @@ void integrate_all_5(struct image *image, IntegrationMethod meth, /* Predict all reflections */ for ( i=0; i<image->n_crystals; i++ ) { - RefList *list; double res; - double saved_R = crystal_get_profile_radius(image->crystals[i]); + double saved_R = crystal_get_profile_radius(image->crystals[i].cr); if ( overpredict ) { - crystal_set_profile_radius(image->crystals[i], + crystal_set_profile_radius(image->crystals[i].cr, saved_R * 5); } - res = estimate_resolution(image->crystals[i], image); - crystal_set_resolution_limit(image->crystals[i], res); + res = estimate_resolution(image->crystals[i].cr, image); + crystal_set_resolution_limit(image->crystals[i].cr, res); - list = predict_to_res(image->crystals[i], res+push_res); - crystal_set_reflections(image->crystals[i], list); + image->crystals[i].refls = predict_to_res(image->crystals[i].cr, image, res+push_res); if ( overpredict ) { - crystal_set_profile_radius(image->crystals[i], saved_R); + crystal_set_profile_radius(image->crystals[i].cr, saved_R); } } @@ -1681,22 +1677,26 @@ void integrate_all_5(struct image *image, IntegrationMethod meth, for ( i=0; i<image->n_crystals; i++ ) { - Crystal *cr = image->crystals[i]; - switch ( meth & INTEGRATION_METHOD_MASK ) { case INTEGRATION_NONE : break; case INTEGRATION_RINGS : - integrate_rings(meth, cr, image, + integrate_rings(meth, + image->crystals[i].cr, + image->crystals[i].refls, + image, int_diag, idh, idk, idl, ir_inn, ir_mid, ir_out, term_lock, masks); break; case INTEGRATION_PROF2D : - integrate_prof2d(meth, cr, image, + integrate_prof2d(meth, + image->crystals[i].cr, + image->crystals[i].refls, + image, int_diag, idh, idk, idl, ir_inn, ir_mid, ir_out, term_lock, masks); @@ -1711,7 +1711,7 @@ void integrate_all_5(struct image *image, IntegrationMethod meth, } for ( i=0; i<image->detgeom->n_panels; i++ ) { - free(masks[i]); + cffree(masks[i]); } } @@ -1794,7 +1794,7 @@ char *str_integration_method(IntegrationMethod m) strcat(tmp, "-grad"); } - return strdup(tmp); + return cfstrdup(tmp); } @@ -1854,10 +1854,10 @@ IntegrationMethod integration_method(const char *str, int *err) return INTEGRATION_NONE; } - free(methods[i]); + cffree(methods[i]); } - free(methods); + cffree(methods); return meth; |