Commit 2bb825ed authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

EcaIndices.cc: changed Field ptr to vector.

parent 8cfa9926
This diff is collapsed.
This diff is collapsed.
......@@ -148,10 +148,10 @@ count(Field &field1, const Field &field2, double mode)
const int grid1 = field1.grid;
const size_t nmiss1 = field1.nmiss;
const double missval1 = field1.missval;
double *array1 = field1.ptr;
auto &array1 = field1.vec;
const int grid2 = field2.grid;
const double missval2 = field2.missval;
const double *array2 = field2.ptr;
const auto &array2 = field2.vec;
size_t len = gridInqSize(grid1);
......@@ -185,7 +185,7 @@ count(Field &field1, const Field &field2, double mode)
}
}
field1.nmiss = arrayNumMV(len, array1, missval1);
field1.nmiss = arrayNumMV(len, array1.data(), missval1);
}
else
{
......@@ -227,11 +227,11 @@ selcomp(Field &field1, const Field &field2, int (*compare)(double, double))
const int grid1 = field1.grid;
const size_t nmiss1 = field1.nmiss;
const double missval1 = field1.missval;
double *array1 = field1.ptr;
auto &array1 = field1.vec;
const int grid2 = field2.grid;
const size_t nmiss2 = field2.nmiss;
const double missval2 = field2.missval;
const double *array2 = field2.ptr;
const auto &array2 = field2.vec;
size_t len = gridInqSize(grid1);
......@@ -249,7 +249,7 @@ selcomp(Field &field1, const Field &field2, int (*compare)(double, double))
if (!compare(array1[i], array2[i])) array1[i] = missval1;
}
field1.nmiss = arrayNumMV(len, array1, missval1);
field1.nmiss = arrayNumMV(len, array1.data(), missval1);
}
/**
......@@ -274,7 +274,7 @@ selcompc(Field &field, double c, int (*compare)(double, double))
const int grid = field.grid;
const size_t nmiss = field.nmiss;
const double missval = field.missval;
double *array = field.ptr;
auto &array = field.vec;
size_t len = gridInqSize(grid);
......@@ -293,7 +293,7 @@ selcompc(Field &field, double c, int (*compare)(double, double))
if (!compare(array[i], c)) array[i] = missval;
}
field.nmiss = arrayNumMV(len, array, missval);
field.nmiss = arrayNumMV(len, array.data(), missval);
}
static int
......@@ -333,34 +333,34 @@ ne(double a, double b)
}
void
farnum(Field &field1, const Field &field2)
vfarnum(Field &field1, const Field &field2)
{
count(field1, field2, 0.0);
}
void
farnum2(Field &field1, const Field &field2)
vfarnum2(Field &field1, const Field &field2)
{
count(field1, field2, 1.0);
}
void
farnum3(Field &field1, const Field &field2, double n)
vfarnum3(Field &field1, const Field &field2, double n)
{
count(field1, field2, n);
}
void
farsel(Field &field1, const Field &field2)
vfarsel(Field &field1, const Field &field2)
{
size_t i;
const int grid1 = field1.grid;
const double missval1 = field1.missval;
double *array1 = field1.ptr;
auto &array1 = field1.vec;
const int grid2 = field2.grid;
const size_t nmiss2 = field2.nmiss;
const double missval2 = field2.missval;
const double *array2 = field2.ptr;
const auto &array2 = field2.vec;
size_t len = gridInqSize(grid1);
......@@ -377,77 +377,77 @@ farsel(Field &field1, const Field &field2)
if (IS_EQUAL(array2[i], 0.0)) array1[i] = missval1;
}
field1.nmiss = arrayNumMV(len, array1, missval1);
field1.nmiss = arrayNumMV(len, array1.data(), missval1);
}
void
farselle(Field &field1, const Field &field2)
vfarselle(Field &field1, const Field &field2)
{
selcomp(field1, field2, le);
}
void
farsellt(Field &field1, const Field &field2)
vfarsellt(Field &field1, const Field &field2)
{
selcomp(field1, field2, lt);
}
void
farselge(Field &field1, const Field &field2)
vfarselge(Field &field1, const Field &field2)
{
selcomp(field1, field2, ge);
}
void
farselgt(Field &field1, const Field &field2)
vfarselgt(Field &field1, const Field &field2)
{
selcomp(field1, field2, gt);
}
void
farseleq(Field &field1, const Field &field2)
vfarseleq(Field &field1, const Field &field2)
{
selcomp(field1, field2, eq);
}
void
farselne(Field &field1, const Field &field2)
vfarselne(Field &field1, const Field &field2)
{
selcomp(field1, field2, ne);
}
void
farsellec(Field &field, double c)
vfarsellec(Field &field, double c)
{
selcompc(field, c, le);
}
void
farselltc(Field &field, double c)
vfarselltc(Field &field, double c)
{
selcompc(field, c, lt);
}
void
farselgec(Field &field, double c)
vfarselgec(Field &field, double c)
{
selcompc(field, c, ge);
}
void
farseleqc(Field &field, double c)
vfarseleqc(Field &field, double c)
{
selcompc(field, c, eq);
}
void
farselnec(Field &field, double c)
vfarselnec(Field &field, double c)
{
selcompc(field, c, ne);
}
void
farselgtc(Field &field, double c)
vfarselgtc(Field &field, double c)
{
selcompc(field, c, gt);
}
......@@ -459,10 +459,10 @@ updateHist(FieldVector2D &field, int nlevels, size_t gridsize, std::vector<doubl
for (size_t i = 0; i < gridsize; i++)
if (onlyNorth)
{
if (yvals[i] >= 0.0) field[1][levelID].ptr[i] = field[0][levelID].ptr[i];
if (yvals[i] >= 0.0) field[1][levelID].vec[i] = field[0][levelID].vec[i];
}
else
field[1][levelID].ptr[i] = field[0][levelID].ptr[i];
field[1][levelID].vec[i] = field[0][levelID].vec[i];
}
void
......@@ -478,27 +478,27 @@ adjustEndDate(int nlevels, size_t gridsize, std::vector<double> &yvals, double m
/* start with southern sphere */
if (yvals[i] < 0)
{
if (DBL_IS_EQUAL(startDateWithHist[1][levelID].ptr[i], missval))
if (DBL_IS_EQUAL(startDateWithHist[1][levelID].vec[i], missval))
{
endDateWithHist[0][levelID].ptr[i] = missval;
endDateWithHist[0][levelID].vec[i] = missval;
continue;
}
if (DBL_IS_EQUAL(endDateWithHist[0][levelID].ptr[i], missval))
if (DBL_IS_EQUAL(endDateWithHist[0][levelID].vec[i], missval))
{
endDateWithHist[0][levelID].ptr[i] = ovdateSouth;
endDateWithHist[0][levelID].vec[i] = ovdateSouth;
}
}
else
{
if (DBL_IS_EQUAL(startDateWithHist[0][levelID].ptr[i], missval))
if (DBL_IS_EQUAL(startDateWithHist[0][levelID].vec[i], missval))
{
endDateWithHist[0][levelID].ptr[i] = missval;
endDateWithHist[0][levelID].vec[i] = missval;
continue;
}
if (DBL_IS_EQUAL(endDateWithHist[0][levelID].ptr[i], missval))
if (DBL_IS_EQUAL(endDateWithHist[0][levelID].vec[i], missval))
{
endDateWithHist[0][levelID].ptr[i] = ovdate;
endDateWithHist[0][levelID].vec[i] = ovdate;
}
}
}
......@@ -521,22 +521,22 @@ computeGsl(int nlevels, size_t gridsize, std::vector<double> &yvals, double miss
/* start with southern sphere */
if (yvals[i] < 0.0)
{
duration = (double) (date_to_julday(CALENDAR_PROLEPTIC, (int64_t) endDateWithHist[0][levelID].ptr[i])
- date_to_julday(CALENDAR_PROLEPTIC, (int64_t) startDateWithHist[1][levelID].ptr[i]));
duration = (double) (date_to_julday(CALENDAR_PROLEPTIC, (int64_t) endDateWithHist[0][levelID].vec[i])
- date_to_julday(CALENDAR_PROLEPTIC, (int64_t) startDateWithHist[1][levelID].vec[i]));
}
else
{
duration = (double) (date_to_julday(CALENDAR_PROLEPTIC, (int64_t) endDateWithHist[1][levelID].ptr[i])
- date_to_julday(CALENDAR_PROLEPTIC, (int64_t) startDateWithHist[1][levelID].ptr[i]));
duration = (double) (date_to_julday(CALENDAR_PROLEPTIC, (int64_t) endDateWithHist[1][levelID].vec[i])
- date_to_julday(CALENDAR_PROLEPTIC, (int64_t) startDateWithHist[1][levelID].vec[i]));
}
if (DBL_IS_EQUAL(startDateWithHist[1][levelID].ptr[i], missval))
if (DBL_IS_EQUAL(startDateWithHist[1][levelID].vec[i], missval))
firstDay = missval;
else
firstDay = (double) day_of_year((int64_t) startDateWithHist[1][levelID].ptr[i]);
firstDay = (double) day_of_year((int64_t) startDateWithHist[1][levelID].vec[i]);
gslDuration[levelID].ptr[i] = duration;
gslFirstDay[levelID].ptr[i] = firstDay;
gslDuration[levelID].vec[i] = duration;
gslFirstDay[levelID].vec[i] = firstDay;
}
}
}
......@@ -550,21 +550,21 @@ computeGsl(int nlevels, size_t gridsize, std::vector<double> &yvals, double miss
/* start with southern sphere */
if (yvals[i] < 0.0)
{
gslDuration[levelID].ptr[i] = missval;
gslFirstDay[levelID].ptr[i] = missval;
gslDuration[levelID].vec[i] = missval;
gslFirstDay[levelID].vec[i] = missval;
}
else
{
duration = (double) (date_to_julday(CALENDAR_PROLEPTIC, (int64_t) endDateWithHist[0][levelID].ptr[i])
- date_to_julday(CALENDAR_PROLEPTIC, (int64_t) startDateWithHist[0][levelID].ptr[i]));
duration = (double) (date_to_julday(CALENDAR_PROLEPTIC, (int64_t) endDateWithHist[0][levelID].vec[i])
- date_to_julday(CALENDAR_PROLEPTIC, (int64_t) startDateWithHist[0][levelID].vec[i]));
if (DBL_IS_EQUAL(startDateWithHist[0][levelID].ptr[i], missval))
if (DBL_IS_EQUAL(startDateWithHist[0][levelID].vec[i], missval))
firstDay = missval;
else
firstDay = (double) day_of_year((int64_t) startDateWithHist[0][levelID].ptr[i]);
firstDay = (double) day_of_year((int64_t) startDateWithHist[0][levelID].vec[i]);
gslDuration[levelID].ptr[i] = duration;
gslFirstDay[levelID].ptr[i] = firstDay;
gslDuration[levelID].vec[i] = duration;
gslFirstDay[levelID].vec[i] = firstDay;
}
}
}
......@@ -572,8 +572,8 @@ computeGsl(int nlevels, size_t gridsize, std::vector<double> &yvals, double miss
for (levelID = 0; levelID < nlevels; levelID++)
{
gslDuration[levelID].nmiss = arrayNumMV(gridsize, gslDuration[levelID].ptr, missval);
gslFirstDay[levelID].nmiss = arrayNumMV(gridsize, gslFirstDay[levelID].ptr, missval);
gslDuration[levelID].nmiss = arrayNumMV(gridsize, gslDuration[levelID].vec.data(), missval);
gslFirstDay[levelID].nmiss = arrayNumMV(gridsize, gslFirstDay[levelID].vec.data(), missval);
}
}
......@@ -591,11 +591,11 @@ writeGslStream(int ostreamID, int otaxisID, int otsID, int ovarID1, int ovarID2,
for (int levelID = 0; levelID < nlevels; levelID++)
{
cdoDefRecord(ostreamID, ovarID1, levelID);
cdoWriteRecord(ostreamID, gslDuration[levelID].ptr, gslDuration[levelID].nmiss);
cdoWriteRecord(ostreamID, gslDuration[levelID].vec.data(), gslDuration[levelID].nmiss);
}
for (int levelID = 0; levelID < nlevels; levelID++)
{
cdoDefRecord(ostreamID, ovarID2, levelID);
cdoWriteRecord(ostreamID, gslFirstDay[levelID].ptr, gslFirstDay[levelID].nmiss);
cdoWriteRecord(ostreamID, gslFirstDay[levelID].vec.data(), gslFirstDay[levelID].nmiss);
}
}
......@@ -42,7 +42,7 @@ unsigned long day_of_year(int date);
* @param field1 the 1st input field, also holds the result
* @param field2 the 2nd input field
*/
void farnum(Field &field1, const Field &field2);
void vfarnum(Field &field1, const Field &field2);
/**
* Counts the number of consecutive nonmissing values in a field.
......@@ -58,7 +58,7 @@ void farnum(Field &field1, const Field &field2);
* @param field1 the 1st input field, also holds the result
* @param field2 the 2nd input field
*/
void farnum2(Field &field1, const Field &field2);
void vfarnum2(Field &field1, const Field &field2);
/**
* Counts the number of values in series of at least n consecutive
......@@ -76,7 +76,7 @@ void farnum2(Field &field1, const Field &field2);
* @param n the number of consecutive values, must be an exact
* mathematical integer
*/
void farnum3(Field &field1, const Field &field2, double n);
void vfarnum3(Field &field1, const Field &field2, double n);
/**
* Selects field elements according to a given mask. The result of
......@@ -91,7 +91,7 @@ void farnum3(Field &field1, const Field &field2, double n);
* @param field1 the input field, also holds the result
* @param field2 the mask
*/
void farsel(Field &field1, const Field &field2);
void vfarsel(Field &field1, const Field &field2);
/**
* Selects all field elements that are less than or equal to the
......@@ -107,7 +107,7 @@ void farsel(Field &field1, const Field &field2);
* @param field1 the input field, also holds the result
* @param field2 the reference field
*/
void farselle(Field &field1, const Field &field2);
void vfarselle(Field &field1, const Field &field2);
/**
* Selects all field elements that are less than the
......@@ -123,7 +123,7 @@ void farselle(Field &field1, const Field &field2);
* @param field1 the input field, also holds the result
* @param field2 the reference field
*/
void farsellt(Field &field1, const Field &field2);
void vfarsellt(Field &field1, const Field &field2);
/**
* Selects all field elements that are greater than or equal to
......@@ -139,7 +139,7 @@ void farsellt(Field &field1, const Field &field2);
* @param field1 the input field, also holds the result
* @param field2 the reference field
*/
void farselge(Field &field1, const Field &field2);
void vfarselge(Field &field1, const Field &field2);
/**
* Selects all field elements that are greater than the
......@@ -155,7 +155,7 @@ void farselge(Field &field1, const Field &field2);
* @param field1 the input field, also holds the result
* @param field2 the reference field
*/
void farselgt(Field &field1, const Field &field2);
void vfarselgt(Field &field1, const Field &field2);
/**
* Selects all field elements that are equal to the
......@@ -171,7 +171,7 @@ void farselgt(Field &field1, const Field &field2);
* @param field1 the input field, also holds the result
* @param field2 the reference field
*/
void farseleq(Field &field1, const Field &field2);
void vfarseleq(Field &field1, const Field &field2);
/**
* Selects all field elements that are not equal to the
......@@ -187,7 +187,7 @@ void farseleq(Field &field1, const Field &field2);
* @param field1 the input field, also holds the result
* @param field2 the reference field
*/
void farselne(Field &field1, const Field &field2);
void vfarselne(Field &field1, const Field &field2);
/**
* Selects all field elements that are less than or equal to a
......@@ -203,7 +203,7 @@ void farselne(Field &field1, const Field &field2);
* @param field the input field, also holds the result
* @param c the reference value
*/
void farsellec(Field &field, double c);
void vfarsellec(Field &field, double c);
/**
* Selects all field elements that are less a
......@@ -219,7 +219,7 @@ void farsellec(Field &field, double c);
* @param field the input field, also holds the result
* @param c the reference value
*/
void farselltc(Field &field, double c);
void vfarselltc(Field &field, double c);
/**
* Selects all field elements that are greater than or equal to a
......@@ -235,7 +235,7 @@ void farselltc(Field &field, double c);
* @param field the input field, also holds the result
* @param c the reference value
*/
void farselgec(Field &field, double c);
void vfarselgec(Field &field, double c);
/**
* Selects all field elements that are greater than a
......@@ -251,7 +251,7 @@ void farselgec(Field &field, double c);
* @param field the input field, also holds the result
* @param c the reference value
*/
void farselgtc(Field &field, double c);
void vfarselgtc(Field &field, double c);
/**
* Selects all field elements that are equal to a
......@@ -267,7 +267,7 @@ void farselgtc(Field &field, double c);
* @param field the input field, also holds the result
* @param c the reference value
*/
void farseleqc(Field &field, double c);
void vfarseleqc(Field &field, double c);
/**
* Selects all field elements that are not equal to a
......@@ -283,7 +283,7 @@ void farseleqc(Field &field, double c);
* @param field the input field, also holds the result
* @param c the reference value
*/
void farselnec(Field &field, double c);
void vfarselnec(Field &field, double c);
/**
* reset the fields real values to the missval for all levels
......
......@@ -491,11 +491,11 @@ fldbrs(Field &field) // Not used!
}
// Field UTILITIES
// update the number non missing values
// update the number of missing values
void
fldunm(Field &field)
vfldunm(Field &field)
{
field.nmiss = arrayNumMV(field.gridsize, field.ptr, field.missval);
field.nmiss = arrayNumMV(field.gridsize, field.vec.data(), field.missval);
}
double
......
......@@ -60,6 +60,12 @@ class Field
vec.resize(size);
}
void resize(size_t _size, double _value)
{
size = _size;
vec.resize(size, _value);
}
bool empty()
{
return size == 0;
......@@ -124,7 +130,7 @@ double vfldvar1w(const Field &field);
double vfldrank(Field &field);
double vfldpctl(Field &field, double pn);
void fldunm(Field &field);
void vfldunm(Field &field);
// fieldzon.cc
void zonfun(const Field &field1, Field &field2, int function);
......
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