Commit c8786580 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

expr: added function ctimestep(), cdate() and ctime().

parent b7886d69
......@@ -290,7 +290,7 @@ int params_add_ts(parse_param_t *parse_arg)
params[varID].gridID = parse_arg->pointID;
params[varID].zaxisID = parse_arg->surfaceID;
params[varID].steptype = TIME_VARYING;
params[varID].ngp = 1;
params[varID].ngp = 3;
params[varID].nlev = 1;
parse_arg->nparams++;
......@@ -573,7 +573,12 @@ void *Expr(void *argument)
int tsID = 0;
while ( (nrecs = pstreamInqTimestep(streamID1, tsID)) )
{
int vdate = taxisInqVdate(taxisID1);
int vtime = taxisInqVtime(taxisID1);
params[vartsID].data[0] = tsID+1;
params[vartsID].data[1] = vdate;
params[vartsID].data[2] = vtime;
taxisCopyTimestep(taxisID2, taxisID1);
pstreamDefTimestep(streamID2, tsID);
......
......@@ -37,7 +37,7 @@ static const char *tmpvnm = "_tmp_";
int pointID = -1;
int surfaceID = -1;
enum {FT_STD, FT_CONST, FT_FLD, FT_VERT, FT_COORD, FT_1C};
enum {FT_STD, FT_CONST, FT_FLD, FT_VERT, FT_COORD, FT_1C, FT_0};
#define COMPLT(x,y) ((x) < (y))
#define COMPGT(x,y) ((x) > (y))
......@@ -69,6 +69,9 @@ static double pt_ngp(paramType *p) { return p->ngp; }
static double pt_nlev(paramType *p) { return p->nlev; }
static double pt_size(paramType *p) { return p->ngp*p->nlev; }
static double pt_missval(paramType *p) { return p->missval; }
static double ts_ctimestep(double *data) { return lround(data[0]); }
static double ts_cdate(double *data) { return lround(data[1]); }
static double ts_ctime(double *data) { return lround(data[2]); }
typedef struct {
int type;
......@@ -144,6 +147,10 @@ static func_t fun_sym_tbl[] =
{FT_COORD, 0, "gridarea", NULL},
{FT_COORD, 0, "gridweight", NULL},
{FT_0, 0, "ctimestep", (double (*)()) ts_ctimestep},
{FT_0, 0, "cdate", (double (*)()) ts_cdate},
{FT_0, 0, "ctime", (double (*)()) ts_ctime},
{FT_1C, 0, "sellevel", NULL},
{FT_1C, 0, "sellevidx", NULL},
// {FT_1C, 0, "gridindex", NULL},
......@@ -775,6 +782,28 @@ nodeType *expr(int init, int oper, nodeType *p1, nodeType *p2)
return p;
}
static
nodeType *ex_fun0_con(int init, int funcID, double *data)
{
int functype = fun_sym_tbl[funcID].type;
if ( functype != FT_0 ) cdoAbort("Function %s not available for constant values!", fun_sym_tbl[funcID].name);
if ( cdoVerbose ) cdoPrint("\t%s\tfunc\t%s", ExIn[init], fun_sym_tbl[funcID].name);
nodeType *p = (nodeType*) Calloc(1, sizeof(nodeType));
p->type = typeCon;
p->ltmpobj = true;
if ( ! init )
{
double (*exprfunc)(double*) = (double (*)(double*)) fun_sym_tbl[funcID].func;
p->u.con.value = exprfunc(data);
}
return p;
}
static
nodeType *ex_fun_con(int funcID, nodeType *p1)
{
......@@ -1038,7 +1067,7 @@ nodeType *fun1c(int init, int funcID, nodeType *p1, double value, parse_param_t
static
nodeType *coord_fun(int init, int funcID, nodeType *p1, parse_param_t *parse_arg)
{
{
const char *funcname = fun_sym_tbl[funcID].name;
if ( p1->type != typeVar ) cdoAbort("Parameter of function %s() needs to be a variable!", funcname);
if ( p1->ltmpobj ) cdoAbort("Temporary objects not allowed in function %s()!", funcname);
......@@ -1645,6 +1674,11 @@ nodeType *expr_run(nodeType *p, parse_param_t *parse_arg)
{
rnode = coord_fun(init, funcID, fnode, parse_arg);
}
else if ( functype == FT_0 )
{
int vartsID = parse_arg->tsID;
rnode = ex_fun0_con(init, funcID, params[vartsID].data);
}
else
{
int functype = fun_sym_tbl[funcID].type;
......
This diff is collapsed.
This diff is collapsed.
......@@ -22,6 +22,7 @@
nodeType *expr_opr(int oper, int nops, ...);
nodeType *expr_var(char *nm);
nodeType *expr_con(double value);
nodeType *expr_fun0(char *fname);
nodeType *expr_fun(char *fname, nodeType *p);
nodeType *expr_fun1c(char *fname, nodeType *op, double value);
nodeType *expr_com(const char *cname, char *vname);
......@@ -105,6 +106,7 @@ expr:
| FUNCTION '(' expr ',' '-' CONSTANT ')' { $$ = expr_fun1c($1, $3, - $6); }
| FUNCTION '(' expr ',' CONSTANT ')' { $$ = expr_fun1c($1, $3, $5); }
| FUNCTION '(' expr ')' { $$ = expr_fun($1, $3); }
| FUNCTION '(' ')' { $$ = expr_fun0($1); }
;
ternary: expr QUESTION expr COLON expr { $$ = expr_opr('?', 3, $1, $3, $5); }
......@@ -144,6 +146,22 @@ nodeType *expr_var(char *nm)
return p;
}
nodeType *expr_fun0(char *fname)
{
nodeType *p = NULL;
/* allocate node */
size_t nodeSize = SIZEOF_NODETYPE + sizeof(funNodeType);
if ( (p = (nodeType*) Calloc(1, nodeSize)) == NULL )
yyerror(NULL, NULL, "Out of memory");
/* copy information */
p->type = typeFun;
p->u.fun.name = strdup(fname);
p->u.fun.op = NULL;
return p;
}
nodeType *expr_fun(char *fname, nodeType *op)
{
nodeType *p = NULL;
......
......@@ -375,6 +375,8 @@ void scrip_remap_bilinear(remapgrid_t *src_grid, remapgrid_t *tgt_grid, const do
struct gridsearch *gs = NULL;
if ( remap_grid_type != REMAP_GRID_TYPE_REG2D )
gs = gridsearch_create(xIsCyclic, dims, src_grid->size, src_grid->cell_center_lon, src_grid->cell_center_lat);
#else
void *gs;
#endif
size_t tgt_grid_size = tgt_grid->size;
......@@ -390,6 +392,7 @@ void scrip_remap_bilinear(remapgrid_t *src_grid, remapgrid_t *tgt_grid, const do
#ifdef HAVE_OPENMP4
#pragma omp parallel for default(none) schedule(static) reduction(+:findex) \
shared(gs) \
shared(cdoSilentMode, remap_grid_type, tgt_grid_size, src_grid, tgt_grid, src_array, tgt_array, missval)
#endif
for ( size_t tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
......
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