From 6728fceab67b1a8a17e7cefbb724430dee65ac95 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 2 Feb 2019 05:55:18 -0700 Subject: [PATCH] uncommented a bunch of rename tests --- nc_test4/tst_rename2.c | 439 ++++++++++++++++------------------------- 1 file changed, 174 insertions(+), 265 deletions(-) diff --git a/nc_test4/tst_rename2.c b/nc_test4/tst_rename2.c index 840f73605..088fc6957 100644 --- a/nc_test4/tst_rename2.c +++ b/nc_test4/tst_rename2.c @@ -41,246 +41,210 @@ See \ref copyright file for more info. int main(int argc, char **argv) { -/* #define NUM_FORMATS 2 */ -/* int formats[NUM_FORMATS] = {NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC}; */ -/* int format; */ +#define NUM_FORMATS 2 + int formats[NUM_FORMATS] = {NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC}; + int format; -/* fprintf(stderr,"*** Testing more renames\n"); */ + fprintf(stderr,"*** Testing more renames\n"); -/* for (format = 0; format < NUM_FORMATS; format++) */ -/* { */ -/* fprintf(stderr,"*** test renaming 3 dimensions with format %d...", */ -/* formats[format]); */ -/* { */ -/* char filename[NC_MAX_NAME + 1]; */ -/* int ncid, dimid[NDIM3]; */ -/* int dimid_in; */ -/* int enddef_setting; */ + for (format = 0; format < NUM_FORMATS; format++) + { + fprintf(stderr,"*** test renaming 3 dimensions with format %d...", + formats[format]); + { + char filename[NC_MAX_NAME + 1]; + int ncid, dimid[NDIM3]; + int dimid_in; + int enddef_setting; -/* if (nc_set_default_format(formats[format], NULL)) ERR; */ + if (nc_set_default_format(formats[format], NULL)) ERR; -/* for (enddef_setting = 0; enddef_setting < NUM_ENDDEF_SETTINGS; */ -/* enddef_setting++) */ -/* { */ -/* sprintf(filename, "%s_%d_%d.nc", TEST_NAME, formats[format], */ -/* enddef_setting); */ + for (enddef_setting = 0; enddef_setting < NUM_ENDDEF_SETTINGS; + enddef_setting++) + { + sprintf(filename, "%s_%d_%d.nc", TEST_NAME, formats[format], + enddef_setting); -/* /\* Create file with three dims. *\/ */ -/* if (nc_create(filename, 0, &ncid)) ERR; */ -/* if (nc_def_dim(ncid, LAT, DIM1_LEN, &dimid[0])) ERR; */ -/* if (nc_def_dim(ncid, LON, DIM1_LEN, &dimid[1])) ERR; */ -/* if (nc_def_dim(ncid, LEV, DIM1_LEN, &dimid[2])) ERR; */ + /* Create file with three dims. */ + if (nc_create(filename, 0, &ncid)) ERR; + if (nc_def_dim(ncid, LAT, DIM1_LEN, &dimid[0])) ERR; + if (nc_def_dim(ncid, LON, DIM1_LEN, &dimid[1])) ERR; + if (nc_def_dim(ncid, LEV, DIM1_LEN, &dimid[2])) ERR; -/* if (enddef_setting) */ -/* { */ -/* if (nc_enddef(ncid)) ERR; */ -/* if (nc_redef(ncid)) ERR; */ -/* } */ + if (enddef_setting) + { + if (nc_enddef(ncid)) ERR; + if (nc_redef(ncid)) ERR; + } -/* /\* Rename the dimensions. *\/ */ -/* if (nc_rename_dim(ncid, 0, DIM_X)) ERR; */ -/* if (nc_rename_dim(ncid, 1, DIM_Y)) ERR; */ -/* if (nc_rename_dim(ncid, 2, DIM_Z)) ERR; */ + /* Rename the dimensions. */ + if (nc_rename_dim(ncid, 0, DIM_X)) ERR; + if (nc_rename_dim(ncid, 1, DIM_Y)) ERR; + if (nc_rename_dim(ncid, 2, DIM_Z)) ERR; -/* /\* Close the file. *\/ */ -/* if (nc_close(ncid)) ERR; */ + /* Close the file. */ + if (nc_close(ncid)) ERR; -/* /\* Reopen the file and check. *\/ */ -/* if (nc_open(filename, NC_NOWRITE, &ncid)) ERR; */ -/* if (nc_inq_dimid(ncid, DIM_X, &dimid_in)) ERR; */ -/* if (dimid_in != 0) ERR; */ -/* if (nc_inq_dimid(ncid, DIM_Y, &dimid_in)) ERR; */ -/* if (dimid_in != 1) ERR; */ -/* if (nc_inq_dimid(ncid, DIM_Z, &dimid_in)) ERR; */ -/* if (dimid_in != 2) ERR; */ -/* if (nc_close(ncid)) ERR; */ -/* } /\* next enddef setting *\/ */ -/* } */ -/* SUMMARIZE_ERR; */ + /* Reopen the file and check. */ + if (nc_open(filename, NC_NOWRITE, &ncid)) ERR; + if (nc_inq_dimid(ncid, DIM_X, &dimid_in)) ERR; + if (dimid_in != 0) ERR; + if (nc_inq_dimid(ncid, DIM_Y, &dimid_in)) ERR; + if (dimid_in != 1) ERR; + if (nc_inq_dimid(ncid, DIM_Z, &dimid_in)) ERR; + if (dimid_in != 2) ERR; + if (nc_close(ncid)) ERR; + } /* next enddef setting */ + } + SUMMARIZE_ERR; -/* fprintf(stderr,"*** test renaming 3 dims with coord data format %d...", */ -/* formats[format]); */ -/* { */ -/* char filename[NC_MAX_NAME + 1]; */ -/* int ncid, dimid[NDIM3], varid[NDIM3]; */ -/* int dimid_in; */ -/* int lat_data[DIM1_LEN] = {0, 1, 2, 3}; */ -/* int lon_data[DIM1_LEN] = {0, 10, 20, 30}; */ -/* int lev_data[DIM1_LEN] = {0, 100, 200, 300}; */ + fprintf(stderr,"*** test renaming 3 dims with coord data format %d...", + formats[format]); + { + char filename[NC_MAX_NAME + 1]; + int ncid, dimid[NDIM3], varid[NDIM3]; + int dimid_in; + int lat_data[DIM1_LEN] = {0, 1, 2, 3}; + int lon_data[DIM1_LEN] = {0, 10, 20, 30}; + int lev_data[DIM1_LEN] = {0, 100, 200, 300}; -/* if (nc_set_default_format(formats[format], NULL)) ERR; */ + if (nc_set_default_format(formats[format], NULL)) ERR; -/* sprintf(filename, "%s_data_%d.nc", TEST_NAME, formats[format]); */ + sprintf(filename, "%s_data_%d.nc", TEST_NAME, formats[format]); -/* /\* Create file with three dims. *\/ */ -/* if (nc_create(filename, 0, &ncid)) ERR; */ -/* if (nc_def_dim(ncid, LAT, DIM1_LEN, &dimid[0])) ERR; */ -/* if (nc_def_dim(ncid, LON, DIM1_LEN, &dimid[1])) ERR; */ -/* if (nc_def_dim(ncid, LEV, DIM1_LEN, &dimid[2])) ERR; */ + /* Create file with three dims. */ + if (nc_create(filename, 0, &ncid)) ERR; + if (nc_def_dim(ncid, LAT, DIM1_LEN, &dimid[0])) ERR; + if (nc_def_dim(ncid, LON, DIM1_LEN, &dimid[1])) ERR; + if (nc_def_dim(ncid, LEV, DIM1_LEN, &dimid[2])) ERR; -/* /\* Define coordinate data vars. *\/ */ -/* if (nc_def_var(ncid, LAT, NC_INT, NDIM1, &dimid[0], &varid[0])) ERR; */ -/* if (nc_def_var(ncid, LON, NC_INT, NDIM1, &dimid[1], &varid[1])) ERR; */ -/* if (nc_def_var(ncid, LEV, NC_INT, NDIM1, &dimid[2], &varid[2])) ERR; */ + /* Define coordinate data vars. */ + if (nc_def_var(ncid, LAT, NC_INT, NDIM1, &dimid[0], &varid[0])) ERR; + if (nc_def_var(ncid, LON, NC_INT, NDIM1, &dimid[1], &varid[1])) ERR; + if (nc_def_var(ncid, LEV, NC_INT, NDIM1, &dimid[2], &varid[2])) ERR; -/* if (nc_enddef(ncid)) ERR; */ + if (nc_enddef(ncid)) ERR; -/* if (nc_put_var(ncid, 0, lat_data)) ERR; */ -/* if (nc_put_var(ncid, 1, lon_data)) ERR; */ -/* if (nc_put_var(ncid, 2, lev_data)) ERR; */ + if (nc_put_var(ncid, 0, lat_data)) ERR; + if (nc_put_var(ncid, 1, lon_data)) ERR; + if (nc_put_var(ncid, 2, lev_data)) ERR; -/* if (nc_close(ncid)) ERR; */ -/* if (nc_open(filename, NC_WRITE, &ncid)) ERR; */ -/* if (nc_redef(ncid)) ERR; */ + if (nc_close(ncid)) ERR; + if (nc_open(filename, NC_WRITE, &ncid)) ERR; + if (nc_redef(ncid)) ERR; -/* /\* Rename the dimensions. *\/ */ -/* if (nc_rename_dim(ncid, 0, DIM_X)) ERR; */ -/* if (nc_rename_dim(ncid, 1, DIM_Y)) ERR; */ -/* if (nc_rename_dim(ncid, 2, DIM_Z)) ERR; */ + /* Rename the dimensions. */ + if (nc_rename_dim(ncid, 0, DIM_X)) ERR; + if (nc_rename_dim(ncid, 1, DIM_Y)) ERR; + if (nc_rename_dim(ncid, 2, DIM_Z)) ERR; -/* /\* Close the file. *\/ */ -/* if (nc_close(ncid)) ERR; */ + /* Close the file. */ + if (nc_close(ncid)) ERR; -/* /\* Reopen the file and check. *\/ */ -/* if (nc_open(filename, NC_NOWRITE, &ncid)) ERR; */ -/* if (nc_inq_dimid(ncid, DIM_X, &dimid_in)) ERR; */ -/* if (dimid_in != 0) ERR; */ -/* if (nc_inq_dimid(ncid, DIM_Y, &dimid_in)) ERR; */ -/* if (dimid_in != 1) ERR; */ -/* if (nc_inq_dimid(ncid, DIM_Z, &dimid_in)) ERR; */ -/* if (dimid_in != 2) ERR; */ -/* if (nc_close(ncid)) ERR; */ -/* } */ -/* SUMMARIZE_ERR; */ + /* Reopen the file and check. */ + if (nc_open(filename, NC_NOWRITE, &ncid)) ERR; + if (nc_inq_dimid(ncid, DIM_X, &dimid_in)) ERR; + if (dimid_in != 0) ERR; + if (nc_inq_dimid(ncid, DIM_Y, &dimid_in)) ERR; + if (dimid_in != 1) ERR; + if (nc_inq_dimid(ncid, DIM_Z, &dimid_in)) ERR; + if (dimid_in != 2) ERR; + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; -/* } /\* next format *\/ */ + } /* 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]; */ +#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); */ -/* 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; */ + /* 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_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_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; */ + 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]; */ + /* 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; */ + /* 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; */ + /* 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; */ + /* 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; */ - /* fprintf(stderr,"*** test renaming non-coord var to same name as dim..."); */ - /* { */ - /* int ncid, dimid1, dimid2, varid1, varid2; */ - /* int dimid_in, varid_in; */ - /* char file_name[NC_MAX_NAME + 1]; */ - - /* /\* Create file with dim and associated coordinate var. *\/ */ - /* sprintf(file_name, "%s_non_coord_to_dim.nc", TEST_NAME); */ - /* if (nc_create(file_name, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR; */ - /* if (nc_def_dim(ncid, D1_NAME, DIM1_LEN, &dimid1)) ERR; */ - /* if (nc_def_dim(ncid, D2_NAME, DIM1_LEN, &dimid2)) ERR; */ - /* if (nc_def_var(ncid, D1_NAME, NC_INT, NDIM1, &dimid1, &varid1)) ERR; */ - /* if (nc_def_var(ncid, D2_NAME, NC_INT, NDIM1, &dimid2, &varid2)) ERR; */ - /* if (nc_close(ncid)) ERR; */ - - /* /\* Open the file and rename the vars. *\/ */ - /* nc_set_log_level(4); */ - /* if (nc_open(file_name, NC_WRITE, &ncid)) ERR; */ - /* if (nc_rename_var(ncid, varid1, TMP_NAME)) ERR; */ - /* if (nc_rename_var(ncid, varid2, D1_NAME)) ERR; */ - /* if (nc_close(ncid)) ERR; */ - - /* /\* Reopen file and check, *\/ */ - /* if (nc_open(file_name, NC_WRITE, &ncid)) ERR; */ - /* if (nc_inq_dimid(ncid, D1_NAME, &dimid_in)) ERR; */ - /* if (dimid_in != dimid1) ERR; */ - /* if (nc_inq_dimid(ncid, D2_NAME, &dimid_in)) ERR; */ - /* if (dimid_in != dimid2) ERR; */ - /* if (nc_inq_dimid(ncid, TMP_NAME, &dimid_in) != NC_EBADDIM) ERR; */ - /* if (nc_inq_varid(ncid, TMP_NAME, &varid_in)) ERR; */ - /* if (varid_in != varid1) ERR; */ - /* if (nc_inq_varid(ncid, D1_NAME, &varid_in)) ERR; */ - /* if (varid_in != varid2) ERR; */ - /* if (nc_close(ncid)) ERR; */ - /* } */ - /* SUMMARIZE_ERR; */ - fprintf(stderr,"*** test renaming coord var to non-coord var..."); + /* 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; + fprintf(stderr,"*** test renaming non-coord var to same name as dim..."); { int ncid, dimid1, dimid2, varid1, varid2; int dimid_in, varid_in; char file_name[NC_MAX_NAME + 1]; - /* Create file with two dims and associated coordinate vars. */ - sprintf(file_name, "%s_coord_to_non_coord.nc", TEST_NAME); + /* Create file with dim and associated coordinate var. */ + sprintf(file_name, "%s_non_coord_to_dim.nc", TEST_NAME); if (nc_create(file_name, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR; if (nc_def_dim(ncid, D1_NAME, DIM1_LEN, &dimid1)) ERR; if (nc_def_dim(ncid, D2_NAME, DIM1_LEN, &dimid2)) ERR; @@ -288,81 +252,26 @@ main(int argc, char **argv) if (nc_def_var(ncid, D2_NAME, NC_INT, NDIM1, &dimid2, &varid2)) ERR; if (nc_close(ncid)) ERR; - /* Open the file and rename a var. */ + /* Open the file and rename the vars. */ nc_set_log_level(4); if (nc_open(file_name, NC_WRITE, &ncid)) ERR; if (nc_rename_var(ncid, varid1, TMP_NAME)) ERR; + if (nc_rename_var(ncid, varid2, D1_NAME)) ERR; if (nc_close(ncid)) ERR; /* Reopen file and check, */ if (nc_open(file_name, NC_WRITE, &ncid)) ERR; if (nc_inq_dimid(ncid, D1_NAME, &dimid_in)) ERR; - printf("dimid_in %d\n", dimid_in); if (dimid_in != dimid1) ERR; if (nc_inq_dimid(ncid, D2_NAME, &dimid_in)) ERR; if (dimid_in != dimid2) ERR; if (nc_inq_dimid(ncid, TMP_NAME, &dimid_in) != NC_EBADDIM) ERR; if (nc_inq_varid(ncid, TMP_NAME, &varid_in)) ERR; - /* if (varid_in != varid1) ERR; */ - if (nc_inq_varid(ncid, D1_NAME, &varid_in) != NC_ENOTVAR) ERR; + if (varid_in != varid1) ERR; + if (nc_inq_varid(ncid, D1_NAME, &varid_in)) ERR; + if (varid_in != varid2) ERR; if (nc_close(ncid)) ERR; - - /* if (nc_open(file_name, NC_WRITE, &ncid)) ERR; */ - /* if (nc_rename_var(ncid, varid2, D1_NAME)) ERR; */ - /* if (nc_close(ncid)) ERR; */ - - /* /\* Reopen file and check, *\/ */ - /* if (nc_open(file_name, NC_WRITE, &ncid)) ERR; */ - /* if (nc_inq_dimid(ncid, D1_NAME, &dimid_in)) ERR; */ - /* if (dimid_in != dimid1) ERR; */ - /* if (nc_inq_dimid(ncid, D2_NAME, &dimid_in)) ERR; */ - /* if (dimid_in != dimid2) ERR; */ - /* if (nc_inq_dimid(ncid, TMP_NAME, &dimid_in) != NC_EBADDIM) ERR; */ - /* if (nc_inq_varid(ncid, TMP_NAME, &varid_in)) ERR; */ - /* if (varid_in != varid1) ERR; */ - /* if (nc_inq_varid(ncid, D1_NAME, &varid_in)) ERR; */ - /* if (varid_in != varid2) ERR; */ - /* if (nc_close(ncid)) ERR; */ } SUMMARIZE_ERR; - /* fprintf(stderr,"*** test exchanging names of two coord vars, making them non-coord vars with names same as dims..."); */ - /* { */ - /* int ncid, dimid1, dimid2, varid1, varid2; */ - /* int dimid_in, varid_in; */ - /* char file_name[NC_MAX_NAME + 1]; */ - - /* /\* Create file with dim and associated coordinate var. *\/ */ - /* sprintf(file_name, "%s_non_coord_to_dim.nc", TEST_NAME); */ - /* if (nc_create(file_name, NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR; */ - /* if (nc_def_dim(ncid, D1_NAME, DIM1_LEN, &dimid1)) ERR; */ - /* if (nc_def_dim(ncid, D2_NAME, DIM1_LEN, &dimid2)) ERR; */ - /* if (nc_def_var(ncid, D1_NAME, NC_INT, NDIM1, &dimid1, &varid1)) ERR; */ - /* if (nc_def_var(ncid, D2_NAME, NC_INT, NDIM1, &dimid2, &varid2)) ERR; */ - /* if (nc_close(ncid)) ERR; */ - - /* /\* Open the file and rename the vars. *\/ */ - /* nc_set_log_level(4); */ - /* if (nc_open(file_name, NC_WRITE, &ncid)) ERR; */ - /* if (nc_rename_var(ncid, varid1, TMP_NAME)) ERR; */ - /* nc_sync(ncid); */ - /* /\* if (nc_rename_var(ncid, varid2, D1_NAME)) ERR; *\/ */ - /* /\* nc_sync(ncid); *\/ */ - /* /\* if (nc_rename_var(ncid, varid1, D2_NAME)) ERR; *\/ */ - /* if (nc_close(ncid)) ERR; */ - - /* /\* Reopen file and check, *\/ */ - /* if (nc_open(file_name, NC_WRITE, &ncid)) ERR; */ - /* /\* if (nc_inq_dimid(ncid, D1_NAME, &dimid_in)) ERR; *\/ */ - /* /\* if (dimid_in != dimid1) ERR; *\/ */ - /* /\* if (nc_inq_dimid(ncid, D2_NAME, &dimid_in)) ERR; *\/ */ - /* /\* if (dimid_in != dimid2) ERR; *\/ */ - /* /\* if (nc_inq_dimid(ncid, TMP_NAME, &dimid_in) != NC_EBADDIM) ERR; *\/ */ - /* /\* if (nc_inq_varid(ncid, TMP_NAME, &varid_in)) ERR; *\/ */ - /* /\* if (varid_in != varid1) ERR; *\/ */ - /* /\* if (nc_inq_varid(ncid, D1_NAME, &varid_in)) ERR; *\/ */ - /* /\* if (varid_in != varid2) ERR; *\/ */ - /* if (nc_close(ncid)) ERR; */ - /* } */ - /* SUMMARIZE_ERR; */ FINAL_RESULTS; }