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

HDF5 filter pipeline support for the nxCDF backend. More...

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

Functions

int NXCDF_def_var_filter (int ncid, int varid, unsigned int id, size_t nparams, const unsigned int *params)
 Define an HDF5 filter on a variable — the nc_def_var_filter() dispatch entry.
int NXCDF_def_var_deflate (int ncid, int varid, int shuffle, int deflate, int deflate_level)
 Set deflate compression — the nc_def_var_deflate() dispatch entry.
int NXCDF_def_var_fletcher32 (int ncid, int varid, int fletcher32)
 Enable the Fletcher32 checksum — the nc_def_var_fletcher32() dispatch entry.
int NXCDF_inq_var_filter_ids (int ncid, int varid, size_t *nfiltersp, unsigned int *ids)
 Inquire the filter ids applied to a variable — the nc_inq_var_filter_ids() dispatch entry.
int NXCDF_inq_var_filter_info (int ncid, int varid, unsigned int id, size_t *nparamsp, unsigned int *params)
 Inquire the parameters of one variable filter — the nc_inq_var_filter_info() dispatch entry.
int NXCDF_inq_filter_avail (int ncid, unsigned int id)
 Test whether an HDF5 filter is available — the nc_inq_filter_avail() dispatch entry.
int nxcdf_apply_filters (hid_t dcpl, NC_VAR_INFO_T *var)
 Apply a variable's filter list to a dataset creation property list.
int nxcdf_load_filters (hid_t dcpl, NC_VAR_INFO_T *var, NXCDF_VAR_INFO_T *vinfo)
 Read a variable's filter pipeline from a dataset creation property list.

Detailed Description

HDF5 filter pipeline support for the nxCDF backend.

nxCDF stores each variable's filter pipeline in the shared NC_VAR_INFO_T::filters list — an NClist of struct NC_HDF5_Filter — and manipulates it through netcdf-c's exported NC4_hdf5_* helpers, exactly as the built-in HDF5 backend does in libhdf5/hdf5filter.c. The list order is the pipeline order: fletcher32 is always first, shuffle first-or-second, and every other filter appears in definition order.

Author
Edward Hartnett
Date
2026-11-20

Function Documentation

◆ nxcdf_apply_filters()

int nxcdf_apply_filters ( hid_t dcpl,
NC_VAR_INFO_T * var )

Apply a variable's filter list to a dataset creation property list.

Iterates var->filters in pipeline order: fletcher32, shuffle, deflate and szip get their dedicated H5Pset_* calls; every other filter is attached with H5Pset_filter() and H5Z_FLAG_OPTIONAL so HDF5 skips it silently on types it cannot process (matching upstream).

Parameters
dcplDataset creation property list identifier.
varVariable.
Returns
NC_NOERR on success, NC_EFILTER on bad parameters, or NC_EHDFERR on an HDF5 failure.

◆ NXCDF_def_var_deflate()

int NXCDF_def_var_deflate ( int ncid,
int varid,
int shuffle,
int deflate,
int deflate_level )

Set deflate compression — the nc_def_var_deflate() dispatch entry.

Upstream NC4_def_var_deflate semantics: shuffle is set first, then deflate is added only when deflate is nonzero and deflate_level is 1-9 — level 0 means "no compression" and adds no filter. Once defined, a filter cannot be removed; re-calling only replaces parameters.

Parameters
ncidNetCDF file identifier.
varidVariable id.
shuffleNonzero to enable the shuffle filter.
deflateNonzero to enable deflate compression.
deflate_levelDeflate level (0-9).
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_def_var_filter()

int NXCDF_def_var_filter ( int ncid,
int varid,
unsigned int id,
size_t nparams,
const unsigned int * params )

Define an HDF5 filter on a variable — the nc_def_var_filter() dispatch entry.

Follows upstream NC4_hdf5_def_var_filter(): the filter must be available to HDF5, the variable must be non-scalar and not yet committed to disk (nxcdf_find_var_for_write rejects that with NC_ELATEDEF), and deflate/szip carry the usual parameter and mutual-exclusion rules. A re-defined filter id replaces its parameters in place. Defining any filter forces chunked storage and marks the variable dcpl_dirty, since HDF5 creation properties are immutable — _enddef rebuilds the dataset once.

Parameters
ncidNetCDF file identifier.
varidVariable id.
idHDF5 filter identifier.
nparamsNumber of filter parameters.
paramsFilter parameter values.
Returns
NC_NOERR on success, NC_ENOFILTER when the filter is unavailable, NC_ELATEDEF on a committed variable, or a NetCDF error code.

◆ NXCDF_def_var_fletcher32()

int NXCDF_def_var_fletcher32 ( int ncid,
int varid,
int fletcher32 )

Enable the Fletcher32 checksum — the nc_def_var_fletcher32() dispatch entry.

NC_FLETCHER32 adds the checksum filter (always first in the pipeline); NC_NOCHECKSUM is a no-op, matching upstream — filters cannot be removed once defined.

Parameters
ncidNetCDF file identifier.
varidVariable id.
fletcher32NC_FLETCHER32 to enable, NC_NOCHECKSUM ignored.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_filter_avail()

int NXCDF_inq_filter_avail ( int ncid,
unsigned int id )

Test whether an HDF5 filter is available — the nc_inq_filter_avail() dispatch entry.

Parameters
ncidNetCDF file identifier (ignored; availability is process-wide).
idHDF5 filter identifier.
Returns
NC_NOERR when available, NC_ENOFILTER when not, or a NetCDF error code.

◆ NXCDF_inq_var_filter_ids()

int NXCDF_inq_var_filter_ids ( int ncid,
int varid,
size_t * nfiltersp,
unsigned int * ids )

Inquire the filter ids applied to a variable — the nc_inq_var_filter_ids() dispatch entry.

Reports the pipeline in order. NC_NOERR with a count of zero is returned for a filterless variable, matching upstream.

Parameters
ncidNetCDF file identifier.
varidVariable id.
nfilterspDestination for the number of filters.
idsDestination for the filter ids, or NULL for count only.
Returns
NC_NOERR on success, or a NetCDF error code.

◆ NXCDF_inq_var_filter_info()

int NXCDF_inq_var_filter_info ( int ncid,
int varid,
unsigned int id,
size_t * nparamsp,
unsigned int * params )

Inquire the parameters of one variable filter — the nc_inq_var_filter_info() dispatch entry.

Parameters
ncidNetCDF file identifier.
varidVariable id.
idFilter identifier to inquire about.
nparamspDestination for the number of filter parameters.
paramsDestination for the filter parameter values.
Returns
NC_NOERR on success, NC_ENOFILTER when the filter is not applied, or a NetCDF error code.

◆ nxcdf_load_filters()

int nxcdf_load_filters ( hid_t dcpl,
NC_VAR_INFO_T * var,
NXCDF_VAR_INFO_T * vinfo )

Read a variable's filter pipeline from a dataset creation property list.

Port of upstream get_filter_info() (libhdf5/hdf5open.c): every filter in the DCPL is recorded on var->filters in order, with its stored parameters — even when the filter plugin is unavailable, so metadata stays readable. An unavailable filter marks the spec and the variable NC_HDF5_VAR_FILTER_MISSING (data reads then fail with NC_ENOFILTER); a mandatory filter on a variable-sized type marks the variable the same way. Deflate's parameters are validated, and szip's HDF5-expanded 4-parameter form is folded back to the 2 netcdf-c reports.

Parameters
dcplDataset creation property list identifier.
varVariable.
vinfonxCDF variable state (flags destination).
Returns
NC_NOERR on success, or a NetCDF error code.