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

nxCDF reference API: create, dereference, and inspect NC_STD_REF (H5T_STD_REF) tokens. More...

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

Functions

int nxcdf_ref_file (int ncid, NC_FILE_INFO_T **h5p, NXCDF_FILE_INFO_T **filep)
 Map a public ncid to the internal file state, rejecting any file not opened through the nxCDF backend.
static int ref_check_native (NXCDF_FILE_INFO_T *file)
 Verify the file is in native mode — required by every nc_ref_* create function since NC_STD_REF data cannot be stored in compatibility-mode files.
static int ref_is_external (NXCDF_FILE_INFO_T *file, const H5R_ref_t *ref, int *extp)
 Report whether a token points into a file other than the one file belongs to.
static int grp_hdf (NC_GRP_INFO_T *grp, NXCDF_FILE_INFO_T *file, hid_t *gid)
 Return the open HDF5 group handle for an in-memory group.
static int grp_ncid (NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp)
 Resolve a group ncid to a full (file-qualified) ncid.
static int grp_for_path (NC_FILE_INFO_T *h5, const char *path, NC_GRP_INFO_T **grpp)
 Find the in-memory group at an absolute HDF5 path.
static int obj_ids (NC_FILE_INFO_T *h5, hid_t obj, int *obj_typep, int *grpidp, int *idp)
 Map an open HDF5 object back to its NetCDF kind and ids.
static int obj_loc (int ncid, int obj_type, int objid, hid_t *locp, hid_t *objp, char **namep)
 Resolve a create-API obj_type/objid pair to the target object's HDF5 handle, the HDF5 location the reference is created in, and the object's name.
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.
static int deref_check (const H5R_ref_t *ref, int expected)
 Shared dereference preamble: token-kind check.
static int ref_same_file (NXCDF_FILE_INFO_T *file, hid_t obj, int *samep)
 Report whether an HDF5 object opened through a reference token lives in the same physical file as 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 object and attribute name.
static int ext_open (int ncid, const char *filename, const char *path, hid_t *efp)
 Validate the external-create arguments and open the destination file read-write through raw HDF5.
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.

Detailed Description

nxCDF reference API: create, dereference, and inspect NC_STD_REF (H5T_STD_REF) tokens.

The public functions declared in nep.h wrap the HDF5 2.x reference API: tokens are 64-byte H5R_ref_t values carried in nc_std_ref_t so nep.h need not include hdf5.h. One token format covers object references (H5Rcreate_object), dataset region references (H5Rcreate_region), and attribute references (H5Rcreate_attr), including references whose target lives in a different file. See nxCDF References for the user-facing documentation.

Author
Edward Hartnett
Date
2026-11-21

Function Documentation

◆ deref_check()

int deref_check ( const H5R_ref_t * ref,
int expected )
static

Shared dereference preamble: token-kind check.

Whether ref points into this file or an external one is decided later by ref_same_file() on the opened object — the token kind is the only thing checked here.

Parameters
refReference token.
expectedRequired NC_STD_REF_* kind value.
Returns
NC_NOERR or NC_EINVAL for a mismatched token kind.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ ext_open()

int ext_open ( int ncid,
const char * filename,
const char * path,
hid_t * efp )
static

Validate the external-create arguments and open the destination file read-write through raw HDF5.

The token is created against the target object in filename; HDF5 records the target file name inside it. filename must be an absolute filesystem path: a relative name would be reinterpreted against whatever working directory a later reader happens to have, so it is rejected outright. The target is opened read-write because HDF5 2.1.1 reopens persisted external references with H5F_ACC_RDWR; a target that cannot be opened read-write now would be undereferenceable later. path must be an absolute HDF5 object path.

Parameters
ncidNetCDF file ID (nxCDF); only used to reject non-nxCDF and compatibility-mode files.
filenameAbsolute path of the file holding the target.
pathAbsolute object path inside filename.
efpDestination for the open HDF5 file identifier; caller closes.
Returns
NC_NOERR on success, NC_EINVAL for a missing or relative filename, or another error code.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ grp_for_path()

int grp_for_path ( NC_FILE_INFO_T * h5,
const char * path,
NC_GRP_INFO_T ** grpp )
static

Find the in-memory group at an absolute HDF5 path.

Walks the children index one path component at a time, starting at the root group; "/" itself resolves to root.

Parameters
h5File info.
pathAbsolute HDF5 object path (for example "/g1/g2").
grppDestination for the group.
Returns
NC_NOERR on success, NC_EINVAL when no group matches.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ grp_hdf()

int grp_hdf ( NC_GRP_INFO_T * grp,
NXCDF_FILE_INFO_T * file,
hid_t * gid )
static

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

The root group's handle is file->rootid; other groups carry theirs in format_grp_info. A group defined but not yet materialized to HDF5 reports NC_EINVAL.

Parameters
grpGroup.
filenxCDF file state.
gidDestination for the HDF5 group identifier.
Returns
NC_NOERR or NC_EINVAL.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ grp_ncid()

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

