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)
size_t nmiss;
streamReadVarSlice(gl_streamID, gl_varID, levelID, gl_data.data(), &nmiss);
double fmin, fmax, fmean;
varrayMinMaxMeanMV(gridsize, gl_data, missval, fmin, fmax, fmean);
auto mmm = varrayMinMaxMeanMV(gridsize, gl_data, missval);
counter_stop(&counter);
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)
int nrecs;
int levelID;
size_t nmiss, imiss = 0;
int ivals = 0;
char varname[CDI_MAX_NAME];
double level;
double arrmin, arrmax, arrmean;
......@@ -121,13 +120,20 @@ Pinfo(void *process)
{
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;
gridsize = ivals;
}
else
{
varrayMinMaxMean(gridsize, array1, arrmin, arrmax, arrmean);
auto mmm = varrayMinMaxMean(gridsize, array1);
arrmin = mmm.min;
arrmax = mmm.max;
arrmean = mmm.mean;
}
if (gridsize)
......
......@@ -346,10 +346,8 @@ Setgrid(void *process)
if (Options::cdoVerbose)
{
const auto areasize = gridcellArea.size();
double arrmean, arrmin, arrmax;
varrayMinMaxMean(areasize, gridcellArea, arrmin, arrmax, arrmean);
cdoPrint("gridcellAreas: %zu %#12.5g%#12.5g%#12.5g", areasize, arrmin, arrmean, arrmax);
auto mmm = varrayMinMaxMean(areasize, gridcellArea);
cdoPrint("gridcellAreas: %zu %#12.5g%#12.5g%#12.5g", areasize, mmm.min, mmm.mean, mmm.max);
}
}
else if (operatorID == SETGRIDMASK)
......
......@@ -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<double> &array, const double missval, MinMaxSum mms);
void
varrayMinMaxMean(const size_t len, const Varray<double> &array, double &rmin, double &rmax, double &rmean)
MinMaxMean
varrayMinMaxMean(const size_t len, const Varray<double> &array)
{
auto mms = varrayMinMaxSum(len, array, MinMaxSum());
rmin = mms.min;
rmax = mms.max;
rmean = len ? mms.sum / (double) len : 0;
double rmean = len ? mms.sum / (double) len : 0;
return MinMaxMean(mms.min, mms.max, rmean, len);
}
size_t
varrayMinMaxMeanMV(const size_t len, const Varray<double> &array, const double missval, double &rmin, double &rmax, double &rmean)
MinMaxMean
varrayMinMaxMeanMV(const size_t len, const Varray<double> &array, const double missval)
{
auto mms = varrayMinMaxSumMV(len, array, missval, MinMaxSum());
rmin = mms.min;
rmax = mms.max;
rmean = mms.n ? mms.sum / (double) mms.n : missval;
return mms.n;
double rmean = mms.n ? mms.sum / (double) mms.n : missval;
return MinMaxMean(mms.min, mms.max, rmean, mms.n);
}
void
......
......@@ -22,7 +22,17 @@
#include <cfloat>
#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
{
double min;
......@@ -34,6 +44,17 @@ struct MinMaxSum
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>;
template <typename T>
......@@ -134,8 +155,8 @@ MinMaxSum varrayMinMaxSum(size_t len, const Varray<T> &array, MinMaxSum mms);
template <typename T>
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);
size_t varrayMinMaxMeanMV(size_t len, const Varray<double> &array, double missval, double &rmin, double &rmax, double &rmean);
MinMaxMean varrayMinMaxMean(size_t len, const Varray<double> &array);
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);
......
......@@ -779,12 +779,11 @@ remapStat(int remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &r
cdoPrint("First order mapping from grid1 to grid2:");
cdoPrint("----------------------------------------------");
double mean, minval, maxval;
varrayMinMaxMeanMV(src_grid.size, array1, missval, minval, maxval, mean);
cdoPrint(" Grid1 min,mean,max: %g %g %g", minval, mean, maxval);
auto mmm = varrayMinMaxMeanMV(src_grid.size, array1, missval);
cdoPrint(" Grid1 min,mean,max: %g %g %g", mmm.min, mmm.mean, mmm.max);
varrayMinMaxMeanMV(tgt_grid.size, array2, missval, minval, maxval, mean);
cdoPrint(" Grid2 min,mean,max: %g %g %g", minval, mean, maxval);
mmm = varrayMinMaxMeanMV(tgt_grid.size, array2, missval);
cdoPrint(" Grid2 min,mean,max: %g %g %g", mmm.min, mmm.mean, mmm.max);
// 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