Commit 2e3eadb6 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

expr: added function add_new_param().

parent 1e9e4f11
......@@ -425,6 +425,17 @@ void setDateAndTime(paramType &varts, int calendar, int tsID, int64_t vdate0, in
varts.data[CHOUR] = hour;
}
static void
addOperators(void)
{
// clang-format off
cdoOperatorAdd("expr", 1, 1, "expressions");
cdoOperatorAdd("exprf", 1, 0, "expr script filename");
cdoOperatorAdd("aexpr", 0, 1, "expressions");
cdoOperatorAdd("aexprf", 0, 0, "expr script filename");
// clang-format on
}
void *
Expr(void *process)
{
......@@ -436,12 +447,7 @@ Expr(void *process)
parseParamType parse_arg = {};
yyset_extra(&parse_arg, scanner);
// clang-format off
cdoOperatorAdd("expr", 1, 1, "expressions");
cdoOperatorAdd("exprf", 1, 0, "expr script filename");
cdoOperatorAdd("aexpr", 0, 1, "expressions");
cdoOperatorAdd("aexprf", 0, 0, "expr script filename");
// clang-format on
addOperators();
const auto operatorID = cdoOperatorID();
const bool replacesVariables = cdoOperatorF1(operatorID);
......@@ -721,11 +727,9 @@ Expr(void *process)
{
const auto pidx = varIDmap[varID];
if (pidx < nvars1) continue;
const auto ngp = params[pidx].ngp;
const auto nlev = params[pidx].nlev;
params[pidx].nmiss = 0;
varrayFill(ngp * nlev, params[pidx].data, 0.0);
varrayFill(params[pidx].ngp * params[pidx].nlev, params[pidx].data, 0.0);
}
parse_arg.cnparams = vartsID + 1;
......
......@@ -1692,6 +1692,23 @@ param_search_name_rev2(const int nparam, const paramType *params, const char *na
return varID;
}
static void
add_new_param(const char *varname, parseParamType *parse_arg, paramType *params, const paramType &param)
{
// printf(" create %s\n", varname);
int varID = parse_arg->nparams;
if (varID >= parse_arg->maxparams) cdoAbort("Too many parameter (limit=%d)", parse_arg->maxparams);
param_meta_copy(params[varID], param);
params[varID].lmiss = param.lmiss;
params[varID].name = strdup(varname);
params[varID].nmiss = param.nmiss;
if (param.units) params[varID].units = strdup(param.units);
if (param.longname) params[varID].longname = strdup(param.longname);
parse_arg->nparams++;
parse_arg->cnparams++;
}
nodeType *
expr_run(nodeType *p, parseParamType *parse_arg)
{
......@@ -1978,8 +1995,8 @@ expr_run(nodeType *p, parseParamType *parse_arg)
if (init)
{
// printf("%s: type %d %d %d\n", varname2, rnode->type, p->u.opr.op[0]->type, p->u.opr.op[1]->type);
// XXX printf("%s: ngp %zu nlev %zu gID %d zID %d\n", varname2, rnode->param.ngp, rnode->param.nlev,
// rnode->param.gridID, rnode->param.zaxisID);
// printf("%s: ngp %zu nlev %zu gID %d zID %d\n", varname2, rnode->param.ngp, rnode->param.nlev,
// rnode->param.gridID, rnode->param.zaxisID);
// varID = param_search_name_rev2(parse_arg->nparams, params, varname2, rnode->param.gridID, rnode->param.zaxisID);
varID = param_search_name_rev(parse_arg->nparams, params, varname2);
if (varID >= 0)
......@@ -2018,18 +2035,7 @@ expr_run(nodeType *p, parseParamType *parse_arg)
}
else if (p->u.opr.op[1]->type != typeCon)
{
// printf(" create %s\n", varname2);
varID = parse_arg->nparams;
if (varID >= parse_arg->maxparams) cdoAbort("Too many parameter (limit=%d)", parse_arg->maxparams);
param_meta_copy(params[varID], rnode->param);
params[varID].lmiss = rnode->param.lmiss;
params[varID].name = strdup(varname2);
params[varID].nmiss = rnode->param.nmiss;
if (rnode->param.units) params[varID].units = strdup(rnode->param.units);
if (rnode->param.longname) params[varID].longname = strdup(rnode->param.longname);
parse_arg->nparams++;
parse_arg->cnparams++;
add_new_param(varname2, parse_arg, params, rnode->param);
}
}
else
......
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