Commit 41953dfb authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

add test version of SUNZIP for GRIB data

parent f6495f4e
2006-08-01 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using GRIB library version 1.0.1
* add test version of SUNZIP for GRIB data
* add DATATYPE PACK1 to PACK32
* change DATATYPE from byte to bit
* split GRIB level type 105 with env var SPLIT_LTYPE_105
......
......@@ -15,23 +15,27 @@ case "${HOSTNAME}" in
ds*)
./configure --prefix=$HOME/local \
--with-netcdf=/pool/ia64/netcdf/netcdf-3.6.0-p1 \
CC=ecc CFLAGS="-g -O2 -Wall -fno-alias CFINT=-Df2cFortran -DMIN_BUF_SIZE=4194304"
CPPFLAGS="-DHAVE_LIBSZ -I$HOME/local/include" LIBS=$HOME/local/lib/libsz.a \
CC=icc CFLAGS="-g -O2 -Wall -fno-alias CFINT=-Df2cFortran -DMIN_BUF_SIZE=4194304"
;;
# i686-suse-linux
linux)
./configure --prefix=$HOME/local \
--enable-dap --with-netcdf=$HOME/local \
CPPFLAGS="-DHAVE_LIBSZ -I$HOME/local/include" LIBS=$HOME/local/lib/libsz.a \
CC=g++ CFLAGS="-g -O2 -Wall" CFINT=-Df2cFortran
;;
gata)
./configure --prefix=$HOME/local/LINUX \
--with-netcdf=/client \
CPPFLAGS="-DHAVE_LIBSZ -I$HOME/local/LINUX/include" LIBS=$HOME/local/LINUX/lib/libsz.a \
CC=gcc CFLAGS="-ansi -g -O2 -Wall" CFINT=-Df2cFortran
;;
# sparc-sun-solaris2.8
xxf)
./configure --prefix=$HOME/local/SUN \
--with-netcdf=/client \
CPPFLAGS="-DHAVE_LIBSZ -I$HOME/local/SUN/include" LIBS=$HOME/local/SUN/lib/libsz.a \
CC=cc CFLAGS="-fast"
;;
# sparc-sun-solaris2.9
......
......@@ -71,7 +71,7 @@ static void usage(void)
fprintf(stderr, " -V Print version number\n");
fprintf(stderr, "\n");
fprintf(stderr, " Report bugs to <schulzweida@dkrz.de>\n");
fprintf(stderr, " Report bugs to <Uwe.Schulzweida@zmaw.de>\n");
}
......@@ -310,16 +310,14 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
fprintf(stdout, " variable");
prec = vlistInqVarDatatype(vlistID, varID);
if ( prec == DATATYPE_PACK ) strcpy(pstr, "P0");
else if ( prec == DATATYPE_PACK8 ) strcpy(pstr, "P1");
else if ( prec == DATATYPE_PACK16 ) strcpy(pstr, "P2");
else if ( prec == DATATYPE_PACK24 ) strcpy(pstr, "P3");
else if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "R4");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "R8");
else if ( prec == DATATYPE_INT8 ) strcpy(pstr, "I1");
else if ( prec == DATATYPE_INT16 ) strcpy(pstr, "I2");
else if ( prec == DATATYPE_INT32 ) strcpy(pstr, "I4");
else strcpy(pstr, "-1");
if ( prec == DATATYPE_PACK ) strcpy(pstr, "P0");
else if ( prec > 0 && prec <= 32 ) sprintf(pstr, "P%d", prec);
else if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "F32");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "F64");
else if ( prec == DATATYPE_INT8 ) strcpy(pstr, "I8");
else if ( prec == DATATYPE_INT16 ) strcpy(pstr, "I16");
else if ( prec == DATATYPE_INT32 ) strcpy(pstr, "I32");
else strcpy(pstr, "-1");
fprintf(stdout, " %-3s", pstr);
......@@ -861,6 +859,7 @@ int main(int argc, char *argv[])
}
tsID = 0;
if ( Info || fname2 )
while ( (nrecs = streamInqTimestep(streamID1, tsID)) > 0 )
{
if ( fname2 && ntsteps != 0 )
......
/* Generated automatically from m214003 on Do Jul 27 20:36:33 CEST 2006 */
/* Generated automatically from m214003 on Mon Jul 31 09:47:39 CEST 2006 */
#if defined (HAVE_CONFIG_H)
# include "config.h"
......@@ -7263,9 +7263,9 @@ int gribBzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbuf
bds_rep = bds_flag >> 7;
bds_cplx = (bds_flag >> 6)&1;
bds_aflag = (bds_flag >> 4)&1;
if ( bds_nbits != 8 && bds_nbits != 16 && bds_nbits != 24 ) return (rec_len);
if ( bds_nbits != 8 && bds_nbits != 16 && bds_nbits != 24 && bds_nbits != 32 ) return (rec_len);
if ( bds_rep == 0 )
{
datstart = 11;
......@@ -7525,9 +7525,18 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
bds_rep = bds_flag >> 7;
bds_cplx = (bds_flag >> 6)&1;
bds_aflag = (bds_flag >> 4)&1;
if ( bds_nbits != 8 && bds_nbits != 16 && bds_nbits != 24 ) return (rec_len);
if ( bds_nbits != 8 && bds_nbits != 16 && bds_nbits != 24 && bds_nbits != 32 )
{
static int linfo = 1;
if ( linfo )
{
linfo = 0;
fprintf(stderr, "GRIB zip is only available for 8, 16, 24 and 32 bit data!\n");
}
return (rec_len);
}
sz_param.options_mask = OPTIONS_MASK;
#if defined (SZTEST)
sz_param.bits_per_pixel = 8;
......@@ -7569,6 +7578,7 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
source = bds + datstart;
dest = sbuf;
#if ! defined (SZTEST)
if ( bds_nbits == 24 )
{
int i, nelem;
......@@ -7584,14 +7594,12 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
memcpy(source, pbuf, sourceLen);
free(pbuf);
}
#endif
#if defined (SZTEST)
{
int nbytes = bds_nbits/8;
int i;
if ( nbytes == 2 )
if ( bds_nbits == 16 )
{
if ( datstart == 15 )
{
......@@ -7599,18 +7607,16 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
tmpbuffer2[1] = source[1];
for ( i = 0; i < sourceLen/4; i++ )
{
tmpbuffer2[(sourceLen/4)*2+2+2*i] = source[2+4*i];
tmpbuffer2[(sourceLen/4)*2+2+2*i+1] = source[2+4*i+1];
tmpbuffer2[2+2*i] = source[2+4*i+2];
tmpbuffer2[2+2*i+1] = source[2+4*i+3];
tmpbuffer2[2+2*i+1] = source[2+4*i+3];
}
for ( i = 0; i < sourceLen/2; i++ )
{
tmpbuffer[i] = tmpbuffer2[2*i];
tmpbuffer[ i] = tmpbuffer2[2*i];
tmpbuffer[sourceLen/2+i] = tmpbuffer2[2*i+1];
}
}
......@@ -7618,17 +7624,17 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
{
for ( i = 0; i < sourceLen/2; i++ )
{
tmpbuffer[i] = source[2*i];
tmpbuffer[ i] = source[2*i];
tmpbuffer[sourceLen/2+i] = source[2*i+1];
}
}
}
else if ( nbytes == 3 )
else if ( bds_nbits == 24 )
{
for ( i = 0; i < sourceLen/3; i++ )
{
tmpbuffer[i] = source[3*i];
tmpbuffer[sourceLen/3+i] = source[3*i+1];
tmpbuffer[ i] = source[3*i];
tmpbuffer[ sourceLen/3+i] = source[3*i+1];
tmpbuffer[2*sourceLen/3+i] = source[3*i+2];
}
}
......@@ -7639,7 +7645,6 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
}
#endif
status = SZ_BufftoBuffCompress(dest, &destLen, source, sourceLen, &sz_param);
if ( status != SZ_OK )
{
......@@ -7795,26 +7800,26 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
recLen = ((int) ((bds[14]<<16)+(bds[15]<<8)+bds[16]));
bds_len = BDS_Len;
bds_nbits = BDS_NumBits;
bds_flag = BDS_Flag;
bds_rep = bds_flag >> 7;
bds_cplx = (bds_flag >> 6)&1;
bds_aflag = (bds_flag >> 4)&1;
bds_len = BDS_Len;
bds_nbits = BDS_NumBits;
bds_flag = BDS_Flag;
bds_rep = bds_flag >> 7;
bds_cplx = (bds_flag >> 6)&1;
bds_aflag = (bds_flag >> 4)&1;
if ( bds_rep == 0 )
{
datstart = 11;
}
else if ( bds_rep == 1 && bds_cplx == 0 )
{
datstart = 15;
}
else
{
fprintf(stderr, "compression of complex packed spectral data unsupported!\n");
return (0);
}
if ( bds_rep == 0 )
{
datstart = 11;
}
else if ( bds_rep == 1 && bds_cplx == 0 )
{
datstart = 15;
}
else
{
fprintf(stderr, "compression of complex packed spectral data unsupported!\n");
return (0);
}
source = (char *) bds + datstart + 12;
sourceLen = ((int) ((bds[20]<<16)+(bds[21]<<8)+bds[22]));
......@@ -7832,8 +7837,8 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
BDS_Flag -= 16;
bdsLen = datstart + destLen;
#if defined (HAVE_LIBSZ)
#if defined (HAVE_LIBSZ)
{
int status;
size_t tmpLen;
......@@ -7931,7 +7936,6 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
fprintf(stderr, "recLen, gribLen, bdsLen %d %d %d\n", recLen, gribLen, bdsLen);
*/
}
#else
if ( libszwarn )
{
......@@ -7942,7 +7946,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
return (gribLen);
}
static const char grb_libvers[] = "1.0.1" " of ""Jul 27 2006"" ""20:36:33";
static const char grb_libvers[] = "1.0.1" " of ""Jul 31 2006"" ""09:47:39";
......
......@@ -223,7 +223,36 @@ int grbDecodeDataDP(unsigned char *gribbuffer, int gribsize, double *data, int g
if ( (izip = gribGetZip(gribsize, gribbuffer, &unzipsize)) > 0 )
{
Error(func, "SZIP decompression not implemented!\n");
if ( izip == 128 ) /* szip */
{
unsigned char *itmpbuffer = NULL;
size_t itmpbuffersize = 0;
if ( unzipsize < (long) gribsize )
{
fprintf(stderr, "Decompressed size smaller than compressed size (in %d; out %ld)!\n",
gribsize, unzipsize);
return (status);
}
if ( itmpbuffersize < gribsize )
{
itmpbuffersize = gribsize;
itmpbuffer = (unsigned char *) realloc(itmpbuffer, itmpbuffersize);
}
memcpy(itmpbuffer, gribbuffer, itmpbuffersize);
unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */
gribsize = gribUnzip(gribbuffer, unzipsize, itmpbuffer, gribsize);
free(itmpbuffer);
}
else
{
fprintf(stderr, "Decompression for %d not implemented!\n", izip);
}
}
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, data,
......@@ -398,6 +427,7 @@ int grbScanTimestep(int streamID)
TAXIS *taxis;
int vlistID;
int rindex, nrecs = 0;
long unzipsize;
COMPVAR compVar, compVar0;
streamCheckID(func, streamID);
......@@ -462,8 +492,20 @@ int grbScanTimestep(int streamID)
streams[streamID].tsteps[tsID].recordSize);
break;
}
if ( gribGetZip(recsize, gribbuffer, &unzipsize) > 0 )
{
unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */
if ( (long) buffersize < unzipsize )
{
buffersize = unzipsize;
gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
}
}
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4,
ipunp, (int *) gribbuffer, recsize, &iword, "J", &iret);
rcode = ISEC1_Parameter;
level1 = ISEC1_Level1;
level2 = ISEC1_Level2;
......@@ -883,6 +925,7 @@ void grbScanTimestep1(int streamID)
int rdate = 0, rtime = 0, tunit = 0, fcast = 0;
TAXIS *taxis;
int vlistID;
long unzipsize;
COMPVAR compVar, compVar0;
streamCheckID(func, streamID);
......@@ -924,6 +967,16 @@ void grbScanTimestep1(int streamID)
status = gribRead(fileID, gribbuffer, &readsize);
if ( status ) break;
if ( gribGetZip(recsize, gribbuffer, &unzipsize) > 0 )
{
unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */
if ( (long) buffersize < unzipsize )
{
buffersize = unzipsize;
gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
}
}
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4,
ipunp, (int *) gribbuffer, recsize, &iword, "J", &iret);
......@@ -1080,6 +1133,7 @@ int grbScanTimestep2(int streamID)
int nextstep;
TAXIS *taxis;
int vlistID;
long unzipsize;
COMPVAR compVar, compVar0;
streamCheckID(func, streamID);
......@@ -1143,6 +1197,16 @@ int grbScanTimestep2(int streamID)
status = gribRead(fileID, gribbuffer, &readsize);
if ( status ) break;
if ( gribGetZip(recsize, gribbuffer, &unzipsize) > 0 )
{
unzipsize += 100; /* need 0 to 1 bytes for rounding of bds */
if ( (long) buffersize < unzipsize )
{
buffersize = unzipsize;
gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
}
}
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4,
ipunp, (int *) gribbuffer, recsize, &iword, "J", &iret);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment