netcdf-c/plugins/H5Zutil.c
Dennis Heimbigner 4c1ed0144b Fix nc_test4/tst_filter.sh for big endian
re: issue https://github.com/Unidata/netcdf-c/issues/1338

Changes:

1. nc_test4/tst_filter.sh + nc_test4/ref_filteredvv.cdl --
   properly suppress _Endianness attribute
2. fix some warnings
2019-02-24 22:20:01 -07:00

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
}