Commit 12c66c4b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added GRIB2 support (testversion) via grib_api(1.8.0)

parent 5db17b1f
...@@ -36,11 +36,10 @@ typedef struct { ...@@ -36,11 +36,10 @@ typedef struct {
#if defined (HAVE_LIBGRIB_API) #if defined (HAVE_LIBGRIB_API)
static static
int gribapiGetGridType(grib_handle *gh) int gribapiGetGridType(grib_handle *gh, int gribgridtype)
{ {
/* static char func[] = "gribapiGetGridType"; */ /* static char func[] = "gribapiGetGridType"; */
int gridtype = 0; int gridtype = 0;
int gribgridtype;
long lpar; long lpar;
GRIB_CHECK(grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar), 0); GRIB_CHECK(grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar), 0);
...@@ -90,6 +89,21 @@ int gribapiGetGridType(grib_handle *gh) ...@@ -90,6 +89,21 @@ int gribapiGetGridType(grib_handle *gh)
} }
#endif #endif
static
int gribapiGetIsRotated(int gribgridtype)
{
/* static char func[] = "cgribexGetIsRotated"; */
int isRotated = 0;
if ( gribgridtype == GRIBAPI_GTYPE_LATLON_ROT )
{
isRotated = 1;
}
return (isRotated);
}
#if defined (HAVE_LIBGRIB_API) #if defined (HAVE_LIBGRIB_API)
static static
int gribapiGetZaxisType(int grb_ltype) int gribapiGetZaxisType(int grb_ltype)
...@@ -167,6 +181,7 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh, ...@@ -167,6 +181,7 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh,
long recsize, off_t position, int prec, int ztype) long recsize, off_t position, int prec, int ztype)
{ {
static char func[] = "gribapiAddRecord"; static char func[] = "gribapiAddRecord";
int gribgridtype;
int gridtype; int gridtype;
int zaxistype; int zaxistype;
int gridID = CDI_UNDEFID, varID; int gridID = CDI_UNDEFID, varID;
...@@ -235,7 +250,9 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh, ...@@ -235,7 +250,9 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh,
(*record).ilevel2 = level2; (*record).ilevel2 = level2;
(*record).ltype = leveltype; (*record).ltype = leveltype;
gridtype = gribapiGetGridType(gh); GRIB_CHECK(grib_get_long(gh, "gridDefinitionTemplateNumber", &lpar), 0);
gribgridtype = (int) lpar;
gridtype = gribapiGetGridType(gh, gribgridtype);
/* /*
if ( streamptr->unreduced && gridtype == GRID_GAUSSIAN_REDUCED ) if ( streamptr->unreduced && gridtype == GRID_GAUSSIAN_REDUCED )
{ {
...@@ -398,14 +415,28 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh, ...@@ -398,14 +415,28 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh,
grid.ni3 = ISEC2_GME_NI3; grid.ni3 = ISEC2_GME_NI3;
break; break;
} }
*/
case GRID_GENERIC: case GRID_GENERIC:
{ {
grid.size = ISEC4_NumValues; int nlon = 0, nlat = 0;
grid.xsize = 0;
grid.ysize = 0; if ( grib_get_long(gh, "Ni", &lpar) == 0 ) nlon = lpar;
if ( grib_get_long(gh, "Nj", &lpar) == 0 ) nlat = lpar;
grid.size = numberOfPoints;
if ( nlon && nlat )
{
grid.xsize = nlon;
grid.ysize = nlat;
}
else
{
grid.xsize = 0;
grid.ysize = 0;
}
break; break;
} }
*/
default: default:
{ {
Error(func, "%s grid unsupported!", gridNamePtr(gridtype)); Error(func, "%s grid unsupported!", gridNamePtr(gridtype));
...@@ -414,15 +445,17 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh, ...@@ -414,15 +445,17 @@ void gribapiAddRecord(int streamID, int code, grib_handle *gh,
} }
grid.isRotated = FALSE; grid.isRotated = FALSE;
/* if ( gribapiGetIsRotated(gribgridtype) )
if ( cgribexGetIsRotated(isec2) )
{ {
grid.isRotated = TRUE; grid.isRotated = TRUE;
grid.ypole = - ISEC2_LatSP * 0.001; GRIB_CHECK(grib_get_double(gh, "latitudeOfSouthernPoleInDegrees", &grid.ypole), 0);
grid.xpole = ISEC2_LonSP * 0.001 - 180; GRIB_CHECK(grib_get_double(gh, "longitudeOfSouthernPoleInDegrees", &grid.xpole), 0);
grid.angle = 0; GRIB_CHECK(grib_get_double(gh, "angleOfRotation", &grid.angle), 0);
/* change from south to north pole */
grid.ypole = -grid.ypole;
grid.xpole = grid.xpole - 180;
} }
*/
grid.xvals = NULL; grid.xvals = NULL;
grid.yvals = NULL; grid.yvals = NULL;
grid.type = gridtype; grid.type = gridtype;
...@@ -1750,13 +1783,20 @@ void gribapiDefGrid(grib_handle *gh, int gridID) ...@@ -1750,13 +1783,20 @@ void gribapiDefGrid(grib_handle *gh, int gridID)
ISEC2_ResFlag = 0; ISEC2_ResFlag = 0;
else else
ISEC2_ResFlag = 128; ISEC2_ResFlag = 128;
*/
if ( gridIsRotated(gridID) ) if ( gridIsRotated(gridID) )
{ {
ISEC2_LatSP = - NINT(gridInqYpole(gridID) * 1000); double xpole, ypole, angle;
ISEC2_LonSP = NINT((gridInqXpole(gridID) + 180) * 1000); xpole = gridInqXpole(gridID);
ypole = gridInqYpole(gridID);
angle = gridInqAngle(gridID);
/* change from noth to south pole */
ypole = -ypole;
xpole = xpole + 180;
GRIB_CHECK(grib_set_double(gh, "latitudeOfSouthernPoleInDegrees", ypole), 0);
GRIB_CHECK(grib_set_double(gh, "longitudeOfSouthernPoleInDegrees", xpole), 0);
GRIB_CHECK(grib_set_double(gh, "angleOfRotation", angle), 0);
} }
*/
/* East -> West */ /* East -> West */
//if ( ISEC2_LastLon < ISEC2_FirstLon ) ISEC2_ScanFlag += 128; //if ( ISEC2_LastLon < ISEC2_FirstLon ) ISEC2_ScanFlag += 128;
...@@ -2048,7 +2088,11 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI ...@@ -2048,7 +2088,11 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
gribapiDefGrid(gh, gridID); gribapiDefGrid(gh, gridID);
gribapiDefLevel(gh, code, zaxisID, levelID); gribapiDefLevel(gh, code, zaxisID, levelID);
// GRIB_CHECK(grib_set_double(gh, "missingValue", GRIB_MISSVAL), 0); if ( nmiss > 0 )
{
GRIB_CHECK(grib_set_long(gh, "bitmapPresent", 1), 0);
GRIB_CHECK(grib_set_double(gh, "missingValue", vlistInqVarMissval(vlistID, varID)), 0);
}
bitsPerValue = grbBitsPerValue(datatype); bitsPerValue = grbBitsPerValue(datatype);
GRIB_CHECK(grib_set_long(gh, "bitsPerValue", bitsPerValue), 0); GRIB_CHECK(grib_set_long(gh, "bitsPerValue", bitsPerValue), 0);
......
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