diff options
author | Thomas White <taw@physics.org> | 2021-07-21 13:26:37 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-07-21 15:34:33 +0200 |
commit | 7e5536832b22036a634a74e16073b4762a416e29 (patch) | |
tree | 25799eb139d235f524a80c53fb25d0c9f64eb6f1 /src | |
parent | 760f17f56b7f79f67a9029cbe7cc55a0acccd3b9 (diff) |
Reduce variable scope where possible
Diffstat (limited to 'src')
-rw-r--r-- | src/ambigator.c | 3 | ||||
-rw-r--r-- | src/check_hkl.c | 2 | ||||
-rw-r--r-- | src/cl-utils.c | 7 | ||||
-rw-r--r-- | src/get_hkl.c | 2 | ||||
-rw-r--r-- | src/gui_project.c | 3 | ||||
-rw-r--r-- | src/im-zmq.c | 3 | ||||
-rw-r--r-- | src/indexamajig.c | 9 | ||||
-rw-r--r-- | src/list_events.c | 2 | ||||
-rw-r--r-- | src/partial_sim.c | 13 | ||||
-rw-r--r-- | src/pattern_sim.c | 4 | ||||
-rw-r--r-- | src/post-refinement.c | 8 | ||||
-rw-r--r-- | src/process_hkl.c | 11 | ||||
-rw-r--r-- | src/render_hkl.c | 3 | ||||
-rw-r--r-- | src/time-accounts.c | 2 | ||||
-rw-r--r-- | src/whirligig.c | 3 |
15 files changed, 39 insertions, 36 deletions
diff --git a/src/ambigator.c b/src/ambigator.c index 1657bfb6..02252cd7 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -119,7 +119,6 @@ static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, signed int h, k, l; signed int ha, ka, la; Reflection *cr; - double res; int group = 0; get_indices(refl, &h, &k, &l); @@ -127,7 +126,7 @@ static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, if ( cell == NULL ) { ERROR("Can't calculate resolution cutoff - no cell\n"); } else { - res = 2.0*resolution(cell, h, k, l); + double res = 2.0*resolution(cell, h, k, l); if ( res < rmin ) continue; if ( res > rmax ) continue; if ( auto_res ) { diff --git a/src/check_hkl.c b/src/check_hkl.c index c4532f31..aa972a7f 100644 --- a/src/check_hkl.c +++ b/src/check_hkl.c @@ -350,12 +350,12 @@ static void wilson_plot(RefList *list, UnitCell *cell, const SymOpList *sym, } else { int bs = (pow(3.125e9/2.0, 2.0) - s2min)/s2step + 1; double lnk, minus2B, cov00, cov01, cov11, sumsq; - double B; if ( nbins - bs < 3 ) { ERROR("Not enough bins to estimate B factor\n"); ERROR("Resolution of data, or number of bins, is too " "low.\n"); } else { + double B; double *s2fit; double *lnifit; int nbfit = 0; diff --git a/src/cl-utils.c b/src/cl-utils.c index c2c1bf1d..1b6667c4 100644 --- a/src/cl-utils.c +++ b/src/cl-utils.c @@ -188,7 +188,7 @@ cl_device_id get_cl_dev(cl_context ctx, int n) cl_device_id *dev; cl_int r; size_t size; - int i, num_devs; + int num_devs; /* Get the required size of the array */ r = clGetContextInfo(ctx, CL_CONTEXT_DEVICES, 0, NULL, &size); @@ -212,6 +212,8 @@ cl_device_id get_cl_dev(cl_context ctx, int n) if ( n < 0 ) { + int i; + STATUS("Available devices:\n"); for ( i=0; i<num_devs; i++ ) { @@ -267,7 +269,6 @@ cl_program load_program_from_string(const char *source_in, size_t len, cl_int r; char cflags[1024] = ""; char *insert_pos; - size_t il; char *source; /* Copy the code because we need to zero-terminate it */ @@ -282,6 +283,8 @@ cl_program load_program_from_string(const char *source_in, size_t len, if ( insert_pos != NULL ) { char *source2; + size_t il; + source2 = malloc(strlen(source)+strlen(insert_stuff)+1); if ( source2 == NULL ) { free(source); diff --git a/src/get_hkl.c b/src/get_hkl.c index 4dd9e3fd..b6895f37 100644 --- a/src/get_hkl.c +++ b/src/get_hkl.c @@ -232,7 +232,6 @@ static RefList *twin_reflections(RefList *in, int need_all_parts, signed int he, ke, le; signed int hu, ku, lu; - Reflection *part; int r; get_equiv(holo, m, j, h, k, l, &he, &ke, &le); @@ -262,6 +261,7 @@ static RefList *twin_reflections(RefList *in, int need_all_parts, double i, sigi; int mult; + Reflection *part; part = find_refl(in, hu, ku, lu); diff --git a/src/gui_project.c b/src/gui_project.c index f72af893..7141fcb8 100644 --- a/src/gui_project.c +++ b/src/gui_project.c @@ -602,9 +602,8 @@ static void handle_var(const char *key, const char *val, void clear_project_files(struct crystfelproject *proj) { - int i; - if ( proj->filenames != NULL ) { + int i; for ( i=0; i<proj->n_frames; i++ ) { free(proj->filenames[i]); free(proj->events[i]); diff --git a/src/im-zmq.c b/src/im-zmq.c index 4273b600..3fd04428 100644 --- a/src/im-zmq.c +++ b/src/im-zmq.c @@ -62,7 +62,6 @@ struct im_zmq *im_zmq_connect(const char *zmq_address, const char *zmq_request) { struct im_zmq *z; - int i; z = malloc(sizeof(struct im_zmq)); if ( z == NULL ) return NULL; @@ -93,6 +92,8 @@ struct im_zmq *im_zmq_connect(const char *zmq_address, if ( zmq_request == NULL ) { + int i; + /* SUB mode */ if ( n_subscriptions == 0 ) { ERROR("WARNING: No ZeroMQ subscriptions. You should " diff --git a/src/indexamajig.c b/src/indexamajig.c index d9b0114d..9bbf7e5d 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -166,12 +166,11 @@ static void write_json_radii(FILE *fh, const char *name, static void write_methods(FILE *fh, const char *name, IndexingPrivate *ipriv) { - int i, n; - const IndexingMethod *methods; - fprintf(fh, " \"%s\": [", name); if ( ipriv != NULL ) { + const IndexingMethod *methods; + int i, n; methods = indexing_methods(ipriv, &n); for ( i=0; i<n; i++ ) { fprintf(fh, " \"%s\"", indexer_str(methods[i])); @@ -190,7 +189,6 @@ static void write_harvest_file(struct index_args *args, int if_peaks, int if_checkcell) { FILE *fh; - char *tmp; fh = fopen(filename, "w"); if ( fh == NULL ) { @@ -234,6 +232,9 @@ static void write_harvest_file(struct index_args *args, fprintf(fh, " \"indexing\": null\n"); fprintf(fh, " \"integration\": null\n"); } else { + + char *tmp; + fprintf(fh, " \"indexing\": {\n"); write_methods(fh, "methods", args->ipriv); write_json_cell(fh, "target_cell", args->cell); diff --git a/src/list_events.c b/src/list_events.c index 960c8929..67b27119 100644 --- a/src/list_events.c +++ b/src/list_events.c @@ -153,13 +153,13 @@ int main(int argc, char *argv[]) do { char filename[1024]; - int i; rval = fgets(filename, 1024, ifh); if ( rval != NULL ) { char **evlist; int num_events; + int i; chomp(filename); diff --git a/src/partial_sim.c b/src/partial_sim.c index efba8ebd..ff9a73ac 100644 --- a/src/partial_sim.c +++ b/src/partial_sim.c @@ -98,7 +98,6 @@ static void calculate_partials(Crystal *cr, { Reflection *refl; RefListIterator *iter; - double res; for ( refl = first_refl(crystal_get_reflections(cr), &iter); refl != NULL; @@ -108,6 +107,7 @@ static void calculate_partials(Crystal *cr, Reflection *rfull; double L, p, Ip, If; int bin; + double res; get_indices(refl, &h, &k, &l); get_asymm(sym, h, k, l, &h, &k, &l); @@ -515,9 +515,7 @@ int main(int argc, char *argv[]) int n_threads = 1; char *rval; int i; - FILE *fh; char *phist_file = NULL; - gsl_rng *rng_for_seeds; int config_random = 0; char *image_prefix = NULL; Stream *template_stream = NULL; @@ -969,6 +967,7 @@ int main(int argc, char *argv[]) fclose(fh); } else { + gsl_rng *rng_for_seeds; rng_for_seeds = gsl_rng_alloc(gsl_rng_mt19937); for ( i=0; i<n_threads; i++ ) { qargs.rngs[i] = gsl_rng_alloc(gsl_rng_mt19937); @@ -993,14 +992,16 @@ int main(int argc, char *argv[]) if ( phist_file != NULL ) { - double overall_max = 0.0; - double overall_mean = 0.0; - long long int overall_total = 0; + FILE *fh; fh = fopen(phist_file, "w"); if ( fh != NULL ) { + double overall_max = 0.0; + double overall_mean = 0.0; + long long int overall_total = 0; + for ( i=0; i<NBINS; i++ ) { double rcen; diff --git a/src/pattern_sim.c b/src/pattern_sim.c index 34d6c809..7098869d 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -131,7 +131,6 @@ static void record_panel(struct detgeom_panel *p, float *dp, for ( fs=0; fs<p->w; fs++ ) { double counts; - double cf; double intensity, sa; double pix_area, Lsq; double xs, ys, rx, ry; @@ -165,8 +164,7 @@ static void record_panel(struct detgeom_panel *p, float *dp, if ( do_poisson ) { counts = poisson_noise(rng, intensity * ph_per_e * sa); } else { - cf = intensity * ph_per_e * sa; - counts = cf; + counts = intensity * ph_per_e * sa; } /* Number of photons in pixel */ diff --git a/src/post-refinement.c b/src/post-refinement.c index 27a8cd6a..c6ff3974 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -268,10 +268,8 @@ static void try_reindex(Crystal *crin, const RefList *full, SymOpList *sym, SymOpList *amb, int scaleflags, PartialityModel pmodel) { - RefList *list; Crystal *cr; - UnitCell *cell; - double residual_original, residual_flipped; + double residual_original; int idx, n; if ( sym == NULL || amb == NULL ) return; @@ -285,6 +283,10 @@ static void try_reindex(Crystal *crin, const RefList *full, for ( idx=0; idx<n; idx++ ) { + RefList *list; + UnitCell *cell; + double residual_flipped; + cell = cell_new_from_cell(crystal_get_cell(crin)); if ( cell == NULL ) return; reindex_cell(cell, amb, idx); diff --git a/src/process_hkl.c b/src/process_hkl.c index ed384a4a..b16146e3 100644 --- a/src/process_hkl.c +++ b/src/process_hkl.c @@ -131,9 +131,8 @@ static void plot_histogram(double *vals, int n, float hist_min, float hist_max, step = (max-min)/nbins; for ( i=0; i<n; i++ ) { - int bin; if ( (vals[i] > min) && (vals[i] < max) ) { - bin = (vals[i]-min)/step; + int bin = (vals[i]-min)/step; histo[bin]++; } } @@ -282,7 +281,7 @@ static int merge_crystal(RefList *model, struct image *image, Crystal *cr, Reflection *refl; RefListIterator *iter; RefList *new_refl; - double scale, cc; + double scale; new_refl = crystal_get_reflections(cr); @@ -291,6 +290,7 @@ static int merge_crystal(RefList *model, struct image *image, Crystal *cr, polarisation_correction(new_refl, crystal_get_cell(cr), p); if ( reference != NULL ) { + double cc; if ( do_scale ) { scale = scale_intensities(reference, new_refl, sym); } else { @@ -431,7 +431,6 @@ static int merge_stream(Stream *st, for ( i=0; i<image->n_crystals; i++ ) { - int r; Crystal *cr = image->crystals[i]; n_crystals_seen++; @@ -439,6 +438,7 @@ static int merge_stream(Stream *st, && (crystal_get_resolution_limit(cr) >= min_res) && (flag_even_odd == 2 || n_crystals_seen%2 == flag_even_odd) ) { + int r; n_crystals++; r = merge_crystal(model, image, cr, reference, sym, hist_vals, @@ -889,8 +889,6 @@ int main(int argc, char *argv[]) if ( twopass ) { - RefList *reference; - if ( rewind_all_streams(&stream_list) ) { ERROR("Couldn't rewind stream - scaling cannot be " @@ -899,6 +897,7 @@ int main(int argc, char *argv[]) } else { int r; + RefList *reference; STATUS("Second pass for scaling and/or CCs...\n"); diff --git a/src/render_hkl.c b/src/render_hkl.c index 94d6202a..c47a2c4d 100644 --- a/src/render_hkl.c +++ b/src/render_hkl.c @@ -421,7 +421,6 @@ static void render_za(UnitCell *cell, RefList *list, double max_val; double scale1, scale2, scale; double sep_u, sep_v, max_r; - double u, v; double as, bs, theta; double asx, asy, asz; double bsx, bsy, bsz; @@ -562,6 +561,8 @@ static void render_za(UnitCell *cell, RefList *list, if ( !noaxes ) { + double u, v; + /* Centre marker */ cairo_arc(dctx, (double)cx, (double)cy, max_r, 0, 2*M_PI); diff --git a/src/time-accounts.c b/src/time-accounts.c index 679eb5f1..77ab9b5d 100644 --- a/src/time-accounts.c +++ b/src/time-accounts.c @@ -77,13 +77,13 @@ void time_accounts_free(TimeAccounts *accs) static int find_account(TimeAccounts *accs, enum timeaccount acc) { int i; - static int warned_toomany = 0; for ( i=0; i<accs->n_accs; i++ ) { if ( accs->accs[i] == acc ) return i; } if ( i == MAX_ACCOUNTS ) { + static int warned_toomany = 0; if ( !warned_toomany ) printf("Too many time accounts used!\n"); warned_toomany = 1; return MAX_ACCOUNTS; diff --git a/src/whirligig.c b/src/whirligig.c index 546301ba..611825ba 100644 --- a/src/whirligig.c +++ b/src/whirligig.c @@ -403,8 +403,6 @@ static void connect_series(struct window *win) { while ( win->join_ptr < win->ws ) { - int i; - if ( win->join_ptr == 0 ) { win->join_ptr++; continue; @@ -415,6 +413,7 @@ static void connect_series(struct window *win) /* Try to join this frame to each of the active series */ if ( win->join_ptr > 1 ) { + int i; for ( i=0; i<MAX_SER; i++ ) { if ( win->ser[i][win->join_ptr-1] != -1 ) { try_join(win, i); |