NEP 4.3.0
NetCDF Expansion Pack
Loading...
Searching...
No Matches
nxcdf_group.c File Reference

nxCDF group creation and inquiry. More...

#include "nxcdf/nxcdf.h"
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "nclist.h"
#include "nxcdf_internal.h"

Functions

static int get_grp_hdf (NC_GRP_INFO_T *grp, hid_t *gid)
 Return the open HDF5 group handle for an in-memory group.
static int attach_grp_hdf (NC_GRP_INFO_T *grp, hid_t hdf_group)
 Attach an HDF5 group handle to a freshly-added group.
static int find_grp_by_id (NC_GRP_INFO_T *root, int grpid, NC_GRP_INFO_T **grpp)
 Recursively find a group in the tree by its in-file group id.
static int get_grp_from_ncid (int ncid, NC_FILE_INFO_T **h5, NC_GRP_INFO_T **grpp)
 Resolve the NC_GRP_INFO_T an ncid refers to.
int NXCDF_def_grp (int ncid, const char *name, int *grpidp)
 Create a subgroup — the nc_def_grp() dispatch entry.
static int find_child_grp (NC_GRP_INFO_T *parent, const char *name, NC_GRP_INFO_T **grpp)
 Locate a direct child group by name.
int NXCDF_inq_ncid (int ncid, const char *name, int *grpidp)
 Get the ncid of a named subgroup — the nc_inq_ncid() dispatch entry.
int NXCDF_inq_grps (int ncid, int *numgrps, int *grpidsp)
 Get the ncids of all subgroups — the nc_inq_grps() dispatch entry.
int NXCDF_inq_grpname (int ncid, char *name)
 Get a group's (short) name — the nc_inq_grpname() dispatch entry.
int NXCDF_inq_grpname_full (int ncid, size_t *lenp, char *name)
 Get a group's full path name — the nc_inq_grpname_full() dispatch entry.
int NXCDF_inq_grp_parent (int ncid, int *parentidp)
 Get a group's parent ncid — the nc_inq_grp_parent() dispatch entry.
int NXCDF_inq_grp_full_ncid (int ncid, const char *full_name, int *grpidp)
 Get the ncid of a group given its full path — the nc_inq_grp_full_ncid() dispatch entry.
int NXCDF_rename_grp (int grpid, const char *name)
 Rename a populated enhanced-model group without changing object IDs. Moves only the parent link, retaining open descendants and their dimension and datatype relationships. Full names are derived from the updated tree.

Detailed Description

nxCDF group creation and inquiry.

Author
Edward Hartnett
Date
2026-08-29

Function Documentation

◆ attach_grp_hdf()

int attach_grp_hdf ( NC_GRP_INFO_T * grp,
hid_t hdf_group )
static

Attach an HDF5 group handle to a freshly-added group.

Companion to get_grp_hdf(): used when the NC_GRP_INFO_T already exists (created by nc4_grp_list_add) and only the private NXCDF_GRP_INFO_T record with its hid_t needs to be hung off it. A no-op if the record is already attached.

Parameters
grpGroup.
hdf_groupHDF5 group identifier to attach.
Returns
NC_NOERR on success or NC_ENOMEM.

◆ find_child_grp()

int find_child_grp ( NC_GRP_INFO_T * parent,
const char * name,
NC_GRP_INFO_T ** grpp )
static

Locate a direct child group by name.

Parameters
parentParent group.
nameName.
grppDestination for the child group.
Returns
NC_NOERR on success or NC_ENOTNC when absent.

◆ find_grp_by_id()

int find_grp_by_id ( NC_GRP_INFO_T * root,
int grpid,
NC_GRP_INFO_T ** grpp )
static

Recursively find a group in the tree by its in-file group id.

In netcdf-c an ncid is two halves: the upper 16 bits identify the file, the lower 16 bits the group inside that file. This walks the in-memory group tree looking for a group whose hdr.id matches the low half — the HDF5 object ids are not used for this lookup.

Parameters
rootGroup tree root.
grpidIn-file group id (low half of an ncid).
grppDestination for the matching group.
Returns
NC_NOERR on success or NC_EBADID.

◆ get_grp_from_ncid()

int get_grp_from_ncid ( int ncid,
NC_FILE_INFO_T ** h5,
NC_GRP_INFO_T ** grpp )
static

Resolve the NC_GRP_INFO_T an ncid refers to.

