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

nxCDF metadata model: dimensions, variables, attributes, type mapping, and on-disk discovery. More...

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

Data Structures

struct  dim_list_t
 Accumulator used while iterating a group's links looking for dimension scales. More...
struct  var_list_t
 Accumulator used while iterating a group's links looking for variable datasets — the varid counterpart of dim_list_t. More...
struct  resolve_scale_t
 Context for scale_resolve_visitor(): group to search, result dimid slot, and a done flag. More...
struct  att_iter_data_t
 Context for load_att_cb(): the attribute index to fill, the owning object, and the HDF5 location to iterate. More...
struct  load_children_data_t
 Context carried to load_children_cb(): file state, parent group record, and parent HDF5 handle. More...

Functions

static int nxcdf_set_att_order (hid_t ocpl)
 Attribute names that are internal to nxCDF/HDF5.
static int nxcdf_dcpl_fill (hid_t dcpl, NC_FILE_INFO_T *h5, NC_VAR_INFO_T *var, hid_t hdf_type)
 Write the variable's fill setting to a dataset creation property list.
static int nxcdf_rewrite_atts (hid_t loc, NCindex *list, NC_GRP_INFO_T *grp)
 Rewrite every attribute on an HDF5 object in index order.
static int nxcdf_reattach_dim (NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim, hid_t old_dset, hid_t new_dset, NC_VAR_INFO_T *skip)
 Reattach every variable on a dimension from one scale dataset to another.
static int nxcdf_write_quantize_att (hid_t dataset, const NC_VAR_INFO_T *var)
 Persist a variable's quantize setting as the upstream _Quantize* attribute.
static int nxcdf_var_dapl (const NC_VAR_INFO_T *var, hid_t *daplp)
 Build an owned access-property list from a variable's session settings.
static int nxcdf_cache_aliases (NC_GRP_INFO_T *grp, hid_t target, const H5O_token_t *token, NClist *slots)
 Collect owned dataset-handle slots aliasing one HDF5 object. All aliases must close before opening with a different DAPL; otherwise HDF5 retains the first open's raw-data cache even for newly opened handles.
