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

New operator fldrange: range of a field (max-min).

parent 942d12cf
......@@ -5,6 +5,7 @@
2017-01-25 Uwe Schulzweida
* New operator fldrange: range of a field (max-min)
* remap: optimzation for constant links per value
2017-01-24 Uwe Schulzweida
......
......@@ -18,6 +18,7 @@
/*
This module contains the following operators:
Fldstat fldrange Field range (max-min)
Fldstat fldmin Field minimum
Fldstat fldmax Field maximum
Fldstat fldsum Field sum
......@@ -93,16 +94,17 @@ void *Fldstat(void *argument)
cdoInitialize(argument);
cdoOperatorAdd("fldmin", func_min, 0, NULL);
cdoOperatorAdd("fldmax", func_max, 0, NULL);
cdoOperatorAdd("fldsum", func_sum, 0, NULL);
cdoOperatorAdd("fldmean", func_mean, 1, NULL);
cdoOperatorAdd("fldavg", func_avg, 1, NULL);
cdoOperatorAdd("fldstd", func_std, 1, NULL);
cdoOperatorAdd("fldstd1", func_std1, 1, NULL);
cdoOperatorAdd("fldvar", func_var, 1, NULL);
cdoOperatorAdd("fldvar1", func_var1, 1, NULL);
cdoOperatorAdd("fldpctl", func_pctl, 0, NULL);
cdoOperatorAdd("fldrange", func_range, 0, NULL);
cdoOperatorAdd("fldmin", func_min, 0, NULL);
cdoOperatorAdd("fldmax", func_max, 0, NULL);
cdoOperatorAdd("fldsum", func_sum, 0, NULL);
cdoOperatorAdd("fldmean", func_mean, 1, NULL);
cdoOperatorAdd("fldavg", func_avg, 1, NULL);
cdoOperatorAdd("fldstd", func_std, 1, NULL);
cdoOperatorAdd("fldstd1", func_std1, 1, NULL);
cdoOperatorAdd("fldvar", func_var, 1, NULL);
cdoOperatorAdd("fldvar1", func_var1, 1, NULL);
cdoOperatorAdd("fldpctl", func_pctl, 0, NULL);
int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID);
......
......@@ -29,19 +29,20 @@ double fldfun(field_t field, int function)
switch (function)
{
case func_min: rval = fldmin(field); break;
case func_max: rval = fldmax(field); break;
case func_sum: rval = fldsum(field); break;
case func_mean: rval = fldmean(field); break;
case func_avg: rval = fldavg(field); break;
case func_std: rval = fldstd(field); break;
case func_std1: rval = fldstd1(field); break;
case func_var: rval = fldvar(field); break;
case func_var1: rval = fldvar1(field); break;
case func_crps: rval = fldcrps(field); break;
case func_brs: rval = fldbrs(field); break;
case func_rank: rval = fldrank(field); break;
case func_roc: rval = fldroc(field); break;
case func_range: rval = fldrange(field); break;
case func_min: rval = fldmin(field); break;
case func_max: rval = fldmax(field); break;
case func_sum: rval = fldsum(field); break;
case func_mean: rval = fldmean(field); break;
case func_avg: rval = fldavg(field); break;
case func_std: rval = fldstd(field); break;
case func_std1: rval = fldstd1(field); break;
case func_var: rval = fldvar(field); break;
case func_var1: rval = fldvar1(field); break;
case func_crps: rval = fldcrps(field); break;
case func_brs: rval = fldbrs(field); break;
case func_rank: rval = fldrank(field); break;
case func_roc: rval = fldroc(field); break;
default: cdoAbort("%s: function %d not implemented!", __func__, function);
}
......@@ -136,6 +137,47 @@ double fldbrs(field_t field)
}
double fldrange(field_t field)
{
const int nmiss = field.nmiss > 0;
const size_t len = field.size;
const double missval = field.missval;
const double *restrict array = field.ptr;
double rmin = DBL_MAX;
double rmax = -DBL_MAX;
double range = 0;
assert(array!=NULL);
if ( nmiss )
{
for ( size_t i = 0; i < len; i++ )
if ( !DBL_IS_EQUAL(array[i], missval) )
{
if ( array[i] < rmin ) rmin = array[i];
if ( array[i] > rmax ) rmax = array[i];
}
if ( IS_EQUAL(rmin, DBL_MAX) && IS_EQUAL(rmax, -DBL_MAX) )
range = missval;
else
range = rmax-rmin;
}
else
{
//#pragma simd reduction(min:rmin)
for ( size_t i = 0; i < len; i++ )
{
if ( array[i] < rmin ) rmin = array[i];
if ( array[i] > rmax ) rmax = array[i];
}
range = rmax-rmin;
}
return range;
}
double fldmin(field_t field)
{
const int nmiss = field.nmiss > 0;
......@@ -152,14 +194,13 @@ double fldmin(field_t field)
if ( !DBL_IS_EQUAL(array[i], missval) )
if ( array[i] < rmin ) rmin = array[i];
if ( IS_EQUAL(rmin, DBL_MAX) )
rmin = missval;
if ( IS_EQUAL(rmin, DBL_MAX) ) rmin = missval;
}
else
{
//#pragma simd reduction(min:rmin)
for ( size_t i = 0; i < len; i++ )
if ( array[i] < rmin ) rmin = array[i];
if ( array[i] < rmin ) rmin = array[i];
}
return rmin;
......@@ -182,13 +223,12 @@ double fldmax(field_t field)
if ( !DBL_IS_EQUAL(array[i], missval) )
if ( array[i] > rmax ) rmax = array[i];
if ( IS_EQUAL(rmax, -DBL_MAX) )
rmax = missval;
if ( IS_EQUAL(rmax, -DBL_MAX) ) rmax = missval;
}
else
{
for ( size_t i = 0; i < len; i++ )
if ( array[i] > rmax ) rmax = array[i];
if ( array[i] > rmax ) rmax = array[i];
}
return rmax;
......
......@@ -106,6 +106,7 @@ void field_free(field_t **field, const int vlistID);
/* field.c */
double fldfun(field_t field, int function);
double fldrange(field_t field);
double fldmin(field_t field);
double fldmax(field_t field);
double fldsum(field_t field);
......
......@@ -329,7 +329,7 @@ void *Maggraph(void *argument);
#define FillmissOperators {"fillmiss", "fillmiss2"}
#define FilterOperators {"bandpass", "highpass", "lowpass"}
#define FldrmsOperators {"fldrms"}
#define FldstatOperators {"fldmin", "fldmax", "fldsum", "fldmean", "fldavg", "fldstd", "fldstd1", "fldvar", "fldvar1", "fldpctl"}
#define FldstatOperators {"fldrange", "fldmin", "fldmax", "fldsum", "fldmean", "fldavg", "fldstd", "fldstd1", "fldvar", "fldvar1", "fldpctl"}
#define FldcorOperators {"fldcor"}
#define FldcovarOperators {"fldcovar"}
#define FourierOperators {"fourier"}
......
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