Commit 003d7db8 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

varrayMinMaxMean(): refactored.

parent 0c988395
...@@ -183,12 +183,11 @@ com_stat(const std::string &arg) ...@@ -183,12 +183,11 @@ com_stat(const std::string &arg)
size_t nmiss; size_t nmiss;
streamReadVarSlice(gl_streamID, gl_varID, levelID, gl_data.data(), &nmiss); streamReadVarSlice(gl_streamID, gl_varID, levelID, gl_data.data(), &nmiss);
double fmin, fmax, fmean; auto mmm = varrayMinMaxMeanMV(gridsize, gl_data, missval);
varrayMinMaxMeanMV(gridsize, gl_data, missval, fmin, fmax, fmean);
counter_stop(&counter); counter_stop(&counter);
fprintf(stdout, "%s: z=%d t=%d size=%zu nmiss=%zu min=%.5g mean=%.5g max=%.5g [%.2fs]\n", fprintf(stdout, "%s: z=%d t=%d size=%zu nmiss=%zu min=%.5g mean=%.5g max=%.5g [%.2fs]\n",
name, levelID + 1, tsID + 1, gridsize, nmiss, fmin, fmean, fmax, counter_cputime(counter)); name, levelID + 1, tsID + 1, gridsize, nmiss, mmm.min, mmm.mean, mmm.max, counter_cputime(counter));
} }
} }
......
...@@ -33,7 +33,6 @@ Pinfo(void *process) ...@@ -33,7 +33,6 @@ Pinfo(void *process)
int nrecs; int nrecs;
int levelID; int levelID;
size_t nmiss, imiss = 0; size_t nmiss, imiss = 0;
int ivals = 0;
char varname[CDI_MAX_NAME]; char varname[CDI_MAX_NAME];
double level; double level;
double arrmin, arrmax, arrmean; double arrmin, arrmax, arrmean;
...@@ -121,13 +120,20 @@ Pinfo(void *process) ...@@ -121,13 +120,20 @@ Pinfo(void *process)
{ {
if (nmiss) if (nmiss)
{ {
ivals = varrayMinMaxMeanMV(gridsize, array1, missval, arrmin, arrmax, arrmean); auto mmm = varrayMinMaxMeanMV(gridsize, array1, missval);
arrmin = mmm.min;
arrmax = mmm.max;
arrmean = mmm.mean;
auto ivals = mmm.n;
imiss = gridsize - ivals; imiss = gridsize - ivals;
gridsize = ivals; gridsize = ivals;
} }
else else
{ {
varrayMinMaxMean(gridsize, array1, arrmin, arrmax, arrmean); auto mmm = varrayMinMaxMean(gridsize, array1);
arrmin = mmm.min;
arrmax = mmm.max;
arrmean = mmm.mean;
} }
if (gridsize) if (gridsize)
......
...@@ -346,10 +346,8 @@ Setgrid(void *process) ...@@ -346,10 +346,8 @@ Setgrid(void *process)
if (Options::cdoVerbose) if (Options::cdoVerbose)
{ {
const auto areasize = gridcellArea.size(); const auto areasize = gridcellArea.size();
auto mmm = varrayMinMaxMean(areasize, gridcellArea);
double arrmean, arrmin, arrmax; cdoPrint("gridcellAreas: %zu %#12.5g%#12.5g%#12.5g", areasize, mmm.min, mmm.mean, mmm.max);
varrayMinMaxMean(areasize, gridcellArea, arrmin, arrmax, arrmean);
cdoPrint("gridcellAreas: %zu %#12.5g%#12.5g%#12.5g", areasize, arrmin, arrmean, arrmax);
} }
} }
else if (operatorID == SETGRIDMASK) else if (operatorID == SETGRIDMASK)
......
...@@ -153,24 +153,20 @@ varrayMinMaxSumMV(const size_t len, const Varray<T> &array, const T missval, Min ...@@ -153,24 +153,20 @@ varrayMinMaxSumMV(const size_t len, const Varray<T> &array, const T missval, Min
template MinMaxSum varrayMinMaxSumMV(const size_t len, const Varray<float> &array, const float missval, MinMaxSum mms); template MinMaxSum varrayMinMaxSumMV(const size_t len, const Varray<float> &array, const float missval, MinMaxSum mms);
template MinMaxSum varrayMinMaxSumMV(const size_t len, const Varray<double> &array, const double missval, MinMaxSum mms); template MinMaxSum varrayMinMaxSumMV(const size_t len, const Varray<double> &array, const double missval, MinMaxSum mms);
void MinMaxMean
varrayMinMaxMean(const size_t len, const Varray<double> &array, double &rmin, double &rmax, double &rmean) varrayMinMaxMean(const size_t len, const Varray<double> &array)
{ {
auto mms = varrayMinMaxSum(len, array, MinMaxSum()); auto mms = varrayMinMaxSum(len, array, MinMaxSum());
rmin = mms.min; double rmean = len ? mms.sum / (double) len : 0;
rmax = mms.max; return MinMaxMean(mms.min, mms.max, rmean, len);
rmean = len ? mms.sum / (double) len : 0;
} }
size_t MinMaxMean
varrayMinMaxMeanMV(const size_t len, const Varray<double> &array, const double missval, double &rmin, double &rmax, double &rmean) varrayMinMaxMeanMV(const size_t len, const Varray<double> &array, const double missval)
{ {
auto mms = varrayMinMaxSumMV(len, array, missval, MinMaxSum()); auto mms = varrayMinMaxSumMV(len, array, missval, MinMaxSum());
rmin = mms.min; double rmean = mms.n ? mms.sum / (double) mms.n : missval;
rmax = mms.max; return MinMaxMean(mms.min, mms.max, rmean, mms.n);
rmean = mms.n ? mms.sum / (double) mms.n : missval;
return mms.n;
} }
void void
......
...@@ -22,7 +22,17 @@ ...@@ -22,7 +22,17 @@
#include <cfloat> #include <cfloat>
#include "compare.h" #include "compare.h"
/*
struct MinMax
{
double min;
double max;
size_t n;
MinMaxSum() : min(DBL_MAX), max(-DBL_MAX), n(0) {};
MinMaxSum(double rmin, double rmax, size_t rn) : min(rmin), max(rmax), n(rn) {};
MinMaxSum(double rmin, double rmax) : min(rmin), max(rmax) {};
};
*/
struct MinMaxSum struct MinMaxSum
{ {
double min; double min;
...@@ -34,6 +44,17 @@ struct MinMaxSum ...@@ -34,6 +44,17 @@ struct MinMaxSum
MinMaxSum(double rmin, double rmax, double rsum) : min(rmin), max(rmax), sum(rsum) {}; MinMaxSum(double rmin, double rmax, double rsum) : min(rmin), max(rmax), sum(rsum) {};
}; };
struct MinMaxMean
{
double min;
double max;
double mean;
size_t n;
MinMaxMean() : min(DBL_MAX), max(-DBL_MAX), mean(0), n(0) {};
MinMaxMean(double rmin, double rmax, double rmean, size_t rn) : min(rmin), max(rmax), mean(rmean), n(rn) {};
MinMaxMean(double rmin, double rmax, double rmean) : min(rmin), max(rmax), mean(rmean) {};
};
using MinMaxVal = std::pair<double, double>; using MinMaxVal = std::pair<double, double>;
template <typename T> template <typename T>
...@@ -134,8 +155,8 @@ MinMaxSum varrayMinMaxSum(size_t len, const Varray<T> &array, MinMaxSum mms); ...@@ -134,8 +155,8 @@ MinMaxSum varrayMinMaxSum(size_t len, const Varray<T> &array, MinMaxSum mms);
template <typename T> template <typename T>
MinMaxSum varrayMinMaxSumMV(size_t len, const Varray<T> &array, T missval, MinMaxSum mms); MinMaxSum varrayMinMaxSumMV(size_t len, const Varray<T> &array, T missval, MinMaxSum mms);
void varrayMinMaxMean(size_t len, const Varray<double> &array, double &rmin, double &rmax, double &rmean); MinMaxMean varrayMinMaxMean(size_t len, const Varray<double> &array);
size_t varrayMinMaxMeanMV(size_t len, const Varray<double> &array, double missval, double &rmin, double &rmax, double &rmean); MinMaxMean varrayMinMaxMeanMV(size_t len, const Varray<double> &array, double missval);
void arrayMinMaxMask(size_t len, const double *array, const Varray<int> &mask, double &rmin, double &rmax); void arrayMinMaxMask(size_t len, const double *array, const Varray<int> &mask, double &rmin, double &rmax);
......
...@@ -779,12 +779,11 @@ remapStat(int remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &r ...@@ -779,12 +779,11 @@ remapStat(int remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &r
cdoPrint("First order mapping from grid1 to grid2:"); cdoPrint("First order mapping from grid1 to grid2:");
cdoPrint("----------------------------------------------"); cdoPrint("----------------------------------------------");
double mean, minval, maxval; auto mmm = varrayMinMaxMeanMV(src_grid.size, array1, missval);
varrayMinMaxMeanMV(src_grid.size, array1, missval, minval, maxval, mean); cdoPrint(" Grid1 min,mean,max: %g %g %g", mmm.min, mmm.mean, mmm.max);
cdoPrint(" Grid1 min,mean,max: %g %g %g", minval, mean, maxval);
varrayMinMaxMeanMV(tgt_grid.size, array2, missval, minval, maxval, mean); mmm = varrayMinMaxMeanMV(tgt_grid.size, array2, missval);
cdoPrint(" Grid2 min,mean,max: %g %g %g", minval, mean, maxval); cdoPrint(" Grid2 min,mean,max: %g %g %g", mmm.min, mmm.mean, mmm.max);
// Conservation Test // Conservation Test
......
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