static int nxcdf_reopen_var_cache (NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
 Reopen every owned alias of a variable with its requested cache. Object identity and metadata stay unchanged. If reopening fails, restore the previous DAPL where possible; a failed recovery leaves invalid, not stale, handles and returns an HDF5 error.
int NXCDF_set_var_chunk_cache (int ncid, int varid, size_t size, size_t nelems, float preemption)
 Apply session-only cache settings without recreating dataset storage. Read-only and data-mode calls are permitted. Pending datasets retain the request until creation; live datasets reopen all owned aliases together.
int NXCDF_get_var_chunk_cache (int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp)
 Inquire effective chunk cache properties, allowing NULL outputs. A pending or nonchunked variable reports its stored session request. Live chunked variables report the DAPL actually attached to the dataset handle.
static void nxcdf_dim_wo_var_name (const NC_DIM_INFO_T *dim, char *namebuf, size_t buflen)
 Build the scale NAME for a dimension without a variable.
static int is_reserved_att (const char *name)
 Test whether an attribute name is reserved for internal use.
static void free_name_list (char **names, size_t n)
 Free a dynamically-allocated string list used by the loader.
int NXCDF_check_write_define (NC_FILE_INFO_T *h5, NXCDF_FILE_INFO_T *file)
 Check that a file is writable and currently in define mode.
int NXCDF_map_hdf_type (nc_type xtype, hid_t *typep)
 Map an atomic nc_type to its on-disk HDF5 datatype.
int NXCDF_type_size (nc_type xtype, size_t *sizep)
 Return the in-memory size, in bytes, of an atomic nc_type.
const char * NXCDF_type_name (nc_type xtype)
 Return the short name for an atomic nc_type.
int NXCDF_check_atomic_type (NXCDF_FILE_INFO_T *file, nc_type xtype)
 Check whether an atomic type is allowed for the file's compatibility mode.
static int set_var_type (NC_VAR_INFO_T *var, nc_type xtype)
 Build the NC_TYPE_INFO_T record for an atomic-typed variable.
static int write_string_att (hid_t loc, const char *name, const char *value)
 Write a null-terminated scalar string HDF5 attribute.
static int write_int_att (hid_t loc, const char *name, int value)
 Write a one-element 32-bit integer HDF5 attribute.
static int write_int_array_att (hid_t loc, const char *name, const int *values, size_t len)
 Write an array of 32-bit integers as an HDF5 attribute.
static int map_nc_type (hid_t htype, nc_type *xtypep)
 Map an on-disk HDF5 datatype back to a NetCDF atomic type.
static int get_att_context (NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NCindex **listp, hid_t *locp)
 Resolve where an attribute lives: on a variable's dataset or on the root group.
static int nxcdf_att_list_del (NCindex *list, NC_ATT_INFO_T *att)
 Delete an attribute from an index and free it.
static NC_ATT_INFO_T * find_att (NCindex *list, const char *name)
 Find an existing attribute by name in an attribute index.
static int nxcdf_type_varsized (NC_GRP_INFO_T *grp, nc_type xtype, int *vsp)
 Report whether a type is (transitively) variable-sized.
static int add_att (NCindex *list, NC_OBJ *container, NC_GRP_INFO_T *grp, const char *name, nc_type xtype, size_t len, const void *data, NC_ATT_INFO_T **attp)
 Allocate and add a new attribute to the in-memory model.
static int read_hdf5_att (hid_t loc, const char *name, NCindex *list, NC_OBJ *container, NC_GRP_INFO_T *grp)
 Read one HDF5 attribute into the in-memory model.
int NXCDF_def_dim (int ncid, const char *name, size_t len, int *idp)
 Define a dimension — the nc_def_dim() dispatch entry.
int NXCDF_inq_dim (int ncid, int dimid, char *name, size_t *lenp)
 Inquire about a dimension — the nc_inq_dim() dispatch entry.
int NXCDF_def_var (int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
 Define a variable — the nc_def_var() dispatch entry.
int nxcdf_create_var_dataset (NC_VAR_INFO_T *var, NC_FILE_INFO_T *h5, NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp)
 Create or re-create the HDF5 dataset for a variable.
int nxcdf_find_var_for_write (int ncid, int varid, NC_FILE_INFO_T **h5, NXCDF_FILE_INFO_T **file, NC_GRP_INFO_T **grp, NC_VAR_INFO_T **var)
 Common prologue for the def-var setter dispatch functions.
int NXCDF_def_var_chunking (int ncid, int varid, int storage, const size_t *chunksizesp)
 Set storage and chunk sizes — the nc_def_var_chunking() dispatch entry.
int NXCDF_def_var_fill (int ncid, int varid, int no_fill, const void *fill_value)
 Set fill behavior — the nc_def_var_fill() dispatch entry.
int NXCDF_def_var_endian (int ncid, int varid, int endianness)
 Set the on-disk byte order — the nc_def_var_endian() dispatch entry.
int NXCDF_def_var_quantize (int ncid, int varid, int quantize_mode, int nsd)
 Set quantization — the nc_def_var_quantize() dispatch entry.
int NXCDF_inq_var_all (int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp, int *shufflep, int *deflatep, int *deflate_levelp, int *fletcher32p, int *contiguousp, size_t *chunksizesp, int *no_fillp, void *fill_valuep, int *endiannessp, unsigned int *idp, size_t *nparamsp, unsigned int *params)
 Inquire about all supported properties of a variable — the nc_inq_var_all() dispatch entry.
int NXCDF_inq_var (int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)
 Inquire about a variable's name, type, dimensions, and attributes — the nc_inq_var() dispatch entry.
static int nxcdf_write_att (hid_t loc, const NC_ATT_INFO_T *att, NC_GRP_INFO_T *grp)
 Write one in-memory attribute to an HDF5 object.
int nxcdf_flush_pending_atts (NC_GRP_INFO_T *grp)
 Materialize attributes deferred while their datatype or dataset was pending — called at _enddef.
int NXCDF_put_att (int ncid, int varid, const char *name, nc_type datatype, size_t len, const void *value, nc_type memtype)
 Create or replace an attribute — the nc_put_att_* dispatch entry.
int NXCDF_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
 Inquire about an attribute — the nc_inq_att() dispatch entry.
int NXCDF_inq_attid (int ncid, int varid, const char *name, int *attnump)
 Learn an attribute's index by name — the nc_inq_attid() dispatch entry.
int NXCDF_get_att (int ncid, int varid, const char *name, void *value, nc_type memtype)
 Read an attribute's value — the nc_get_att_* dispatch entry.
int NXCDF_rename_att (int ncid, int varid, const char *name, const char *newname)
 Rename an attribute — the nc_rename_att() dispatch entry.
static int nxcdf_dimscale_create (NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim, const char *name, hid_t *dsetp)
 Create a standalone dimension-scale dataset for a dimension.
static int nxcdf_break_coord_var (NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim, NC_VAR_INFO_T *cvar, const char *scalename)
 Break a coordinate-variable relationship.
static int nxcdf_reform_coord_var (NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim, NC_VAR_INFO_T *var)
 Reform a coordinate-variable relationship.
static NC_VAR_INFO_T * find_coord_var (NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim)
static NC_DIM_INFO_T * coord_var_dim (NC_VAR_INFO_T *var)
int NXCDF_rename_dim (int ncid, int dimid, const char *name)
 Rename a dimension and update its HDF5 link.
int NXCDF_rename_var (int ncid, int varid, const char *name)
 Rename a variable and update its HDF5 link.
int NXCDF_del_att (int ncid, int varid, const char *name)
 Delete an attribute from a group or variable.
static herr_t find_dim_cb (hid_t loc, const char *name, const H5L_info_t *info, void *op_data)
 H5Literate callback collecting dimension-scale datasets.
static int load_one_dim (NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp, const char *name, int dimid)
 Load one dimension from its scale dataset into the in-memory tree.
static int load_dimensions (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp)
 Load all of a group's dimensions in stable dimid order.
static herr_t find_var_cb (hid_t loc, const char *name, const H5L_info_t *info, void *op_data)
 H5Literate callback collecting candidate variable datasets.
static NC_DIM_INFO_T * find_dim_by_name (NC_GRP_INFO_T *grp, const char *name)
 Find a dimension by name in a group or any ancestor.
static int scale_resolve_visitor (hid_t did, unsigned int dim, hid_t dsid, void *op_data)
 H5DSiterate_scales visitor resolving one attached scale to a dimid.
static int resolve_var_dimids (NC_GRP_INFO_T *grp, hid_t dset, int ndims, int *dimids)
 Resolve a variable's dimids from its attached dimension scales.
static int load_one_var (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp, const char *name, int varid)
 Load one variable dataset into the in-memory tree.
static H5_index_t att_iter_index (hid_t obj, int group)
 Pick the H5Aiterate2 index that preserves attribute creation order when the object tracks it.
static herr_t load_att_cb (hid_t loc, const char *attr_name, const H5A_info_t *ainfo, void *op_data)
 H5Aiterate2 callback loading a single user attribute.
static int nxcdf_fill_from_att (NC_VAR_INFO_T *var)
 Mirror a loaded _FillValue attribute into var->fill_value.
static int nxcdf_quantize_from_att (NC_VAR_INFO_T *var)
 Restore a variable's quantize setting from its _Quantize* attribute.
static int load_variables (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp)
 Load all of a group's variables and their attributes.
static int load_group_attributes (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp)
 Load a group's own (non-global) attributes.
static int load_children (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, hid_t parent_hdf, NC_GRP_INFO_T *parent)
 Iterate a group's links loading child groups and committed types.
static int load_one_type (NC_GRP_INFO_T *grp, hid_t htype, const char *name)
 Load one committed HDF5 datatype into the in-memory type list.
static int load_types (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp)
 Register every committed datatype in a group.
static int load_type_members (NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 Fill the members of a registered type record from its HDF5 datatype.
static int load_group_metadata (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp, hid_t hdf_grp)
 Load one group's full metadata: dimensions, committed types, variables, attributes, then children recursively.
static int load_one_group (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5, NC_GRP_INFO_T *parent, hid_t parent_hdf, const char *name)
 Open one child HDF5 group and load it recursively.
static herr_t load_type_cb (hid_t loc, const char *name, const H5L_info_t *info, void *op_data)
 H5Literate callback loading one committed datatype.
static herr_t load_children_cb (hid_t loc, const char *name, const H5L_info_t *info, void *op_data)
 H5Literate callback dispatching each child link to the right loader.
int NXCDF_load_metadata (NXCDF_FILE_INFO_T *file, NC_FILE_INFO_T *h5)
 Load all metadata for an open nxCDF file — the entry point NXCDF_open() calls after checking the marker attributes.

Variables

static const char * reserved_atts []

Detailed Description

nxCDF metadata model: dimensions, variables, attributes, type mapping, and on-disk discovery.

This file contains the two halves of the metadata lifecycle (see nxCDF Architecture): the def/inq dispatch entries that build and query the in-memory NC_*_INFO_T tree during define mode, and the loader (NXCDF_load_metadata and its helpers) that rebuilds the same tree from HDF5 contents at open.

Author
Edward Hartnett
Date
2026-08-28

Function Documentation

◆ add_att()

int add_att ( NCindex * list,
NC_OBJ * container,
NC_GRP_INFO_T * grp,
const char * name,
nc_type xtype,
size_t len,
const void * data,
NC_ATT_INFO_T ** attp )
static

Allocate and add a new attribute to the in-memory model.

Deep-copies the attribute value: numeric data by memcpy, NC_STRING values element-by-element (NULL elements become empty strings), and variable-sized user types (vlens and compounds containing them) recursively through NEP's reclaim-safe nxcdf_copy_data() — so the attribute record owns its data outright and the caller may mutate or free the input immediately.

Parameters
listAttribute index to add to.
containerObject that owns the attribute (group or var hdr).
grpGroup used to resolve user-defined type sizes.
nameName.
xtypeNetCDF atomic or user-defined type.
lenNumber of elements.
dataData buffer.
attpDestination for the new attribute.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ att_iter_index()

H5_index_t att_iter_index ( hid_t obj,
int group )
static

Pick the H5Aiterate2 index that preserves attribute creation order when the object tracks it.

nxCDF and upstream files record H5P_CRT_ORDER_TRACKED on every group and dataset; plain HDF5 objects without tracking fall back to name order.

Parameters
objHDF5 dataset or group identifier.
groupNonzero when obj is a group, zero for a dataset.
Returns
H5_INDEX_CRT_ORDER or H5_INDEX_NAME.

◆ coord_var_dim()

NC_DIM_INFO_T * coord_var_dim ( NC_VAR_INFO_T * var)
static

Determine if a variable is a 1D coordinate variable.

Parameters
varVariable.
Returns
Pointer to the dimension, or NULL if none.

◆ find_att()

NC_ATT_INFO_T * find_att ( NCindex * list,
const char * name )
static

Find an existing attribute by name in an attribute index.

Parameters
listAttribute index to search.
nameName.
Returns
Pointer to the attribute, or NULL if not found.

◆ find_coord_var()

NC_VAR_INFO_T * find_coord_var ( NC_GRP_INFO_T * grp,
NC_DIM_INFO_T * dim )
static

Find a 1D coordinate variable that uses a dimension.

Parameters
grpGroup.
dimDimension.
Returns
Pointer to the coordinate variable, or NULL if none.

◆ find_dim_by_name()

NC_DIM_INFO_T * find_dim_by_name ( NC_GRP_INFO_T * grp,
const char * name )
static

Find a dimension by name in a group or any ancestor.

Dimension scope in netCDF flows downward — a variable may use any ancestor's dimensions, never a sibling's.

Parameters
grpGroup.
nameName.
Returns
Pointer to the dimension, or NULL if not found.

◆ find_dim_cb()

herr_t find_dim_cb ( hid_t loc,
const char * name,
const H5L_info_t * info,
void * op_data )
static

H5Literate callback collecting dimension-scale datasets.

A link is a dimension scale when its dataset carries CLASS = "DIMENSION_SCALE" and a _Netcdf4Dimid attribute; those two hidden attributes are how the loader recovers both the name and the dimid. Anything else is skipped.

Parameters
locHDF5 location identifier.
nameName.
infoLink info (unused).
op_datadim_list_t collection context.
Returns
0 to continue iteration, negative on error.

◆ find_var_cb()

herr_t find_var_cb ( hid_t loc,
const char * name,
const H5L_info_t * info,
void * op_data )
static

H5Literate callback collecting candidate variable datasets.

Datasets carrying _Netcdf4Varid are variables unconditionally. Without it (files written by upstream netcdf-c or older nxCDF), heuristics apply: dimension scales count only if they are coordinate variables (carry _Netcdf4Coordinates), and plain datasets count only if they have attached scales or the coordinates attribute — this is what lets the loader read unmarked netCDF-4/HDF5 files.

Parameters
locHDF5 location identifier.
nameName.
infoLink info (unused).
op_datavar_list_t collection context.
Returns
0 to continue iteration, negative on error.

◆ free_name_list()

void free_name_list ( char ** names,
size_t n )
static

Free a dynamically-allocated string list used by the loader.

The H5Literate callbacks (find_dim_cb, find_var_cb) build NULL-terminated-capacity arrays of strdup'd names; this frees the elements and the array.

Parameters
namesString array.
nElement count.

◆ get_att_context()

int get_att_context ( NC_GRP_INFO_T * grp,
NC_VAR_INFO_T * var,
NCindex ** listp,
hid_t * locp )
static

Resolve where an attribute lives: on a variable's dataset or on the root group.

netCDF attributes are either per-variable or global (NC_GLOBAL, which nxCDF stores on the root group). Returns both the in-memory NCindex and the HDF5 hid_t the attribute is written to.

Parameters
grpGroup.
varVariable, or NULL for a group (global) attribute.
listpDestination for the attribute index.
locpDestination for the HDF5 location identifier — a negative value when the variable's dataset has not been created yet (user-defined types defer it to _enddef), in which case the caller must skip HDF5 writes and mark the attributes pending.
Returns
NC_NOERR on success.

◆ is_reserved_att()

int is_reserved_att ( const char * name)
static

Test whether an attribute name is reserved for internal use.

See reserved_atts. Used to hide nxCDF bookkeeping attributes from users and to reject reserved names in nc_put_att.

Parameters
nameName.
Returns
Nonzero when name is a reserved attribute name.

◆ load_att_cb()

herr_t load_att_cb ( hid_t loc,
const char * attr_name,
const H5A_info_t * ainfo,
void * op_data )
static

H5Aiterate2 callback loading a single user attribute.

Reserved (internal) attributes and attributes whose datatype doesn't map to an atomic nc_type are skipped — neither should make an otherwise-valid file unopenable. _FillValue on a variable is the one exception: upstream exposes it as a normal, user-visible attribute (#377).

Parameters
locHDF5 location identifier.
attr_nameHDF5 attribute name.
ainfoAttribute info (unused).
op_dataatt_iter_data_t iteration context.
Returns
0 always; failures are swallowed as skips.

◆ load_children()

int load_children ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
hid_t parent_hdf,
NC_GRP_INFO_T * parent )
static

Iterate a group's links loading child groups and committed types.

Parameters
filenxCDF file state.
h5NetCDF-4 file state.
parent_hdfParent HDF5 group identifier.
parentParent group.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ load_children_cb()

herr_t load_children_cb ( hid_t loc,
const char * name,
const H5L_info_t * info,
void * op_data )
static

H5Literate callback dispatching each child link to the right loader.

Links that open as groups become subgroups (load_one_group); committed datatypes were already registered by the load_types() pass and datasets by the variable pass. Anything else is skipped.

Parameters
locHDF5 location identifier.
nameName.
infoLink info (unused).
op_dataload_children_data_t iteration context.
Returns
0 to continue iteration, -1 on load failure.

◆ load_dimensions()

int load_dimensions ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp )
static

Load all of a group's dimensions in stable dimid order.

HDF5 iterates links by name, but netCDF dimids are positional — so the callback pass collects them and this replays them 0..maxid. Missing ids (a sparse id space) fail as NC_EFILEMETA.

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

◆ load_group_attributes()

int load_group_attributes ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp )
static

