Renaming dimensions, variables, attributes, and groups is one of the subtler parts of the netCDF-4 data model: a rename can change which datasets are dimension scales, which variables are coordinate variables, and how names resolve. The upstream netCDF-c HDF5 backend has several known rename defects — some documented only by commented-out test code in nc_test4. This page records what is broken upstream and what nxCDF does instead.
Rename operations
| API call | nxCDF behavior |
| nc_rename_dim | Renames the dimension; a coordinate variable linked to it keeps its own name and the link is broken (upstream semantics). Renaming a dim onto an existing variable name merges them — the variable becomes the coordinate variable of the renamed dimension. |
| nc_rename_var | Renames the variable; a coordinate variable that no longer shares its dimension's name becomes a plain variable (link broken). Varids are stable across renames and reopen. |
| nc_rename_att | Renames the attribute in place. |
| nc_rename_grp | Renames a non-root group with a flush per rename (Sprint 1O). Works on native and NC_NETCDF4_MODEL files, including files written by upstream netcdf-c; NC_ENAMEINUSE for a name already in use (including committed type names), NC_EBADNAME for names containing /, NC_EBADGRPID for the root group, NC_EPERM on read-only opens. |
Cases broken in upstream netcdf-c that work in nxCDF
The upstream test files nc_test4/tst_rename.c, tst_rename2.c, and tst_rename3.c contain code commented out as "should work but does
not (yet)". Their nxCDF ports in test/nxcdf/nc_test4/ enable those blocks:
- Variable IDs are stable across rename. Upstream's varid_in != varid1 assertions are commented out in tst_rename3; nxCDF keeps varids stable (tst_rename3).
- Renaming a coordinate variable onto an existing dimension name. After d1's coord var is renamed away, renaming another var to d1 makes it the coordinate var of d1 — the block upstream disabled in tst_rename3 runs in the nxCDF port.
- Exchanging coordinate-variable names. The three-rename sequence d1 → t1, d2 → d1, t1 → d2 (disabled upstream in tst_rename3) completes correctly in nxCDF; the port's final assertions are corrected for the true end state (no var t1 remains).
- nc_sync mid-rename. The nc_sync between renames commented out in tst_rename2 is enabled in the port.
- Nested group renames carrying types. Groups holding committed vlen and compound types, dimensions, and child groups rename cleanly; the upstream shell test run_grp_rename is ported as the self-contained tst_grp_rename (no ncgen/ncdump needed).
Cases fixed in Sprint 1Z
- Phantom dimscale after coordinate-variable rename (issue #398, fixed). Breaking a coordinate-variable relationship now strips all scale markers (_Netcdf4Dimid, CLASS, NAME) from the former shared dataset, so upstream readers no longer recover a phantom dimension under the variable's link name. The detached dimension gets a standalone scale under the dimension name.
- nc_rename_dim onto a name squatted by that phantom (issue #399, fixed). With #398 resolved, renaming a dimension onto the former coordinate variable's name merges as upstream expects. nc_inq_grp_full_ncid("/") returns the root group's ncid and nc_rename_grp on the root ncid returns NC_EBADGRPID.
- Variable renamed onto an unrelated dimension's name. nxCDF now uses upstream's hidden-link scheme: the dimension keeps its scale and the variable's dataset moves to _nc4_non_coord_<name>; the public netCDF name stays <name> and is restored on open.
- Standalone scales marked for upstream readers. Scales for dimensions without a coordinate variable now carry upstream's NAME = "This is a netCDF dimension but not a netCDF variable." marker, so upstream readers do not invent a phantom variable for them.
Rename semantics matching upstream
- Define mode is not required for renames. nc_rename_var, nc_rename_dim, and nc_rename_att apply directly in data mode; a classic-model file rejects only a rename to a longer name with NC_ENOTINDEFINE. nc_rename_grp re-enters define mode like upstream.
- Name normalization. Definition paths (nc_def_dim, nc_def_var, nc_put_att, nc_def_grp) and nc_rename_dim/ nc_rename_att store the NFC-normalized form of names, as upstream does; name lookups normalize their query first. Matching upstream, nc_rename_var stores the name exactly as given without normalization.
- Classic model is restored on open. The _nc3_strict marker is read at open so reopened files keep classic-model semantics.
Test coverage
| Test | Source | Notes |
| tst_rename | upstream nc_test4/tst_rename.c | Ported in Sprint 1L2; Charlie Zender's coord-dim/coord-var rename cases. |
| tst_rename2 | upstream nc_test4/tst_rename2.c | Sprint 1Y; dim renames, dim/var name collisions, varid stability; all assertions enabled in 1Z. |
| tst_rename3 | upstream nc_test4/tst_rename3.c | Sprint 1Y; upstream-disabled blocks enabled, including the nc_inq_dimid(TMP_NAME) phantom checks. |
| tst_grp_rename | upstream renamegroup.c + run_grp_rename.sh | Sprint 1Y; folded into a self-contained C test — nested group renames with committed vlen/compound types, root-rename rejection. |
| tst_nxcdf_rename | NEP | Group/dim/coord-var renames, long names, NC_ENAMEINUSE/NC_EBADNAME/NC_EBADGRPID/NC_EPERM, upstream-written files. |
| tst_rehash | upstream nc_test4/tst_rehash.c | Sprint 1Z (#400); rename cases exercising the metadata hash index. |
| tst_grps_rename | upstream nc_test4/tst_grps.c rename sections | Sprint 1Z (#400); group renames including path lookups. |
| tst_vars2_rename | upstream nc_test4/tst_vars2.c rename sections | Sprint 1Z (#400); var/dim rename error codes and the data-mode classic NC_ENOTINDEFINE rule. |
| tst_utf8_rename | upstream nc_test4/tst_utf8.c rename sections | Sprint 1Z (#400); UTF-8 rename normalization cases. |
The non-rename remainder of tst_grps.c, tst_vars2.c, and tst_utf8.c stays with the suite-expansion backlog, tracked by issue #400.