Commit 8edf81f7 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Removed function varDefEnsembleInfo().

parent 57fd0c23
......@@ -62,7 +62,6 @@ cdi_key_t *find_key(cdi_keys_t *keysp, int key)
return NULL;
}
static
cdi_keys_t *cdi_get_keysp(int objID, int varID)
{
......@@ -89,6 +88,27 @@ cdi_keys_t *cdi_get_keysp(int objID, int varID)
return keysp;
}
int vlist_key_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int keynum)
{
cdi_keys_t *keyspa = get_keysp(a, varIDA),
*keyspb = get_keysp(b, varIDB);
if (keyspa == NULL && keyspb == NULL)
return 0;
xassert(keynum >= 0 && keynum < (int)keyspa->nelems
&& keynum < (int)keyspb->nelems);
cdi_key_t *keypa = keyspa->value + keynum,
*keypb = keyspb->value + keynum;
if ( keypa->key != keypb->key )
return 1;
if ( keypa->v.i != keypb->v.i )
return 1;
return 0;
}
// cqdiDefKeyInt: Define a CDI varianble integer value from a key
int cdiDefKeyInt(int cdiID, int varID, int key, int value)
{
......
......@@ -451,9 +451,17 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d
if ( ISEC1_LocalFLag )
{
if ( ISEC1_CenterID == 78 && isec1[36] == 253 ) // DWD local extension
varDefEnsembleInfo(varID, isec1[54], isec1[53], isec1[52]);
{
varDefKeyInt(varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, isec1[52]);
varDefKeyInt(varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, isec1[53]);
varDefKeyInt(varID, CDI_KEY_PERTURBATIONNUMBER, isec1[54]);
}
else if ( ISEC1_CenterID == 252 && isec1[36] == 1 ) // MPIM local extension
varDefEnsembleInfo(varID, isec1[38], isec1[39], isec1[37]);
{
varDefKeyInt(varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, isec1[37]);
varDefKeyInt(varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, isec1[39]);
varDefKeyInt(varID, CDI_KEY_PERTURBATIONNUMBER, isec1[38]);
}
}
if ( lmv ) varDefMissval(varID, FSEC3_MissVal);
......
......@@ -431,6 +431,24 @@ void gribapiGetKeys(grib_handle *gh, int varID)
long backgroundProcess = 0;
if ( grib_get_long(gh, "backgroundProcess", &backgroundProcess) == 0 )
varDefKeyInt(varID, CDI_KEY_BACKGROUNDPROCESS, (int) backgroundProcess);
/*
Get the ensemble Info from the grib-2 Tables and update the intermediate datastructure.
Further update to the "vlist" is handled in the same way as for GRIB-1 by "cdi_generate_vars"
*/
long typeOfEnsembleForecast = 0;
if ( grib_get_long(gh, "typeOfEnsembleForecast", &typeOfEnsembleForecast) == 0 )
{
long perturbationNumber = 0, numberOfForecastsInEnsemble = 0;
GRIB_CHECK(grib_get_long(gh, "numberOfForecastsInEnsemble", &numberOfForecastsInEnsemble), 0);
GRIB_CHECK(grib_get_long(gh, "perturbationNumber", &perturbationNumber), 0);
if ( perturbationNumber > 0 )
{
varDefKeyInt(varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, (int) typeOfEnsembleForecast);
varDefKeyInt(varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, (int) numberOfForecastsInEnsemble);
varDefKeyInt(varID, CDI_KEY_PERTURBATIONNUMBER, (int) perturbationNumber);
}
}
}
static
......@@ -594,20 +612,6 @@ void gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh,
varDefCompType(varID, comptype);
/*
Get the ensemble Info from the grib-2 Tables and update the intermediate datastructure.
Further update to the "vlist" is handled in the same way as for GRIB-1 by "cdi_generate_vars"
*/
long ens_index = 0, ens_count = 0, ens_forecast_type = 0;
if ( grib_get_long(gh, "typeOfEnsembleForecast", &ens_forecast_type) == 0 )
{
GRIB_CHECK(grib_get_long(gh, "numberOfForecastsInEnsemble", &ens_count), 0);
GRIB_CHECK(grib_get_long(gh, "perturbationNumber", &ens_index), 0);
}
if ( ens_index > 0 )
varDefEnsembleInfo(varID, (int)ens_index, (int)ens_count, (int)ens_forecast_type);
gribapiGetKeys(gh, varID);
if (lread_additional_keys)
......
......@@ -74,7 +74,6 @@ typedef struct
char *stdname;
char *longname;
char *units;
ensinfo_t *ensdata;
/* meta-data for specification of tiles (currently only GRIB-API: */
subtype_t *tiles;
......@@ -129,7 +128,6 @@ void paramInitEntry(unsigned varID, int param)
vartable[varID].stdname = NULL;
vartable[varID].longname = NULL;
vartable[varID].units = NULL;
vartable[varID].ensdata = NULL;
vartable[varID].tiles = NULL;
}
......@@ -189,7 +187,6 @@ void varFree(void)
if ( vartable[varID].stdname ) Free(vartable[varID].stdname);
if ( vartable[varID].longname ) Free(vartable[varID].longname);
if ( vartable[varID].units ) Free(vartable[varID].units);
if ( vartable[varID].ensdata ) Free(vartable[varID].ensdata);
if ( vartable[varID].tiles ) subtypeDestroyPtr(vartable[varID].tiles);
if ( vartable[varID].opt_grib_kvpair )
......@@ -1093,17 +1090,6 @@ void varDefTable(int varID, int tableID)
}
void varDefEnsembleInfo(int varID, int ens_idx, int ens_count, int forecast_type)
{
if ( vartable[varID].ensdata == NULL )
vartable[varID].ensdata = (ensinfo_t *) Malloc( sizeof( ensinfo_t ) );
vartable[varID].ensdata->ens_index = ens_idx;
vartable[varID].ensdata->ens_count = ens_count;
vartable[varID].ensdata->forecast_init_type = forecast_type;
}
void varDefKeyInt(int varID, int key, int value)
{
if ( vartable[varID].nikeys < MAX_KEYS )
......
......@@ -28,7 +28,6 @@ void varDefModel(int varID, int modelID);
int varInqModel(int varID);
void varDefTable(int varID, int tableID);
int varInqTable(int varID);
void varDefEnsembleInfo(int varID, int ens_idx, int ens_count, int forecast_type);
void varDefKeyInt(int varID, int key, int value);
......
#if defined (HAVE_CONFIG_H)
# include "config.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "dmemory.h"
......@@ -17,7 +17,7 @@
#include "resource_unpack.h"
#include "serialize.h"
#if defined (HAVE_LIBGRIB_API)
#ifdef HAVE_LIBGRIB_API
/* list of additional GRIB2 keywords which are read by the open process */
int cdiNAdditionalGRIBKeys = 0;
char* cdiAdditionalGRIBKeys[MAX_OPT_GRIB_ENTRIES];
......@@ -27,19 +27,19 @@ static int VLIST_Debug = 0;
static void vlist_initialize(void);
#if defined (HAVE_LIBPTHREAD)
# include <pthread.h>
#ifdef HAVE_LIBPTHREAD
#include <pthread.h>
static pthread_once_t _vlist_init_thread = PTHREAD_ONCE_INIT;
# define VLIST_INIT() \
#define VLIST_INIT() \
pthread_once(&_vlist_init_thread, vlist_initialize)
#else
static bool vlistIsInitialized = false;
# define VLIST_INIT() \
#define VLIST_INIT() \
if ( !vlistIsInitialized ) vlist_initialize()
#endif
......@@ -208,8 +208,8 @@ int vlistCreate(void)
return vlistptr->self;
}
static void
vlist_delete(vlist_t *vlistptr)
static
void vlist_delete(vlist_t *vlistptr)
{
int vlistID = vlistptr->self;
if ( CDI_Debug ) Message("call to vlist_delete, vlistID = %d", vlistID);
......@@ -226,7 +226,6 @@ vlist_delete(vlist_t *vlistptr)
if ( vars[varID].longname ) Free(vars[varID].longname);
if ( vars[varID].stdname ) Free(vars[varID].stdname);
if ( vars[varID].units ) Free(vars[varID].units);
if ( vars[varID].ensdata ) Free(vars[varID].ensdata);
if ( vlistptr->vars[varID].opt_grib_kvpair )
{
......@@ -290,10 +289,12 @@ void var_copy_entries(var_t *var2, var_t *var1)
if ( var1->longname ) var2->longname = strdupx(var1->longname);
if ( var1->stdname ) var2->stdname = strdupx(var1->stdname);
if ( var1->units ) var2->units = strdupx(var1->units);
if ( var1->ensdata )
size_t nkeys = var1->keys.nelems;
for ( size_t i = 0; i < nkeys; ++i )
{
var2->ensdata = (ensinfo_t *) Malloc(sizeof(ensinfo_t));
memcpy(var2->ensdata, var1->ensdata, sizeof(ensinfo_t));
var2->keys.value[i].v.i = var1->keys.value[i].v.i;
var2->keys.nelems++;
}
var2->opt_grib_kvpair_size = 0;
......
......@@ -78,7 +78,6 @@ typedef struct
levinfo_t *levinfo;
int comptype; // compression type
int complevel; // compression level
ensinfo_t *ensdata; // Ensemble information
cdi_keys_t keys;
cdi_atts_t atts;
int iorank;
......@@ -118,6 +117,8 @@ typedef struct
vlist_t;
int vlist_key_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int keynum);
vlist_t *vlist_to_pointer(int vlistID);
void cdiVlistMakeInternal(int vlistID);
void cdiVlistMakeImmutable(int vlistID);
......
......@@ -8,7 +8,6 @@
#include "vlist.h"
#include "vlist_var.h"
#include "resource_handle.h"
#include "cdi_att.h"
#include "tablepar.h"
#include "namespace.h"
#include "serialize.h"
......@@ -60,7 +59,6 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].lvalidrange = false;
vlistptr->vars[varID].validrange[0] = VALIDMISS;
vlistptr->vars[varID].validrange[1] = VALIDMISS;
vlistptr->vars[varID].ensdata = NULL;
vlistptr->vars[varID].iorank = CDI_UNDEFID;
vlistptr->vars[varID].opt_grib_kvpair_size = 0;
vlistptr->vars[varID].opt_grib_kvpair = NULL;
......@@ -1949,15 +1947,19 @@ int vlistVarCompare(vlist_t *a, int varIDA, vlist_t *b, int varIDB)
if (diff)
return 1;
}
size_t natts = a->vars[varIDA].atts.nelems;
if (natts != b->vars[varIDB].atts.nelems)
return 1;
for (size_t attID = 0; attID < natts; ++attID)
diff |= cdi_att_compare(a, varIDA, b, varIDB, (int)attID);
if ((diff |= ((pva->ensdata == NULL) ^ (pvb->ensdata == NULL))))
size_t nkeys = a->vars[varIDA].keys.nelems;
if (nkeys != b->vars[varIDB].keys.nelems)
return 1;
if (pva->ensdata)
diff = (memcmp(pva->ensdata, pvb->ensdata, sizeof (*(pva->ensdata)))) != 0;
for (size_t keyID = 0; keyID < nkeys; ++keyID)
diff |= vlist_key_compare(a, varIDA, b, varIDB, (int)keyID);
return diff;
}
......
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