Commit 11fa6f92 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

use opt_grib_* variables only if GRIBAPI is available

parent 366effc7
......@@ -131,9 +131,11 @@ int grbDecode(int filetype, unsigned char *gribbuffer, int gribsize, double *dat
#if defined (HAVE_LIBCGRIBEX)
if ( filetype == FILETYPE_GRB )
{
#if defined (HAVE_LIBGRIB_API)
extern int cdiNAdditionalGRIBKeys;
if ( cdiNAdditionalGRIBKeys > 0 )
Error("CGRIBEX decode does not support reading of additional GRIB keys!");
#endif
status = cgribexDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip, missval);
}
else
......
......@@ -786,6 +786,7 @@ void gribapiGetString(grib_handle *gh, const char *key, char *string, size_t len
else if ( length == 2 && memcmp(string, "~", length) == 0 ) string[0] = 0;
}
#if defined (HAVE_LIBGRIB_API)
static
void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
long recsize, off_t position, int datatype, int comptype, size_t len, const char *varname,
......@@ -993,6 +994,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
Message("varID = %d param = %d zaxistype = %d gridID = %d levelID = %d",
varID, param, zaxistype, gridID, levelID);
}
#endif
static
int gribapiGetParam(grib_handle *gh)
......
......@@ -64,6 +64,7 @@ typedef struct
char *longname;
char *units;
ensinfo_t *ensdata;
#if defined (HAVE_LIBGRIB_API)
/* (Optional) list of keyword/double value pairs */
int opt_grib_dbl_nentries;
char* opt_grib_dbl_keyword[MAX_OPT_GRIB_ENTRIES];
......@@ -72,6 +73,7 @@ typedef struct
int opt_grib_int_nentries;
char* opt_grib_int_keyword[MAX_OPT_GRIB_ENTRIES];
int opt_grib_int_val[MAX_OPT_GRIB_ENTRIES];
#endif
}
vartable_t;
......@@ -261,8 +263,10 @@ int paramNewEntry(int param)
for( i = 0; i < varTablesize; i++ )
{
vartable[i].param = UNDEF_PARAM;
#if defined (HAVE_LIBGRIB_API)
vartable[i].opt_grib_int_nentries = 0;
vartable[i].opt_grib_dbl_nentries = 0;
#endif
}
}
else
......@@ -292,8 +296,10 @@ int paramNewEntry(int param)
for( i = varID; i < varTablesize; i++ )
{
vartable[i].param = UNDEF_PARAM;
#if defined (HAVE_LIBGRIB_API)
vartable[i].opt_grib_int_nentries = 0;
vartable[i].opt_grib_dbl_nentries = 0;
#endif
}
}
......@@ -587,6 +593,7 @@ void cdi_generate_vars(stream_t *streamptr)
vartable[varid].ensdata->ens_count,
vartable[varid].ensdata->forecast_init_type);
#if defined (HAVE_LIBGRIB_API)
/* ---------------------------------- */
/* Local change: 2013-04-23, FP (DWD) */
/* ---------------------------------- */
......@@ -611,6 +618,7 @@ void cdi_generate_vars(stream_t *streamptr)
vlistptr->vars[varID].opt_grib_dbl_keyword[idx] = strdupx(vartable[varid].opt_grib_dbl_keyword[idx]);
}
/* note: if the key is not defined, we do not throw an error! */
#endif
if ( cdiDefaultTableID != UNDEFID )
{
......@@ -990,30 +998,34 @@ void varDefEnsembleInfo(int varID, int ens_idx, int ens_count, int forecast_type
void varDefOptGribInt(int varID, long lval, const char *keyword)
{
#if defined (HAVE_LIBGRIB_API)
int idx = vartable[varID].opt_grib_int_nentries;
vartable[varID].opt_grib_int_nentries++;
if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/integer value pairs!");
vartable[varID].opt_grib_int_val[idx] = (int) lval;
vartable[varID].opt_grib_int_keyword[idx] = strdupx(keyword);
#endif
}
void varDefOptGribDbl(int varID, double dval, const char *keyword)
{
#if defined (HAVE_LIBGRIB_API)
int idx = vartable[varID].opt_grib_dbl_nentries;
vartable[varID].opt_grib_dbl_nentries++;
if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/double value pairs!");
vartable[varID].opt_grib_dbl_val[idx] = dval;
vartable[varID].opt_grib_dbl_keyword[idx] = strdupx(keyword);
#endif
}
int varOptGribNentries(int varID)
{
int nentries = 0;
#if defined (HAVE_LIBGRIB_API)
nentries = vartable[varID].opt_grib_int_nentries + vartable[varID].opt_grib_dbl_nentries;
#endif
return (nentries);
}
......
......@@ -15,11 +15,11 @@
#include "vlist_att.h"
#include "pio_rpc.h"
#if defined (HAVE_LIBGRIB_API)
/* list of additional GRIB2 keywords which are read by the open process */
int cdiNAdditionalGRIBKeys = 0;
char* cdiAdditionalGRIBKeys[MAX_OPT_GRIB_ENTRIES];
#endif
extern void zaxisGetIndexList ( int, int * );
......@@ -232,6 +232,7 @@ void vlistDestroy(int vlistID)
if ( vlistptr->vars[varID].ensdata ) free(vlistptr->vars[varID].ensdata);
#if defined (HAVE_LIBGRIB_API)
int i;
for (i=0; i<vlistptr->vars[varID].opt_grib_int_nentries; i++) {
if ( vlistptr->vars[varID].opt_grib_int_keyword[i] )
......@@ -241,6 +242,7 @@ void vlistDestroy(int vlistID)
if ( vlistptr->vars[varID].opt_grib_dbl_keyword[i] )
free(vlistptr->vars[varID].opt_grib_dbl_keyword[i]);
}
#endif
vlistDelAtts(vlistID, varID);
}
......@@ -308,6 +310,7 @@ void vlistCopy(int vlistID2, int vlistID1)
vlistptr1->vars[varID].ensdata, sizeof(ensinfo_t));
}
#if defined (HAVE_LIBGRIB_API)
/* ---------------------------------- */
/* Local change: 2013-01-28, FP (DWD) */
/* ---------------------------------- */
......@@ -327,6 +330,7 @@ void vlistCopy(int vlistID2, int vlistID1)
vlistptr2->vars[varID].opt_grib_dbl_val[i] = vlistptr1->vars[varID].opt_grib_dbl_val[i];
}
}
#endif
vlistptr2->vars[varID].atts.nelems = 0;
vlistCopyVarAtts(vlistID1, varID, vlistID2, varID);
......@@ -557,6 +561,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vlistptr1->vars[varID].ensdata, sizeof(ensinfo_t));
}
#if defined (HAVE_LIBGRIB_API)
/* ---------------------------------- */
/* Local change: 2013-01-28, FP (DWD) */
/* ---------------------------------- */
......@@ -576,6 +581,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vlistptr2->vars[varID2].opt_grib_dbl_val[i] = vlistptr1->vars[varID].opt_grib_dbl_val[i];
}
}
#endif
vlistptr2->vars[varID2].atts.nelems = 0;
vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2);
......@@ -776,6 +782,7 @@ void vlistCat(int vlistID2, int vlistID1)
memcpy(vlistptr2->vars[varID2].ensdata, vlistptr1->vars[varID].ensdata, sizeof(ensinfo_t));
}
#if defined (HAVE_LIBGRIB_API)
/* ---------------------------------- */
/* Local change: 2013-01-28, FP (DWD) */
/* ---------------------------------- */
......@@ -795,6 +802,7 @@ void vlistCat(int vlistID2, int vlistID1)
vlistptr2->vars[varID2].opt_grib_dbl_val[i] = vlistptr1->vars[varID].opt_grib_dbl_val[i];
}
}
#endif
vlistptr2->vars[varID2].atts.nelems = 0;
vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2);
......
......@@ -115,6 +115,7 @@ typedef struct
int decoSize;
deco_t *deco;
#if defined (HAVE_LIBGRIB_API)
/* ---------------------------------- */
/* Local change: 2013-01-28, FP (DWD) */
/* ---------------------------------- */
......@@ -127,6 +128,7 @@ typedef struct
int opt_grib_int_nentries;
char* opt_grib_int_keyword[MAX_OPT_GRIB_ENTRIES];
int opt_grib_int_val[MAX_OPT_GRIB_ENTRIES];
#endif
}
var_t;
......@@ -178,9 +180,10 @@ void vlistDefVarValidrange(int vlistID, int varID, const double *validrange);
/* vlistInqVarValidrange: Get the valid range of a Variable */
int vlistInqVarValidrange(int vlistID, int varID, double *validrange);
#if defined (HAVE_LIBGRIB_API)
extern int cdiNAdditionalGRIBKeys;
extern char* cdiAdditionalGRIBKeys[];
#endif
#endif /* _VLIST_H */
/*
......
......@@ -65,6 +65,7 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].decoSize = 0;
vlistptr->vars[varID].deco = NULL;
#if defined (HAVE_LIBGRIB_API)
/* ---------------------------------- */
/* Local change: 2013-01-28, FP (DWD) */
/* ---------------------------------- */
......@@ -78,6 +79,7 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].opt_grib_int_keyword[i] = NULL;
vlistptr->vars[varID].opt_grib_dbl_keyword[i] = NULL;
} // for
#endif
}
static
......@@ -1901,6 +1903,7 @@ int vlistInqVarEnsemble( int vlistID, int varID, int *ensID, int *ensCount, int
/* vlistDefVarIntKey: Set an arbitrary keyword/integer value pair for GRIB API */
void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value)
{
#if defined (HAVE_LIBGRIB_API)
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
......@@ -1912,11 +1915,13 @@ void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value)
vlistptr->vars[varID].opt_grib_int_keyword[idx] = strdupx(name);
else
Error("Internal error!");
#endif
}
/* vlistDefVarDblKey: Set an arbitrary keyword/double value pair for GRIB API */
void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value)
{
#if defined (HAVE_LIBGRIB_API)
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
......@@ -1928,6 +1933,7 @@ void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value)
vlistptr->vars[varID].opt_grib_dbl_keyword[idx] = strdupx(name);
else
Error("Internal error!");
#endif
}
#if defined (HAVE_LIBGRIB_API)
......@@ -1939,9 +1945,11 @@ void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value)
/* cdiClearAdditionalKeys: Clears the list of additional GRIB keys. */
void cdiClearAdditionalKeys()
{
#if defined (HAVE_LIBGRIB_API)
int i;
for (i=0; i<cdiNAdditionalGRIBKeys; i++) free(cdiAdditionalGRIBKeys[i]);
cdiNAdditionalGRIBKeys = 0;
#endif
}
/* cdiDefAdditionalKey: Register an additional GRIB key which is read when file is opened. */
......
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