NEP 4.3.0
NetCDF Expansion Pack
Loading...
Searching...
No Matches
nxcdf.h File Reference

Public API for the nxCDF UDF backend. More...

#include <stdint.h>
#include <netcdf.h>
#include <netcdf_dispatch.h>
#include <nep.h>

Go to the source code of this file.

Data Structures

struct  nc_std_ref_s

Macros

#define NC_FORMATX_NXCDF   NC_FORMATX_UDF9
 Extended format identifier reported by nc_inq_format_extended() for nxCDF files.
#define NC_NXCDF   NEP_UDF_NXCDF
#define NC_NETCDF4_MODEL   0x04000000
#define NC_SWMR_WRITE   0x08000000
#define NC_SWMR_READ   0x10000000
#define NC_FLOAT16   17
#define NC_BFLOAT16   18
#define NC_FLOAT8_E4M3   19
#define NC_FLOAT8_E5M2   20
#define NC_FLOAT6_E2M3   21
#define NC_FLOAT6_E3M2   22
#define NC_FLOAT4_E2M1   23
#define NC_COMPLEX   24
#define NC_DOUBLECOMPLEX   25
#define NC_BITFIELD8   26
#define NC_BITFIELD16   27
#define NC_BITFIELD32   28
#define NC_BITFIELD64   29
#define NC_STD_REF   30
#define NC_STD_REF_SIZE   64
#define NC_STD_REF_OBJECT   1
#define NC_STD_REF_REGION   2
#define NC_STD_REF_ATTR   3
#define NC_REF_OBJ_VAR   1
#define NC_REF_OBJ_GRP   2
#define NC_REF_OBJ_TYPE   3
#define NC_REF_OBJ_ATT   4

Typedefs

typedef struct nc_std_ref_s nc_std_ref_t

Functions

NC_Dispatch * NC_NXCDF_initialize (void)
 Register the nxCDF dispatch table in UDF slot 9.
int NC_NXCDF_finalize (void)
 Finalize process-wide nxCDF dispatch state.
int nc_ref_object (int ncid, int obj_type, int objid, nc_std_ref_t *ref)
 Create an HDF5 object reference to a variable, group, or user-defined type in a nxCDF file.
int nc_deref_object (int ncid, const nc_std_ref_t *ref, int *obj_typep, int *grpidp, int *idp)
 Resolve an object reference token back to NetCDF ids.
int nc_ref_region (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, nc_std_ref_t *ref)
 Create a dataset region reference to a strided hyperslab of a variable in a nxCDF file.
int nc_deref_region (int ncid, const nc_std_ref_t *ref, int *grpidp, int *varidp, int *ndimsp, size_t *startp, size_t *countp, ptrdiff_t *stridep)
 Resolve a dataset region reference token back to its variable and selection.
int nc_ref_attr (int ncid, int obj_type, int objid, const char *att_name, nc_std_ref_t *ref)
 Create an HDF5 attribute reference to an attribute on a variable, group, or committed datatype in a nxCDF file.
int nc_deref_attr (int ncid, const nc_std_ref_t *ref, int *obj_typep, int *grpidp, int *idp, char *att_name)
 Resolve an attribute reference token back to its owner and attribute name.
int nc_ref_object_ext (int ncid, const char *filename, const char *path, nc_std_ref_t *ref)
 Create an object reference pointing into another file.
int nc_ref_region_ext (int ncid, const char *filename, const char *path, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, nc_std_ref_t *ref)
 Create a dataset region reference pointing into another file.
int nc_ref_attr_ext (int ncid, const char *filename, const char *path, const char *att_name, nc_std_ref_t *ref)
 Create an attribute reference pointing into another file.
int nc_ref_open_target (int ncid, const nc_std_ref_t *ref, int *target_ncidp)
 Open the external file a reference token points into.
int nc_ref_get_type (const nc_std_ref_t *ref, int *ref_typep)
 Report the kind of a reference token.
int nc_ref_get_file_name (const nc_std_ref_t *ref, char *name, size_t size)
 Copy the file name stored in a reference token.
int nc_ref_get_obj_name (const nc_std_ref_t *ref, char *name, size_t size)
 Copy the object path stored in a reference token.
int nc_ref_free (nc_std_ref_t *ref)
 Release the resources held by a reference token.
int nc_ref_open_remote (int ncid, const char *url, const char *path, int *target_ncidp, int *kindp, int *objidp, char *att_name, size_t att_name_size)
 Open a remote reference target and resolve its object path.
int nc_ref_resolve (int ncid, const char *path, int *kindp, int *objidp, char *att_name, size_t att_name_size)
 Resolve an object path on an already-open remote session.
