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

Renamed fldavg() to fldavgw().

parent a918b7d9
......@@ -99,7 +99,7 @@ void *Fldstat(void *argument)
cdoOperatorAdd("fldmax", func_max, 0, NULL);
cdoOperatorAdd("fldsum", func_sum, 0, 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("fldstd1", func_std1, 1, NULL);
cdoOperatorAdd("fldvar", func_var, 1, NULL);
......
......@@ -554,19 +554,16 @@ void *Gridboxstat(void *argument)
cdoOperatorAdd("gridboxmin", func_min, 0, NULL);
cdoOperatorAdd("gridboxmax", func_max, 0, NULL);
cdoOperatorAdd("gridboxsum", func_sum, 0, NULL);
cdoOperatorAdd("gridboxmean", func_meanw, 0, NULL);
cdoOperatorAdd("gridboxavg", func_avg, 0, NULL);
cdoOperatorAdd("gridboxvar", func_var, 0, NULL);
cdoOperatorAdd("gridboxvar1", func_var1, 0, NULL);
cdoOperatorAdd("gridboxstd", func_std, 0, NULL);
cdoOperatorAdd("gridboxstd1", func_std1, 0, NULL);
cdoOperatorAdd("gridboxmean", func_meanw, 1, NULL);
cdoOperatorAdd("gridboxavg", func_avgw, 1, NULL);
cdoOperatorAdd("gridboxvar", func_var, 1, NULL);
cdoOperatorAdd("gridboxvar1", func_var1, 1, NULL);
cdoOperatorAdd("gridboxstd", func_std, 1, NULL);
cdoOperatorAdd("gridboxstd1", func_std1, 1, NULL);
int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID);
bool needWeights = (operfunc == func_meanw || operfunc == func_avg ||
operfunc == func_var || operfunc == func_std ||
operfunc == func_var1 || operfunc == func_std1);
bool needWeights = cdoOperatorF2(operatorID) != 0;
int streamID1 = streamOpenRead(cdoStreamName(0));
......
......@@ -55,7 +55,7 @@ void *Merstat(void *argument)
cdoOperatorAdd("mermax", func_max, 0, NULL);
cdoOperatorAdd("mersum", func_sum, 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("mervar1", func_var1, 0, NULL);
cdoOperatorAdd("merstd", func_std, 0, NULL);
......@@ -73,7 +73,7 @@ void *Merstat(void *argument)
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_var1 || operfunc == func_std1 )
needWeights = true;
......
......@@ -118,7 +118,7 @@ static func_t fun_sym_tbl[] =
{FT_FLD, 0, "fldmax", (double (*)()) fldmax},
{FT_FLD, 0, "fldsum", (double (*)()) fldsum},
{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, "fldstd1", (double (*)()) fldstd1},
{FT_FLD, 1, "fldvar", (double (*)()) fldvar},
......@@ -129,7 +129,7 @@ static func_t fun_sym_tbl[] =
{FT_VERT, 0, "vertmax", (double (*)()) fldmax},
{FT_VERT, 0, "vertsum", (double (*)()) fldsum},
{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, "vertstd1", (double (*)()) fldstd1},
{FT_VERT, 1, "vertvar", (double (*)()) fldvar},
......
......@@ -36,6 +36,7 @@ double fldfun(field_type field, int function)
case func_mean: rval = fldmean(field); break;
case func_meanw: rval = fldmeanw(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_std1: rval = fldstd1(field); break;
case func_var: rval = fldvar(field); break;
......@@ -369,6 +370,43 @@ double fldavg(field_type field)
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
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)
......
......@@ -112,6 +112,7 @@ double fldmin(field_type field);
double fldmax(field_type field);
double fldsum(field_type field);
double fldavg(field_type field);
double fldavgw(field_type field);
double fldmean(field_type field);
double fldmeanw(field_type field);
double fldstd(field_type field);
......@@ -149,8 +150,8 @@ void merfun(field_type field1, field_type *field2, const int function);
void mermin(field_type field1, field_type *field2);
void mermax(field_type field1, field_type *field2);
void mersum(field_type field1, field_type *field2);
void meravg(field_type field1, field_type *field2);
void mermean(field_type field1, field_type *field2);
void meravgw(field_type field1, field_type *field2);
void mermeanw(field_type field1, field_type *field2);
void merstd(field_type field1, field_type *field2);
void merstd1(field_type field1, field_type *field2);
void mervar(field_type field1, field_type *field2);
......
......@@ -22,12 +22,15 @@
void farcfun(field_type *field, double rconst, int function)
{
if ( function == func_add ) farcadd(field, rconst);
else if ( function == func_sub ) farcsub(field, rconst);
else if ( function == func_mul ) farcmul(field, rconst);
else if ( function == func_div ) farcdiv(field, rconst);
else if ( function == func_mod ) farmod(field, rconst);
else cdoAbort("%s: function %d not implemented!", __func__, function);
switch (function)
{
case func_add: farcadd(field, rconst); break;
case func_sub: farcsub(field, rconst); break;
case func_mul: farcmul(field, rconst); break;
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)
......
......@@ -23,16 +23,19 @@
void merfun(field_type field1, field_type *field2, int function)
{
if ( function == func_min ) mermin(field1, field2);
else if ( function == func_max ) mermax(field1, field2);
else if ( function == func_sum ) mersum(field1, field2);
else if ( function == func_meanw ) mermean(field1, field2);
else if ( function == func_avg ) meravg(field1, field2);
else if ( function == func_std ) merstd(field1, field2);
else if ( function == func_std1 ) merstd1(field1, field2);
else if ( function == func_var ) mervar(field1, field2);
else if ( function == func_var1 ) mervar1(field1, field2);
else cdoAbort("function %d not implemented!", function);
switch (function)
{
case func_min: mermin(field1, field2); break;
case func_max: mermax(field1, field2); break;
case func_sum: mersum(field1, field2); break;
case func_meanw: mermeanw(field1, field2); break;
case func_avgw: meravgw(field1, field2); break;
case func_std: merstd(field1, field2); break;
case func_std1: merstd1(field1, field2); break;
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)
}
void mermean(field_type field1, field_type *field2)
void mermeanw(field_type field1, field_type *field2)
{
long i, j, nx, ny;
int rnmiss = 0;
......@@ -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;
int rnmiss = 0;
......
......@@ -23,17 +23,20 @@
void zonfun(field_type field1, field_type *field2, int function)
{
if ( function == func_min ) zonmin(field1, field2);
else if ( function == func_max ) zonmax(field1, field2);
else if ( function == func_range ) zonrange(field1, field2);
else if ( function == func_sum ) zonsum(field1, field2);
else if ( function == func_mean ) zonmean(field1, field2);
else if ( function == func_avg ) zonavg(field1, field2);
else if ( function == func_std ) zonstd(field1, field2);
else if ( function == func_std1 ) zonstd1(field1, field2);
else if ( function == func_var ) zonvar(field1, field2);
else if ( function == func_var1 ) zonvar1(field1, field2);
else cdoAbort("function %d not implemented!", function);
switch (function)
{
case func_min: zonmin(field1, field2); break;
case func_max: zonmax(field1, field2); break;
case func_range: zonrange(field1, field2); break;
case func_sum: zonsum(field1, field2); break;
case func_mean: zonmean(field1, field2); break;
case func_avg: zonavg(field1, field2); break;
case func_std: zonstd(field1, field2); break;
case func_std1: zonstd1(field1, field2); break;
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 @@
#define func_sum 13
#define func_avg 14
#define func_mean 15
#define func_meanw 16
#define func_std 17
#define func_std1 18
#define func_var 19
#define func_var1 20
#define func_pctl 21
#define func_cor 22
#define func_covar 23
#define func_std 16
#define func_std1 17
#define func_var 18
#define func_var1 19
#define func_pctl 20
#define func_cor 21
#define func_covar 22
#define func_avgw 23
#define func_meanw 24
#define func_crps 30
#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