mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-04-24 18:30:51 +08:00
Merge branch 'ejh_rename_bug' of https://github.com/NetCDF-World-Domination-Council/netcdf-c into pr-aggregation.wif
This commit is contained in:
commit
9aae0351ac
@ -385,7 +385,7 @@ delete_dimscale_dataset(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T *dim)
|
||||
* @param dim Pointer to dimension info struct.
|
||||
*
|
||||
* @return ::NC_NOERR No error.
|
||||
* @author Quincey Koziol
|
||||
* @author Quincey Koziol, Ed Hartnett
|
||||
*/
|
||||
int
|
||||
nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
||||
@ -406,14 +406,14 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
||||
hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
|
||||
hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
|
||||
|
||||
/* Detach dimscales from the [new] coordinate variable */
|
||||
/* Detach dimscales from the [new] coordinate variable. */
|
||||
if (var->dimscale_attached)
|
||||
{
|
||||
int dims_detached = 0;
|
||||
int finished = 0;
|
||||
int d;
|
||||
|
||||
/* Loop over all dimensions for variable */
|
||||
/* Loop over all dimensions for variable. */
|
||||
for (d = 0; d < var->ndims && !finished; d++)
|
||||
{
|
||||
/* Is there a dimscale attached to this axis? */
|
||||
@ -439,7 +439,8 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
||||
|
||||
/* Find dataset ID for dimension */
|
||||
if (dim1->coord_var)
|
||||
dim_datasetid = ((NC_HDF5_VAR_INFO_T *)(dim1->coord_var->format_var_info))->hdf_datasetid;
|
||||
dim_datasetid = ((NC_HDF5_VAR_INFO_T *)
|
||||
(dim1->coord_var->format_var_info))->hdf_datasetid;
|
||||
else
|
||||
dim_datasetid = hdf5_dim1->hdf_dimscaleid;
|
||||
|
||||
@ -450,7 +451,8 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
||||
if (dim_datasetid > 0)
|
||||
{
|
||||
LOG((3, "detaching scale from %s", var->hdr.name));
|
||||
if (H5DSdetach_scale(hdf5_var->hdf_datasetid, dim_datasetid, d) < 0)
|
||||
if (H5DSdetach_scale(hdf5_var->hdf_datasetid,
|
||||
dim_datasetid, d) < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
}
|
||||
var->dimscale_attached[d] = NC_FALSE;
|
||||
@ -462,7 +464,7 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
||||
}
|
||||
} /* next variable dimension */
|
||||
|
||||
/* Release & reset the array tracking attached dimscales */
|
||||
/* Release & reset the array tracking attached dimscales. */
|
||||
free(var->dimscale_attached);
|
||||
var->dimscale_attached = NULL;
|
||||
need_to_reattach_scales++;
|
||||
@ -476,31 +478,32 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
|
||||
BAIL(NC_EHDFERR);
|
||||
hdf5_dim->hdf_dimscaleid = 0;
|
||||
|
||||
/* Now delete the dimscale's dataset
|
||||
(it will be recreated later, if necessary) */
|
||||
/* Now delete the dimscale's dataset (it will be recreated
|
||||
later, if necessary). */
|
||||
if (H5Gunlink(hdf5_grp->hdf_grpid, dim->hdr.name) < 0)
|
||||
return NC_EDIMMETA;
|
||||
}
|
||||
|
||||
/* Attach variable to dimension */
|
||||
/* Attach variable to dimension. */
|
||||
var->dimscale = NC_TRUE;
|
||||
dim->coord_var = var;
|
||||
|
||||
/* Check if this variable used to be a coord. var */
|
||||
if (need_to_reattach_scales || (var->was_coord_var && grp != NULL))
|
||||
{
|
||||
/* Reattach the scale everywhere it is used. */
|
||||
/* (Recall that netCDF dimscales are always 1-D) */
|
||||
/* Reattach the scale everywhere it is used. (Recall that netCDF
|
||||
* dimscales are always 1-D) */
|
||||
if ((retval = rec_reattach_scales(grp->nc4_info->root_grp,
|
||||
var->dimids[0], hdf5_var->hdf_datasetid)))
|
||||
return retval;
|
||||
|
||||
/* Set state transition indicator (cancels earlier transition) */
|
||||
/* Set state transition indicator (cancels earlier
|
||||
* transition). */
|
||||
var->was_coord_var = NC_FALSE;
|
||||
}
|
||||
else
|
||||
/* Set state transition indicator */
|
||||
var->became_coord_var = NC_TRUE;
|
||||
|
||||
/* Set state transition indicator */
|
||||
var->became_coord_var = NC_TRUE;
|
||||
|
||||
exit:
|
||||
return retval;
|
||||
|
@ -25,6 +25,10 @@ See \ref copyright file for more info.
|
||||
#define DIM_X "x"
|
||||
#define DIM_Y "y"
|
||||
#define DIM_Z "z"
|
||||
#define VAR_NAME_START "lon"
|
||||
#define VAR_NAME_END "lo"
|
||||
#define DIM_NAME_START "lon"
|
||||
#define DIM_NAME_END "lo"
|
||||
|
||||
#define DIM1_LEN 4
|
||||
#define NDIM1 1
|
||||
@ -147,5 +151,89 @@ main(int argc, char **argv)
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
} /* next format */
|
||||
|
||||
#define FILE_NAME1 "tst_dims_foo1.nc"
|
||||
#define DIM_NAME "lat_T42"
|
||||
#define VAR_NAME DIM_NAME
|
||||
#define DIM_NAME2 "lat"
|
||||
#define VAR_NAME2 DIM_NAME2
|
||||
#define RANK_lat_T42 1
|
||||
fprintf(stderr,"*** test renaming with sync...");
|
||||
{
|
||||
int ncid, dimid, varid;
|
||||
char file_name[NC_MAX_NAME + 1];
|
||||
char name[NC_MAX_NAME + 1];
|
||||
|
||||
/* Create file with dim and associated coordinate var. */
|
||||
sprintf(file_name, "%s_sync.nc", TEST_NAME);
|
||||
nc_set_log_level(4);
|
||||
if (nc_create(file_name, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME_END, DIM1_LEN, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, DIM_NAME_END, NC_INT, NDIM1, &dimid, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
if (nc_create(file_name, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME_START, DIM1_LEN, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, DIM_NAME_END, NC_INT, NDIM1, &dimid, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
if (nc_open(file_name, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_rename_dim(ncid, dimid, DIM_NAME_END)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen file and check, */
|
||||
if (nc_open(file_name, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME_END, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, DIM_NAME_END, &varid)) ERR;
|
||||
if (nc_inq_dimname(ncid, dimid, name)) ERR;
|
||||
if (strcmp(name, DIM_NAME_END)) ERR;
|
||||
if (nc_inq_varname(ncid, varid, name)) ERR;
|
||||
if (strcmp(name, DIM_NAME_END)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
fprintf(stderr,"*** test renaming with sync...");
|
||||
{
|
||||
int ncid, dimid, varid;
|
||||
char file_name[NC_MAX_NAME + 1];
|
||||
char name[NC_MAX_NAME + 1];
|
||||
|
||||
/* Create file with dim and associated coordinate var. */
|
||||
sprintf(file_name, "%s_sync.nc", TEST_NAME);
|
||||
if (nc_create(file_name, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME_START, DIM1_LEN, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_START, NC_INT, NDIM1, &dimid, &varid)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
nc_set_log_level(4);
|
||||
/* Open the file and rename the var. */
|
||||
if (nc_open(file_name, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME_START, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME_START, &varid)) ERR;
|
||||
if (nc_rename_var(ncid, varid, VAR_NAME_END)) ERR;
|
||||
|
||||
/* Sync to disk. Now the file has one dim and one var. The dim
|
||||
* is a dimscale only dataset, and the var is a dataset with a
|
||||
* dimscale attached pointing to the dim. */
|
||||
/* if (nc_sync(ncid)) ERR; */
|
||||
if (nc_close(ncid)) ERR;
|
||||
if (nc_open(file_name, NC_WRITE, &ncid)) ERR;
|
||||
/* Now rename the dim to the same name as the var. After this
|
||||
* there will be one dataset, called DIM_NAME_END, which will be
|
||||
* a dimscale. */
|
||||
if (nc_rename_dim(ncid, dimid, DIM_NAME_END)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen file and check, */
|
||||
if (nc_open(file_name, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimid(ncid, DIM_NAME_END, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, VAR_NAME_END, &varid)) ERR;
|
||||
if (nc_inq_dimname(ncid, dimid, name)) ERR;
|
||||
if (strcmp(name, DIM_NAME_END)) ERR;
|
||||
if (nc_inq_varname(ncid, varid, name)) ERR;
|
||||
if (strcmp(name, VAR_NAME_END)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user