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

nxCDF user-defined types and NC_STRING support. More...

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

Macros

#define NXCDF_ENUM_BASE_OK(t)

Functions

int NXCDF_get_type_size (nc_type xtype, size_t *sizep)
 Return the in-memory size of an atomic type — a thin public wrapper over NXCDF_type_size().
static int check_type_write (NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp)
 Check that the file may have a user-defined type defined now.
static int get_grp_and_file (int ncid, NC_FILE_INFO_T **h5, NC_GRP_INFO_T **grp, NXCDF_FILE_INFO_T **filep)
 Resolve file state and the group an ncid refers to.
int nxcdf_find_type (NC_GRP_INFO_T *grp, nc_type xtype, NC_TYPE_INFO_T **typep)
 Find the user-defined type record an nc_type id refers to.
int nxcdf_type_size (NC_GRP_INFO_T *grp, nc_type xtype, size_t *sizep)
 Resolve the in-memory element size of any supported type.
int nxcdf_file_type (NC_GRP_INFO_T *grp, nc_type xtype, hid_t *typep)
 Produce an owned HDF5 datatype with the type's file layout.
static int user_mem_type (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type, hid_t *typep)
 Build an owned HDF5 memory datatype for a user-defined type.
int nxcdf_memory_type (NC_GRP_INFO_T *grp, nc_type xtype, hid_t *typep)
 Produce an owned HDF5 memory datatype for any supported type.
int nxcdf_hdf_type_match (NC_GRP_INFO_T *grp, hid_t htype, NC_TYPE_INFO_T **typep)
 Resolve an HDF5 datatype to a registered committed user type by object identity.
static hid_t base_hdf_type (nc_type xtype)
 Map an atomic nc_type to a fresh HDF5 datatype hid_t.
void nxcdf_free_type_info (NC_TYPE_INFO_T *type)
 Release a type's nxCDF-private record and its HDF5 datatype handle, if any.
static int attach_hdf_type (NC_TYPE_INFO_T *type, hid_t hdf)
 Record a built HDF5 datatype on a type, still uncommitted.
static int commit_hdf_type (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type, hid_t hdf)
 Commit (name and store) an HDF5 datatype into a group.
int NXCDF_def_compound (int ncid, size_t size, const char *name, nc_type *typeidp)
 Define a compound type — the nc_def_compound() dispatch entry.
static int type_graph_contains (NC_FILE_INFO_T *h5, NC_TYPE_INFO_T *t, NC_TYPE_INFO_T *target, NClist *seen)
 Check whether target appears anywhere in t's member graph — the cycle check for compound insertion and vlen bases.
static int type_graph_has_forbidden (NC_FILE_INFO_T *h5, NC_TYPE_INFO_T *t, NClist *seen)
 Check whether t's type graph contains a reference member.
static int check_graph_clean (NC_FILE_INFO_T *h5, NC_TYPE_INFO_T *t)
 Reject a type graph containing references.
static int member_type_ok (NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp, nc_type xtype, NC_TYPE_INFO_T *container)
 Validate a compound member's element type.
static int field_hdf_type (NC_GRP_INFO_T *grp, const NC_FIELD_INFO_T *f, hid_t *typep, int *ownedp)
 Build the HDF5 datatype for one compound field.
int NXCDF_insert_compound (int ncid, nc_type typeid, const char *name, size_t offset, nc_type xtype)
 Insert a scalar field into a compound type — the nc_insert_compound() dispatch entry.
int NXCDF_insert_array_compound (int ncid, nc_type typeid, const char *name, size_t offset, nc_type xtype, int ndims, const int *dim_sizesp)
 Insert a scalar or fixed-size array field into a compound type — the nc_insert_array_compound() dispatch entry.
int NXCDF_inq_compound_field (int ncid, nc_type typeid, int fieldid, char *name, size_t *offsetp, nc_type *fieldtypep, int *ndimsp, int *dim_sizesp)
 Inquire a field of a compound type — the nc_inq_compound_field() dispatch entry.
