This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Nan,
> thanks for your email.  I tried using the workaround
> you suggested (in this case it was required because the
> new name was longer than the old) but it doesn't work
> for me.  did you get it to work somehow?  Maybe there
> is a little trick I am missing (?)
Here's what I did to verify the workaround:
First, I created a netCDF test file, by creating the file dbug.cdl:
--------------------- dbug.cdl ------------------------------------
netcdf dbug {
dimensions:
        row = 2;
        col = 3;
variables:
        float a(row,col);
}
-------------------------------------------------------------------
and running
    $ ncgen -n dbug.cdl
to create the file "dbug.nc".
Then I created the following C program to demonstrate the error:
---------------------- nan.c --------------------------------------
#include <netcdf.h>
main()
{
    int ncid = ncopen("dbug.nc",NC_WRITE);
    int did;
    ncredef(ncid);              /* enter define mode */
    did = ncdimid(ncid, "row");
    ncdimrename(ncid,did,"rows");
    ncendef(ncid);
    did = ncdimid(ncid, "rows");
    ncdimrename(ncid,did,"row");
    ncredef(ncid);              /* enter define mode */
    did = ncdimid(ncid, "row");  /* FAILS: ncdimid: dim "row" not found */
    ncdimrename(ncid,did,"rows");
    ncendef(ncid);
    ncclose(ncid);
}
-------------------------------------------------------------------
When I compiled and linked with the latest beta release of netCDF 2.4, it
duplicated the problem you saw:
    $ cc -g -I../libsrc nan.c -o nan -L../libsrc -lnetcdf -lnsl
    $ ncgen -b dbug.cdl
    $ ./nan
    ncdimid: dim "row" not found
When I inserted calls to ncredef(ncid) and ncendef(id) around the middle
ncdimid and ncdimrename calls, as in:
    ncredef(ncid);              /* enter define mode */
    did = ncdimid(ncid, "rows");
    ncdimrename(ncid,did,"row");
    ncendef(ncid);
and recreated the "dbug.nc" file before running this new test, everything
worked fine.
--Russ