int nc_start_swmr_write (int ncid)
 Start a single-writer/multiple-reader session on a native nxCDF file.
int nc_swmr_flush (int ncid)
 Publish all datasets and dimension scales of an active SWMR writer.
int nc_swmr_refresh (int ncid)
 Refresh a nxCDF SWMR reader session so newly published data becomes visible.

Detailed Description

Public API for the nxCDF UDF backend.

nxCDF is a netCDF User Defined Format (UDF) backend: a plug-in file format registered in UDF slot 9 (NC_NXCDF). This installed header declares everything applications need — the mode flags, the extended format identifier, the initialize/finalize pair, the nxCDF atomic types, and the reference, remote-reference, and SWMR APIs. nc_create()/nc_open() with the NC_NXCDF mode flag routes to the backend through netcdf-c; see nxCDF Architecture.

This header may be included by downstream projects: it depends only on installed netcdf-c headers and nep.h.

Author
Edward Hartnett
Date
2026-08-28

Macro Definition Documentation

◆ NC_BFLOAT16

#define NC_BFLOAT16   18

nxCDF 16-bit bfloat16 floating point type (HDF5 2.1.1+). Untyped I/O uses raw uint16_t; typed float/double I/O uses NEP round-to-nearest-even, with single rounding from double.

◆ NC_BITFIELD16

#define NC_BITFIELD16   27

nxCDF 16-bit bitfield type.

◆ NC_BITFIELD32

#define NC_BITFIELD32   28

nxCDF 32-bit bitfield type.

◆ NC_BITFIELD64

#define NC_BITFIELD64   29

nxCDF 64-bit bitfield type.

◆ NC_BITFIELD8

#define NC_BITFIELD8   26

nxCDF 8-bit bitfield type.

◆ NC_COMPLEX

#define NC_COMPLEX   24

nxCDF single-precision complex number type.

◆ NC_DOUBLECOMPLEX

#define NC_DOUBLECOMPLEX   25

nxCDF double-precision complex number type.

◆ NC_FLOAT16

#define NC_FLOAT16   17

nxCDF 16-bit IEEE 754 half-precision floating point type. Untyped I/O uses raw uint16_t; typed float/double I/O uses NEP round-to-nearest-even, with single rounding from double.

◆ NC_FLOAT4_E2M1

#define NC_FLOAT4_E2M1   23

nxCDF 4-bit E2M1 floating point type (HDF5 2.1.1+). Untyped I/O (raw uint8_t) only.

◆ NC_FLOAT6_E2M3

#define NC_FLOAT6_E2M3   21

nxCDF 6-bit E2M3 floating point type (HDF5 2.1.1+). Untyped I/O (raw uint8_t) only.

◆ NC_FLOAT6_E3M2

#define NC_FLOAT6_E3M2   22

nxCDF 6-bit E3M2 floating point type (HDF5 2.1.1+). Untyped I/O (raw uint8_t) only.

◆ NC_FLOAT8_E4M3

#define NC_FLOAT8_E4M3   19

nxCDF 8-bit E4M3 floating point type (HDF5 2.1.1+). Untyped I/O (raw uint8_t) only.

◆ NC_FLOAT8_E5M2

#define NC_FLOAT8_E5M2   20

nxCDF 8-bit E5M2 floating point type (HDF5 2.1.1+). Untyped I/O (raw uint8_t) only.

◆ NC_FORMATX_NXCDF

#define NC_FORMATX_NXCDF   NC_FORMATX_UDF9

Extended format identifier reported by nc_inq_format_extended() for nxCDF files.

◆ NC_NETCDF4_MODEL

#define NC_NETCDF4_MODEL   0x04000000

Request NetCDF-4-model compatibility from the nxCDF backend

◆ NC_NXCDF

#define NC_NXCDF   NEP_UDF_NXCDF

Explicit create/open mode for the nxCDF backend

◆ NC_REF_OBJ_ATT

#define NC_REF_OBJ_ATT   4

Resolved object kind reported by nc_ref_resolve() and nc_ref_open_remote() when the stored path carried a #attname suffix: an attribute on the resolved owner. (Distinct from NC_STD_REF_ATTR, which shares its numeric value with NC_REF_OBJ_TYPE.)

◆ NC_REF_OBJ_GRP

#define NC_REF_OBJ_GRP   2

Reference target kind: a NetCDF group (HDF5 group).

◆ NC_REF_OBJ_TYPE

#define NC_REF_OBJ_TYPE   3

Reference target kind: a NetCDF user-defined type (HDF5 committed datatype).

