Commit 57250f4c authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function cdiDefKeyBytes().

parent 13725a68
......@@ -44,6 +44,16 @@ int main(void)
vlistDefVarName(vlistID, varID2, "P");
cdiDefKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_CENTRE, 252);
cdiDefKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_SUBCENTRE, 0);
cdiDefKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_MPIMTYPE, 1);
cdiDefKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_MPIMCLASS, 2);
cdiDefKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_MPIMUSER, 1403);
cdiDefKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_REVSTATUS, 0);
unsigned char revNumber[] = { 187, 128, 50, 251, 161, 44, 146, 63, 154, 149,
83, 90, 81, 103, 109, 138, 157, 216, 208, 64 };
cdiDefKeyBytes(vlistID, CDI_GLOBAL, CDI_KEY_REVNUMBER, revNumber, 20);
// Create a Time axis
taxisID = taxisCreate(TAXIS_ABSOLUTE);
......@@ -63,7 +73,7 @@ int main(void)
streamDefVlist(streamID, vlistID);
int vlistID0 = streamInqVlist(streamID);
/*
for ( int varID = 0; varID < 2; ++varID )
{
// vlistDefVarIntKey(vlistID0, varID, "centre", 252);
......@@ -74,7 +84,7 @@ int main(void)
vlistDefVarIntKey(vlistID0, varID, "mpimUser", 1403);
// vlistDefVarIntKey(vlistID0, varID, "shortendRevNo", 99);
}
*/
// Loop over the number of time steps
for ( int tsID = 0; tsID < nts; tsID++ )
{
......
......@@ -817,12 +817,18 @@ size_t gridInqYCvals(int gridID, char *ycvals[]);
#define CDI_KEY_REVSTATUS 816 // GRIB2 revStatus
#define CDI_KEY_REVNUMBER 817 // GRIB2 revNumber
// cdiDefKeyInt: Define a CDI variable integer value from a key
// cdiDefKeyInt: Define an integer value from a key of a CDI variable
int cdiDefKeyInt(int cdiID, int varID, int key, int value);
// cdiInqKeyInt: Get a CDI variable integer value from a key
// cdiInqKeyInt: Get an integer value from a key of a CDI variable
int cdiInqKeyInt(int cdiID, int varID, int key, int *value);
// cdiDefKeyBytes: Define a bytes array from a key of a CDI variable
int cdiDefKeyBytes(int cdiID, int varID, int key, unsigned char *bytes, int length);
// cdiInqKeyBytes: Get a bytes array from a key of a CDI variable
int cdiInqKeyBytes(int cdiID, int varID, int key, unsigned char *bytes, int *length);
int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2);
// CDI grid keys
......
......@@ -9,6 +9,7 @@
#include "zaxis.h"
#include "resource_unpack.h"
enum {KEY_INT, KEY_FLOAT, KEY_BYTES};
static
cdi_keys_t *get_keysp(vlist_t *vlistptr, int varID)
......@@ -39,7 +40,6 @@ cdi_key_t *new_key(cdi_keys_t *keysp, int key)
keysp->nelems++;
keyp->key = key;
// keyp->v = 0;
return keyp;
}
......@@ -121,13 +121,16 @@ int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2)
for ( size_t keyid = 0; keyid < keysp->nelems; keyid++ )
{
cdi_key_t *keyp = &(keysp->value[keyid]);
cdiDefKeyInt(cdiID2, varID2, keyp->key, keyp->v.i);
if ( keyp->type == KEY_INT )
cdiDefKeyInt(cdiID2, varID2, keyp->key, keyp->v.i);
else if ( keyp->type == KEY_BYTES )
cdiDefKeyBytes(cdiID2, varID2, keyp->key, keyp->v.s, keyp->length);
}
return status;
}
// cdiDefKeyInt: Define a CDI variable integer value from a key
// 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;
......@@ -142,15 +145,15 @@ int cdiDefKeyInt(int cdiID, int varID, int key, int value)
{
if ( keyp->v.i != value )
{
keyp->type = KEY_INT;
keyp->v.i = value;
//reshSetStatus(cdiID, &vlistOps, RESH_DESYNC_IN_USE);
}
}
return status;
}
// cdiInqKeyInt: Get a CDI variable integer value from a key
// cdiInqKeyInt: Get an integer value from a key of a CDI variable
int cdiInqKeyInt(int cdiID, int varID, int key, int *value)
{
int status = -1;
......@@ -163,23 +166,45 @@ int cdiInqKeyInt(int cdiID, int varID, int key, int *value)
cdi_key_t *keyp = find_key(keysp, key);
if ( keyp != NULL ) // key in use
{
// if ( keyp->indtype == indtype )
if ( keyp->type == KEY_INT )
{
*value = keyp->v.i;
status = CDI_NOERR;
*value = keyp->v.i;
status = CDI_NOERR;
}
/*
else
{
Warning("Key %d has wrong data type!", key);
status = -2;
}
*/
}
return status;
}
// cdiDefKeyBytes: Define a bytes array from a key of a CDI variable
int cdiDefKeyBytes(int cdiID, int varID, int key, unsigned char *bytes, int length)
{
int status = CDI_NOERR;
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
cdi_key_t *keyp = find_key(keysp, key);
if ( keyp == NULL ) keyp = new_key(keysp, key);
if ( keyp != NULL )
{
if ( keyp->length != 0 && keyp->length != length ) free(keyp->v.s);
keyp->length = length;
keyp->v.s = (unsigned char *) malloc(length);
memcpy(keyp->v.s, bytes, length);
keyp->type = KEY_BYTES;
}
return status;
}
// cdiInqKeyBytes: Get a bytes array from a key of a CDI variable
int cdiInqKeyBytes(int cdiID, int varID, int key, unsigned char *bytes, int *length)
{
int status = -1;
return status;
}
/*
* Local Variables:
......
#ifndef CDI_KEY_H
#define CDI_KEY_H
// CDI key
typedef struct {
int key; // CDI key
int nelems; // length of buffer v.s
int type; // KEY_INT, KEY_FLOAT, KEY_BYTES
int length; // number of bytes in v.s
union {
int i;
double d;
char *s;
unsigned char *s;
} v;
} cdi_key_t;
......
......@@ -107,6 +107,8 @@ void vlist_init_entry(vlist_t *vlistptr)
vlistptr->ntsteps = CDI_UNDEFID;
vlistptr->keys.nalloc = MAX_KEYS;
vlistptr->keys.nelems = 0;
for ( int i = 0; i < MAX_KEYS; ++i )
vlistptr->keys.value[i].length = 0;
vlistptr->atts.nalloc = MAX_ATTRIBUTES;
vlistptr->atts.nelems = 0;
vlistptr->nsubtypes = 0;
......
......@@ -54,6 +54,8 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].complevel = 1;
vlistptr->vars[varID].keys.nalloc = MAX_KEYS;
vlistptr->vars[varID].keys.nelems = 0;
for ( int i = 0; i < MAX_KEYS; ++i )
vlistptr->vars[varID].keys.value[i].length = 0;
vlistptr->vars[varID].atts.nalloc = MAX_ATTRIBUTES;
vlistptr->vars[varID].atts.nelems = 0;
vlistptr->vars[varID].lvalidrange = false;
......
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