|
NEP 4.3.0
NetCDF Expansion Pack
|
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. | |
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.
|
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.
| ref | Reference token. |
| expected | Required NC_STD_REF_* kind value. |
|
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.
| ncid | NetCDF file ID (nxCDF); only used to reject non-nxCDF and compatibility-mode files. |
| filename | Absolute path of the file holding the target. |
| path | Absolute object path inside filename. |
| efp | Destination for the open HDF5 file identifier; caller closes. |
filename, or another error code.
|
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.
| h5 | File info. |
| path | Absolute HDF5 object path (for example "/g1/g2"). |
| grpp | Destination for the group. |
|
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.
| grp | Group. |
| file | nxCDF file state. |
| gid | Destination for the HDF5 group identifier. |
|
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.
| h5 | File info. |
| grp | Group. |
| 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().
| ncid | NetCDF file ID (nxCDF); for an external token, the session returned by nc_ref_open_target(). |
| ref | Reference token. |
| obj_typep | Receives NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE for the attribute-bearing object; may be NULL. |
| grpidp | Containing group's ncid (or the group itself for NC_REF_OBJ_GRP); may be NULL. |
| idp | The 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_name | Receives the attribute name; must be a caller buffer of at least NC_MAX_NAME + 1 bytes, or NULL. |
| 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.
| ncid | NetCDF file ID (nxCDF); for an external token, the session returned by nc_ref_open_target(). |
| ref | Reference token. |
| obj_typep | Receives NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE; may be NULL. |
| grpidp | For a variable or type, the containing group's ncid; for a group, the group ncid itself. May be NULL. |
| idp | For a variable the varid, a group the group ncid, or a type the typeid. May be NULL. |
| 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().
| ncid | NetCDF file ID (nxCDF); for an external token, the session returned by nc_ref_open_target(). |
| ref | Reference token. |
| grpidp | Containing group's ncid; may be NULL. |
| varidp | Variable ID; may be NULL. |
| ndimsp | Variable rank; may be NULL. |
| startp | Receives the selection start (rank elements); may be NULL. |
| countp | Receives the selection count (rank elements); may be NULL. |
| stridep | Receives the selection stride (rank elements); may be NULL. |
| 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.
| ncid | NetCDF file ID (nxCDF, native mode). |
| obj_type | NC_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. |
| objid | Object identifier, interpreted per obj_type. |
| att_name | Name of an existing attribute on the object. |
| ref | Receives the opaque reference token. |
obj_type, target, or missing attribute; NC_EHDFERR on HDF5 failure.| 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.
| ncid | NetCDF file ID (nxCDF, native mode). |
| filename | Absolute filesystem path of the HDF5 file holding the target object; the target must be writable by the application. |
| path | HDF5 path of the target object in filename; may name any attribute-bearing object kind. |
| att_name | Name of an attribute on the target object. |
| ref | Receives the opaque reference token. |
filename; NC_EHDFERR on HDF5 failure.| 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.
| ref | 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.
Differs from the containing file only for external references.
| ref | Reference token. |
| name | Destination buffer of size bytes. |
| size | Buffer size in bytes, including room for the null terminator. |
size is too small; NC_EHDFERR on HDF5 failure.| 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.
| ref | Reference token. |
| name | Destination buffer of size bytes. |
| size | Buffer size in bytes, including room for the null terminator. |
size is too small; NC_EHDFERR on HDF5 failure.| 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.
| ref | Reference token. |
| ref_typep | Receives NC_STD_REF_OBJECT, NC_STD_REF_REGION, or NC_STD_REF_ATTR. |
| 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.
| ncid | NetCDF file ID (nxCDF, native mode). |
| obj_type | NC_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. |
| objid | Object identifier, interpreted per obj_type. |
| ref | Receives the opaque reference token. |
obj_type or target; NC_EHDFERR on HDF5 failure.| 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.
| ncid | NetCDF file ID (nxCDF, native mode); validated but otherwise unused. |
| filename | Absolute 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. |
| path | HDF5 path of the target object in filename (for example "grp/dset" or "/grp/dset"). |
| ref | Receives the opaque reference token. |
filename; NC_EHDFERR on HDF5 failure.| 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.
| ncid | NetCDF file ID (nxCDF) of the file the token was created in or read from. |
| ref | Reference token pointing into another file. |
| target_ncidp | Receives the NetCDF file ID of the opened target file; set to -1 on failure. |
| 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.
| ncid | NetCDF file ID (nxCDF, native mode). |
| varid | Variable ID. |
| startp | Start index in each dimension (rank elements). |
| countp | Edge count in each dimension (rank elements). |
| stridep | Stride in each dimension, or NULL for unit stride. |
| ref | Receives the opaque reference token. |
| 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().
| ncid | NetCDF file ID (nxCDF, native mode). |
| filename | Absolute filesystem path of the HDF5 file holding the target dataset; the target must be writable by the application. |
| path | HDF5 path of the target dataset in filename. |
| startp | Start index in each dimension. |
| countp | Edge count in each dimension. |
| stridep | Stride in each dimension, or NULL for unit stride. |
| ref | Receives the opaque reference token. |
filename; NC_EHDFERR on HDF5 failure.| 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:
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.
| ncid | NetCDF file ID. |
| h5p | Destination for NC_FILE_INFO_T, or NULL. |
| filep | Destination for NXCDF_FILE_INFO_T, or NULL. |
|
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.
| h5 | File info. |
| obj | Open HDF5 object identifier. |
| obj_typep | Destination for NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE. |
| grpidp | Destination for the containing group's ncid (the group itself for NC_REF_OBJ_GRP). |
| idp | Destination for the varid, group ncid, or typeid. |
|
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.
| ncid | Group context for variable and type targets. |
| obj_type | NC_REF_OBJ_VAR, NC_REF_OBJ_GRP, or NC_REF_OBJ_TYPE. |
| objid | Varid, group ncid, or typeid per obj_type. |
| locp | Destination for the loc_id argument of H5Rcreate_*. |
| objp | Destination for the target object's own HDF5 handle (used for attribute checks), or NULL. |
| namep | Destination for a malloc'd absolute path of the target; caller frees. |
|
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.
| file | nxCDF file state. |
|
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.
| file | nxCDF file state. |
| ref | Reference token. |
| extp | Destination; nonzero when the target file differs. |
|
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.
| file | nxCDF file state of the session being dereferenced. |
| obj | Open HDF5 object identifier from H5Ropen_*. |
| samep | Destination; nonzero when the object belongs to this file. |