◆ NC_REF_OBJ_VAR

#define NC_REF_OBJ_VAR   1

Reference target kind for nc_ref_object(), nc_ref_attr() and the nc_deref_*() functions: a NetCDF variable (HDF5 dataset).

◆ NC_STD_REF

#define NC_STD_REF   30

nxCDF HDF5 standard reference type (H5T_STD_REF). Elements are opaque 64-byte nc_std_ref_t tokens covering object, dataset region, and attribute references; see nc_ref_object() and friends. Native mode only.

◆ NC_STD_REF_ATTR

#define NC_STD_REF_ATTR   3

Attribute reference token kind, reported by nc_ref_get_type().

◆ NC_STD_REF_OBJECT

#define NC_STD_REF_OBJECT   1

Object reference token kind, reported by nc_ref_get_type().

◆ NC_STD_REF_REGION

#define NC_STD_REF_REGION   2

Dataset region reference token kind, reported by nc_ref_get_type().

◆ NC_STD_REF_SIZE

#define NC_STD_REF_SIZE   64

Bytes in one opaque nxCDF reference token. Matches HDF5 H5R_REF_BUF_SIZE (the size of H5R_ref_t).

◆ NC_SWMR_READ

#define NC_SWMR_READ   0x10000000

Request a native serial nxCDF SWMR reader session at open.

Read-only flag combined with NC_NXCDF in the mode of nc_open(). The file is opened with HDF5 SWMR read access so it can coexist with a live writer and observe records the writer publishes. Any file the HDF5 layer accepts for SWMR reading may be opened: a live writer's file, a quiescent file after the writer closed, or a file never written in SWMR mode — provided its superblock is v3, which includes NC_NETCDF4_MODEL files. After opening, the reader polls nc_swmr_refresh() and reads with the ordinary inquiry/data calls; multiple independent readers are supported. Rejected at nc_create, and at open when combined with NC_WRITE, NC_SWMR_WRITE, NC_CLASSIC_MODEL or MPI parameters. This is a NEP-only flag, not an upstream NetCDF mode. See nc_swmr_refresh().

◆ NC_SWMR_WRITE

#define NC_SWMR_WRITE   0x08000000

Request a native serial nxCDF SWMR writer session at create/open.

SWMR (Single Writer / Multiple Reader) lets one process write a file while other processes read it concurrently. Passing this flag in the cmode of nc_create() or the mode of nc_open(NC_WRITE) asks the backend to start HDF5 SWMR writing automatically: creates defer activation until enddef commits the schema, writable opens activate after metadata load. Equivalent to calling nc_start_swmr_write() after an ordinary open. Requires a native nxCDF file on a superblock-v3, SWMR-capable driver; rejected on MPI sessions and compatibility modes. Once active, the schema and attributes are frozen and the writer publishes data with nc_swmr_flush() or nc_sync(). This is a NEP-only flag, not an upstream NetCDF mode.

Typedef Documentation

◆ nc_std_ref_t

typedef struct nc_std_ref_s nc_std_ref_t

One opaque nxCDF reference token; layout-compatible with HDF5 H5R_ref_t so tokens move to and from the HDF5 reference API without conversion. Never interpret the bytes.

Function Documentation

◆ nc_deref_attr()

int nc_deref_attr ( int ncid,
const nc_std_ref_t * ref,
int * obj_typep,
int * grpidp,
int * idp,
char * att_name )

Resolve an attribute reference token back to its owner and attribute name.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Resolve an attribute reference token back to its owner and attribute name.

Reports the owner kind and ids as nc_deref_object() does, plus the attribute name. For an external token, ncid is the target session returned by nc_ref_open_target().

Parameters
ncidNetCDF file ID (nxCDF); for an external token, the session returned by nc_ref_open_target().
refReference token.
obj_typepReceives NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE for the attribute-bearing object; may be NULL.
grpidpContaining group's ncid (or the group itself for NC_REF_OBJ_GRP); may be NULL.
idpThe varid, group ncid, or typeid of the owner; may be NULL. For NC_REF_OBJ_TYPE owners the attribute value is read through the HDF5 API (H5Aopen/H5Aread), not the NetCDF API.
att_nameReceives the attribute name; must be a caller buffer of at least NC_MAX_NAME + 1 bytes, or NULL.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file; NC_EINVAL for a non-attribute token, a session that is not the token's target file, or a missing target; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_deref_object()

int nc_deref_object ( int ncid,
const nc_std_ref_t * ref,
int * obj_typep,
int * grpidp,
int * idp )

