changed loop to use ncindexlookup() instead of looping through the names
@@ -1586,45 +1586,34 @@ write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
/* Check dims if the variable will be replaced, so that the
* dimensions will be de-attached and re-attached correctly. */
if (replace_existing_var)
- {
- int i;
-
- for (i = 0; i < ncindexsize(grp->dim); i++)
{
NC_DIM_INFO_T *d1;
- NC_HDF5_DIM_INFO_T *hdf5_d1;
- /* Get info about the dim, including HDF5-specific info. */
- d1 = (NC_DIM_INFO_T *)ncindexith(grp->dim, i);
- assert(d1 && d1->format_dim_info && d1->hdr.name);
- hdf5_d1 = (NC_HDF5_DIM_INFO_T *)d1->format_dim_info;
-
- if (!strcmp(d1->hdr.name, var->hdr.name))
+ /* Is there a dim with this var's name? */
+ if ((d1 = (NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name)))
{
nc_bool_t exists;
+ assert(d1->format_dim_info && d1->hdr.name);
- if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name,
- &exists)))
+ if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
return retval;
if (exists)
{
- hid_t dim_datasetid; /* Dataset ID for dimension */
+ hid_t dsid;
/* Find dataset ID for dimension */
if (d1->coord_var)
- dim_datasetid = ((NC_HDF5_VAR_INFO_T *)(d1->coord_var->format_var_info))->hdf_datasetid;
+ dsid = ((NC_HDF5_VAR_INFO_T *)d1->coord_var->format_var_info)->hdf_datasetid;
else
- dim_datasetid = hdf5_d1->hdf_dimscaleid;
- assert(dim_datasetid > 0);
+ dsid = ((NC_HDF5_DIM_INFO_T *)d1->format_dim_info)->hdf_dimscaleid;
+ assert(dsid > 0);
/* If we're replacing an existing dimscale dataset, go to
* every var in the file and detach this dimension scale,
* because we have to delete it. */
if ((retval = rec_detach_scales(grp->nc4_info->root_grp,
- var->dimids[0], dim_datasetid)))
+ var->dimids[0], dsid)))
return retval;
- break;
- }
}
}
}
