Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
cdo
Commits
c8786580
Commit
c8786580
authored
Jan 17, 2018
by
Uwe Schulzweida
Browse files
expr: added function ctimestep(), cdate() and ctime().
parent
b7886d69
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
src/Exprf.cc
View file @
c8786580
...
...
@@ -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
);
...
...
src/expr.cc
View file @
c8786580
...
...
@@ -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
\t
func
\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
;
...
...
src/expr_lex.cc
View file @
c8786580
This diff is collapsed.
Click to expand it.
src/expr_yacc.cc
View file @
c8786580
This diff is collapsed.
Click to expand it.
src/expr_yacc.y
View file @
c8786580
...
...
@@ -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;
...
...
src/remap_bilinear_scrip.cc
View file @
c8786580
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment