Commit 3783e8d4 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Replace repeated code with inline function.

parent 89ba0ceb
......@@ -678,15 +678,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
levID2++;
}
for ( index = 0; index <vlistptr2->ngrids; index++ )
if (vlistptr2->gridIDs[index] == gridID ) break;
if ( index == vlistptr2->ngrids )
{
vlistptr2->gridIDs[vlistptr2->ngrids++] = gridID;
if (vlistptr2->ngrids >= MAX_GRIDS_PS )
Error("Internal Problem! More than %d grids.", MAX_GRIDS_PS);
}
vlistAdd2GridIDs(vlistptr2, gridID);
for ( index = 0; index < vlistptr2->nzaxis; index++ )
if ( vlistptr2->zaxisIDs[index] == zaxisID ) break;
......@@ -810,15 +802,7 @@ void vlistCat(int vlistID2, int vlistID1)
vlistCopyVarAtts(vlistID1, varID, vlistID2, varID2);
gridID = vlistptr1->vars[varID].gridID;
for ( index = 0; index < vlistptr2->ngrids; index++ )
if ( gridID == vlistptr2->gridIDs[index] ) break;
if ( index == vlistptr2->ngrids )
{
vlistptr2->gridIDs[vlistptr2->ngrids++] = gridID;
if ( vlistptr2->ngrids >= MAX_GRIDS_PS )
Error("Internal Problem! More than %d grids.", MAX_GRIDS_PS);
}
vlistAdd2GridIDs(vlistptr2, gridID);
zaxisID = vlistptr1->vars[varID].zaxisID;
for ( index = 0; index < vlistptr2->nzaxis; index++ )
......
......@@ -173,6 +173,22 @@ int vlistInqVarValidrange(int vlistID, int varID, double *validrange);
int vlist_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB,
int attnum);
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 ( index == ngrids )
{
if (ngrids >= MAX_GRIDS_PS)
Error("Internal limit exceeded: more than %d grids.", MAX_GRIDS_PS);
++(vlistptr->ngrids);
vlistptr->gridIDs[ngrids] = gridID;
}
}
#if defined (HAVE_LIBGRIB_API)
extern int cdiNAdditionalGRIBKeys;
extern char* cdiAdditionalGRIBKeys[];
......
......@@ -214,19 +214,9 @@ int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype)
vlistptr->vars[varID].tsteptype = TSTEP_INSTANT;
}
int index;
for ( index = 0; index < vlistptr->ngrids; index++ )
if ( gridID == vlistptr->gridIDs[index] ) break;
if ( index == vlistptr->ngrids )
{
if ( vlistptr->ngrids + 1 >= MAX_GRIDS_PS )
Error("Maximum of %d grids reached", MAX_GRIDS_PS);
vlistptr->gridIDs[vlistptr->ngrids] = gridID;
vlistptr->ngrids++;
}
vlistAdd2GridIDs(vlistptr, gridID);
int index;
for ( index = 0; index < vlistptr->nzaxis; index++ )
if ( zaxisID == vlistptr->zaxisIDs[index] ) break;
......@@ -1537,19 +1527,7 @@ void vlistChangeVarGrid(int vlistID, int varID, int gridID)
vlistptr->gridIDs[index] = gridID;
}
else
{
for ( index = 0; index < vlistptr->ngrids; index++ )
if ( vlistptr->gridIDs[index] == gridID ) break;
if ( index == vlistptr->ngrids )
{
if ( vlistptr->ngrids + 1 >= MAX_GRIDS_PS )
Error("Maximum of %d grids reached", MAX_GRIDS_PS);
vlistptr->gridIDs[vlistptr->ngrids] = gridID;
vlistptr->ngrids++;
}
}
vlistAdd2GridIDs(vlistptr, gridID);
vlistptr->vars[varID].gridID = gridID;
}
......
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