15 #include "nc4internal.h"
16 #include "nc4dispatch.h"
32 NC4_inq_ncid(
int ncid,
const char *name,
int *grp_ncid)
34 NC_GRP_INFO_T *grp, *g;
39 LOG((2,
"nc_inq_ncid: ncid 0x%x name %s", ncid, name));
42 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
47 if ((retval = nc4_check_name(name, norm_name)))
50 g = (NC_GRP_INFO_T*)ncindexlookup(grp->children,norm_name);
54 *grp_ncid = grp->nc4_info->controller->ext_ncid | g->hdr.id;
75 NC4_inq_grps(
int ncid,
int *numgrps,
int *ncids)
77 NC_GRP_INFO_T *grp, *g;
83 LOG((2,
"nc_inq_grps: ncid 0x%x", ncid));
86 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
91 for(i=0;i<ncindexsize(grp->children);i++)
93 g = (NC_GRP_INFO_T*)ncindexith(grp->children,i);
94 if(g == NULL)
continue;
100 *ncids = g->hdr.id | g->nc4_info->controller->ext_ncid;
124 NC4_inq_grpname(
int ncid,
char *name)
130 LOG((2,
"nc_inq_grpname: ncid 0x%x", ncid));
133 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
139 strcpy(name, grp->hdr.name);
160 NC4_inq_grpname_full(
int ncid,
size_t *lenp,
char *full_name)
163 int g,
id = ncid, parent_id, *gid;
167 for (g = 0; !NC4_inq_grp_parent(
id, &parent_id); g++,
id = parent_id)
171 if (!(name = malloc((g + 1) * (
NC_MAX_NAME + 1) + 1)))
173 if (!(gid = malloc((g + 1) *
sizeof(
int))))
181 strcpy(name, NC_GROUP_NAME);
185 for (i = 1; i < g && !ret; i++)
186 ret = NC4_inq_grp_parent(gid[i - 1], &gid[i]);
189 for (i = g - 1; !ret && i >= 0 && !ret; i--)
191 if ((ret = NC4_inq_grpname(gid[i], grp_name)))
193 strcat(name, grp_name);
200 *lenp = strlen(name);
203 if (!ret && full_name)
204 strcpy(full_name, name);
227 NC4_inq_grp_parent(
int ncid,
int *parent_ncid)
233 LOG((2,
"nc_inq_grp_parent: ncid 0x%x", ncid));
236 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
244 *parent_ncid = grp->nc4_info->controller->ext_ncid | grp->parent->hdr.id;
267 NC4_inq_grp_full_ncid(
int ncid,
const char *full_name,
int *grp_ncid)
272 char *cp, *full_name_cpy;
279 if ((ret = nc4_find_grp_h5(ncid, &grp, &h5)))
285 if (!(full_name_cpy = strdup(full_name)))
289 if (!(cp = strtok(full_name_cpy,
"/")))
304 for (; cp; id1 = id2)
306 if ((ret = NC4_inq_ncid(id1, cp, &id2)))
311 cp = strtok(NULL,
"/");
336 NC4_inq_varids(
int ncid,
int *nvars,
int *varids)
345 LOG((2,
"nc_inq_varids: ncid 0x%x", ncid));
348 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
354 for (i=0; i < ncindexsize(grp->vars); i++)
356 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
359 varids[num_vars] = var->hdr.id;
382 int int_cmp(
const void *a,
const void *b)
384 const int *ia = (
const int *)a;
385 const int *ib = (
const int *)b;
405 NC4_inq_dimids(
int ncid,
int *ndims,
int *dimids,
int include_parents)
407 NC_GRP_INFO_T *grp, *g;
413 LOG((2,
"nc_inq_dimids: ncid 0x%x include_parents: %d", ncid,
417 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
422 num = ncindexcount(grp->dim);
423 if (include_parents) {
424 for (g = grp->parent; g; g = g->parent)
425 num += ncindexcount(g->dim);
435 for(i=0;i<ncindexsize(grp->dim);i++) {
436 dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
437 if(dim == NULL)
continue;
438 dimids[n++] = dim->hdr.id;
443 for (g = grp->parent; g; g = g->parent) {
444 for(i=0;i<ncindexsize(g->dim);i++) {
445 dim = (NC_DIM_INFO_T*)ncindexith(g->dim,i);
446 if(dim == NULL)
continue;
447 dimids[n++] = dim->hdr.id;
450 qsort(dimids, num,
sizeof(
int), int_cmp);
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_ENOGRP
No group found.
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_NOERR
No Error.