Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
cdo
Commits
0eca0206
Commit
0eca0206
authored
10 years ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
expr: added support for operator ?: (short ifelse)
parent
9970a5b0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ChangeLog
+1
-0
1 addition, 0 deletions
ChangeLog
src/expr.c
+76
-27
76 additions, 27 deletions
src/expr.c
src/expr_yacc.c
+424
-591
424 additions, 591 deletions
src/expr_yacc.c
src/expr_yacc.h
+26
-44
26 additions, 44 deletions
src/expr_yacc.h
with
527 additions
and
662 deletions
ChangeLog
+
1
−
0
View file @
0eca0206
...
...
@@ -4,6 +4,7 @@
2015-03-25 Uwe Schulzweida
* expr: added support for operator ?: (short ifelse)
* eof, eof3d: use area weights instead of no weights
* vertmean, vertavg: changed to weighted means if layer bounds are available
...
...
This diff is collapsed.
Click to expand it.
src/expr.c
+
76
−
27
View file @
0eca0206
...
...
@@ -683,30 +683,75 @@ nodeType *ex_ifelse(nodeType *p1, nodeType *p2, nodeType *p3)
{
if
(
cdoVerbose
)
printf
(
"
\t
%s ? %s : %s
\n
"
,
p1
->
u
.
var
.
nm
,
p2
->
u
.
var
.
nm
,
p3
->
u
.
var
.
nm
);
if
(
p1
->
type
==
typeCon
)
cdoAbort
(
"First expression is a constant but must be a variable!"
);
if
(
p2
->
type
==
typeCon
)
cdoAbort
(
"Second expression is a constant but must be a variable!"
);
if
(
p2
->
type
==
typeCon
)
cdoAbort
(
"Third expression is a constant but must be a variable!"
);
if
(
p1
->
type
==
typeCon
)
cdoAbort
(
"expr?expr:expr: First expression is a constant but must be a variable!"
);
int
nmiss1
=
p1
->
nmiss
;
double
missval1
=
p1
->
missval
;
double
missval2
=
p2
->
missval
;
double
missval3
=
p3
->
missval
;
long
ngp1
=
gridInqSize
(
p1
->
gridID
);
long
ngp2
=
gridInqSize
(
p2
->
gridID
);
long
ngp3
=
gridInqSize
(
p3
->
gridID
);
if
(
ngp1
!=
ngp2
)
cdoAbort
(
"Number of grid points differ. ngp1 = %ld, ngp2 = %ld"
,
ngp1
,
ngp2
);
if
(
ngp1
!=
ngp3
)
cdoAbort
(
"Number of grid points differ. ngp1 = %ld, ngp3 = %ld"
,
ngp1
,
ngp3
);
long
nlev1
=
zaxisInqSize
(
p1
->
zaxisID
);
double
missval1
=
p1
->
missval
;
double
*
pdata1
=
p1
->
data
;
long
ngp
=
ngp1
;
long
nlev
=
nlev1
;
nodeType
*
px
=
p1
;
long
nlev1
=
zaxisInqSize
(
p1
->
zaxisID
);
long
nlev2
=
zaxisInqSize
(
p2
->
zaxisID
);
long
nlev3
=
zaxisInqSize
(
p3
->
zaxisID
);
double
missval2
=
missval1
;
double
*
pdata2
;
long
ngp2
=
1
;
long
nlev2
=
1
;
if
(
p2
->
type
==
typeCon
)
{
pdata2
=
&
p2
->
u
.
con
.
value
;
}
else
{
ngp2
=
gridInqSize
(
p2
->
gridID
);
nlev2
=
zaxisInqSize
(
p2
->
zaxisID
);
missval2
=
p2
->
missval
;
pdata2
=
p2
->
data
;
if
(
ngp2
>
1
&&
ngp2
!=
ngp1
)
cdoAbort
(
"expr?expr:expr: Number of grid points differ. ngp1 = %ld, ngp2 = %ld"
,
ngp1
,
ngp2
);
if
(
nlev2
>
1
&&
nlev2
!=
nlev
)
{
if
(
nlev
==
1
)
{
nlev
=
nlev2
;
px
=
p2
;
}
else
cdoAbort
(
"expr?expr:expr: Number of levels differ. nlev = %ld, nlev2 = %ld"
,
nlev
,
nlev2
);
}
}
if
(
nlev1
!=
nlev2
)
cdoAbort
(
"Number of levels differ. nlev1 = %ld, nlev2 = %ld"
,
nlev1
,
nlev2
);
if
(
nlev1
!=
nlev3
)
cdoAbort
(
"Number of levels differ. nlev1 = %ld, nlev3 = %ld"
,
nlev1
,
nlev3
);
double
missval3
=
missval1
;
double
*
pdata3
;
long
ngp3
=
1
;
long
nlev3
=
1
;
if
(
p3
->
type
==
typeCon
)
{
pdata3
=
&
p3
->
u
.
con
.
value
;
}
else
{
ngp3
=
gridInqSize
(
p3
->
gridID
);
nlev3
=
zaxisInqSize
(
p3
->
zaxisID
);
missval3
=
p3
->
missval
;
pdata3
=
p3
->
data
;
if
(
ngp3
>
1
&&
ngp3
!=
ngp1
)
cdoAbort
(
"expr?expr:expr: Number of grid points differ. ngp1 = %ld, ngp3 = %ld"
,
ngp1
,
ngp3
);
if
(
nlev3
>
1
&&
nlev3
!=
nlev
)
{
if
(
nlev
==
1
)
{
nlev
=
nlev3
;
px
=
p3
;
}
else
cdoAbort
(
"expr?expr:expr: Number of levels differ. nlev = %ld, nlev3 = %ld"
,
nlev
,
nlev3
);
}
}
nodeType
*
p
=
(
nodeType
*
)
malloc
(
sizeof
(
nodeType
));
...
...
@@ -714,10 +759,9 @@ nodeType *ex_ifelse(nodeType *p1, nodeType *p2, nodeType *p3)
p
->
tmpvar
=
1
;
p
->
u
.
var
.
nm
=
strdupx
(
"tmp"
);
long
nlev
=
nlev1
;
p
->
gridID
=
p1
->
gridID
;
p
->
zaxisID
=
p1
->
zaxisID
;
p
->
missval
=
p1
->
missval
;
p
->
gridID
=
px
->
gridID
;
p
->
zaxisID
=
px
->
zaxisID
;
p
->
missval
=
px
->
missval
;
p
->
data
=
(
double
*
)
malloc
(
ngp
*
nlev
*
sizeof
(
double
));
...
...
@@ -736,19 +780,24 @@ nodeType *ex_ifelse(nodeType *p1, nodeType *p2, nodeType *p3)
if
(
nlev3
==
1
)
loff3
=
0
;
else
loff3
=
k
*
ngp
;
const
double
*
restrict
idat1
=
p
1
->
data
+
loff1
;
const
double
*
restrict
idat2
=
p
2
->
data
+
loff2
;
const
double
*
restrict
idat3
=
p
3
->
data
+
loff3
;
const
double
*
restrict
idat1
=
pdata
1
+
loff1
;
const
double
*
restrict
idat2
=
pdata
2
+
loff2
;
const
double
*
restrict
idat3
=
pdata
3
+
loff3
;
double
*
restrict
odat
=
p
->
data
+
loff
;
double
ival2
=
idat2
[
0
];
double
ival3
=
idat3
[
0
];
for
(
long
i
=
0
;
i
<
ngp
;
++
i
)
{
if
(
nmiss1
&&
DBL_IS_EQUAL
(
idat1
[
i
],
missval1
)
)
if
(
ngp2
>
1
)
ival2
=
idat2
[
i
];
if
(
ngp3
>
1
)
ival3
=
idat3
[
i
];
if
(
nmiss1
&&
DBL_IS_EQUAL
(
idat1
[
i
],
missval1
)
)
odat
[
i
]
=
missval1
;
else
if
(
IS_NOT_EQUAL
(
idat1
[
i
],
0
)
)
odat
[
i
]
=
DBL_IS_EQUAL
(
i
dat2
[
i
],
missval2
)
?
missval1
:
i
dat2
[
i
]
;
odat
[
i
]
=
DBL_IS_EQUAL
(
i
val2
,
missval2
)
?
missval1
:
i
val2
;
else
odat
[
i
]
=
DBL_IS_EQUAL
(
i
dat3
[
i
],
missval3
)
?
missval1
:
i
dat3
[
i
]
;
odat
[
i
]
=
DBL_IS_EQUAL
(
i
val3
,
missval3
)
?
missval1
:
i
val3
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/expr_yacc.c
+
424
−
591
View file @
0eca0206
This diff is collapsed.
Click to expand it.
src/expr_yacc.h
+
26
−
44
View file @
0eca0206
/* A Bison parser, made by GNU Bison
2.7.12-4996
. */
/* A Bison parser, made by GNU Bison
3.0.4
. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-201
3
Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-201
5
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
...
...
@@ -26,13 +26,13 @@
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_EXPR_YACC_H_INCLUDED
# define YY_YY_EXPR_YACC_H_INCLUDED
/*
Enablin
g traces. */
/*
Debu
g traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
...
...
@@ -40,55 +40,37 @@
extern
int
yydebug
;
#endif
/* Token
s
. */
/* Token
type
. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum
yytokentype
{
CONSTANT
=
258
,
VARIABLE
=
259
,
FUNCTION
=
260
,
NE
=
261
,
EQ
=
262
,
LE
=
263
,
GE
=
264
,
LEG
=
265
,
UMINUS
=
266
};
enum
yytokentype
{
CONSTANT
=
258
,
VARIABLE
=
259
,
FUNCTION
=
260
,
LEG
=
261
,
GE
=
262
,
LE
=
263
,
EQ
=
264
,
NE
=
265
,
UMINUS
=
266
};
#endif
/* Tokens. */
#define CONSTANT 258
#define VARIABLE 259
#define FUNCTION 260
#define
NE
261
#define E
Q
262
#define
LEG
261
#define
G
E 262
#define LE 263
#define
G
E 264
#define
LEG
265
#define E
Q
264
#define
NE
265
#define UMINUS 266
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
# define yystype YYSTYPE
/* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int
yyparse
(
void
*
YYPARSE_PARAM
);
#else
int
yyparse
();
#endif
#else
/* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int
yyparse
(
parse_parm_t
*
parse_arg
,
void
*
scanner
);
#else
int
yyparse
();
#endif
#endif
/* ! YYPARSE_PARAM */
#endif
/* !YY_YY_EXPR_YACC_H_INCLUDED */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment