NetCDF 4.10.1
Loading...
Searching...
No Matches
Groups

NetCDF-4 added support for hierarchical groups within netCDF datasets. More...

Functions

int nc_def_grp (int parent_ncid, const char *name, int *new_ncid)
 Define a new group.
int nc_inq_dimids (int ncid, int *ndims, int *dimids, int include_parents)
 Retrieve a list of dimension ids associated with a group.
int nc_inq_grp_full_ncid (int ncid, const char *full_name, int *grp_ncid)
 Get the full ncid given a group name.
int nc_inq_grp_ncid (int ncid, const char *grp_name, int *grp_ncid)
 Get a group ncid given the group name.
int nc_inq_grp_parent (int ncid, int *parent_ncid)
 Get the ID of the parent based on a group ID.
int nc_inq_grpname (int ncid, char *name)
 Get the name of a group given an ID.
int nc_inq_grpname_full (int ncid, size_t *lenp, char *full_name)
 Get the full path/groupname of a group/subgroup given an ID.
int nc_inq_grpname_len (int ncid, size_t *lenp)
 Get the length of a group name given an ID.
int nc_inq_grps (int ncid, int *numgrps, int *ncids)
 Get a list of groups or subgroups from a file or groupID.
int nc_inq_ncid (int ncid, const char *name, int *grp_ncid)
 Return the group ID for a group given the name.
int nc_inq_typeids (int ncid, int *ntypes, int *typeids)
 Retrieve a list of types associated with a group.
int nc_inq_varids (int ncid, int *nvars, int *varids)
 Get a list of varids associated with a group given a group ID.
int nc_rename_grp (int grpid, const char *name)
 Rename a group.
int nc_show_metadata (int ncid)
 Print the metadata for a file.

Detailed Description

NetCDF-4 added support for hierarchical groups within netCDF datasets.

Groups are identified with a ncid, which identifies both the open file, and the group within that file. When a file is opened with nc_open or nc_create, the ncid for the root group of that file is provided. Using that as a starting point, users can add new groups, or list and navigate existing groups or rename a group.

All netCDF calls take a ncid which determines where the call will take its action. For example, the nc_def_var function takes a ncid as its first parameter. It will create a variable in whichever group its ncid refers to. Use the root ncid provided by nc_create or nc_open to create a variable in the root group. Or use nc_def_grp to create a group and use its ncid to define a variable in the new group.

Variable are only visible in the group in which they are defined. The same applies to attributes. “Global” attributes are associated with the group whose ncid is used.

Dimensions are visible in their groups, and all child groups.

Group operations are only permitted on netCDF-4 files - that is, files created with the HDF5 flag in nc_create(). Groups are not compatible with the netCDF classic data model, so files created with the NC_CLASSIC_MODEL file cannot contain groups (except the root group).

Encoding both the open file id and group id in a single integer currently limits the number of groups per netCDF-4 file to no more than 32767. Similarly, the number of simultaneously open netCDF-4 files in one program context is limited to 32767.

Function Documentation

◆ nc_def_grp()

int nc_def_grp ( int parent_ncid,
const char * name,
int * new_ncid )

Define a new group.

The function nc_def_grp() adds a new group to an open netCDF dataset in define mode. It returns (as an argument) a group id, given the parent ncid and the name of the group.

A group may be a top-level group if it is passed the ncid of the file, or a sub-group if passed the ncid of an existing group.

Parameters
[in]parent_ncidThe ncid of the parent for the group.
[in]nameName of the new group.
[out]new_ncidPointer to memory to hold the new ncid.
Returns
NC_NOERR No error.
NC_ENOTNC4 Not a netCDF-4 file.
NC_ENOTINDEFINE Not in define mode.
NC_ESTRICTNC3 Not permissible in nc4 classic mode.
NC_EPERM Write to read only.
NC_ENOMEM Memory allocation (malloc) failure.
NC_ENAMEINUSE String match to name in use.

Example

Here is an example using nc_def_grp() to create a new group and define a variable in it.

#include <netcdf.h>
...
int ncid, grpid, varid, dimid;
if (nc_create("foo.nc", NC_NETCDF4, &ncid)) ERR;
if (nc_def_grp(ncid, "my_group", &grpid)) ERR;
if (nc_def_dim(grpid, "x", 10, &dimid)) ERR;
if (nc_def_var(grpid, "data", NC_INT, 1, &dimid, &varid)) ERR;
if (nc_close(ncid)) ERR;
EXTERNL int nc_close(int ncid)
Close an open netCDF dataset.
Definition dfile.c:1330
EXTERNL int nc_create(const char *path, int cmode, int *ncidp)
Create a new netCDF file.
Definition dfile.c:428
EXTERNL int nc_def_dim(int ncid, const char *name, size_t len, int *idp)
Define a new dimension.
Definition ddim.c:121
EXTERNL int nc_def_grp(int parent_ncid, const char *name, int *new_ncid)
Define a new group.
Definition dgroup.c:296
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
Definition dvar.c:216
Main header file for the C API.
#define NC_NETCDF4
Use netCDF-4/HDF5 format.
Definition netcdf.h:179
#define NC_INT
signed 4 byte integer
Definition netcdf.h:38

Definition at line 296 of file dgroup.c.

◆ nc_inq_dimids()