int NXCDF_inq_compound_fieldindex (int ncid, nc_type typeid, const char *name, int *fieldidxp)
 Get a compound field's index by name — the nc_inq_compound_fieldindex() dispatch entry.
int NXCDF_def_vlen (int ncid, const char *name, nc_type base_typeid, nc_type *typeidp)
 Define a variable-length type — the nc_def_vlen() dispatch entry.
static int find_vlen_type (int ncid, nc_type typeid, NC_FILE_INFO_T **h5p, NC_TYPE_INFO_T **typep)
 Resolve a vlen type record from a typeid — shared prologue for the vlen element helpers.
int NXCDF_put_vlen_element (int ncid, int typeid, void *vlen_element, size_t len, const void *data)
 Write a vlen element value — the nc_put_vlen_element() dispatch entry.
int NXCDF_get_vlen_element (int ncid, int typeid, const void *vlen_element, size_t *lenp, void *data)
 Read a vlen element value — the nc_get_vlen_element() dispatch entry.
int NXCDF_def_enum (int ncid, nc_type base_typeid, const char *name, nc_type *typeidp)
 Define an enum type — the nc_def_enum() dispatch entry.
int NXCDF_insert_enum (int ncid, nc_type typeid, const char *name, const void *value)
 Insert a member into an enum type — the nc_insert_enum() dispatch entry.
int NXCDF_inq_enum_member (int ncid, nc_type typeid, int idx, char *name, void *value)
 Inquire an enum member by index — the nc_inq_enum_member() dispatch entry.
int NXCDF_inq_enum_ident (int ncid, nc_type typeid, long long value, char *identifier)
 Get an enum member name by value — the nc_inq_enum_ident() dispatch entry.
int NXCDF_def_opaque (int ncid, size_t size, const char *name, nc_type *typeidp)
 Define an opaque type — the nc_def_opaque() dispatch entry.
