Commit 67dde6e9 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added support for GRIB2 key tablesVersion/localTablesVersion.

parent 61fca261
......@@ -4,6 +4,7 @@
2018-01-04 Uwe Schulzweida
* Added support for GRIB2 key tablesVersion/localTablesVersion
* Added CDI function cdiDefKeyInt()/cdiInqKeyInt()
2017-12-07 Uwe Schulzweida
......
......@@ -574,17 +574,14 @@ void gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh,
if ( ens_index > 0 )
varDefEnsembleInfo(varID, (int)ens_index, (int)ens_count, (int)ens_forecast_type);
/*
long tablesVersion = 0;
if ( grib_get_long(gh, "tablesVersion", &tablesVersion) == 0 )
printf("tablesVersion %ld\n", tablesVersion);
// varDefTablesVersion(varID, (int) tablesVersion);
varDefKeyInt(varID, CDI_KEY_TABLESVERSION, (int) tablesVersion);
long localTablesVersion = 0;
if ( grib_get_long(gh, "localTablesVersion", &localTablesVersion) == 0 )
printf("localTablesVersion %ld\n", localTablesVersion);
//varDefLocalTablesVersion(varID, (int) localTablesVersion);
*/
varDefKeyInt(varID, CDI_KEY_LOCALTABLESVERSION, (int) localTablesVersion);
long typeOfGeneratingProcess = 0;
if ( grib_get_long(gh, "typeOfGeneratingProcess", &typeOfGeneratingProcess) == 0 )
varDefTypeOfGeneratingProcess(varID, (int) typeOfGeneratingProcess);
......@@ -1697,7 +1694,7 @@ int gribapiDefSteptype(int editionNumber, grib_handle *gh, int productDefinition
long proDefTempNum = 0;
const char *stepType;
if (tsteptype >= TSTEP_INSTANT && tsteptype <= TSTEP_RATIO)
if ( tsteptype >= TSTEP_INSTANT && tsteptype <= TSTEP_RATIO )
{
stepType = cdiGribAPI_ts_str_map[tsteptype].sname;
proDefTempNum = cdiGribAPI_ts_str_map[tsteptype].productionTemplate;
......@@ -2354,6 +2351,7 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int zaxisID, int levelI
}
long grib_ltype = (editionNumber <= 1) ? zaxisTypeToGrib1ltype(zaxistype) : zaxisTypeToGrib2ltype(zaxistype);
// long grib_ltype2 = (ltype != ltype2) ? ltype2 : grib_ltype;
switch (zaxistype)
{
......@@ -3022,7 +3020,15 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
if ( editionNumber == 2 )
{
if ( typeOfGeneratingProcess == -1 ) typeOfGeneratingProcess = 0;
if ( ! gc->init ) GRIB_CHECK(my_grib_set_long(gh, "typeOfGeneratingProcess", typeOfGeneratingProcess), 0);
if ( ! gc->init )
{
GRIB_CHECK(my_grib_set_long(gh, "typeOfGeneratingProcess", typeOfGeneratingProcess), 0);
int status, tablesVersion, localTablesVersion;
status = cdiInqKeyInt(vlistID, varID, CDI_KEY_TABLESVERSION, &tablesVersion);
if ( status == 0 ) GRIB_CHECK(my_grib_set_long(gh, "tablesVersion", (long)tablesVersion), 0);
status = cdiInqKeyInt(vlistID, varID, CDI_KEY_LOCALTABLESVERSION, &localTablesVersion);
if ( status == 0 ) GRIB_CHECK(my_grib_set_long(gh, "localTablesVersion", (long)localTablesVersion), 0);
}
}
/*
......
......@@ -82,6 +82,14 @@ typedef struct
/* meta-data for specification of tiles (currently only GRIB-API: */
subtype_t *tiles;
size_t nikeys;
struct ikeyvalue_t
{
int key;
int value;
} ikeyvalue_t;
struct ikeyvalue_t ikeyvalues[MAX_KEYS];
int opt_grib_nentries; /* current no. key-value pairs */
int opt_grib_kvpair_size; /* current allocated size */
opt_key_val_pair_t *opt_grib_kvpair; /* (optional) list of keyword/value pairs */
......@@ -117,6 +125,8 @@ void paramInitEntry(unsigned varID, int param)
vartable[varID].tableID = CDI_UNDEFID;
vartable[varID].typeOfGeneratingProcess = CDI_UNDEFID;
vartable[varID].productDefinitionTemplate = CDI_UNDEFID;
vartable[varID].nikeys = 0;
for ( int i = 0; i < MAX_KEYS; ++i ) vartable[varID].ikeyvalues[i].value = 0;
vartable[varID].comptype = CDI_COMPRESS_NONE;
vartable[varID].complevel = 1;
vartable[varID].lmissval = false;
......@@ -576,6 +586,13 @@ int cmp_varname(const void *s1, const void *s2)
}
void varCopyKeys(int vlistID, int varID)
{
for ( int i = 0; i < vartable[varID].nikeys; ++i )
cdiDefKeyInt(vlistID, varID, vartable[varID].ikeyvalues[i].key, vartable[varID].ikeyvalues[i].value);
}
void cdi_generate_vars(stream_t *streamptr)
{
int vlistID = streamptr->vlistID;
......@@ -769,8 +786,7 @@ void cdi_generate_vars(stream_t *streamptr)
if ( vartable[varid].typeOfGeneratingProcess != CDI_UNDEFID )
vlistDefVarTypeOfGeneratingProcess(vlistID, varID, vartable[varid].typeOfGeneratingProcess);
if ( vartable[varid].productDefinitionTemplate != CDI_UNDEFID )
vlistDefVarProductDefinitionTemplate(vlistID, varID, vartable[varid].productDefinitionTemplate);
varCopyKeys(vlistID, varID);
if ( vartable[varid].lmissval ) vlistDefVarMissval(vlistID, varID, vartable[varid].missval);
if ( vartable[varid].name ) vlistDefVarName(vlistID, varID, vartable[varid].name);
......@@ -1113,6 +1129,18 @@ void varDefProductDefinitionTemplate(int varID, int productDefinitionTemplate)
vartable[varID].productDefinitionTemplate = productDefinitionTemplate;
}
void varDefKeyInt(int varID, int key, int value)
{
if ( vartable[varID].nikeys < MAX_KEYS )
{
vartable[varID].ikeyvalues[vartable[varID].nikeys].key = key;
vartable[varID].ikeyvalues[vartable[varID].nikeys].value = value;
vartable[varID].nikeys++;
}
}
#if defined (HAVE_LIBGRIB_API)
/* Resizes and initializes opt_grib_kvpair data structure. */
static
......
......@@ -33,6 +33,7 @@ void varDefEnsembleInfo(int varID, int ens_idx, int ens_count, int forecast_type
void varDefTypeOfGeneratingProcess(int varID, int typeOfGeneratingProcess);
void varDefProductDefinitionTemplate(int varID, int productDefinitionTemplate);
void varDefKeyInt(int varID, int key, int value);
void varDefOptGribInt(int varID, int tile_index, long lval, const char *keyword);
void varDefOptGribDbl(int varID, int tile_index, double dval, const char *keyword);
......
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