Commit 07f7bf35 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function gridIsEqual() (testversion).

parent d1f48101
......@@ -2070,10 +2070,10 @@ bool compareXYvals2(grid_t *gridRef, grid_t *gridTest)
}
static
bool gridCompare(int gridID, const grid_t *grid)
bool gridCompare(int gridID, const grid_t *grid, bool coord_compare)
{
bool differ = true;
grid_t *gridRef = gridID2Ptr(gridID);
const grid_t *gridRef = gridID2Ptr(gridID);
if ( grid->type == gridRef->type || grid->type == GRID_GENERIC )
{
......@@ -2123,7 +2123,7 @@ bool gridCompare(int gridID, const grid_t *grid)
}
}
else if ( grid->x.vals && grid->y.vals )
differ = gridRef->vtable->compareXYFull(gridRef, (grid_t *)grid);
differ = gridRef->vtable->compareXYFull((grid_t *)gridRef, (grid_t *)grid);
}
else
differ = true;
......@@ -2134,7 +2134,7 @@ bool gridCompare(int gridID, const grid_t *grid)
{
if ( grid->x.flag == 1 && grid->y.flag == 1
&& grid->x.vals && grid->y.vals )
differ = gridRef->vtable->compareXYFull(gridRef, (grid_t *)grid);
differ = gridRef->vtable->compareXYFull((grid_t *)gridRef, (grid_t *)grid);
}
else if ( (grid->y.size == 0 || grid->y.size == 1) &&
grid->x.size == gridRef->x.size*gridRef->y.size )
......@@ -2159,7 +2159,7 @@ bool gridCompare(int gridID, const grid_t *grid)
}
}
else if ( grid->x.vals && grid->y.vals )
differ = gridRef->vtable->compareXYFull(gridRef, (grid_t *)grid);
differ = gridRef->vtable->compareXYFull((grid_t *)gridRef, (grid_t *)grid);
}
else
differ = true;
......@@ -2182,48 +2182,65 @@ bool gridCompare(int gridID, const grid_t *grid)
printf("grid nv %d\n", gridInqNvertex(gridID));
*/
if ( grid->x.size == gridRef->x.size && grid->y.size == gridRef->y.size )
differ = gridRef->vtable->compareXYAO(gridRef, (grid_t *)grid);
differ = gridRef->vtable->compareXYAO((grid_t *)gridRef, (grid_t *)grid);
}
else if ( grid->type == GRID_UNSTRUCTURED )
{
/* FIXME: not octet 0 but octet 7 is guaranteed non-zero
* for any non-NULL UUID */
differ = differ || ( gridRef->uuid[0] && grid->uuid[0] && memcmp(gridRef->uuid, grid->uuid, CDI_UUID_SIZE) != 0 );
if ( !differ &&
((grid->x.vals == NULL) ^ (gridRef->x.vals == NULL)) &&
((grid->y.vals == NULL) ^ (gridRef->y.vals == NULL)) )
if ( coord_compare )
{
int nvertexA, nvertexB, numberA, numberB;
differ = ( (nvertexA = grid->nvertex)
&& (nvertexB = gridRef->nvertex)
&& (nvertexA != nvertexB) )
|| (numberA = grid->number, numberB = gridRef->number,
( (numberA)
&& numberB
&& (numberA != numberB) )
|| ( (numberA && numberB)
&& (grid->position) != (gridRef->position) ) );
differ = grid->nvertex != gridRef->nvertex
|| gridRef->vtable->compareXYAO((grid_t *)gridRef, (grid_t *)grid);
}
else if ( !differ )
else
{
differ = grid->nvertex != gridRef->nvertex
|| grid->number != gridRef->number
|| (grid->number > 0 && grid->position != gridRef->position)
|| gridRef->vtable->compareXYAO(gridRef, (grid_t *)grid);
/* FIXME: not octet 0 but octet 7 is guaranteed non-zero for any non-NULL UUID */
differ = differ || ( gridRef->uuid[0] && grid->uuid[0] && memcmp(gridRef->uuid, grid->uuid, CDI_UUID_SIZE) != 0 );
if ( !differ &&
((grid->x.vals == NULL) ^ (gridRef->x.vals == NULL)) &&
((grid->y.vals == NULL) ^ (gridRef->y.vals == NULL)) )
{
int nvertexA, nvertexB, numberA, numberB;
differ = ( (nvertexA = grid->nvertex)
&& (nvertexB = gridRef->nvertex)
&& (nvertexA != nvertexB) )
|| (numberA = grid->number, numberB = gridRef->number,
( (numberA)
&& numberB
&& (numberA != numberB) )
|| ( (numberA && numberB)
&& (grid->position) != (gridRef->position) ) );
}
else if ( !differ )
{
differ = grid->nvertex != gridRef->nvertex
|| grid->number != gridRef->number
|| (grid->number > 0 && grid->position != gridRef->position)
|| gridRef->vtable->compareXYAO((grid_t *)gridRef, (grid_t *)grid);
}
}
}
}
}
}
return differ;
}
/*
int gridIsEqual(int gridID1, int gridID2)
{
const grid_t *grid2 = gridID2Ptr(gridID2);
int grid_is_equal = gridCompare(gridID1, grid2, true) == false;
return grid_is_equal;
}
*/
int gridCompareP ( void * gridptr1, void * gridptr2 )
int gridCompareP(void *gridptr1, void *gridptr2)
{
grid_t * g1 = ( grid_t * ) gridptr1;
grid_t * g2 = ( grid_t * ) gridptr2;
grid_t *g1 = ( grid_t * ) gridptr1;
grid_t *g2 = ( grid_t * ) gridptr2;
enum { equal = 0,
differ = -1 };
int i, size;
......@@ -2268,7 +2285,7 @@ int gridCompareP ( void * gridptr1, void * gridptr2 )
if ( IS_NOT_EQUAL(g1->lcc.yinc , g2->lcc.yinc) ) return differ;
const double *restrict g1_xvals = g1->vtable->inqXValsPtr(g1),
*restrict g2_xvals = g2->vtable->inqXValsPtr(g2);
*restrict g2_xvals = g2->vtable->inqXValsPtr(g2);
if ( g1_xvals )
{
if ( g1->type == GRID_UNSTRUCTURED || g1->type == GRID_CURVILINEAR )
......@@ -2286,7 +2303,7 @@ int gridCompareP ( void * gridptr1, void * gridptr2 )
return differ;
const double *restrict g1_yvals = g1->vtable->inqYValsPtr(g1),
*restrict g2_yvals = g2->vtable->inqYValsPtr(g2);
*restrict g2_yvals = g2->vtable->inqYValsPtr(g2);
if ( g1_yvals )
{
if ( g1->type == GRID_UNSTRUCTURED || g1->type == GRID_CURVILINEAR )
......@@ -2304,7 +2321,7 @@ int gridCompareP ( void * gridptr1, void * gridptr2 )
return differ;
const double *restrict g1_area = g1->vtable->inqAreaPtr(g1),
*restrict g2_area = g2->vtable->inqAreaPtr(g2);
*restrict g2_area = g2->vtable->inqAreaPtr(g2);
if ( g1_area )
{
xassert ( g1->size );
......@@ -2394,7 +2411,7 @@ int gridCompareP ( void * gridptr1, void * gridptr2 )
else if ( g2->mask_gme )
return differ;
if (memcmp(g1->uuid, g2->uuid, CDI_UUID_SIZE))
if ( memcmp(g1->uuid, g2->uuid, CDI_UUID_SIZE) )
return differ;
return equal;
......@@ -4471,7 +4488,7 @@ gridCompareSearch(int id, void *res, void *data)
{
struct gridCompareSearchState *state = (struct gridCompareSearchState*)data;
(void)res;
if ( gridCompare(id, state->queryKey) == false )
if ( gridCompare(id, state->queryKey, false) == false )
{
state->resIDValue = id;
return CDI_APPLY_STOP;
......@@ -4500,7 +4517,7 @@ struct addIfNewRes cdiVlistAddGridIfNew(int vlistID, grid_t *grid, int mode)
{
if ( (gridID = vlistptr->gridIDs[index]) != UNDEFID )
{
if ( gridCompare(gridID, grid) == false )
if ( gridCompare(gridID, grid, false) == false )
{
griddefined = true;
break;
......
......@@ -132,6 +132,8 @@ const char *gridInqReferencePtr(int gridID);
int gridGenerate(const grid_t *grid);
//int gridIsEqual(int gridID1, int gridID2);
void cdiGridGetIndexList(unsigned, int * );
void
......
......@@ -230,10 +230,11 @@ vlist_delete(vlist_t *vlistptr)
if ( vlistptr->vars[varID].opt_grib_kvpair )
{
for (int i=0; i<vlistptr->vars[varID].opt_grib_nentries; i++) {
if ( vlistptr->vars[varID].opt_grib_kvpair[i].keyword )
Free(vlistptr->vars[varID].opt_grib_kvpair[i].keyword);
}
for ( int i = 0; i<vlistptr->vars[varID].opt_grib_nentries; i++ )
{
if ( vlistptr->vars[varID].opt_grib_kvpair[i].keyword )
Free(vlistptr->vars[varID].opt_grib_kvpair[i].keyword);
}
Free(vlistptr->vars[varID].opt_grib_kvpair);
}
vlistptr->vars[varID].opt_grib_nentries = 0;
......@@ -531,7 +532,6 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
{
int nvars = vlistptr1->nvars;
int nvars2 = 0;
int varID2;
vlistptr2->ngrids = 0;
vlistptr2->nzaxis = 0;
......@@ -548,7 +548,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vlistptr2->vars = vars2;
varID2 = 0;
int varID2 = 0;
for ( int varID = 0; varID < nvars; varID++ )
if ( vars1[varID].flag )
{
......
......@@ -18,6 +18,7 @@
#define VALIDMISS 1.e+303
#include "cdi_att.h"
#include "grid.h"
typedef struct
{
......@@ -151,23 +152,27 @@ void resize_opt_grib_entries(var_t *var, int nentries);
static inline void
vlistAdd2GridIDs(vlist_t *vlistptr, int gridID)
static inline
void vlistAdd2GridIDs(vlist_t *vlistptr, int gridID)
{
int index, ngrids = vlistptr->ngrids;
for ( index = 0; index < ngrids; index++ )
if (vlistptr->gridIDs[index] == gridID ) break;
{
if ( vlistptr->gridIDs[index] == gridID ) break;
// if ( gridIsEqual(vlistptr->gridIDs[index], gridID) ) break;
}
if ( index == ngrids )
{
if (ngrids >= MAX_GRIDS_PS)
if ( ngrids >= MAX_GRIDS_PS )
Error("Internal limit exceeded: more than %d grids.", MAX_GRIDS_PS);
++(vlistptr->ngrids);
vlistptr->gridIDs[ngrids] = gridID;
++(vlistptr->ngrids);
}
}
static inline void
vlistAdd2ZaxisIDs(vlist_t *vlistptr, int zaxisID)
static inline
void vlistAdd2ZaxisIDs(vlist_t *vlistptr, int zaxisID)
{
int index, nzaxis = vlistptr->nzaxis;
for ( index = 0; index < nzaxis; index++ )
......@@ -178,24 +183,25 @@ vlistAdd2ZaxisIDs(vlist_t *vlistptr, int zaxisID)
if ( nzaxis >= MAX_ZAXES_PS )
Error("Internal limit exceeded: more than %d zaxis.", MAX_ZAXES_PS);
vlistptr->zaxisIDs[nzaxis] = zaxisID;
vlistptr->nzaxis++;
++(vlistptr->nzaxis);
}
}
static inline void
vlistAdd2SubtypeIDs(vlist_t *vlistptr, int subtypeID)
static inline
void vlistAdd2SubtypeIDs(vlist_t *vlistptr, int subtypeID)
{
if ( subtypeID == CDI_UNDEFID ) return;
int index, nsubs = vlistptr->nsubtypes;
for ( index = 0; index < nsubs; index++ )
if (vlistptr->subtypeIDs[index] == subtypeID ) break;
if ( vlistptr->subtypeIDs[index] == subtypeID ) break;
if ( index == nsubs )
{
if (nsubs >= MAX_SUBTYPES_PS)
if ( nsubs >= MAX_SUBTYPES_PS )
Error("Internal limit exceeded: more than %d subs.", MAX_SUBTYPES_PS);
++(vlistptr->nsubtypes);
vlistptr->subtypeIDs[nsubs] = subtypeID;
++(vlistptr->nsubtypes);
}
}
......
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