Commit 3cfe894f authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Replace array of resource handles with apply call.

parent 1d9efebb
......@@ -866,6 +866,33 @@ int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, const dou
return (differ);
}
struct varDefZAxisSearchState
{
int resIDValue;
int zaxistype;
int nlevels;
double *levels;
int lbounds;
char *longname, *units;
int ltype;
};
static enum cdiApplyRet
varDefZAxisSearch(int id, void *res, void *data)
{
struct varDefZAxisSearchState *state = data;
(void)res;
if (zaxisCompare(id, state->zaxistype, state->nlevels, state->lbounds,
state->levels, state->longname, state->units, state->ltype)
== 0)
{
state->resIDValue = id;
return CDI_APPLY_STOP;
}
else
return CDI_APPLY_GO_ON;
}
int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbounds,
double *levels1, double *levels2, int vctsize, double *vct, char *name,
......@@ -900,29 +927,22 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
if ( ! zaxisdefined )
{
reshLock();
unsigned nzaxis = cdiZaxisCount();
if ( nzaxis > 0 )
{
int *zaxisIndexList;
zaxisIndexList = (int *)xmalloc((size_t)nzaxis * sizeof (int));
cdiZaxisGetIndexList ( nzaxis, zaxisIndexList );
for (unsigned i = 0; i < nzaxis; i++ )
{
zaxisID = zaxisIndexList[i];
if ( zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, longname, units, ltype1) == 0 )
{
zaxisglobdefined = 1;
break;
}
}
free(zaxisIndexList);
}
reshUnlock();
struct varDefZAxisSearchState query = {
.zaxistype = zaxistype,
.nlevels = nlevels,
.levels = levels,
.lbounds = lbounds,
.longname = longname,
.units = units,
.ltype = ltype1,
};
if ((zaxisglobdefined
= (cdiResHFilterApply(&zaxisOps, varDefZAxisSearch, &query)
== CDI_APPLY_STOP)))
zaxisID = query.resIDValue;
nzaxis = (unsigned)vlistptr->nzaxis;
if ( mode == 1 )
for (unsigned index = 0; index < nzaxis; index++ )
if ( mode == 1 && zaxisglobdefined)
for (int index = 0; index < nzaxis; index++ )
if ( vlistptr->zaxisIDs[index] == zaxisID )
{
zaxisglobdefined = FALSE;
......
......@@ -94,7 +94,7 @@ static int zaxisGetPackSize ( void * zaxisptr, void *context);
static void zaxisPack ( void * zaxisptr, void * buffer, int size, int *pos, void *context);
static int zaxisTxCode ( void );
static const resOps zaxisOps = {
const resOps zaxisOps = {
(int (*)(void *, void *))zaxisCompareP,
zaxisDestroyP,
zaxisPrintP,
......
#ifndef _ZAXIS_H
#define _ZAXIS_H
#ifndef RESOURCE_HANDLE_H
#include "resource_handle.h"
#endif
unsigned cdiZaxisCount(void);
void cdiZaxisGetIndexList(unsigned numIDs, int IDs[numIDs]);
......@@ -12,4 +16,6 @@ zaxisUnpack(char * unpackBuffer, int unpackBufferSize,
void zaxisDefLtype2(int zaxisID, int ltype2);
extern const resOps zaxisOps;
#endif
Supports Markdown
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