From 8698e5742421773828b94669a9a1dfee2fb528c2 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 13 Jul 2016 13:13:14 -0400 Subject: [PATCH] Compile with c89 -- eliminate init in for-loop --- libsrc4/nc4grp.c | 3 ++- libsrc4/nc4hdf.c | 23 +++++++++++++---------- libsrc4/nc4internal.c | 18 +++++++++++------- libsrc4/nc4var.c | 8 +++++--- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/libsrc4/nc4grp.c b/libsrc4/nc4grp.c index 77bfe1aeb..ab8588126 100644 --- a/libsrc4/nc4grp.c +++ b/libsrc4/nc4grp.c @@ -392,6 +392,7 @@ NC4_inq_varids(int ncid, int *nvars, int *varids) NC_VAR_INFO_T *var; int v, num_vars = 0; int retval; + int i; LOG((2, "nc_inq_varids: ncid 0x%x", ncid)); @@ -413,7 +414,7 @@ NC4_inq_varids(int ncid, int *nvars, int *varids) { /* This is a netCDF-4 group. Round up them doggies and count * 'em. The list is in correct (i.e. creation) order. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; diff --git a/libsrc4/nc4hdf.c b/libsrc4/nc4hdf.c index daa942d29..7949e9f5b 100644 --- a/libsrc4/nc4hdf.c +++ b/libsrc4/nc4hdf.c @@ -69,7 +69,7 @@ rec_reattach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid) { NC_VAR_INFO_T *var; NC_GRP_INFO_T *child_grp; - int d; + int d, i; int retval; assert(grp && grp->name && dimid >= 0 && dimscaleid >= 0); @@ -81,7 +81,7 @@ rec_reattach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid) return retval; /* Find any vars that use this dimension id. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; @@ -112,7 +112,7 @@ rec_detach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid) { NC_VAR_INFO_T *var; NC_GRP_INFO_T *child_grp; - int d; + int d, i; int retval; assert(grp && grp->name && dimid >= 0 && dimscaleid >= 0); @@ -124,7 +124,7 @@ rec_detach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid) return retval; /* Find any vars that use this dimension id. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; @@ -2061,11 +2061,11 @@ attach_dimscales(NC_GRP_INFO_T *grp) NC_VAR_INFO_T *var; NC_DIM_INFO_T *dim1; NC_GRP_INFO_T *g; - int d; + int d, i; int retval = NC_NOERR; /* Attach dimension scales. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; @@ -2363,6 +2363,7 @@ static int write_dim(NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid) { int retval; + int i; /* If there's no dimscale dataset for this dim, create one, * and mark that it should be hidden from netCDF as a @@ -2447,7 +2448,7 @@ write_dim(NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid) /* If this is a dimension without a variable, then update * the secret length information at the end of the NAME * attribute. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { if (grp->vars.value[i] && !strcmp(grp->vars.value[i]->name, dim->name)) { @@ -2505,9 +2506,10 @@ nc4_rec_detect_need_to_preserve_dimids(NC_GRP_INFO_T *grp, nc_bool_t *bad_coord_ NC_GRP_INFO_T *child_grp; int last_dimid = -1; int retval; + int i; /* Iterate over variables in this group */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; @@ -3650,7 +3652,8 @@ nc4_rec_match_dimscales(NC_GRP_INFO_T *grp) NC_VAR_INFO_T *var; NC_DIM_INFO_T *dim; int retval = NC_NOERR; - + int i; + assert(grp && grp->name); LOG((4, "%s: grp->name %s", __func__, grp->name)); @@ -3661,7 +3664,7 @@ nc4_rec_match_dimscales(NC_GRP_INFO_T *grp) /* Check all the vars in this group. If they have dimscale info, * try and find a dimension for them. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index 3c199aef3..47c2b1936 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -373,11 +373,12 @@ nc4_find_dim(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T **dim, int nc4_find_var(NC_GRP_INFO_T *grp, const char *name, NC_VAR_INFO_T **var) { + int i; assert(grp && var && name); /* Find the var info. */ *var = NULL; - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { if (0 == strcmp(name, grp->vars.value[i]->name)) { @@ -501,6 +502,7 @@ nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len) NC_GRP_INFO_T *g; NC_VAR_INFO_T *var; int retval; + int i; assert(grp && len); LOG((3, "nc4_find_dim_len: grp->name %s dimid %d", grp->name, dimid)); @@ -513,7 +515,7 @@ nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len) /* For all variables in this group, find the ones that use this * dimension, and remember the max length. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { size_t mylen; var = grp->vars.value[i]; @@ -770,6 +772,7 @@ nc4_check_dup_name(NC_GRP_INFO_T *grp, char *name) NC_GRP_INFO_T *g; NC_VAR_INFO_T *var; uint32_t hash; + int i; /* Any types of this name? */ for (type = grp->type; type; type = type->l.next) @@ -783,7 +786,7 @@ nc4_check_dup_name(NC_GRP_INFO_T *grp, char *name) /* Any variables of this name? */ hash = hash_fast(name, strlen(name)); - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; @@ -1124,7 +1127,8 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp) NC_DIM_INFO_T *d, *dim; NC_TYPE_INFO_T *type, *t; int retval; - + int i; + assert(grp); LOG((3, "%s: grp->name %s", __func__, grp->name)); @@ -1152,7 +1156,7 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp) } /* Delete all vars. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; @@ -1463,7 +1467,7 @@ rec_print_metadata(NC_GRP_INFO_T *grp, int tab_count) char tabs[MAX_NESTS] = ""; char *dims_string = NULL; char temp_string[10]; - int t, retval, d; + int t, retval, d, i; /* Come up with a number of tabs relative to the group. */ for (t = 0; t < tab_count && t < MAX_NESTS; t++) @@ -1480,7 +1484,7 @@ rec_print_metadata(NC_GRP_INFO_T *grp, int tab_count) LOG((2, "%s DIMENSION - dimid: %d name: %s len: %d unlimited: %d", tabs, dim->dimid, dim->name, dim->len, dim->unlimited)); - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; diff --git a/libsrc4/nc4var.c b/libsrc4/nc4var.c index ad976096b..6a0487381 100644 --- a/libsrc4/nc4var.c +++ b/libsrc4/nc4var.c @@ -1158,6 +1158,7 @@ NC4_inq_varid(int ncid, const char *name, int *varidp) char norm_name[NC_MAX_NAME + 1]; int retval; uint32_t nn_hash; + int i; if (!name) return NC_EINVAL; @@ -1177,7 +1178,7 @@ NC4_inq_varid(int ncid, const char *name, int *varidp) nn_hash = hash_fast(norm_name, strlen(norm_name)); /* Find var of this name. */ - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue; @@ -1203,7 +1204,8 @@ NC4_rename_var(int ncid, int varid, const char *name) NC_VAR_INFO_T *var, *tmp_var; uint32_t nn_hash; int retval = NC_NOERR; - + int i; + LOG((2, "%s: ncid 0x%x varid %d name %s", __func__, ncid, varid, name)); @@ -1229,7 +1231,7 @@ NC4_rename_var(int ncid, int varid, const char *name) /* Check if name is in use, and retain a pointer to the correct variable */ nn_hash = hash_fast(name, strlen(name)); tmp_var = NULL; - for (int i=0; i < grp->vars.nelems; i++) + for (i=0; i < grp->vars.nelems; i++) { var = grp->vars.value[i]; if (!var) continue;