diff --git a/nc_test4/tst_rename2.c b/nc_test4/tst_rename2.c index e50ff29e5..1580cafc6 100644 --- a/nc_test4/tst_rename2.c +++ b/nc_test4/tst_rename2.c @@ -273,5 +273,44 @@ main(int argc, char **argv) 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; }