Commit 78fb1d87 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function cdiCopyKeys().

parent fbf9d39e
......@@ -809,6 +809,8 @@ size_t gridInqYCvals(int gridID, char *ycvals[]);
#define CDI_KEY_TYPEOFENSEMBLEFORECAST 808 // GRIB2 typeOfEnsembleForecast
#define CDI_KEY_NUMBEROFFORECASTSINENSEMBLE 809 // GRIB2 numberOfForecastsInEnsemble
#define CDI_KEY_PERTURBATIONNUMBER 810 // GRIB2 perturbationNumber
#define CDI_KEY_CENTRE 811 // GRIB2 centre
#define CDI_KEY_SUBCENTRE 812 // GRIB2 subCentre
// cdiDefKeyInt: Define a CDI variable integer value from a key
int cdiDefKeyInt(int cdiID, int varID, int key, int value);
......@@ -816,6 +818,8 @@ int cdiDefKeyInt(int cdiID, int varID, int key, int value);
// cdiInqKeyInt: Get a CDI variable integer value from a key
int cdiInqKeyInt(int cdiID, int varID, int key, int *value);
int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2);
// CDI grid keys
#define CDI_KEY_XNAME 901 // X-axis name
#define CDI_KEY_XDIMNAME 902 // X-axis dimension name
......
......@@ -238,7 +238,7 @@ int cdi_def_att(int indtype, int exdtype, int cdiID, int varID, const char *name
{
int status = CDI_NOERR;
if ( len != 0 && xp == NULL ) /* Null arg */
if ( len != 0 && xp == NULL ) // Null arg
return CDI_EINVAL;
cdi_atts_t *attsp = cdi_get_attsp(cdiID, varID);
......@@ -257,7 +257,7 @@ int cdi_inq_att(int indtype, int cdiID, int varID, const char *name, size_t mxsz
{
int status = CDI_NOERR;
if ( mxsz != 0 && xp == NULL ) /* Null arg */
if ( mxsz != 0 && xp == NULL ) // Null arg
return CDI_EINVAL;
cdi_atts_t *attsp = cdi_get_attsp(cdiID, varID);
......@@ -296,7 +296,7 @@ int cdiCopyAtts(int cdiID1, int varID1, int cdiID2, int varID2)
cdi_atts_t *attsp1 = cdi_get_attsp(cdiID1, varID1);
xassert(attsp1 != NULL);
for ( int attid = 0; attid < (int)attsp1->nelems; attid++ )
for ( size_t attid = 0; attid < attsp1->nelems; attid++ )
{
cdi_att_t *attp = &(attsp1->value[attid]);
cdi_def_att(attp->indtype, attp->exdtype, cdiID2, varID2, attp->name, attp->nelems, attp->xsz, attp->xvalue);
......
......@@ -9,9 +9,7 @@
#include "cdi_limits.h"
#endif
/*
* CDI attribute
*/
// CDI attribute
typedef struct {
size_t xsz; // amount of space at xvalue
size_t namesz; // size of name
......@@ -35,9 +33,7 @@ typedef struct {
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);
#endif
......
......@@ -7,19 +7,19 @@
#include "vlist.h"
#include "grid.h"
#include "zaxis.h"
#include "resource_unpack.h"
static
cdi_keys_t *get_keysp(vlist_t *vlistptr, int varID)
{
cdi_keys_t *keysp = NULL;
/*
if ( varID == CDI_GLOBAL )
{
keysp = &vlistptr->keys;
}
else
*/
{
if ( varID >= 0 && varID < vlistptr->nvars )
keysp = &(vlistptr->vars[varID].keys);
......@@ -80,6 +80,7 @@ cdi_keys_t *cdi_get_keysp(int objID, int varID)
}
else
*/
if ( reshGetTxCode(objID) == VLIST )
{
vlist_t *vlistptr = vlist_to_pointer(objID);
keysp = get_keysp(vlistptr, varID);
......@@ -109,8 +110,25 @@ int vlist_key_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int keynum
return 0;
}
// cqdiDefKeyInt: Define a CDI varianble integer value from a key
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(cdiID1, varID1);
xassert(keysp != NULL);
for ( size_t keyid = 0; keyid < keysp->nelems; keyid++ )
{
cdi_key_t *keyp = &(keysp->value[keyid]);
cdiDefKeyInt(cdiID2, varID2, keyp->key, keyp->v.i);
}
return status;
}
// cdiDefKeyInt: Define a CDI variable integer value from a key
int cdiDefKeyInt(int cdiID, int varID, int key, int value)
{
int status = CDI_NOERR;
......@@ -132,8 +150,8 @@ int cdiDefKeyInt(int cdiID, int varID, int key, int value)
return status;
}
// cdiInqKeyInt: Get a CDI variable integer value from a key
int cdiInqKeyInt(int cdiID, int varID, int key, int *value)
// cdiInqKeyInt: Get a CDI variable integer value from a key
int cdiInqKeyInt(int cdiID, int varID, int key, int *value)
{
int status = CDI_NOERR;
......
#ifndef CDI_KEY_H
#define CDI_KEY_H
#ifndef CDI_KEY_H
#define CDI_KEY_H
/*
* CDI key
*/
// CDI key
typedef struct {
int key; // CDI key
int nelems; // length of buffer v.s
union {
int i;
double d;
......
......@@ -1545,6 +1545,18 @@ void gribapiDefInstitut(grib_handle *gh, int vlistID, int varID)
if ( subcenter != subcenter0 )
GRIB_CHECK(my_grib_set_long(gh, "subCentre", subcenter), 0);
}
int status;
int centre, subCentre;
status = cdiInqKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_CENTRE, &centre);
if ( status == 0 ) grib_set_long(gh, "centre", centre);
status = cdiInqKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_SUBCENTRE, &subCentre);
if ( status == 0 ) grib_set_long(gh, "subCentre", subCentre);
status = cdiInqKeyInt(vlistID, varID, CDI_KEY_CENTRE, &centre);
if ( status == 0 ) grib_set_long(gh, "centre", centre);
status = cdiInqKeyInt(vlistID, varID, CDI_KEY_SUBCENTRE, &subCentre);
if ( status == 0 ) grib_set_long(gh, "subCentre", subCentre);
}
static
......
......@@ -105,6 +105,8 @@ void vlist_init_entry(vlist_t *vlistptr)
vlistptr->tableID = cdiDefaultTableID;
vlistptr->varsAllocated = 0;
vlistptr->ntsteps = CDI_UNDEFID;
vlistptr->keys.nalloc = MAX_KEYS;
vlistptr->keys.nelems = 0;
vlistptr->atts.nalloc = MAX_ATTRIBUTES;
vlistptr->atts.nelems = 0;
vlistptr->nsubtypes = 0;
......@@ -290,13 +292,6 @@ void var_copy_entries(var_t *var2, var_t *var1)
if ( var1->stdname ) var2->stdname = strdupx(var1->stdname);
if ( var1->units ) var2->units = strdupx(var1->units);
size_t nkeys = var1->keys.nelems;
for ( size_t i = 0; i < nkeys; ++i )
{
var2->keys.value[i].v.i = var1->keys.value[i].v.i;
var2->keys.nelems++;
}
var2->opt_grib_kvpair_size = 0;
var2->opt_grib_kvpair = NULL;
var2->opt_grib_nentries = 0;
......@@ -345,6 +340,7 @@ void vlistCopy(int vlistID2, int vlistID1)
var_t *vars2 = vlistptr2->vars;
vlist_copy(vlistptr2, vlistptr1);
cdiCopyKeys(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL);
cdiCopyAtts(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL);
if ( vars1 )
......@@ -360,6 +356,7 @@ void vlistCopy(int vlistID2, int vlistID1)
for ( int varID = 0; varID < nvars; varID++ )
{
var_copy_entries(&vars2[varID], &vars1[varID]);
cdiCopyKeys(vlistID1, varID, vlistID2, varID);
vlistptr2->vars[varID].atts.nelems = 0;
cdiCopyAtts(vlistID1, varID, vlistID2, varID);
......@@ -532,6 +529,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vlist_copy(vlistptr2, vlistptr1);
cdiCopyKeys(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL);
cdiCopyAtts(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL);
if ( vlistptr1->vars )
......@@ -567,6 +565,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vars2[varID2].mvarID = varID2;
var_copy_entries(&vars2[varID2], &vars1[varID]);
cdiCopyKeys(vlistID1, varID, vlistID2, varID2);
vlistptr2->vars[varID2].atts.nelems = 0;
cdiCopyAtts(vlistID1, varID, vlistID2, varID2);
......@@ -774,6 +773,7 @@ void vlistCat(int vlistID2, int vlistID1)
}
var_copy_entries(&vars2[varID2], &vars1[varID]);
cdiCopyKeys(vlistID1, varID, vlistID2, varID2);
if ( vars1[varID].levinfo )
{
......
......@@ -112,6 +112,7 @@ typedef struct
int zaxisIDs[MAX_ZAXES_PS];
int subtypeIDs[MAX_SUBTYPES_PS];
var_t *vars;
cdi_keys_t keys;
cdi_atts_t atts;
}
vlist_t;
......
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