Commit 939c2091 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

New operator not: logical NOT (1, if x equal 0; else 0).

parent 8b908e44
2017-11-30 Uwe Schulzweida
* New operator not: logical NOT (1, if x equal 0; else 0)
2017-11-23 Uwe Schulzweida 2017-11-23 Uwe Schulzweida
* Fix read error on grid description file [Bug #8099] * Fix read error on grid description file [Bug #8099]
......
...@@ -205,6 +205,7 @@ Operator catalog: ...@@ -205,6 +205,7 @@ Operator catalog:
Math acos Arc cosine Math acos Arc cosine
Math atan Arc tangent Math atan Arc tangent
Math reci Reciprocal value Math reci Reciprocal value
Math not Logical NOT
Arithc addc Add a constant Arithc addc Add a constant
Arithc subc Subtract a constant Arithc subc Subtract a constant
Arithc mulc Multiply with a constant Arithc mulc Multiply with a constant
......
...@@ -198,7 +198,7 @@ keepaspectratio]{cdo_libdep.pdf}}% ...@@ -198,7 +198,7 @@ keepaspectratio]{cdo_libdep.pdf}}%
\end{picture} \end{picture}
\begin{flushright} \begin{flushright}
\large \textbf{Climate Data Operators \\ Version 1.9.2 \\ November 2017} \large \textbf{Climate Data Operators \\ Version 1.9.3 \\ February 2018}
\end{flushright} \end{flushright}
\vfill \vfill
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
\put(0,0.0){\line(1,0){3.95}} \put(0,0.0){\line(1,0){3.95}}
\end{picture} \end{picture}
\begin{flushright} \begin{flushright}
{\small{Climate Data Operators \\ Version 1.9.2 \\ November 2017}} {\small{Climate Data Operators \\ Version 1.9.3 \\ February 2018}}
\end{flushright} \end{flushright}
\vspace*{0mm} \vspace*{0mm}
......
...@@ -41,7 +41,7 @@ The following operators are supported: ...@@ -41,7 +41,7 @@ The following operators are supported:
<=> & less equal greater & x <=> y & -1, if x less y; 1, if x greater y; else 0 <=> & less equal greater & x <=> y & -1, if x less y; 1, if x greater y; else 0
\and & logical AND & x \and y & 1, if x and y not equal 0; else 0 \and & logical AND & x \and y & 1, if x and y not equal 0; else 0
\or & logical OR & x \or y & 1, if x or y not equal 0; else 0 \or & logical OR & x \or y & 1, if x or y not equal 0; else 0
! & logical NOT & !x & 1, if x equal 0; else 1 ! & logical NOT & !x & 1, if x equal 0; else 0
?: & ternary conditional & x ? y : z & y, if x not equal 0, else z ?: & ternary conditional & x ? y : z & y, if x not equal 0, else z
@EndTable @EndTable
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
@Section = Arithmetic @Section = Arithmetic
@Class = Arithmetic @Class = Arithmetic
@Arguments = infile outfile @Arguments = infile outfile
@Operators = abs int nint pow sqr sqrt exp ln log10 sin cos tan asin acos atan reci @Operators = abs int nint pow sqr sqrt exp ln log10 sin cos tan asin acos atan reci not
@BeginDescription @BeginDescription
This module contains some standard mathematical functions. This module contains some standard mathematical functions.
...@@ -286,6 +286,22 @@ o(t,x) = 1 / i(t,x) ...@@ -286,6 +286,22 @@ o(t,x) = 1 / i(t,x)
@EndOperator @EndOperator
@BeginOperator_not
@Title = Logical NOT
@BeginDescription
@IfMan
o(t,x) = 1, if x equal 0; else 0
@EndifMan
@IfDoc
@BeginMath
o(t,x) = 1, if x equal 0; else 0
@EndMath
@EndifDoc
@EndDescription
@EndOperator
@BeginExample @BeginExample
To calculate the square root for all field elements use: To calculate the square root for all field elements use:
@BeginVerbatim @BeginVerbatim
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
void *Math(void *argument) void *Math(void *argument)
{ {
enum {ABS, FINT, FNINT, SQR, SQRT, EXP, LN, LOG10, SIN, COS, TAN, ASIN, ACOS, ATAN, POW, RECI}; enum {ABS, FINT, FNINT, SQR, SQRT, EXP, LN, LOG10, SIN, COS, TAN, ASIN, ACOS, ATAN, POW, RECI, NOT};
int nrecs; int nrecs;
int varID, levelID; int varID, levelID;
size_t nmiss, nmiss2; size_t nmiss, nmiss2;
...@@ -68,6 +68,7 @@ void *Math(void *argument) ...@@ -68,6 +68,7 @@ void *Math(void *argument)
cdoOperatorAdd("atan", ATAN, 0, NULL); cdoOperatorAdd("atan", ATAN, 0, NULL);
cdoOperatorAdd("pow", POW, 0, NULL); cdoOperatorAdd("pow", POW, 0, NULL);
cdoOperatorAdd("reci", RECI, 0, NULL); cdoOperatorAdd("reci", RECI, 0, NULL);
cdoOperatorAdd("not", NOT, 0, NULL);
// clang-format on // clang-format on
int operatorID = cdoOperatorID(); int operatorID = cdoOperatorID();
...@@ -185,6 +186,10 @@ void *Math(void *argument) ...@@ -185,6 +186,10 @@ void *Math(void *argument)
for ( i = 0; i < gridsize; i++ ) for ( i = 0; i < gridsize; i++ )
array2[i] = DBL_IS_EQUAL(array1[i], missval1) || DBL_IS_EQUAL(array1[i], 0.) ? missval1 : 1/array1[i]; array2[i] = DBL_IS_EQUAL(array1[i], missval1) || DBL_IS_EQUAL(array1[i], 0.) ? missval1 : 1/array1[i];
break; break;
case NOT:
for ( i = 0; i < gridsize; i++ )
array2[i] = DBL_IS_EQUAL(array1[i], missval1) ? missval1 : IS_EQUAL(array1[i], 0);
break;
default: default:
cdoAbort("operator not implemented!"); cdoAbort("operator not implemented!");
break; break;
......
...@@ -48,7 +48,7 @@ enum {FT_STD, FT_CONST, FT_FLD, FT_VERT, FT_COORD, FT_1C}; ...@@ -48,7 +48,7 @@ enum {FT_STD, FT_CONST, FT_FLD, FT_VERT, FT_COORD, FT_1C};
#define COMPLEG(x,y) ((x) < (y) ? -1. : ((x) > (y))) #define COMPLEG(x,y) ((x) < (y) ? -1. : ((x) > (y)))
#define COMPAND(x,y) (IS_NOT_EQUAL(x,0) && IS_NOT_EQUAL(y,0)) #define COMPAND(x,y) (IS_NOT_EQUAL(x,0) && IS_NOT_EQUAL(y,0))
#define COMPOR(x,y) (IS_NOT_EQUAL(x,0) || IS_NOT_EQUAL(y,0)) #define COMPOR(x,y) (IS_NOT_EQUAL(x,0) || IS_NOT_EQUAL(y,0))
#define COMPNOT(x) (!IS_NOT_EQUAL(x,0)) #define COMPNOT(x) (IS_EQUAL(x,0))
#define MVCOMPLT(x,y) (DBL_IS_EQUAL((x),missval1) ? missval1 : COMPLT(x,y)) #define MVCOMPLT(x,y) (DBL_IS_EQUAL((x),missval1) ? missval1 : COMPLT(x,y))
#define MVCOMPGT(x,y) (DBL_IS_EQUAL((x),missval1) ? missval1 : COMPGT(x,y)) #define MVCOMPGT(x,y) (DBL_IS_EQUAL((x),missval1) ? missval1 : COMPGT(x,y))
#define MVCOMPLE(x,y) (DBL_IS_EQUAL((x),missval1) ? missval1 : COMPLE(x,y)) #define MVCOMPLE(x,y) (DBL_IS_EQUAL((x),missval1) ? missval1 : COMPLE(x,y))
......
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
#define MaskregionOperators {"maskregion"} #define MaskregionOperators {"maskregion"}
#define MastrfuOperators {"mastrfu"} #define MastrfuOperators {"mastrfu"}
#define MathOperators {"abs", "int", "nint", "sqr", "sqrt", "exp", "ln", "log10", "sin", \ #define MathOperators {"abs", "int", "nint", "sqr", "sqrt", "exp", "ln", "log10", "sin", \
"cos", "tan", "asin", "acos", "atan", "pow", "reci"} "cos", "tan", "asin", "acos", "atan", "pow", "reci", "not"}
#define MergeOperators {"merge"} #define MergeOperators {"merge"}
#define MergegridOperators {"mergegrid"} #define MergegridOperators {"mergegrid"}
#define MergetimeOperators {"mergetime"} #define MergetimeOperators {"mergetime"}
......
...@@ -1493,7 +1493,7 @@ std::vector<std::string> ExprHelp = { ...@@ -1493,7 +1493,7 @@ std::vector<std::string> ExprHelp = {
" <=> & less equal greater & x <=> y & -1, if x less y; 1, if x greater y; else 0 ", " <=> & less equal greater & x <=> y & -1, if x less y; 1, if x greater y; else 0 ",
" && & logical AND & x && y & 1, if x and y not equal 0; else 0", " && & logical AND & x && y & 1, if x and y not equal 0; else 0",
" || & logical OR & x || y & 1, if x or y not equal 0; else 0", " || & logical OR & x || y & 1, if x or y not equal 0; else 0",
" ! & logical NOT & !x & 1, if x equal 0; else 1", " ! & logical NOT & !x & 1, if x equal 0; else 0",
" ?: & ternary conditional & x ? y : z & y, if x not equal 0, else z ", " ?: & ternary conditional & x ? y : z & y, if x not equal 0, else z ",
" ", " ",
" The following functions are supported:", " The following functions are supported:",
...@@ -1571,7 +1571,7 @@ std::vector<std::string> ExprHelp = { ...@@ -1571,7 +1571,7 @@ std::vector<std::string> ExprHelp = {
std::vector<std::string> MathHelp = { std::vector<std::string> MathHelp = {
"NAME", "NAME",
" abs, int, nint, pow, sqr, sqrt, exp, ln, log10, sin, cos, tan, asin, acos, ", " abs, int, nint, pow, sqr, sqrt, exp, ln, log10, sin, cos, tan, asin, acos, ",
" atan, reci - Mathematical functions", " atan, reci, not - Mathematical functions",
"", "",
"SYNOPSIS", "SYNOPSIS",
" <operator> infile outfile", " <operator> infile outfile",
...@@ -1613,6 +1613,8 @@ std::vector<std::string> MathHelp = { ...@@ -1613,6 +1613,8 @@ std::vector<std::string> MathHelp = {
" o(t,x) = atan(i(t,x))", " o(t,x) = atan(i(t,x))",
" reci Reciprocal value", " reci Reciprocal value",
" o(t,x) = 1 / i(t,x)", " o(t,x) = 1 / i(t,x)",
" not Logical NOT",
" o(t,x) = 1, if x equal 0; else 0",
}; };
std::vector<std::string> ArithcHelp = { std::vector<std::string> ArithcHelp = {
......
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