Resolve an object reference token back to NetCDF ids.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Reports the target kind (NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE), the containing group ncid, and the object id. For an external token, ncid is the target session returned by nc_ref_open_target() and the returned IDs belong to it.

Parameters
ncidNetCDF file ID (nxCDF); for an external token, the session returned by nc_ref_open_target().
refReference token.
obj_typepReceives NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE; may be NULL.
grpidpFor a variable or type, the containing group's ncid; for a group, the group ncid itself. May be NULL.
idpFor a variable the varid, a group the group ncid, or a type the typeid. May be NULL.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file; NC_EINVAL for a non-object token, a session that is not the token's target file, or a target that no longer exists; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_deref_region()

int nc_deref_region ( int ncid,
const nc_std_ref_t * ref,
int * grpidp,
int * varidp,
int * ndimsp,
size_t * startp,
size_t * countp,
ptrdiff_t * stridep )

Resolve a dataset region reference token back to its variable and selection.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Recovers the target variable and the stored start/count/stride arrays. For an external token, ncid is the target session returned by nc_ref_open_target().

Parameters
ncidNetCDF file ID (nxCDF); for an external token, the session returned by nc_ref_open_target().
refReference token.
grpidpContaining group's ncid; may be NULL.
varidpVariable ID; may be NULL.
ndimspVariable rank; may be NULL.
startpReceives the selection start (rank elements); may be NULL.
countpReceives the selection count (rank elements); may be NULL.
stridepReceives the selection stride (rank elements); may be NULL.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file; NC_EINVAL for a non-region token, a session that is not the token's target file, a missing target, or a selection that is not a regular strided hyperslab with unit blocks; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ NC_NXCDF_finalize()

int NC_NXCDF_finalize ( void )
extern

Finalize process-wide nxCDF dispatch state.

nxCDF currently keeps no state that needs teardown, so this is a placeholder for symmetry with NC_NXCDF_initialize() and the other NEP backends.

Returns
NC_NOERR.

◆ NC_NXCDF_initialize()

NC_Dispatch * NC_NXCDF_initialize ( void )
extern

Register the nxCDF dispatch table in UDF slot 9.

Applications call this once before using NC_NXCDF (unless the backend is autoloaded via .ncrc). Also reads NEP_LOG_LEVEL.

Register the nxCDF dispatch table in UDF slot 9.

Installs NXCDF_dispatcher into UDF slot 9 by calling netcdf-c's nc_def_user_format(). Applications must call this once before using NC_NXCDF (unless the backend is autoloaded via .ncrc). Also reads the NEP_LOG_LEVEL environment variable to set the initial log level when logging is compiled in.

Returns
Pointer to the nxCDF dispatch table.

◆ nc_ref_attr()

int nc_ref_attr ( int ncid,
int obj_type,
int objid,
const char * att_name,
nc_std_ref_t * ref )

Create an HDF5 attribute reference to an attribute on a variable, group, or committed datatype in a nxCDF file.

Author
Edward Hartnett, Intelligent Data Design, Inc.

obj_type/objid are dispatched exactly as in nc_ref_object(), so every attribute-bearing object kind is covered.

Parameters
ncidNetCDF file ID (nxCDF, native mode).
obj_typeNC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE, dispatched exactly as in nc_ref_object(). NC_REF_OBJ_GRP covers the attributes the NetCDF API attaches to NC_GLOBAL.
objidObject identifier, interpreted per obj_type.
att_nameName of an existing attribute on the object.
refReceives the opaque reference token.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file or a compatibility mode; NC_EINVAL for a bad obj_type, target, or missing attribute; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_attr_ext()

int nc_ref_attr_ext ( int ncid,
const char * filename,
const char * path,
const char * att_name,
nc_std_ref_t * ref )

Create an attribute reference pointing into another file.

Like nc_ref_attr(), but the target is the attribute att_name on the object named by path in filename. path may name any attribute-bearing object kind. filename must be an absolute filesystem path and the target file must be writable by the application, as for nc_ref_object_ext().

Author
Edward Hartnett, Intelligent Data Design, Inc.

The attribute is named on the object at path in filename.

Parameters
ncidNetCDF file ID (nxCDF, native mode).
filenameAbsolute filesystem path of the HDF5 file holding the target object; the target must be writable by the application.
pathHDF5 path of the target object in filename; may name any attribute-bearing object kind.
att_nameName of an attribute on the target object.
refReceives the opaque reference token.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file or a compatibility mode; NC_EINVAL for bad arguments, including a relative filename; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_free()

int nc_ref_free ( nc_std_ref_t * ref)

Release the resources held by a reference token.