Resolve a group ncid to a full (file-qualified) ncid.

Group ncids carry the file id in the upper 16 bits and the in-file group id in the lower 16; the root group has id 0, so its ncid is the file ncid itself.

Parameters
h5File info.
grpGroup.
Returns
The group's ncid.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ 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 object and attribute name.

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.

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.

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_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.

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.

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.

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.

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.

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.

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.

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 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_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.

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.

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.

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.

◆ nxcdf_ref_file()

int nxcdf_ref_file ( int ncid,
NC_FILE_INFO_T ** h5p,
NXCDF_FILE_INFO_T ** filep )

Map a public ncid to the internal file state, rejecting any file not opened through the nxCDF backend.

Every public reference function takes an opaque integer NetCDF file ID. This helper turns it into the two structures the reference code works on:

  • NC_FILE_INFO_T — the generic netCDF-4 in-memory metadata tree (group/variable/type indexes) that obj_ids() walks to map an opened HDF5 object back to a NetCDF group ncid, varid, or typeid.
  • NXCDF_FILE_INFO_T — the backend's per-file state holding the HDF5 handles (hdfid, rootid), open mode, and SWMR flags.

The ncid is rejected with NC_ENOTNC4 when it belongs to another dispatch backend (an upstream NetCDF-4 or NetCDF-3 file, another NEP UDF handler, etc.): the dispatch-table pointer must be NXCDF_dispatch_table and format_file_info must be present, so a foreign file fails cleanly instead of being dereferenced as garbage.

Parameters
ncidNetCDF file ID.
h5pDestination for NC_FILE_INFO_T, or NULL.
filepDestination for NXCDF_FILE_INFO_T, or NULL.
Returns
NC_NOERR on success, NC_ENOTNC4 for a non-nxCDF file, or the underlying lookup error.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ obj_ids()

int obj_ids ( NC_FILE_INFO_T * h5,
hid_t obj,
int * obj_typep,
int * grpidp,
int * idp )
static

Map an open HDF5 object back to its NetCDF kind and ids.

H5Iget_type gives the object kind and H5Iget_name its absolute path; the basename is then looked up in the containing group's variable or type index, or the path itself resolves the group. Works on the NC_*_INFO_T lists directly to avoid re-entering the public nc_* API.

Parameters
h5File info.
objOpen HDF5 object identifier.
obj_typepDestination for NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE.
grpidpDestination for the containing group's ncid (the group itself for NC_REF_OBJ_GRP).
idpDestination for the varid, group ncid, or typeid.
Returns
NC_NOERR on success, NC_EINVAL for an unnamed or unmappable object, NC_ENOMEM, or NC_EHDFERR.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ obj_loc()

int obj_loc ( int ncid,
int obj_type,
int objid,
hid_t * locp,
hid_t * objp,
char ** namep )
static

Resolve a create-API obj_type/objid pair to the target object's HDF5 handle, the HDF5 location the reference is created in, and the object's name.

Variable and type targets live in the file ncid belongs to. A group target may name any group ncid — including one in a different nxCDF file, which produces a cross-file reference. A non-nxCDF file is rejected.

Parameters
ncidGroup context for variable and type targets.
obj_typeNC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE.
objidVarid, group ncid, or typeid per obj_type.
locpDestination for the loc_id argument of H5Rcreate_*.
objpDestination for the target object's own HDF5 handle (used for attribute checks), or NULL.
namepDestination for a malloc'd absolute path of the target; caller frees.
Returns
NC_NOERR on success, or an error code.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ ref_check_native()

int ref_check_native ( NXCDF_FILE_INFO_T * file)
static

Verify the file is in native mode — required by every nc_ref_* create function since NC_STD_REF data cannot be stored in compatibility-mode files.

Parameters
filenxCDF file state.
Returns
NC_NOERR or NC_ENOTNC4.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ ref_is_external()

int ref_is_external ( NXCDF_FILE_INFO_T * file,
const H5R_ref_t * ref,
int * extp )
static

Report whether a token points into a file other than the one file belongs to.

HDF5 stores the target file's name inside the token; for an in-file reference it equals the containing file's own name.

Parameters
filenxCDF file state.
refReference token.
extpDestination; nonzero when the target file differs.
Returns
NC_NOERR or an error code.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ ref_same_file()

int ref_same_file ( NXCDF_FILE_INFO_T * file,
hid_t obj,
int * samep )
static

Report whether an HDF5 object opened through a reference token lives in the same physical file as file.

H5Ropen_* resolves an external token by reopening its target file internally, so the opened object's file identity — not a stored or reported file name — decides whether the session the caller passed is the token's target. H5O_info2_t.fileno is constant across multiple opens of the same file, which also makes the check immune to relative-versus-absolute spelling of the session's path.

Parameters
filenxCDF file state of the session being dereferenced.
objOpen HDF5 object identifier from H5Ropen_*.
samepDestination; nonzero when the object belongs to this file.
Returns
NC_NOERR or NC_EHDFERR.
Author
Edward Hartnett, Intelligent Data Design, Inc.