Load a group's own (non-global) attributes.

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

◆ load_group_metadata()

int load_group_metadata ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp,
hid_t hdf_grp )
static

Load one group's full metadata: dimensions, committed types, variables, attributes, then children recursively.

Order matters — dimensions and committed types must exist before variables resolve their dimids and datatypes, and children load last so their parent's types are visible to them. An unmarked root group with nothing loadable is rejected (NC_ENOTNC): a plain HDF5 file with no netCDF structure is not a netCDF file.

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

◆ load_one_dim()

int load_one_dim ( NXCDF_FILE_INFO_T * file,
NC_GRP_INFO_T * grp,
const char * name,
int dimid )
static

Load one dimension from its scale dataset into the in-memory tree.

Recovers current length and unlimited-ness (H5S_UNLIMITED max extent) from the dataset's dataspace, keeps the dataset hid_t open in NXCDF_DIM_INFO_T for later scale attachment.

Parameters
filenxCDF file state.
grpGroup.
nameName.
dimidDimension identifier.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ load_one_group()

int load_one_group ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * parent,
hid_t parent_hdf,
const char * name )
static

Open one child HDF5 group and load it recursively.

Parameters
filenxCDF file state.
h5NetCDF-4 file state.
parentParent group.
parent_hdfParent HDF5 group identifier.
nameName.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ load_one_type()