int nc_inq_dimids ( int ncid,
int * ndims,
int * dimids,
int include_parents )

Retrieve a list of dimension ids associated with a group.

Parameters
[in]ncidThe ncid of the group in question.
[out]ndimsPointer to memory to contain the number of dimids associated with the group.
[out]dimidsPointer to memory to contain the number of dimensions associated with the group.
[in]include_parentsIf non-zero, parent groups are also traversed.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.

Definition at line 226 of file dgroup.c.

◆ nc_inq_grp_full_ncid()

int nc_inq_grp_full_ncid ( int ncid,
const char * full_name,
int * grp_ncid )

Get the full ncid given a group name.

Parameters
[in]ncidThe ncid of the file.
[in]full_nameThe full name of the group in question.
[out]grp_ncidPointer to memory to hold the identifier of the full group in question.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOGRP Group not found.
NC_ENOMEM Out of memory.
NC_EINVAL Name is required.

Definition at line 188 of file dgroup.c.

◆ nc_inq_grp_ncid()

int nc_inq_grp_ncid ( int ncid,
const char * grp_name,
int * grp_ncid )

Get a group ncid given the group name.

Parameters
[in]ncidThe ncid of the file.
[in]grp_nameThe name of the group in question.
[out]grp_ncidPointer to memory to hold the identifier of the group in question.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOTNC4 Not a netCDF-4 file.
NC_ENOGRP Group not found.
Note
{This has same semantics as nc_inq_ncid}

Definition at line 170 of file dgroup.c.

◆ nc_inq_grp_parent()

int nc_inq_grp_parent ( int ncid,
int * parent_ncid )

Get the ID of the parent based on a group ID.

Parameters
[in]ncidThe ncid of the group in question.
[out]parent_ncidPointer to memory to hold the identifier of the parent of the group in question.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOGRP No parent group (i.e. the root group was given).

Definition at line 147 of file dgroup.c.

◆ nc_inq_grpname()

int nc_inq_grpname ( int ncid,
char * name )

Get the name of a group given an ID.

Parameters
[in]ncidThe ncid of the file or parent group.
[out]nameThe name of the group associated with the id.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.

Definition at line 93 of file dgroup.c.

◆ nc_inq_grpname_full()

int nc_inq_grpname_full ( int ncid,
size_t * lenp,
char * full_name )

Get the full path/groupname of a group/subgroup given an ID.

Parameters
[in]ncidThe ncid of the file or parent group.
[out]lenpPointer to memory to hold the length of the full name.
[out]full_namePointer to memory to hold the full name of the group including root/parent.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOMEM Out of memory.

Definition at line 113 of file dgroup.c.

◆ nc_inq_grpname_len()

int nc_inq_grpname_len ( int ncid,
size_t * lenp )

Get the length of a group name given an ID.

Parameters
[in]ncidThe ncid of the group in question.
[out]lenpPointer to memory to hold the length of the name of the group in question.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOMEM Out of memory.

Definition at line 131 of file dgroup.c.

◆ nc_inq_grps()

int nc_inq_grps ( int ncid,
int * numgrps,
int * ncids )

Get a list of groups or subgroups from a file or groupID.

Parameters
[in]ncidThe ncid of the file or parent group.
[out]numgrpsPointer to memory to hold the number of groups.
[out]ncidsPointer to memory to hold the ncid for each group.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.

Definition at line 76 of file dgroup.c.

◆ nc_inq_ncid()

int nc_inq_ncid ( int ncid,
const char * name,
int * grp_ncid )

Return the group ID for a group given the name.

Parameters
[in]ncidA valid file or group ncid.
[in]nameThe name of the group you are querying.
[out]grp_ncidPointer to memory to hold the group ncid.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOTNC4 Not a netCDF-4 file.
NC_ENOGRP Group not found.

Definition at line 58 of file dgroup.c.

◆ nc_inq_typeids()

int nc_inq_typeids ( int ncid,
int * ntypes,
int * typeids )

Retrieve a list of types associated with a group.

Parameters
[in]ncidThe ncid for the group in question.
[out]ntypesPointer to memory to hold the number of typeids contained by the group in question.
[out]typeidsPointer to memory to hold the typeids contained by the group in question.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.

Definition at line 245 of file dgroup.c.

◆ nc_inq_varids()

int nc_inq_varids ( int ncid,
int * nvars,
int * varids )

Get a list of varids associated with a group given a group ID.

Parameters
[in]ncidThe ncid of the group in question.
[out]nvarsPointer to memory to hold the number of variables in the group in question.
[out]varidsPointer to memory to hold the variable ids contained by the group in question.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.

Definition at line 207 of file dgroup.c.

◆ nc_rename_grp()

int nc_rename_grp ( int grpid,
const char * name )

Rename a group.

Parameters
[in]grpidThe ID for the group in question.
[in]nameThe new name for the group.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOTNC4 Not a netCDF-4 file.
NC_EPERM Write to read only.
NC_EBADNAME Bad name.
NC_ENAMEINUSE Name already in use.

Definition at line 317 of file dgroup.c.

◆ nc_show_metadata()

int nc_show_metadata ( int ncid)

Print the metadata for a file.

Parameters
[in]ncidThe ncid of an open file.
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.

Definition at line 333 of file dgroup.c.