I use this function to get the group ID
int nc_inq_grp_full_ncid(int ncid, char *full_name, int *grp_ncid);
then this function to get the number of dimensions
int nc_inq_dimids(int grp_ncid , int *ndims, int *dimids, int include_parents);
Note here that the first parameter of this function has to be "grp_ncid" , not
"ncid" ( "ncid" is the id obtained with nc_open )
so
nc_inq_dimids(grp_ncid , ndims, NULL, 0 );
gets the number of dims defined in this group
nc_inq_dimids(grp_ncid , ndims_parents, NULL, 1);
gets the number of dims defined in this group and parents (last parameter is 1
instead of 0, and the third parameter for "dimids" is NULL )
Pedro
----- Original Message -----
From: David W. Pierce
To: netcdfgroup@xxxxxxxxxxxxxxxx
Cc: Mark Payne
Sent: Saturday, October 20, 2012 9:51 PM
Subject: [netcdfgroup] inquire number of dims visible from a group
Hello netcdf group,
I'm running into odd behavior when trying to determine the number of dims
visible from a group.
The file has 2 dims defined in the root group, then a sub-group with a var
that uses those 2 dims. When processing the file, I need to be able to
determine how many dims are visible from the sub-group (in this case, 2).
The documentation for routine
int nc_inq_dimids(int ncid, int *ndims, int *dimids, int include_parents)Says:
dimids
An already allocated array of ints when the dimids of the visible
dimensions will be stashed. Use nc_inq_ndims to find out how many dims are
visible from this group. (see nc_inq Family).
However, when I actually use nc_inq_ndims, passing in the group ID, it
doesn't return 2 (the number of dims visible from that group), it returns 0
(the number of dims defined in that group). There doesn't seem to be any member
of the nc_inq family of calls that takes an "include_ parents" parameter, which
would handle this case.
So, it seems like either:
1) The documentation is a bit off, but in that case, how are you supposed to
figure out the number of dims visible from a group? (I will note that this
could easily be handled if nc_inq_dimids did not attempt to fill array dimids
if dimids==NULL).
2) The documentation is describing what the code is supposed to be doing, but
the code doesn't actually implement this correctly.
I'm using netcdf library version 4.2.1.1.
Any suggestions?
Regards,
--Dave
--
David W. Pierce
Division of Climate, Atmospheric Science, and Physical Oceanography
Scripps Institution of Oceanography, La Jolla, California, USA
(858) 534-8276 (voice) / (858) 534-8561 (fax) dpierce@xxxxxxxx
------------------------------------------------------------------------------
_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit:
http://www.unidata.ucar.edu/mailing_lists/