An HDF5 reference token holds a reference to the file it was created in; until it is released the file cannot fully close. Call this on every token obtained from nc_ref_object(), nc_ref_region(), nc_ref_attr(), or the nc_ref_*_ext() variants when the token is no longer needed. Tokens read from a dataset or attribute may also be passed here. Releasing an uninitialized or already-released token is safe.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Wraps H5Rdestroy(); safe on uninitialized tokens. A token holds a reference to the file it was created in — until it is released the file cannot fully close. Call this on every token obtained from nc_ref_object(), nc_ref_region(), nc_ref_attr(), or the nc_ref_*_ext() variants, and on tokens read back from a dataset or attribute, when it is no longer needed.

Parameters
refReference token.
Returns
NC_NOERR on success; NC_EINVAL for a NULL argument; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_get_file_name()

int nc_ref_get_file_name ( const nc_std_ref_t * ref,
char * name,
size_t size )

Copy the file name stored in a reference token.

Returns the name of the file the token points into, which differs from the containing file only for external references.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Differs from the containing file only for external references.

Parameters
refReference token.
nameDestination buffer of size bytes.
sizeBuffer size in bytes, including room for the null terminator.
Returns
NC_NOERR on success; NC_EINVAL for bad arguments or when size is too small; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_get_obj_name()

int nc_ref_get_obj_name ( const nc_std_ref_t * ref,
char * name,
size_t size )

Copy the object path stored in a reference token.

For an attribute reference this is the path of the object that carries the attribute; use nc_deref_attr() for the attribute name itself.

Author
Edward Hartnett, Intelligent Data Design, Inc.

For an attribute reference this is the path of the object that carries the attribute; use nc_deref_attr() for the attribute name itself.

Parameters
refReference token.
nameDestination buffer of size bytes.
sizeBuffer size in bytes, including room for the null terminator.
Returns
NC_NOERR on success; NC_EINVAL for bad arguments or when size is too small; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_get_type()

int nc_ref_get_type ( const nc_std_ref_t * ref,
int * ref_typep )

Report the kind of a reference token.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Returns NC_STD_REF_OBJECT, NC_STD_REF_REGION, or NC_STD_REF_ATTR.

Parameters
refReference token.
ref_typepReceives NC_STD_REF_OBJECT, NC_STD_REF_REGION, or NC_STD_REF_ATTR.
Returns
NC_NOERR on success; NC_EINVAL for bad arguments or an unrecognized token kind.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_object()

int nc_ref_object ( int ncid,
int obj_type,
int objid,
nc_std_ref_t * ref )

Create an HDF5 object reference to a variable, group, or user-defined type in a nxCDF file.

Author
Edward Hartnett, Intelligent Data Design, Inc.

The object is identified by an NC_REF_OBJ_* kind and an id interpreted per kind; the token is written to ref.

Parameters
ncidNetCDF file ID (nxCDF, native mode).
obj_typeNC_REF_OBJ_VAR: objid is a varid in group ncid. NC_REF_OBJ_GRP: objid is a group ncid (ncid is ignored). NC_REF_OBJ_TYPE: objid is a typeid in group ncid.
objidObject identifier, interpreted per obj_type.
refReceives the opaque reference token.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file or a compatibility mode; NC_EINVAL for a bad obj_type or target; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_object_ext()

int nc_ref_object_ext ( int ncid,
const char * filename,
const char * path,
nc_std_ref_t * ref )

Create an object reference pointing into another file.

The token encodes filename; storing it in an NC_STD_REF variable or attribute of the file ncid produces a cross-file reference. ncid is validated like nc_ref_object() but is otherwise unused.

filename must be an absolute filesystem path: a stored relative name would be reinterpreted against whatever working directory a later reader happens to have. The target file must also be writable by the application — HDF5 may reopen persisted external references read-write, so a read-only target can be referenced but never dereferenced.

Author
Edward Hartnett, Intelligent Data Design, Inc.

The token records filename so H5Ropen_* and the nc_ref_get_* inspectors can resolve the external target.

Parameters
ncidNetCDF file ID (nxCDF, native mode); validated but otherwise unused.
filenameAbsolute filesystem path of the HDF5 file holding the target object; relative names are rejected because a stored relative path would be reinterpreted against the reader's working directory. The target must be writable by the application.
pathHDF5 path of the target object in filename (for example "grp/dset" or "/grp/dset").
refReceives the opaque reference token.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file or a compatibility mode; NC_EINVAL for bad arguments, including a relative filename; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_open_remote()

int nc_ref_open_remote ( int ncid,
const char * url,
const char * path,
int * target_ncidp,
int * kindp,
int * objidp,
char * att_name,
size_t att_name_size )

