Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on reading unkown dimensions in netCDF-4 misleading #2873

Closed
mwiesenberger opened this issue Feb 29, 2024 · 1 comment · Fixed by #2986
Closed

Documentation on reading unkown dimensions in netCDF-4 misleading #2873

mwiesenberger opened this issue Feb 29, 2024 · 1 comment · Fixed by #2986

Comments

@mwiesenberger
Copy link

The documentation
https://docs.unidata.ucar.edu/netcdf-c/current/reading_unknown.html
recommends using nc_inq to get the number of dimension and then using nc_inq_dim to get the name and length of each of the dimensions. However code like this

int ndims;
nc_inq( ncid, &ndims, 0,0,0);
for( int i=0; i<ndims; i++)
{
        char dimname[256];
        size_t len;
        err = nc_inq_dim( ncid, i, dimname, &len);
}

can have unexpected behaviour in NetCDF-4 if dimensions are defined in groups, e.g.

    int ncid;
    int err;
    err = nc_create( "test.nc", NC_NETCDF4|NC_CLOBBER, &ncid);
    int dimID;
    int grpid;
    err = nc_def_dim( ncid, "x", 10, &dimID);
    err = nc_def_grp(ncid,"group",&grpid);
    err = nc_def_dim( grpid, "gdim", 10, &dimID);
    err = nc_def_dim( ncid, "y", 10, &dimID);

Because the dimIDs will not be sequential, the first code thinks "x" and "gdim" are the dimensions in ncid instead of "x" and "y".

The code in ncdump.c shows how to do it correctly using nc_inq_dimids.
I think the documentation at the above place should show and explain how to do it correctly as well

@edwardhartnett
Copy link
Contributor

I agree. Can you submit a PR with the change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants