diff options
-rw-r--r-- | libcrystfel/src/reflist.c | 1 | ||||
-rw-r--r-- | libcrystfel/src/stream.c | 12 | ||||
-rw-r--r-- | libcrystfel/src/stream.h | 2 | ||||
-rw-r--r-- | src/partialator.c | 8 | ||||
-rw-r--r-- | src/post-refinement.c | 27 |
5 files changed, 34 insertions, 16 deletions
diff --git a/libcrystfel/src/reflist.c b/libcrystfel/src/reflist.c index f1d759ea..9c8a6a14 100644 --- a/libcrystfel/src/reflist.c +++ b/libcrystfel/src/reflist.c @@ -233,6 +233,7 @@ void reflist_free(RefList *list) if ( list->head != NULL ) { recursive_free(list->head); } /* else empty list */ + if ( list->notes != NULL ) free(list->notes); free(list); } diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index bcd2627e..66b3b657 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -1131,6 +1131,18 @@ static void read_crystal(Stream *st, struct image *image, StreamReadFlags srf) } +void free_stuff_from_stream(struct stuff_from_stream *sfs) +{ + int i; + if ( sfs == NULL ) return; + for ( i=0; i<sfs->n_fields; i++ ) { + free(sfs->fields[i]); + } + free(sfs->fields); + free(sfs); +} + + static int read_and_store_field(struct image *image, const char *line) { char **new_fields; diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h index a8e3e2ee..bd7aa690 100644 --- a/libcrystfel/src/stream.h +++ b/libcrystfel/src/stream.h @@ -106,6 +106,8 @@ extern Stream *open_stream_fd_for_write(int fd); extern int get_stream_fd(Stream *st); extern void close_stream(Stream *st); +extern void free_stuff_from_stream(struct stuff_from_stream *sfs); + extern int read_chunk(Stream *st, struct image *image); extern int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf); diff --git a/src/partialator.c b/src/partialator.c index aacf241f..8b4893a5 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -1237,6 +1237,7 @@ int main(int argc, char *argv[]) ERROR("Unknown partiality model '%s'.\n", pmodel_str); return 1; } + free(pmodel_str); } if ( (pmodel == PMODEL_UNITY) && !no_pr ) { @@ -1377,6 +1378,7 @@ int main(int argc, char *argv[]) *image = cur; image->n_crystals = 1; image->crystals = &crystals[n_crystals]; + free(cur.crystals); /* This is the raw list of reflections */ cr_refl = crystal_get_reflections(cr); @@ -1420,6 +1422,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); if ( sparams_fh != NULL ) fclose(sparams_fh); audit_info = stream_audit_info(st); + free(audit_info); close_stream(st); STATUS("Initial partiality calculation...\n"); @@ -1568,7 +1571,12 @@ int main(int argc, char *argv[]) /* Clean up */ gsl_rng_free(rng); for ( i=0; i<n_crystals; i++ ) { + struct image *image = crystal_get_image(crystals[i]); reflist_free(crystal_get_reflections(crystals[i])); + free_stuff_from_stream(image->stuff_from_stream); + free(image->filename); + free(image); + cell_free(crystal_get_cell(crystals[i])); crystal_free(crystals[i]); } free_contribs(full); diff --git a/src/post-refinement.c b/src/post-refinement.c index 4ae72685..fd0d5c4e 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -84,17 +84,14 @@ const char *str_prflag(enum prflag flag) } -static UnitCell *rotate_cell_xy(const UnitCell *cell, double ang1, double ang2) +static void rotate_cell_xy(UnitCell *cell, double ang1, double ang2) { - UnitCell *o; double asx, asy, asz; double bsx, bsy, bsz; double csx, csy, csz; double xnew, ynew, znew; - o = cell_new_from_cell(cell); - - cell_get_reciprocal(o, &asx, &asy, &asz, + cell_get_reciprocal(cell, &asx, &asy, &asz, &bsx, &bsy, &bsz, &csx, &csy, &csz); @@ -134,9 +131,7 @@ static UnitCell *rotate_cell_xy(const UnitCell *cell, double ang1, double ang2) znew = -csx*sin(ang2) + csz*cos(ang2); csx = xnew; csy = ynew; csz = znew; - cell_set_reciprocal(o, asx, asy, asz, bsx, bsy, bsz, csx, csy, csz); - - return o; + cell_set_reciprocal(cell, asx, asy, asz, bsx, bsy, bsz, csx, csy, csz); } @@ -201,7 +196,6 @@ static void apply_parameters(const gsl_vector *v, const gsl_vector *initial, { int i; double ang1, ang2, R, lambda; - UnitCell *cell; /* Default parameters if not used in refinement */ ang1 = 0.0; @@ -240,9 +234,7 @@ static void apply_parameters(const gsl_vector *v, const gsl_vector *initial, } } - cell = rotate_cell_xy(crystal_get_cell_const(cr), ang1, ang2); - crystal_set_cell(cr, cell); - + rotate_cell_xy(crystal_get_cell(cr), ang1, ang2); crystal_set_profile_radius(cr, R); crystal_get_image(cr)->lambda = lambda; } @@ -254,7 +246,6 @@ static double residual_f(const gsl_vector *v, void *pp) RefList *list; struct image im; Crystal *cr; - UnitCell *cell; double res; int i; @@ -263,14 +254,14 @@ static double residual_f(const gsl_vector *v, void *pp) } cr = crystal_copy(pv->cr); - cell = cell_new_from_cell(crystal_get_cell(cr)); - if ( cell == NULL ) return GSL_NAN; - crystal_set_cell(cr, cell); im = *crystal_get_image(cr); crystal_set_image(cr, &im); + crystal_set_cell(cr, cell_new_from_cell(crystal_get_cell(cr))); + apply_parameters(v, pv->initial, pv->rv, cr); if ( fabs(crystal_get_profile_radius(cr)) > 5e9 ) { + cell_free(crystal_get_cell(cr)); crystal_free(cr); if ( pv->verbose ) STATUS("radius > 5e9\n"); return GSL_NAN; @@ -278,12 +269,14 @@ static double residual_f(const gsl_vector *v, void *pp) /* Can happen with grid scans and certain --force-radius values */ if ( fabs(crystal_get_profile_radius(cr)) < 0.0000001e9 ) { + cell_free(crystal_get_cell(cr)); crystal_free(cr); if ( pv->verbose ) STATUS("radius very small\n"); return GSL_NAN; } if ( im.lambda <= 0.0 ) { + cell_free(crystal_get_cell(cr)); crystal_free(cr); if ( pv->verbose ) STATUS("lambda < 0\n"); return GSL_NAN; @@ -296,6 +289,8 @@ static double residual_f(const gsl_vector *v, void *pp) calculate_partialities(cr, PMODEL_XSPHERE); if ( scale_one_crystal(cr, pv->full, pv->scaleflags) ) { + cell_free(crystal_get_cell(cr)); + reflist_free(crystal_get_reflections(cr)); crystal_free(cr); if ( pv->verbose ) STATUS("Bad scaling\n"); return GSL_NAN; |