Commit 07e02c46 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

expr: added command remove to remove input variables

parent 861b3ef0
......@@ -89,6 +89,7 @@ char *exprs_from_file(const char *exprf)
#define MAX_PARAMS 4096
static
paramType *params_new(int vlistID1)
{
......@@ -114,6 +115,7 @@ paramType *params_new(int vlistID1)
vlistInqVarUnits(vlistID1, varID, units);
params[varID].select = false;
params[varID].remove = false;
params[varID].coord = 0;
params[varID].gridID = gridID;
params[varID].zaxisID = zaxisID;
......@@ -245,14 +247,21 @@ void *Expr(void *argument)
int *varIDmap = (int*) Malloc(parse_arg.nparams*sizeof(int));
int vlistID2 = -1;
if ( REPLACES_VARIABLES(operatorID) )
int vlistID2 = vlistCreate();
if ( ! REPLACES_VARIABLES(operatorID) )
{
vlistID2 = vlistCreate();
}
else
{
vlistID2 = vlistDuplicate(vlistID1);
vlistClearFlag(vlistID1);
for ( int varID = 0; varID < nvars1; varID++ )
{
if ( params[varID].remove == false )
{
int nlevs = zaxisInqSize(vlistInqVarZaxis(vlistID1, varID));
for ( int levID = 0; levID < nlevs; levID++ )
vlistDefFlag(vlistID1, varID, levID, TRUE);
}
}
vlistCopyFlag(vlistID2, vlistID1);
for ( int pidx = 0; pidx < nvars1; pidx++ )
{
varIDmap[pidx] = pidx;
......@@ -262,9 +271,10 @@ void *Expr(void *argument)
for ( int pidx = 0; pidx < parse_arg.nparams; pidx++ )
{
if ( pidx < nvars1 && params[pidx].select == false ) continue;
if ( pidx >= nvars1 && *params[pidx].name == '_' ) continue;
if ( pidx < nvars1 && params[pidx].select == false ) continue;
if ( pidx >= nvars1 && params[pidx].name[0] == '_' ) continue;
if ( pidx >= nvars1 && params[pidx].coord ) continue;
int varID = vlistDefVar(vlistID2, params[pidx].gridID, params[pidx].zaxisID, params[pidx].steptype);
vlistDefVarName(vlistID2, varID, params[pidx].name);
vlistDefVarMissval(vlistID2, varID, params[pidx].missval);
......
......@@ -37,7 +37,7 @@ static const char *tmpvnm = "_tmp_";
int pointID = -1;
int surfaceID = -1;
enum {FT_STD, FT_CONST, FT_FLD, FT_VERT};
enum {FT_STD, FT_CONST, FT_FLD, FT_VERT, FT_GRID};
#define COMPLT(x,y) ((x) < (y) ? 1 : 0)
#define COMPGT(x,y) ((x) > (y) ? 1 : 0)
......@@ -117,7 +117,7 @@ static func_t fun_sym_tbl[] =
{FT_FLD, 1, "fldvar", (void (*)()) fldvar},
{FT_FLD, 1, "fldvar1", (void (*)()) fldvar1},
// cdo field functions (Reduce grid to point)
// cdo field functions (Reduce level to point)
{FT_VERT, 0, "vertmin", (void (*)()) fldmin},
{FT_VERT, 0, "vertmax", (void (*)()) fldmax},
{FT_VERT, 0, "vertsum", (void (*)()) fldsum},
......@@ -127,6 +127,8 @@ static func_t fun_sym_tbl[] =
{FT_VERT, 1, "vertstd1", (void (*)()) fldstd1},
{FT_VERT, 1, "vertvar", (void (*)()) fldvar},
{FT_VERT, 1, "vertvar1", (void (*)()) fldvar1},
// {FT_GRID, 1, "x", (void (*)()) xcoord},
};
static int NumFunc = sizeof(fun_sym_tbl) / sizeof(fun_sym_tbl[0]);
......@@ -671,6 +673,8 @@ void ex_copy(int init, nodeType *p2, nodeType *p1)
static
nodeType *expr(int init, int oper, nodeType *p1, nodeType *p2)
{
if ( p1 == NULL || p2 == NULL ) return NULL;
const char *coper = "???";
if ( cdoVerbose )
......@@ -1150,6 +1154,25 @@ nodeType *expr_run(nodeType *p, parse_param_t *parse_arg)
switch ( p->type )
{
case typeCom:
{
const char *cname = p->u.com.cname;
const char *vname = p->u.com.vname;
if ( parse_arg->debug ) cdoPrint("\tstatement\t\t%s(%s)", cname, vname);
varID = param_search_name(parse_arg->nparams, params, vname);
if ( varID == -1 ) cdoAbort("Variable %s not found, needed for statement %s(%s)!", vname, cname, vname);
if ( init )
{
if ( strcmp(cname, "remove") == 0 )
{
if ( varID < parse_arg->nvars1 ) params[varID].remove = true;
}
}
break;
}
case typeCon:
{
if ( parse_arg->debug ) cdoPrint("\tpush\tconst\t%g", p->u.con.value);
......
......@@ -28,7 +28,13 @@ int fileno(FILE *stream);
#endif
typedef enum { typeCon, typeVar, typeFun, typeOpr } nodeEnum;
typedef enum { typeCon, typeVar, typeFun, typeOpr, typeCom } nodeEnum;
// commands
typedef struct {
char *cname; // command name
char *vname; // variable name
} comNodeType;
// constants
typedef struct {
......@@ -56,6 +62,7 @@ typedef struct {
// parameter
typedef struct {
bool select;
bool remove;
int coord;
int gridID;
int zaxisID;
......@@ -80,6 +87,7 @@ typedef struct nodeTypeTag {
// union must be last entry in nodeType
// because operNodeType may dynamically increase
union {
comNodeType com; // commands
conNodeType con; // constants
varNodeType var; // variables
funNodeType fun; // functions
......
This diff is collapsed.
......@@ -56,6 +56,7 @@ M_E {
return CONSTANT;
} /* end constant */
"remove(" { return REMOVE; }
{LPH}{LPHDGT}*/[ ]*\( {
yylval->fname = strdup(yytext);
......
This diff is collapsed.
......@@ -48,32 +48,34 @@ extern int yydebug;
CONSTANT = 258,
VARIABLE = 259,
FUNCTION = 260,
AND = 261,
OR = 262,
LEG = 263,
GE = 264,
LE = 265,
EQ = 266,
NE = 267,
GT = 268,
LT = 269,
UMINUS = 270
REMOVE = 261,
AND = 262,
OR = 263,
LEG = 264,
GE = 265,
LE = 266,
EQ = 267,
NE = 268,
GT = 269,
LT = 270,
UMINUS = 271
};
#endif
/* Tokens. */
#define CONSTANT 258
#define VARIABLE 259
#define FUNCTION 260
#define AND 261
#define OR 262
#define LEG 263
#define GE 264
#define LE 265
#define EQ 266
#define NE 267
#define GT 268
#define LT 269
#define UMINUS 270
#define REMOVE 261
#define AND 262
#define OR 263
#define LEG 264
#define GE 265
#define LE 266
#define EQ 267
#define NE 268
#define GT 269
#define LT 270
#define UMINUS 271
/* Value type. */
......
......@@ -21,6 +21,7 @@ nodeType *expr_opr(int oper, int nops, ...);
nodeType *expr_var(char *nm);
nodeType *expr_con(double value);
nodeType *expr_fun(char *fname, nodeType *p);
nodeType *expr_com(const char *cname, char *vname);
void freeNode(nodeType *p);
int expr_run(nodeType *p, parse_param_t *parse_arg);
......@@ -38,6 +39,7 @@ int expr_run(nodeType *p, parse_param_t *parse_arg);
%token <cvalue> CONSTANT
%token <varnm> VARIABLE
%token <fname> FUNCTION
%token REMOVE
%left AND OR
%left LEG GE LE EQ NE GT LT
......@@ -65,6 +67,7 @@ stmt:
| expr ';' { $$ = $1; }
| VARIABLE '=' expr ';' { $$ = expr_opr('=', 2, expr_var($1), $3); }
| VARIABLE ';' { $$ = expr_opr('=', 2, expr_var($1), expr_var($1)); } /* conflicts: 1 shift/reduce */
| REMOVE VARIABLE ')' ';' { $$ = expr_com("remove", $2); }
| '{' stmt_list '}' { $$ = $2; }
;
......@@ -146,6 +149,22 @@ nodeType *expr_fun(char *fname, nodeType *op)
return p;
}
nodeType *expr_com(const char *cname, char *vname)
{
nodeType *p = NULL;
/* allocate node */
size_t nodeSize = SIZEOF_NODETYPE + sizeof(comNodeType);
if ( (p = (nodeType*) Calloc(1, nodeSize)) == NULL )
yyerror(NULL, NULL, "Out of memory");
/* copy information */
p->type = typeCom;
p->u.com.cname = strdup(cname);
p->u.com.vname = strdup(vname);
return p;
}
nodeType *expr_opr(int oper, int nops, ...)
{
nodeType *p = NULL;
......
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