Open a remote reference target and resolve its object path.

Remote references are a stored convention, not an HDF5 token: the application keeps a URL and an object path as strings (for example in parallel NC_STRING variables or attributes), and this function resolves one pair. The URL is opened with nc_open(url, NC_NOWRITE, ...) — no NC_NXCDF flag — so any remote-capable dispatch in the installed NetCDF-C may answer: DAP2, DAP4, or NCZarr file/byte-range stores. (s3:// URLs additionally require NetCDF-C built with NC_HAS_S3.) The returned session is an ordinary upstream NetCDF file ID, not a nxCDF session.

path follows the nc_ref_resolve() grammar: a leading /, /-separated group components, a final component naming a variable, group, or committed datatype, and an optional #attname suffix selecting an attribute of that object.

On success the caller owns target_ncidp and must close it with nc_close(); each call returns an independent session. The IDs reported through kindp/objidp belong to that session and die with it. If the open succeeds but path fails to resolve, the session is closed, target_ncidp is set to -1 and the resolution error is returned. Remote access is read-only.

Requires NEP built with NEP_ENABLE_REMOTE_REFS (see NEP_HAS_REMOTE_REFS in nep_meta.h).

Parameters
ncidNetCDF file ID (nxCDF) of the file holding the reference; provides context only.
urlURL the installed NetCDF-C can open remotely.
pathObject path inside the remote dataset (see nc_ref_resolve()).
target_ncidpReceives the remote session's NetCDF file ID; set to -1 on failure.
kindpReceives NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, NC_REF_OBJ_TYPE, or NC_REF_OBJ_ATT when path carried a #attname suffix.
objidpReceives the resolved ID: a varid, group ncid, typeid, or — for NC_REF_OBJ_ATT — the attribute owner's varid, group ncid or typeid.
att_nameBuffer receiving the attribute name when path carried a #attname suffix; may be NULL otherwise.
att_name_sizeSize of att_name in bytes.
Returns
NC_NOERR on success; NC_ENOTBUILT when built without NEP_ENABLE_REMOTE_REFS; NC_ENOTNC4 for a non-nxCDF ncid; NC_EINVAL for bad arguments or malformed path; otherwise the nc_open/inquiry error for an unreachable URL or missing object.
Author
Edward Hartnett, Intelligent Data Design, Inc.

Implementation of the public contract declared in nep.h: the containing file is validated as nxCDF (context only), the URL is opened with plain nc_open(NC_NOWRITE) so any remote-capable upstream dispatch answers, and the path is resolved with nc_ref_resolve(). A failed resolution closes the fresh session.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_open_target()

int nc_ref_open_target ( int ncid,
const nc_std_ref_t * ref,
int * target_ncidp )

Open the external file a reference token points into.

The token records an absolute filename for its target file; this function opens that file as a new nxCDF session and returns its NetCDF file ID. Pass the returned ncid to nc_deref_object(), nc_deref_region(), or nc_deref_attr() to resolve the token; the IDs those calls return belong to the target session and remain valid until it is closed.

The caller owns the returned session: close it with nc_close(). Each call returns an independent session, even for tokens into the same file. Token lifetime is independent — release ref with nc_ref_free() when done; freeing the token does not close the target session, and closing the target session does not affect the token.

The target file must be writable by the application: HDF5 may reopen persisted external references read-write, so the session is opened with NC_WRITE even when only reads are intended. Dereferencing never intentionally modifies target contents.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Extracts the stored absolute filename and opens it through nc_open() with NC_NXCDF|NC_WRITE. The returned ncid is a normal caller-owned session: pass it to nc_deref_* to resolve the token, and close it with nc_close(). Each call returns an independent session. The IDs the nc_deref_* calls return belong to that target session and remain valid until it is closed; token lifetime (nc_ref_free) is independent of target-session lifetime. The target must be writable: HDF5 may reopen persisted external references read-write, so the session is opened with NC_WRITE even when only reads are intended.

Parameters
ncidNetCDF file ID (nxCDF) of the file the token was created in or read from.
refReference token pointing into another file.
target_ncidpReceives the NetCDF file ID of the opened target file; set to -1 on failure.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF containing file or a target that is not a nxCDF-readable NetCDF-4 file; NC_EINVAL for bad arguments, a token that does not point into another file, or a stored filename that is not absolute; NC_EPERM when the target cannot be opened read-write; nc_open's codes for a missing or unreadable target; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_region()

int nc_ref_region ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
const ptrdiff_t * stridep,
nc_std_ref_t * ref )

