mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-27 08:49:16 +08:00
11fe00ea05
Filter support has three goals: 1. Use the existing HDF5 filter implementations, 2. Allow filter metadata to be stored in the NumCodecs metadata format used by Zarr, 3. Allow filters to be used even when HDF5 is disabled Detailed usage directions are define in docs/filters.md. For now, the existing filter API is left in place. So filters are defined using ''nc_def_var_filter'' using the HDF5 style where the id and parameters are unsigned integers. This is a big change since filters affect many parts of the code. In the following, the terms "compressor" and "filter" and "codec" are generally used synonomously. ### Filter-Related Changes: * In order to support dynamic loading of shared filter libraries, a new library was added in the libncpoco directory; it helps to isolate dynamic loading across multiple platforms. * Provide a json parsing library for use by plugins; this is created by merging libdispatch/ncjson.c with include/ncjson.h. * Add a new _Codecs attribute to allow clients to see what codecs are being used; let ncdump -s print it out. * Provide special headers to help support compilation of HDF5 filters when HDF5 is not enabled: netcdf_filter_hdf5_build.h and netcdf_filter_build.h. * Add a number of new test to test the new nczarr filters. * Let ncgen parse _Codecs attribute, although it is ignored. ### Plugin directory changes: * Add support for the Blosc compressor; this is essential because it is the most common compressor used in Zarr datasets. This also necessitated adding a CMake FindBlosc.cmake file * Add NCZarr support for the big-four filters provided by HDF5: shuffle, fletcher32, deflate (zlib), and szip * Add a Codec defaulter (see docs/filters.md) for the big four filters. * Make plugins work with windows by properly adding __declspec declaration. ### Misc. Non-Filter Changes * Replace most uses of USE_NETCDF4 (deprecated) with USE_HDF5. * Improve support for caching * More fixes for path conversion code * Fix misc. memory leaks * Add new utility -- ncdump/ncpathcvt -- that does more or less the same thing as cygpath. * Add a number of new test to test the non-filter fixes. * Update the parsers * Convert most instances of '#ifdef _MSC_VER' to '#ifdef _WIN32'
163 lines
3.7 KiB
C
163 lines
3.7 KiB
C
/* This is part of the netCDF package.
|
|
Copyright 2018 University Corporation for Atmospheric Research/Unidata
|
|
See COPYRIGHT file for conditions of use.
|
|
|
|
@Author Dennis Heimbigner
|
|
*/
|
|
|
|
/*********************************************************************
|
|
* Copyright 2018, UCAR/Unidata
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
*********************************************************************/
|
|
/* $Id: main.c,v 1.33 2010/05/26 21:43:36 dmh Exp $ */
|
|
/* $Header: /upc/share/CVS/netcdf-3/ncgen/main.c,v 1.33 2010/05/26 21:43:36 dmh Exp $ */
|
|
|
|
#ifndef TEST_NCZARR_UTILS_H
|
|
#define TEST_NCZARR_UTILS_H
|
|
|
|
#include "config.h"
|
|
#include <assert.h>
|
|
#ifdef HAVE_GETOPT_H
|
|
#include <getopt.h>
|
|
#endif
|
|
|
|
#if defined(_WIN32) && !defined(__MINGW32__)
|
|
#include "XGetopt.h"
|
|
#endif
|
|
|
|
#include "nc_tests.h"
|
|
#include "err_macros.h"
|
|
#include "ncbytes.h"
|
|
#include "zincludes.h"
|
|
|
|
static char* progname = NULL;
|
|
|
|
struct ITOptions {
|
|
NCZM_IMPL impl;
|
|
char* path;
|
|
char* cloud;
|
|
char* otherfragments;
|
|
} itoptions = {NCZM_UNDEF, NULL, NULL, NULL};
|
|
|
|
static void
|
|
test_usage(void)
|
|
{
|
|
fprintf(stderr,"usage: <test> [-e <zmapimpl>]\n");
|
|
exit(1);
|
|
}
|
|
|
|
/* strip off leading path; result is malloc'd */
|
|
static char *
|
|
ubasename(char *logident)
|
|
{
|
|
char* sep;
|
|
|
|
sep = strrchr(logident,'/');
|
|
#ifdef MSDOS
|
|
if(sep == NULL) sep = strrchr(logident,'\\');
|
|
#endif
|
|
if(sep == NULL) return logident;
|
|
sep++; /* skip past the separator */
|
|
return sep;
|
|
}
|
|
|
|
static void
|
|
setimpl(const char* name)
|
|
{
|
|
if(strcasecmp(name,"s3")==0) itoptions.impl = NCZM_S3;
|
|
else if(strcasecmp(name,"file")==0) itoptions.impl = NCZM_FILE;
|
|
else if(strcasecmp(name,"zip")==0) itoptions.impl = NCZM_ZIP;
|
|
else test_usage();
|
|
}
|
|
|
|
static const char*
|
|
implname(void)
|
|
{
|
|
switch (itoptions.impl) {
|
|
case NCZM_S3: return "s3";
|
|
case NCZM_FILE: return "file";
|
|
case NCZM_ZIP: return "zip";
|
|
default: test_usage();
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static void
|
|
buildpath(const char* target,NCZM_IMPL impl)
|
|
{
|
|
NCbytes* buf = ncbytesnew();
|
|
switch(itoptions.impl) {
|
|
case NCZM_ZIP:
|
|
case NCZM_FILE:
|
|
ncbytescat(buf,"file://");
|
|
ncbytescat(buf,target);
|
|
ncbytescat(buf,".");
|
|
ncbytescat(buf,implname());
|
|
ncbytescat(buf,"#mode=nczarr");
|
|
ncbytescat(buf,",");
|
|
ncbytescat(buf,implname());
|
|
break;
|
|
case NCZM_S3:
|
|
ncbytescat(buf,itoptions.cloud);
|
|
if(itoptions.cloud[strlen(itoptions.cloud)-1] != '/')
|
|
ncbytescat(buf,"/");
|
|
ncbytescat(buf,target);
|
|
ncbytescat(buf,"#mode=nczarr");
|
|
ncbytescat(buf,",");
|
|
ncbytescat(buf,implname());
|
|
break;
|
|
default: test_usage();
|
|
}
|
|
if(itoptions.otherfragments != NULL) {
|
|
ncbytescat(buf,",");
|
|
ncbytescat(buf,itoptions.otherfragments);
|
|
}
|
|
itoptions.path = ncbytesextract(buf);
|
|
ncbytesfree(buf);
|
|
}
|
|
|
|
void
|
|
processoptions(int argc, char** argv, const char* base_file_name)
|
|
{
|
|
int c;
|
|
|
|
if(argc == 1) test_usage();
|
|
progname = nulldup(ubasename(argv[0]));
|
|
|
|
while ((c = getopt(argc, argv, "e:c:F:")) != EOF)
|
|
switch(c) {
|
|
case 'e': /* zmap choice */
|
|
setimpl(optarg);
|
|
break;
|
|
case 'c': /* cloud appliance url prefix*/
|
|
itoptions.cloud = strdup(optarg);
|
|
break;
|
|
case 'F': /* fragments */
|
|
itoptions.otherfragments = strdup(optarg);
|
|
break;
|
|
case '?':
|
|
test_usage();
|
|
break;
|
|
}
|
|
|
|
argc -= optind;
|
|
argv += optind;
|
|
|
|
if(itoptions.impl == NCZM_UNDEF) itoptions.impl = NCZM_FILE;
|
|
if(itoptions.impl == NCZM_S3 && itoptions.cloud == NULL) test_usage();
|
|
|
|
buildpath(base_file_name,itoptions.impl);
|
|
|
|
}
|
|
|
|
void
|
|
clearoptions(void)
|
|
{
|
|
nullfree(itoptions.path);
|
|
nullfree(itoptions.cloud);
|
|
nullfree(itoptions.otherfragments);
|
|
nullfree(progname);
|
|
}
|
|
|
|
#endif /*TEST_NCZARR_UTILS_H*/
|