Commit bb971e1e authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added support to encode/decode GRIB1 with GRIB_API

parent 24de3893
2011-01-19 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added support to encode/decode GRIB1 with GRIB_API
2011-01-03 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using CGRIBEX library version 1.4.7
......
......@@ -38,19 +38,27 @@ const char *gribapiLibraryVersion(void)
void gribapiDefHandles(int streamID)
{
stream_t *streamptr = NULL;
stream_t *streamptr;
int vlistID, ngrids, nzaxis, i;
streamptr = stream_to_pointer(streamID);
vlistID = streamInqVlist(streamID);
ngrids = vlistNgrids(vlistID);
nzaxis = vlistNzaxis(vlistID);
#if defined (HAVE_LIBCGRIBEX)
if ( streamptr->filetype == FILETYPE_GRB )
{
}
else
#endif
{
vlistID = streamInqVlist(streamID);
ngrids = vlistNgrids(vlistID);
nzaxis = vlistNzaxis(vlistID);
streamptr->gribHandleNums = ngrids*nzaxis;
streamptr->gribHandle = (void **) malloc(streamptr->gribHandleNums*sizeof(void *));
streamptr->gribHandleNums = ngrids*nzaxis;
streamptr->gribHandle = (void **) malloc(streamptr->gribHandleNums*sizeof(void *));
for ( i = 0; i < streamptr->gribHandleNums; ++i )
streamptr->gribHandle[i] = gribHandleNew();
for ( i = 0; i < streamptr->gribHandleNums; ++i )
streamptr->gribHandle[i] = gribHandleNew();
}
}
......@@ -1996,7 +1996,8 @@ void streamDefVlist(int streamID, int vlistID)
{
cdfDefVars(streamID);
}
else if ( streamptr->filetype == FILETYPE_GRB2 )
else if ( streamptr->filetype == FILETYPE_GRB ||
streamptr->filetype == FILETYPE_GRB2 )
{
gribapiDefHandles(streamID);
}
......
......@@ -69,9 +69,11 @@ int grbDecode(int filetype, unsigned char *gribbuffer, int gribsize, double *dat
{
int status = 0;
#if defined (HAVE_LIBCGRIBEX)
if ( filetype == FILETYPE_GRB )
status = cgribexDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip, missval);
else
#endif
status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip, missval);
return (status);
......@@ -138,11 +140,13 @@ int grbScanTimestep1(int streamID)
streamptr = stream_to_pointer(streamID);
filetype = streamptr->filetype;
#if defined (HAVE_LIBCGRIBEX)
if ( filetype == FILETYPE_GRB )
{
status = cgribexScanTimestep1(streamID);
}
else
#endif
{
status = gribapiScanTimestep1(streamID);
}
......@@ -160,11 +164,13 @@ int grbScanTimestep2(int streamID)
streamptr = stream_to_pointer(streamID);
filetype = streamptr->filetype;
#if defined (HAVE_LIBCGRIBEX)
if ( filetype == FILETYPE_GRB )
{
status = cgribexScanTimestep2(streamID);
}
else
#endif
{
status = gribapiScanTimestep2(streamID);
}
......@@ -182,11 +188,13 @@ int grbScanTimestep(int streamID)
streamptr = stream_to_pointer(streamID);
filetype = streamptr->filetype;
#if defined (HAVE_LIBCGRIBEX)
if ( filetype == FILETYPE_GRB )
{
status = cgribexScanTimestep(streamID);
}
else
#endif
{
status = gribapiScanTimestep(streamID);
}
......@@ -383,6 +391,7 @@ size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID,
{
size_t nbytes;
#if defined (HAVE_LIBCGRIBEX)
if ( filetype == FILETYPE_GRB )
{
nbytes = cgribexEncode(varID, levelID, vlistID, gridID, zaxisID,
......@@ -390,6 +399,7 @@ size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID,
datasize, data, nmiss, gribbuffer, gribbuffersize);
}
else
#endif
{
nbytes = gribapiEncode(varID, levelID, vlistID, gridID, zaxisID,
date, time, tsteptype, numavg,
......@@ -476,7 +486,12 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
gribbuffersize = datasize*4+3000;
gribbuffer = (unsigned char *) malloc(gribbuffersize);
if ( filetype == FILETYPE_GRB2 )
#if defined (HAVE_LIBCGRIBEX)
if ( filetype == FILETYPE_GRB )
{
}
else
#endif
{
int ngrids = vlistNgrids(vlistID);
int ghindex = ngrids*vlistGridIndex(vlistID, gridID) + vlistZaxisIndex(vlistID, zaxisID);
......@@ -488,7 +503,9 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
if ( streamptr->ztype == COMPRESS_JPEG )
{
if ( filetype == FILETYPE_GRB2 )
ljpeg = 1;
{
ljpeg = 1;
}
else
{
if ( ljpeg_warn ) Warning("Jpeg compression of GRIB1 records not available!");
......
......@@ -213,12 +213,19 @@ int gribapiGetTimeUnits(grib_handle *gh)
static
int gribapiTimeIsFC(grib_handle *gh)
{
long editionNumber;
int isFC = TRUE;
long sigofrtime;
GRIB_CHECK(grib_get_long(gh, "significanceOfReferenceTime", &sigofrtime), 0);
GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0);
if ( editionNumber == 2 )
{
long sigofrtime;
GRIB_CHECK(grib_get_long(gh, "significanceOfReferenceTime", &sigofrtime), 0);
if ( sigofrtime == 3 ) isFC = FALSE;
if ( sigofrtime == 3 ) isFC = FALSE;
}
return (isFC);
}
......@@ -264,9 +271,16 @@ int gribapiGetTsteptype(grib_handle *gh)
void gribapiGetValidityDateTime(grib_handle *gh, int *vdate, int *vtime)
{
long lpar;
long sigofrtime;
long sigofrtime = 3;
long editionNumber;
GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0);
if ( editionNumber == 2 )
{
GRIB_CHECK(grib_get_long(gh, "significanceOfReferenceTime", &sigofrtime), 0);
}
GRIB_CHECK(grib_get_long(gh, "significanceOfReferenceTime", &sigofrtime), 0);
if ( sigofrtime == 3 )
{
GRIB_CHECK(grib_get_long(gh, "dataDate", &lpar), 0);
......@@ -402,6 +416,7 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh,
{
if ( grid.xsize > 1 )
{
if ( (grid.xfirst > grid.xlast) && (grid.xfirst >= 180) ) grid.xfirst -= 360;
/*
if ( ISEC2_ResFlag && ISEC2_LonIncr > 0 )
grid.xinc = ISEC2_LonIncr;
......
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