mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-21 08:39:46 +08:00
3ffe7be446
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.
129 lines
4.8 KiB
Bash
Executable File
129 lines
4.8 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
|
|
. ../test_common.sh
|
|
|
|
set -e
|
|
|
|
# For a netCDF-4 build, test nccopy on netCDF files in this directory
|
|
|
|
if test -f tst_group_data${ext} ; then ${execdir}/tst_group_data ; fi
|
|
if test -f tst_enum_data${ext} ; then ${execdir}/tst_enum_data ; fi
|
|
if test -f tst_comp${ext} ; then ${execdir}/tst_comp ; fi
|
|
if test -f tst_comp2${ext} ; then ${execdir}/tst_comp2 ; fi
|
|
|
|
echo ""
|
|
|
|
# These files are actually in $srcdir in distcheck builds, so they
|
|
# need to be handled differently.
|
|
# ref_tst_compounds2 ref_tst_compounds3 ref_tst_compounds4
|
|
TESTFILES0='tst_comp tst_comp2 tst_enum_data tst_fillbug
|
|
tst_group_data tst_nans tst_opaque_data tst_solar_1 tst_solar_2
|
|
tst_solar_cmp tst_special_atts'
|
|
|
|
TESTFILES="$TESTFILES0 tst_string_data"
|
|
|
|
# Causes memory leak; source unknown
|
|
MEMLEAK="tst_vlen_data"
|
|
|
|
echo "*** Testing netCDF-4 features of nccopy on ncdump/*.nc files"
|
|
for i in $TESTFILES ; do
|
|
echo "*** Test nccopy $i.nc copy_of_$i.nc ..."
|
|
# if test "x$i" = xtst_vlen_data ; then
|
|
# ls -l tst_vlen_data*
|
|
# ls -l *.nc
|
|
# fi
|
|
${NCCOPY} $i.nc copy_of_$i.nc
|
|
${NCDUMP} -n copy_of_$i $i.nc > tmp_$i.cdl
|
|
${NCDUMP} copy_of_$i.nc > copy_of_$i.cdl
|
|
echo "*** compare " with copy_of_$i.cdl
|
|
diff copy_of_$i.cdl tmp_$i.cdl
|
|
rm copy_of_$i.nc copy_of_$i.cdl tmp_$i.cdl
|
|
done
|
|
|
|
# echo "*** Testing compression of deflatable files ..."
|
|
./tst_compress
|
|
echo "*** Test nccopy -d1 can compress a classic format file ..."
|
|
${NCCOPY} -d1 tst_inflated.nc tst_deflated.nc
|
|
if test `wc -c < tst_deflated.nc` -ge `wc -c < tst_inflated.nc`; then
|
|
exit 1
|
|
fi
|
|
echo "*** Test nccopy -d1 can compress a netCDF-4 format file ..."
|
|
${NCCOPY} -d1 tst_inflated4.nc tst_deflated.nc
|
|
if test `wc -c < tst_deflated.nc` -ge `wc -c < tst_inflated4.nc`; then
|
|
exit 1
|
|
fi
|
|
echo "*** Test nccopy -d1 -s can compress a classic model netCDF-4 file even more ..."
|
|
${NCCOPY} -d1 -s tst_inflated.nc tmp.nc
|
|
if test `wc -c < tmp.nc` -ge `wc -c < tst_inflated.nc`; then
|
|
exit 1
|
|
fi
|
|
echo "*** Test nccopy -d1 -s can compress a netCDF-4 file even more ..."
|
|
${NCCOPY} -d1 -s tst_inflated4.nc tmp.nc
|
|
if test `wc -c < tmp.nc` -ge `wc -c < tst_inflated4.nc`; then
|
|
exit 1
|
|
fi
|
|
echo "*** Test nccopy -d0 turns off compression, shuffling of compressed, shuffled file ..."
|
|
${NCCOPY} -d0 tst_inflated4.nc tmp.nc
|
|
${NCDUMP} -sh tmp.nc > tmp.cdl
|
|
if fgrep '_DeflateLevel' < tmp.cdl ; then
|
|
exit 1
|
|
fi
|
|
if fgrep '_Shuffle' < tmp.cdl ; then
|
|
exit 1
|
|
fi
|
|
rm tst_deflated.nc tst_inflated.nc tst_inflated4.nc tmp.nc tmp.cdl
|
|
|
|
echo "*** Testing nccopy -d1 -s on ncdump/*.nc files"
|
|
for i in $TESTFILES0 ; do
|
|
echo "*** Test nccopy -d1 -s $i.nc copy_of_$i.nc ..."
|
|
${NCCOPY} -d1 -s $i.nc copy_of_$i.nc
|
|
${NCDUMP} -n copy_of_$i $i.nc > tmp.cdl
|
|
${NCDUMP} copy_of_$i.nc > copy_of_$i.cdl
|
|
# echo "*** compare " with copy_of_$i.cdl
|
|
diff copy_of_$i.cdl tmp.cdl
|
|
rm copy_of_$i.nc copy_of_$i.cdl tmp.cdl
|
|
done
|
|
./tst_chunking
|
|
echo "*** Test that nccopy -c can chunk and unchunk files"
|
|
${NCCOPY} -M0 tst_chunking.nc tmp.nc
|
|
${NCDUMP} tmp.nc > tmp.cdl
|
|
${NCCOPY} -c dim0/,dim1/1,dim2/,dim3/1,dim4/,dim5/1,dim6/ tst_chunking.nc tmp-chunked.nc
|
|
${NCDUMP} -n tmp tmp-chunked.nc > tmp-chunked.cdl
|
|
diff tmp.cdl tmp-chunked.cdl
|
|
${NCCOPY} -c dim0/,dim1/,dim2/,dim3/,dim4/,dim5/,dim6/ tmp-chunked.nc tmp-unchunked.nc
|
|
${NCDUMP} -n tmp tmp-unchunked.nc > tmp-unchunked.cdl
|
|
diff tmp.cdl tmp-unchunked.cdl
|
|
${NCCOPY} -c // tmp-chunked.nc tmp-unchunked2.nc
|
|
${NCDUMP} -n tmp tmp-unchunked.nc > tmp-unchunked2.cdl
|
|
diff tmp.cdl tmp-unchunked2.cdl
|
|
echo "*** Test that nccopy -c works as intended for record dimension default (1)"
|
|
${NCGEN} -b -o tst_bug321.nc $srcdir/tst_bug321.cdl
|
|
${NCCOPY} -k nc7 -c"lat/2,lon/2" tst_bug321.nc tmp.nc
|
|
${NCDUMP} -n tst_bug321 tmp.nc > tmp.cdl
|
|
diff -b $srcdir/tst_bug321.cdl tmp.cdl
|
|
|
|
rm tst_chunking.nc tmp.nc tmp.cdl tmp-chunked.nc tmp-chunked.cdl tmp-unchunked.nc tmp-unchunked.cdl
|
|
|
|
echo "*** Test that nccopy -c dim/n works as intended "
|
|
${NCGEN} -4 -b -o tst_perdimspecs.nc $srcdir/ref_tst_perdimspecs.cdl
|
|
${NCCOPY} -M0 -4 -c "time/10,lat/15,lon/20" tst_perdimspecs.nc tmppds.nc
|
|
${NCDUMP} -hs tmppds.nc > tmppds.cdl
|
|
STORAGE=`cat tmppds.cdl | sed -e '/tas:_Storage/p' -ed | tr -d '\t \r'`
|
|
test "x$STORAGE" = 'xtas:_Storage="chunked";'
|
|
CHUNKSIZES=`cat tmppds.cdl | sed -e '/tas:_ChunkSizes/p' -ed | tr -d '\t \r'`
|
|
test "x$CHUNKSIZES" = 'xtas:_ChunkSizes=10,15,20;'
|
|
|
|
echo "*** Test that nccopy -F var1,none works as intended "
|
|
${NCGEN} -4 -b -o tst_nofilters.nc $srcdir/ref_tst_nofilters.cdl
|
|
${NCCOPY} -M0 -4 -F var1,none -c // tst_nofilters.nc tmp_nofilters.nc
|
|
${NCDUMP} -hs tmp_nofilters.nc > tmp_nofilters.cdl
|
|
STORAGE=`cat tmp_nofilters.cdl | sed -e '/var1:_Storage/p' -ed | tr -d '\t \r'`
|
|
test "x$STORAGE" = 'xvar1:_Storage="contiguous";'
|
|
FILTERS=`cat tmp_nofilters.cdl | sed -e '/var1:_Filters/p' -ed | tr -d '\t \r'`
|
|
test "x$FILTERS" = 'x'
|
|
|
|
echo "*** All nccopy tests passed!"
|
|
|
|
exit 0
|