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

Renamed fldavg() to fldavgw().

parent a918b7d9
...@@ -94,20 +94,20 @@ void *Fldstat(void *argument) ...@@ -94,20 +94,20 @@ void *Fldstat(void *argument)
cdoInitialize(argument); cdoInitialize(argument);
cdoOperatorAdd("fldrange", func_range, 0, NULL); cdoOperatorAdd("fldrange", func_range, 0, NULL);
cdoOperatorAdd("fldmin", func_min, 0, NULL); cdoOperatorAdd("fldmin", func_min, 0, NULL);
cdoOperatorAdd("fldmax", func_max, 0, NULL); cdoOperatorAdd("fldmax", func_max, 0, NULL);
cdoOperatorAdd("fldsum", func_sum, 0, NULL); cdoOperatorAdd("fldsum", func_sum, 0, NULL);
cdoOperatorAdd("fldmean", func_meanw, 1, NULL); cdoOperatorAdd("fldmean", func_meanw, 1, NULL);
cdoOperatorAdd("fldavg", func_avg, 1, NULL); cdoOperatorAdd("fldavg", func_avgw, 1, NULL);
cdoOperatorAdd("fldstd", func_std, 1, NULL); cdoOperatorAdd("fldstd", func_std, 1, NULL);
cdoOperatorAdd("fldstd1", func_std1, 1, NULL); cdoOperatorAdd("fldstd1", func_std1, 1, NULL);
cdoOperatorAdd("fldvar", func_var, 1, NULL); cdoOperatorAdd("fldvar", func_var, 1, NULL);
cdoOperatorAdd("fldvar1", func_var1, 1, NULL); cdoOperatorAdd("fldvar1", func_var1, 1, NULL);
cdoOperatorAdd("fldpctl", func_pctl, 0, NULL); cdoOperatorAdd("fldpctl", func_pctl, 0, NULL);
int operatorID = cdoOperatorID(); int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID); int operfunc = cdoOperatorF1(operatorID);
bool needWeights = cdoOperatorF2(operatorID) != 0; bool needWeights = cdoOperatorF2(operatorID) != 0;
double pn = 0; double pn = 0;
......
...@@ -551,22 +551,19 @@ void *Gridboxstat(void *argument) ...@@ -551,22 +551,19 @@ void *Gridboxstat(void *argument)
int xinc = parameter2int(operatorArgv()[0]); int xinc = parameter2int(operatorArgv()[0]);
int yinc = parameter2int(operatorArgv()[1]); int yinc = parameter2int(operatorArgv()[1]);
cdoOperatorAdd("gridboxmin", func_min, 0, NULL); cdoOperatorAdd("gridboxmin", func_min, 0, NULL);
cdoOperatorAdd("gridboxmax", func_max, 0, NULL); cdoOperatorAdd("gridboxmax", func_max, 0, NULL);
cdoOperatorAdd("gridboxsum", func_sum, 0, NULL); cdoOperatorAdd("gridboxsum", func_sum, 0, NULL);
cdoOperatorAdd("gridboxmean", func_meanw, 0, NULL); cdoOperatorAdd("gridboxmean", func_meanw, 1, NULL);
cdoOperatorAdd("gridboxavg", func_avg, 0, NULL); cdoOperatorAdd("gridboxavg", func_avgw, 1, NULL);
cdoOperatorAdd("gridboxvar", func_var, 0, NULL); cdoOperatorAdd("gridboxvar", func_var, 1, NULL);
cdoOperatorAdd("gridboxvar1", func_var1, 0, NULL); cdoOperatorAdd("gridboxvar1", func_var1, 1, NULL);
cdoOperatorAdd("gridboxstd", func_std, 0, NULL); cdoOperatorAdd("gridboxstd", func_std, 1, NULL);
cdoOperatorAdd("gridboxstd1", func_std1, 0, NULL); cdoOperatorAdd("gridboxstd1", func_std1, 1, NULL);
int operatorID = cdoOperatorID(); int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID); int operfunc = cdoOperatorF1(operatorID);
bool needWeights = cdoOperatorF2(operatorID) != 0;
bool needWeights = (operfunc == func_meanw || operfunc == func_avg ||
operfunc == func_var || operfunc == func_std ||
operfunc == func_var1 || operfunc == func_std1);
int streamID1 = streamOpenRead(cdoStreamName(0)); int streamID1 = streamOpenRead(cdoStreamName(0));
......
...@@ -51,16 +51,16 @@ void *Merstat(void *argument) ...@@ -51,16 +51,16 @@ void *Merstat(void *argument)
cdoInitialize(argument); cdoInitialize(argument);
cdoOperatorAdd("mermin", func_min, 0, NULL); cdoOperatorAdd("mermin", func_min, 0, NULL);
cdoOperatorAdd("mermax", func_max, 0, NULL); cdoOperatorAdd("mermax", func_max, 0, NULL);
cdoOperatorAdd("mersum", func_sum, 0, NULL); cdoOperatorAdd("mersum", func_sum, 0, NULL);
cdoOperatorAdd("mermean", func_meanw, 0, NULL); cdoOperatorAdd("mermean", func_meanw, 0, NULL);
cdoOperatorAdd("meravg", func_avg, 0, NULL); cdoOperatorAdd("meravg", func_avgw, 0, NULL);
cdoOperatorAdd("mervar", func_var, 0, NULL); cdoOperatorAdd("mervar", func_var, 0, NULL);
cdoOperatorAdd("mervar1", func_var1, 0, NULL); cdoOperatorAdd("mervar1", func_var1, 0, NULL);
cdoOperatorAdd("merstd", func_std, 0, NULL); cdoOperatorAdd("merstd", func_std, 0, NULL);
cdoOperatorAdd("merstd1", func_std1, 0, NULL); cdoOperatorAdd("merstd1", func_std1, 0, NULL);
cdoOperatorAdd("merpctl", func_pctl, 0, NULL); cdoOperatorAdd("merpctl", func_pctl, 0, NULL);
int operatorID = cdoOperatorID(); int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID); int operfunc = cdoOperatorF1(operatorID);
...@@ -73,7 +73,7 @@ void *Merstat(void *argument) ...@@ -73,7 +73,7 @@ void *Merstat(void *argument)
percentile_check_number(pn); percentile_check_number(pn);
} }
if ( operfunc == func_meanw || operfunc == func_avg || if ( operfunc == func_meanw || operfunc == func_avgw ||
operfunc == func_var || operfunc == func_std || operfunc == func_var || operfunc == func_std ||
operfunc == func_var1 || operfunc == func_std1 ) operfunc == func_var1 || operfunc == func_std1 )
needWeights = true; needWeights = true;
......
...@@ -118,7 +118,7 @@ static func_t fun_sym_tbl[] = ...@@ -118,7 +118,7 @@ static func_t fun_sym_tbl[] =
{FT_FLD, 0, "fldmax", (double (*)()) fldmax}, {FT_FLD, 0, "fldmax", (double (*)()) fldmax},
{FT_FLD, 0, "fldsum", (double (*)()) fldsum}, {FT_FLD, 0, "fldsum", (double (*)()) fldsum},
{FT_FLD, 1, "fldmean", (double (*)()) fldmeanw}, {FT_FLD, 1, "fldmean", (double (*)()) fldmeanw},
{FT_FLD, 1, "fldavg", (double (*)()) fldavg}, {FT_FLD, 1, "fldavg", (double (*)()) fldavgw},
{FT_FLD, 1, "fldstd", (double (*)()) fldstd}, {FT_FLD, 1, "fldstd", (double (*)()) fldstd},
{FT_FLD, 1, "fldstd1", (double (*)()) fldstd1}, {FT_FLD, 1, "fldstd1", (double (*)()) fldstd1},
{FT_FLD, 1, "fldvar", (double (*)()) fldvar}, {FT_FLD, 1, "fldvar", (double (*)()) fldvar},
...@@ -129,7 +129,7 @@ static func_t fun_sym_tbl[] = ...@@ -129,7 +129,7 @@ static func_t fun_sym_tbl[] =
{FT_VERT, 0, "vertmax", (double (*)()) fldmax}, {FT_VERT, 0, "vertmax", (double (*)()) fldmax},
{FT_VERT, 0, "vertsum", (double (*)()) fldsum}, {FT_VERT, 0, "vertsum", (double (*)()) fldsum},
{FT_VERT, 1, "vertmean", (double (*)()) fldmeanw}, {FT_VERT, 1, "vertmean", (double (*)()) fldmeanw},
{FT_VERT, 1, "vertavg", (double (*)()) fldavg}, {FT_VERT, 1, "vertavg", (double (*)()) fldavgw},
{FT_VERT, 1, "vertstd", (double (*)()) fldstd}, {FT_VERT, 1, "vertstd", (double (*)()) fldstd},
{FT_VERT, 1, "vertstd1", (double (*)()) fldstd1}, {FT_VERT, 1, "vertstd1", (double (*)()) fldstd1},
{FT_VERT, 1, "vertvar", (double (*)()) fldvar}, {FT_VERT, 1, "vertvar", (double (*)()) fldvar},
......
...@@ -36,6 +36,7 @@ double fldfun(field_type field, int function) ...@@ -36,6 +36,7 @@ double fldfun(field_type field, int function)
case func_mean: rval = fldmean(field); break; case func_mean: rval = fldmean(field); break;
case func_meanw: rval = fldmeanw(field); break; case func_meanw: rval = fldmeanw(field); break;
case func_avg: rval = fldavg(field); break; case func_avg: rval = fldavg(field); break;
case func_avgw: rval = fldavgw(field); break;
case func_std: rval = fldstd(field); break; case func_std: rval = fldstd(field); break;
case func_std1: rval = fldstd1(field); break; case func_std1: rval = fldstd1(field); break;
case func_var: rval = fldvar(field); break; case func_var: rval = fldvar(field); break;
...@@ -369,6 +370,43 @@ double fldavg(field_type field) ...@@ -369,6 +370,43 @@ double fldavg(field_type field)
return ravg; return ravg;
} }
double fldavgw(field_type field)
{
const int nmiss = field.nmiss > 0;
const size_t len = field.size;
const double missval1 = field.missval;
const double missval2 = field.missval;
const double *restrict array = field.ptr;
const double *restrict w = field.weight;
double rsum = 0, rsumw = 0;
assert(array!=NULL);
assert(w!=NULL);
if ( nmiss )
{
for ( size_t i = 0; i < len; i++ )
if ( !DBL_IS_EQUAL(w[i], missval1) )
{
rsum = ADDMN(rsum, MULMN(w[i], array[i]));
rsumw = ADDMN(rsumw, w[i]);
}
}
else
{
for ( size_t i = 0; i < len; i++ )
{
rsum += w[i] * array[i];
rsumw += w[i];
}
}
double ravg = DIVMN(rsum, rsumw);
return ravg;
}
static static
void prevarsum(const double *restrict array, const double *restrict w, size_t len, int nmiss, void prevarsum(const double *restrict array, const double *restrict w, size_t len, int nmiss,
double missval, double *rsum, double *rsumw, double *rsumq, double *rsumwq) double missval, double *rsum, double *rsumw, double *rsumq, double *rsumwq)
......
...@@ -112,6 +112,7 @@ double fldmin(field_type field); ...@@ -112,6 +112,7 @@ double fldmin(field_type field);
double fldmax(field_type field); double fldmax(field_type field);
double fldsum(field_type field); double fldsum(field_type field);
double fldavg(field_type field); double fldavg(field_type field);
double fldavgw(field_type field);
double fldmean(field_type field); double fldmean(field_type field);
double fldmeanw(field_type field); double fldmeanw(field_type field);
double fldstd(field_type field); double fldstd(field_type field);
...@@ -149,8 +150,8 @@ void merfun(field_type field1, field_type *field2, const int function); ...@@ -149,8 +150,8 @@ void merfun(field_type field1, field_type *field2, const int function);
void mermin(field_type field1, field_type *field2); void mermin(field_type field1, field_type *field2);
void mermax(field_type field1, field_type *field2); void mermax(field_type field1, field_type *field2);
void mersum(field_type field1, field_type *field2); void mersum(field_type field1, field_type *field2);
void meravg(field_type field1, field_type *field2); void meravgw(field_type field1, field_type *field2);
void mermean(field_type field1, field_type *field2); void mermeanw(field_type field1, field_type *field2);
void merstd(field_type field1, field_type *field2); void merstd(field_type field1, field_type *field2);
void merstd1(field_type field1, field_type *field2); void merstd1(field_type field1, field_type *field2);
void mervar(field_type field1, field_type *field2); void mervar(field_type field1, field_type *field2);
......
...@@ -22,12 +22,15 @@ ...@@ -22,12 +22,15 @@
void farcfun(field_type *field, double rconst, int function) void farcfun(field_type *field, double rconst, int function)
{ {
if ( function == func_add ) farcadd(field, rconst); switch (function)
else if ( function == func_sub ) farcsub(field, rconst); {
else if ( function == func_mul ) farcmul(field, rconst); case func_add: farcadd(field, rconst); break;
else if ( function == func_div ) farcdiv(field, rconst); case func_sub: farcsub(field, rconst); break;
else if ( function == func_mod ) farmod(field, rconst); case func_mul: farcmul(field, rconst); break;
else cdoAbort("%s: function %d not implemented!", __func__, function); case func_div: farcdiv(field, rconst); break;
case func_mod: farmod(field, rconst); break;
default: cdoAbort("%s: function %d not implemented!", __func__, function);
}
} }
void farcmul(field_type *field, double rconst) void farcmul(field_type *field, double rconst)
......
...@@ -23,16 +23,19 @@ ...@@ -23,16 +23,19 @@
void merfun(field_type field1, field_type *field2, int function) void merfun(field_type field1, field_type *field2, int function)
{ {
if ( function == func_min ) mermin(field1, field2); switch (function)
else if ( function == func_max ) mermax(field1, field2); {
else if ( function == func_sum ) mersum(field1, field2); case func_min: mermin(field1, field2); break;
else if ( function == func_meanw ) mermean(field1, field2); case func_max: mermax(field1, field2); break;
else if ( function == func_avg ) meravg(field1, field2); case func_sum: mersum(field1, field2); break;
else if ( function == func_std ) merstd(field1, field2); case func_meanw: mermeanw(field1, field2); break;
else if ( function == func_std1 ) merstd1(field1, field2); case func_avgw: meravgw(field1, field2); break;
else if ( function == func_var ) mervar(field1, field2); case func_std: merstd(field1, field2); break;
else if ( function == func_var1 ) mervar1(field1, field2); case func_std1: merstd1(field1, field2); break;
else cdoAbort("function %d not implemented!", function); case func_var: mervar(field1, field2); break;
case func_var1: mervar1(field1, field2); break;
default: cdoAbort("function %d not implemented!", function);
}
} }
...@@ -167,7 +170,7 @@ void mersum(field_type field1, field_type *field2) ...@@ -167,7 +170,7 @@ void mersum(field_type field1, field_type *field2)
} }
void mermean(field_type field1, field_type *field2) void mermeanw(field_type field1, field_type *field2)
{ {
long i, j, nx, ny; long i, j, nx, ny;
int rnmiss = 0; int rnmiss = 0;
...@@ -216,7 +219,7 @@ void mermean(field_type field1, field_type *field2) ...@@ -216,7 +219,7 @@ void mermean(field_type field1, field_type *field2)
} }
void meravg(field_type field1, field_type *field2) void meravgw(field_type field1, field_type *field2)
{ {
long i, j, nx, ny; long i, j, nx, ny;
int rnmiss = 0; int rnmiss = 0;
...@@ -265,7 +268,7 @@ void meravg(field_type field1, field_type *field2) ...@@ -265,7 +268,7 @@ void meravg(field_type field1, field_type *field2)
static static
void prevarsum_mer(const double *restrict array, const double *restrict w, int nx, int ny, int nmiss, void prevarsum_mer(const double *restrict array, const double *restrict w, int nx, int ny, int nmiss,
double missval, double *restrict rsum, double *restrict rsumw, double *restrict rsumq, double *restrict rsumwq) double missval, double *restrict rsum, double *restrict rsumw, double *restrict rsumq, double *restrict rsumwq)
{ {
*rsum = 0; *rsum = 0;
*rsumq = 0; *rsumq = 0;
......
...@@ -23,17 +23,20 @@ ...@@ -23,17 +23,20 @@
void zonfun(field_type field1, field_type *field2, int function) void zonfun(field_type field1, field_type *field2, int function)
{ {
if ( function == func_min ) zonmin(field1, field2); switch (function)
else if ( function == func_max ) zonmax(field1, field2); {
else if ( function == func_range ) zonrange(field1, field2); case func_min: zonmin(field1, field2); break;
else if ( function == func_sum ) zonsum(field1, field2); case func_max: zonmax(field1, field2); break;
else if ( function == func_mean ) zonmean(field1, field2); case func_range: zonrange(field1, field2); break;
else if ( function == func_avg ) zonavg(field1, field2); case func_sum: zonsum(field1, field2); break;
else if ( function == func_std ) zonstd(field1, field2); case func_mean: zonmean(field1, field2); break;
else if ( function == func_std1 ) zonstd1(field1, field2); case func_avg: zonavg(field1, field2); break;
else if ( function == func_var ) zonvar(field1, field2); case func_std: zonstd(field1, field2); break;
else if ( function == func_var1 ) zonvar1(field1, field2); case func_std1: zonstd1(field1, field2); break;
else cdoAbort("function %d not implemented!", function); case func_var: zonvar(field1, field2); break;
case func_var1: zonvar1(field1, field2); break;
default: cdoAbort("function %d not implemented!", function);
}
} }
......
...@@ -11,14 +11,15 @@ ...@@ -11,14 +11,15 @@
#define func_sum 13 #define func_sum 13
#define func_avg 14 #define func_avg 14
#define func_mean 15 #define func_mean 15
#define func_meanw 16 #define func_std 16
#define func_std 17 #define func_std1 17
#define func_std1 18 #define func_var 18
#define func_var 19 #define func_var1 19
#define func_var1 20 #define func_pctl 20
#define func_pctl 21 #define func_cor 21
#define func_cor 22 #define func_covar 22
#define func_covar 23 #define func_avgw 23
#define func_meanw 24
#define func_crps 30 #define func_crps 30
#define func_brs 31 #define func_brs 31
......
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