2017-10-09 06:37:42 +08:00
|
|
|
/*
|
2018-12-07 05:29:57 +08:00
|
|
|
* Copyright 2018, University Corporation for Atmospheric Research
|
2017-10-09 06:37:42 +08:00
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*/
|
2022-05-04 22:04:54 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Functions for working with filters.
|
|
|
|
*/
|
2017-10-09 06:37:42 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "netcdf.h"
|
2019-02-01 12:13:06 +08:00
|
|
|
#include "netcdf_filter.h"
|
2020-02-17 03:59:33 +08:00
|
|
|
#include "ncdispatch.h"
|
|
|
|
#include "nc4internal.h"
|
2017-10-09 06:37:42 +08:00
|
|
|
|
2019-05-22 21:36:22 +08:00
|
|
|
#ifdef USE_HDF5
|
2019-03-22 01:33:27 +08:00
|
|
|
#include "hdf5internal.h"
|
|
|
|
#endif
|
|
|
|
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
#ifdef ENABLE_NCZARR
|
|
|
|
#include "zdispatch.h"
|
|
|
|
#endif
|
|
|
|
|
2017-10-09 06:37:42 +08:00
|
|
|
/*
|
2020-02-17 03:59:33 +08:00
|
|
|
Unified filter related code
|
2017-10-09 06:37:42 +08:00
|
|
|
*/
|
|
|
|
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
/**************************************************/
|
|
|
|
/* Per-variable filters */
|
|
|
|
|
2020-02-17 03:59:33 +08:00
|
|
|
/**
|
|
|
|
Find the set of filters (if any) associated with a variable.
|
2020-09-28 02:43:46 +08:00
|
|
|
Assumes HDF5 format using unsigned ints.
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param ncid NetCDF or group ID, from a previous call to nc_open(),
|
2020-02-17 03:59:33 +08:00
|
|
|
nc_create(), nc_def_grp(), or associated inquiry functions such as
|
|
|
|
nc_inq_ncid().
|
2022-05-04 22:04:54 +08:00
|
|
|
@param varid Variable ID
|
|
|
|
@param nfiltersp Pointer that gets the number of filters; may be zero.
|
|
|
|
@param ids return the filter ids (caller allocates)
|
|
|
|
|
|
|
|
@returns ::NC_NOERR No error.
|
|
|
|
@returns ::NC_ENOTNC4 Not a netCDF-4 file.
|
|
|
|
@returns ::NC_EBADID Bad ncid
|
|
|
|
@returns ::NC_ENOTVAR Invalid variable ID.
|
|
|
|
@returns ::NC_EINVAL Invalid arguments
|
|
|
|
@ingroup variables
|
|
|
|
@author Dennis Heimbigner
|
2020-02-17 03:59:33 +08:00
|
|
|
*/
|
|
|
|
EXTERNL int
|
2020-09-28 02:43:46 +08:00
|
|
|
nc_inq_var_filter_ids(int ncid, int varid, size_t* nfiltersp, unsigned int* ids)
|
2020-02-17 03:59:33 +08:00
|
|
|
{
|
2020-09-28 02:43:46 +08:00
|
|
|
NC* ncp;
|
|
|
|
int stat = NC_check_id(ncid,&ncp);
|
|
|
|
if(stat != NC_NOERR) return stat;
|
|
|
|
TRACE(nc_inq_var_filter_ids);
|
|
|
|
if((stat = ncp->dispatch->inq_var_filter_ids(ncid,varid,nfiltersp,ids))) goto done;
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
|
|
|
|
done:
|
2020-02-17 03:59:33 +08:00
|
|
|
return stat;
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
}
|
2020-02-17 03:59:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Find the the param info about filter (if any)
|
|
|
|
associated with a variable and with specified id.
|
2020-09-28 02:43:46 +08:00
|
|
|
Assumes HDF5 format using unsigned ints.
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param ncid NetCDF or group ID, from a previous call to nc_open(),
|
2020-02-17 03:59:33 +08:00
|
|
|
nc_create(), nc_def_grp(), or associated inquiry functions such as
|
|
|
|
nc_inq_ncid().
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param varid Variable ID
|
|
|
|
@param id The filter id of interest
|
|
|
|
@param nparamsp (Out) Storage which will get the number of parameters to the filter
|
|
|
|
@param params (Out) Storage which will get associated parameters.
|
2020-02-17 03:59:33 +08:00
|
|
|
Note: the caller must allocate and free.
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@returns ::NC_NOERR No error.
|
|
|
|
@returns ::NC_ENOTNC4 Not a netCDF-4 file.
|
|
|
|
@returns ::NC_EBADID Bad ncid.
|
|
|
|
@returns ::NC_ENOTVAR Invalid variable ID.
|
|
|
|
@returns ::NC_ENOFILTER Specified filter not defined for this variable.
|
|
|
|
@ingroup variables
|
|
|
|
@author Dennis Heimbigner
|
2020-02-17 03:59:33 +08:00
|
|
|
*/
|
|
|
|
EXTERNL int
|
|
|
|
nc_inq_var_filter_info(int ncid, int varid, unsigned int id, size_t* nparamsp, unsigned int* params)
|
|
|
|
{
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
NC* ncp;
|
|
|
|
int stat = NC_check_id(ncid,&ncp);
|
|
|
|
if(stat != NC_NOERR) return stat;
|
|
|
|
TRACE(nc_inq_var_filter_info);
|
2020-09-28 02:43:46 +08:00
|
|
|
if((stat = ncp->dispatch->inq_var_filter_info(ncid,varid,id,nparamsp,params))) goto done;
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
|
|
|
|
done:
|
2020-09-28 02:43:46 +08:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Define a new variable filter
|
|
|
|
Assumes HDF5 format using unsigned ints.
|
|
|
|
Only variables with chunked storage can use filters.
|
|
|
|
|
|
|
|
@param ncid File and group ID.
|
|
|
|
@param varid Variable ID.
|
|
|
|
@param id Filter ID.
|
|
|
|
@param nparams Number of filter parameters.
|
2022-05-04 22:04:54 +08:00
|
|
|
@param params Filter parameters.
|
2020-09-28 02:43:46 +08:00
|
|
|
|
|
|
|
@return ::NC_NOERR No error.
|
|
|
|
@return ::NC_EINVAL Variable must be chunked.
|
|
|
|
@return ::NC_EBADID Bad ID.
|
|
|
|
@author Dennis Heimbigner
|
|
|
|
*/
|
|
|
|
|
|
|
|
EXTERNL int
|
|
|
|
nc_def_var_filter(int ncid, int varid, unsigned int id, size_t nparams, const unsigned int* params)
|
|
|
|
{
|
2022-02-20 07:47:31 +08:00
|
|
|
int stat = NC_NOERR;
|
2020-09-28 02:43:46 +08:00
|
|
|
NC* ncp;
|
2022-02-20 07:47:31 +08:00
|
|
|
int fixedsize;
|
|
|
|
nc_type xtype;
|
|
|
|
|
|
|
|
TRACE(nc_inq_var_filter);
|
|
|
|
if((stat = NC_check_id(ncid,&ncp))) return stat;
|
|
|
|
/* Get variable' type */
|
|
|
|
if((stat = nc_inq_vartype(ncid,varid,&xtype))) return stat;
|
|
|
|
/* If the variable's type is not fixed-size, then signal error */
|
|
|
|
if((stat = NC4_inq_type_fixed_size(ncid, xtype, &fixedsize))) return stat;
|
|
|
|
if(!fixedsize) return NC_EFILTER;
|
2020-09-28 02:43:46 +08:00
|
|
|
if((stat = ncp->dispatch->def_var_filter(ncid,varid,id,nparams,params))) goto done;
|
|
|
|
done:
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
return stat;
|
2020-02-17 03:59:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Find the first filter (if any) associated with a variable.
|
2020-09-28 02:43:46 +08:00
|
|
|
Assumes HDF5 format using unsigned int.
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param ncid NetCDF or group ID, from a previous call to nc_open(),
|
2020-02-17 03:59:33 +08:00
|
|
|
nc_create(), nc_def_grp(), or associated inquiry functions such as
|
|
|
|
nc_inq_ncid().
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param varid Variable ID
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param idp Storage which will get the filter id; a return value of zero means variable has no filters.
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param nparamsp Storage which will get the number of parameters to the filter
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@param params Storage which will get associated parameters (call allocates and frees).
|
2020-09-28 02:43:46 +08:00
|
|
|
|
|
|
|
This is redundant over the multi-filter API, so
|
|
|
|
it can be implemented in terms of those functions.
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@returns ::NC_NOERR No error.
|
|
|
|
@returns ::NC_ENOTNC4 Not a netCDF-4 file.
|
|
|
|
@returns ::NC_EBADID Bad ncid.
|
|
|
|
@returns ::NC_ENOTVAR Invalid variable ID.
|
2020-09-28 02:43:46 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
@ingroup variables
|
|
|
|
@author Dennis Heimbigner
|
2020-02-17 03:59:33 +08:00
|
|
|
*/
|
|
|
|
EXTERNL int
|
|
|
|
nc_inq_var_filter(int ncid, int varid, unsigned int* idp, size_t* nparamsp, unsigned int* params)
|
|
|
|
{
|
|
|
|
NC* ncp;
|
2020-09-28 02:43:46 +08:00
|
|
|
size_t nfilters;
|
|
|
|
unsigned int* ids = NULL;
|
2020-02-17 03:59:33 +08:00
|
|
|
int stat = NC_check_id(ncid,&ncp);
|
2020-09-28 02:43:46 +08:00
|
|
|
|
2020-02-17 03:59:33 +08:00
|
|
|
if(stat != NC_NOERR) return stat;
|
2020-09-28 02:43:46 +08:00
|
|
|
TRACE(nc_inq_var_filter);
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
|
2020-09-28 02:43:46 +08:00
|
|
|
/* Get the number of filters on this variable */
|
|
|
|
if((stat = nc_inq_var_filter_ids(ncid,varid,&nfilters, NULL))) goto done;
|
|
|
|
/* If no filters, then return zero */
|
|
|
|
if(nfilters == 0) {
|
|
|
|
if(idp) *idp = 0;
|
|
|
|
goto done;
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
}
|
2020-09-28 02:43:46 +08:00
|
|
|
/* Get the filter ids */
|
|
|
|
if((ids = calloc(sizeof(unsigned int),nfilters)) == NULL) {stat = NC_ENOMEM; goto done;}
|
|
|
|
if((stat = nc_inq_var_filter_ids(ncid,varid,&nfilters, ids))) goto done;
|
|
|
|
/* Get params for the first filter */
|
|
|
|
if((stat = nc_inq_var_filter_info(ncid,varid,ids[0],nparamsp,params))) goto done;
|
|
|
|
if(idp) *idp = ids[0];
|
|
|
|
done:
|
|
|
|
nullfree(ids);
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
return stat;
|
2020-02-17 03:59:33 +08:00
|
|
|
}
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/** Test if filter is available. Would prefer
|
|
|
|
* returning a list of all available filters, but HDF5
|
|
|
|
* does not support that capability.
|
|
|
|
*
|
|
|
|
* @param ncid ID of file for which filter list is desired
|
|
|
|
* @param id filter id of interest
|
|
|
|
*
|
|
|
|
* @return NC_NOERR if the filter is available
|
|
|
|
* @return NC_EBADID if ncid is invalid
|
|
|
|
* @return NC_ENOFILTER if filter is not available.
|
|
|
|
* @author Dennis Heimbigner
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
EXTERNL int
|
|
|
|
nc_inq_filter_avail(int ncid, unsigned id)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
NC* ncp;
|
|
|
|
|
|
|
|
stat = NC_check_id(ncid,&ncp);
|
|
|
|
if(stat != NC_NOERR) return stat;
|
|
|
|
if((stat = ncp->dispatch->inq_filter_avail(ncid,id))) goto done;
|
|
|
|
done:
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2020-09-28 02:43:46 +08:00
|
|
|
/**************************************************/
|
|
|
|
/* Support direct user defined filters */
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2020-09-28 02:43:46 +08:00
|
|
|
#ifdef ENABLE_CLIENTSIDE_FILTERS
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/** Register filer client.
|
|
|
|
* @note Use void* to avoid having to include hdf.h
|
|
|
|
*
|
|
|
|
* @param id Filter ID
|
|
|
|
* @param info Pointer that gets info.
|
|
|
|
*
|
|
|
|
* @return NC_NOERR if the filter is available
|
|
|
|
* @return NC_EBADID if ncid is invalid
|
|
|
|
* @return NC_ENOFILTER if filter is not available.
|
|
|
|
* @author Dennis Heimbigner
|
|
|
|
*/
|
2020-02-17 03:59:33 +08:00
|
|
|
EXTERNL int
|
2020-09-28 02:43:46 +08:00
|
|
|
nc_filter_client_register(unsigned int id, void* info)
|
2020-02-17 03:59:33 +08:00
|
|
|
{
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
int stat = NC_NOERR;
|
2020-09-28 02:43:46 +08:00
|
|
|
#ifdef USE_HDF5
|
|
|
|
NC_FILTER_OBJ_HDF5 client;
|
|
|
|
if(id == 0 ||info == NULL)
|
|
|
|
return NC_EINVAL;
|
|
|
|
memset(&client,0,sizeof(client));
|
|
|
|
client.hdr.format = NC_FILTER_FORMAT_HDF5;
|
|
|
|
client.sort = NC_FILTER_SORT_CLIENT;
|
|
|
|
client.u.client.id = id;
|
|
|
|
client.u.client.info = info;
|
|
|
|
/* Note use of a global function, not part of the dispatch table */
|
|
|
|
stat = nc4_global_filter_action(NCFILTER_CLIENT_REG, id, &client);
|
|
|
|
#else
|
|
|
|
stat = NC_ENOTBUILT;
|
|
|
|
#endif
|
|
|
|
return stat;
|
|
|
|
}
|
2020-02-17 03:59:33 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/** Unregister filer client.
|
|
|
|
* @note Use void* to avoid having to include hdf.h
|
|
|
|
*
|
|
|
|
* @param id Filter ID
|
|
|
|
*
|
|
|
|
* @return NC_NOERR if the filter is available
|
|
|
|
* @author Dennis Heimbigner
|
|
|
|
*/
|
2020-09-28 02:43:46 +08:00
|
|
|
EXTERNL int
|
|
|
|
nc_filter_client_unregister(unsigned int id)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
#ifdef USE_HDF5
|
|
|
|
stat = nc4_global_filter_action(NCFILTER_CLIENT_UNREG, id, NULL);
|
|
|
|
#else
|
|
|
|
stat = NC_ENOTBUILT;
|
|
|
|
#endif
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
return stat;
|
2019-02-01 12:13:06 +08:00
|
|
|
}
|
2020-09-28 02:43:46 +08:00
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/** Inquire about filer client.
|
|
|
|
* @note Use void* to avoid having to include hdf.h
|
|
|
|
*
|
|
|
|
* @param id Filter ID
|
|
|
|
* @param infop Pointer that gets info.
|
|
|
|
*
|
|
|
|
* @return NC_NOERR if the filter is available
|
|
|
|
* @author Dennis Heimbigner
|
|
|
|
*/
|
2020-09-28 02:43:46 +08:00
|
|
|
EXTERNL int
|
|
|
|
nc_filter_client_inq(unsigned int id, void* infop)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
#ifdef USE_HDF5
|
|
|
|
H5Z_class2_t* hct = (H5Z_class2_t*)infop;
|
|
|
|
NC_FILTER_OBJ_HDF5 client;
|
|
|
|
if(id == 0 ||infop == NULL)
|
|
|
|
return NC_EINVAL;
|
|
|
|
memset(&client,0,sizeof(client));
|
|
|
|
client.hdr.format = NC_FILTER_FORMAT_HDF5;
|
|
|
|
client.sort = NC_FILTER_SORT_CLIENT;
|
|
|
|
client.u.client.id = id;
|
|
|
|
client.u.client.info = hct;
|
|
|
|
/* Note use of a global function, not part of the dispatch table */
|
|
|
|
stat = nc4_global_filter_action(NCFILTER_CLIENT_INQ, id, &client);
|
|
|
|
if(stat == NC_NOERR) {
|
|
|
|
*hct = *(H5Z_class2_t*)client.u.client.info;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
stat = NC_ENOTBUILT;
|
|
|
|
#endif
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
#endif /*ENABLE_CLIENTSIDE_FILTERS*/
|
|
|
|
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
/**************************************************/
|
|
|
|
/* Functions for accessing standardized filters */
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/**
|
|
|
|
* Turn on bzip2 compression for a variable.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param level From 1 to 9. Set the block size to 100k, 200k ... 900k
|
|
|
|
* when compressing. (bzip2 default level is 9).
|
|
|
|
*
|
|
|
|
* @return 0 for success, error code otherwise.
|
|
|
|
* @author Dennis Heimbigner, Ed Hartnett
|
|
|
|
*/
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
int
|
|
|
|
nc_def_var_bzip2(int ncid, int varid, int level)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
unsigned ulevel;
|
|
|
|
|
|
|
|
if((stat = nc_inq_filter_avail(ncid,H5Z_FILTER_BZIP2))) goto done;
|
|
|
|
/* Filter is available */
|
|
|
|
/* 1 <= Level <= 9 */
|
|
|
|
if (level < 1 || level > 9)
|
|
|
|
return NC_EINVAL;
|
|
|
|
ulevel = (unsigned) level; /* Keep bit pattern */
|
|
|
|
if((stat = nc_def_var_filter(ncid,varid,H5Z_FILTER_BZIP2,1,&ulevel))) goto done;
|
|
|
|
done:
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/**
|
|
|
|
* Learn whether bzip2 compression is on for a variable, and, if so,
|
|
|
|
* the level setting.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param hasfilterp Pointer that gets a 0 if bzip2 is not in use for this
|
|
|
|
* var, and a 1 if it is. Ignored if NULL.
|
|
|
|
* @param levelp Pointer that gets the level setting (from 1 to 9), if
|
|
|
|
* bzip2 is in use. Ignored if NULL.
|
|
|
|
*
|
|
|
|
* @return 0 for success, error code otherwise.
|
|
|
|
* @author Dennis Heimbigner, Ed Hartnett
|
|
|
|
*/
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
int
|
|
|
|
nc_inq_var_bzip2(int ncid, int varid, int* hasfilterp, int *levelp)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
size_t nparams;
|
|
|
|
unsigned params = 0;
|
|
|
|
int hasfilter = 0;
|
|
|
|
|
|
|
|
if((stat = nc_inq_filter_avail(ncid,H5Z_FILTER_BZIP2))) goto done;
|
|
|
|
/* Filter is available */
|
|
|
|
/* Get filter info */
|
|
|
|
stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_BZIP2,&nparams,NULL);
|
|
|
|
if(stat == NC_ENOFILTER) {stat = NC_NOERR; hasfilter = 0; goto done;}
|
|
|
|
if(stat != NC_NOERR) goto done;
|
|
|
|
hasfilter = 1;
|
|
|
|
if(nparams != 1) {stat = NC_EFILTER; goto done;}
|
|
|
|
if((stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_BZIP2,&nparams,¶ms))) goto done;
|
|
|
|
done:
|
|
|
|
if(levelp) *levelp = (int)params;
|
|
|
|
if(hasfilterp) *hasfilterp = hasfilter;
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/**
|
|
|
|
* Turn on Zstandard compression for a variable.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param level From -131072 to 22 (depends on Zstandard version).
|
|
|
|
* when compressing. Regular compression levels are from 1 up to 19.
|
|
|
|
* Use levels >= 20, labeled `--ultra`, cautiously: they require more memory.
|
|
|
|
* Negative compression levels that extend the range of speed vs. ratio preferences.
|
|
|
|
* The lower the level, the faster the speed (at the cost of compression).
|
|
|
|
*
|
|
|
|
* @return 0 for success, error code otherwise.
|
|
|
|
* @author Charlie Zender, Dennis Heimbigner, Ed Hartnett
|
|
|
|
*/
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
int
|
|
|
|
nc_def_var_zstandard(int ncid, int varid, int level)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_ZSTD
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
unsigned ulevel;
|
|
|
|
|
|
|
|
if((stat = nc_inq_filter_avail(ncid,H5Z_FILTER_ZSTD))) goto done;
|
|
|
|
/* Filter is available */
|
|
|
|
/* Level must be between -131072 and 22 on Zstandard v. 1.4.5 (~202009)
|
|
|
|
Earlier versions have fewer levels (especially fewer negative levels) */
|
|
|
|
if (level < -131072 || level > 22)
|
|
|
|
return NC_EINVAL;
|
|
|
|
ulevel = (unsigned) level; /* Keep bit pattern */
|
|
|
|
if((stat = nc_def_var_filter(ncid,varid,H5Z_FILTER_ZSTD,1,&ulevel))) goto done;
|
|
|
|
done:
|
|
|
|
return stat;
|
|
|
|
#else
|
|
|
|
return NC_NOERR;
|
|
|
|
#endif /*HAVE_ZSTD*/
|
|
|
|
}
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/**
|
|
|
|
* Learn whether Zstandard compression is on for a variable, and, if so,
|
|
|
|
* the level setting.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param hasfilterp Pointer that gets a 0 if Zstandard is not in use for this
|
|
|
|
* var, and a 1 if it is. Ignored if NULL.
|
|
|
|
* @param levelp Pointer that gets the level setting (from -131072 to 22), if
|
|
|
|
* Zstandard is in use. Ignored if NULL.
|
|
|
|
*
|
|
|
|
* @return 0 for success, error code otherwise.
|
|
|
|
* @author Charlie Zender, Dennis Heimbigner, Ed Hartnett
|
|
|
|
*/
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
int
|
|
|
|
nc_inq_var_zstandard(int ncid, int varid, int* hasfilterp, int *levelp)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_ZSTD
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
size_t nparams;
|
|
|
|
unsigned params = 0;
|
|
|
|
int hasfilter = 0;
|
|
|
|
|
|
|
|
if((stat = nc_inq_filter_avail(ncid,H5Z_FILTER_ZSTD))) goto done;
|
|
|
|
/* Filter is available */
|
|
|
|
/* Get filter info */
|
|
|
|
stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_ZSTD,&nparams,NULL);
|
|
|
|
if(stat == NC_ENOFILTER) {stat = NC_NOERR; hasfilter = 0; goto done;}
|
|
|
|
if(stat != NC_NOERR) goto done;
|
|
|
|
hasfilter = 1;
|
|
|
|
if(nparams != 1) {stat = NC_EFILTER; goto done;}
|
|
|
|
if((stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_ZSTD,&nparams,¶ms))) goto done;
|
|
|
|
done:
|
|
|
|
if(levelp) *levelp = (int)params;
|
|
|
|
if(hasfilterp) *hasfilterp = hasfilter;
|
|
|
|
return stat;
|
|
|
|
#else
|
|
|
|
return NC_NOERR;
|
|
|
|
#endif /*HAVE_ZSTD*/
|
|
|
|
}
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/**
|
|
|
|
* Turn on blosc for a variable.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param subcompressor The subcompressor.
|
|
|
|
* @param level The level setting.
|
|
|
|
* @param blocksize The block size.
|
|
|
|
* @param addshuffle If non-zero, turn on shuffle.
|
|
|
|
*
|
|
|
|
* @return 0 for success, error code otherwise.
|
|
|
|
* @author Dennis Heimbigner
|
|
|
|
* @ingroup variables
|
|
|
|
*/
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
int
|
|
|
|
nc_def_var_blosc(int ncid, int varid, unsigned subcompressor, unsigned level, unsigned blocksize, unsigned addshuffle)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_BLOSC
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
unsigned params[7];;
|
|
|
|
|
|
|
|
if((stat = nc_inq_filter_avail(ncid,H5Z_FILTER_BLOSC))) goto done;
|
|
|
|
/* Filter is available */
|
|
|
|
|
|
|
|
/* Verify parameters */
|
|
|
|
if(addshuffle > (unsigned)BLOSC_BITSHUFFLE) {stat = NC_EINVAL; goto done;}
|
|
|
|
if(subcompressor > (unsigned)BLOSC_ZSTD) {stat = NC_EINVAL; goto done;}
|
|
|
|
|
|
|
|
/* Set the parameters */
|
|
|
|
params[0] = 0;
|
|
|
|
params[1] = 0;
|
|
|
|
params[2] = 0;
|
|
|
|
params[3] = blocksize;
|
|
|
|
params[4] = level;
|
|
|
|
params[5] = addshuffle;
|
|
|
|
params[6] = subcompressor;
|
|
|
|
if((stat = nc_def_var_filter(ncid,varid,H5Z_FILTER_BLOSC,7,params))) goto done;
|
|
|
|
done:
|
|
|
|
return stat;
|
|
|
|
#else
|
|
|
|
return NC_NOERR;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-05-04 22:04:54 +08:00
|
|
|
/**
|
|
|
|
* Learn whether Blosc compression is on for a variable, and, if so,
|
|
|
|
* the settings.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param hasfilterp Pointer that gets a 0 if blosc is not in use for this
|
|
|
|
* var, and a 1 if it is. Ignored if NULL.
|
|
|
|
* @param subcompressorp Pointer that gets the subcompressor, if
|
|
|
|
* blosc is in use. Ignored if NULL.
|
|
|
|
* @param levelp Pointer that gets the level setting, if
|
|
|
|
* blosc is in use. Ignored if NULL.
|
|
|
|
* @param blocksizep Pointer that gets the block size, if
|
|
|
|
* blosc is in use. Ignored if NULL.
|
|
|
|
* @param addshufflep Pointer that gets non-zero value if shuffle is
|
|
|
|
* in use, if blosc is in use. Ignored if NULL.
|
|
|
|
*
|
|
|
|
* @return 0 for success, error code otherwise.
|
|
|
|
* @author Dennis Heimbigner
|
|
|
|
*/
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
int
|
2022-05-04 22:04:54 +08:00
|
|
|
nc_inq_var_blosc(int ncid, int varid, int* hasfilterp, unsigned* subcompressorp,
|
|
|
|
unsigned* levelp, unsigned* blocksizep, unsigned* addshufflep)
|
Enhance/Fix filter support
re: Discussion https://github.com/Unidata/netcdf-c/discussions/2214
The primary change is to support so-called "standard filters".
A standard filter is one that is defined by the following
netcdf-c API:
````
int nc_def_var_XXX(int ncid, int varid, size_t nparams, unsigned* params);
int nc_inq_var_XXXX(int ncid, int varid, int* usefilterp, unsigned* params);
````
So for example, zstandard would be a standard filter by defining
the functions *nc_def_var_zstandard* and *nc_inq_var_zstandard*.
In order to define these functions, we need a new dispatch function:
````
int nc_inq_filter_avail(int ncid, unsigned filterid);
````
This function, combined with the existing filter API can be used
to implement arbitrary standard filters using a simple code pattern.
Note that I would have preferred that this function return a list
of all available filters, but HDF5 does not support that functionality.
So this PR implements the dispatch function and implements
the following standard functions:
+ bzip2
+ zstandard
+ blosc
Specific test cases are also provided for HDF5 and NCZarr.
Over time, other specific standard filters will be defined.
## Primary Changes
* Add nc_inq_filter_avail() to netcdf-c API.
* Add standard filter implementations to test use of *nc_inq_filter_avail*.
* Bump the dispatch table version number and add to all the relevant
dispatch tables (libsrc, libsrcp, etc).
* Create a program to invoke nc_inq_filter_avail so that it is accessible
to shell scripts.
* Cleanup szip support to properly support szip
when HDF5 is disabled. This involves detecting
libsz separately from testing if HDF5 supports szip.
* Integrate shuffle and fletcher32 into the existing
filter API. This means that, for example, nc_def_var_fletcher32
is now a wrapper around nc_def_var_filter.
* Extend the Codec defaulting to allow multiple default shared libraries.
## Misc. Changes
* Modify configure.ac/CMakeLists.txt to look for the relevant
libraries implementing standard filters.
* Modify libnetcdf.settings to list available standard filters
(including deflate and szip).
* Add CMake test modules to locate libbz2 and libzstd.
* Cleanup the HDF5 memory manager function use in the plugins.
* remove unused file include//ncfilter.h
* remove tests for the HDF5 memory operations e.g. H5allocate_memory.
* Add flag to ncdump to force use of _Filter instead of _Deflate
or _Shuffle or _Fletcher32. Used for testing.
2022-03-15 02:39:37 +08:00
|
|
|
{
|
|
|
|
#ifdef HAVE_BLOSC
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
size_t nparams;
|
|
|
|
unsigned params[7];
|
|
|
|
int hasfilter = 0;
|
|
|
|
|
|
|
|
if((stat = nc_inq_filter_avail(ncid,H5Z_FILTER_BLOSC))) goto done;
|
|
|
|
/* Filter is available */
|
|
|
|
|
|
|
|
/* Get filter info */
|
|
|
|
stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_BLOSC,&nparams,NULL);
|
|
|
|
if(stat == NC_ENOFILTER) {stat = NC_NOERR; hasfilter = 0; goto done;}
|
|
|
|
if(stat != NC_NOERR) goto done;
|
|
|
|
hasfilter = 1;
|
|
|
|
if(nparams != 7) {stat = NC_EFILTER; goto done;}
|
|
|
|
if((stat = nc_inq_var_filter_info(ncid,varid,H5Z_FILTER_BLOSC,&nparams,params))) goto done;
|
|
|
|
if(blocksizep) *blocksizep = params[3];
|
|
|
|
if(levelp) *levelp = params[4];
|
|
|
|
if(addshufflep) *addshufflep = params[5];
|
|
|
|
if(subcompressorp) *subcompressorp = params[6];
|
|
|
|
done:
|
|
|
|
if(hasfilterp) *hasfilterp = hasfilter;
|
|
|
|
return stat;
|
|
|
|
#else
|
|
|
|
return NC_NOERR;
|
|
|
|
#endif
|
|
|
|
}
|