Commit 8cfa9926 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

array.cc: changed some function to std::vector.

parent e6bfc6de
......@@ -313,43 +313,43 @@ arrayNumMV_f(const size_t len, const float *restrict array, const double missval
}
double
arrayMin(const size_t len, const double *restrict array)
arrayMin(const size_t len, const std::vector<double> &v)
{
assert(array != nullptr);
assert(v.size() >= len);
double min = array[0];
double min = v[0];
for (size_t i = 0; i < len; ++i)
if (array[i] < min) min = array[i];
if (v[i] < min) min = v[i];
return min;
}
double
arrayMax(const size_t len, const double *restrict array)
arrayMax(const size_t len, const std::vector<double> &v)
{
assert(array != nullptr);
assert(v.size() >= len);
double max = array[0];
double max = v[0];
for (size_t i = 0; i < len; ++i)
if (array[i] > max) max = array[i];
if (v[i] > max) max = v[i];
return max;
}
double
arrayRange(const size_t len, const double *restrict array)
arrayRange(const size_t len, const std::vector<double> &v)
{
assert(array != nullptr);
assert(v.size() >= len);
double min = array[0];
double max = array[0];
double min = v[0];
double max = v[0];
for (size_t i = 0; i < len; ++i)
{
if (array[i] < min) min = array[i];
if (array[i] > max) max = array[i];
if (v[i] < min) min = v[i];
if (v[i] > max) max = v[i];
}
double range = max - min;
......@@ -358,15 +358,15 @@ arrayRange(const size_t len, const double *restrict array)
}
double
arrayMinMV(const size_t len, const double *restrict array, const double missval)
arrayMinMV(const size_t len, const std::vector<double> &v, const double missval)
{
assert(array != nullptr);
assert(v.size() >= len);
double min = DBL_MAX;
for (size_t i = 0; i < len; ++i)
if (!DBL_IS_EQUAL(array[i], missval))
if (array[i] < min) min = array[i];
if (!DBL_IS_EQUAL(v[i], missval))
if (v[i] < min) min = v[i];
if (IS_EQUAL(min, DBL_MAX)) min = missval;
......@@ -374,15 +374,15 @@ arrayMinMV(const size_t len, const double *restrict array, const double missval)
}
double
arrayMaxMV(const size_t len, const double *restrict array, const double missval)
arrayMaxMV(const size_t len, const std::vector<double> &v, const double missval)
{
assert(array != nullptr);
assert(v.size() >= len);
double max = -DBL_MAX;
for (size_t i = 0; i < len; ++i)
if (!DBL_IS_EQUAL(array[i], missval))
if (array[i] > max) max = array[i];
if (!DBL_IS_EQUAL(v[i], missval))
if (v[i] > max) max = v[i];
if (IS_EQUAL(max, -DBL_MAX)) max = missval;
......@@ -390,19 +390,19 @@ arrayMaxMV(const size_t len, const double *restrict array, const double missval)
}
double
arrayRangeMV(const size_t len, const double *restrict array, const double missval)
arrayRangeMV(const size_t len, const std::vector<double> &v, const double missval)
{
assert(array != nullptr);
assert(v.size() >= len);
double min = DBL_MAX;
double max = -DBL_MAX;
for (size_t i = 0; i < len; ++i)
{
if (!DBL_IS_EQUAL(array[i], missval))
if (!DBL_IS_EQUAL(v[i], missval))
{
if (array[i] < min) min = array[i];
if (array[i] > max) max = array[i];
if (v[i] < min) min = v[i];
if (v[i] > max) max = v[i];
}
}
......@@ -416,21 +416,21 @@ arrayRangeMV(const size_t len, const double *restrict array, const double missva
}
double
arraySum(const size_t len, const double *restrict array)
arraySum(const size_t len, const std::vector<double> &v)
{
assert(array != nullptr);
assert(v.size() >= len);
double sum = 0;
for (size_t i = 0; i < len; ++i) sum += array[i];
for (size_t i = 0; i < len; ++i) sum += v[i];
return sum;
}
double
arraySumMV(const size_t len, const double *restrict array, const double missval)
arraySumMV(const size_t len, const std::vector<double> &v, const double missval)
{
assert(array != nullptr);
assert(v.size() >= len);
double sum = 0;
size_t nvals = 0;
......@@ -438,18 +438,18 @@ arraySumMV(const size_t len, const double *restrict array, const double missval)
if (DBL_IS_NAN(missval))
{
for (size_t i = 0; i < len; ++i)
if (!DBL_IS_EQUAL(array[i], missval))
if (!DBL_IS_EQUAL(v[i], missval))
{
sum += array[i];
sum += v[i];
nvals++;
}
}
else
{
for (size_t i = 0; i < len; ++i)
if (IS_NOT_EQUAL(array[i], missval))
if (IS_NOT_EQUAL(v[i], missval))
{
sum += array[i];
sum += v[i];
nvals++;
}
}
......@@ -460,26 +460,26 @@ arraySumMV(const size_t len, const double *restrict array, const double missval)
}
double
arrayMean(const size_t len, const double *restrict array)
arrayMean(const size_t len, const std::vector<double> &v)
{
assert(array != nullptr);
assert(v.size() >= len);
double sum = arraySum(len, array);
const double sum = arraySum(len, v);
return sum / len;
}
double
arrayMeanMV(const size_t len, const double *restrict array, const double missval)
arrayMeanMV(const size_t len, const std::vector<double> &v, const double missval)
{
assert(array != nullptr);
assert(v.size() >= len);
double sum = 0, sumw = 0;
for (size_t i = 0; i < len; ++i)
if (!DBL_IS_EQUAL(array[i], missval))
if (!DBL_IS_EQUAL(v[i], missval))
{
sum += array[i];
sum += v[i];
sumw += 1;
}
......@@ -488,16 +488,16 @@ arrayMeanMV(const size_t len, const double *restrict array, const double missval
}
double
arrayWeightedMean(const size_t len, const std::vector<double> &array, const std::vector<double> &w, const double missval)
arrayWeightedMean(const size_t len, const std::vector<double> &v, const std::vector<double> &w, const double missval)
{
assert(array.size() >= len);
assert(v.size() >= len);
assert(w.size() >= len);
double sum = 0, sumw = 0;
for (size_t i = 0; i < len; ++i)
{
sum += w[i] * array[i];
sum += w[i] * v[i];
sumw += w[i];
}
......@@ -505,18 +505,18 @@ arrayWeightedMean(const size_t len, const std::vector<double> &array, const std:
}
double
arrayWeightedMeanMV(const size_t len, const std::vector<double> &array, const std::vector<double> &w, const double missval)
arrayWeightedMeanMV(const size_t len, const std::vector<double> &v, const std::vector<double> &w, const double missval)
{
assert(array.size() >= len);
assert(v.size() >= len);
assert(w.size() >= len);
const double missval1 = missval, missval2 = missval;
double sum = 0, sumw = 0;
for (size_t i = 0; i < len; ++i)
if (!DBL_IS_EQUAL(array[i], missval1) && !DBL_IS_EQUAL(w[i], missval1))
if (!DBL_IS_EQUAL(v[i], missval1) && !DBL_IS_EQUAL(w[i], missval1))
{
sum += w[i] * array[i];
sum += w[i] * v[i];
sumw += w[i];
}
......@@ -524,16 +524,16 @@ arrayWeightedMeanMV(const size_t len, const std::vector<double> &array, const st
}
double
arrayAvgMV(const size_t len, const double *restrict array, const double missval)
arrayAvgMV(const size_t len, const std::vector<double> &v, const double missval)
{
assert(array != nullptr);
assert(v.size() >= len);
double missval1 = missval, missval2 = missval;
const double missval1 = missval, missval2 = missval;
double sum = 0, sumw = 0;
for (size_t i = 0; i < len; ++i)
{
sum = ADDMN(sum, array[i]);
sum = ADDMN(sum, v[i]);
sumw += 1;
}
......@@ -541,9 +541,9 @@ arrayAvgMV(const size_t len, const double *restrict array, const double missval)
}
double
arrayWeightedAvgMV(const size_t len, const std::vector<double> &array, const std::vector<double> &w, const double missval)
arrayWeightedAvgMV(const size_t len, const std::vector<double> &v, const std::vector<double> &w, const double missval)
{
assert(array.size() >= len);
assert(v.size() >= len);
assert(w.size() >= len);
const double missval1 = missval, missval2 = missval;
......@@ -552,7 +552,7 @@ arrayWeightedAvgMV(const size_t len, const std::vector<double> &array, const std
for (size_t i = 0; i < len; ++i)
if (!DBL_IS_EQUAL(w[i], missval))
{
sum = ADDMN(sum, MULMN(w[i], array[i]));
sum = ADDMN(sum, MULMN(w[i], v[i]));
sumw = ADDMN(sumw, w[i]);
}
......
......@@ -126,22 +126,22 @@ arrayCopy(const size_t len, const T *array1, T *array2)
size_t arrayNumMV(const size_t len, const double *array, const double missval);
size_t arrayNumMV_f(const size_t len, const float *array, const double missval);
double arrayMin(const size_t len, const double *array);
double arrayMax(const size_t len, const double *array);
double arrayRange(const size_t len, const double *array);
double arrayMinMV(const size_t len, const double *array, const double missval);
double arrayMaxMV(const size_t len, const double *array, const double missval);
double arrayRangeMV(const size_t len, const double *array, const double missval);
double arraySum(const size_t len, const double *array);
double arraySumMV(const size_t len, const double *array, const double missval);
double arrayMean(const size_t len, const double *array);
double arrayMeanMV(const size_t len, const double *array, const double missval);
double arrayWeightedMean(const size_t len, const std::vector<double> &array, const std::vector<double> &w, const double missval);
double arrayWeightedMeanMV(const size_t len, const std::vector<double> &array, const std::vector<double> &w, const double missval);
double arrayAvgMV(const size_t len, const double *array, double missval);
double arrayWeightedAvgMV(const size_t len, const std::vector<double> &array, const std::vector<double> &w, const double missval);
double arrayMin(const size_t len, const std::vector<double> &v);
double arrayMax(const size_t len, const std::vector<double> &v);
double arrayRange(const size_t len, const std::vector<double> &v);
double arrayMinMV(const size_t len, const std::vector<double> &v, const double missval);
double arrayMaxMV(const size_t len, const std::vector<double> &v, const double missval);
double arrayRangeMV(const size_t len, const std::vector<double> &v, const double missval);
double arraySum(const size_t len, const std::vector<double> &v);
double arraySumMV(const size_t len, const std::vector<double> &v, const double missval);
double arrayMean(const size_t len, const std::vector<double> &v);
double arrayMeanMV(const size_t len, const std::vector<double> &v, const double missval);
double arrayWeightedMean(const size_t len, const std::vector<double> &v, const std::vector<double> &w, const double missval);
double arrayWeightedMeanMV(const size_t len, const std::vector<double> &v, const std::vector<double> &w, const double missval);
double arrayAvgMV(const size_t len, const std::vector<double> &v, double missval);
double arrayWeightedAvgMV(const size_t len, const std::vector<double> &v, const std::vector<double> &w, const double missval);
#endif // ARRAY_H
......@@ -25,31 +25,31 @@
static double
vfldrange(const Field &field)
{
return field.nmiss ? arrayRangeMV(field.gridsize, field.vec.data(), field.missval) : arrayRange(field.gridsize, field.vec.data());
return field.nmiss ? arrayRangeMV(field.gridsize, field.vec, field.missval) : arrayRange(field.gridsize, field.vec);
}
double
vfldmin(const Field &field)
{
return field.nmiss ? arrayMinMV(field.gridsize, field.vec.data(), field.missval) : arrayMin(field.gridsize, field.vec.data());
return field.nmiss ? arrayMinMV(field.gridsize, field.vec, field.missval) : arrayMin(field.gridsize, field.vec);
}
double
vfldmax(const Field &field)
{
return field.nmiss ? arrayMaxMV(field.gridsize, field.vec.data(), field.missval) : arrayMax(field.gridsize, field.vec.data());
return field.nmiss ? arrayMaxMV(field.gridsize, field.vec, field.missval) : arrayMax(field.gridsize, field.vec);
}
double
vfldsum(const Field &field)
{
return field.nmiss ? arraySumMV(field.gridsize, field.vec.data(), field.missval) : arraySum(field.gridsize, field.vec.data());
return field.nmiss ? arraySumMV(field.gridsize, field.vec, field.missval) : arraySum(field.gridsize, field.vec);
}
double
vfldmean(const Field &field)
{
return field.nmiss ? arrayMeanMV(field.gridsize, field.vec.data(), field.missval) : arrayMean(field.gridsize, field.vec.data());
return field.nmiss ? arrayMeanMV(field.gridsize, field.vec, field.missval) : arrayMean(field.gridsize, field.vec);
}
double
......@@ -62,7 +62,7 @@ vfldmeanw(const Field &field)
double
vfldavg(const Field &field)
{
return field.nmiss ? arrayMeanMV(field.gridsize, field.vec.data(), field.missval) : arrayMean(field.gridsize, field.vec.data());
return field.nmiss ? arrayMeanMV(field.gridsize, field.vec, field.missval) : arrayMean(field.gridsize, field.vec);
}
double
......
......@@ -36,12 +36,12 @@ mermin(const Field &field1, Field &field2)
if (field1.nmiss)
{
rmin = arrayMinMV(ny, &v[0], field1.missval);
rmin = arrayMinMV(ny, v, field1.missval);
if (DBL_IS_EQUAL(rmin, field1.missval)) rnmiss++;
}
else
{
rmin = arrayMin(ny, &v[0]);
rmin = arrayMin(ny, v);
}
field2.vec[i] = rmin;
......@@ -67,12 +67,12 @@ mermax(const Field &field1, Field &field2)
if (field1.nmiss)
{
rmax = arrayMaxMV(ny, &v[0], field1.missval);
rmax = arrayMaxMV(ny, v, field1.missval);
if (DBL_IS_EQUAL(rmax, field1.missval)) rnmiss++;
}
else
{
rmax = arrayMax(ny, &v[0]);
rmax = arrayMax(ny, v);
}
field2.vec[i] = rmax;
......@@ -98,12 +98,12 @@ merrange(const Field &field1, Field &field2)
if (field1.nmiss)
{
range = arrayRangeMV(ny, &v[0], field1.missval);
range = arrayRangeMV(ny, v, field1.missval);
if (DBL_IS_EQUAL(range, field1.missval)) rnmiss++;
}
else
{
range = arrayRange(ny, &v[0]);
range = arrayRange(ny, v);
}
field2.vec[i] = range;
......@@ -129,12 +129,12 @@ mersum(const Field &field1, Field &field2)
if (field1.nmiss)
{
rsum = arraySumMV(ny, &v[0], field1.missval);
rsum = arraySumMV(ny, v, field1.missval);
if (DBL_IS_EQUAL(rsum, field1.missval)) rnmiss++;
}
else
{
rsum = arraySum(ny, &v[0]);
rsum = arraySum(ny, v);
}
field2.vec[i] = rsum;
......
......@@ -37,12 +37,12 @@ zonmin(const Field &field1, Field &field2)
if (field1.nmiss)
{
rmin = arrayMinMV(nx, v.data(), field1.missval);
rmin = arrayMinMV(nx, v, field1.missval);
if (DBL_IS_EQUAL(rmin, field1.missval)) rnmiss++;
}
else
{
rmin = arrayMin(nx, v.data());
rmin = arrayMin(nx, v);
}
field2.vec[j] = rmin;
......@@ -68,12 +68,12 @@ zonmax(const Field &field1, Field &field2)
if (field1.nmiss)
{
rmax = arrayMaxMV(nx, v.data(), field1.missval);
rmax = arrayMaxMV(nx, v, field1.missval);
if (DBL_IS_EQUAL(rmax, field1.missval)) rnmiss++;
}
else
{
rmax = arrayMax(nx, v.data());
rmax = arrayMax(nx, v);
}
field2.vec[j] = rmax;
......@@ -99,12 +99,12 @@ zonrange(const Field &field1, Field &field2)
if (field1.nmiss)
{
range = arrayRangeMV(nx, v.data(), field1.missval);
range = arrayRangeMV(nx, v, field1.missval);
if (DBL_IS_EQUAL(range, field1.missval)) rnmiss++;
}
else
{
range = arrayRange(nx, v.data());
range = arrayRange(nx, v);
}
field2.vec[j] = range;
......@@ -130,12 +130,12 @@ zonsum(const Field &field1, Field &field2)
if (field1.nmiss)
{
rsum = arraySumMV(nx, v.data(), field1.missval);
rsum = arraySumMV(nx, v, field1.missval);
if (DBL_IS_EQUAL(rsum, field1.missval)) rnmiss++;
}
else
{
rsum = arraySum(nx, v.data());
rsum = arraySum(nx, v);
}
field2.vec[j] = rsum;
......@@ -161,11 +161,11 @@ zonmean(const Field &field1, Field &field2)
if (field1.nmiss)
{
rmean = arrayMeanMV(nx, v.data(), field1.missval);
rmean = arrayMeanMV(nx, v, field1.missval);
}
else
{
rmean = arrayMean(nx, v.data());
rmean = arrayMean(nx, v);
}
if (DBL_IS_EQUAL(rmean, field1.missval)) rnmiss++;
......@@ -193,11 +193,11 @@ zonavg(const Field &field1, Field &field2)
if (field1.nmiss)
{
ravg = arrayAvgMV(nx, v.data(), field1.missval);
ravg = arrayAvgMV(nx, v, field1.missval);
}
else
{
ravg = arrayMean(nx, v.data());
ravg = arrayMean(nx, v);
}
if (DBL_IS_EQUAL(ravg, field1.missval)) rnmiss++;
......
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