Commit 427625e0 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Vargen: use remap_nn_reg2d_to_reg2d() for Gaussian grids.

parent 93aa60d6
Pipeline #4771 passed with stages
in 17 minutes and 24 seconds
......@@ -104,9 +104,10 @@ conv_generic_grid(const int gridID, const size_t gridsize, Varray<double> &xvals
}
static void
remap_nn_reg2d_reg2d(size_t nx, size_t ny, const double *restrict data, const int gridID, double *restrict array)
remap_nn_reg2d_to_reg2d(size_t nx, size_t ny, const double *restrict data, const int gridID, double *restrict array)
{
if (gridInqType(gridID) != GRID_LONLAT) cdoAbort("Internal error, wrong grid type!");
const auto gridtype = gridInqType(gridID);
if (gridtype != GRID_LONLAT && gridtype != GRID_GAUSSIAN) cdoAbort("Internal error, wrong grid type!");
auto nxvals = gridInqXsize(gridID);
auto nyvals = gridInqYsize(gridID);
......@@ -140,7 +141,7 @@ remap_nn_reg2d_reg2d(size_t nx, size_t ny, const double *restrict data, const in
}
static void
remap_nn_reg2d_nonreg2d(const size_t nx, const size_t ny, const double *restrict data, const int gridID, double *restrict array)
remap_nn_reg2d_to_nonreg2d(const size_t nx, const size_t ny, const double *restrict data, const int gridID, double *restrict array)
{
auto gridID2 = gridID;
const auto gridsize = gridInqSize(gridID2);
......@@ -177,14 +178,15 @@ remap_nn_reg2d_nonreg2d(const size_t nx, const size_t ny, const double *restrict
static void
remap_nn_reg2d(const size_t nx, const size_t ny, const double *restrict data, const int gridID, double *restrict array)
{
if (gridInqType(gridID) == GRID_LONLAT)
remap_nn_reg2d_reg2d(nx, ny, data, gridID, array);
const auto gridtype = gridInqType(gridID);
if (gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN)
remap_nn_reg2d_to_reg2d(nx, ny, data, gridID, array);
else
remap_nn_reg2d_nonreg2d(nx, ny, data, gridID, array);
remap_nn_reg2d_to_nonreg2d(nx, ny, data, gridID, array);
}
static int
randomInit(const int operatorID)
random_init(const int operatorID)
{
unsigned int seed = Options::Random_Seed;
operatorInputArg(cdoOperatorEnter(operatorID));
......@@ -201,25 +203,25 @@ randomInit(const int operatorID)
}
static void
randomCompute(const size_t gridsize, Varray<double> &array)
random_compute(const size_t gridsize, Varray<double> &array)
{
for (size_t i = 0; i < gridsize; ++i) array[i] = ((double) std::rand()) / ((double) RAND_MAX);
}
static void
sincosCompute(const size_t gridsize, Varray<double> &array, const Varray<double> &xvals, const Varray<double> &yvals)
sincos_compute(const size_t gridsize, Varray<double> &array, const Varray<double> &xvals, const Varray<double> &yvals)
{
for (size_t i = 0; i < gridsize; ++i) array[i] = std::cos(1.0 * xvals[i]) * std::sin(2.0 * yvals[i]);
}
static void
coshillCompute(const size_t gridsize, Varray<double> &array, const Varray<double> &xvals, const Varray<double> &yvals)
coshill_compute(const size_t gridsize, Varray<double> &array, const Varray<double> &xvals, const Varray<double> &yvals)
{
for (size_t i = 0; i < gridsize; ++i) array[i] = 2 - std::cos(std::acos(std::cos(xvals[i]) * std::cos(yvals[i])) / 1.2);
}
static void
testfieldCompute(const size_t gridsize, Varray<double> &array, const Varray<double> &xvals, const Varray<double> &yvals)
testfield_compute(const size_t gridsize, Varray<double> &array, const Varray<double> &xvals, const Varray<double> &yvals)
{
double xyz[3];
for (size_t i = 0; i < gridsize; ++i)
......@@ -233,13 +235,13 @@ testfieldCompute(const size_t gridsize, Varray<double> &array, const Varray<doub
}
static void
unpackData(const size_t datasize, Varray<double> &data, const double scale, const double offset, const unsigned short *zdata)
unpack_data(const size_t datasize, Varray<double> &data, const double scale, const double offset, const unsigned short *zdata)
{
for (size_t i = 0; i < datasize; ++i) data[i] = zdata[i] / scale - offset;
}
static int
definePointGrid()
define_point_grid()
{
const auto gridID = gridCreate(GRID_LONLAT, 1);
gridDefXsize(gridID, 1);
......@@ -252,7 +254,7 @@ definePointGrid()
}
static int
defineZaxis(const bool lstdatm, const int nlevels, double *levels)
define_zaxis(const bool lstdatm, const int nlevels, double *levels)
{
int zaxisID = -1;
......@@ -273,7 +275,7 @@ defineZaxis(const bool lstdatm, const int nlevels, double *levels)
}
static void
definePressureAttributes(const int vlistID, const int varID)
define_pressure_attributes(const int vlistID, const int varID)
{
vlistDefVarParam(vlistID, varID, cdiEncodeParam(1, 255, 255));
cdiDefKeyString(vlistID, varID, CDI_KEY_NAME, "P");
......@@ -283,7 +285,7 @@ definePressureAttributes(const int vlistID, const int varID)
}
static void
defineTemperatureAttributes(const int vlistID, const int varID)
define_temperature_attributes(const int vlistID, const int varID)
{
vlistDefVarParam(vlistID, varID, cdiEncodeParam(130, 128, 255));
cdiDefKeyString(vlistID, varID, CDI_KEY_NAME, "T");
......@@ -295,8 +297,7 @@ defineTemperatureAttributes(const int vlistID, const int varID)
void *
Vargen(void *process)
{
constexpr size_t nlat = 360;
constexpr size_t nlon = 720;
constexpr size_t nlat = 360, nlon = 720;
double lon[nlon], lat[nlat];
int ntimesteps, nlevels = 1;
int gridID = -1, gridIDdata = -1;
......@@ -323,7 +324,7 @@ Vargen(void *process)
if (operatorID == RANDOM)
{
gridID = randomInit(operatorID);
gridID = random_init(operatorID);
}
else if (operatorID == SINCOS || operatorID == COSHILL || operatorID == TESTFIELD)
{
......@@ -366,7 +367,7 @@ Vargen(void *process)
rinc = (operatorArgc() == 3) ? parameter2double(cdoOperatorArgv(2)) : 1;
if (DBL_IS_EQUAL(rinc, 0.0)) cdoAbort("Increment is zero!");
gridID = definePointGrid();
gridID = define_point_grid();
}
else if (operatorID == STDATM)
{
......@@ -377,10 +378,10 @@ Vargen(void *process)
if (Options::cdoVerbose)
for (int i = 0; i < nlevels; ++i) printf("levels %d: %g\n", i, levels[i]);
gridID = definePointGrid();
gridID = define_point_grid();
}
const auto zaxisID = defineZaxis(operatorID == STDATM, nlevels, levels.data());
const auto zaxisID = define_zaxis(operatorID == STDATM, nlevels, levels.data());
const auto vlistID = vlistCreate();
......@@ -398,8 +399,8 @@ Vargen(void *process)
if (operatorID == STDATM)
{
definePressureAttributes(vlistID, varID);
defineTemperatureAttributes(vlistID, varID2);
define_pressure_attributes(vlistID, varID);
define_temperature_attributes(vlistID, varID2);
}
else
{
......@@ -452,7 +453,7 @@ Vargen(void *process)
if (operatorID == RANDOM)
{
randomCompute(gridsize, array);
random_compute(gridsize, array);
}
else if (operatorID == SINCOS || operatorID == COSHILL || operatorID == TESTFIELD)
{
......@@ -479,15 +480,15 @@ Vargen(void *process)
if (operatorID == SINCOS)
{
sincosCompute(gridsize, array, xvals, yvals);
sincos_compute(gridsize, array, xvals, yvals);
}
else if (operatorID == COSHILL)
{
coshillCompute(gridsize, array, xvals, yvals);
coshill_compute(gridsize, array, xvals, yvals);
}
else if (operatorID == TESTFIELD)
{
testfieldCompute(gridsize, array, xvals, yvals);
testfield_compute(gridsize, array, xvals, yvals);
}
}
else if (operatorID == CONST)
......@@ -500,9 +501,9 @@ Vargen(void *process)
Varray<double> data(datasize);
// clang-format off
if (operatorID == TOPO) unpackData(datasize, data, etopo_scale, etopo_offset, etopo);
else if (operatorID == TEMP) unpackData(datasize, data, temp_scale, temp_offset, temp);
else if (operatorID == MASK) unpackData(datasize, data, mask_scale, mask_offset, mask);
if (operatorID == TOPO) unpack_data(datasize, data, etopo_scale, etopo_offset, etopo);
else if (operatorID == TEMP) unpack_data(datasize, data, temp_scale, temp_offset, temp);
else if (operatorID == MASK) unpack_data(datasize, data, mask_scale, mask_offset, mask);
// clang-format on
if (gridID != gridIDdata && gridIDdata != -1)
......
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