Commit 3501f865 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Change cdiDefCompress to streamDefZtype/streamDefZlevel

parent e6628039
......@@ -5,6 +5,7 @@
* new attribute routines: vlistInqNatts, vlistDefAttr and vlistInqAttr
for Int, Flt and Txt
* Add support for Lambert grids [request: Patrick Samuelsson]
* Change cdiDefCompress to streamDefZtype/streamDefZlevel
* Version 1.1.0 released
2007-10-22 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
......
......@@ -29,13 +29,17 @@ extern int optind, opterr, optopt;
char *Progname;
int DefaultFileType = CDI_UNDEFID;
int DefaultDataType = CDI_UNDEFID;
int DefaultFileType = CDI_UNDEFID;
int DefaultDataType = CDI_UNDEFID;
int DefaultByteorder = CDI_UNDEFID;
int Ztype = COMPRESS_NONE;
int Zlevel = 0;
static void version(void)
{
fprintf(stderr, "CDI version 1.6.1\n");
fprintf(stderr, "CDI version 1.6.2\n");
cdiPrintVersion();
fprintf(stderr, "\n");
/*
......@@ -51,6 +55,7 @@ static void version(void)
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
1.6.1 27 Feb 2007 : short info with ltype for GENERIC zaxis
1.6.2 3 Jan 2008 : changes for CDI library version 1.1.0 (compress)
*/
}
......@@ -74,6 +79,7 @@ static void usage(void)
fprintf(stderr, "\n");
fprintf(stderr, " -V Print version number\n");
fprintf(stderr, " -z szip Compress GRIB records with szip\n");
fprintf(stderr, "\n");
fprintf(stderr, " Report bugs to <Uwe.Schulzweida@zmaw.de>\n");
}
......@@ -152,9 +158,6 @@ static void printInfo(int gridtype, int date, int time, int code, double level,
}
#define CDI_BIGENDIAN 0 /* Data type BIGENDIAN */
#define CDI_LITTLEENDIAN 1 /* Data type LITTLEENDIAN */
void printFiletype(int streamID, int vlistID)
{
int filetype;
......@@ -644,38 +647,50 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
}
#undef IsBigendian
#define IsBigendian() ( u_byteorder.c[sizeof(long) - 1] )
static void setDefaultDataType(char *datatypestr)
{
static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1};
int datatype = -1;
if ( isdigit((int) *datatypestr) )
{
datatype = atoi(datatypestr);
datatypestr++;
if ( datatype < 10 )
datatypestr += 1;
else
datatypestr += 2;
if ( datatype == 1 ) DefaultDataType = DATATYPE_PACK8;
else if ( datatype == 2 ) DefaultDataType = DATATYPE_PACK16;
else if ( datatype == 3 ) DefaultDataType = DATATYPE_PACK24;
else if ( datatype == 4 ) DefaultDataType = DATATYPE_FLT32;
else if ( datatype == 8 ) DefaultDataType = DATATYPE_FLT64;
if ( datatype > 0 && datatype < 32 ) DefaultDataType = datatype;
else if ( datatype == 32 )
{
if ( DefaultFileType == FILETYPE_GRB )
DefaultDataType = DATATYPE_PACK32;
else
DefaultDataType = DATATYPE_FLT32;
}
else if ( datatype == 64 ) DefaultDataType = DATATYPE_FLT64;
else
{
fprintf(stderr, "Unsupported datatype %d!\n", datatype);
fprintf(stderr, "Use 4/8 for filetype nc, srv, ext, ieg and 1/2/3 for grb.\n");
exit(-1);
fprintf(stderr, "Use 32/64 for filetype nc, srv, ext, ieg and 1-32 for grb.\n");
exit(EXIT_FAILURE);
}
}
if ( *datatypestr == 'z' || *datatypestr == 'Z' )
if ( *datatypestr == 'l' || *datatypestr == 'L' )
{
int level = 6;
if ( IsBigendian() ) DefaultByteorder = CDI_LITTLEENDIAN;
datatypestr++;
}
if ( *datatypestr == 'b' || *datatypestr == 'B' )
{
if ( ! IsBigendian() ) DefaultByteorder = CDI_BIGENDIAN;
datatypestr++;
if ( isdigit((int) *datatypestr) )
{
level = atoi(datatypestr);
datatypestr++;
}
cdiDefCompress(COMPRESS_GZIP, level);
}
}
......@@ -743,9 +758,14 @@ void defineCompress(const char *arg)
size_t len = strlen(arg);
if ( strncmp(arg, "szip", len) == 0 )
cdiDefCompress(COMPRESS_SZIP, 0);
{
Ztype = COMPRESS_SZIP;
}
else if ( strncmp(arg, "gzip", len) == 0 )
cdiDefCompress(COMPRESS_GZIP, 6);
{
Ztype = COMPRESS_GZIP;
Zlevel = 6;
}
else
fprintf(stderr, "Compression %s unsupported!\n", arg);
}
......@@ -812,9 +832,6 @@ int main(int argc, char *argv[])
case 'w':
wTable = optarg;
break;
case 'Z':
cdiDefCompress(COMPRESS_GZIP, 6);
break;
case 'z':
defineCompress(optarg);
break;
......@@ -919,6 +936,15 @@ int main(int argc, char *argv[])
if ( streamID2 < 0 )
return (handle_error(streamID2, "Open failed on %s", fname2));
if ( DefaultByteorder != CDI_UNDEFID )
streamDefByteorder(streamID2, DefaultByteorder);
if ( Ztype != COMPRESS_NONE )
{
streamDefZtype(streamID2, Ztype);
streamDefZlevel(streamID2, Zlevel);
}
streamDefVlist(streamID2, vlistID2);
if ( otableID == CDI_UNDEFID ) otableID = itableID;
......
......@@ -373,6 +373,24 @@ Define time step.
Define the Vlist for a stream.
\section*{\tt \htmlref{streamDefZlevel}{streamDefZlevel}}
\begin{verbatim}
void streamDefZlevel (intstreamID, intzlevel);
\end{verbatim}
Define compression level.
\section*{\tt \htmlref{streamDefZtype}{streamDefZtype}}
\begin{verbatim}
void streamDefZtype (intstreamID, intztype);
\end{verbatim}
Define compression type.
\section*{\tt \htmlref{streamInqByteorder}{streamInqByteorder}}
\begin{verbatim}
......@@ -409,6 +427,24 @@ Get time step.
Get the Vlist of a stream.
\section*{\tt \htmlref{streamInqZlevel}{streamInqZlevel}}
\begin{verbatim}
int streamInqZlevel (intstreamID);
\end{verbatim}
Get compression level.
\section*{\tt \htmlref{streamInqZtype}{streamInqZtype}}
\begin{verbatim}
int streamInqZtype (intstreamID);
\end{verbatim}
Get compression type.
\section*{\tt \htmlref{streamOpenRead}{streamOpenRead}}
\begin{verbatim}
......
......@@ -373,6 +373,24 @@ Define time step.
Define the Vlist for a stream.
\section*{\tt \htmlref{streamDefZlevel}{streamDefZlevel}}
\begin{verbatim}
SUBROUTINE streamDefZlevel (INTEGER streamID, INTEGER zlevel)
\end{verbatim}
Define compression level.
\section*{\tt \htmlref{streamDefZtype}{streamDefZtype}}
\begin{verbatim}
SUBROUTINE streamDefZtype (INTEGER streamID, INTEGER ztype)
\end{verbatim}
Define compression type.
\section*{\tt \htmlref{streamInqByteorder}{streamInqByteorder}}
\begin{verbatim}
......@@ -409,6 +427,24 @@ Get time step.
Get the Vlist of a stream.
\section*{\tt \htmlref{streamInqZlevel}{streamInqZlevel}}
\begin{verbatim}
INTEGER FUNCTION streamInqZlevel (INTEGER streamID)
\end{verbatim}
Get compression level.
\section*{\tt \htmlref{streamInqZtype}{streamInqZtype}}
\begin{verbatim}
INTEGER FUNCTION streamInqZtype (INTEGER streamID)
\end{verbatim}
Get compression type.
\section*{\tt \htmlref{streamOpenRead}{streamOpenRead}}
\begin{verbatim}
......
......@@ -36,6 +36,7 @@ extern "C" {
/* Compress types */
#define COMPRESS_NONE 0
#define COMPRESS_SZIP 1
#define COMPRESS_GZIP 2
#define COMPRESS_BZIP2 3
......@@ -158,7 +159,6 @@ void cdiPrintVersion(void);
void cdiDefMissval(double missval);
double cdiInqMissval(void);
int cdiDefGlobal(const char *string, int val);
void cdiDefCompress(int type, int level);
/* STREAM control routines */
......@@ -188,6 +188,18 @@ void streamDefByteorder(int streamID, int byteorder);
/* streamInqByteorder: Get the byteorder */
int streamInqByteorder(int streamID);
/* streamDefZtype: Define compression type */
void streamDefZtype(int streamID, int ztype);
/* streamDefZlevel: Define compression level */
void streamDefZlevel(int streamID, int zlevel);
/* streamInqZtype: Get compression type */
int streamInqZtype(int streamID);
/* streamInqZlevel: Get compression level */
int streamInqZlevel(int streamID);
/* streamDefTimestep: Define time step */
int streamDefTimestep(int streamID, int tsID);
......
......@@ -48,6 +48,8 @@
!
! Compress types
!
INTEGER COMPRESS_NONE
PARAMETER (COMPRESS_NONE = 0)
INTEGER COMPRESS_SZIP
PARAMETER (COMPRESS_SZIP = 1)
INTEGER COMPRESS_GZIP
......@@ -267,11 +269,6 @@
! INTEGER val)
EXTERNAL cdiDefGlobal
! cdiDefCompress
! (INTEGER type,
! INTEGER level)
EXTERNAL cdiDefCompress
!
! STREAM control routines
!
......@@ -314,6 +311,24 @@
! (INTEGER streamID)
EXTERNAL streamInqByteorder
! streamDefZtype
! (INTEGER streamID,
! INTEGER ztype)
EXTERNAL streamDefZtype
! streamDefZlevel
! (INTEGER streamID,
! INTEGER zlevel)
EXTERNAL streamDefZlevel
INTEGER streamInqZtype
! (INTEGER streamID)
EXTERNAL streamInqZtype
INTEGER streamInqZlevel
! (INTEGER streamID)
EXTERNAL streamInqZlevel
INTEGER streamDefTimestep
! (INTEGER streamID,
! INTEGER tsID)
......
......@@ -58,7 +58,6 @@ FCALLSCSUB0 (cdiPrintVersion, CDIPRINTVERSION, cdiprintversion)
FCALLSCSUB1 (cdiDefMissval, CDIDEFMISSVAL, cdidefmissval, DOUBLE)
FCALLSCFUN0 (DOUBLE, cdiInqMissval, CDIINQMISSVAL, cdiinqmissval)
FCALLSCFUN2 (INT, cdiDefGlobal, CDIDEFGLOBAL, cdidefglobal, STRING, INT)
FCALLSCSUB2 (cdiDefCompress, CDIDEFCOMPRESS, cdidefcompress, INT, INT)
/* STREAM control routines */
......@@ -71,6 +70,10 @@ FCALLSCFUN1 (INT, streamInqVlist, STREAMINQVLIST, streaminqvlist, INT)
FCALLSCFUN1 (INT, streamInqFiletype, STREAMINQFILETYPE, streaminqfiletype, INT)
FCALLSCSUB2 (streamDefByteorder, STREAMDEFBYTEORDER, streamdefbyteorder, INT, INT)
FCALLSCFUN1 (INT, streamInqByteorder, STREAMINQBYTEORDER, streaminqbyteorder, INT)
FCALLSCSUB2 (streamDefZtype, STREAMDEFZTYPE, streamdefztype, INT, INT)
FCALLSCSUB2 (streamDefZlevel, STREAMDEFZLEVEL, streamdefzlevel, INT, INT)
FCALLSCFUN1 (INT, streamInqZtype, STREAMINQZTYPE, streaminqztype, INT)
FCALLSCFUN1 (INT, streamInqZlevel, STREAMINQZLEVEL, streaminqzlevel, INT)
FCALLSCFUN2 (INT, streamDefTimestep, STREAMDEFTIMESTEP, streamdeftimestep, INT, INT)
FCALLSCFUN2 (INT, streamInqTimestep, STREAMINQTIMESTEP, streaminqtimestep, INT, INT)
FCALLSCFUN1 (STRING, streamFilename, STREAMFILENAME, streamfilename, INT)
......
......@@ -1909,3 +1909,59 @@ int streamInqVlist(int streamID)
return (streamptr->vlistID);
}
void streamDefZtype(int streamID, int ztype)
{
static char func[] = "streamDefZtype";
int nvars, varID;
int gridID, zaxisID;
STREAM *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
streamptr->ztype = ztype;
}
void streamDefZlevel(int streamID, int zlevel)
{
static char func[] = "streamDefZlevel";
int nvars, varID;
int gridID, zaxisID;
STREAM *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
streamptr->zlevel = zlevel;
}
int streamInqZtype(int streamID)
{
static char func[] = "streamInqZtype";
STREAM *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
return (streamptr->ztype);
}
int streamInqZlevel(int streamID)
{
static char func[] = "streamInqZlevel";
STREAM *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
return (streamptr->zlevel);
}
......@@ -2290,7 +2290,7 @@ void grbWriteVarDP(int streamID, int varID, const double *data, int nmiss)
nbytes = iword*sizeof(int);
if ( streamptr->compressType == COMPRESS_SZIP )
if ( streamptr->ztype == COMPRESS_SZIP )
{
unsigned char *buffer;
size_t buffersize;
......@@ -2409,7 +2409,7 @@ void grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data
nbytes = iword*sizeof(int);
if ( streamptr->compressType == COMPRESS_SZIP )
if ( streamptr->ztype == COMPRESS_SZIP )
{
unsigned char *buffer;
size_t buffersize;
......@@ -2474,7 +2474,7 @@ int grbCopyRecord(int streamID2, int streamID1)
izip = gribGetZip(recsize, gribbuffer, &unzipsize);
if ( izip == 0 )
if ( streamptr2->compressType == COMPRESS_SZIP )
if ( streamptr2->ztype == COMPRESS_SZIP )
{
unsigned char *buffer;
size_t buffersize;
......@@ -2601,7 +2601,7 @@ int grbWriteRecord(int streamID, const double *data, int nmiss)
nbytes = iword*sizeof(int);
if ( streamptr->compressType == COMPRESS_SZIP )
if ( streamptr->ztype == COMPRESS_SZIP )
{
unsigned char *buffer;
size_t buffersize;
......
......@@ -50,8 +50,6 @@ int CDI_Debug = 0; /* If set to 1, debugging */
int cdiDefaultLeveltype = -1;
static int cdiDataUnreduced = 0;
static int cdiCompressType = 0;
static int cdiCompressLevel = 0;
long cdiGetenvInt(char *envName)
......@@ -318,8 +316,8 @@ static void stream_init_entry(STREAM *streamptr)
streamptr->vct.ilevID = UNDEFID;
streamptr->vct.mlevID = UNDEFID;
streamptr->unreduced = cdiDataUnreduced;
streamptr->compressType = cdiCompressType;
streamptr->compressLevel = cdiCompressLevel;
streamptr->ztype = COMPRESS_NONE;
streamptr->zlevel = 0;
basetimeInit(&streamptr->basetime);
......@@ -439,13 +437,6 @@ int cdiDefGlobal(const char *string, int val)
}
void cdiDefCompress(int type, int level)
{
cdiCompressType = type;
cdiCompressLevel = level;
}
void cdiDefMissval(double missval)
{
cdiInitialize();
......
......@@ -216,8 +216,8 @@ typedef struct {
int localatts;
VCT vct;
int unreduced;
int compressType;
int compressLevel;
int ztype;
int zlevel;
int curfile;
int nfiles;
char **fnames;
......
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