int load_one_type ( NC_GRP_INFO_T * grp,
hid_t htype,
const char * name )
static

Load one committed HDF5 datatype into the in-memory type list.

Committed datatypes are the on-disk form of user-defined types. The HDF5 class sets the nc_type_class; enum and vlen base types are recovered from the datatype's super-type. The hid_t is kept open in NXCDF_TYPE_INFO_T.

Parameters
grpGroup.
htypeHDF5 committed datatype (ownership transferred on success).
nameName.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ load_one_var()

int load_one_var ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp,
const char * name,
int varid )
static

Load one variable dataset into the in-memory tree.

Rebuilds the full NC_VAR_INFO_T: type via map_nc_type(), rank and dims from the dataspace, dimids from _Netcdf4Coordinates (or attached scales), then — from the dataset creation property list — chunking/storage, fill behavior and value, the filter pipeline (deflate/shuffle/fletcher32), and endianness from the datatype's byte order. meta_read/atts_read/created are set so netcdf-c treats the variable as fully loaded, not new.

Parameters
filenxCDF file state.
h5NetCDF-4 file state.
grpGroup.
nameName.
varidVariable identifier (currently unused; ids come from load order).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ load_type_cb()

herr_t load_type_cb ( hid_t loc,
const char * name,
const H5L_info_t * info,
void * op_data )
static

H5Literate callback loading one committed datatype.

Committed datatypes are the on-disk form of user-defined types. They must all be registered — and their members populated — before any variable or attribute that references them is loaded, so this pass runs ahead of load_variables()/load_group_attributes().

Parameters
locHDF5 location identifier.
nameName.
infoLink info (unused).
op_dataload_children_data_t iteration context.
Returns
0 to continue iteration, -1 on load failure.

◆ load_type_members()

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

Fill the members of a registered type record from its HDF5 datatype.

Second pass of load_types(): runs once every committed datatype in the group has a registered record, so compound member types and vlen bases resolve through nxcdf_hdf_type_match() regardless of the order HDF5 links were iterated. Array members recover their rank and shape via H5Tget_array_ndims()/H5Tget_array_dims().

Parameters
grpGroup.
typeType record with format_type_info populated.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ load_types()

int load_types ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp )
static

Register every committed datatype in a group.

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

◆ load_variables()

int load_variables ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5,
NC_GRP_INFO_T * grp )
static

Load all of a group's variables and their attributes.

Collects candidates with find_var_cb(), then loads in stored-varid order when _Netcdf4Varid attributes exist (preserving the ids assigned at create), else in HDF5 iteration order. Each variable's user attributes are iterated with H5Aiterate2.

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

◆ map_nc_type()

int map_nc_type ( hid_t htype,
nc_type * xtypep )
static

Map an on-disk HDF5 datatype back to a NetCDF atomic type.

Inverse of NXCDF_map_hdf_type(), used at open. HDF5 class + size + sign resolves the standard types; small floats, references and complex need H5Tequal against specific predefined types. Datatypes that don't map (e.g. committed user types, which are loaded by load_one_type instead) yield NC_EBADTYPE.

Parameters
htypeHDF5 datatype to map.
xtypepDestination for the NetCDF atomic type.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_att_list_del()

int nxcdf_att_list_del ( NCindex * list,
NC_ATT_INFO_T * att )
static

Delete an attribute from an index and free it.

nc4_att_list_del() deletes by att->hdr.id, but ids drift out of sync with list positions after earlier deletes: mid-list removal does not rehash the name map or renumber the survivors, so a later delete can drop the wrong attribute and ncindexlookup() returns stale positions. Find the real slot, delete it, renumber, rebuild the name map, then free the record.

Parameters
listAttribute index.
attAttribute to delete.
Returns
NC_NOERR on success, NC_ENOTATT when absent.

◆ nxcdf_break_coord_var()

int nxcdf_break_coord_var ( NXCDF_FILE_INFO_T * file,
NC_GRP_INFO_T * grp,
NC_DIM_INFO_T * dim,
NC_VAR_INFO_T * cvar,
const char * scalename )
static

Break a coordinate-variable relationship.

Upstream nc4_break_coord_var() semantics: the shared dataset stays with the variable under its link name, the dimension gets a standalone scale dataset under scalename, all other variables are reattached to it, and the variable's dataset loses all its dimscale markers (_Netcdf4Dimid, CLASS, NAME) so neither the loader nor upstream readers recover a phantom dimension (#398).

Parameters
filenxCDF file state.
grpGroup containing the dimension.
dimDimension leaving the relationship.
cvarFormer coordinate variable.
scalenameName for the dimension's new scale dataset.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_cache_aliases()

int nxcdf_cache_aliases ( NC_GRP_INFO_T * grp,
hid_t target,
const H5O_token_t * token,
NClist * slots )
static

Collect owned dataset-handle slots aliasing one HDF5 object. All aliases must close before opening with a different DAPL; otherwise HDF5 retains the first open's raw-data cache even for newly opened handles.

Parameters
grpSubtree to search for variable and dimension-scale handles.
targetOpen dataset used as the object-token comparison location.
tokenTarget object token.
slotsList of pointers to owned handle slots, not handles to close yet.
Returns
NC_NOERR, NC_ENOMEM or NC_EHDFERR.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ NXCDF_check_atomic_type()

int NXCDF_check_atomic_type ( NXCDF_FILE_INFO_T * file,
nc_type xtype )

Check whether an atomic type is allowed for the file's compatibility mode.

Called at nc_def_var/nc_put_att time. NC_CLASSIC_MODEL files accept only the six classic types; NC_NETCDF4_MODEL adds the enhanced types (unsigned ints, int64, string) but not the nxCDF-only types (small floats, complex, bitfields, references), keeping the file readable by upstream netcdf-c. See the mode table in nxCDF Architecture.

Parameters
filenxCDF file state.
xtypeCandidate NetCDF type.
Returns
NC_NOERR or NC_EBADTYPE/NC_ENOTNC4.

◆ NXCDF_check_write_define()

int NXCDF_check_write_define ( NC_FILE_INFO_T * h5,
NXCDF_FILE_INFO_T * file )

Check that a file is writable and currently in define mode.

Common guard for every metadata-changing dispatch entry (nc_def_*, nc_rename_*, nc_put_att, nc_del_att). netCDF semantics require define mode for metadata changes; files opened read-only reject them outright. A metadata call in data mode silently re-enters define mode, as upstream NC4_redef does; classic-model files keep the strict NC_ENOTINDEFINE rule.

Parameters
h5NetCDF-4 file state (may be NULL).
filenxCDF file state.
Returns
NC_NOERR, NC_EPERM (read-only file), or NC_ENOTINDEFINE.

◆ nxcdf_create_var_dataset()

int nxcdf_create_var_dataset ( NC_VAR_INFO_T * var,
NC_FILE_INFO_T * h5,
NXCDF_FILE_INFO_T * file,
NC_GRP_INFO_T * grp )

Create or re-create the HDF5 dataset for a variable.

Called by NXCDF_def_var and from NXCDF__enddef for every variable a def-var setter marked dcpl_dirty: because HDF5 dataset creation properties are immutable, changing chunking/compression/fill/endian requires deleting the dataset link and recreating it with a new creation property list. Recreation detaches the dimension-scale references that point at the old object, rewrites the hidden id attributes and the variable's scale attachments, re-attaches a coordinate variable's dependents to the new scale, and restores the user attributes the delete dropped. The variable's filter pipeline comes from var->filters via nxcdf_apply_filters().

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

