Commit 0759c7fa authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Replace repeated code with wrapper.

parent 6c5ac2cb
......@@ -175,6 +175,13 @@ zaxis_t *zaxisNewEntry(int id)
return (zaxisptr);
}
static inline zaxis_t *
zaxisID2Ptr(int id)
{
return (zaxis_t *)reshGetVal(id, &zaxisOps);
}
static
void zaxisInit(void)
{
......@@ -202,6 +209,7 @@ unsigned cdiZaxisCount(void)
return reshCountType(&zaxisOps);
}
static int
zaxisCreate_(int zaxistype, int size, int id)
{
......@@ -315,7 +323,7 @@ static void zaxisDestroyKernel( zaxis_t * zaxisptr )
*/
void zaxisDestroy(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
zaxisDestroyKernel ( zaxisptr );
}
......@@ -330,13 +338,9 @@ void zaxisDestroyP ( void * zaxisptr )
char *zaxisNamePtr(int zaxistype)
{
char *name;
if ( zaxistype >= 0 && zaxistype < CDI_NumZaxistype )
name = ZaxistypeEntry[zaxistype].longname;
else
name = ZaxistypeEntry[ZAXIS_GENERIC].longname;
char *name = (zaxistype >= 0 && zaxistype < CDI_NumZaxistype)
? ZaxistypeEntry[zaxistype].longname
: ZaxistypeEntry[ZAXIS_GENERIC].longname;
return (name);
}
......@@ -362,7 +366,7 @@ The function @func{zaxisDefName} defines the name of a Z-axis.
*/
void zaxisDefName(int zaxisID, const char *name)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( name )
{
......@@ -388,7 +392,7 @@ The function @func{zaxisDefLongname} defines the longname of a Z-axis.
*/
void zaxisDefLongname(int zaxisID, const char *longname)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( longname )
{
......@@ -414,7 +418,7 @@ The function @func{zaxisDefUnits} defines the units of a Z-axis.
*/
void zaxisDefUnits(int zaxisID, const char *units)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( units )
{
......@@ -445,7 +449,7 @@ The function @func{zaxisInqName} returns the name of a Z-axis.
*/
void zaxisInqName(int zaxisID, char *name)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
strcpy(name, zaxisptr->name);
}
......@@ -470,7 +474,7 @@ The function @func{zaxisInqLongname} returns the longname of a Z-axis.
*/
void zaxisInqLongname(int zaxisID, char *longname)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
strcpy(longname, zaxisptr->longname);
}
......@@ -495,21 +499,21 @@ The function @func{zaxisInqUnits} returns the units of a Z-axis.
*/
void zaxisInqUnits(int zaxisID, char *units)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
strcpy(units, zaxisptr->units);
}
void zaxisInqStdname(int zaxisID, char *stdname)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
strcpy(stdname, zaxisptr->stdname);
}
void zaxisDefPrec(int zaxisID, int prec)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if (zaxisptr->prec != prec)
{
......@@ -521,7 +525,7 @@ void zaxisDefPrec(int zaxisID, int prec)
int zaxisInqPrec(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->prec);
}
......@@ -529,7 +533,7 @@ int zaxisInqPrec(int zaxisID)
void zaxisDefPositive(int zaxisID, int positive)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if (zaxisptr->positive != positive)
{
......@@ -541,7 +545,7 @@ void zaxisDefPositive(int zaxisID, int positive)
int zaxisInqPositive(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->positive);
}
......@@ -549,7 +553,7 @@ int zaxisInqPositive(int zaxisID)
void zaxisDefLtype(int zaxisID, int ltype)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if (zaxisptr->ltype != ltype)
{
......@@ -561,7 +565,7 @@ void zaxisDefLtype(int zaxisID, int ltype)
int zaxisInqLtype(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->ltype);
}
......@@ -569,7 +573,7 @@ int zaxisInqLtype(int zaxisID)
void zaxisDefLtype2(int zaxisID, int ltype2)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if (zaxisptr->ltype2 != ltype2)
{
......@@ -581,7 +585,7 @@ void zaxisDefLtype2(int zaxisID, int ltype2)
int zaxisInqLtype2(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->ltype2);
}
......@@ -602,7 +606,7 @@ The function @func{zaxisDefLevels} defines the levels of a Z-axis.
*/
void zaxisDefLevels(int zaxisID, const double *levels)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
int size = zaxisptr->size;
......@@ -630,7 +634,7 @@ The function @func{zaxisDefLevel} defines one level of a Z-axis.
*/
void zaxisDefLevel(int zaxisID, int levelID, double level)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( levelID >= 0 && levelID < zaxisptr->size )
zaxisptr->vals[levelID] = level;
......@@ -640,7 +644,7 @@ void zaxisDefLevel(int zaxisID, int levelID, double level)
void zaxisDefNlevRef(int zaxisID, const int nhlev)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if (zaxisptr->nhlev != nhlev)
{
......@@ -652,7 +656,7 @@ void zaxisDefNlevRef(int zaxisID, const int nhlev)
int zaxisInqNlevRef(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->nhlev);
}
......@@ -673,7 +677,7 @@ The function @func{zaxisDefNumber} defines the reference number for a generalize
*/
void zaxisDefNumber(int zaxisID, const int number)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if (zaxisptr->number != number)
{
......@@ -699,7 +703,7 @@ The function @func{zaxisInqNumber} returns the reference number to a generalized
*/
int zaxisInqNumber(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->number);
}
......@@ -720,7 +724,7 @@ The function @func{zaxisDefUUID} defines the UUID for a generalized Z-axis.
*/
void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
memcpy(zaxisptr->uuid, uuid, CDI_UUID_SIZE);
reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
......@@ -744,7 +748,7 @@ The function @func{zaxisInqUUID} returns the UUID to a generalized Z-axis.
*/
void zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE])
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
memcpy(uuid, zaxisptr->uuid, CDI_UUID_SIZE);
}
......@@ -767,7 +771,7 @@ The function @func{zaxisInqLevel} returns one level of a Z-axis.
double zaxisInqLevel(int zaxisID, int levelID)
{
double level = 0;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( levelID >= 0 && levelID < zaxisptr->size )
level = zaxisptr->vals[levelID];
......@@ -778,7 +782,7 @@ double zaxisInqLevel(int zaxisID, int levelID)
double zaxisInqLbound(int zaxisID, int index)
{
double level = 0;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( zaxisptr->lbounds )
if ( index >= 0 && index < zaxisptr->size )
......@@ -791,7 +795,7 @@ double zaxisInqLbound(int zaxisID, int index)
double zaxisInqUbound(int zaxisID, int index)
{
double level = 0;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( zaxisptr->ubounds )
if ( index >= 0 && index < zaxisptr->size )
......@@ -803,7 +807,7 @@ double zaxisInqUbound(int zaxisID, int index)
const double *zaxisInqLevelsPtr(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return ( zaxisptr->vals );
}
......@@ -826,7 +830,7 @@ The function @func{zaxisInqLevels} returns all levels of a Z-axis.
*/
void zaxisInqLevels(int zaxisID, double *levels)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
int size = zaxisptr->size;
for (int i = 0; i < size; i++ )
levels[i] = zaxisptr->vals[i];
......@@ -836,7 +840,7 @@ void zaxisInqLevels(int zaxisID, double *levels)
int zaxisInqLbounds(int zaxisID, double *lbounds)
{
int size = 0;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( zaxisptr->lbounds )
{
......@@ -854,7 +858,7 @@ int zaxisInqLbounds(int zaxisID, double *lbounds)
int zaxisInqUbounds(int zaxisID, double *ubounds)
{
int size = 0;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( zaxisptr->ubounds )
{
......@@ -872,7 +876,7 @@ int zaxisInqUbounds(int zaxisID, double *ubounds)
int zaxisInqWeights(int zaxisID, double *weights)
{
int size = 0;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( zaxisptr->weights )
{
......@@ -890,7 +894,7 @@ int zaxisInqWeights(int zaxisID, double *weights)
int zaxisInqLevelID(int zaxisID, double level)
{
int levelID = CDI_UNDEFID;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
int size = zaxisptr->size;
for ( int i = 0; i < size; i++ )
......@@ -930,7 +934,7 @@ The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
*/
int zaxisInqType(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->type);
}
......@@ -952,14 +956,14 @@ The function @func{zaxisInqSize} returns the size of a Z-axis.
*/
int zaxisInqSize(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->size);
}
void cdiCheckZaxis(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( zaxisInqType(zaxisID) == ZAXIS_GENERIC )
{
......@@ -995,7 +999,7 @@ void cdiCheckZaxis(int zaxisID)
void zaxisDefVct(int zaxisID, int size, const double *vct)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
if ( zaxisptr->vct == 0 )
{
......@@ -1012,28 +1016,28 @@ void zaxisDefVct(int zaxisID, int size, const double *vct)
void zaxisInqVct(int zaxisID, double *vct)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
memcpy(vct, zaxisptr->vct, (size_t)zaxisptr->vctsize * sizeof (double));
}
int zaxisInqVctSize(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->vctsize);
}
const double *zaxisInqVctPtr(int zaxisID)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
return (zaxisptr->vct);
}
void zaxisDefLbounds(int zaxisID, const double *lbounds)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
size_t size = (size_t)zaxisptr->size;
......@@ -1051,7 +1055,7 @@ void zaxisDefLbounds(int zaxisID, const double *lbounds)
void zaxisDefUbounds(int zaxisID, const double *ubounds)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
size_t size = (size_t)zaxisptr->size;
......@@ -1069,7 +1073,7 @@ void zaxisDefUbounds(int zaxisID, const double *ubounds)
void zaxisDefWeights(int zaxisID, const double *weights)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
size_t size = (size_t)zaxisptr->size;
......@@ -1087,14 +1091,14 @@ void zaxisDefWeights(int zaxisID, const double *weights)
void zaxisChangeType(int zaxisID, int zaxistype)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
zaxisptr->type = zaxistype;
}
void zaxisResize(int zaxisID, int size)
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
xassert(size >= 0);
......@@ -1108,13 +1112,13 @@ void zaxisResize(int zaxisID, int size)
int zaxisDuplicate(int zaxisID)
{
int zaxisIDnew;
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
int zaxistype = zaxisInqType(zaxisID);
int zaxissize = zaxisInqSize(zaxisID);
zaxisIDnew = zaxisCreate(zaxistype, zaxissize);
zaxis_t *zaxisptrnew = (zaxis_t *)reshGetVal(zaxisIDnew, &zaxisOps);
zaxis_t *zaxisptrnew = zaxisID2Ptr(zaxisIDnew);
zaxis_copy(zaxisptrnew, zaxisptr);
......@@ -1275,7 +1279,7 @@ void zaxisPrintKernel ( zaxis_t * zaxisptr, int index, FILE * fp )
void zaxisPrint ( int zaxisID, int index )
{
zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
zaxisPrintKernel ( zaxisptr, index, stdout );
}
......
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