mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-27 08:49:16 +08:00
8714066b18
re: issue https://github.com/Unidata/netcdf-c/issues/1278 re: issue https://github.com/Unidata/netcdf-c/issues/876 re: issue https://github.com/Unidata/netcdf-c/issues/806 * Major change to the handling of 8-byte parameters for nc_def_var_filter. The old code was not well thought out. * The new algorithm is documented in docs/filters.md. * Added new utility file plugins/H5Zutil.c to support * Modified plugins/H5Zmisc.c to use new algorithm the new algorithm. * Renamed include/ncfilter.h to include/netcdf_filter.h and made it an installed header so clients can access the new algorithm utility. * Fixed nc_test4/tst_filterparser.c and nc_test4/test_filter_misc.c to use the new algorithm * libdap4/ fixes: * d4swap.c has an error in the endian pre-processing such that record counts were not being swapped correctly. * d4data.c had an error in that checksums were being computed after endian swapping rather than before. * ocinitialize() was never being called, so xxdr bigendian handling was never set correctly. * Required adding debug statements to occompile * Found and fixed memory leak in ncdump.c Not tested: * HDF4 * Pnetcdf * parallel HDF5
66 lines
1.3 KiB
C
66 lines
1.3 KiB
C
/*
|
|
* Copyright 2018, University Corporation for Atmospheric Research
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
*/
|
|
|
|
|
|
#include <hdf5.h>
|
|
|
|
/*
|
|
Common utilities related to filters.
|
|
Taken from libdispatch/dfilters.c.
|
|
*/
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
/* Byte swap an 8-byte integer in place */
|
|
static void
|
|
byteswap8(unsigned char* mem)
|
|
{
|
|
unsigned char c;
|
|
c = mem[0];
|
|
mem[0] = mem[7];
|
|
mem[7] = c;
|
|
c = mem[1];
|
|
mem[1] = mem[6];
|
|
mem[6] = c;
|
|
c = mem[2];
|
|
mem[2] = mem[5];
|
|
mem[5] = c;
|
|
c = mem[3];
|
|
mem[3] = mem[4];
|
|
mem[4] = c;
|
|
}
|
|
|
|
/* Byte swap an 8-byte integer in place */
|
|
static void
|
|
byteswap4(unsigned char* mem)
|
|
{
|
|
unsigned char c;
|
|
c = mem[0];
|
|
mem[0] = mem[3];
|
|
mem[3] = c;
|
|
c = mem[1];
|
|
mem[1] = mem[2];
|
|
mem[2] = c;
|
|
}
|
|
#endif /*WORDS_BIGENDIAN*/
|
|
|
|
void
|
|
NC_filterfix8(void* mem0, int decode)
|
|
{
|
|
#ifdef WORDS_BIGENDIAN
|
|
unsigned char* mem = mem0;
|
|
if(decode) { /* Apply inverse of the encode case */
|
|
byteswap4(mem); /* step 1: byte-swap each piece */
|
|
byteswap4(mem+4);
|
|
byteswap8(mem); /* step 2: convert to little endian format */
|
|
} else { /* encode */
|
|
byteswap8(mem); /* step 1: convert to little endian format */
|
|
byteswap4(mem); /* step 2: byte-swap each piece */
|
|
byteswap4(mem+4);
|
|
}
|
|
#else /* Little endian */
|
|
/* No action is necessary */
|
|
#endif
|
|
}
|