◆ nxcdf_dcpl_fill()

int nxcdf_dcpl_fill ( hid_t dcpl,
NC_FILE_INFO_T * h5,
NC_VAR_INFO_T * var,
hid_t hdf_type )
static

Write the variable's fill setting to a dataset creation property list.

Mirrors upstream: no_fill disables fill entirely; otherwise the user's fill value or the type default is written, so unwritten elements read back NC_FILL_* instead of HDF5's zero default.

Parameters
dcplDataset creation property list.
h5NetCDF-4 file state.
varVariable.
hdf_typeDataset HDF5 datatype.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_dim()

int NXCDF_def_dim ( int ncid,
const char * name,
size_t len,
int * idp )

Define a dimension — the nc_def_dim() dispatch entry.

nxCDF stores each dimension as an HDF5 dimension scale: a 1-D int8 dataset marked CLASS = "DIMENSION_SCALE" with hidden NAME and _Netcdf4Dimid attributes. An unlimited dimension (len == 0) becomes a chunked dataset with H5S_UNLIMITED extent. Classic-model files get at most one unlimited dimension.

Parameters
ncidNetCDF file identifier.
nameDimension name.
lenDimension length, or 0 for unlimited.
idpDestination for the assigned dimension id.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_var()

int NXCDF_def_var ( int ncid,
const char * name,
nc_type xtype,
int ndims,
const int * dimidsp,
int * varidp )

Define a variable — the nc_def_var() dispatch entry.

Builds the NC_VAR_INFO_T record and creates the HDF5 dataset immediately: scalar variables get a scalar dataspace, dimensioned variables a simple dataspace (unlimited dims force chunked layout). The hidden _Netcdf4Varid and _Netcdf4Coordinates attributes are written on the dataset, and each dimension's scale is attached with H5DSattach_scale. A 1-D variable named after its only dimension is a coordinate variable — it replaces the dimension's scale dataset so the variable's data is the scale.

