Commit c4996c2d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Removed ptr from class Field.

parent 2bb825ed
......@@ -27,9 +27,8 @@ double varToStd(double rvar, double missval);
enum field_flag
{
FIELD_NONE = 1,
FIELD_PTR = 2,
FIELD_VEC = 4,
FIELD_FLT = 8,
FIELD_VEC = 2,
FIELD_FLT = 4,
};
class Field
......@@ -43,13 +42,11 @@ class Field
size_t nsamp;
size_t nmiss;
double missval;
double *ptr;
std::vector<double> vec;
std::vector<float> vecf;
std::vector<double> weightv;
Field() : fpeRaised(0), nwpv(-1), memtype(-1), grid(-1), gridsize(0), nsamp(0),
nmiss(0), missval(0), ptr(nullptr)
Field() : fpeRaised(0), nwpv(-1), memtype(-1), grid(-1), gridsize(0), nsamp(0), nmiss(0), missval(0)
{
size = 0;
}
......@@ -153,16 +150,8 @@ void merpctl(Field &field1, Field &field2, int p);
void vfldrms(const Field &field1, const Field &field2, Field &field3);
// fieldc.cc
void farcfun(Field &field, double rconst, int function);
void vfarcfun(Field &field, double rconst, int function);
void farcmul(Field &field, double rconst);
void farcdiv(Field &field, double rconst);
void farcadd(Field &field, double rconst);
void farcsub(Field &field, double rconst);
void farcmin(Field &field, double rconst);
void farcmax(Field &field, double rconst);
void vfarcmul(Field &field, double rconst);
void vfarcdiv(Field &field, double rconst);
void vfarcadd(Field &field, double rconst);
......@@ -177,24 +166,14 @@ void vfarcfuncplx(Field &field, const double rconstcplx[2], int function);
// field2.cc
void vfarfun(Field &field1, const Field &field2, int function);
void faradd(Field &field1, const Field &field2);
void vfaradd(Field &field1, const Field &field2);
void farsum(Field &field1, const Field &field2);
void vfarsum(Field &field1, const Field &field2);
void farsub(Field &field1, const Field &field2);
void vfarsub(Field &field1, const Field &field2);
void farmul(Field &field1, const Field &field2);
void vfarmul(Field &field1, const Field &field2);
void fardiv(Field &field1, const Field &field2);
void vfardiv(Field &field1, const Field &field2);
void farmin(Field &field1, const Field &field2);
void vfarmin(Field &field1, const Field &field2);
void farmax(Field &field1, const Field &field2);
void vfarmax(Field &field1, const Field &field2);
void faratan2(Field &field1, const Field &field2);
void vfaratan2(Field &field1, const Field &field2);
void farsetmiss(Field &field1, const Field &field2);
void vfarsetmiss(Field &field1, const Field &field2);
void vfarsumq(Field &field1, const Field &field2);
void vfarsumw(Field &field1, const Field &field2, double w);
......
......@@ -22,30 +22,8 @@
#include "array.h"
void
vfarfun(Field &field1, const Field &field2, int function)
{
// clang-format off
switch (function)
{
case func_add: vfaradd(field1, field2); break;
case func_min: vfarmin(field1, field2); break;
case func_max: vfarmax(field1, field2); break;
case func_sum: vfarsum(field1, field2); break;
case func_mean: vfarsum(field1, field2); break;
case func_avg: vfaradd(field1, field2); break;
case func_sub: vfarsub(field1, field2); break;
case func_mul: vfarmul(field1, field2); break;
case func_div: vfardiv(field1, field2); break;
case func_atan2: vfaratan2(field1, field2); break;
case func_setmiss: vfarsetmiss(field1, field2); break;
default: cdoAbort("%s: function %d not implemented!", __func__, function);
}
// clang-format on
}
static int
farsetnmiss(size_t len, std::vector<double> &array, double missval)
vfarsetnmiss(size_t len, std::vector<double> &array, double missval)
{
size_t nmiss = 0;
......@@ -95,36 +73,6 @@ vfarcpy(Field &field1, const Field &field2)
for (size_t i = 0; i < len; i++) array1[i] = array2[i];
}
void
faradd(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
size_t nmiss1 = field1.nmiss;
size_t nmiss2 = field2.nmiss;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1 > 0 || nmiss2 > 0)
{
for (size_t i = 0; i < len; i++) array1[i] = ADDMN(array1[i], array2[i]);
field1.nmiss = arrayNumMV(len, array1, missval1);
}
else
{
arrayAddArray(len, array1, array2);
}
}
void
vfaradd(Field &field1, const Field &field2)
{
......@@ -161,39 +109,6 @@ vfaradd(Field &field1, const Field &field2)
}
}
void
farsum(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
size_t gridsize1 = field1.gridsize;
size_t gridsize2 = field2.gridsize;
size_t nmiss1 = field1.nmiss;
size_t nmiss2 = field2.nmiss;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (gridsize1 == 0) gridsize1 = gridInqSize(field1.grid);
if (gridsize2 == 0) gridsize2 = gridInqSize(field2.grid);
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridsize1;
if (len != nwpv * gridsize2) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1 > 0 || nmiss2 > 0)
{
arrayAddArrayMV(len, array1, array2, missval2);
field1.nmiss = arrayNumMV(len, array1, missval1);
}
else
{
arrayAddArray(len, array1, array2);
}
}
void
vfarsum(Field &field1, const Field &field2)
{
......@@ -410,36 +325,6 @@ vfarsumqw(Field &field1, const Field &field2, double w)
}
}
void
farsub(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
size_t nmiss1 = field1.nmiss;
size_t nmiss2 = field2.nmiss;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1 > 0 || nmiss2 > 0)
{
for (size_t i = 0; i < len; i++) array1[i] = SUBMN(array1[i], array2[i]);
field1.nmiss = arrayNumMV(len, array1, missval1);
}
else
{
for (size_t i = 0; i < len; i++) array1[i] -= array2[i];
}
}
void
vfarsub(Field &field1, const Field &field2)
{
......@@ -468,36 +353,6 @@ vfarsub(Field &field1, const Field &field2)
}
}
void
farmul(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
size_t nmiss1 = field1.nmiss;
size_t nmiss2 = field2.nmiss;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1 > 0 || nmiss2 > 0)
{
for (size_t i = 0; i < len; i++) array1[i] = MULMN(array1[i], array2[i]);
field1.nmiss = arrayNumMV(len, array1, missval1);
}
else
{
for (size_t i = 0; i < len; i++) array1[i] *= array2[i];
}
}
void
vfarmul(Field &field1, const Field &field2)
{
......@@ -526,27 +381,6 @@ vfarmul(Field &field1, const Field &field2)
}
}
void
fardiv(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *array1 = field1.ptr;
double *array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
for (size_t i = 0; i < len; i++) array1[i] = DIVMN(array1[i], array2[i]);
field1.nmiss = arrayNumMV(len, array1, missval1);
}
void
vfardiv(Field &field1, const Field &field2)
{
......@@ -568,28 +402,6 @@ vfardiv(Field &field1, const Field &field2)
field1.nmiss = arrayNumMV(len, array1.data(), missval1);
}
void
faratan2(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
for (size_t i = 0; i < len; i++)
array1[i] = DBL_IS_EQUAL(array1[i], missval1) || DBL_IS_EQUAL(array2[i], missval2) ? missval1 : atan2(array1[i], array2[i]);
field1.nmiss = arrayNumMV(len, array1, missval1);
}
void
vfaratan2(Field &field1, const Field &field2)
{
......@@ -612,30 +424,6 @@ vfaratan2(Field &field1, const Field &field2)
field1.nmiss = arrayNumMV(len, array1.data(), missval1);
}
void
farsetmiss(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
size_t nmiss1 = field1.nmiss;
double missval1 = field1.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1)
{
for (size_t i = 0; i < len; i++) array1[i] = DBL_IS_EQUAL(array1[i], missval1) ? array2[i] : array1[i];
field1.nmiss = arrayNumMV(len, array1, missval1);
}
}
void
vfarsetmiss(Field &field1, const Field &field2)
{
......@@ -659,41 +447,6 @@ vfarsetmiss(Field &field1, const Field &field2)
}
}
void
farmin(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
size_t nmiss1 = field1.nmiss;
size_t nmiss2 = field2.nmiss;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1 > 0 || nmiss2 > 0)
{
for (size_t i = 0; i < len; i++)
{
array1[i] = DBL_IS_EQUAL(array2[i], missval2)
? array1[i]
: DBL_IS_EQUAL(array1[i], missval1) ? array2[i] : cdo::min(array1[i], array2[i]);
}
field1.nmiss = arrayNumMV(len, array1, missval1);
}
else
{
for (size_t i = 0; i < len; i++) array1[i] = cdo::min(array1[i], array2[i]);
}
}
void
vfarmin(Field &field1, const Field &field2)
{
......@@ -727,41 +480,6 @@ vfarmin(Field &field1, const Field &field2)
}
}
void
farmax(Field &field1, const Field &field2)
{
int nwpv = field1.nwpv;
int grid1 = field1.grid;
int grid2 = field2.grid;
size_t nmiss1 = field1.nmiss;
size_t nmiss2 = field2.nmiss;
double missval1 = field1.missval;
double missval2 = field2.missval;
double *restrict array1 = field1.ptr;
const double *restrict array2 = field2.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid1);
if (len != (nwpv * gridInqSize(grid2))) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1 > 0 || nmiss2 > 0)
{
for (size_t i = 0; i < len; i++)
{
array1[i] = DBL_IS_EQUAL(array2[i], missval2)
? array1[i]
: DBL_IS_EQUAL(array1[i], missval1) ? array2[i] : cdo::max(array1[i], array2[i]);
}
field1.nmiss = arrayNumMV(len, array1, missval1);
}
else
{
for (size_t i = 0; i < len; i++) array1[i] = cdo::max(array1[i], array2[i]);
}
}
void
vfarmax(Field &field1, const Field &field2)
{
......@@ -946,7 +664,7 @@ vfarvar(Field &field1, const Field &field2, const Field &field3, int divisor)
}
}
field1.nmiss = farsetnmiss(len, array1, missval1);
field1.nmiss = vfarsetnmiss(len, array1, missval1);
}
void
......@@ -1020,7 +738,7 @@ vfarcvar(Field &field1, const Field &field2, int nsets, int divisor)
}
}
field1.nmiss = farsetnmiss(len, array1, missval1);
field1.nmiss = vfarsetnmiss(len, array1, missval1);
}
void
......@@ -1165,3 +883,25 @@ vfarcount(Field &field1, const Field &field2)
for (size_t i = 0; i < len; i++) array1[i] += 1.0;
}
}
void
vfarfun(Field &field1, const Field &field2, int function)
{
// clang-format off
switch (function)
{
case func_add: vfaradd(field1, field2); break;
case func_min: vfarmin(field1, field2); break;
case func_max: vfarmax(field1, field2); break;
case func_sum: vfarsum(field1, field2); break;
case func_mean: vfarsum(field1, field2); break;
case func_avg: vfaradd(field1, field2); break;
case func_sub: vfarsub(field1, field2); break;
case func_mul: vfarmul(field1, field2); break;
case func_div: vfardiv(field1, field2); break;
case func_atan2: vfaratan2(field1, field2); break;
case func_setmiss: vfarsetmiss(field1, field2); break;
default: cdoAbort("%s: function %d not implemented!", __func__, function);
}
// clang-format on
}
......@@ -19,51 +19,6 @@
#include "cdo_int.h"
void
vfarcfun(Field &field, double rconst, int function)
{
switch (function)
{
case func_add: vfarcadd(field, rconst); break;
case func_sub: vfarcsub(field, rconst); break;
case func_mul: vfarcmul(field, rconst); break;
case func_div: vfarcdiv(field, rconst); break;
case func_min: vfarcmin(field, rconst); break;
case func_max: vfarcmax(field, rconst); break;
case func_mod: vfarmod(field, rconst); break;
default: cdoAbort("%s: function %d not implemented!", __func__, function);
}
}
void
farcmul(Field &field, double rconst)
{
int nwpv = field.nwpv;
int grid = field.grid;
size_t nmiss = field.nmiss;
double missval1 = field.missval;
double missval2 = field.missval;
double *array = field.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid);
if (nmiss > 0)
{
for (size_t i = 0; i < len; i++) array[i] = MULMN(array[i], rconst);
}
else
{
/*
#ifdef _OPENMP
#pragma omp parallel for default(shared) private(i)
#endif
*/
for (size_t i = 0; i < len; i++) array[i] *= rconst;
}
}
void
vfarcmul(Field &field, double rconst)
{
......@@ -71,7 +26,7 @@ vfarcmul(Field &field, double rconst)
int grid = field.grid;
double missval1 = field.missval;
double missval2 = field.missval;
std::vector<double> &array = field.vec;
auto &array = field.vec;
if (nwpv != 2) nwpv = 1;
......@@ -92,32 +47,6 @@ vfarcmul(Field &field, double rconst)
}
}
void
farcdiv(Field &field, double rconst)
{
int nwpv = field.nwpv;
int grid = field.grid;
size_t nmiss = field.nmiss;
double missval1 = field.missval;
double missval2 = field.missval;
double *array = field.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid);
if (nmiss > 0 || IS_EQUAL(rconst, 0))
{
for (size_t i = 0; i < len; i++) array[i] = DIVMN(array[i], rconst);
if (IS_EQUAL(rconst, 0)) field.nmiss = len;
}
else
{
for (size_t i = 0; i < len; i++) array[i] /= rconst;
}
}
void
vfarcdiv(Field &field, double rconst)
{
......@@ -126,7 +55,7 @@ vfarcdiv(Field &field, double rconst)
size_t nmiss = field.nmiss;
double missval1 = field.missval;
double missval2 = field.missval;
std::vector<double> &array = field.vec;
auto &array = field.vec;
if (nwpv != 2) nwpv = 1;
......@@ -144,30 +73,6 @@ vfarcdiv(Field &field, double rconst)
}
}
void
farcadd(Field &field, double rconst)
{
int nwpv = field.nwpv;
int grid = field.grid;
size_t nmiss = field.nmiss;
double missval1 = field.missval;
double missval2 = field.missval;
double *array = field.ptr;
if (nwpv != 2) nwpv = 1;
size_t len = nwpv * gridInqSize(grid);
if (nmiss > 0)
{
for (size_t i = 0; i < len; i++) array[i] = ADDMN(array[i], rconst);
}
else
{
for (size_t i = 0; i < len; i++) array[i] += rconst;
}
}
void
vfarcadd(Field &field, double rconst)
{
......@@ -176,7 +81,7 @@ vfarcadd(Field &field, double rconst)
size_t nmiss = field.nmiss;
double missval1 = field.missval;
double missval2 = field.missval;
std::vector<double> &array = field.vec;
auto &array = field.vec;
if (nwpv != 2) nwpv = 1;
......@@ -192,12 +97,6 @@ vfarcadd(Field &field, double rconst)
}
}
void
farcsub(Field &field, double rconst)
{
farcadd(field, -rconst);
}
void
vfarcsub(Field &field, double rconst)
{
......@@ -211,7 +110,7 @@ vfarcmin(Field &field, double rconst)
int grid = field.grid;
size_t nmiss = field.nmiss;
double missval1 = field.missval;
std::vector<double> &array = field.vec;
auto &array = field.vec;