static int commit_one_type (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 Commit one previously-attached-but-uncommitted type.
static int rebuild_compound_transient (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 Rebuild a compound's transient HDF5 datatype from its field metadata.
static NC_GRP_INFO_T * find_type_owner (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 Find the group whose type index owns a record.
static int rebuild_vlen_transient (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 Rebuild a vlen's transient HDF5 datatype around its committed base.
static int commit_type_tree (NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 Commit one type after its dependencies.
static int commit_types_in_grp (NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp)
 Recursively commit all uncommitted types in a group tree.
int NXCDF_write_types (NC_FILE_INFO_T *h5)
 Commit every pending user-defined type — called by NXCDF__enddef() before the metadata writer runs, so committed datatypes exist when variable datasets are created.
int NXCDF_inq_user_type (int ncid, nc_type typeid, char *name, size_t *sizep, nc_type *base_typep, size_t *nfieldsp, int *classp)
 Inquire a user-defined type — the nc_inq_user_type() dispatch entry.
int NXCDF_inq_typeid (int ncid, const char *name, nc_type *typeidp)
 Get a type's id by name — the nc_inq_typeid() dispatch entry.
static int types_equal (NC_FILE_INFO_T *h5_1, NC_TYPE_INFO_T *t1, NC_FILE_INFO_T *h5_2, NC_TYPE_INFO_T *t2)
 Structural comparison for nc_inq_type_equal().
int NXCDF_inq_type_equal (int ncid1, nc_type typeid1, int ncid2, nc_type typeid2, int *equalp)
 Compare two types for equality — the nc_inq_type_equal() dispatch entry.
int NXCDF_inq_typeids (int ncid, int *ntypes, int *typeids)
 Get the type ids of the user-defined types in a group — the nc_inq_typeids() dispatch entry.
int nxcdf_storage_memory_type (hid_t memory, hid_t storage, hid_t *typep)
 Preserve storage string character sets in a native memory layout.
int nxcdf_copy_data (NC *nc, nc_type xtype, const void *src, size_t count, void *dst)
 Deep-copy values with initialized, reclaim-safe partial results.

Detailed Description

nxCDF user-defined types and NC_STRING support.

Author
Edward Hartnett
Date
2026-08-29

Macro Definition Documentation

◆ NXCDF_ENUM_BASE_OK

#define NXCDF_ENUM_BASE_OK ( t)
Value:
((t) == NC_BYTE || (t) == NC_CHAR || (t) == NC_SHORT || \
(t) == NC_INT || (t) == NC_UBYTE || (t) == NC_USHORT || \
(t) == NC_UINT || (t) == NC_INT64 || (t) == NC_UINT64)

Function Documentation

◆ attach_hdf_type()

int attach_hdf_type ( NC_TYPE_INFO_T * type,
hid_t hdf )
static

Record a built HDF5 datatype on a type, still uncommitted.

HDF5 distinguishes a "transient" datatype (exists only in memory) from a "committed" one (named and stored in the file). Types being defined stay transient so members can still be inserted; they are committed later at _enddef by NXCDF_write_types() (or immediately for vlen/opaque, which have no members).

Parameters
typeIn-memory type record.
hdfHDF5 datatype identifier to attach (ownership stays with the record).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ base_hdf_type()

hid_t base_hdf_type ( nc_type xtype)
static

Map an atomic nc_type to a fresh HDF5 datatype hid_t.

Convenience wrapper over NXCDF_map_hdf_type() returning -1 instead of an error code. The caller owns the returned datatype.

Parameters
xtypeNetCDF atomic type.
Returns
HDF5 datatype, or negative on unsupported type.

◆ check_graph_clean()

int check_graph_clean ( NC_FILE_INFO_T * h5,
NC_TYPE_INFO_T * t )
static

Reject a type graph containing references.

Parameters
h5NetCDF-4 file state.
tType record to inspect.
Returns
NC_NOERR when the graph is clean, NC_EBADTYPE otherwise.

◆ check_type_write()

int check_type_write ( NXCDF_FILE_INFO_T * file,
NC_GRP_INFO_T * grp )
static

Check that the file may have a user-defined type defined now.

User-defined types (compound, vlen, enum, opaque) require define mode and write access. They are an enhanced-model feature, so NC_CLASSIC_MODEL files reject them; NC_NETCDF4_MODEL files permit the standard enhanced-model types because upstream netcdf-c files can represent them.

Parameters
filenxCDF file state.
grpGroup (currently unused).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ commit_hdf_type()

int commit_hdf_type ( NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type,
hid_t hdf )
static

Commit (name and store) an HDF5 datatype into a group.

Committed datatypes are named objects in the file, like variables — this is what makes a user-defined type persistent. Falls back to the root group when the group's own HDF5 handle isn't open yet.

Parameters
grpGroup.
typeIn-memory type record.
hdfHDF5 datatype to commit.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ commit_one_type()

int commit_one_type ( NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type )
static

Commit one previously-attached-but-uncommitted type.

Used at _enddef for compounds and enums, whose HDF5 datatypes were built transient so members could be inserted during define mode.

Parameters
grpGroup the type belongs to.
typeIn-memory type record.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ commit_type_tree()

int commit_type_tree ( NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type )
static

Commit one type after its dependencies.

For compounds, every uncommitted user-defined member type is committed first (in its own group), then the container's transient datatype is rebuilt so stored members are shared references to the committed datatypes. A vlen whose base is a user type gets the same treatment: commit the base first, then rebuild the vlen around it. Cycles cannot form — insertion rejects them — so plain recursion is sufficient.

Parameters
h5NetCDF-4 file state.
grpGroup the type belongs to.
typeType record.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ commit_types_in_grp()

int commit_types_in_grp ( NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp )
static

Recursively commit all uncommitted types in a group tree.

Parameters
h5NetCDF-4 file state.
grpGroup.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ field_hdf_type()

int field_hdf_type ( NC_GRP_INFO_T * grp,
const NC_FIELD_INFO_T * f,
hid_t * typep,
int * ownedp )
static

Build the HDF5 datatype for one compound field.

Resolves the element type (atomic via NXCDF_map_hdf_type, or a user-defined type's own HDF5 datatype) and wraps it in H5Tarray_create2 when the field is an array. The returned id is owned by the caller only when *ownedp is nonzero; a borrowed committed member datatype stays owned by its type record.

Parameters
grpGroup resolving member type ids.
fField record.
typepDestination for the HDF5 datatype.
ownedpDestination for the ownership flag.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ find_type_owner()

NC_GRP_INFO_T * find_type_owner ( NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type )
static

Find the group whose type index owns a record.

Parameters
grpGroup to walk recursively.
typeType record to locate.
Returns
Owning group, or NULL.

◆ find_vlen_type()

int find_vlen_type ( int ncid,
nc_type typeid,
NC_FILE_INFO_T ** h5p,
NC_TYPE_INFO_T ** typep )
static

Resolve a vlen type record from a typeid — shared prologue for the vlen element helpers.

Parameters
ncidNetCDF file identifier.
typeidType id (must name a NC_VLEN user type).
h5pDestination for the NetCDF-4 file state.
typepDestination for the borrowed type record.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ get_grp_and_file()

int get_grp_and_file ( int ncid,
NC_FILE_INFO_T ** h5,
NC_GRP_INFO_T ** grp,
NXCDF_FILE_INFO_T ** filep )
static

Resolve file state and the group an ncid refers to.

Shared prologue for the def_* functions: NXCDF_get_file() maps the ncid to file state, nc4_find_nc4_grp finds the in-memory group (types are defined per-group in the enhanced model).

Parameters
ncidNetCDF file identifier.
h5Destination for the NetCDF-4 file state.
grpDestination for the group.
filepDestination for the nxCDF file state; may be NULL.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ member_type_ok()

int member_type_ok ( NXCDF_FILE_INFO_T * file,
NC_GRP_INFO_T * grp,
nc_type xtype,
NC_TYPE_INFO_T * container )
static

Validate a compound member's element type.

Atomic members use the file's compatibility rules, excluding NC_STD_REF. Compounds, enums, opaques and vlens all nest, including string leaves, but their member graph must contain no references and must not contain the container itself.

Parameters
filenxCDF file state.
grpGroup the container type lives in (visibility scope).
xtypeCandidate member element type.
containerCompound record receiving the member.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_copy_data()

int nxcdf_copy_data ( NC * nc,
nc_type xtype,
const void * src,
size_t count,
void * dst )

Deep-copy values with initialized, reclaim-safe partial results.

Parameters
ncFile controller owning user-type metadata.
xtypeAtomic or user-defined type.
srcBorrowed source element buffer.
countNumber of elements.
dstUninitialized destination element buffer.
Returns
NC_NOERR or a NetCDF error; failure leaves a zeroed destination.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ NXCDF_def_compound()

int NXCDF_def_compound ( int ncid,
size_t size,
const char * name,
nc_type * typeidp )

Define a compound type — the nc_def_compound() dispatch entry.

A compound type is a C-struct-like record of named fields at byte offsets. Creates an empty transient H5T_COMPOUND, registers the NC_TYPE_INFO_T, and attaches the datatype uncommitted — fields are added by NXCDF_insert_compound() and the type is committed at _enddef.

Parameters
ncidNetCDF file identifier.
sizeSize of the compound type in bytes.
nameType name.
typeidpDestination for the new type id.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_enum()

int NXCDF_def_enum ( int ncid,
nc_type base_typeid,
const char * name,
nc_type * typeidp )

Define an enum type — the nc_def_enum() dispatch entry.

An enum is named constants over an integer base type. Creates a transient H5Tenum_create datatype and attaches it uncommitted; members are added by NXCDF_insert_enum() and the type is committed at _enddef.

Parameters
ncidNetCDF file identifier.
base_typeidInteger base type id.
nameType name.
typeidpDestination for the new type id.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_opaque()

int NXCDF_def_opaque ( int ncid,
size_t size,
const char * name,
nc_type * typeidp )

Define an opaque type — the nc_def_opaque() dispatch entry.

An opaque type is a fixed-size blob the library does not interpret. Like vlens it has no members, so the H5T_OPAQUE datatype is committed immediately.

Parameters
ncidNetCDF file identifier.
sizeSize of the opaque data in bytes.
nameType name.
typeidpDestination for the new type id.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_vlen()

int NXCDF_def_vlen ( int ncid,
const char * name,
nc_type base_typeid,
nc_type * typeidp )

Define a variable-length type — the nc_def_vlen() dispatch entry.

A vlen variable stores a different number of elements per datum (nc_vlen_t handles in memory, heap-allocated on disk). The base type may be any supported atomic type except NC_STD_REF, or a visible user-defined type — compounds, enums, opaques and other vlens all nest.

When the base is still uncommitted (a compound whose fields may still grow), the vlen's datatype stays transient and commit is deferred to _enddef, where commit_type_tree() commits the base first and rebuilds the vlen around it; vlens over committed bases commit immediately, like opaques.

The public nc_vlen_t descriptor and HDF5's hvl_t must have the same layout — I/O moves descriptors verbatim.

Parameters
ncidNetCDF file identifier.
nameType name.
base_typeidBase type of the vlen elements.
typeidpDestination for the new type id.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_file_type()

int nxcdf_file_type ( NC_GRP_INFO_T * grp,
nc_type xtype,
hid_t * typep )

Produce an owned HDF5 datatype with the type's file layout.

Atomic types map through NXCDF_map_hdf_type(); user-defined types copy the record's committed (or still-transient) HDF5 datatype so the dataset or attribute links to the named type. The caller owns the returned handle and must H5Tclose it.

Parameters
grpGroup the type is being used from.
xtypeType id.
typepDestination for an owned HDF5 datatype.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_find_type()

int nxcdf_find_type ( NC_GRP_INFO_T * grp,
nc_type xtype,
NC_TYPE_INFO_T ** typep )

Find the user-defined type record an nc_type id refers to.

Type visibility flows downward in the enhanced model: a type defined in a group is usable in that group and its descendants, never in siblings or ancestors. The search therefore walks the group and its ancestors only; the returned record is borrowed — the caller must not free it or alter its reference count.

Parameters
grpGroup the type is being used from.
xtypeType id (must be NC_FIRSTUSERTYPEID or above).
typepDestination for the borrowed record.
Returns
NC_NOERR on success, NC_EBADTYPE for an atomic id, or NC_EBADTYPID when no visible user type has the id.

◆ nxcdf_free_type_info()

void nxcdf_free_type_info ( NC_TYPE_INFO_T * type)

Release a type's nxCDF-private record and its HDF5 datatype handle, if any.

nc4_type_free() knows nothing about format_type_info, so every definition failure path and the file-close walk must dispose of it separately. Safe on a type with no private record.

Parameters
typeIn-memory type record.

◆ NXCDF_get_type_size()

int NXCDF_get_type_size ( nc_type xtype,
size_t * sizep )

Return the in-memory size of an atomic type — a thin public wrapper over NXCDF_type_size().

Parameters
xtypeNetCDF atomic type.
sizepDestination for the size.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_get_vlen_element()

int NXCDF_get_vlen_element ( int ncid,
int typeid,
const void * vlen_element,
size_t * lenp,
void * data )

Read a vlen element value — the nc_get_vlen_element() dispatch entry.

Reports the descriptor's element count and copies the payload into the caller's buffer using the base type's real in-memory size. The copy is shallow: for a vlen whose base is itself dynamic (a nested vlen, or a compound containing vlen members) the copied descriptors still alias the source element's inner payloads. Those aliases must not be reclaimed independently — callers wanting an owned deep copy use nc_copy_data().

Parameters
ncidNetCDF file identifier.
typeidVlen type id.
vlen_elementSource nc_vlen_t descriptor.
lenpDestination for the element count (required).
dataDestination for the element data (required when the descriptor is non-empty).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_hdf_type_match()

int nxcdf_hdf_type_match ( NC_GRP_INFO_T * grp,
hid_t htype,
NC_TYPE_INFO_T ** typep )

Resolve an HDF5 datatype to a registered committed user type by object identity.

Datasets and attributes created from a committed datatype keep a reference to that named object; comparing the HDF5 object token of htype against every committed type visible from grp (the group and its ancestors) recovers the exact NC_TYPE_INFO_T — matching on H5Tequal alone would conflate distinct named types with equal shapes.

Parameters
grpGroup the datatype is being used from.
htypeHDF5 datatype (need not be committed itself).
typepDestination for the borrowed type record.
Returns
NC_NOERR on success, NC_EBADTYPID when no visible committed type is the same object.

◆ NXCDF_inq_compound_field()

int NXCDF_inq_compound_field ( int ncid,
nc_type typeid,
int fieldid,
char * name,
size_t * offsetp,
nc_type * fieldtypep,
int * ndimsp,
int * dim_sizesp )

Inquire a field of a compound type — the nc_inq_compound_field() dispatch entry.

Parameters
ncidNetCDF file identifier.
typeidCompound type id.
fieldidField index.
nameDestination for the field name.
offsetpDestination for the field offset.
fieldtypepDestination for the field type.
ndimspDestination for the field rank.
dim_sizespDestination for the field dimension sizes.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_compound_fieldindex()

int NXCDF_inq_compound_fieldindex ( int ncid,
nc_type typeid,
const char * name,
int * fieldidxp )

Get a compound field's index by name — the nc_inq_compound_fieldindex() dispatch entry.

Parameters
ncidNetCDF file identifier.
typeidCompound type id.
nameField name.
fieldidxpDestination for the field index.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_enum_ident()

int NXCDF_inq_enum_ident ( int ncid,
nc_type typeid,
long long value,
char * identifier )

Get an enum member name by value — the nc_inq_enum_ident() dispatch entry.

Parameters
ncidNetCDF file identifier.
typeidEnum type id.
valueMember value.
identifierDestination for the member name.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_enum_member()

int NXCDF_inq_enum_member ( int ncid,
nc_type typeid,
int idx,
char * name,
void * value )

Inquire an enum member by index — the nc_inq_enum_member() dispatch entry.

Parameters
ncidNetCDF file identifier.
typeidEnum type id.
idxMember index.
nameDestination for the member name.
valueDestination for the member value.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_type_equal()

int NXCDF_inq_type_equal ( int ncid1,
nc_type typeid1,
int ncid2,
nc_type typeid2,
int * equalp )

Compare two types for equality — the nc_inq_type_equal() dispatch entry.

Two types count as equal when they are the same in-memory record or structurally equal: same class, size and member layout/base/member values, recursively for nested members.

Parameters
ncid1NetCDF file identifier of the first type.
typeid1First type id.
ncid2NetCDF file identifier of the second type.
typeid2Second type id.
equalpDestination for the nonzero-if-equal flag.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_typeid()

int NXCDF_inq_typeid ( int ncid,
const char * name,
nc_type * typeidp )

Get a type's id by name — the nc_inq_typeid() dispatch entry.

Type names are visible file-wide in netCDF semantics; the lookup recurses through the group tree via netcdf-c's nc4_rec_find_named_type.

Parameters
ncidNetCDF file identifier.
nameType name.
typeidpDestination for the type id.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_typeids()

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

Get the type ids of the user-defined types in a group — the nc_inq_typeids() dispatch entry.

Parameters
ncidNetCDF file identifier.
ntypesDestination for the number of types.
typeidsDestination for the type ids.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_user_type()

int NXCDF_inq_user_type ( int ncid,
nc_type typeid,
char * name,
size_t * sizep,
nc_type * base_typep,
size_t * nfieldsp,
int * classp )

Inquire a user-defined type — the nc_inq_user_type() dispatch entry.

Parameters
ncidNetCDF file identifier.
typeidType id.
nameDestination for the type name.
sizepDestination for the type size.
base_typepDestination for the base type id.
nfieldspDestination for the number of fields/members.
classpDestination for the type class.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_insert_array_compound()

int NXCDF_insert_array_compound ( int ncid,
nc_type typeid,
const char * name,
size_t offset,
nc_type xtype,
int ndims,
const int * dim_sizesp )

Insert a scalar or fixed-size array field into a compound type — the nc_insert_array_compound() dispatch entry.

Members may be supported atomic types (excluding NC_STD_REF) or visible user-defined types, including strings and dynamic nesting. Validation happens entirely before H5Tinsert and the metadata update, so a rejected call changes nothing.

Parameters
ncidNetCDF file identifier.
typeidCompound type id.
nameField name.
offsetField offset in bytes.
xtypeNetCDF type of the field elements.
ndimsNumber of array dimensions; 0 inserts a scalar.
dim_sizespArray dimension sizes (required when ndims>0).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_insert_compound()

int NXCDF_insert_compound ( int ncid,
nc_type typeid,
const char * name,
size_t offset,
nc_type xtype )

Insert a scalar field into a compound type — the nc_insert_compound() dispatch entry.

Thin wrapper over NXCDF_insert_array_compound() with rank zero, matching upstream's delegation.

Parameters
ncidNetCDF file identifier.
typeidCompound type id.
nameField name.
offsetField offset in bytes.
xtypeNetCDF type of the field.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_insert_enum()

int NXCDF_insert_enum ( int ncid,
nc_type typeid,
const char * name,
const void * value )

Insert a member into an enum type — the nc_insert_enum() dispatch entry.

The member value arrives as raw bytes in the enum's base type; it is widened to long long for H5Tenum_insert and stored byte-for-byte in the in-memory record.

Parameters
ncidNetCDF file identifier.
typeidEnum type id.
nameMember name.
valueMember value.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_memory_type()

int nxcdf_memory_type ( NC_GRP_INFO_T * grp,
nc_type xtype,
hid_t * typep )

Produce an owned HDF5 memory datatype for any supported type.

Atomic types delegate to NXCDF_memory_type(); ids at or above NC_FIRSTUSERTYPEID resolve through nxcdf_find_type() and build the memory layout described by user_mem_type(). The caller owns the returned handle and must H5Tclose it.

Parameters
grpGroup the type is being used from.
xtypeType id.
typepDestination for an owned HDF5 datatype.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_put_vlen_element()

int NXCDF_put_vlen_element ( int ncid,
int typeid,
void * vlen_element,
size_t len,
const void * data )

Write a vlen element value — the nc_put_vlen_element() dispatch entry.

Fills the caller's nc_vlen_t descriptor with the element count and a borrowed pointer to data — nothing is copied and no ownership is taken. The payload must stay valid until the write it feeds (typically nc_put_vara) has completed.

Parameters
ncidNetCDF file identifier.
typeidVlen type id.
vlen_elementDestination nc_vlen_t descriptor.
lenNumber of elements.
dataElement data (required when len is nonzero).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_storage_memory_type()

int nxcdf_storage_memory_type ( hid_t memory,
hid_t storage,
hid_t * typep )

Preserve storage string character sets in a native memory layout.

Parameters
memoryBorrowed datatype describing the caller's layout.
storageBorrowed stored datatype with matching members.
typepOwned result, closed by the caller.
Returns
NC_NOERR or NC_EHDFERR.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nxcdf_type_size()

int nxcdf_type_size ( NC_GRP_INFO_T * grp,
nc_type xtype,
size_t * sizep )

Resolve the in-memory element size of any supported type.

Atomic ids delegate to NXCDF_type_size(); ids at or above NC_FIRSTUSERTYPEID resolve through nxcdf_find_type() and return the type record's size.

Parameters
grpGroup the type is being used from.
xtypeType id.
sizepDestination for the size in bytes.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_write_types()

int NXCDF_write_types ( NC_FILE_INFO_T * h5)

Commit every pending user-defined type — called by NXCDF__enddef() before the metadata writer runs, so committed datatypes exist when variable datasets are created.

Parameters
h5NetCDF-4 file state.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ rebuild_compound_transient()

int rebuild_compound_transient ( NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type )
static

Rebuild a compound's transient HDF5 datatype from its field metadata.

Called at commit time, after the compound's dependency member types have themselves been committed: building members from the now- committed HDF5 datatypes makes the stored members shared datatype references (as upstream netcdf-c writes), rather than anonymous copies of what were transient ids at insert time.

Parameters
grpGroup the type belongs to (visibility scope).
typeCompound type record.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ rebuild_vlen_transient()

int rebuild_vlen_transient ( NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type )
static

Rebuild a vlen's transient HDF5 datatype around its committed base.

Called at commit time when the vlen's base is a user-defined type: building the vlen from the now-committed base datatype makes the stored base a shared datatype reference (as upstream netcdf-c writes), rather than an anonymous copy of the transient id the base had when nc_def_vlen ran.

Parameters
grpGroup the type belongs to (visibility scope).
typeVlen type record.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ type_graph_contains()

int type_graph_contains ( NC_FILE_INFO_T * h5,
NC_TYPE_INFO_T * t,
NC_TYPE_INFO_T * target,
NClist * seen )
static

Check whether target appears anywhere in t's member graph — the cycle check for compound insertion and vlen bases.

Member types form a DAG by construction (every insert runs this check), so a depth-first walk through user-typed fields and vlen bases is enough; seen bounds the recursion on a malformed graph.

Parameters
h5NetCDF-4 file state used to resolve member type ids.
tType record whose member graph is walked.
targetType record being searched for.
seenScratch list of already-visited records (may be NULL; allocated lazily by the caller).
Returns
Nonzero when target is reachable from t's members.

◆ type_graph_has_forbidden()

int type_graph_has_forbidden ( NC_FILE_INFO_T * h5,
NC_TYPE_INFO_T * t,
NClist * seen )
static

Check whether t's type graph contains a reference member.

NC_STD_REF tokens cannot legally nest inside compounds or vlens. String members and bases are supported. The walk covers compound fields, array elements and vlen bases recursively; seen bounds the recursion on a malformed graph.

Parameters
h5NetCDF-4 file state used to resolve member type ids.
tType record whose member graph is walked.
seenScratch list of already-visited records.
Returns
Nonzero when a forbidden type is reachable from t.

◆ types_equal()

int types_equal ( NC_FILE_INFO_T * h5_1,
NC_TYPE_INFO_T * t1,
NC_FILE_INFO_T * h5_2,
NC_TYPE_INFO_T * t2 )
static

Structural comparison for nc_inq_type_equal().

Compares class, size and contents recursively — member type ids are file-local, so user-defined members compare by structure through each side's own type list, never by numeric id or by name.

Parameters
h5_1File state of the first type.
t1First type record.
h5_2File state of the second type.
t2Second type record.
Returns
Nonzero when the types are structurally equal.

◆ user_mem_type()

int user_mem_type ( NC_GRP_INFO_T * grp,
NC_TYPE_INFO_T * type,
hid_t * typep )
static

Build an owned HDF5 memory datatype for a user-defined type.

The memory layout uses native-endian atomic components so HDF5 converts between buffer and file representations: compounds are rebuilt field-by-field at the offsets nc_inq_compound_field reports (array fields wrapped in H5Tarray_create), enums are rebuilt over the native integer base with the recorded member values, opaques are plain H5T_OPAQUE, and vlens wrap the memory base.

Parameters
grpGroup the type is being used from.
typeIn-memory user-type record.
typepDestination for an owned HDF5 datatype.
Returns
NC_NOERR on success, or a NetCDF error code.