var->storage starts at -1 ("not specified") so that layout is decided here and a later def-var setter cannot silently change it (issue #382).

Parameters
ncidNetCDF file identifier.
nameVariable name.
xtypeNetCDF atomic type.
ndimsNumber of dimensions.
dimidspArray of dimension ids.
varidpDestination for the assigned variable id.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_var_chunking()

int NXCDF_def_var_chunking ( int ncid,
int varid,
int storage,
const size_t * chunksizesp )

Set storage and chunk sizes — the nc_def_var_chunking() dispatch entry.

Records the layout and per-dimension chunk sizes and marks the variable dcpl_dirty; layout is fixed at dataset creation in HDF5, so _enddef rebuilds the dataset once with the new creation properties.

Parameters
ncidNetCDF file identifier.
varidVariable identifier.
storageStorage class (NC_CHUNKED or NC_CONTIGUOUS; NC_COMPACT is rejected).
chunksizespChunk size for each dimension, or NULL.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_var_endian()

int NXCDF_def_var_endian ( int ncid,
int varid,
int endianness )

Set the on-disk byte order — the nc_def_var_endian() dispatch entry.

Records the byte order on the variable and marks it dcpl_dirty; the _enddef rebuild applies it to the dataset's datatype. NC_ENDIAN_NATIVE leaves the little-endian default produced by NXCDF_map_hdf_type().

Parameters
ncidNetCDF file identifier.
varidVariable id.
endiannessNC_ENDIAN_NATIVE, NC_ENDIAN_LITTLE or NC_ENDIAN_BIG.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_var_fill()

int NXCDF_def_var_fill ( int ncid,
int varid,
int no_fill,
const void * fill_value )

Set fill behavior — the nc_def_var_fill() dispatch entry.

Stores the no-fill flag and a private copy of the fill value on the variable and marks it dcpl_dirty: fill value and fill time are HDF5 creation properties, so _enddef rebuilds the dataset once with them.

Parameters
ncidNetCDF file identifier.
varidVariable id.
no_fillNonzero to suppress fill values.
fill_valueFill value, or NULL for the type default.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_var_quantize()

int NXCDF_def_var_quantize ( int ncid,
int varid,
int quantize_mode,
int nsd )

Set quantization — the nc_def_var_quantize() dispatch entry.

Quantization records a mode and precision on the variable; it is applied at write time by nxcdf_convert_type(), so no dataset recreation is needed here.

Parameters
ncidNetCDF file identifier.
varidVariable id.
quantize_modeNC_NOQUANTIZE, NC_QUANTIZE_BITGROOM, NC_QUANTIZE_GRANULARBR or NC_QUANTIZE_BITROUND.
nsdNumber of significant digits.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_del_att()

int NXCDF_del_att ( int ncid,
int varid,
const char * name )

Delete an attribute from a group or variable.

Parameters
ncidNetCDF file identifier.
varidVariable id or NC_GLOBAL.
nameAttribute name.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_dim_wo_var_name()

void nxcdf_dim_wo_var_name ( const NC_DIM_INFO_T * dim,
char * namebuf,
size_t buflen )
static

Build the scale NAME for a dimension without a variable.

Upstream marks a dimension scale that has no coordinate variable with a NAME attribute of DIM_WITHOUT_VARIABLE plus the dimension length; a scale whose NAME is anything else is read by upstream as a coordinate variable. The HDF5 link keeps the dimension's name.

Parameters
dimDimension.
namebufDestination buffer.
buflenSize of namebuf.

◆ nxcdf_dimscale_create()

int nxcdf_dimscale_create ( NXCDF_FILE_INFO_T * file,
NC_GRP_INFO_T * grp,
NC_DIM_INFO_T * dim,
const char * name,
hid_t * dsetp )
static

Create a standalone dimension-scale dataset for a dimension.

Used when a coordinate-variable relationship ends and the dimension no longer shares its dataset with a variable. The scale carries CLASS, NAME and _Netcdf4Dimid attributes like the scales def_dim creates.

Parameters
filenxCDF file state.
grpGroup containing the dimension.
dimDimension.
nameLink and scale name.
dsetpReceives the new dataset identifier.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_fill_from_att()

int nxcdf_fill_from_att ( NC_VAR_INFO_T * var)
static

Mirror a loaded _FillValue attribute into var->fill_value.

_FillValue loads as a normal attribute; when present it is the authoritative fill for nc_inq_var_fill() — the DCPL fill message recovered earlier fills only the gap when no attribute exists.

Parameters
varVariable whose attribute index was just populated.
Returns
NC_NOERR or a NetCDF allocation/type error.

◆ nxcdf_find_var_for_write()

int nxcdf_find_var_for_write ( int ncid,
int varid,
NC_FILE_INFO_T ** h5,
NXCDF_FILE_INFO_T ** file,
NC_GRP_INFO_T ** grp,
NC_VAR_INFO_T ** var )

Common prologue for the def-var setter dispatch functions.

Resolves the variable and file state and checks define-mode write access, so each setter only validates its own arguments.

Parameters
ncidNetCDF file identifier.
varidVariable identifier.
h5Destination for the NetCDF-4 file state.
fileDestination for the nxCDF file state.
grpDestination for the group.
varDestination for the variable.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_flush_pending_atts()

int nxcdf_flush_pending_atts ( NC_GRP_INFO_T * grp)

Materialize attributes deferred while their datatype or dataset was pending — called at _enddef.

Attributes whose datatype was an uncommitted user type, or that live on a user-typed variable whose dataset did not exist yet, are marked atts_pending on the owning group/variable. Once NXCDF_write_types() and the deferred dataset creations have run, this rewrites the pending objects' attribute lists in index order, preserving definition order on disk.

Parameters
grpGroup to walk (recursively).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_get_att()

int NXCDF_get_att ( int ncid,
int varid,
const char * name,
void * value,
nc_type memtype )

Read an attribute's value — the nc_get_att_* dispatch entry.

Reads from the in-memory record (all attributes were loaded at open), converting through nxcdf_convert_type() when the caller asks for a different type. NC_STRING attributes return strdup'd strings the caller owns.

Parameters
ncidNetCDF file identifier.
varidVariable id or NC_GLOBAL.
nameAttribute name.
valueDestination buffer.
memtypeRequested in-memory type.
Returns
NC_NOERR on success, NC_ERANGE when data was delivered but overflowed, or a NetCDF error code.

◆ NXCDF_get_var_chunk_cache()

int NXCDF_get_var_chunk_cache ( int ncid,
int varid,
size_t * sizep,
size_t * nelemsp,
float * preemptionp )

Inquire effective chunk cache properties, allowing NULL outputs. A pending or nonchunked variable reports its stored session request. Live chunked variables report the DAPL actually attached to the dataset handle.

Inquire effective live chunk-cache settings or pending requests.

Parameters
ncidFile or group identifier.
varidVariable identifier within the group.
sizepOptional byte-capacity destination.
nelemspOptional hash-slot destination.
preemptionpOptional preemption destination.
Returns
NC_NOERR or an identifier/HDF5 error.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ NXCDF_inq_att()

int NXCDF_inq_att ( int ncid,
int varid,
const char * name,
nc_type * xtypep,
size_t * lenp )

Inquire about an attribute — the nc_inq_att() dispatch entry.

Stock NC4_inq_att resolves att->nc_typeid through nc4_find_type(), which knows only stock atomic typeids and the file's user-defined types — NEP atomic types (float16, bitfield, NC_STD_REF, ...) all fail there. This version returns the stored typeid directly, so nc_inq_att() and the generic nc_get_att() work for NEP types.

Parameters
ncidNetCDF file identifier.
varidVariable id or NC_GLOBAL.
nameAttribute name.
xtypepDestination for the attribute's type, or NULL.
lenpDestination for the attribute's length, or NULL.
Returns
NC_NOERR on success, NC_ENOTATT when the attribute does not exist, or a NetCDF error code.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ NXCDF_inq_attid()

int NXCDF_inq_attid ( int ncid,
int varid,
const char * name,
int * attnump )

Learn an attribute's index by name — the nc_inq_attid() dispatch entry.

The shared NC4_inq_attid cannot intercept the provenance names, which live outside the attribute index; this entry answers them with upstream's NC_EATTMETA (virtual attributes have no index) and otherwise returns the attribute's position in the index.

Parameters
ncidNetCDF file identifier.
varidVariable id or NC_GLOBAL.
nameAttribute name.
attnumpDestination for the attribute index.
Returns
NC_NOERR on success, NC_EATTMETA for a provenance name, NC_ENOTATT when the attribute does not exist, or a NetCDF error code.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ NXCDF_inq_dim()

int NXCDF_inq_dim ( int ncid,
int dimid,
char * name,
size_t * lenp )

Inquire about a dimension — the nc_inq_dim() dispatch entry.

Answers from the in-memory tree; for an unlimited dimension lenp is the current length.

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

◆ NXCDF_inq_var()

int NXCDF_inq_var ( int ncid,
int varid,
char * name,
nc_type * xtypep,
int * ndimsp,
int * dimidsp,
int * nattsp )

Inquire about a variable's name, type, dimensions, and attributes — the nc_inq_var() dispatch entry.

Parameters
ncidNetCDF file identifier.
varidVariable id.
nameDestination for the variable name.
xtypepDestination for the variable type.
ndimspDestination for the rank.
dimidspDestination for the dimension ids.
nattspDestination for the number of attributes.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_var_all()

int NXCDF_inq_var_all ( int ncid,
int varid,
char * name,
nc_type * xtypep,
int * ndimsp,
int * dimidsp,
int * nattsp,
int * shufflep,
int * deflatep,
int * deflate_levelp,
int * fletcher32p,
int * contiguousp,
size_t * chunksizesp,
int * no_fillp,
void * fill_valuep,
int * endiannessp,
unsigned int * idp,
size_t * nparamsp,
unsigned int * params )

Inquire about all supported properties of a variable — the nc_inq_var_all() dispatch entry.

The kitchen-sink inquiry used internally by netcdf-c; every output pointer is optional. The idp/nparamsp/params filter outputs are never populated — upstream's shared NC4_inq_var_all doesn't populate them either; filter inquiry goes through nc_inq_var_filter_ids()/nc_inq_var_filter_info().

Parameters
ncidNetCDF file identifier.
varidVariable id.
nameDestination for the variable name.
xtypepDestination for the variable type.
ndimspDestination for the rank.
dimidspDestination for the dimension ids.
nattspDestination for the number of attributes.
shufflepDestination for the shuffle flag.
deflatepDestination for the deflate flag.
deflate_levelpDestination for the deflate level.
fletcher32pDestination for the Fletcher32 flag.
contiguouspDestination for the contiguous-storage flag.
chunksizespDestination for the chunk sizes.
no_fillpDestination for the no-fill flag.
fill_valuepDestination for the fill value.
endiannesspDestination for the endianness.
idpDestination for the filter ids.
nparamspDestination for the filter parameter count.
paramsDestination for the filter parameters.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_load_metadata()

int NXCDF_load_metadata ( NXCDF_FILE_INFO_T * file,
NC_FILE_INFO_T * h5 )

Load all metadata for an open nxCDF file — the entry point NXCDF_open() calls after checking the marker attributes.

Recursively walks the HDF5 file starting at the root group and rebuilds the complete NC_*_INFO_T tree (groups, dimensions, variables, attributes, committed types) that the dispatch entries then operate on. See nxCDF Architecture.

Parameters
fileOpen nxCDF state.
h5Common NetCDF-4 file metadata.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_map_hdf_type()

int NXCDF_map_hdf_type ( nc_type xtype,
hid_t * typep )

Map an atomic nc_type to its on-disk HDF5 datatype.

Every netCDF atomic type is stored as a copy of an HDF5 predefined type — little-endian for numerics so files are architecture-independent. The mapping covers the standard types (NC_BYTE…NC_DOUBLE, NC_CHAR, NC_STRING) plus nxCDF's extended set: NC_FLOAT16, NC_BFLOAT16, the HDF5 2.x small floats (FP8/FP6/FP4), complex, bitfields, and the reference type NC_STD_REF. The caller owns the returned hid_t and must H5Tclose it. The inverse mapping (disk → nc_type) is map_nc_type().

Parameters
xtypeNetCDF atomic type.
typepDestination for an HDF5 datatype identifier.
Returns
NC_NOERR or NC_EBADTYPE.

◆ NXCDF_put_att()

int NXCDF_put_att ( int ncid,
int varid,
const char * name,
nc_type datatype,
size_t len,
const void * value,
nc_type memtype )

Create or replace an attribute — the nc_put_att_* dispatch entry.

Converts the value from the caller's memory type to the attribute's storage type through nxcdf_convert_type() (overflow returns NC_ERANGE after the write), replaces any same-named attribute in both the in-memory index and HDF5, and persists immediately — attributes are written to the file in define mode, not deferred to _enddef. Reserved (internal) names are rejected.

Parameters
ncidNetCDF file identifier.
varidVariable id or NC_GLOBAL.
nameAttribute name.
datatypeNetCDF atomic type.
lenNumber of elements.
valueAttribute data.
memtypeIn-memory type for the attribute value.
Returns
NC_NOERR on success, NC_ERANGE when the value was written but overflowed during conversion, or a NetCDF error code.

◆ nxcdf_quantize_from_att()

int nxcdf_quantize_from_att ( NC_VAR_INFO_T * var)
static

Restore a variable's quantize setting from its _Quantize* attribute.

Upstream persists quantize as a one-element integer attribute whose name encodes the mode; the attribute loads as a normal user-visible attribute, so this mirrors the value into var->quantize_mode and var->nsd for nc_inq_var_quantize() and write-time quantization.

Parameters
varVariable whose attribute index was just populated.
Returns
NC_NOERR always; missing or malformed attributes leave the defaults alone.

◆ nxcdf_reattach_dim()

int nxcdf_reattach_dim ( NC_GRP_INFO_T * grp,
NC_DIM_INFO_T * dim,
hid_t old_dset,
hid_t new_dset,
NC_VAR_INFO_T * skip )
static

Reattach every variable on a dimension from one scale dataset to another.

Mirrors upstream's rec_detach_scales(): all variables in grp (recursively) that attach old_dset as the scale for dim are detached and re-attached to new_dset. skip is exempted (the coordinate variable being broken/reformed never self-attaches).

Parameters
grpGroup to walk.
dimDimension whose scale changed.
old_dsetPrevious scale dataset.
new_dsetNew scale dataset.
skipVariable to exempt, or NULL.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_reform_coord_var()

int nxcdf_reform_coord_var ( NXCDF_FILE_INFO_T * file,
NC_GRP_INFO_T * grp,
NC_DIM_INFO_T * dim,
NC_VAR_INFO_T * var )
static

Reform a coordinate-variable relationship.

Upstream nc4_reform_coord_var() semantics: var's dataset becomes the dimension's scale — it gains CLASS/NAME/_Netcdf4Dimid markers, every other variable on the dimension is reattached to it, and the dimension's previous standalone scale (if any) is unlinked.

Parameters
filenxCDF file state.
grpGroup containing the dimension.
dimDimension regaining a coordinate variable.
varVariable whose dataset becomes the scale.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_rename_att()

int NXCDF_rename_att ( int ncid,
int varid,
const char * name,
const char * newname )

Rename an attribute — the nc_rename_att() dispatch entry.

HDF5 attributes cannot be renamed in place, so the old attribute is deleted and the value rewritten under the new name via NXCDF_put_att(); the in-memory index is rebuilt by delete-and-re-add for the same reason.

Parameters
ncidNetCDF file identifier.
varidVariable id or NC_GLOBAL.
nameCurrent attribute name.
newnameNew attribute name.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_rename_dim()

int NXCDF_rename_dim ( int ncid,
int dimid,
const char * name )

Rename a dimension and update its HDF5 link.

Parameters
ncidNetCDF file identifier.
dimidDimension id.
nameNew dimension name.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_rename_var()

int NXCDF_rename_var ( int ncid,
int varid,
const char * name )

Rename a variable and update its HDF5 link.

Parameters
ncidNetCDF file identifier.
varidVariable id.
nameNew variable name.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_reopen_var_cache()

int nxcdf_reopen_var_cache ( NC_GRP_INFO_T * grp,
NC_VAR_INFO_T * var )
static

Reopen every owned alias of a variable with its requested cache. Object identity and metadata stay unchanged. If reopening fails, restore the previous DAPL where possible; a failed recovery leaves invalid, not stale, handles and returns an HDF5 error.

Parameters
grpVariable's containing group.
varVariable whose session request should become effective.
Returns
NC_NOERR, NC_ENOMEM or NC_EHDFERR.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nxcdf_rewrite_atts()

int nxcdf_rewrite_atts ( hid_t loc,
NCindex * list,
NC_GRP_INFO_T * grp )
static

Rewrite every attribute on an HDF5 object in index order.

netcdf-c defers attribute writes to _enddef, so the on-disk creation order always matches the metadata index order. nxCDF writes eagerly: a renamed or replaced attribute would land last in HDF5 creation order and reopen in the wrong position. Deleting the indexed attributes and rewriting them in index order keeps the two consistent. Internal (_Netcdf4*, CLASS, ...) attributes are not in the index and are untouched.

Parameters
locHDF5 object (dataset or group).
listAttribute index.
grpGroup used to resolve user-defined datatypes.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_set_att_order()

int nxcdf_set_att_order ( hid_t ocpl)
static

Attribute names that are internal to nxCDF/HDF5.

Enable HDF5 attribute creation-order tracking on an object creation property list.

nxCDF (and the NetCDF-4/HDF5 convention generally) stores bookkeeping as ordinary HDF5 attributes: marker attributes like _NxcdfBackend, dimension-scale attributes like CLASS and NAME, and netcdf-c's own conventions like _Netcdf4Coordinates and _FillValue. They must never appear in nc_inq_att* results, so is_reserved_att() filters them during metadata load and nc_put_att/nc_rename_att reject them as user names.

Upstream netcdf-4 tracks attribute creation order on every group and dataset so nc_inq_attname() returns names in creation order after reopen; nxCDF does the same and iterates with H5_INDEX_CRT_ORDER at load.

Parameters
ocplObject creation property list.
Returns
NC_NOERR on success, NC_EHDFERR on failure.

◆ NXCDF_set_var_chunk_cache()

int NXCDF_set_var_chunk_cache ( int ncid,
int varid,
size_t size,
size_t nelems,
float preemption )

Apply session-only cache settings without recreating dataset storage. Read-only and data-mode calls are permitted. Pending datasets retain the request until creation; live datasets reopen all owned aliases together.

Set session cache parameters and reopen an existing dataset.

Parameters
ncidFile or group identifier.
varidVariable identifier within the group.
sizeCache capacity in bytes; zero disables raw chunk caching.
nelemsHash slot count; zero is permitted.
preemptionFinite cache preemption weight in [0,1].
Returns
NC_NOERR or an identifier, validation, memory or HDF5 error.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ NXCDF_type_name()

const char * NXCDF_type_name ( nc_type xtype)

Return the short name for an atomic nc_type.

These names ("float16", "bfloat16", ...) label the in-memory NC_TYPE_INFO_T records set_var_type() builds for atomic-typed variables.

Parameters
xtypeNetCDF atomic type.
Returns
Static name string, or "unknown".

◆ NXCDF_type_size()

int NXCDF_type_size ( nc_type xtype,
size_t * sizep )

Return the in-memory size, in bytes, of an atomic nc_type.

This is the size of one element in a user buffer: NC_STRING is sizeof(char *), references are their opaque token sizes (8 and 12 bytes), the sub-byte small floats round up to 1 byte.

Parameters
xtypeNetCDF atomic type.
sizepDestination for the size in bytes.
Returns
NC_NOERR or NC_EBADTYPE.

◆ nxcdf_type_varsized()

int nxcdf_type_varsized ( NC_GRP_INFO_T * grp,
nc_type xtype,
int * vsp )
static

Report whether a type is (transitively) variable-sized.

Dynamic types — vlens and compounds containing them — carry pointers inside each element, so values must be deep-copied and reclaimed rather than memcpy'd and free'd.

Parameters
grpGroup used to resolve user-defined types.
xtypeNetCDF atomic or user-defined type.
vspDestination for the variable-sized flag.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_var_dapl()

int nxcdf_var_dapl ( const NC_VAR_INFO_T * var,
hid_t * daplp )
static

Build an owned access-property list from a variable's session settings.

Parameters
varVariable holding bytes, slots and preemption in netCDF order.
daplpDestination for the owned HDF5 property list.
Returns
NC_NOERR or NC_EHDFERR.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nxcdf_write_att()

int nxcdf_write_att ( hid_t loc,
const NC_ATT_INFO_T * att,
NC_GRP_INFO_T * grp )
static

Write one in-memory attribute to an HDF5 object.

The attribute name/type/length/data come from att; the HDF5 datatype maps from att->nc_typeid.

Parameters
locHDF5 object (dataset or group) to write on.
attAttribute to write.
grpGroup used to resolve user-defined datatypes.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_write_quantize_att()

int nxcdf_write_quantize_att ( hid_t dataset,
const NC_VAR_INFO_T * var )
static

Persist a variable's quantize setting as the upstream _Quantize* attribute.

Upstream stores the mode in the attribute name and the NSD/NSB as a one-element integer attribute on the variable's dataset (libhdf5/nc4hdf.c write_quantize_att), so this writes the identical object — no-op for NC_NOQUANTIZE.

Parameters
datasetOpen HDF5 dataset for the variable.
varVariable holding quantize_mode and nsd.
Returns
NC_NOERR on success, NC_EINVAL for an unknown mode, or NC_EHDFERR.

◆ read_hdf5_att()

int read_hdf5_att ( hid_t loc,
const char * name,
NCindex * list,
NC_OBJ * container,
NC_GRP_INFO_T * grp )
static

Read one HDF5 attribute into the in-memory model.

Loader helper: opens the attribute, maps its datatype through map_nc_type(), reads the values with a matching memory type, and registers the result via add_att(). Attributes whose datatype does not map to an atomic nc_type fail — the caller skips them so an unrecognised attribute cannot sink a file open.

Parameters
locHDF5 location identifier.
nameName.
listAttribute index to add to.
containerObject that owns the attribute.
grpGroup used to resolve committed user-defined datatypes.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ resolve_var_dimids()

int resolve_var_dimids ( NC_GRP_INFO_T * grp,
hid_t dset,
int ndims,
int * dimids )
static

Resolve a variable's dimids from its attached dimension scales.

Fallback for variables lacking the _Netcdf4Coordinates attribute: each dimension must have at least one scale attached, resolved by scale_resolve_visitor().

Parameters
grpGroup.
dsetVariable dataset.
ndimsNumber of dimensions.
dimidsDestination for the resolved dimension IDs.
Returns
NC_NOERR on success, NC_EFILEMETA/NC_EBADDIM when the scales cannot be resolved.

◆ scale_resolve_visitor()

int scale_resolve_visitor ( hid_t did,
unsigned int dim,
hid_t dsid,
void * op_data )
static

H5DSiterate_scales visitor resolving one attached scale to a dimid.

Prefers the scale's _Netcdf4Dimid attribute; falls back to matching the scale's name against the group's dimensions for files written without the attribute. Only the first attached scale per dimension is used.

Parameters
didDimension scale dataset being visited (unused).
dimDimension index being visited (unused).
dsidVariable dataset the scale is attached to.
op_dataresolve_scale_t search context.
Returns
0 always (iteration continues or stops via found).

◆ set_var_type()

int set_var_type ( NC_VAR_INFO_T * var,
nc_type xtype )
static

Build the NC_TYPE_INFO_T record for an atomic-typed variable.

netcdf-c expects every variable to point at a type record; atomic types get a small synthetic one whose hdr.id is the nc_type itself. The nc_type_class mapping groups the extended types onto classic classes (small floats → NC_FLOAT, bitfields → NC_INT, references → NC_OPAQUE) so shared NC4_* inquiry helpers keep working.

Parameters
varVariable.
xtypeNetCDF atomic type.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ write_int_array_att()

int write_int_array_att ( hid_t loc,
const char * name,
const int * values,
size_t len )
static

Write an array of 32-bit integers as an HDF5 attribute.

Helper for _Netcdf4Coordinates, which records a variable's dimids so open can recover them without walking dimension scales. A zero-length attribute uses an H5S_NULL dataspace.

Parameters
locHDF5 location identifier.
nameName.
valuesArray of int values to write.
lenNumber of values.
Returns
NC_NOERR on success, or NC_EHDFERR.

◆ write_int_att()

int write_int_att ( hid_t loc,
const char * name,
int value )
static

Write a one-element 32-bit integer HDF5 attribute.

Helper for the hidden id attributes (_Netcdf4Dimid, _Netcdf4Varid).

Parameters
locHDF5 location identifier.
nameName.
valueData buffer.
Returns
NC_NOERR on success, or NC_EHDFERR.

◆ write_string_att()

int write_string_att ( hid_t loc,
const char * name,
const char * value )
static

Write a null-terminated scalar string HDF5 attribute.

Helper for the hidden marker attributes (CLASS, NAME) written on dimension scales.

Parameters
locHDF5 location identifier.
nameName.
valueData buffer.
Returns
NC_NOERR on success, or NC_EHDFERR.

Variable Documentation

◆ reserved_atts

const char* reserved_atts[]
static
Initial value:
= {
"CLASS",
"NAME",
"REFERENCE_LIST",
"DIMENSION_LIST",
"_Netcdf4Coordinates",
"_FillValue",
"_Format",
"_nc3_strict",
"_NCProperties",
"_SuperblockVersion",
"_IsNetcdf4",
"_ARRAY_DIMENSIONS",
"_Codecs",
NULL
}
#define NXCDF_BACKEND_ATT
Hidden root attribute identifying a nxCDF-created file.
Definition nxcdf_internal.h:106
#define NXCDF_MODEL_ATT
Hidden root attribute marking NC_NETCDF4_MODEL compatibility mode, so the mode survives reopen.
Definition nxcdf_internal.h:109
#define NXCDF_DIMID_ATT
Hidden attribute on a dimension scale storing its stable NetCDF dimid, so ids survive reopen independ...
Definition nxcdf_internal.h:115
#define NXCDF_VARID_ATT
Hidden attribute on a variable dataset storing its stable NetCDF varid.
Definition nxcdf_internal.h:118
#define NXCDF_VARDIMIDS_ATT
Hidden attribute on a variable dataset storing its dimid list — the fast path for recovering a variab...
Definition nxcdf_internal.h:122