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

Intlevel: changed type of weights to float.

parent 1009fc49
Pipeline #4224 passed with stages
in 21 minutes and 16 seconds
......@@ -32,15 +32,15 @@
template <typename T>
static double
vert_interp_lev_kernel(double w1, double w2, const T var1L1, const T var1L2, const T missval)
vert_interp_lev_kernel(float w1, float w2, const T var1L1, const T var1L2, const T missval)
{
if (DBL_IS_EQUAL(var1L1, missval)) w1 = 0.0;
if (DBL_IS_EQUAL(var1L2, missval)) w2 = 0.0;
if (DBL_IS_EQUAL(var1L1, missval)) w1 = 0.0f;
if (DBL_IS_EQUAL(var1L2, missval)) w2 = 0.0f;
// clang-format off
if (IS_EQUAL(w1, 0.0) && IS_EQUAL(w2, 0.0)) return missval;
else if (IS_EQUAL(w1, 0.0)) return (w2 >= 0.5) ? var1L2 : missval;
else if (IS_EQUAL(w2, 0.0)) return (w1 >= 0.5) ? var1L1 : missval;
if (IS_EQUAL(w1, 0.0f) && IS_EQUAL(w2, 0.0f)) return missval;
else if (IS_EQUAL(w1, 0.0f)) return (w2 >= 0.5f) ? var1L2 : missval;
else if (IS_EQUAL(w2, 0.0f)) return (w1 >= 0.5f) ? var1L1 : missval;
else return var1L1 * w1 + var1L2 * w2;
// clang-format on
}
......@@ -48,7 +48,7 @@ vert_interp_lev_kernel(double w1, double w2, const T var1L1, const T var1L2, con
// 1D vertical interpolation
static void
vert_interp_lev(size_t gridsize, double missval, const Varray<double> &vardata1, Varray<double> &vardata2, int nlev2,
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<double> &lev_wgt1, const Varray<double> &lev_wgt2)
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<float> &lev_wgt1, const Varray<float> &lev_wgt2)
{
for (int ilev = 0; ilev < nlev2; ++ilev)
{
......@@ -75,7 +75,7 @@ vert_interp_lev(size_t gridsize, double missval, const Varray<double> &vardata1,
template <typename T>
void
vert_interp_lev3d(size_t gridsize, T missval, const Varray<T> &vardata1, Varray<T> &vardata2, int nlev2,
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<double> &lev_wgt1, const Varray<double> &lev_wgt2)
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<float> &lev_wgt1, const Varray<float> &lev_wgt2)
{
for (int ilev = 0; ilev < nlev2; ilev++)
{
......@@ -104,10 +104,10 @@ vert_interp_lev3d(size_t gridsize, T missval, const Varray<T> &vardata1, Varray<
// Explicit instantiation
template void
vert_interp_lev3d(size_t gridsize, float missval, const Varray<float> &vardata1, Varray<float> &vardata2, int nlev2,
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<double> &lev_wgt1, const Varray<double> &lev_wgt2);
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<float> &lev_wgt1, const Varray<float> &lev_wgt2);
template void
vert_interp_lev3d(size_t gridsize, double missval, const Varray<double> &vardata1, Varray<double> &vardata2, int nlev2,
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<double> &lev_wgt1, const Varray<double> &lev_wgt2);
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<float> &lev_wgt1, const Varray<float> &lev_wgt2);
/*
void
......@@ -127,7 +127,7 @@ vert_interp_lev3d(size_t gridsize, double missval, Field3D &field1, Field3D &fie
void
vert_gen_weights(int expol, int nlev1, const Varray<double> &lev1, int nlev2, const Varray<double> &lev2, Varray<int> &lev_idx1, Varray<int> &lev_idx2,
Varray<double> &lev_wgt1, Varray<double> &lev_wgt2)
Varray<float> &lev_wgt1, Varray<float> &lev_wgt2)
{
for (int i2 = 0; i2 < nlev2; ++i2)
{
......@@ -152,7 +152,7 @@ vert_gen_weights(int expol, int nlev1, const Varray<double> &lev1, int nlev2, co
{
lev_idx1[i2] = 1;
lev_idx2[i2] = 1;
lev_wgt1[i2] = 0;
lev_wgt1[i2] = 0.0f;
lev_wgt2[i2] = (expol || IS_EQUAL(lev2[i2], val2));
}
else if (i1 == nlev1 - 1) // destination level is beyond the last value of the input z field
......@@ -160,7 +160,7 @@ vert_gen_weights(int expol, int nlev1, const Varray<double> &lev1, int nlev2, co
lev_idx1[i2] = nlev1 - 2;
lev_idx2[i2] = nlev1 - 2;
lev_wgt1[i2] = (expol || IS_EQUAL(lev2[i2], val2));
lev_wgt2[i2] = 0;
lev_wgt2[i2] = 0.0f;
}
else // target z values has two bounday values in input z field
{
......@@ -202,10 +202,10 @@ levelDirDown(const int nlev, const double *const lev)
template <typename T>
static void
vert_gen_weights3d1d(bool expol, size_t gridsize, int nlev1, const Varray<T> &xlev1, int nlev2, const Varray<double> &lev2,
Varray<int> &xlev_idx1, Varray<int> &xlev_idx2, Varray<double> &xlev_wgt1, Varray<double> &xlev_wgt2)
Varray<int> &xlev_idx1, Varray<int> &xlev_idx2, Varray<float> &xlev_wgt1, Varray<float> &xlev_wgt2)
{
Varray<double> lev1p2(nlev1 + 2);
Varray<double> lev_wgt1(nlev2), lev_wgt2(nlev2);
Varray<float> lev_wgt1(nlev2), lev_wgt2(nlev2);
Varray<int> lev_idx1(nlev2), lev_idx2(nlev2);
// Check monotony of vertical levels
......@@ -233,7 +233,7 @@ vert_gen_weights3d1d(bool expol, size_t gridsize, int nlev1, const Varray<T> &xl
static void
vert_gen_weights3d1d(bool expol, size_t gridsize, int nlev1, Field3D &field1, int nlev2, const Varray<double> &lev2,
Varray<int> &lev_idx1, Varray<int> &lev_idx2, Varray<double> &lev_wgt1, Varray<double> &lev_wgt2)
Varray<int> &lev_idx1, Varray<int> &lev_idx2, Varray<float> &lev_wgt1, Varray<float> &lev_wgt2)
{
if (field1.memType == MemType::Float)
{
......@@ -415,7 +415,7 @@ Intlevel(void *process)
varListInit(varList2, vlistID2);
Varray<int> lev_idx1(wisize), lev_idx2(wisize);
Varray<double> lev_wgt1(wisize), lev_wgt2(wisize);
Varray<float> lev_wgt1(wisize), lev_wgt2(wisize);
const auto streamID2 = cdoOpenWrite(1);
......
......@@ -31,9 +31,9 @@
template <typename T>
void vert_interp_lev3d(size_t gridsize, T missval, const Varray<T> &vardata1, Varray<T> &vardata2, int nlev2,
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<double> &lev_wgt1, const Varray<double> &lev_wgt2);
const Varray<int> &lev_idx1, const Varray<int> &lev_idx2, const Varray<float> &lev_wgt1, const Varray<float> &lev_wgt2);
void vert_gen_weights(int expol, int nlev1, const Varray<double> &lev1, int nlev2, const Varray<double> &lev2,
Varray<int> &lev_idx1, Varray<int> &lev_idx2, Varray<double> &lev_wgt1, Varray<double> &lev_wgt2);
Varray<int> &lev_idx1, Varray<int> &lev_idx2, Varray<float> &lev_wgt1, Varray<float> &lev_wgt2);
bool levelDirUp(const int nlev, const double *const lev);
bool levelDirDown(const int nlev, const double *const lev);
......@@ -47,11 +47,11 @@ bool levelDirDown(const int nlev, const double *const lev);
*/
static void
vert_gen_weights3d(bool expol, size_t gridsize, int nlev1, Varray<double> &xlev1, int nlev2, Varray<double> &xlev2,
Varray<int> &xlev_idx1, Varray<int> &xlev_idx2, Varray<double> &xlev_wgt1, Varray<double> &xlev_wgt2)
Varray<int> &xlev_idx1, Varray<int> &xlev_idx2, Varray<float> &xlev_wgt1, Varray<float> &xlev_wgt2)
{
Varray<double> lev1p2(nlev1 + 2);
Varray<double> lev1(nlev1), lev2(nlev2);
Varray<double> lev_wgt1(nlev2), lev_wgt2(nlev2);
Varray<double> lev2(nlev2);
Varray<float> lev_wgt1(nlev2), lev_wgt2(nlev2);
Varray<int> lev_idx1(nlev2), lev_idx2(nlev2);
// Check monotony of vertical levels
......@@ -85,7 +85,6 @@ Intlevel3d(void *process)
int nrecs;
int i;
int varID = -1, levelID = -1;
int nvct;
int zaxisID1 = -1, zaxisID3;
int gridID3 = -1;
int nlevo, maxlev;
......@@ -234,7 +233,7 @@ Intlevel3d(void *process)
// Create weights for later interpolation - assumption: input vertical correct is constant in time
Varray<int> lev_idx1(nlevo * gridSize), lev_idx2(nlevo * gridSize);
Varray<double> lev_wgt1(nlevo * gridSize), lev_wgt2(nlevo * gridSize);
Varray<float> lev_wgt1(nlevo * gridSize), lev_wgt2(nlevo * gridSize);
vert_gen_weights3d(expol, gridSize, nlevi, zlevels_in, nlevo, zlevels_out, lev_idx1, lev_idx2, lev_wgt1, lev_wgt2);
......@@ -246,7 +245,7 @@ Intlevel3d(void *process)
zaxisDefLevels(zaxisID3, lev2.data());
cdiDefKeyString(zaxisID3, CDI_GLOBAL, CDI_KEY_NAME, "lev");
// copy VCT from input vlistID1 to output vlistID3 if there is one
nvct = zaxisInqVctSize(zaxisID1);
const auto nvct = zaxisInqVctSize(zaxisID1);
if (nvct > 0) zaxisDefVct(zaxisID3, zaxisInqVctSize(zaxisID1), zaxisInqVctPtr(zaxisID1));
for (i = 0; i < nzaxis; i++)
......
......@@ -96,7 +96,7 @@ OFILE=${OPERATOR}_res
#
CDOTEST="$OPERATOR"
CDOCOMMAND="$CDO $FORMAT $OPERATOR,100000,92500,85000,50000,20000 $IFILE $OFILE"
TESTCOMMAND="$CDO diff $OFILE $RFILE"
TESTCOMMAND="$CDO diff,abslim=0.001 $OFILE $RFILE"
#
runTest
#
......
No preview for this file type
No preview for this file type
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