Commit 9c96cf72 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added support for cosmo GRIB parameter tables

parent c5b0dbbc
2010-01-07 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
2010-01-07 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using CGRIBEX library version 1.4.2 (large record support)
2010-01-13 Oliver Fuhrer <oliver.fuhrer@meteoswiss.ch>
* added support for cosmo GRIB parameter tables
* added missing value support for cosmo GRIB files
2009-12-29 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using EXSE library version 1.2.0
......
......@@ -78,7 +78,7 @@
#define ISEC1_DecScaleFactor (isec1[22]) /* Decimal scale factor */
#define ISEC1_LocalFLag (isec1[23]) /* Flag field to indicate local use in isec1 */
#define ISEC1_ECMWF_LocalExtention (isec1[36])
#define ISEC1_ECMWF_LocalExtension (isec1[36])
#define ISEC1_ECMWF_Class (isec1[37])
......
/* Automatically generated by m214003 at 2010-01-12, do not edit */
/* Automatically generated by m214003 at 2010-01-13, do not edit */
/* CGRIBEXLIB_VERSION="1.4.2" */
......@@ -2864,6 +2864,7 @@ void encodeES(GRIBPACK *lGrib, long *gribLen, long bdsstart)
#define DWD_extension_253_len 37
#define DWD_extension_254_len 26
#define ECMWF_extension_1_len 24
#define MCH_extension_254_len 19
static
long getLocalExtLen(int *isec1)
......@@ -2874,21 +2875,16 @@ long getLocalExtLen(int *isec1)
{
if ( ISEC1_CenterID == 78 )
{
if ( isec1[36] == 254 )
{
extlen = DWD_extension_254_len;
}
else if ( isec1[36] == 253 )
{
extlen = DWD_extension_253_len;
}
if ( isec1[36] == 254 ) extlen = DWD_extension_254_len;
else if ( isec1[36] == 253 ) extlen = DWD_extension_253_len;
}
else if ( ISEC1_CenterID == 98 )
{
if ( isec1[36] == 1 )
{
extlen = ECMWF_extension_1_len;
}
if ( isec1[36] == 1 ) extlen = ECMWF_extension_1_len;
}
else if ( ISEC1_CenterID == 215 )
{
if ( isec1[36] == 254 ) extlen = MCH_extension_254_len;
}
}
......@@ -3059,7 +3055,8 @@ void encodePDS(GRIBPACK *lpds, long pdsLen, int *isec1)
Put1Byte(ISEC1_TimePeriod1);
Put1Byte(0);
}
else if ( ISEC1_TimeRange == 4 || ISEC1_TimeRange == 2 )
else if ( ISEC1_TimeRange == 5 || ISEC1_TimeRange == 4 ||
ISEC1_TimeRange == 3 || ISEC1_TimeRange == 2 )
{
Put1Byte(0);
Put1Byte(ISEC1_TimePeriod2);
......@@ -9139,7 +9136,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
return (gribLen);
}
static const char grb_libvers[] = "1.4.2" " of ""Jan 12 2010"" ""14:20:20";
static const char grb_libvers[] = "1.4.2" " of ""Jan 13 2010"" ""10:15:04";
const char *
cgribexLibraryVersion(void)
{
......
......@@ -11,6 +11,7 @@
int ECMWF = UNDEFID;
int MPIMET = UNDEFID;
int MCH = UNDEFID;
typedef struct
{
......@@ -287,6 +288,7 @@ void institutsDefault(void)
(void) institutDef( 98, 255, "MPIMET", "Max-Planck-Institute for Meteorology");
(void) institutDef( 98, 232, "MPIMET", "Max-Planck Institute for Meteorology");
(void) institutDef( 78, 255, "DWD", "Deutscher Wetterdienst");
MCH = institutDef(215, 255, "MCH", "MeteoSwiss");
(void) institutDef( 7, 0, "NCEP", "National Centers for Environmental Prediction");
(void) institutDef( 7, 1, "NCEP", "National Centers for Environmental Prediction");
(void) institutDef( 60, 0, "NCAR", "National Center for Atmospheric Research");
......
......@@ -11,6 +11,7 @@
int ECHAM4 = UNDEFID;
int ECHAM5 = UNDEFID;
int COSMO = UNDEFID;
typedef struct
{
......@@ -225,6 +226,9 @@ static void model_defaults(void)
instID = institutInq( 0, 0, "DWD", NULL);
(void) modelDef(instID, 149, "GME");
instID = institutInq( 0, 0, "MCH", NULL);
COSMO = modelDef(instID, 255, "COSMO");
instID = institutInq( 0, 1, "NCEP", NULL);
(void) modelDef(instID, 80, "T62L28MRF");
}
......
......@@ -1256,7 +1256,7 @@ int cgribexScanTimestep(int streamID)
int cgribexDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
int unreduced, int *nmiss, int *zip)
int unreduced, int *nmiss, int *zip, double *missval)
{
static char func[] = "cgribexDecode";
int status = 0;
......@@ -1274,6 +1274,7 @@ int cgribexDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
else strcpy(hoper, "D");
FSEC3_MissVal = cdiDefaultMissval;
*missval = cdiDefaultMissval;
if ( (izip = gribGetZip(gribsize, gribbuffer, &unzipsize)) > 0 )
{
......@@ -1320,6 +1321,37 @@ int cgribexDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
*nmiss = ISEC4_NumValues - ISEC4_NumNonMissValues;
else
*nmiss = 0;
/* 2010-01-13: Oliver Fuhrer */
if (ISEC1_CenterID == 215 ) {
int i;
double undef_pds, undef_eps;
if (isec1[34] != 0 && isec1[34] != 255) {
if (isec1[34] & 2) {
if (isec1[34] & 1) {
undef_pds = -0.99*pow(10.0,-isec1[35]);
} else {
undef_pds = +0.99*pow(10.0,-isec1[35]);
}
undef_eps = pow(10.0,-isec1[35]-1);
} else {
if (isec1[34] & 1) {
undef_pds = -0.99*pow(10.0,+isec1[35]);
} else {
undef_pds = +0.99*pow(10.0,+isec1[35]);
}
undef_eps = pow(10.0,isec1[35]-1);
}
for ( i = 0; i < gridsize; i++ )
if ( (abs(data[i]-undef_pds) < undef_eps) || IS_EQUAL(data[i],FSEC3_MissVal) ) {
data[i] = undef_pds;
(*nmiss)++;
}
FSEC3_MissVal = undef_pds;
*missval = undef_pds;
}
}
#else
Error(func, "CGRIBEX support not compiled in!");
#endif
......
......@@ -67,19 +67,15 @@ int grbDefRecord(int streamID)
static
int grbDecode(int filetype, unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
int unreduced, int *nmiss, int *zip)
int unreduced, int *nmiss, int *zip, double *missval)
{
//static char func[] = "grbDecode";
int status = 0;
if ( filetype == FILETYPE_GRB )
{
status = cgribexDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip);
}
status = cgribexDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip, missval);
else
{
status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip);
}
status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip, missval);
return (status);
}
......@@ -98,6 +94,7 @@ int grbReadRecord(int streamID, double *data, int *nmiss)
int vlistID;
int zip;
int filetype;
double missval;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
......@@ -126,7 +123,9 @@ int grbReadRecord(int streamID, double *data, int *nmiss)
fileRead(fileID, gribbuffer, (size_t) recsize);
grbDecode(filetype, gribbuffer, recsize, data, gridsize, streamptr->unreduced, nmiss, &zip);
grbDecode(filetype, gribbuffer, recsize, data, gridsize, streamptr->unreduced, nmiss, &zip, &missval);
if ( nmiss > 0 ) vlistDefVarMissval(vlistID, varID, missval);
streamptr->tsteps[tsID].records[recID].zip = zip;
......@@ -276,6 +275,7 @@ void grbReadVarDP(int streamID, int varID, double *data, int *nmiss)
int vlistID;
int zip;
int filetype;
double missval;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
......@@ -310,7 +310,10 @@ void grbReadVarDP(int streamID, int varID, double *data, int *nmiss)
fileRead(fileID, gribbuffer, recsize);
grbDecode(filetype, gribbuffer, recsize, &data[levelID*gridsize], gridsize, streamptr->unreduced, &imiss, &zip);
grbDecode(filetype, gribbuffer, recsize, &data[levelID*gridsize], gridsize,
streamptr->unreduced, &imiss, &zip, &missval);
if ( imiss > 0 ) vlistDefVarMissval(vlistID, varID, missval);
*nmiss += imiss;
......@@ -333,6 +336,7 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *
int vlistID;
int zip;
int filetype;
double missval;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
......@@ -367,7 +371,9 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *
fileRead(fileID, gribbuffer, recsize);
grbDecode(filetype, gribbuffer, recsize, data, gridsize, streamptr->unreduced, nmiss, &zip);
grbDecode(filetype, gribbuffer, recsize, data, gridsize, streamptr->unreduced, nmiss, &zip, &missval);
if ( nmiss > 0 ) vlistDefVarMissval(vlistID, varID, missval);
fileSetPos(fileID, currentfilepos, SEEK_SET);
......
......@@ -1521,7 +1521,7 @@ int gribapiScanTimestep(int streamID)
int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
int unreduced, int *nmiss, int *zip)
int unreduced, int *nmiss, int *zip, double *missval)
{
static char func[] = "gribapiDecode";
int status = 0;
......@@ -1545,6 +1545,7 @@ int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
recsize = gribsize;
gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize);
GRIB_CHECK(grib_set_double(gh, "missingValue", GRIB_MISSVAL), 0);
*missval = GRIB_MISSVAL;
GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 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