Skip to content
Snippets Groups Projects
Commit 3ed09448 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Remapweights: add parameter map3d

parent a5aa5bef
No related branches found
No related tags found
1 merge request!145M214003/develop
......@@ -31,7 +31,38 @@
#include "griddes.h"
#include "cdo_options.h"
#include "util_string.h"
#include "pmlist.h"
static void
get_parameter(int offset, int &neighbors, bool &map3D, std::string &grid)
{
auto pargc = cdo_operator_argc() - offset;
if (pargc)
{
auto pargv = cdo_get_oper_argv();
pargv.erase(pargv.begin(), pargv.begin() + offset);
KVList kvlist;
kvlist.name = cdo_module_name();
if (kvlist.parse_arguments(pargc, pargv) != 0) cdo_abort("Parse error!");
if (Options::cdoVerbose) kvlist.print();
for (const auto &kv : kvlist)
{
const auto &key = kv.key;
if (kv.nvalues > 1) cdo_abort("Too many values for parameter key >%s<!", key);
if (kv.nvalues < 1) cdo_abort("Missing value for parameter key >%s<!", key);
const auto &value = kv.values[0];
// clang-format off
if (key == "grid") grid = parameter_to_word(value);
else if (key == "neighbors") neighbors = parameter_to_int(value);
else if (key == "map3D" || key == "map3d") map3D = parameter_to_bool(value);
else cdo_abort("Invalid parameter key >%s<!", key);
// clang-format on
}
}
}
static void
remap_write_weights(const std::string remapWeightsFile, const RemapSwitches &remapSwitches, RemapType &remap)
......@@ -64,8 +95,9 @@ add_operators(void)
class ModuleRemapweights
{
RemapSwitches remapSwitches;
int numRemaps = 0;
int numNeighbors = 0;
int numRemaps{ 0 };
int numNeighbors{ 0 };
bool map3D{ false };
CdoStreamID streamID1;
int vlistID1;
......@@ -115,21 +147,26 @@ public:
if (Options::cdoVerbose) cdo_print("Extrapolation %s!", remapExtrapolate ? "enabled" : "disabled");
{
operator_input_arg("grid description file or name");
if (operfunc == GENDIS && cdo_operator_argc() == 2)
{
auto inum = parameter_to_int(cdo_operator_argv(1));
if (inum < 1) cdo_abort("Number of nearest neighbors out of range (>0)!");
numNeighbors = inum;
}
else
{
operator_check_argc(1);
}
}
operator_input_arg("grid description file or name");
auto targetGrid = cdo_operator_argv(0);
int offset = string_starts_with(targetGrid, "grid=") ? 0 : 1;
if (cdo_operator_argc() > offset)
{
int numNeighborsParam = 0;
get_parameter(offset, numNeighborsParam, map3D, targetGrid);
if (map3D) remapParams.genMultiWeights = 1;
if (operfunc == GENDIS)
{
if (numNeighborsParam < 0) cdo_abort("Number of nearest neighbors out of range (>0)!");
if (numNeighborsParam > 0) numNeighbors = numNeighborsParam;
}
}
else
{
operator_check_argc(1);
}
gridID2 = cdo_define_grid(cdo_operator_argv(0));
gridID2 = cdo_define_grid(targetGrid);
if (gridInqType(gridID2) == GRID_GENERIC) cdo_abort("Unsupported target grid type (generic)!");
streamID1 = cdo_open_read(0);
......@@ -194,10 +231,7 @@ public:
if (remapGrids[gridIndex])
{
if (numRemaps == 0)
{
gridIDout = var.gridID;
}
if (numRemaps == 0) { gridIDout = var.gridID; }
else if (gridIDout != var.gridID)
{
continue;
......@@ -293,7 +327,7 @@ public:
outFile += ".nc";
}
//remap_write_weights(outFile, remapSwitches, remap);
// remap_write_weights(outFile, remapSwitches, remap);
if (numRemaps > 1) writeWorker.join();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment