Commit daf85b52 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Complete comparison of vlists.

parent 3e35d2b1
......@@ -46,15 +46,20 @@ static int vlistIsInitialized = 0;
#endif
/* FIXME: implementation incomplete, fix once leaf nodes are complete */
static int
vlist_compare(vlist_t *a, vlist_t *b)
{
int diff;
diff = (a->nvars != b->nvars) || (a->ngrids != b->ngrids)
|| (a->nzaxis != b->nzaxis) || (a->instID != b->instID)
|| (a->modelID != b->modelID) || (a->tableID != b->tableID)
|| (a->ntsteps != b->ntsteps);
diff = (a->nvars != b->nvars) | (a->ngrids != b->ngrids)
| (a->nzaxis != b->nzaxis) | (a->instID != b->instID)
| (a->modelID != b->modelID) | (a->tableID != b->tableID)
| (a->ntsteps != b->ntsteps) | (a->atts.nelems != b->atts.nelems);
int nvars = a->nvars;
for (int varID = 0; varID < nvars; ++varID)
diff |= vlistVarCompare(a, varID, b, varID);
int natts = a->atts.nelems;
for (int attID = 0; attID < natts; ++attID)
diff |= vlist_att_compare(a, CDI_GLOBAL, b, CDI_GLOBAL, attID);
return diff;
}
......
......@@ -164,6 +164,9 @@ 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);
int vlist_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB,
int attnum);
#if defined (HAVE_LIBGRIB_API)
extern int cdiNAdditionalGRIBKeys;
extern char* cdiAdditionalGRIBKeys[];
......
......@@ -473,6 +473,32 @@ vlistAttTypeLookup(cdi_att_t *attp)
return type;
}
int vlist_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB,
int attnum)
{
cdi_atts_t *attspa = get_attsp(a, varIDA),
*attspb = get_attsp(b, varIDB);
if (attspa == NULL && attspb == NULL)
return 0;
xassert(attnum >= 0 && attnum < (int)attspa->nelems
&& attnum < (int)attspb->nelems);
cdi_att_t *attpa = attspa->value + attnum,
*attpb = attspb->value + attnum;
size_t len;
if ((len = attpa->namesz) != attpb->namesz)
return 1;
int diff;
if ((diff = memcmp(attpa->name, attpb->name, len)))
return 1;
if (attpa->indtype != attpb->indtype
|| attpa->exdtype != attpb->exdtype
|| attpa->nelems != attpb->nelems)
return 1;
return memcmp(attpa->xvalue, attpb->xvalue, attpa->xsz);
}
static int
vlistAttGetSize(vlist_t *vlistptr, int varID, int attnum, void *context)
{
......
......@@ -2116,6 +2116,51 @@ int vlistInqVarIOrank(int vlistID, int varID)
}
int vlistVarCompare(vlist_t *a, int varIDA, vlist_t *b, int varIDB)
{
xassert(a && b
&& varIDA >= 0 && varIDA < a->nvars
&& varIDB >= 0 && varIDB < b->nvars);
var_t *pva = a->vars + varIDA, *pvb = b->vars + varIDB;
#define FCMP(f) ((pva->f) != (pvb->f))
#define FCMPSTR(fs) ((pva->fs) != (pvb->fs) && strcmp((pva->fs), (pvb->fs)))
#define FCMP2(f) (namespaceResHDecode(pva->f).idx \
!= namespaceResHDecode(pvb->f).idx)
int diff = FCMP(fvarID) | FCMP(mvarID) | FCMP(flag) | FCMP(param)
| FCMP(datatype) | FCMP(tsteptype) | FCMP(timave) | FCMP(timaccu)
| FCMP(chunktype) | FCMP(xyz) | FCMP2(gridID) | FCMP2(zaxisID)
| FCMP2(instID) | FCMP2(modelID) | FCMP2(tableID) | FCMP(missvalused)
| FCMP(missval) | FCMP(addoffset) | FCMP(scalefactor) | FCMPSTR(name)
| FCMPSTR(longname) | FCMPSTR(stdname) | FCMPSTR(units) | FCMPSTR(extra)
| FCMP(comptype) | FCMP(complevel) | FCMP(lvalidrange)
| FCMP(validrange[0]) | FCMP(validrange[1]);
#undef FCMP
#undef FCMP2
if ((diff |= ((pva->levinfo == NULL) ^ (pvb->levinfo == NULL))))
return 1;
if (pva->levinfo)
{
int zaxisID = pva->zaxisID;
int nlevs = zaxisInqSize(zaxisID);
diff |= (memcmp(pva->levinfo, pvb->levinfo, sizeof (levinfo_t) * nlevs)
!= 0);
if (diff)
return 1;
}
int natts = a->vars[varIDA].atts.nelems;
if (natts != b->vars[varIDB].atts.nelems)
return 1;
for (int attID = 0; attID < natts; ++attID)
diff |= vlist_att_compare(a, varIDA, b, varIDB, attID);
if ((diff |= ((pva->ensdata == NULL) ^ (pvb->ensdata == NULL))))
return 1;
if (pva->ensdata)
diff = (memcmp(pva->ensdata, pvb->ensdata, sizeof (*(pva->ensdata)))) != 0;
return diff;
}
enum {
vlistvar_nints = 20,
vlistvar_ndbls = 3,
......
......@@ -14,6 +14,7 @@ void vlistVarPack(vlist_t *p, int varID,
char * buffer, int bufferSize, int * pos, void *context);
void vlistVarUnpack(int vlistID,
char * buf, int size, int *position, int, void *context);
int vlistVarCompare(vlist_t *a, int varIDA, vlist_t *b, int varIDB);
void vlistDefVarIOrank ( int, int, int );
int vlistInqVarIOrank ( int, int );
......
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