15#include "nc4internal.h"
16#include "nc4dispatch.h"
32NC4_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)))
49 NC_FILE_INFO_T* file = grp->nc4_info;
50 *grp_ncid = file->controller->ext_ncid | file->root_grp->hdr.id;
56 if ((retval = nc4_check_name(name, norm_name)))
59 g = (NC_GRP_INFO_T*)ncindexlookup(grp->children,norm_name);
63 *grp_ncid = grp->nc4_info->controller->ext_ncid | g->hdr.id;
84NC4_inq_grps(
int ncid,
int *numgrps,
int *ncids)
86 NC_GRP_INFO_T *grp, *g;
91 LOG((2,
"nc_inq_grps: ncid 0x%x", ncid));
94 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
99 for(
size_t i=0;i<ncindexsize(grp->children);i++)
101 g = (NC_GRP_INFO_T*)ncindexith(grp->children,i);
102 if(g == NULL)
continue;
108 *ncids = g->hdr.id | g->nc4_info->controller->ext_ncid;
132NC4_inq_grpname(
int ncid,
char *name)
138 LOG((2,
"nc_inq_grpname: ncid 0x%x", ncid));
141 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
147 strcpy(name, grp->hdr.name);
168NC4_inq_grpname_full(
int ncid,
size_t *lenp,
char *full_name)
171 int g,
id = ncid, parent_id, *gid;
175 for (g = 0; !NC4_inq_grp_parent(
id, &parent_id); g++,
id = parent_id)
179 if (!(name = malloc((
size_t)(g + 1) * (
NC_MAX_NAME + 1) + 1)))
181 if (!(gid = malloc((
size_t)(g + 1) *
sizeof(
int))))
189 strcpy(name, NC_GROUP_NAME);
193 for (i = 1; i < g && !ret; i++)
194 ret = NC4_inq_grp_parent(gid[i - 1], &gid[i]);
197 for (i = g - 1; !ret && i >= 0 && !ret; i--)
199 if ((ret = NC4_inq_grpname(gid[i], grp_name)))
201 strcat(name, grp_name);
208 *lenp = strlen(name);
211 if (!ret && full_name)
212 strcpy(full_name, name);
235NC4_inq_grp_parent(
int ncid,
int *parent_ncid)
241 LOG((2,
"nc_inq_grp_parent: ncid 0x%x", ncid));
244 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
252 *parent_ncid = grp->nc4_info->controller->ext_ncid | grp->parent->hdr.id;
275NC4_inq_grp_full_ncid(
int ncid,
const char *full_name,
int *grp_ncid)
280 char *cp, *full_name_cpy;
287 if ((ret = nc4_find_grp_h5(ncid, &grp, &h5)))
293 if (!(full_name_cpy = strdup(full_name)))
297 if (!(cp = strtok(full_name_cpy,
"/")))
312 for (; cp; id1 = id2)
314 if ((ret = NC4_inq_ncid(id1, cp, &id2)))
319 cp = strtok(NULL,
"/");
344NC4_inq_varids(
int ncid,
int *nvars,
int *varids)
352 LOG((2,
"nc_inq_varids: ncid 0x%x", ncid));
355 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
361 for (
size_t i=0; i < ncindexsize(grp->vars); i++)
363 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
366 varids[num_vars] = var->hdr.id;
389int int_cmp(
const void *a,
const void *b)
391 const int *ia = (
const int *)a;
392 const int *ib = (
const int *)b;
412NC4_inq_dimids(
int ncid,
int *ndims,
int *dimids,
int include_parents)
414 NC_GRP_INFO_T *grp, *g;
420 LOG((2,
"nc_inq_dimids: ncid 0x%x include_parents: %d", ncid,
424 if ((retval = nc4_find_grp_h5(ncid, &grp, &h5)))
429 num = ncindexcount(grp->dim);
430 if (include_parents) {
431 for (g = grp->parent; g; g = g->parent)
432 num += ncindexcount(g->dim);
441 for(
size_t i=0;i<ncindexsize(grp->dim);i++) {
442 dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
443 if(dim == NULL)
continue;
444 dimids[n++] = dim->hdr.id;
449 for (g = grp->parent; g; g = g->parent) {
450 for(
size_t i=0;i<ncindexsize(g->dim);i++) {
451 dim = (NC_DIM_INFO_T*)ncindexith(g->dim,i);
452 if(dim == NULL)
continue;
453 dimids[n++] = dim->hdr.id;
456 qsort(dimids, (
size_t)num,
sizeof(
int), int_cmp);
#define NC_ENOGRP
No group found.
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_NOERR
No Error.