52 Array1D(
const size_t& asize,
const T& init);
67 void size(
size_t&
nx)
const;
71 void resize(
const size_t& asize);
72 void resize(
const size_t& asize,
const T& init);
153 : vecData(asize), nx(asize), keep_nodata(true)
159 : vecData(asize, init), nx(asize), keep_nodata(true)
165 keep_nodata = i_keep_nodata;
186 vecData.resize(asize);
192 vecData.resize(asize, init);
199 std::stringstream ss;
200 ss <<
"Trying to access array(" << index <<
")";
201 ss <<
" while array is (" << nx <<
")";
205 return vecData[index];
211 std::stringstream ss;
212 ss <<
"Trying to access array(" << index <<
")";
213 ss <<
" while array is (" << nx <<
")";
217 return vecData[index];
222 return vecData.at(index);
224 return vecData[index];
230 return vecData.at(index);
232 return vecData[index];
246 std::stringstream os;
248 for (
size_t ii=0; ii<nx; ii++) {
249 os << vecData[ii] <<
" ";
251 os <<
"\n</array1d>\n";
257 os.write(
reinterpret_cast<const char*
>(&array.
nx),
sizeof(array.
nx));
258 os.write(
reinterpret_cast<const char*
>(&array.
vecData[0]),
static_cast<std::streamsize
>(array.
nx*
sizeof(P)));
264 is.read(
reinterpret_cast<char*
>(&array.
nx),
sizeof(array.
nx));
266 is.read(
reinterpret_cast<char*
>(&array.
vecData[0]),
static_cast<std::streamsize
>(array.
nx*
sizeof(P)));
272 vecData.push_back(
e);
274 }
else if ((index >= 0) && (index < (
int)vecData.size())) {
275 vecData.insert(vecData.begin() + index,
e);
278 std::stringstream ss;
279 ss <<
"Inserting an element at (" << index <<
") in an array of size [" << nx <<
"]";
285 if (index < vecData.size()) {
286 vecData.erase(vecData.begin()+index);
293 T min = std::numeric_limits<T>::max();
295 if (keep_nodata==
false) {
296 min = *min_element(vecData.begin(), vecData.end());
297 if (min!=std::numeric_limits<T>::max())
return min;
300 for (
size_t ii=0; ii<nx; ii++) {
301 const T val = vecData[ii];
304 if (min!=std::numeric_limits<T>::max())
return min;
311 T max = -std::numeric_limits<T>::max();
313 if (keep_nodata==
false) {
314 max = *max_element(vecData.begin(), vecData.end());
315 if (max!=-std::numeric_limits<T>::max())
return max;
318 for (
size_t ii=0; ii<nx; ii++) {
319 const T val = vecData[ii];
322 if (max!=-std::numeric_limits<T>::max())
return max;
331 if (keep_nodata==
false) {
332 if (nx>0)
return std::accumulate(vecData.begin(), vecData.end(), 0.) / (T)(nx);
336 for (
size_t ii=0; ii<nx; ii++) {
337 const T val = vecData[ii];
350 if (keep_nodata==
false) {
354 for (
size_t ii=0; ii<nx; ii++) {
362 if (std::numeric_limits<T>::is_signed) {
363 if (keep_nodata==
false) {
364 for (
size_t ii=0; ii<nx; ii++) {
365 T& val = vecData[ii];
369 for (
size_t ii=0; ii<nx; ii++) {
370 T& val = vecData[ii];
386 if (nx!=rhs.
nx)
return false;
388 for (
size_t jj=0; jj<nx; jj++)
400 std::fill(vecData.begin(), vecData.end(), value);
408 std::stringstream ss;
409 ss <<
"Trying to add two Array1D objects with different dimensions: ";
410 ss <<
"(" << nx <<
") + (" << rhs.
nx <<
")";
415 if (keep_nodata==
false) {
416 for (
size_t ii=0; ii<nx; ii++) {
417 vecData[ii] += rhs(ii);
420 for (
size_t ii=0; ii<nx; ii++) {
424 vecData[ii] += rhs(ii);
441 if (rhs==0.)
return *
this;
444 if (keep_nodata==
false) {
445 for (
size_t ii=0; ii<nx; ii++) {
449 for (
size_t ii=0; ii<nx; ii++) {
470 std::stringstream ss;
471 ss <<
"Trying to substract two Array1D objects with different dimensions: ";
472 ss <<
"(" << nx <<
") - (" << rhs.
nx <<
")";
477 if (keep_nodata==
false) {
478 for (
size_t ii=0; ii<nx; ii++) {
479 vecData[ii] -= rhs(ii);
482 for (
size_t ii=0; ii<nx; ii++) {
486 vecData[ii] -= rhs(ii);
519 std::stringstream ss;
520 ss <<
"Trying to multiply two Array1D objects with different dimensions: ";
521 ss <<
"(" << nx <<
") * (" << rhs.
nx <<
")";
525 if (keep_nodata==
false) {
526 for (
size_t ii=0; ii<nx; ii++) {
527 vecData[ii] *= rhs(ii);
530 for (
size_t ii=0; ii<nx; ii++) {
534 vecData[ii] *= rhs(ii);
551 if (rhs==1.)
return *
this;
554 if (keep_nodata==
false) {
555 for (
size_t ii=0; ii<nx; ii++) {
559 for (
size_t ii=0; ii<nx; ii++) {
580 std::stringstream ss;
581 ss <<
"Trying to divide two Array1D objects with different dimensions: ";
582 ss <<
"(" << nx <<
") / (" << rhs.
nx <<
")";
586 if (keep_nodata==
false) {
587 for (
size_t ii=0; ii<nx; ii++) {
588 vecData[ii] /= rhs(ii);
591 for (
size_t ii=0; ii<nx; ii++) {
595 vecData[ii] /= rhs(ii);
625 const size_t in_nx = in.
getNx();
630 for (
size_t jj=0; jj<nx; jj++)
#define AT
Definition: IOExceptions.h:28
The template class Array1D is a 1D array (vector) able to hold any type of object as datatype....
Definition: Array1D.h:43
Array1D< T > & operator/=(const T &rhs)
Definition: Array1D.h:610
void resize(const size_t &asize)
Definition: Array1D.h:184
bool checkEpsilonEquality(const Array1D< double > &rhs, const double &epsilon) const
Definition: Array1D.h:385
void clear()
Definition: Array1D.h:236
const Array1D< T > operator*(const T &rhs) const
Definition: Array1D.h:568
std::vector< T > vecData
the actual data structure, that holds the objects of type T
Definition: Array1D.h:147
size_t size() const
Definition: Array1D.h:176
T & operator()(const size_t &index)
Definition: Array1D.h:196
void setKeepNodata(const bool i_keep_nodata)
set how to process nodata values (ie: as nodata or as normal numbers)
Definition: Array1D.h:164
bool operator==(const Array1D< T > &) const
Operator that tests for equality.
Definition: Array1D.h:624
void insertAt(const int &index, T e)
Definition: Array1D.h:270
const Array1D< T > operator+(const T &rhs) const
Definition: Array1D.h:458
Array1D< T > & operator-=(const T &rhs)
Definition: Array1D.h:501
void abs()
Definition: Array1D.h:361
size_t getNx() const
Definition: Array1D.h:180
T & operator[](const size_t &index)
Definition: Array1D.h:220
friend std::ostream & operator<<(std::ostream &os, const Array1D< P > &array)
Definition: Array1D.h:255
Array1D< T > & operator=(const T &value)
Definition: Array1D.h:398
size_t nx
this is introduced to omit the costly vecData.size()
Definition: Array1D.h:148
void removeAt(const size_t &index)
Definition: Array1D.h:284
bool keep_nodata
Definition: Array1D.h:149
Array1D(const size_t &asize=0)
Definition: Array1D.h:152
T getMean() const
returns the mean value contained in the grid
Definition: Array1D.h:327
bool operator!=(const Array1D< T > &) const
Operator that tests for inequality.
Definition: Array1D.h:636
T getMax() const
returns the maximum value contained in the grid
Definition: Array1D.h:309
Array1D< T > & operator*=(const T &rhs)
Definition: Array1D.h:549
const std::string toString() const
Definition: Array1D.h:245
bool empty() const
Definition: Array1D.h:241
T getMin() const
returns the minimum value contained in the grid
Definition: Array1D.h:291
friend std::istream & operator>>(std::istream &is, Array1D< P > &array)
Definition: Array1D.h:262
const Array1D< T > operator-(const T &rhs) const
Definition: Array1D.h:507
size_t getCount() const
returns the number of points contained in the grid. If setNodataHandling(IOUtils::RAW_NODATA),...
Definition: Array1D.h:348
const Array1D< T > operator/(const T &rhs) const
Definition: Array1D.h:616
const Array1D< T > getAbs() const
returns the grid of the absolute value of values contained in the grid
Definition: Array1D.h:377
bool getKeepNodata()
get how to process nodata values (ie: as nodata or as normal numbers)
Definition: Array1D.h:168
Array1D< T > & operator+=(const T &rhs)
Definition: Array1D.h:439
The basic exception class adjusted for the needs of SLF software.
Definition: IOExceptions.h:40
thrown when an index is out of bounds
Definition: IOExceptions.h:106
static const double e
Definition: Meteoconst.h:68
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
size_t count(const std::string &input, const std::string &search)
count how many times a substring appears in a string
Definition: IOUtils.cc:257
bool checkEpsilonEquality(const double &val1, const double &val2, const double &epsilon)
Check whether two values are equal regarding a certain epsilon environment (within certain radius of ...
Definition: IOUtils.h:121
std::istream & operator>>(std::istream &is, Config &cfg)
Definition: Config.cc:480
std::ostream & operator<<(std::ostream &os, const Config &cfg)
Definition: Config.cc:445