Create a dataset region reference to a strided hyperslab of a variable in a nxCDF file.

Author
Edward Hartnett, Intelligent Data Design, Inc.

Only regular strided hyperslabs (start/count/stride) are supported; irregular selections are rejected.

Parameters
ncidNetCDF file ID (nxCDF, native mode).
varidVariable ID.
startpStart index in each dimension (rank elements).
countpEdge count in each dimension (rank elements).
stridepStride in each dimension, or NULL for unit stride.
refReceives the opaque reference token.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file or a compatibility mode; NC_EINVAL for bad arguments; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_region_ext()

int nc_ref_region_ext ( int ncid,
const char * filename,
const char * path,
const size_t * startp,
const size_t * countp,
const ptrdiff_t * stridep,
nc_std_ref_t * ref )

Create a dataset region reference pointing into another file.

Like nc_ref_region(), but the target is the variable named by path in filename. filename must be an absolute filesystem path and the target file must be writable by the application, as for nc_ref_object_ext().

Author
Edward Hartnett, Intelligent Data Design, Inc.

The selection uses start/count/stride like nc_ref_region().

Parameters
ncidNetCDF file ID (nxCDF, native mode).
filenameAbsolute filesystem path of the HDF5 file holding the target dataset; the target must be writable by the application.
pathHDF5 path of the target dataset in filename.
startpStart index in each dimension.
countpEdge count in each dimension.
stridepStride in each dimension, or NULL for unit stride.
refReceives the opaque reference token.
Returns
NC_NOERR on success; NC_ENOTNC4 for a non-nxCDF file or a compatibility mode; NC_EINVAL for bad arguments, including a relative filename; NC_EHDFERR on HDF5 failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_ref_resolve()

int nc_ref_resolve ( int ncid,
const char * path,
int * kindp,
int * objidp,
char * att_name,
size_t att_name_size )

Resolve an object path on an already-open remote session.

Maps a stored object path to NetCDF IDs on ncid, which is typically a session returned by nc_ref_open_remote() but may be any open NetCDF file ID. Use it to resolve several stored paths against one remote session without paying a remote open per reference.

path grammar: a leading /, /-separated group components, and a final component naming a variable, group or committed datatype. An optional #attname suffix selects an attribute of the named object. / alone resolves to the root group. Resolution precedence for the final component is variable, then group, then committed type.

When path carries no # suffix, kindp receives NC_REF_OBJ_VAR, NC_REF_OBJ_GRP or NC_REF_OBJ_TYPE and objidp the varid, group ncid or typeid. With a #attname suffix, kindp receives NC_REF_OBJ_ATT, att_name the attribute name and objidp the owner's varid, group ncid or typeid. Attribute existence is verified with nc_inq_attid() for variable and group owners; attributes on committed-datatype owners are not verifiable through the NetCDF API and the name is returned unchecked.

Parameters
ncidOpen NetCDF file ID to resolve against.
pathObject path (see above).
kindpReceives the resolved kind (see above).
objidpReceives the resolved ID (see above).
att_nameBuffer receiving the attribute name, or NULL when path carries no # suffix.
att_name_sizeSize of att_name in bytes.
Returns
NC_NOERR on success; NC_ENOTBUILT when built without NEP_ENABLE_REMOTE_REFS; NC_EINVAL for bad arguments or malformed path; NC_ENOTVAR when the final component names no variable, group or type; NC_ENOTATT for a missing attribute; other inquiry errors propagate.
Author
Edward Hartnett, Intelligent Data Design, Inc.

Implementation of the public contract declared in nep.h: split the optional #attname suffix, walk the group components with nc_inq_grp_ncid(), and resolve the leaf as variable, group or committed type in that order.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_start_swmr_write()

int nc_start_swmr_write ( int ncid)

Start a single-writer/multiple-reader session on a native nxCDF file.

SWMR (Single Writer / Multiple Reader) is an HDF5 concurrency mode: one process holds a file open for writing while any number of other processes hold the same file open read-only and watch the data grow, without file locks or re-opening. The writer calls nc_swmr_flush() (or nc_sync()) to publish what it has written; each reader calls nc_swmr_refresh() to make the newly published records visible. NEP exposes this through libncnxcdf on nxCDF (HDF5) files only. This function is the writer-side entry point; readers never call it — they open with NC_SWMR_READ instead.

