Commit 76b25beb authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

add option -z szip for SZIP compression of GRIB records

parent dc57a74b
......@@ -346,6 +346,15 @@ Get all values of a Y-axis.
Close an open dataset.
\section*{\tt \htmlref{streamDefByteorder}{streamDefByteorder}}
\begin{verbatim}
void streamDefByteorder (intstreamID, intbyteorder);
\end{verbatim}
Define the byteorder.
\section*{\tt \htmlref{streamDefTimestep}{streamDefTimestep}}
\begin{verbatim}
......@@ -364,6 +373,15 @@ Define time step.
Define the Vlist for a stream.
\section*{\tt \htmlref{streamInqByteorder}{streamInqByteorder}}
\begin{verbatim}
int streamInqByteorder (intstreamID);
\end{verbatim}
Get the byteorder.
\section*{\tt \htmlref{streamInqFiletype}{streamInqFiletype}}
\begin{verbatim}
......@@ -591,6 +609,15 @@ Copy some entries of a variable list.
Create a variable list.
\section*{\tt \htmlref{vlistDefTaxis}{vlistDefTaxis}}
\begin{verbatim}
void vlistDefTaxis (intvlistID, inttaxisID);
\end{verbatim}
Define the time axis of a variable list.
\section*{\tt \htmlref{vlistDefVar}{vlistDefVar}}
\begin{verbatim}
......@@ -672,6 +699,69 @@ Destroy a variable list.
Duplicate a variable list.
\section*{\tt \htmlref{vlistInqTaxis}{vlistInqTaxis}}
\begin{verbatim}
int vlistInqTaxis (intvlistID);
\end{verbatim}
Get the time axis of a variable list.
\section*{\tt \htmlref{vlistInqVarCode}{vlistInqVarCode}}
\begin{verbatim}
int vlistInqVarCode (intvlistID, intvarID);
\end{verbatim}
Get the code number of a Variable.
\section*{\tt \htmlref{vlistInqVarDatatype}{vlistInqVarDatatype}}
\begin{verbatim}
int vlistInqVarDatatype (intvlistID, intvarID);
\end{verbatim}
Get the data type of a Variable.
\section*{\tt \htmlref{vlistInqVarLongname}{vlistInqVarLongname}}
\begin{verbatim}
void vlistInqVarLongname (intvlistID, intvarID, char *longname);
\end{verbatim}
Get the long name of a Variable.
\section*{\tt \htmlref{vlistInqVarMissval}{vlistInqVarMissval}}
\begin{verbatim}
double vlistInqVarMissval (intvlistID, intvarID);
\end{verbatim}
Get the missing value of a Variable.
\section*{\tt \htmlref{vlistInqVarName}{vlistInqVarName}}
\begin{verbatim}
void vlistInqVarName (intvlistID, intvarID, char *name);
\end{verbatim}
Get the name of a Variable.
\section*{\tt \htmlref{vlistInqVarUnits}{vlistInqVarUnits}}
\begin{verbatim}
void vlistInqVarUnits (intvlistID, intvarID, char *units);
\end{verbatim}
Get the units of a Variable.
\section*{\tt \htmlref{vlistMerge}{vlistMerge}}
\begin{verbatim}
......
......@@ -129,7 +129,7 @@ The function {\tt taxisDefVdate} defines the reference time of a Time axis.
\item[{\tt taxisID}]
Time axis ID, from a previous call to {\htmlref{\tt taxisCreate}{taxisCreate}}
\item[{\tt rtime}]
Reference time (HHMM)
Reference time (hhmm)
\end{deflist}
\end{minipage}
......@@ -227,7 +227,7 @@ The function {\tt taxisDefVtime} defines the verification time of a Time axis.
\item[{\tt taxisID}]
Time axis ID, from a previous call to {\htmlref{\tt taxisCreate}{taxisCreate}}
\item[{\tt vtime}]
Verification time (HHMM)
Verification time (hhmm)
\end{deflist}
\end{minipage}
......
......@@ -347,8 +347,8 @@ Variable list ID, from a previous call to {\htmlref{\tt vlistCreate}{vlistCreate
Variable identifier
\item[{\tt datatype}]
The data type identifier.
The valid {\CDI} data types are {\tt DATATYPE\_PACK1}, {\tt DATATYPE\_PACK2},
{\tt DATATYPE\_PACK3}, {\tt DATATYPE\_REAL4} and {\tt DATATYPE\_REAL8}.
The valid {\CDI} data types are {\tt DATATYPE\_PACK8}, {\tt DATATYPE\_PACK16},
{\tt DATATYPE\_PACK24}, {\tt DATATYPE\_FLT32} and {\tt DATATYPE\_FLT64}.
\end{deflist}
......@@ -380,8 +380,8 @@ Variable identifier
\subsubsection*{Result}
{\tt vlistInqVarDatatype} returns an identifier to the data type of the variable.
The valid {\CDI} data types are {\tt DATATYPE\_PACK1}, {\tt DATATYPE\_PACK2}, {\tt DATATYPE\_PACK3},
{\tt DATATYPE\_REAL4} and {\tt DATATYPE\_REAL8}.
The valid {\CDI} data types are {\tt DATATYPE\_PACK8}, {\tt DATATYPE\_PACK16}, {\tt DATATYPE\_PACK24},
{\tt DATATYPE\_FLT32} and {\tt DATATYPE\_FLT64}.
......
......@@ -346,6 +346,15 @@ Get all values of a Y-axis.
Close an open dataset.
\section*{\tt \htmlref{streamDefByteorder}{streamDefByteorder}}
\begin{verbatim}
SUBROUTINE streamDefByteorder (INTEGER streamID, INTEGER byteorder)
\end{verbatim}
Define the byteorder.
\section*{\tt \htmlref{streamDefTimestep}{streamDefTimestep}}
\begin{verbatim}
......@@ -364,6 +373,15 @@ Define time step.
Define the Vlist for a stream.
\section*{\tt \htmlref{streamInqByteorder}{streamInqByteorder}}
\begin{verbatim}
INTEGER FUNCTION streamInqByteorder (INTEGER streamID)
\end{verbatim}
Get the byteorder.
\section*{\tt \htmlref{streamInqFiletype}{streamInqFiletype}}
\begin{verbatim}
......@@ -593,6 +611,15 @@ Copy some entries of a variable list.
Create a variable list.
\section*{\tt \htmlref{vlistDefTaxis}{vlistDefTaxis}}
\begin{verbatim}
SUBROUTINE vlistDefTaxis (INTEGER vlistID, INTEGER taxisID)
\end{verbatim}
Define the time axis of a variable list.
\section*{\tt \htmlref{vlistDefVar}{vlistDefVar}}
\begin{verbatim}
......@@ -677,6 +704,70 @@ Destroy a variable list.
Duplicate a variable list.
\section*{\tt \htmlref{vlistInqTaxis}{vlistInqTaxis}}
\begin{verbatim}
INTEGER FUNCTION vlistInqTaxis (INTEGER vlistID)
\end{verbatim}
Get the time axis of a variable list.
\section*{\tt \htmlref{vlistInqVarCode}{vlistInqVarCode}}
\begin{verbatim}
INTEGER FUNCTION vlistInqVarCode (INTEGER vlistID, INTEGER varID)
\end{verbatim}
Get the code number of a Variable.
\section*{\tt \htmlref{vlistInqVarDatatype}{vlistInqVarDatatype}}
\begin{verbatim}
INTEGER FUNCTION vlistInqVarDatatype (INTEGER vlistID, INTEGER varID)
\end{verbatim}
Get the data type of a Variable.
\section*{\tt \htmlref{vlistInqVarLongname}{vlistInqVarLongname}}
\begin{verbatim}
SUBROUTINE vlistInqVarLongname (INTEGER vlistID, INTEGER varID,
CHARACTER*(*) longname)
\end{verbatim}
Get the long name of a Variable.
\section*{\tt \htmlref{vlistInqVarMissval}{vlistInqVarMissval}}
\begin{verbatim}
DOUBLEPRECISION FUNCTION vlistInqVarMissval (INTEGER vlistID, INTEGER varID)
\end{verbatim}
Get the missing value of a Variable.
\section*{\tt \htmlref{vlistInqVarName}{vlistInqVarName}}
\begin{verbatim}
SUBROUTINE vlistInqVarName (INTEGER vlistID, INTEGER varID, CHARACTER*(*) name)
\end{verbatim}
Get the name of a Variable.
\section*{\tt \htmlref{vlistInqVarUnits}{vlistInqVarUnits}}
\begin{verbatim}
SUBROUTINE vlistInqVarUnits (INTEGER vlistID, INTEGER varID, CHARACTER*(*) units)
\end{verbatim}
Get the units of a Variable.
\section*{\tt \htmlref{vlistMerge}{vlistMerge}}
\begin{verbatim}
......
......@@ -129,7 +129,7 @@ The function {\tt taxisDefVdate} defines the reference time of a Time axis.
\item[{\tt taxisID}]
Time axis ID, from a previous call to {\htmlref{\tt taxisCreate}{taxisCreate}}
\item[{\tt rtime}]
Reference time (HHMM)
Reference time (hhmm)
\end{deflist}
\end{minipage}
......@@ -227,7 +227,7 @@ The function {\tt taxisDefVtime} defines the verification time of a Time axis.
\item[{\tt taxisID}]
Time axis ID, from a previous call to {\htmlref{\tt taxisCreate}{taxisCreate}}
\item[{\tt vtime}]
Verification time (HHMM)
Verification time (hhmm)
\end{deflist}
\end{minipage}
......
......@@ -350,8 +350,8 @@ Variable list ID, from a previous call to {\htmlref{\tt vlistCreate}{vlistCreate
Variable identifier
\item[{\tt datatype}]
The data type identifier.
The valid {\CDI} data types are {\tt DATATYPE\_PACK1}, {\tt DATATYPE\_PACK2},
{\tt DATATYPE\_PACK3}, {\tt DATATYPE\_REAL4} and {\tt DATATYPE\_REAL8}.
The valid {\CDI} data types are {\tt DATATYPE\_PACK8}, {\tt DATATYPE\_PACK16},
{\tt DATATYPE\_PACK24}, {\tt DATATYPE\_FLT32} and {\tt DATATYPE\_FLT64}.
\end{deflist}
......@@ -383,8 +383,8 @@ Variable identifier
\subsubsection*{Result}
{\tt vlistInqVarDatatype} returns an identifier to the data type of the variable.
The valid {\CDI} data types are {\tt DATATYPE\_PACK1}, {\tt DATATYPE\_PACK2}, {\tt DATATYPE\_PACK3},
{\tt DATATYPE\_REAL4} and {\tt DATATYPE\_REAL8}.
The valid {\CDI} data types are {\tt DATATYPE\_PACK8}, {\tt DATATYPE\_PACK16}, {\tt DATATYPE\_PACK24},
{\tt DATATYPE\_FLT32} and {\tt DATATYPE\_FLT64}.
......
......@@ -32,7 +32,7 @@ int DefaultDataType = CDI_UNDEFID;
static void version(void)
{
fprintf(stderr, "CDI version 1.5.1\n");
fprintf(stderr, "CDI version 1.6.0\n");
cdiPrintVersion();
fprintf(stderr, "\n");
/*
......@@ -46,6 +46,7 @@ static void version(void)
1.4.3 11 Apr 2005 : change date and time format to ISO
1.5.0 22 Nov 2005 : IEG support
1.5.1 21 Feb 2006 : add option -s for short info
1.6.0 1 Aug 2006 : add option -z szip for SZIP compression of GRIB records
*/
}
......@@ -617,7 +618,7 @@ static void setDefaultDataType(char *datatypestr)
level = atoi(datatypestr);
datatypestr++;
}
cdiDefCompress(level);
cdiDefCompress(COMPRESS_GZIP, level);
}
}
......@@ -672,6 +673,20 @@ int handle_error(int cdiErrno, const char *fmt, ...)
}
void defineCompress(const char *arg)
{
size_t len = strlen(arg);
if ( strncmp(arg, "szip", len) == 0 )
cdiDefCompress(COMPRESS_SZIP, 0);
else if ( strncmp(arg, "gzip", len) == 0 )
cdiDefCompress(COMPRESS_GZIP, 6);
else
fprintf(stderr, "Compression %s unsupported!\n", arg);
}
int main(int argc, char *argv[])
{
int c;
......@@ -695,7 +710,7 @@ int main(int argc, char *argv[])
if (Progname == 0) Progname = argv[0];
else Progname++;
while ( (c = getopt(argc, argv, "f:t:w:cdhlmqrsvVz")) != EOF )
while ( (c = getopt(argc, argv, "f:t:w:z:cdhlmqrsvVZ")) != EOF )
{
switch (c)
{
......@@ -732,8 +747,11 @@ int main(int argc, char *argv[])
case 'w':
wTable = optarg;
break;
case 'Z':
cdiDefCompress(COMPRESS_GZIP, 6);
break;
case 'z':
cdiDefCompress(6);
defineCompress(optarg);
break;
case 'h':
usage();
......
......@@ -31,6 +31,12 @@ extern "C" {
#define FILETYPE_H5 7 /* File type HDF5 */
#define FILETYPE_IEG 8 /* File type IEG */
/* Compress types */
#define COMPRESS_SZIP 1
#define COMPRESS_GZIP 2
#define COMPRESS_BZIP2 3
/* Data types */
#define DATATYPE_PACK 0
......@@ -140,7 +146,7 @@ void cdiPrintVersion(void);
void cdiDefMissval(double missval);
double cdiInqMissval(void);
int cdiDefGlobal(const char *string, int val);
void cdiDefCompress(int level);
void cdiDefCompress(int type, int level);
/* STREAM control routines */
......
!
! Fortran interface for CDI library version 1.0.0
! Fortran interface for CDI library version 1.0.1
!
INTEGER CDI_UNDEFID
PARAMETER (CDI_UNDEFID = -1)
!
! Byte order
!
INTEGER CDI_BIGENDIAN
PARAMETER (CDI_BIGENDIAN = 0)
INTEGER CDI_LITTLEENDIAN
PARAMETER (CDI_LITTLEENDIAN = 1)
!
! Error identifier
!
INTEGER CDI_ESYSTEM
......@@ -37,6 +44,13 @@
INTEGER FILETYPE_IEG
PARAMETER (FILETYPE_IEG = 8)
!
! Compress types
!
INTEGER COMPRESS_SZIP
PARAMETER (COMPRESS_SZIP = 1)
INTEGER COMPRESS_GZIP
PARAMETER (COMPRESS_GZIP = 2)
!
! Data types
!
INTEGER DATATYPE_PACK
......@@ -47,16 +61,74 @@
PARAMETER (DATATYPE_PACK2 = 2)
INTEGER DATATYPE_PACK3
PARAMETER (DATATYPE_PACK3 = 3)
INTEGER DATATYPE_REAL4
PARAMETER (DATATYPE_REAL4 = 4)
INTEGER DATATYPE_REAL8
PARAMETER (DATATYPE_REAL8 = 5)
INTEGER DATATYPE_INT1
PARAMETER (DATATYPE_INT1 = 6)
INTEGER DATATYPE_INT2
PARAMETER (DATATYPE_INT2 = 7)
INTEGER DATATYPE_INT4
PARAMETER (DATATYPE_INT4 = 8)
INTEGER DATATYPE_PACK4
PARAMETER (DATATYPE_PACK4 = 4)
INTEGER DATATYPE_PACK5
PARAMETER (DATATYPE_PACK5 = 5)
INTEGER DATATYPE_PACK6
PARAMETER (DATATYPE_PACK6 = 6)
INTEGER DATATYPE_PACK7
PARAMETER (DATATYPE_PACK7 = 7)
INTEGER DATATYPE_PACK8
PARAMETER (DATATYPE_PACK8 = 8)
INTEGER DATATYPE_PACK9
PARAMETER (DATATYPE_PACK9 = 9)
INTEGER DATATYPE_PACK10
PARAMETER (DATATYPE_PACK10 = 10)
INTEGER DATATYPE_PACK11
PARAMETER (DATATYPE_PACK11 = 11)
INTEGER DATATYPE_PACK12
PARAMETER (DATATYPE_PACK12 = 12)
INTEGER DATATYPE_PACK13
PARAMETER (DATATYPE_PACK13 = 13)
INTEGER DATATYPE_PACK14
PARAMETER (DATATYPE_PACK14 = 14)
INTEGER DATATYPE_PACK15
PARAMETER (DATATYPE_PACK15 = 15)
INTEGER DATATYPE_PACK16
PARAMETER (DATATYPE_PACK16 = 16)
INTEGER DATATYPE_PACK17
PARAMETER (DATATYPE_PACK17 = 17)
INTEGER DATATYPE_PACK18
PARAMETER (DATATYPE_PACK18 = 18)
INTEGER DATATYPE_PACK19
PARAMETER (DATATYPE_PACK19 = 19)
INTEGER DATATYPE_PACK20
PARAMETER (DATATYPE_PACK20 = 20)
INTEGER DATATYPE_PACK21
PARAMETER (DATATYPE_PACK21 = 21)
INTEGER DATATYPE_PACK22
PARAMETER (DATATYPE_PACK22 = 22)
INTEGER DATATYPE_PACK23
PARAMETER (DATATYPE_PACK23 = 23)
INTEGER DATATYPE_PACK24
PARAMETER (DATATYPE_PACK24 = 24)
INTEGER DATATYPE_PACK25
PARAMETER (DATATYPE_PACK25 = 25)
INTEGER DATATYPE_PACK26
PARAMETER (DATATYPE_PACK26 = 26)
INTEGER DATATYPE_PACK27
PARAMETER (DATATYPE_PACK27 = 27)
INTEGER DATATYPE_PACK28
PARAMETER (DATATYPE_PACK28 = 28)
INTEGER DATATYPE_PACK29
PARAMETER (DATATYPE_PACK29 = 29)
INTEGER DATATYPE_PACK30
PARAMETER (DATATYPE_PACK30 = 30)
INTEGER DATATYPE_PACK31
PARAMETER (DATATYPE_PACK31 = 31)
INTEGER DATATYPE_PACK32
PARAMETER (DATATYPE_PACK32 = 32)
INTEGER DATATYPE_FLT32
PARAMETER (DATATYPE_FLT32 = 132)
INTEGER DATATYPE_FLT64
PARAMETER (DATATYPE_FLT64 = 164)
INTEGER DATATYPE_INT8
PARAMETER (DATATYPE_INT8 = 208)
INTEGER DATATYPE_INT16
PARAMETER (DATATYPE_INT16 = 216)
INTEGER DATATYPE_INT32
PARAMETER (DATATYPE_INT32 = 232)
!
! GRID types
!
......@@ -179,7 +251,8 @@
EXTERNAL cdiDefGlobal
! cdiDefCompress
! (INTEGER level)
! (INTEGER type,
! INTEGER level)
EXTERNAL cdiDefCompress
!
......
......@@ -13,12 +13,18 @@
#endif
/* Byte order */
/* Error identifier */
/* File types */
/* Compress types */
/* Data types */
......@@ -49,7 +55,7 @@ FCALLSCSUB0 (cdiPrintVersion, CDIPRINTVERSION, cdiprintversion)
FCALLSCSUB1 (cdiDefMissval, CDIDEFMISSVAL, cdidefmissval, DOUBLE)
FCALLSCFUN0 (DOUBLE, cdiInqMissval, CDIINQMISSVAL, cdiinqmissval)
FCALLSCFUN2 (INT, cdiDefGlobal, CDIDEFGLOBAL, cdidefglobal, STRING, INT)
FCALLSCSUB1 (cdiDefCompress, CDIDEFCOMPRESS, cdidefcompress, INT)
FCALLSCSUB2 (cdiDefCompress, CDIDEFCOMPRESS, cdidefcompress, INT, INT)
/* STREAM control routines */
......
/* Generated automatically from m214003 on Mon Jul 31 09:47:39 CEST 2006 */
/* Generated automatically from m214003 on Tue Aug 1 14:58:09 CEST 2006 */
#if defined (HAVE_CONFIG_H)
# include "config.h"
......@@ -7756,6 +7756,8 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
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",
......@@ -7768,7 +7770,7 @@ int gribZip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbufs
#else
if ( libszwarn )
{
Warning(func, "Compression disabled, szlib not available!");
Warning(func, "Decompression disabled, szlib not available!");
libszwarn = 0;
}
#endif
......@@ -7946,7 +7948,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 31 2006"" ""09:47:39";
static const char grb_libvers[] = "1.0.1" " of ""Aug 1 2006"" ""14:58:09";
......
......@@ -2224,6 +2224,7 @@ int grbWriteRecord(int streamID, const double *data, int nmiss)
int varID;
int datatype;
int vlistID;
size_t nbytes;
streamCheckID(func, streamID);
......@@ -2298,10 +2299,27 @@ int grbWriteRecord(int streamID, const double *data, int nmiss)
gribExDP(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, (double*) data,
datasize, (int *) gribbuffer, gribsize, &iword, "C", &iret);
if ( iret ) Error(func, "Problem during GRIB encode (errno = %d)!", iret);;
if ( iret ) Error(func, "Problem during GRIB encode (errno = %d)!", iret);
nbytes = iword*sizeof(int);
if ( streams[streamID].compressType == COMPRESS_SZIP )
{
unsigned char *buffer;
size_t buffersize;
buffersize = gribbuffersize;
buffer = (unsigned char *) malloc(buffersize);
memcpy(buffer, gribbuffer, gribbuffersize);
nbytes = gribZip(gribbuffer, (long) gribbuffersize, buffer, (long) buffersize);
free(buffer);
}
/* gribPrintSec2DP(isec0, isec2, fsec2); */
status = gribWrite(fileID, gribbuffer, iword*sizeof(int));
status = gribWrite(fileID, gribbuffer, nbytes);
if ( gribbuffer ) free(gribbuffer);
......
......@@ -1980,6 +1980,7 @@ int hdfDefVar(int streamID, int varID)
int tablenum;
hsize_t cdims[9];
int plistid;
int compressType;
int compressLevel;
int vlistID;
......@@ -2079,8 +2080,9 @@ int hdfDefVar(int streamID, int varID)
plistid = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_chunk(plistid, ndims, cdims);