mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
added rename test to tst_rename2.c which fails :-(
This commit is contained in:
parent
6f1d0b8191
commit
713804ea03
@ -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…
Reference in New Issue
Block a user