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

Upstream-compatible provenance attributes for nxCDF. More...

#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "nxcdf_internal.h"
#include "nep_meta.h"

Macros

#define NXCDF_NCPROPS   "_NCProperties"
 Upstream's provenance attribute names (nc_provenance.h).
#define NXCDF_NC3_STRICT   "_nc3_strict"
#define NXCDF_ISNETCDF4   "_IsNetcdf4"
#define NXCDF_SUPERBLOCK   "_SuperblockVersion"

Functions

int nxcdf_build_ncproperties (char **out)
 Build the _NCProperties value for a new file.
int nxcdf_read_ncproperties (NXCDF_FILE_INFO_T *file)
 Read an existing _NCProperties attribute at open.
int nxcdf_write_provenance (NXCDF_FILE_INFO_T *file)
 Write _NCProperties and _nc3_strict to a file nxCDF created.
static herr_t count_marker_atts (hid_t loc, const char *name, const H5O_info_t *info, void *op_data)
 Count objects carrying NetCDF-4 bookkeeping attributes.
static int nxcdf_isnetcdf4 (NXCDF_FILE_INFO_T *file)
 Whether the open file was written by a netCDF-4 library.
int nxcdf_get_att_special (NXCDF_FILE_INFO_T *file, const char *name, nc_type *xtypep, nc_type mem_type, size_t *lenp, int *attnump, void *data)
 Answer a name lookup for a provenance attribute.

Variables

static const char * isnetcdf4_markers []
 Hidden attribute names that mark an object as NetCDF-4 bookkeeping; two or more anywhere in the file mean "written by netcdf-4", matching upstream's NC4_isnetcdf4 walk.

Detailed Description

Upstream-compatible provenance attributes for nxCDF.

Writes the same hidden root-group attributes upstream netcdf-c produces (_NCProperties, _nc3_strict) and answers name lookups for the virtual attributes (_IsNetcdf4, _SuperblockVersion, _NCProperties) that upstream synthesizes in nc4_get_att_special() rather than storing. The stored attributes are deferred to _enddef/nc_sync/nc_close, never overwrite an existing stamp, and are only written for files nxCDF created — a foreign file opened for write keeps whatever provenance it had. See nxCDF Architecture.

Author
Edward Hartnett, Intelligent Data Design, Inc.
Date
2026-11-23

Macro Definition Documentation

◆ NXCDF_ISNETCDF4

#define NXCDF_ISNETCDF4   "_IsNetcdf4"

◆ NXCDF_NC3_STRICT

#define NXCDF_NC3_STRICT   "_nc3_strict"

◆ NXCDF_NCPROPS

#define NXCDF_NCPROPS   "_NCProperties"

Upstream's provenance attribute names (nc_provenance.h).

◆ NXCDF_SUPERBLOCK

#define NXCDF_SUPERBLOCK   "_SuperblockVersion"

Function Documentation

◆ count_marker_atts()

herr_t count_marker_atts ( hid_t loc,
const char * name,
const H5O_info_t * info,
void * op_data )
static

Count objects carrying NetCDF-4 bookkeeping attributes.

H5Ovisit callback for nxcdf_isnetcdf4(): increments the counter when the visited object has any of the hidden marker attributes — upstream's threshold of two distinguishes a netCDF-4 file from a plain HDF5 file that happens to carry one such name.

◆ nxcdf_build_ncproperties()

int nxcdf_build_ncproperties ( char ** out)

Build the _NCProperties value for a new file.

Produces version=2,netcdf=<netcdf-c version>,hdf5=<hdf5 version>, nxcdf=<nep version> — upstream's property string plus a nxcdf key, which the version-2 format tolerates. The netcdf-c version is the first token of nc_inq_libvers(); the HDF5 version comes from H5get_libversion; the NEP version is the build-time NEP_VERSION.

Parameters
outDestination for a malloc'd string the caller frees.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ nxcdf_get_att_special()

int nxcdf_get_att_special ( NXCDF_FILE_INFO_T * file,
const char * name,
nc_type * xtypep,
nc_type mem_type,
size_t * lenp,
int * attnump,
void * data )

Answer a name lookup for a provenance attribute.

nxCDF's nc4_get_att_special equivalent: _NCProperties is answered from the in-memory copy (built at create or read at open), while _IsNetcdf4 and _SuperblockVersion are synthesized — they exist only as answers to name lookups, never as stored attributes and never in nc_inq_natts/nc_inq_attname results.

Parameters
fileOpen nxCDF state.
nameAttribute name.
xtypepOptional destination for the file type.
mem_typeRequested in-memory type (NC_NAT allowed).
lenpOptional destination for the attribute length.
attnumpNon-NULL asks for the attribute's index, which virtual attributes do not have.
dataOptional destination for the attribute's value.
Returns
NC_NOERR on success, NC_EATTMETA for an attnum inquiry, NC_ENOTATT when the attribute does not exist, NC_ECHAR for a non-character read of _NCProperties, NC_ERANGE for a non-integer memtype of the integer attributes, or a NetCDF error code.

◆ nxcdf_isnetcdf4()

int nxcdf_isnetcdf4 ( NXCDF_FILE_INFO_T * file)
static

Whether the open file was written by a netCDF-4 library.

Mirrors upstream's NC4_isnetcdf4: 1 when _nc3_strict or _NCProperties exists on the root group, else a whole-file walk that requires at least two objects carrying NetCDF-4 marker attributes.

Parameters
fileOpen nxCDF state.
Returns
1 for a netCDF-4 file, 0 otherwise.

◆ nxcdf_read_ncproperties()

int nxcdf_read_ncproperties ( NXCDF_FILE_INFO_T * file)

Read an existing _NCProperties attribute at open.

Populates file->ncproperties when the root group carries the attribute. A missing or malformed attribute is tolerated — the field stays NULL, matching upstream's "invalid attribute: ignored" leniency.

Parameters
fileOpen nxCDF state.
Returns
NC_NOERR on success, or NC_ENOMEM.

◆ nxcdf_write_provenance()

int nxcdf_write_provenance ( NXCDF_FILE_INFO_T * file)

Write _NCProperties and _nc3_strict to a file nxCDF created.

Called from NXCDF__enddef, NXCDF_sync and NXCDF_close on writable files — the same deferred points upstream's NC4_write_provenance runs. _NCProperties is stored exactly as upstream does: a scalar fixed-length ASCII string of strlen bytes with H5T_STR_NULLTERM padding. _nc3_strict is a scalar H5T_NATIVE_INT = 1 written only for NC_CLASSIC_MODEL files. Neither attribute is ever overwritten, so an existing stamp survives a write-open update. Files nxCDF did not create are never stamped.

Parameters
fileOpen writable nxCDF state.
Returns
NC_NOERR on success, or a NetCDF error code.

Variable Documentation

◆ isnetcdf4_markers

const char* isnetcdf4_markers[]
static
Initial value:
= {
"CLASS",
"NAME",
"REFERENCE_LIST",
"DIMENSION_LIST",
"_Netcdf4Coordinates",
"_Netcdf4Dimid",
NULL
}

Hidden attribute names that mark an object as NetCDF-4 bookkeeping; two or more anywhere in the file mean "written by netcdf-4", matching upstream's NC4_isnetcdf4 walk.