Commit 5696eff4 authored by Uwe Schulzweida's avatar Uwe Schulzweida

Added function expr_run_type_var_grid().

parent 074168a3
Pipeline #5506 passed with stages
in 15 minutes and 37 seconds
......@@ -1772,6 +1772,83 @@ expr_run_type_con(nodeType *p, parseParamType *parse_arg)
return p;
}
static int
expr_run_type_var_grid(const char *vnm, int coord, parseParamType *parse_arg)
{
auto params = parse_arg->params;
const auto len = strlen(vnm);
auto varname = strdup(vnm);
varname[len - 2] = 0;
const auto varID = param_search_name(parse_arg->nparams, params, varname);
if (varID == -1) cdoAbort("Coordinate %c: variable >%s< not found!", coord, varname);
const auto nvarID = parse_arg->nparams;
if (nvarID >= parse_arg->maxparams) cdoAbort("Too many parameter (limit=%d)", parse_arg->maxparams);
const auto coordID = params_get_coordID(parse_arg, coord, params[varID].gridID);
parse_arg->coords[coordID].needed = true;
const auto units = parse_arg->coords[coordID].units.data();
const auto longname = parse_arg->coords[coordID].longname.data();
params[nvarID].coord = coord;
params[nvarID].lmiss = false;
params[nvarID].name = strdup(vnm);
params[nvarID].missval = params[varID].missval;
params[nvarID].gridID = params[varID].gridID;
params[nvarID].zaxisID = parse_arg->surfaceID;
params[nvarID].steptype = TIME_CONSTANT;
params[nvarID].ngp = params[varID].ngp;
params[nvarID].nlat = params[varID].nlat;
params[nvarID].nlev = 1;
if (units) params[nvarID].units = strdup(units);
if (longname) params[nvarID].longname = strdup(longname);
parse_arg->nparams++;
parse_arg->cnparams++;
free(varname);
return nvarID;
}
static int
expr_run_type_var_zaxis(const char *vnm, int coord, parseParamType *parse_arg)
{
auto params = parse_arg->params;
const auto len = strlen(vnm);
auto varname = strdup(vnm);
varname[len - 2] = 0;
const auto varID = param_search_name(parse_arg->nparams, params, varname);
if (varID == -1) cdoAbort("Coordinate %c: variable >%s< not found!", coord, varname);
const auto nvarID = parse_arg->nparams;
if (nvarID >= parse_arg->maxparams) cdoAbort("Too many parameter (limit=%d)", parse_arg->maxparams);
const auto coordID = params_get_coordID(parse_arg, coord, params[varID].zaxisID);
parse_arg->coords[coordID].needed = true;
const auto units = parse_arg->coords[coordID].units.data();
const auto longname = parse_arg->coords[coordID].longname.data();
params[nvarID].coord = coord;
params[nvarID].lmiss = false;
params[nvarID].name = strdup(vnm);
params[nvarID].missval = params[varID].missval;
params[nvarID].gridID = parse_arg->pointID;
params[nvarID].zaxisID = params[varID].zaxisID;
params[nvarID].steptype = TIME_CONSTANT;
params[nvarID].ngp = 1;
params[nvarID].nlev = params[varID].nlev;
if (units) params[nvarID].units = strdup(units);
if (longname) params[nvarID].longname = strdup(longname);
parse_arg->nparams++;
parse_arg->cnparams++;
free(varname);
return nvarID;
}
static nodeType *
expr_run_type_var(nodeType *p, parseParamType *parse_arg)
{
......@@ -1788,76 +1865,11 @@ expr_run_type_var(nodeType *p, parseParamType *parse_arg)
{
if (coord == 'x' || coord == 'y' || coord == 'a' || coord == 'w')
{
auto varname = strdup(vnm);
varname[len - 2] = 0;
varID = param_search_name(parse_arg->nparams, params, varname);
if (varID == -1)
{
cdoAbort("Coordinate %c: variable >%s< not found!", coord, varname);
}
else
{
const auto nvarID = parse_arg->nparams;
if (nvarID >= parse_arg->maxparams) cdoAbort("Too many parameter (limit=%d)", parse_arg->maxparams);
const auto coordID = params_get_coordID(parse_arg, coord, params[varID].gridID);
parse_arg->coords[coordID].needed = true;
const auto units = parse_arg->coords[coordID].units.data();
const auto longname = parse_arg->coords[coordID].longname.data();
params[nvarID].coord = coord;
params[nvarID].lmiss = false;
params[nvarID].name = strdup(vnm);
params[nvarID].missval = params[varID].missval;
params[nvarID].gridID = params[varID].gridID;
params[nvarID].zaxisID = parse_arg->surfaceID;
params[nvarID].steptype = TIME_CONSTANT;
params[nvarID].ngp = params[varID].ngp;
params[nvarID].nlat = params[varID].nlat;
params[nvarID].nlev = 1;
if (units) params[nvarID].units = strdup(units);
if (longname) params[nvarID].longname = strdup(longname);
parse_arg->nparams++;
parse_arg->cnparams++;
varID = nvarID;
}
free(varname);
varID = expr_run_type_var_grid(vnm, coord, parse_arg);
}
else if (coord == 'z')
{
auto varname = strdup(vnm);
varname[len - 2] = 0;
varID = param_search_name(parse_arg->nparams, params, varname);
if (varID == -1)
{
cdoAbort("Coordinate %c: variable >%s< not found!", coord, varname);
}
else
{
const auto nvarID = parse_arg->nparams;
if (nvarID >= parse_arg->maxparams) cdoAbort("Too many parameter (limit=%d)", parse_arg->maxparams);
const auto coordID = params_get_coordID(parse_arg, coord, params[varID].zaxisID);
parse_arg->coords[coordID].needed = true;
const auto units = parse_arg->coords[coordID].units.data();
const auto longname = parse_arg->coords[coordID].longname.data();
params[nvarID].coord = coord;
params[nvarID].lmiss = false;
params[nvarID].name = strdup(vnm);
params[nvarID].missval = params[varID].missval;
params[nvarID].gridID = parse_arg->pointID;
params[nvarID].zaxisID = params[varID].zaxisID;
params[nvarID].steptype = TIME_CONSTANT;
params[nvarID].ngp = 1;
params[nvarID].nlev = params[varID].nlev;
if (units) params[nvarID].units = strdup(units);
if (longname) params[nvarID].longname = strdup(longname);
parse_arg->nparams++;
parse_arg->cnparams++;
varID = nvarID;
}
free(varname);
varID = expr_run_type_var_zaxis(vnm, coord, parse_arg);
}
}
}
......@@ -1898,20 +1910,18 @@ expr_run_type_fun1c(nodeType *p, parseParamType *parse_arg)
const auto funcID = get_funcID(p->u.fun1c.name);
const auto functype = fun_sym_tbl[funcID].type;
nodeType *rnode = nullptr;
if (functype == FT_1C)
{
auto fnode = expr_run(p->u.fun1c.op, parse_arg);
const auto value = p->u.fun1c.value;
rnode = fun1c(init, funcID, fnode, value, parse_arg);
return fun1c(init, funcID, fnode, value, parse_arg);
}
else
{
cdoAbort("Syntax error in call to %s(), check number of parameter!\n", p->u.fun1c.name);
}
return rnode;
return nullptr;
}
static nodeType *
......@@ -1922,21 +1932,19 @@ expr_run_type_fun2c(nodeType *p, parseParamType *parse_arg)
const auto funcID = get_funcID(p->u.fun2c.name);
const auto functype = fun_sym_tbl[funcID].type;
nodeType *rnode = nullptr;
if (functype == FT_2C)
{
auto fnode = expr_run(p->u.fun2c.op, parse_arg);
const auto value1 = p->u.fun2c.value1;
const auto value2 = p->u.fun2c.value2;
rnode = fun2c(init, funcID, fnode, value1, value2, parse_arg);
return fun2c(init, funcID, fnode, value1, value2, parse_arg);
}
else
{
cdoAbort("Syntax error in call to %s(), check number of parameter!\n", p->u.fun1c.name);
}
return rnode;
return nullptr;
}
static nodeType *
......@@ -1945,8 +1953,6 @@ expr_run_type_fun(nodeType *p, parseParamType *parse_arg)
const auto init = parse_arg->init;
auto params = parse_arg->params;
nodeType *rnode = nullptr;
const auto funcID = get_funcID(p->u.fun.name);
auto functype = fun_sym_tbl[funcID].type;
......@@ -1954,12 +1960,12 @@ expr_run_type_fun(nodeType *p, parseParamType *parse_arg)
if (functype == FT_COORD)
{
rnode = coord_fun(init, funcID, fnode, parse_arg);
return coord_fun(init, funcID, fnode, parse_arg);
}
else if (functype == FT_0)
{
const auto vartsID = parse_arg->tsID;
rnode = ex_fun0_con(init, funcID, params[vartsID].data);
return ex_fun0_con(init, funcID, params[vartsID].data);
}
else
{
......@@ -1973,12 +1979,13 @@ expr_run_type_fun(nodeType *p, parseParamType *parse_arg)
else
fnode->param.weight = parse_arg->coords[coordID].data.data();
}
rnode = ex_fun(init, funcID, fnode);
// if ( fnode->ltmpobj ) node_delete(fnode);
auto rnode = ex_fun(init, funcID, fnode);
// if (fnode->ltmpobj) node_delete(fnode);
// Free(fnode);
return rnode;
}
return rnode;
return nullptr;
}
static nodeType *
......@@ -1987,14 +1994,12 @@ expr_run_type_opr(nodeType *p, parseParamType *parse_arg)
const auto init = parse_arg->init;
auto params = parse_arg->params;
nodeType *rnode = nullptr;
// clang-format off
switch (p->u.opr.oper)
{
case '=':
{
rnode = expr_run(p->u.opr.op[1], parse_arg);
auto rnode = expr_run(p->u.opr.op[1], parse_arg);
const auto varname2 = p->u.opr.op[0]->u.var.nm;
......@@ -2068,7 +2073,7 @@ expr_run_type_opr(nodeType *p, parseParamType *parse_arg)
}
// clang-format on
return rnode;
return nullptr;
}
nodeType *
......
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