Commit 074168a3 authored by Uwe Schulzweida's avatar Uwe Schulzweida

Added function expr_run_type_opr().

parent adffb038
...@@ -1740,7 +1740,7 @@ add_new_param(const char *varname, parseParamType *parse_arg, paramType *params, ...@@ -1740,7 +1740,7 @@ add_new_param(const char *varname, parseParamType *parse_arg, paramType *params,
parse_arg->cnparams++; parse_arg->cnparams++;
} }
void static nodeType *
expr_run_type_com(nodeType *p, parseParamType *parse_arg) expr_run_type_com(nodeType *p, parseParamType *parse_arg)
{ {
const auto init = parse_arg->init; const auto init = parse_arg->init;
...@@ -1761,9 +1761,18 @@ expr_run_type_com(nodeType *p, parseParamType *parse_arg) ...@@ -1761,9 +1761,18 @@ expr_run_type_com(nodeType *p, parseParamType *parse_arg)
{ {
if (cdo_cmpstr(cname, "print")) param_print(vname, params[varID], std::lround(params[parse_arg->tsID].data[0])); if (cdo_cmpstr(cname, "print")) param_print(vname, params[varID], std::lround(params[parse_arg->tsID].data[0]));
} }
return nullptr;
} }
nodeType * static nodeType *
expr_run_type_con(nodeType *p, parseParamType *parse_arg)
{
if (parse_arg->debug) cdoPrint("\tpush\tconst\t%g", p->u.con.value);
return p;
}
static nodeType *
expr_run_type_var(nodeType *p, parseParamType *parse_arg) expr_run_type_var(nodeType *p, parseParamType *parse_arg)
{ {
const auto init = parse_arg->init; const auto init = parse_arg->init;
...@@ -1881,7 +1890,7 @@ expr_run_type_var(nodeType *p, parseParamType *parse_arg) ...@@ -1881,7 +1890,7 @@ expr_run_type_var(nodeType *p, parseParamType *parse_arg)
return p; return p;
} }
nodeType * static nodeType *
expr_run_type_fun1c(nodeType *p, parseParamType *parse_arg) expr_run_type_fun1c(nodeType *p, parseParamType *parse_arg)
{ {
const auto init = parse_arg->init; const auto init = parse_arg->init;
...@@ -1905,7 +1914,7 @@ expr_run_type_fun1c(nodeType *p, parseParamType *parse_arg) ...@@ -1905,7 +1914,7 @@ expr_run_type_fun1c(nodeType *p, parseParamType *parse_arg)
return rnode; return rnode;
} }
nodeType * static nodeType *
expr_run_type_fun2c(nodeType *p, parseParamType *parse_arg) expr_run_type_fun2c(nodeType *p, parseParamType *parse_arg)
{ {
const auto init = parse_arg->init; const auto init = parse_arg->init;
...@@ -1930,7 +1939,7 @@ expr_run_type_fun2c(nodeType *p, parseParamType *parse_arg) ...@@ -1930,7 +1939,7 @@ expr_run_type_fun2c(nodeType *p, parseParamType *parse_arg)
return rnode; return rnode;
} }
nodeType * static nodeType *
expr_run_type_fun(nodeType *p, parseParamType *parse_arg) expr_run_type_fun(nodeType *p, parseParamType *parse_arg)
{ {
const auto init = parse_arg->init; const auto init = parse_arg->init;
...@@ -1971,156 +1980,118 @@ expr_run_type_fun(nodeType *p, parseParamType *parse_arg) ...@@ -1971,156 +1980,118 @@ expr_run_type_fun(nodeType *p, parseParamType *parse_arg)
return rnode; return rnode;
} }
/*
nodeType * static nodeType *
expr_run_type_(nodeType *p, parseParamType *parse_arg) expr_run_type_opr(nodeType *p, parseParamType *parse_arg)
{
const auto init = parse_arg->init;
auto params = parse_arg->params;
}
*/
nodeType *
expr_run(nodeType *p, parseParamType *parse_arg)
{ {
pointID = parse_arg->pointID;
zonalID = parse_arg->zonalID;
surfaceID = parse_arg->surfaceID;
const auto init = parse_arg->init; const auto init = parse_arg->init;
auto params = parse_arg->params; auto params = parse_arg->params;
nodeType *rnode = nullptr;
if (!p) return rnode; nodeType *rnode = nullptr;
// if (!init) { exNode(p, parse_arg); return 0; }
switch (p->type) // clang-format off
switch (p->u.opr.oper)
{ {
case typeCom: case '=':
{
expr_run_type_com(p, parse_arg);
break;
}
case typeCon:
{
if (parse_arg->debug) cdoPrint("\tpush\tconst\t%g", p->u.con.value);
rnode = p;
break;
}
case typeVar:
{
rnode = expr_run_type_var(p, parse_arg);
break;
}
case typeFun1c:
{
rnode = expr_run_type_fun1c(p, parse_arg);
break;
}
case typeFun2c:
{
rnode = expr_run_type_fun2c(p, parse_arg);
break;
}
case typeFun:
{ {
rnode = expr_run_type_fun(p, parse_arg); rnode = expr_run(p->u.opr.op[1], parse_arg);
break;
}
case typeOpr:
switch (p->u.opr.oper)
{
case '=':
{
rnode = expr_run(p->u.opr.op[1], parse_arg);
const auto varname2 = p->u.opr.op[0]->u.var.nm; const auto varname2 = p->u.opr.op[0]->u.var.nm;
if (parse_arg->debug) if (parse_arg->debug)
{ {
if (rnode && rnode->type == typeVar) if (rnode && rnode->type == typeVar)
cdoPrint("\tpop\tvar\t%s[N%zu][L%zu]", varname2, rnode->param.ngp, rnode->param.nlev); cdoPrint("\tpop\tvar\t%s[N%zu][L%zu]", varname2, rnode->param.ngp, rnode->param.nlev);
else else
cdoPrint("\tpop\tconst\t%s", varname2); cdoPrint("\tpop\tconst\t%s", varname2);
} }
//auto varID = param_search_name_size(parse_arg->nparams, params, varname2, rnode->param.ngp, rnode->param.nlev); //auto varID = param_search_name_size(parse_arg->nparams, params, varname2, rnode->param.ngp, rnode->param.nlev);
auto varID = param_search_name(parse_arg->nparams, params, varname2); auto varID = param_search_name(parse_arg->nparams, params, varname2);
if (init) if (init)
{
if (varID >= 0)
{ {
if (varID >= 0) // printf(" found %s\n", varname2);
{ if (varID < parse_arg->nvars1)
// printf(" found %s\n", varname2);
if (varID < parse_arg->nvars1)
{
if (params[varID].nlev != rnode->param.nlev)
cdoAbort("The number of layers must not change (name=%s layers: in=%zu out=%zu)!", params[varID].name,
params[varID].nlev, rnode->param.nlev);
params[varID].select = true;
parse_arg->needed[varID] = true;
}
else if (params[varID].coord)
cdoAbort("Coordinate variable %s is read only!", varname2);
/*
else
cdoWarning("Variable %s already defined!", varname2);
*/
}
else if (rnode && rnode->type == typeCon)
{
add_new_constant(varname2, parse_arg, params, rnode->param);
}
else if (p->u.opr.op[1]->type != typeCon)
{ {
add_new_param(varname2, parse_arg, params, rnode->param); if (params[varID].nlev != rnode->param.nlev)
cdoAbort("The number of layers must not change (name=%s layers: in=%zu out=%zu)!", params[varID].name,
params[varID].nlev, rnode->param.nlev);
params[varID].select = true;
parse_arg->needed[varID] = true;
} }
else if (params[varID].coord)
cdoAbort("Coordinate variable %s is read only!", varname2);
/*
else
cdoWarning("Variable %s already defined!", varname2);
*/
} }
else else if (rnode && rnode->type == typeCon)
{ {
if (varID < 0) cdoAbort("Variable >%s< not found!", varname2); add_new_constant(varname2, parse_arg, params, rnode->param);
if (params[varID].coord) cdoAbort("Coordinate variable %s is read only!", varname2);
param_meta_copy(p->param, params[varID]);
p->param.name = params[varID].name;
p->param.data = params[varID].data;
p->ltmpobj = false;
ex_copy(init, p, rnode);
params[varID].nmiss = p->param.nmiss;
} }
else if (p->u.opr.op[1]->type != typeCon)
if (rnode && rnode->ltmpobj)
{ {
node_delete(rnode); add_new_param(varname2, parse_arg, params, rnode->param);
rnode = nullptr;
} }
// else Free(rnode);
break;
}
case UMINUS:
{
rnode = ex_uminus(init, expr_run(p->u.opr.op[0], parse_arg));
break;
}
case NOT:
{
rnode = ex_not(init, expr_run(p->u.opr.op[0], parse_arg));
break;
} }
case '?': else
{ {
rnode = ex_ifelse(init, expr_run(p->u.opr.op[0], parse_arg), expr_run(p->u.opr.op[1], parse_arg), if (varID < 0) cdoAbort("Variable >%s< not found!", varname2);
expr_run(p->u.opr.op[2], parse_arg));
break; if (params[varID].coord) cdoAbort("Coordinate variable %s is read only!", varname2);
param_meta_copy(p->param, params[varID]);
p->param.name = params[varID].name;
p->param.data = params[varID].data;
p->ltmpobj = false;
ex_copy(init, p, rnode);
params[varID].nmiss = p->param.nmiss;
} }
default:
if (rnode && rnode->ltmpobj)
{ {
rnode = expr(init, p->u.opr.oper, expr_run(p->u.opr.op[0], parse_arg), expr_run(p->u.opr.op[1], parse_arg)); node_delete(rnode);
break; rnode = nullptr;
} }
} // else Free(rnode);
break; break;
}
case UMINUS: return ex_uminus(init, expr_run(p->u.opr.op[0], parse_arg));
case NOT: return ex_not(init, expr_run(p->u.opr.op[0], parse_arg));
case '?': return ex_ifelse(init, expr_run(p->u.opr.op[0], parse_arg), expr_run(p->u.opr.op[1], parse_arg),
expr_run(p->u.opr.op[2], parse_arg));
default: return expr(init, p->u.opr.oper, expr_run(p->u.opr.op[0], parse_arg), expr_run(p->u.opr.op[1], parse_arg));
} }
// clang-format on
return rnode; return rnode;
} }
nodeType *
expr_run(nodeType *p, parseParamType *parse_arg)
{
pointID = parse_arg->pointID;
zonalID = parse_arg->zonalID;
surfaceID = parse_arg->surfaceID;
if (!p) return nullptr;
// clang-format off
switch (p->type)
{
case typeCom: return expr_run_type_com(p, parse_arg);
case typeCon: return expr_run_type_con(p, parse_arg);
case typeVar: return expr_run_type_var(p, parse_arg);
case typeFun1c: return expr_run_type_fun1c(p, parse_arg);
case typeFun2c: return expr_run_type_fun2c(p, parse_arg);
case typeFun: return expr_run_type_fun(p, parse_arg);
case typeOpr: return expr_run_type_opr(p, parse_arg);
}
// clang-format on
return nullptr;
}
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