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

Expr: added function isMissing(x).

parent f4e2e86b
2019-10-15 Uwe Schulzweida
2019-10-29 Uwe Schulzweida
* Using CDI library version 1.9.8
* Version 1.9.8 release
2019-10-21 Uwe Schulzweida
* Expr: added function isMissing(x)
2019-10-18 Uwe Schulzweida
* ensavg: Wrong result if data contains missing values (same result as ensmean)
......
......@@ -3,12 +3,12 @@ CDO NEWS
Improvement
Version 1.9.8 (15 October 2019):
Version 1.9.8 (29 October 2019):
New features:
* Proj 4 to 6 API Migration
* smooth/smooth9: Added support for gridtype PROJECTION [Feature #9202]
* Expr: Added function rand(x)
* Expr: Added function rand(x) and isMissing(x)
* Remap: Added support for Gaussian reduced grids
* trend, detrend: Added parameter equal=false for unequal timesteps
New operators:
......
......@@ -49,7 +49,7 @@ The following functions are supported:
Math intrinsics:
@BeginList log10(x)
@BeginList isMissing(x)
@Item = abs(x)
Absolute value of x
@Item = floor(x)
......@@ -90,6 +90,8 @@ Convert x from degrees to radians
Convert x from radians to degrees
@Item = rand(x)
Replace x by pseudo-random numbers in the range of 0 to 1
@Item = isMissing(x)
Returns 1 where x is missing
@EndList
Coordinates:
......
......@@ -74,6 +74,7 @@ static double f_rand(const double x) { (void)x; return ((double) rand()) / ((dou
static double f_sqr(const double x) { return x * x; }
static double f_rad(const double x) { return x * M_PI / 180.; }
static double f_deg(const double x) { return x * 180. / M_PI; }
static double f_isMissval(const double x) { (void)x; return 0; }
static double pt_ngp(const paramType *p) { return p->ngp; }
static double pt_nlev(const paramType *p) { return p->nlev; }
static double pt_size(const paramType *p) { return p->ngp * p->nlev; }
......@@ -129,6 +130,7 @@ static func_t fun_sym_tbl[] = {
{ FT_STD, 0, "sqr", reinterpret_cast<void (*)(void)>(&f_sqr) },
{ FT_STD, 0, "rad", reinterpret_cast<void (*)(void)>(&f_rad) },
{ FT_STD, 0, "deg", reinterpret_cast<void (*)(void)>(&f_deg) },
{ FT_STD, 0, "isMissval", reinterpret_cast<void (*)(void)>(&f_isMissval) },
// constant functions
{ FT_CONST, 0, "ngp", reinterpret_cast<void (*)(void)>(&pt_ngp) }, // number of horizontal grid points
......@@ -818,6 +820,46 @@ ex_fun_con(const int funcID, nodeType *p1)
return p;
}
static void
ex_fun_std(const int funcID, size_t ngp, size_t nlev, size_t nmiss, double missval, double *p1data, double *pdata)
{
double (*exprfunc)(double) = (double (*)(double)) fun_sym_tbl[funcID].func;
if (nmiss)
{
if (cstrIsEqual(fun_sym_tbl[funcID].name, "isMissval"))
{
for (size_t i = 0; i < ngp * nlev; i++)
{
pdata[i] = DBL_IS_EQUAL(p1data[i], missval);
}
}
else
{
for (size_t i = 0; i < ngp * nlev; i++)
{
errno = -1;
pdata[i] = DBL_IS_EQUAL(p1data[i], missval) ? missval : exprfunc(p1data[i]);
if (errno == EDOM || errno == ERANGE)
pdata[i] = missval;
else if (std::isnan(pdata[i]))
pdata[i] = missval;
}
}
}
else
{
for (size_t i = 0; i < ngp * nlev; i++)
{
errno = -1;
pdata[i] = exprfunc(p1data[i]);
if (errno == EDOM || errno == ERANGE)
pdata[i] = missval;
else if (std::isnan(pdata[i]))
pdata[i] = missval;
}
}
}
static nodeType *
ex_fun_var(const int init, const int funcID, nodeType *p1)
{
......@@ -871,31 +913,7 @@ ex_fun_var(const int init, const int funcID, nodeType *p1)
if (functype == FT_STD)
{
double (*exprfunc)(double) = (double (*)(double)) fun_sym_tbl[funcID].func;
if (nmiss)
{
for (size_t i = 0; i < ngp * nlev; i++)
{
errno = -1;
pdata[i] = DBL_IS_EQUAL(p1data[i], missval) ? missval : exprfunc(p1data[i]);
if (errno == EDOM || errno == ERANGE)
pdata[i] = missval;
else if (std::isnan(pdata[i]))
pdata[i] = missval;
}
}
else
{
for (size_t i = 0; i < ngp * nlev; i++)
{
errno = -1;
pdata[i] = exprfunc(p1data[i]);
if (errno == EDOM || errno == ERANGE)
pdata[i] = missval;
else if (std::isnan(pdata[i]))
pdata[i] = missval;
}
}
ex_fun_std(funcID, ngp, nlev, nmiss, missval, p1data, pdata);
}
else if (functype == FT_FLD)
{
......
......@@ -1566,26 +1566,27 @@ static const std::vector<std::string> ExprHelp = {
" ",
" Math intrinsics:",
" ",
" abs(x) " " Absolute value of x",
" floor(x)" " Round to largest integral value not greater than x",
" ceil(x) " " Round to smallest integral value not less than x",
" float(x)" " 32-bit float value of x",
" int(x) " " Integer value of x",
" nint(x) " " Nearest integer value of x",
" sqr(x) " " Square of x",
" sqrt(x) " " Square Root of x",
" exp(x) " " Exponential of x",
" ln(x) " " Natural logarithm of x",
" log10(x)" " Base 10 logarithm of x",
" sin(x) " " Sine of x, where x is specified in radians",
" cos(x) " " Cosine of x, where x is specified in radians",
" tan(x) " " Tangent of x, where x is specified in radians",
" asin(x) " " Arc-sine of x, where x is specified in radians",
" acos(x) " " Arc-cosine of x, where x is specified in radians",
" atan(x) " " Arc-tangent of x, where x is specified in radians",
" rad(x) " " Convert x from degrees to radians",
" deg(x) " " Convert x from radians to degrees",
" rand(x) " " Replace x by pseudo-random numbers in the range of 0 to 1 ",
" abs(x) " " Absolute value of x",
" floor(x) " " Round to largest integral value not greater than x",
" ceil(x) " " Round to smallest integral value not less than x",
" float(x) " " 32-bit float value of x",
" int(x) " " Integer value of x",
" nint(x) " " Nearest integer value of x",
" sqr(x) " " Square of x",
" sqrt(x) " " Square Root of x",
" exp(x) " " Exponential of x",
" ln(x) " " Natural logarithm of x",
" log10(x) " " Base 10 logarithm of x",
" sin(x) " " Sine of x, where x is specified in radians",
" cos(x) " " Cosine of x, where x is specified in radians",
" tan(x) " " Tangent of x, where x is specified in radians",
" asin(x) " " Arc-sine of x, where x is specified in radians",
" acos(x) " " Arc-cosine of x, where x is specified in radians",
" atan(x) " " Arc-tangent of x, where x is specified in radians",
" rad(x) " " Convert x from degrees to radians",
" deg(x) " " Convert x from radians to degrees",
" rand(x) " " Replace x by pseudo-random numbers in the range of 0 to 1 ",
" isMissing(x)" " Returns 1 where x is missing",
" ",
" Coordinates:",
" ",
......
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