From 7e5536832b22036a634a74e16073b4762a416e29 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 21 Jul 2021 13:26:37 +0200 Subject: Reduce variable scope where possible --- libcrystfel/src/indexers/asdf.c | 21 ++++++++++++++++----- libcrystfel/src/indexers/felix.c | 2 +- libcrystfel/src/indexers/fromfile.c | 3 ++- libcrystfel/src/indexers/mosflm.c | 5 ++--- libcrystfel/src/indexers/xds.c | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) (limited to 'libcrystfel/src/indexers') diff --git a/libcrystfel/src/indexers/asdf.c b/libcrystfel/src/indexers/asdf.c index 7030a3e7..a1f8f50d 100644 --- a/libcrystfel/src/indexers/asdf.c +++ b/libcrystfel/src/indexers/asdf.c @@ -364,7 +364,7 @@ static float find_ds_fft(double *projections, int N_projections, double d_max, memcpy(projections_sorted, projections, sizeof(double) * n); qsort(projections_sorted, n, sizeof(double), compare_doubles); - int i, k; + int i; int N = fftw.N; // number of points in fft calculation double *in = fftw.in; @@ -376,6 +376,7 @@ static float find_ds_fft(double *projections, int N_projections, double d_max, } for ( i=0; i max) { max = a; @@ -581,8 +582,6 @@ static int refine_asdf_cell(struct asdf_cell *c, gsl_vector **reflections, static int reduce_asdf_cell(struct asdf_cell *cl) { - double a, b, c, alpha, beta, gamma, ab, bc, ca, bb, cc; - gsl_vector *va = gsl_vector_alloc(3); gsl_vector *vb = gsl_vector_alloc(3); gsl_vector *vc = gsl_vector_alloc(3); @@ -591,6 +590,9 @@ static int reduce_asdf_cell(struct asdf_cell *cl) int n = 0; while ( changed ) { + + double a, b, c, alpha, beta, gamma, ab, bc, ca; + n += 1; changed = 0; @@ -612,6 +614,8 @@ static int reduce_asdf_cell(struct asdf_cell *cl) if ( changed == 0 ) { + double bb; + if ( gamma < 90 ) { gsl_vector_scale(vb, -1); gamma = 180 - gamma; @@ -634,6 +638,8 @@ static int reduce_asdf_cell(struct asdf_cell *cl) if ( changed == 0 ) { + double cc; + if ( beta < 90 ) { gsl_vector_scale(vc, -1); beta = 180 - beta; @@ -659,6 +665,9 @@ static int reduce_asdf_cell(struct asdf_cell *cl) } if ( changed == 0 ) { + + double cc; + if ( alpha < 90 ) { gsl_vector_scale(vc, -1); beta = 180 - beta; @@ -901,10 +910,12 @@ static int **generate_triplets(int N_reflections, int N_triplets_max, int *N) return 0; } - int is_in_triplets; n = 0; while ( n < N_triplets ) { + + int is_in_triplets; + /* Generate three different integer numbers < N_reflections */ i = rand() % N_reflections; j = i; diff --git a/libcrystfel/src/indexers/felix.c b/libcrystfel/src/indexers/felix.c index b7d2a8a3..db7da8c4 100644 --- a/libcrystfel/src/indexers/felix.c +++ b/libcrystfel/src/indexers/felix.c @@ -131,7 +131,6 @@ static int read_felix(struct felix_private *gp, struct image *image, float mean_ia; int ngv; char line[1024]; - int r; int n_crystals = 0; fh = fopen(filename, "r"); @@ -151,6 +150,7 @@ static int read_felix(struct felix_private *gp, struct image *image, Crystal *cr; UnitCell *cell; + int r; /* One line per grain */ if ( fgets( line, 1024, fh ) == NULL ) { diff --git a/libcrystfel/src/indexers/fromfile.c b/libcrystfel/src/indexers/fromfile.c index d7dfbd09..1716dd66 100644 --- a/libcrystfel/src/indexers/fromfile.c +++ b/libcrystfel/src/indexers/fromfile.c @@ -228,7 +228,6 @@ void *fromfile_prepare(IndexingMethod *indm, struct fromfile_options *opts) float vals[11]; struct fromfile_key key; Crystal *cr; - UnitCell *cell; size_t len; int n_sp; struct fromfile_entry *item = NULL; @@ -286,6 +285,8 @@ void *fromfile_prepare(IndexingMethod *indm, struct fromfile_options *opts) } else { + UnitCell *cell; + cr = crystal_new(); /* mm -> m */ diff --git a/libcrystfel/src/indexers/mosflm.c b/libcrystfel/src/indexers/mosflm.c index 129e6859..e77f6384 100644 --- a/libcrystfel/src/indexers/mosflm.c +++ b/libcrystfel/src/indexers/mosflm.c @@ -481,7 +481,6 @@ static char *mosflm_spacegroup_for_lattice(UnitCell *cell) static void mosflm_send_next(struct image *image, struct mosflm_data *mosflm) { char tmp[256]; - char cen; double wavelength; double a = 0, b = 0, c = 0, alpha = 0, beta = 0, gamma = 0; @@ -548,6 +547,7 @@ static void mosflm_send_next(struct image *image, struct mosflm_data *mosflm) case 9 : if ( mosflm->mp->indm & INDEXING_USE_CELL_PARAMETERS ) { + char cen; cell_get_parameters(mosflm->mp->template, &a, &b, &c, &alpha, &beta, &gamma); cen = cell_get_centering(mosflm->mp->template); @@ -886,9 +886,8 @@ const char *mosflm_probe(UnitCell *cell) fh = fdopen(pty, "r"); for ( l=0; l<10; l++ ) { - char *pos; if ( fgets(line, 1024, fh) != NULL ) { - pos = strstr(line, "Mosflm version "); + char *pos = strstr(line, "Mosflm version "); if ( pos != NULL ) ok = 1; } } diff --git a/libcrystfel/src/indexers/xds.c b/libcrystfel/src/indexers/xds.c index 3936f791..8ef496cf 100644 --- a/libcrystfel/src/indexers/xds.c +++ b/libcrystfel/src/indexers/xds.c @@ -523,8 +523,8 @@ const char *xds_probe(UnitCell *cell) fh = fdopen(pty, "r"); for ( l=0; l<10; l++ ) { - char *pos; if ( fgets(line, 1024, fh) != NULL ) { + char *pos; pos = strstr(line, "** XDS **"); if ( pos != NULL ) { ok = 1; -- cgit v1.2.3