From 13d65b9785d1557e29f5f06871d01bad8e76e44c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 21 Jul 2021 15:22:12 +0200 Subject: Clean up shadowed variables --- libcrystfel/src/cell-utils.c | 1 - libcrystfel/src/datatemplate.c | 10 ++++----- libcrystfel/src/image-hdf5.c | 44 +++++++++++++++++++------------------- libcrystfel/src/indexers/dirax.c | 6 +++--- libcrystfel/src/indexers/taketwo.c | 8 +++---- libcrystfel/src/rational.c | 10 ++++----- libcrystfel/src/reflist-utils.c | 1 - libcrystfel/src/stream.c | 16 +++++++------- libcrystfel/src/thread-pool.c | 10 ++++----- src/ambigator.c | 27 ++++++++++++----------- src/cell_tool.c | 22 +++++++++---------- src/crystfel_gui.c | 18 ++++++++-------- src/diffraction-gpu.c | 13 +++++++---- src/gui_backend_slurm.c | 6 +++--- src/gui_project.c | 42 ++++++++++++++++++------------------ src/partialator.c | 37 ++++++++++++++++---------------- src/pattern_sim.c | 26 +++++++++++----------- src/process_hkl.c | 14 ++++++------ src/render_hkl.c | 3 +-- src/whirligig.c | 26 ++++++++++++---------- 20 files changed, 175 insertions(+), 165 deletions(-) diff --git a/libcrystfel/src/cell-utils.c b/libcrystfel/src/cell-utils.c index cdd4156b..5131fb20 100644 --- a/libcrystfel/src/cell-utils.c +++ b/libcrystfel/src/cell-utils.c @@ -982,7 +982,6 @@ UnitCell *load_cell_from_file(const char *filename) do { - char line[1024]; int n1; int i; char **bits; diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index a2b974a7..48fe4cfa 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1122,10 +1122,10 @@ DataTemplate *data_template_new_from_string(const char *string_in) /* Copy the next line from the big string */ const char *nl = strchr(string, '\n'); if ( nl != NULL ) { - size_t len = nl - string; - line = strndup(string, nl-string); - line[len] = '\0'; - string += len+1; + size_t nlen = nl - string; + line = strndup(string, nlen); + line[nlen] = '\0'; + string += nlen+1; } else { line = strdup(string); done = 1; @@ -1437,7 +1437,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) for ( rgci=0; rgciname); diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index 494254cc..ec8fc36f 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -814,13 +814,13 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) } else if ( class == H5T_STRING ) { htri_t v; - hid_t type; + hid_t stype; char *val; - int r; + int rv; - type = H5Dget_type(dh); - v = H5Tis_variable_str(type); - H5Tclose(type); + stype = H5Dget_type(dh); + v = H5Tis_variable_str(stype); + H5Tclose(stype); if ( v == 0 ) { val = read_single_fixed_string(dh); @@ -835,16 +835,16 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( val != NULL ) { image_cache_header_str(image, name, val); free(val); - r = 0; + rv = 0; } else { ERROR("Failed to read string '%s'\n", subst_name); - r = 1; + rv = 1; } free(subst_name); close_hdf5(fh); - return r; + return rv; } else { /* Should never be reached */ @@ -956,18 +956,18 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) } else if ( class == H5T_STRING ) { - hid_t type; + hid_t stype; - type = H5Dget_type(dh); - if ( H5Tis_variable_str(type) ) { + stype = H5Dget_type(dh); + if ( H5Tis_variable_str(stype) ) { /* Vlen string from array */ - herr_t r; + herr_t rv; char *val; - r = H5Dread(dh, type, ms, sh, H5P_DEFAULT, &val); - if ( r < 0 ) { + rv = H5Dread(dh, stype, ms, sh, H5P_DEFAULT, &val); + if ( rv < 0 ) { ERROR("Can't read HDF5 vlen string from array - %s\n", subst_name); free(subst_name); @@ -988,20 +988,20 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) /* Fixed-length string from array */ - herr_t r; + herr_t rv; char *val; - size_t size; + size_t ssize; - size = H5Tget_size(type); - val = malloc(size); + ssize = H5Tget_size(stype); + val = malloc(ssize); if ( val == NULL ) { close_hdf5(fh); free(subst_name); return 1; } - r = H5Dread(dh, type, ms, sh, H5P_DEFAULT, val); - H5Tclose(type); - if ( r < 0 ) { + rv = H5Dread(dh, stype, ms, sh, H5P_DEFAULT, val); + H5Tclose(stype); + if ( rv < 0 ) { ERROR("Couldn't read HDF5 fixed string from array - %s\n", subst_name); close_hdf5(fh); @@ -1009,7 +1009,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) return 1; } else { - val[size] = '\0'; + val[ssize] = '\0'; chomp(val); image_cache_header_str(image, name, val); free(val); diff --git a/libcrystfel/src/indexers/dirax.c b/libcrystfel/src/indexers/dirax.c index ef90a3f7..d1be9e7c 100644 --- a/libcrystfel/src/indexers/dirax.c +++ b/libcrystfel/src/indexers/dirax.c @@ -228,10 +228,10 @@ static void dirax_parseline(const char *line, struct image *image, &d, &d, &d, &d, &d, &d, &di) == 9 ) { if ( acl_nh > dirax->best_acl_nh ) { - int i, found = 0; + int i_acl, found = 0; - for ( i=0; in_acls_tried; i++ ) { - if ( dirax->acls_tried[i] == acl ) found = 1; + for ( i_acl=0; i_acln_acls_tried; i_acl++ ) { + if ( dirax->acls_tried[i_acl] == acl ) found = 1; } if ( !found ) { diff --git a/libcrystfel/src/indexers/taketwo.c b/libcrystfel/src/indexers/taketwo.c index 72aa0bad..29598a01 100644 --- a/libcrystfel/src/indexers/taketwo.c +++ b/libcrystfel/src/indexers/taketwo.c @@ -1538,15 +1538,15 @@ static int find_seeds(struct TakeTwoCell *cell, struct taketwo_private *tp) cell->seeds = tmp; - int i; - for ( i = 0; i < seed_num; i++) + int seed_i; + for ( seed_i = 0; seed_i < seed_num; seed_i++) { - if (seeds[i].idx1 < 0 || seeds[i].idx2 < 0) + if (seeds[seed_i].idx1 < 0 || seeds[seed_i].idx2 < 0) { continue; } - cell->seeds[cell->seed_count] = seeds[i]; + cell->seeds[cell->seed_count] = seeds[seed_i]; cell->seed_count++; } diff --git a/libcrystfel/src/rational.c b/libcrystfel/src/rational.c index 76aa7014..db02ee93 100644 --- a/libcrystfel/src/rational.c +++ b/libcrystfel/src/rational.c @@ -460,16 +460,16 @@ int transform_fractional_coords_rtnl(const RationalMatrix *P, rtnl_mtx_get(cm, h, k)); for ( j=0; jcols; j++ ) { - Rational t = rtnl_mtx_get(cm, i, j); + Rational tcol = rtnl_mtx_get(cm, i, j); Rational p = rtnl_mul(dval, rtnl_mtx_get(cm, h, j)); - t = rtnl_sub(t, p); - rtnl_mtx_set(cm, i, j, t); + tcol = rtnl_sub(tcol, p); + rtnl_mtx_set(cm, i, j, tcol); } /* Divide the right hand side as well */ - Rational t = vec[i]; + Rational trhs = vec[i]; Rational p = rtnl_mul(dval, vec[h]); - vec[i] = rtnl_sub(t, p); + vec[i] = rtnl_sub(trhs, p); } h++; diff --git a/libcrystfel/src/reflist-utils.c b/libcrystfel/src/reflist-utils.c index 4a284c07..52cf5e61 100644 --- a/libcrystfel/src/reflist-utils.c +++ b/libcrystfel/src/reflist-utils.c @@ -411,7 +411,6 @@ static RefList *read_reflections_from_file(FILE *fh, char **sym) /* We are now in the notes region */ do { - char line[1024]; rval = fgets(line, 1023, fh); if ( rval == NULL ) continue; chomp(line); diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index 6c716fda..3dc8abcd 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -240,7 +240,7 @@ static RefList *read_stream_reflections_2_3(Stream *st) char line[1024]; signed int h, k, l; float intensity, sigma, fs, ss, pk, bg; - char pn[32]; + char pname[32]; int r; rval = fgets(line, 1023, st->fh); @@ -252,7 +252,7 @@ static RefList *read_stream_reflections_2_3(Stream *st) r = sscanf(line, "%i %i %i %f %f %f %f %f %f %s", &h, &k, &l, &intensity, &sigma, &pk, &bg, - &fs, &ss, pn); + &fs, &ss, pname); if ( (r != 10) && (!first) ) { reflist_free(out); @@ -664,12 +664,12 @@ int stream_write_chunk(Stream *st, const struct image *i, if ( i->detgeom != NULL ) { - int j; + int pn; double tclen = 0.0; - for ( j=0; jdetgeom->n_panels; j++ ) { - tclen += i->detgeom->panels[j].cnz - * i->detgeom->panels[j].pixel_pitch; + for ( pn=0; pndetgeom->n_panels; pn++ ) { + tclen += i->detgeom->panels[pn].cnz + * i->detgeom->panels[pn].pixel_pitch; } fprintf(st->fh, "average_camera_length = %f m\n", tclen / i->detgeom->n_panels); @@ -814,8 +814,8 @@ static void read_crystal(Stream *st, struct image *image, } if ( strncmp(line, "num_saturated_reflections = ", 28) == 0 ) { - int n = atoi(line+28); - crystal_set_num_saturated_reflections(cr, n); + int nsat = atoi(line+28); + crystal_set_num_saturated_reflections(cr, nsat); } if ( sscanf(line, "diffraction_resolution_limit = %f nm^-1", diff --git a/libcrystfel/src/thread-pool.c b/libcrystfel/src/thread-pool.c index 7860d698..0951fcc6 100644 --- a/libcrystfel/src/thread-pool.c +++ b/libcrystfel/src/thread-pool.c @@ -86,11 +86,11 @@ static void *task_worker(void *pargsv) { struct worker_args *w = pargsv; struct task_queue *q = w->tq; - int *cookie; + int *cookie_slot; - cookie = malloc(sizeof(int)); - *cookie = w->id; - pthread_setspecific(status_label_key, cookie); + cookie_slot = malloc(sizeof(int)); + *cookie_slot = w->id; + pthread_setspecific(status_label_key, cookie_slot); free(w); @@ -129,7 +129,7 @@ static void *task_worker(void *pargsv) } while ( 1 ); - free(cookie); + free(cookie_slot); return NULL; } diff --git a/src/ambigator.c b/src/ambigator.c index 02252cd7..a7ec0eae 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -1056,7 +1056,7 @@ int main(int argc, char *argv[]) int n_dif; struct flist **crystals; Stream *st; - int i; + int j; int *assignments; int *orig_assignments; gsl_rng *rng; @@ -1362,6 +1362,7 @@ int main(int argc, char *argv[]) if ( start_ass_fn != NULL ) { FILE *fh; + int i; fh = fopen(start_ass_fn, "r"); if ( fh == NULL ) { ERROR("Failed to open '%s'\n", start_ass_fn); @@ -1387,13 +1388,14 @@ int main(int argc, char *argv[]) free(start_ass_fn); } else { + int i; for ( i=0; i 0.5); } } - for ( i=0; is); - free(crystals[i]->i); - free(crystals[i]->s_reidx); - free(crystals[i]->i_reidx); - free(crystals[i]); + for ( j=0; js); + free(crystals[j]->i); + free(crystals[j]->s_reidx); + free(crystals[j]->i_reidx); + free(crystals[j]); } free(crystals); - for ( i=0; in_blocks; i++ ) { + for ( ijob=0; ijobn_blocks; ijob++ ) { char tmp[128]; char *stderr_filename; - snprintf(tmp, 127, "stderr-%i.log", i); + snprintf(tmp, 127, "stderr-%i.log", ijob); stderr_filename = relative_to_cwd(job->workdir, tmp); n_proc += read_number_processed(stderr_filename); diff --git a/src/gui_project.c b/src/gui_project.c index 7141fcb8..952bbbe6 100644 --- a/src/gui_project.c +++ b/src/gui_project.c @@ -891,7 +891,7 @@ int load_project(struct crystfelproject *proj) int save_project(struct crystfelproject *proj) { - int i; + int ibackend, iresult, iframe; FILE *fh; fh = fopen("crystfel.project", "w"); @@ -986,9 +986,9 @@ int save_project(struct crystfelproject *proj) fprintf(fh, "indexing.backend %s\n", proj->backends[proj->indexing_backend_selected].name); - for ( i=0; in_backends; i++ ) { + for ( ibackend=0; ibackendn_backends; ibackend++ ) { struct crystfel_backend *be; - be = &proj->backends[i]; + be = &proj->backends[ibackend]; be->write_indexing_opts(be->indexing_opts_priv, fh); } @@ -1064,9 +1064,9 @@ int save_project(struct crystfelproject *proj) } fprintf(fh, "ambi.backend %s\n", proj->backends[proj->ambi_backend_selected].name); - for ( i=0; in_backends; i++ ) { + for ( ibackend=0; ibackendn_backends; ibackend++ ) { struct crystfel_backend *be; - be = &proj->backends[i]; + be = &proj->backends[ibackend]; be->write_ambi_opts(be->ambi_opts_priv, fh); } if ( proj->ambi_new_job_title != NULL ) { @@ -1109,9 +1109,9 @@ int save_project(struct crystfelproject *proj) fprintf(fh, "merging.backend %s\n", proj->backends[proj->merging_backend_selected].name); - for ( i=0; in_backends; i++ ) { + for ( ibackend=0; ibackendn_backends; ibackend++ ) { struct crystfel_backend *be; - be = &proj->backends[i]; + be = &proj->backends[ibackend]; be->write_merging_opts(be->merging_opts_priv, fh); } if ( proj->merging_new_job_title != NULL ) { @@ -1134,33 +1134,33 @@ int save_project(struct crystfelproject *proj) fprintf(fh, "label_refls %i\n", proj->label_refls); fprintf(fh, "-----\n"); - for ( i=0; in_results; i++ ) { + for ( iresult=0; iresultn_results; iresult++ ) { int j; - fprintf(fh, "Result %s\n", proj->results[i].name); - for ( j=0; jresults[i].n_streams; j++ ) { + fprintf(fh, "Result %s\n", proj->results[iresult].name); + for ( j=0; jresults[iresult].n_streams; j++ ) { fprintf(fh, " Stream %s\n", - proj->results[i].streams[j]); + proj->results[iresult].streams[j]); } if ( strcmp(selected_result(proj), - proj->results[i].name) == 0 ) + proj->results[iresult].name) == 0 ) { fprintf(fh, " Selected\n"); } } - for ( i=0; in_merge_results; i++ ) { - fprintf(fh, "Result %s\n", proj->merge_results[i].name); - fprintf(fh, " HKL %s\n", proj->merge_results[i].hkl); - fprintf(fh, " HKL1 %s\n", proj->merge_results[i].hkl1); - fprintf(fh, " HKL2 %s\n", proj->merge_results[i].hkl2); + for ( iresult=0; iresultn_merge_results; iresult++ ) { + fprintf(fh, "Result %s\n", proj->merge_results[iresult].name); + fprintf(fh, " HKL %s\n", proj->merge_results[iresult].hkl); + fprintf(fh, " HKL1 %s\n", proj->merge_results[iresult].hkl1); + fprintf(fh, " HKL2 %s\n", proj->merge_results[iresult].hkl2); } fprintf(fh, "-----\n"); - for ( i=0; in_frames; i++ ) { - if ( proj->events[i] != NULL ) { + for ( iframe=0; iframen_frames; iframe++ ) { + if ( proj->events[iframe] != NULL ) { fprintf(fh, "%s %s\n", - proj->filenames[i], proj->events[i]); + proj->filenames[iframe], proj->events[iframe]); } else { - fprintf(fh, "%s\n", proj->filenames[i]); + fprintf(fh, "%s\n", proj->filenames[iframe]); } } diff --git a/src/partialator.c b/src/partialator.c index 249eda93..ca0249ce 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -1014,7 +1014,7 @@ int main(int argc, char *argv[]) SymOpList *amb; SymOpList *w_sym; int nthreads = 1; - int i; + int istream, icmd, icryst, itn; int n_iter = 10; RefList *full; int n_images = 0; @@ -1104,8 +1104,8 @@ int main(int argc, char *argv[]) }; cmdline[0] = '\0'; - for ( i=1; in_datasets; i++ ) { write_custom_split(csplit, i, crystals, n_crystals, pmodel, min_measurements, push_res, @@ -1754,15 +1755,15 @@ int main(int argc, char *argv[]) /* Clean up */ gsl_rng_free(rng); - for ( i=0; ispectrum); - reflist_free(crystal_get_reflections(crystals[i])); + reflist_free(crystal_get_reflections(crystals[icryst])); free(image->filename); free(image->ev); free(image); - cell_free(crystal_get_cell(crystals[i])); - crystal_free(crystals[i]); + cell_free(crystal_get_cell(crystals[icryst])); + crystal_free(crystals[icryst]); } free_contribs(full); reflist_free(full); diff --git a/src/pattern_sim.c b/src/pattern_sim.c index 7098869d..b6414aa1 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -481,7 +481,7 @@ int main(int argc, char *argv[]) int config_gpu = 0; int config_random = 0; char *powder_fn = NULL; - char *filename = NULL; + char *cell_filename = NULL; char *grad_str = NULL; char *outfile = NULL; char *geometry = NULL; @@ -599,7 +599,7 @@ int main(int argc, char *argv[]) break; case 'p' : - filename = strdup(optarg); + cell_filename = strdup(optarg); break; case 'o' : @@ -761,8 +761,8 @@ int main(int argc, char *argv[]) return 1; } - if ( filename == NULL ) { - filename = strdup("molecule.pdb"); + if ( cell_filename == NULL ) { + cell_filename = strdup("molecule.pdb"); } if ( outfile == NULL ) { @@ -844,7 +844,7 @@ int main(int argc, char *argv[]) free(spectrum_str); /* Load unit cell */ - input_cell = load_cell_from_file(filename); + input_cell = load_cell_from_file(cell_filename); if ( input_cell == NULL ) { exit(1); } @@ -988,7 +988,7 @@ int main(int argc, char *argv[]) do { int na, nb, nc; - double a, b, c, d; + double a, b, c, dis; UnitCell *cell; int err = 0; int pi; @@ -1094,7 +1094,7 @@ int main(int argc, char *argv[]) } - cell_get_parameters(cell, &a, &b, &c, &d, &d, &d); + cell_get_parameters(cell, &a, &b, &c, &dis, &dis, &dis); STATUS("Particle size = %i x %i x %i" " ( = %5.2f x %5.2f x %5.2f nm)\n", na, nb, nc, na*a/1.0e-9, nb*b/1.0e-9, nc*c/1.0e-9); @@ -1148,22 +1148,22 @@ int main(int argc, char *argv[]) if ( !config_noimages ) { - char filename[1024]; + char h5filename[1024]; if ( n_images != 1 ) { - snprintf(filename, 1023, "%s-%i.h5", + snprintf(h5filename, 1023, "%s-%i.h5", outfile, number); } else { - strncpy(filename, outfile, 1023); + strncpy(h5filename, outfile, 1023); } number++; /* Write the output file */ - image_write(image, dtempl, filename); + image_write(image, dtempl, h5filename); /* Add some pattern_sim-specific metadata */ - add_metadata(filename, orientation, cell); + add_metadata(h5filename, orientation, cell); } @@ -1190,7 +1190,7 @@ skip: cell_free(input_cell); free(intensities); free(outfile); - free(filename); + free(cell_filename); free(sym_str); free_symoplist(sym); diff --git a/src/process_hkl.c b/src/process_hkl.c index b16146e3..be1c95d4 100644 --- a/src/process_hkl.c +++ b/src/process_hkl.c @@ -604,7 +604,7 @@ int main(int argc, char *argv[]) .disable = 0}; char *rval; int min_measurements = 2; - int r; + int merge_r; int start_after = 0; int stop_after = 0; double min_snr = -INFINITY; @@ -876,13 +876,13 @@ int main(int argc, char *argv[]) if ( config_scale ) twopass = 1; hist_i = 0; - r = merge_all(&stream_list, model, NULL, sym, - &hist_vals, hist_h, hist_k, hist_l, - &hist_i, polarisation, min_measurements, min_snr, - max_adu, start_after, stop_after, min_res, push_res, - min_cc, config_scale, flag_even_odd, stat_output); + merge_r = merge_all(&stream_list, model, NULL, sym, + &hist_vals, hist_h, hist_k, hist_l, + &hist_i, polarisation, min_measurements, min_snr, + max_adu, start_after, stop_after, min_res, push_res, + min_cc, config_scale, flag_even_odd, stat_output); fprintf(stderr, "\n"); - if ( r ) { + if ( merge_r ) { ERROR("Error while reading stream.\n"); return 1; } diff --git a/src/render_hkl.c b/src/render_hkl.c index c47a2c4d..00992d71 100644 --- a/src/render_hkl.c +++ b/src/render_hkl.c @@ -758,7 +758,6 @@ int main(int argc, char *argv[]) int config_colkey = 0; int config_zawhinge = 0; char *cellfile = NULL; - int r = 0; double boost = 1.0; char *sym_str = NULL; char *sym_str_fromfile = NULL; @@ -1049,5 +1048,5 @@ int main(int argc, char *argv[]) reflist_free(list); if ( outfile != NULL ) free(outfile); - return r; + return 0; } diff --git a/src/whirligig.c b/src/whirligig.c index 611825ba..20fcfa40 100644 --- a/src/whirligig.c +++ b/src/whirligig.c @@ -485,12 +485,14 @@ static void add_to_window(struct image *cur, struct window *win, if ( pos >= win->ws ) { - int sf, i; + int sf, iwin; sf = (pos - win->ws) + 1; if ( series_fills_window(win) ) { + int i; + win->ws += sf; win->img = realloc(win->img, win->ws*sizeof(struct image)); @@ -513,6 +515,8 @@ static void add_to_window(struct image *cur, struct window *win, } else { + int iser; + pos -= sf; if ( sf > win->join_ptr ) { @@ -534,29 +538,29 @@ static void add_to_window(struct image *cur, struct window *win, sf = win->ws; } - for ( i=0; iimg[i].serial != 0 ) { - free_all_crystals(&win->img[i]); + for ( iser=0; iserimg[iser].serial != 0 ) { + free_all_crystals(&win->img[iser]); } } memmove(win->img, win->img+sf, (win->ws-sf)*sizeof(struct image)); - for ( i=0; iser[i], win->ser[i]+sf, + for ( iser=0; iserser[iser], win->ser[iser]+sf, (win->ws-sf)*sizeof(signed int)); - memmove(win->mat[i], win->mat[i]+sf, + memmove(win->mat[iser], win->mat[iser]+sf, (win->ws-sf)*sizeof(IntegerMatrix *)); } } - for ( i=0; iimg[win->ws-sf+i].serial = 0; + win->img[win->ws-sf+iwin].serial = 0; for ( j=0; jser[j][win->ws-sf+i] = -1; - win->mat[j][win->ws-sf+i] = NULL; + win->ser[j][win->ws-sf+iwin] = -1; + win->mat[j][win->ws-sf+iwin] = NULL; } } -- cgit v1.2.3