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,31 +1772,17 @@ expr_run_type_con(nodeType *p, parseParamType *parse_arg)
return p;
}
static nodeType *
expr_run_type_var(nodeType *p, parseParamType *parse_arg)
static int
expr_run_type_var_grid(const char *vnm, int coord, parseParamType *parse_arg)
{
const auto init = parse_arg->init;
auto params = parse_arg->params;
const auto vnm = p->u.var.nm;
auto varID = param_search_name(parse_arg->nparams, params, vnm);
if (varID == -1 && init)
{
const auto len = strlen(vnm);
const auto coord = vnm[len - 1];
if (len > 2 && vnm[len - 2] == '.')
{
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 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);
......@@ -1819,21 +1805,23 @@ expr_run_type_var(nodeType *p, parseParamType *parse_arg)
if (longname) params[nvarID].longname = strdup(longname);
parse_arg->nparams++;
parse_arg->cnparams++;
varID = nvarID;
}
free(varname);
}
else if (coord == 'z')
{
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;
varID = param_search_name(parse_arg->nparams, params, varname);
if (varID == -1)
{
cdoAbort("Coordinate %c: variable >%s< not found!", coord, varname);
}
else
{
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);
......@@ -1855,9 +1843,33 @@ expr_run_type_var(nodeType *p, parseParamType *parse_arg)
if (longname) params[nvarID].longname = strdup(longname);
parse_arg->nparams++;
parse_arg->cnparams++;
varID = nvarID;
}
free(varname);
return nvarID;
}
static nodeType *
expr_run_type_var(nodeType *p, parseParamType *parse_arg)
{
const auto init = parse_arg->init;
auto params = parse_arg->params;
const auto vnm = p->u.var.nm;
auto varID = param_search_name(parse_arg->nparams, params, vnm);
if (varID == -1 && init)
{
const auto len = strlen(vnm);
const auto coord = vnm[len - 1];
if (len > 2 && vnm[len - 2] == '.')
{
if (coord == 'x' || coord == 'y' || coord == 'a' || coord == 'w')
{
varID = expr_run_type_var_grid(vnm, coord, parse_arg);
}
else if (coord == 'z')
{
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