Splits the ncid into file id (upper 16 bits) and in-file group id (lower 16 bits), locates the file's root group via netcdf-c's nc4_find_grp_h5, then descends the in-memory group tree. Group operations dispatch on an ncid that may name any group in the file, so nearly every public function in this file starts here.

Parameters
ncidNetCDF file identifier (file id | group id).
h5Destination for the file state, or NULL; if non-NULL and *h5 is NULL it is filled with the file's NC_FILE_INFO_T.
grppDestination for the group.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ get_grp_hdf()

int get_grp_hdf ( NC_GRP_INFO_T * grp,
hid_t * gid )
static

Return the open HDF5 group handle for an in-memory group.

Every NC_GRP_INFO_T carries a NXCDF_GRP_INFO_T holding the hid_t of the corresponding HDF5 group. If that private record was never allocated (for example for the root group right after create), this function allocates it on demand: non-root groups get a placeholder handle that is filled in when the HDF5 group is created; the root group uses the file's rootid.

Parameters
grpGroup.
gidDestination for the HDF5 group identifier.
Returns
NC_NOERR on success or NC_ENOMEM.

◆ NXCDF_def_grp()

int NXCDF_def_grp ( int ncid,
const char * name,
int * grpidp )

Create a subgroup — the nc_def_grp() dispatch entry.

Validates define-mode write access, creates the HDF5 group under the parent's hid_t, adds the matching NC_GRP_INFO_T to the in-memory tree, and returns the child ncid. Groups are an enhanced-model feature: native and NC_NETCDF4_MODEL files accept them, while NC_CLASSIC_MODEL files return NC_ENOTNC4.

Parameters
ncidNetCDF file identifier of the parent group.
nameSubgroup name.
grpidpDestination for the new subgroup ncid.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_grp_full_ncid()

int NXCDF_inq_grp_full_ncid ( int ncid,
const char * full_name,
int * grpidp )

Get the ncid of a group given its full path — the nc_inq_grp_full_ncid() dispatch entry.

NXCDF_inq_ncid() already accepts absolute paths, so this is a straight delegation.

Parameters
ncidNetCDF file identifier.
full_nameFull group path.
grpidpDestination for the group ncid.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_grp_parent()

int NXCDF_inq_grp_parent ( int ncid,
int * parentidp )

Get a group's parent ncid — the nc_inq_grp_parent() dispatch entry.

Parameters
ncidNetCDF file identifier.
parentidpDestination for the parent ncid.
Returns
NC_NOERR on success, NC_ENOGRP for the root group, or another NetCDF error code.

◆ NXCDF_inq_grpname()

int NXCDF_inq_grpname ( int ncid,
char * name )

Get a group's (short) name — the nc_inq_grpname() dispatch entry.

Parameters
ncidNetCDF file identifier.
nameDestination for the group name.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_grpname_full()

int NXCDF_inq_grpname_full ( int ncid,
size_t * lenp,
char * name )

Get a group's full path name — the nc_inq_grpname_full() dispatch entry.

Rebuilds "/g1/g2/..." by walking the parent chain up to the root; the root group itself contributes nothing but the leading slash. Nesting is capped at 32 levels.

Parameters
ncidNetCDF file identifier.
lenpDestination for the name length.
nameDestination for the full group name.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_grps()

int NXCDF_inq_grps ( int ncid,
int * numgrps,
int * grpidsp )

Get the ncids of all subgroups — the nc_inq_grps() dispatch entry.

Parameters
ncidNetCDF file identifier.
numgrpsDestination for the number of subgroups.
grpidspDestination for the subgroup ncids.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_ncid()

int NXCDF_inq_ncid ( int ncid,
const char * name,
int * grpidp )

Get the ncid of a named subgroup — the nc_inq_ncid() dispatch entry.

name may be a simple name ("g1"), a relative path ("g1/g2"), or an absolute path ("/g1/g2"); "/" alone resolves to the root group. The lookup walks the in-memory group tree component by component — no HDF5 calls are needed because the metadata was fully loaded at open.

Parameters
ncidNetCDF file identifier.
nameSubgroup name or path.
grpidpDestination for the subgroup ncid.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_rename_grp()

int NXCDF_rename_grp ( int grpid,
const char * name )

Rename a populated enhanced-model group without changing object IDs. Moves only the parent link, retaining open descendants and their dimension and datatype relationships. Full names are derived from the updated tree.

Rename a non-root enhanced-model group and flush its link.

Parameters
grpidNon-root group identifier.
nameNew short name, normalized according to netCDF naming rules.
Returns
NC_NOERR, a naming/access error, or NC_EHDFERR on link/flush failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.