Commit db35384f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced ikeyvalue_t by cdi_keys_t.

parent c5d48d06
......@@ -200,7 +200,7 @@ int cdiInqAtt(int cdiID, int varID, int attnum, char *name, int *typep, int *len
}
int cdiDelAtts(int cdiID, int varID)
int cdiDeleteAtts(int cdiID, int varID)
{
int status = CDI_NOERR;
......
......@@ -32,6 +32,7 @@ typedef struct {
} cdi_atts_t;
int cdiDeleteAtts(int vlistID, int varID);
int cdiAttsGetSize(void *p, int varID, void *context);
void cdiAttsPack(void *p, int varID, void *buf, int size, int *position, void *context);
void cdiAttsUnpack(int cdiID, int varID, void *buf, int size, int *position, void *context);
......
......@@ -111,17 +111,12 @@ int vlist_key_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int keynum
}
int cdiDelKeys(int cdiID, int varID)
void cdiDeleteVarKeys(cdi_keys_t *keysp)
{
int status = CDI_NOERR;
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
for ( int keyid = 0; keyid < (int)keysp->nelems; keyid++ )
{
cdi_key_t *keyp = &(keysp->value[keyid]);
if ( keyp->length && keyp->v.s )
if ( keyp->length )
{
free(keyp->v.s);
keyp->v.s = NULL;
......@@ -130,6 +125,17 @@ int cdiDelKeys(int cdiID, int varID)
}
keysp->nelems = 0;
}
int cdiDeleteKeys(int cdiID, int varID)
{
int status = CDI_NOERR;
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
cdiDeleteVarKeys(keysp);
return status;
}
......@@ -154,13 +160,8 @@ int cdiInqKeyLen(int cdiID, int varID, int key, int *length)
}
int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2)
void cdiCopyVarKeys(cdi_keys_t *keysp, int cdiID2, int varID2)
{
int status = CDI_NOERR;
cdi_keys_t *keysp = cdi_get_keysp(cdiID1, varID1);
xassert(keysp != NULL);
for ( size_t keyid = 0; keyid < keysp->nelems; keyid++ )
{
cdi_key_t *keyp = &(keysp->value[keyid]);
......@@ -169,18 +170,24 @@ int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2)
else if ( keyp->type == KEY_BYTES )
cdiDefKeyBytes(cdiID2, varID2, keyp->key, keyp->v.s, keyp->length);
}
return status;
}
// cdiDefKeyInt: Define an integer value from a key of a CDI variable
int cdiDefKeyInt(int cdiID, int varID, int key, int value)
int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2)
{
int status = CDI_NOERR;
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
cdi_keys_t *keysp = cdi_get_keysp(cdiID1, varID1);
xassert(keysp != NULL);
cdiCopyVarKeys(keysp, cdiID2, varID2);
return status;
}
void cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value)
{
cdi_key_t *keyp = find_key(keysp, key);
if ( keyp == NULL ) keyp = new_key(keysp, key);
......@@ -192,6 +199,17 @@ int cdiDefKeyInt(int cdiID, int varID, int key, int value)
keyp->v.i = value;
}
}
}
// cdiDefKeyInt: Define an integer value from a key of a CDI variable
int cdiDefKeyInt(int cdiID, int varID, int key, int value)
{
int status = CDI_NOERR;
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
cdiDefVarKeyInt(keysp, key, value);
return status;
}
......
......@@ -21,6 +21,11 @@ typedef struct {
cdi_key_t value[MAX_KEYS];
} cdi_keys_t;
void cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value);
void cdiCopyVarKeys(cdi_keys_t *keysp, int cdiID2, int varID2);
void cdiDeleteVarKeys(cdi_keys_t *keysp);
int cdiDeleteKeys(int cdiID, int varID);
#endif
/*
......
......@@ -6,6 +6,7 @@
#include "cdi.h"
#include "cdi_int.h"
#include "cdi_uuid.h"
#include "cdi_key.h"
#include "dmemory.h"
#include "resource_handle.h"
#include "varscan.h"
......@@ -78,13 +79,7 @@ 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];
cdi_keys_t keys;
int opt_grib_nentries; /* current no. key-value pairs */
int opt_grib_kvpair_size; /* current allocated size */
......@@ -118,8 +113,10 @@ void paramInitEntry(unsigned varID, int param)
vartable[varID].instID = CDI_UNDEFID;
vartable[varID].modelID = CDI_UNDEFID;
vartable[varID].tableID = CDI_UNDEFID;
vartable[varID].nikeys = 0;
for ( int i = 0; i < MAX_KEYS; ++i ) vartable[varID].ikeyvalues[i].value = 0;
vartable[varID].keys.nalloc = MAX_KEYS;
vartable[varID].keys.nelems = 0;
for ( int i = 0; i < MAX_KEYS; ++i )
vartable[varID].keys.value[i].length = 0;
vartable[varID].comptype = CDI_COMPRESS_NONE;
vartable[varID].complevel = 1;
vartable[varID].lmissval = false;
......@@ -189,6 +186,9 @@ void varFree(void)
if ( vartable[varID].units ) Free(vartable[varID].units);
if ( vartable[varID].tiles ) subtypeDestroyPtr(vartable[varID].tiles);
cdi_keys_t *keysp = &(vartable[varID].keys);
cdiDeleteVarKeys(keysp);
if ( vartable[varID].opt_grib_kvpair )
{
for (int i=0; i<vartable[varID].opt_grib_nentries; i++) {
......@@ -580,8 +580,8 @@ 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);
cdi_keys_t *keysp = &(vartable[varID].keys);
cdiCopyVarKeys(keysp, vlistID, varID);
}
......@@ -1092,12 +1092,8 @@ void varDefTable(int varID, int tableID)
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++;
}
cdi_keys_t *keysp = &(vartable[varID].keys);
cdiDefVarKeyInt(keysp, key, value);
}
......
......@@ -221,8 +221,8 @@ void vlist_delete(vlist_t *vlistptr)
int vlistID = vlistptr->self;
if ( CDI_Debug ) Message("call to vlist_delete, vlistID = %d", vlistID);
cdiDelKeys(vlistID, CDI_GLOBAL);
cdiDelAtts(vlistID, CDI_GLOBAL);
cdiDeleteKeys(vlistID, CDI_GLOBAL);
cdiDeleteAtts(vlistID, CDI_GLOBAL);
int nvars = vlistptr->nvars;
var_t *vars = vlistptr->vars;
......@@ -248,8 +248,8 @@ void vlist_delete(vlist_t *vlistptr)
vlistptr->vars[varID].opt_grib_kvpair_size = 0;
vlistptr->vars[varID].opt_grib_kvpair = NULL;
cdiDelKeys(vlistID, varID);
cdiDelAtts(vlistID, varID);
cdiDeleteKeys(vlistID, varID);
cdiDeleteAtts(vlistID, varID);
}
if ( vars ) Free(vars);
......
......@@ -132,9 +132,6 @@ void cdiVlistDestroy_(int vlistID);
int vlistInqVarMissvalUsed(int vlistID, int varID);
int vlistHasTime(int vlistID);
int cdiDelKeys(int vlistID, int varID);
int cdiDelAtts(int vlistID, int varID);
void vlistUnpack(char * buffer, int bufferSize, int * pos,
int originNamespace, void *context, int force_id);
......
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