2018-11-26 20:35:44 +08:00
|
|
|
/* Copyright 2005-2018 University Corporation for Atmospheric
|
|
|
|
Research/Unidata. */
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @internal This header file contains prototypes and initialization
|
|
|
|
* for the HDF5 dispatch layer.
|
|
|
|
*
|
2019-02-25 07:54:13 +08:00
|
|
|
* @author Ed Hartnett, Dennis Heimbigner
|
2019-02-19 20:18:02 +08:00
|
|
|
*/
|
2018-11-26 20:35:44 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
2018-11-26 23:13:57 +08:00
|
|
|
#include "hdf5internal.h"
|
2018-11-26 20:35:44 +08:00
|
|
|
|
2024-03-19 04:31:58 +08:00
|
|
|
#ifdef NETCDF_ENABLE_BYTERANGE
|
Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251
Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.
This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.
Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.
Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.
An additional goal here is to gain some experience with
the Amazon S3 REST protocol.
This architecture and its use documented in
the file docs/byterange.dox.
There are currently two test cases:
1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
datasets.
This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).
1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs
Other changes:
1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
fragment tag with a more general mode= tag.
Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-02 09:27:36 +08:00
|
|
|
#include "H5FDhttp.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-31 04:06:20 +08:00
|
|
|
static const NC_Dispatch HDF5_dispatcher = {
|
2018-11-26 20:35:44 +08:00
|
|
|
|
2019-02-19 20:18:02 +08:00
|
|
|
NC_FORMATX_NC4,
|
2020-02-28 05:06:45 +08:00
|
|
|
NC_DISPATCH_VERSION,
|
2019-02-19 20:18:02 +08:00
|
|
|
|
|
|
|
NC4_create,
|
|
|
|
NC4_open,
|
|
|
|
|
|
|
|
NC4_redef,
|
|
|
|
NC4__enddef,
|
|
|
|
NC4_sync,
|
|
|
|
NC4_abort,
|
|
|
|
NC4_close,
|
|
|
|
NC4_set_fill,
|
|
|
|
NC4_inq_format,
|
|
|
|
NC4_inq_format_extended,
|
|
|
|
|
|
|
|
NC4_inq,
|
|
|
|
NC4_inq_type,
|
|
|
|
|
2020-08-18 09:15:47 +08:00
|
|
|
HDF5_def_dim,
|
2019-02-19 20:18:02 +08:00
|
|
|
NC4_inq_dimid,
|
2020-08-18 09:15:47 +08:00
|
|
|
HDF5_inq_dim,
|
2019-02-19 20:18:02 +08:00
|
|
|
NC4_inq_unlimdim,
|
2020-08-18 09:15:47 +08:00
|
|
|
HDF5_rename_dim,
|
2019-02-19 20:18:02 +08:00
|
|
|
|
|
|
|
NC4_HDF5_inq_att,
|
|
|
|
NC4_HDF5_inq_attid,
|
|
|
|
NC4_HDF5_inq_attname,
|
|
|
|
NC4_HDF5_rename_att,
|
|
|
|
NC4_HDF5_del_att,
|
|
|
|
NC4_HDF5_get_att,
|
|
|
|
NC4_HDF5_put_att,
|
|
|
|
|
|
|
|
NC4_def_var,
|
|
|
|
NC4_inq_varid,
|
|
|
|
NC4_rename_var,
|
|
|
|
NC4_get_vara,
|
|
|
|
NC4_put_vara,
|
|
|
|
NC4_get_vars,
|
|
|
|
NC4_put_vars,
|
|
|
|
NCDEFAULT_get_varm,
|
|
|
|
NCDEFAULT_put_varm,
|
|
|
|
|
|
|
|
NC4_HDF5_inq_var_all,
|
|
|
|
|
|
|
|
NC4_var_par_access,
|
|
|
|
NC4_def_var_fill,
|
2018-11-26 20:35:44 +08:00
|
|
|
|
2019-02-19 20:18:02 +08:00
|
|
|
NC4_show_metadata,
|
|
|
|
NC4_inq_unlimdims,
|
|
|
|
|
|
|
|
NC4_inq_ncid,
|
|
|
|
NC4_inq_grps,
|
|
|
|
NC4_inq_grpname,
|
|
|
|
NC4_inq_grpname_full,
|
|
|
|
NC4_inq_grp_parent,
|
|
|
|
NC4_inq_grp_full_ncid,
|
|
|
|
NC4_inq_varids,
|
|
|
|
NC4_inq_dimids,
|
|
|
|
NC4_inq_typeids,
|
|
|
|
NC4_inq_type_equal,
|
|
|
|
NC4_def_grp,
|
|
|
|
NC4_rename_grp,
|
|
|
|
NC4_inq_user_type,
|
|
|
|
NC4_inq_typeid,
|
|
|
|
|
|
|
|
NC4_def_compound,
|
|
|
|
NC4_insert_compound,
|
|
|
|
NC4_insert_array_compound,
|
|
|
|
NC4_inq_compound_field,
|
|
|
|
NC4_inq_compound_fieldindex,
|
|
|
|
NC4_def_vlen,
|
|
|
|
NC4_put_vlen_element,
|
|
|
|
NC4_get_vlen_element,
|
|
|
|
NC4_def_enum,
|
|
|
|
NC4_insert_enum,
|
|
|
|
NC4_inq_enum_member,
|
|
|
|
NC4_inq_enum_ident,
|
|
|
|
NC4_def_opaque,
|
|
|
|
NC4_def_var_deflate,
|
|
|
|
NC4_def_var_fletcher32,
|
|
|
|
NC4_def_var_chunking,
|
|
|
|
NC4_def_var_endian,
|
2020-09-28 02:43:46 +08:00
|
|
|
NC4_hdf5_def_var_filter,
|
2019-02-19 20:18:02 +08:00
|
|
|
NC4_HDF5_set_var_chunk_cache,
|
|
|
|
NC4_get_var_chunk_cache,
|
2018-11-26 20:35:44 +08:00
|
|
|
|
2020-09-28 02:43:46 +08:00
|
|
|
NC4_hdf5_inq_var_filter_ids,
|
|
|
|
NC4_hdf5_inq_var_filter_info,
|
2021-08-24 15:26:44 +08:00
|
|
|
|
2021-08-24 15:53:16 +08:00
|
|
|
NC4_def_var_quantize,
|
|
|
|
NC4_inq_var_quantize,
|
2021-08-24 15:26:44 +08:00
|
|
|
|
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
|
|
|
NC4_hdf5_inq_filter_avail,
|
2018-11-26 20:35:44 +08:00
|
|
|
};
|
|
|
|
|
2019-03-31 04:06:20 +08:00
|
|
|
const NC_Dispatch* HDF5_dispatch_table = NULL; /* moved here from ddispatch.c */
|
2018-11-26 20:35:44 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal Initialize the HDF5 dispatch layer.
|
|
|
|
*
|
|
|
|
* @return ::NC_NOERR No error.
|
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
NC_HDF5_initialize(void)
|
|
|
|
{
|
2019-03-31 04:06:20 +08:00
|
|
|
HDF5_dispatch_table = &HDF5_dispatcher;
|
2019-02-19 20:18:02 +08:00
|
|
|
if (!nc4_hdf5_initialized)
|
|
|
|
nc4_hdf5_initialize();
|
2018-11-26 20:35:44 +08:00
|
|
|
|
2024-03-19 04:31:58 +08:00
|
|
|
#ifdef NETCDF_ENABLE_BYTERANGE
|
2019-02-24 08:14:12 +08:00
|
|
|
(void)H5FD_http_init();
|
2019-05-04 03:22:54 +08:00
|
|
|
#endif
|
2019-02-24 08:14:12 +08:00
|
|
|
return NC4_provenance_init();
|
2018-11-26 20:35:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal Finalize the HDF5 dispatch layer.
|
|
|
|
*
|
|
|
|
* @return ::NC_NOERR No error.
|
|
|
|
* @author Dennis Heimbigner
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
NC_HDF5_finalize(void)
|
|
|
|
{
|
2024-03-19 04:31:58 +08:00
|
|
|
#ifdef NETCDF_ENABLE_BYTERANGE
|
2023-12-13 07:16:31 +08:00
|
|
|
(void)H5FD_http_finalize();
|
|
|
|
#endif
|
Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251
Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.
This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.
Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.
Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.
An additional goal here is to gain some experience with
the Amazon S3 REST protocol.
This architecture and its use documented in
the file docs/byterange.dox.
There are currently two test cases:
1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
datasets.
This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).
1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs
Other changes:
1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
fragment tag with a more general mode= tag.
Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-02 09:27:36 +08:00
|
|
|
(void)nc4_hdf5_finalize();
|
2018-11-26 20:35:44 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|