Commit 9101e12b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

grbCopyRecord: add SZIP support

parent aafb2b82
......@@ -2,14 +2,15 @@
2006-09-?? Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using GRIB library version 1.0.2
* grbCopyRecord: add SZIP support
* cdfDefVar: set default datatype for addoffset and scalefactor to double
* cdfWriteVar*: round integer field with NINT [report: Etienne Tourigny]
* cdfWriteVar*: round integer fields with NINT [report: Etienne Tourigny]
* Version 1.0.2 released
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 test version of SZIP 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
......
/* Generated automatically from m214003 on Fri Aug 25 13:27:40 CEST 2006 */
/* Generated automatically from m214003 on Mon Sep 4 11:08:24 CEST 2006 */
#if defined (HAVE_CONFIG_H)
# include "config.h"
......@@ -7690,7 +7690,6 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
if ( destLen < MIN_COMPRESS*sourceLen )
{
int zz;
/*
if ( sourceLen < 1000000 )
{
......@@ -7774,11 +7773,6 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
dbuf[4] = 255 & (gribLen >> 16);
dbuf[5] = 255 & (gribLen >> 8);
dbuf[6] = 255 & (gribLen);
zz = gribLen;
while ( zz & 7 ) dbuf[zz++] = 0;
gribLen = zz;
}
/*
fprintf(stderr, "%3d %3d griblen in %6d out %6d CR %g slen %6d dlen %6d CR %g\n",
......@@ -7796,6 +7790,8 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
}
#endif
while ( gribLen & 7 ) dbuf[gribLen++] = 0;
rec_len = gribLen;
return (rec_len);
......@@ -7969,7 +7965,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
return (gribLen);
}
static const char grb_libvers[] = "1.0.2" " of ""Aug 25 2006"" ""13:27:40";
static const char grb_libvers[] = "1.0.2" " of ""Sep 4 2006"" ""11:08:25";
......
......@@ -2150,6 +2150,8 @@ int cdfDefVar(int streamID, int varID)
{
astype = NC_FLOAT;
}
if ( xtype == (int) NC_FLOAT ) astype = NC_FLOAT;
}
if ( laddoffset )
......
......@@ -205,7 +205,7 @@ int grbDefRecord(int streamID)
int grbDecodeDataDP(unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
int unreduced, int *nmiss)
int unreduced, int *nmiss, int *zip)
{
static char func[] = "grbDecodeDataDP";
int status = 0;
......@@ -216,6 +216,8 @@ int grbDecodeDataDP(unsigned char *gribbuffer, int gribsize, double *data, int g
double fsec2[512], fsec3[2];
char hoper[2];
*zip = 0;
if ( unreduced ) strcpy(hoper, "R");
else strcpy(hoper, "D");
......@@ -223,6 +225,7 @@ int grbDecodeDataDP(unsigned char *gribbuffer, int gribsize, double *data, int g
if ( (izip = gribGetZip(gribsize, gribbuffer, &unzipsize)) > 0 )
{
*zip = izip;
if ( izip == 128 ) /* szip */
{
unsigned char *itmpbuffer = NULL;
......@@ -281,6 +284,7 @@ int grbReadRecord(int streamID, double *data, int *nmiss)
off_t recpos;
int gridsize;
int vlistID;
int zip;
streamCheckID(func, streamID);
......@@ -302,7 +306,9 @@ int grbReadRecord(int streamID, double *data, int *nmiss)
fileRead(fileID, gribbuffer, (size_t) recsize);
grbDecodeDataDP(gribbuffer, recsize, data, gridsize, streams[streamID].unreduced, nmiss);
grbDecodeDataDP(gribbuffer, recsize, data, gridsize, streams[streamID].unreduced, nmiss, &zip);
streams[streamID].tsteps[tsID].records[recID].zip = zip;
return (status);
}
......@@ -1425,6 +1431,7 @@ void grbReadVarDP(int streamID, int varID, double *data, int *nmiss)
off_t recpos, currentfilepos;
int imiss;
int vlistID;
int zip;
streamCheckID(func, streamID);
......@@ -1454,14 +1461,17 @@ void grbReadVarDP(int streamID, int varID, double *data, int *nmiss)
fileRead(fileID, gribbuffer, recsize);
grbDecodeDataDP(gribbuffer, recsize, &data[levelID*gridsize], gridsize, streams[streamID].unreduced, &imiss);
grbDecodeDataDP(gribbuffer, recsize, &data[levelID*gridsize], gridsize, streams[streamID].unreduced, &imiss, &zip);
*nmiss += imiss;
streams[streamID].tsteps[tsID].records[recID].zip = zip;
}
fileSetPos(fileID, currentfilepos, SEEK_SET);
}
void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *nmiss)
{
static char func[] = "grbReadVarSliceDP";
......@@ -1472,6 +1482,7 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *
off_t recpos, currentfilepos;
int tsID, recID;
int vlistID;
int zip;
streamCheckID(func, streamID);
......@@ -1501,11 +1512,14 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *
fileRead(fileID, gribbuffer, recsize);
grbDecodeDataDP(gribbuffer, recsize, data, gridsize, streams[streamID].unreduced, nmiss);
grbDecodeDataDP(gribbuffer, recsize, data, gridsize, streams[streamID].unreduced, nmiss, &zip);
fileSetPos(fileID, currentfilepos, SEEK_SET);
streams[streamID].tsteps[tsID].records[recID].zip = zip;
}
void grbDefInstitut(int *isec1, int center, int subcenter)
{
ISEC1_CenterID = center;
......@@ -2169,10 +2183,13 @@ int grbCopyRecord(int ostreamID, int istreamID)
int ifileID, ofileID;
int tsID, recID, vrecID;
long recsize;
long bufsize;
size_t gribbuffersize;
off_t recpos;
int status = 0;
char *buffer;
char *gribbuffer;
size_t nbytes;
long unzipsize;
int izip;
streamCheckID(func, istreamID);
streamCheckID(func, ostreamID);
......@@ -2188,17 +2205,37 @@ int grbCopyRecord(int ostreamID, int istreamID)
fileSetPos(ifileID, recpos, SEEK_SET);
bufsize = recsize == (recsize>>3)<<3 ? recsize : (1+(recsize>>3))<<3;
gribbuffersize = recsize == (recsize>>3)<<3 ? recsize : (1+(recsize>>3))<<3;
gribbuffer = (char *) malloc(gribbuffersize);
buffer = (char *) malloc(bufsize);
fileRead(ifileID, gribbuffer, recsize);
fileRead(ifileID, buffer, recsize);
nbytes = recsize;
izip = gribGetZip(recsize, gribbuffer, &unzipsize);
while ( recsize & 7 ) buffer[recsize++] = 0;
if ( izip == 0 )
if ( streams[ostreamID].compressType == COMPRESS_SZIP )
{
unsigned char *buffer;
size_t buffersize;
buffersize = gribbuffersize;
buffer = (unsigned char *) malloc(buffersize);
fileWrite(ofileID, buffer, recsize);
memcpy(buffer, gribbuffer, gribbuffersize);
free(buffer);
nbytes = gribZip(gribbuffer, (long) gribbuffersize, buffer, (long) buffersize);
free(buffer);
}
while ( nbytes & 7 ) gribbuffer[nbytes++] = 0;
fileWrite(ofileID, gribbuffer, nbytes);
free(gribbuffer);
return (status);
}
......@@ -2334,7 +2371,9 @@ void streamInqGinfo(int streamID, int *intnum, float *fltnum)
int filetype;
void *gribbuffer;
long recsize;
long gribbuffersize;
off_t recpos;
int zip;
streamCheckID(func, streamID);
......@@ -2347,10 +2386,15 @@ void streamInqGinfo(int streamID, int *intnum, float *fltnum)
recID = streams[streamID].tsteps[tsID].recIDs[vrecID];
recpos = streams[streamID].tsteps[tsID].records[recID].position;
recsize = streams[streamID].tsteps[tsID].records[recID].size;
zip = streams[streamID].tsteps[tsID].records[recID].zip;
gribbuffer = streams[streamID].record->buffer;
gribbuffersize = streams[streamID].record->buffersize;
gribGinfo(recpos, recsize, (unsigned char *) gribbuffer, intnum, fltnum);
if ( zip > 0 )
Error(func, "Compressed GRIB records unsupported!");
else
gribGinfo(recpos, gribbuffersize, (unsigned char *) gribbuffer, intnum, fltnum);
}
}
......@@ -117,6 +117,7 @@ typedef struct
{
off_t position;
size_t size;
int zip;
int ilevel;
int ilevel2;
int ltype;
......
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