diff --git a/libhdf5/hdf5open.c b/libhdf5/hdf5open.c index 1bc66bb59..703b9f55d 100644 --- a/libhdf5/hdf5open.c +++ b/libhdf5/hdf5open.c @@ -1699,6 +1699,7 @@ read_scale(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, NC_DIM_INFO_T **dim) { NC_DIM_INFO_T *new_dim; /* Dimension added to group */ + NC_HDF5_DIM_INFO_T *new_hdf5_dim; /* HDF5-specific dim info. */ char dimscale_name_att[NC_MAX_NAME + 1] = ""; /* Dimscale name, for checking if dim without var */ htri_t attr_exists = -1; /* Flag indicating hidden attribute exists */ hid_t attid = -1; /* ID of hidden attribute (to store dim ID) */ @@ -1741,6 +1742,7 @@ read_scale(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, /* Create struct for HDF5-specific dim info. */ if (!(new_dim->format_dim_info = calloc(1, sizeof(NC_HDF5_DIM_INFO_T)))) BAIL(NC_ENOMEM); + new_hdf5_dim = (NC_HDF5_DIM_INFO_T *)new_dim->format_dim_info; new_dim->too_long = too_long; @@ -1775,8 +1777,9 @@ read_scale(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, /* Hold open the dataset, since the dimension doesn't have a * coordinate variable */ + new_hdf5_dim->hdf_dimscaleid = datasetid; new_dim->hdf_dimscaleid = datasetid; - H5Iinc_ref(new_dim->hdf_dimscaleid); /* Increment number of objects using ID */ + H5Iinc_ref(new_hdf5_dim->hdf_dimscaleid); /* Increment number of objects using ID */ } } @@ -1854,7 +1857,7 @@ read_dataset(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, /* Add a var to the linked list, and get its metadata, * unless this is one of those funny dimscales that are a * dimension in netCDF but not a variable. (Spooky!) */ - if (NULL == dim || (dim && !dim->hdf_dimscaleid)) + if (!dim || (dim && !dim->hdf_dimscaleid)) if ((retval = read_var(grp, datasetid, obj_name, ndims, dim))) BAIL(retval); diff --git a/libhdf5/nc4hdf.c b/libhdf5/nc4hdf.c index dc12e6fb2..11cd7c189 100644 --- a/libhdf5/nc4hdf.c +++ b/libhdf5/nc4hdf.c @@ -1399,9 +1399,11 @@ attach_dimscales(NC_GRP_INFO_T *grp) { if (!var->dimscale_attached[d]) { + NC_HDF5_DIM_INFO_T *hdf5_dim; hid_t dim_datasetid; /* Dataset ID for dimension */ dim1 = var->dim[d]; - assert(dim1 && dim1->hdr.id == var->dimids[d]); + assert(dim1 && dim1->hdr.id == var->dimids[d] && dim1->format_dim_info); + hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim1->format_dim_info; LOG((2, "%s: attaching scale for dimid %d to var %s", __func__, var->dimids[d], var->hdr.name)); @@ -1585,20 +1587,27 @@ 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. */ - /* (Note: There's a temptation to merge this loop over the dimensions with - * the prior loop over dimensions, but that blurs the line over the - * purpose of them, so they are currently separate. If performance - * becomes an issue here, it would be possible to merge them. -QAK) + /* Check dims if the variable will be replaced, so that the + * dimensions will be de-attached and re-attached correctly. (Note: + * There's a temptation to merge this loop over the dimensions with + * the prior loop over dimensions, but that blurs the line over the + * purpose of them, so they are currently separate. If performance + * becomes an issue here, it would be possible to merge them. -QAK) */ if (replace_existing_var) { - NC_DIM_INFO_T *d1; int i; - for(i=0;idim);i++) { - if((d1 = (NC_DIM_INFO_T*)ncindexith(grp->dim,i)) == NULL) continue; + 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)) { nc_bool_t exists; @@ -1647,11 +1656,14 @@ write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid) /* If this is a regular var, detach all its dim scales. */ for (d = 0; d < var->ndims; d++) + { if (var->dimscale_attached[d]) { hid_t dim_datasetid; /* Dataset ID for dimension */ NC_DIM_INFO_T *dim1 = var->dim[d]; - assert(dim1 && dim1->hdr.id == var->dimids[d]); + NC_HDF5_DIM_INFO_T *hdf5_dim1; + assert(dim1 && dim1->hdr.id == var->dimids[d] && dim1->format_dim_info); + hdf5_dim1 = (NC_HDF5_DIM_INFO_T *)dim1->format_dim_info; /* Find dataset ID for dimension */ if (dim1->coord_var) @@ -1664,6 +1676,7 @@ write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid) BAIL(NC_EHDFERR); var->dimscale_attached[d] = NC_FALSE; } + } } } @@ -1745,8 +1758,12 @@ exit: static int write_dim(NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid) { + NC_HDF5_DIM_INFO_T *hdf5_dim; int retval; + assert(dim && dim->format_dim_info); + hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info; + /* If there's no dimscale dataset for this dim, create one, * and mark that it should be hidden from netCDF as a * variable. (That is, it should appear as a dimension