Link libncnxcdf and enable NEP_HAS_NXCDF. A file or subgroup ncid addresses the whole file. Pending definitions are committed before HDF5 SWMR activation; calling again on an active writer is a no-op. Only serial native files with superblock v3 and a SWMR-capable driver are supported. Variables must have fixed-size atomic types (including NEP small floats, complex and bitfield types), not NC_STRING, NC_STD_REF or user types. Declared user types, even unused ones, are excluded. All schema and attributes freeze at activation; in-bounds writes and unlimited growth remain allowed. This is session state, not a persistent mode marker.

Alternatively request NC_SWMR_WRITE at create/open: creates defer start until enddef (including automatic enddef on write); writable opens start after metadata loading. Closing an inactive requested file never starts SWMR. Failed activation may leave ordinary definitions committed; it does not roll them back and leaves the session inactive and closable.

Parameters
ncidOpen file or group identifier.
Returns
NC_NOERR on success; NC_EBADID for an invalid identifier; NC_ENOTNC4 for another backend; NC_EPERM for read-only access; NC_EINVAL for compatibility/MPI sessions, old superblocks or unsupported drivers; NC_ENOTBUILT for excluded schema; NC_EHDFERR for HDF5 failures; or an error propagated while committing pending metadata.
Author
Edward Hartnett, Intelligent Data Design, Inc.

Start a single-writer/multiple-reader session on a native nxCDF file.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_swmr_flush()

int nc_swmr_flush ( int ncid)

Publish all datasets and dimension scales of an active SWMR writer.

This is the writer's half of the SWMR handshake. In a SWMR session data written by the writer is not automatically visible to readers: it sits in the writer's HDF5 caches until the writer publishes it. nc_swmr_flush() flushes every variable dataset and every dimension-scale dataset, then flushes the file, which is what makes the appended records readable by SWMR readers after their next nc_swmr_refresh(). nc_sync() on an active writer performs the same publication, so applications may use either call as their publish boundary.

Link libncnxcdf. Publication is reader visibility, not an atomic multi-variable timestep, rollback or power-loss durability guarantee. HDF5 may also flush opportunistically before this call. Readers must open with NC_SWMR_READ and call nc_swmr_refresh() to observe published data. Does not enter define mode or activate an inactive session.

Parameters
ncidOpen file or group identifier; the entire file is flushed.
Returns
NC_NOERR on success; NC_EBADID for an invalid identifier; NC_ENOTNC4 for another backend; NC_EPERM for read-only access; NC_EINVAL for an inactive writer; NC_EHDFERR for a flush failure. Partial publication on error is not rolled back.
Author
Edward Hartnett, Intelligent Data Design, Inc.

Publish all datasets and dimension scales of an active SWMR writer.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_swmr_refresh()

int nc_swmr_refresh ( int ncid)

Refresh a nxCDF SWMR reader session so newly published data becomes visible.

This is the reader's half of the SWMR handshake. A SWMR reader holds the file open with HDF5 SWMR read access; its datasets and dimension extents are snapshots that do not change on their own. After the writer publishes new records with nc_swmr_flush() or nc_sync(), the reader calls nc_swmr_refresh() once and then reads the new data with the ordinary nc_inq_dimlen()/nc_get_vara() calls. A typical reader loop is: wait for the application's own publish signal, call nc_swmr_refresh(), call nc_inq_dimlen() for the current record count, then read the new records. Any number of readers may do this independently, and readers may open before or after the writer starts SWMR writing and may close in either order.

Link libncnxcdf. Requires a file opened read-only with NC_NXCDF|NC_SWMR_READ; a file or subgroup ncid addresses the whole file. Every open variable dataset and dimension-scale dataset is refreshed through H5Drefresh, then the cached length of each dimension is reloaded from its scale dataset's current extent. Calling when nothing new was published is a cheap no-op, so it is safe to call on every iteration of a polling loop.

Refresh is not a re-open: the SWMR writer contract freezes the schema and attributes at activation, so variables, dimensions, attributes or types added afterwards are never expected and are not discovered — reopen the file to see such changes. Reads mid-append are well defined at the dataset level, but whether a multi-variable logical record is complete is an application concern; a common protocol is for the writer to update a scalar marker variable last, after the record data, and for readers to check the marker after refreshing. Calling this on an ordinary read-only, writable or writer session returns NC_EINVAL.

Parameters
ncidOpen file or group identifier of a SWMR reader session.
Returns
NC_NOERR on success; NC_EBADID for an invalid identifier; NC_ENOTNC4 for another backend; NC_EINVAL when the session was not opened with NC_SWMR_READ; NC_EHDFERR on an HDF5 refresh failure.
Author
Edward Hartnett, Intelligent Data Design, Inc.

Refresh a nxCDF SWMR reader session so newly published data becomes visible.

Author
Edward Hartnett, Intelligent Data Design, Inc.