Commit 728d970e authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

remapReadDataScrip: pass some variable by reference instead of pointers.

parent 1f821564
Pipeline #4942 passed with stages
in 16 minutes and 47 seconds
......@@ -858,7 +858,7 @@ Remap(void *argument)
int remapOrder = 0;
if (lremap)
{
remapReadDataScrip(remap_file, gridID1, gridID2, &mapType, &submapType, &numNeighbors, remapOrder, remaps[0].src_grid,
remapReadDataScrip(remap_file, gridID1, gridID2, mapType, submapType, numNeighbors, remapOrder, remaps[0].src_grid,
remaps[0].tgt_grid, remaps[0].vars);
if (remaps[0].vars.links_per_value == 0) remapLinksPerValue(remaps[0].vars);
......
......@@ -222,7 +222,7 @@ remapGetNormOpt(const std::string &normOptStr)
return normOpt;
}
RemapMethod getMapType(int ncfileid, SubmapType *submapType, int *numNeighbors, int &remapOrder);
RemapMethod getMapType(int ncfileid, SubmapType &submapType, int &numNeighbors, int &remapOrder);
static void
readRemapGridScrip(const int ncfileid, const std::string &prefix, bool lgridarea, RemapGridW &grid)
......@@ -279,7 +279,7 @@ readRemapFileScrip(const char *remapFile, RemapAttributes &remapAtts, RemapMetho
}
// Map Type
mapType = getMapType(ncfileid, &submapType, &numNeighbors, remapOrder);
mapType = getMapType(ncfileid, submapType, numNeighbors, remapOrder);
const bool lgridarea = (mapType == RemapMethod::CONSERV || mapType == RemapMethod::CONSERV_SCRIP);
remapVarsWInit(mapType, remapOrder, rv);
......@@ -344,7 +344,7 @@ readRemapFileScrip(const char *remapFile, RemapAttributes &remapAtts, RemapMetho
// Close input file
cdo_cdf_close(ncfileid);
} // remapReadDataScrip
} // readRemapFileScrip
static int
cdfDefDim(int ncfileid, const char *name, size_t len)
......
......@@ -190,8 +190,8 @@ void sort_iter(size_t num_links, size_t num_wts, size_t *add1, size_t *add2, dou
void remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType submapType, int numNeighbors, int remapOrder,
RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &rv);
void remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMethod *mapType, SubmapType *submapType,
int *numNeighbors, int &remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &rv);
void remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMethod &mapType, SubmapType &submapType,
int &numNeighbors, int &remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &rv);
void calcLatBins(GridSearchBins &searchBins);
size_t get_srch_cells(size_t tgt_cell_addr, GridSearchBins &tgtBins, GridSearchBins &srcBins, float *tgt_cell_bound_box,
......
......@@ -36,22 +36,22 @@ bicubicSetWeights(double iw, double jw, double (&weights)[4][4])
const auto jw2 = jw*(jw-1.0)*(jw-1.0);
const auto jw3 = jw*jw*(3.0-2.0*jw);
// clang-format off
weights[0][0] = (1.0-jw3) * (1.0-iw3);
weights[1][0] = (1.0-jw3) * iw3;
weights[2][0] = jw3 * iw3;
weights[3][0] = jw3 * (1.0-iw3);
weights[0][1] = (1.0-jw3) * iw2;
weights[1][1] = (1.0-jw3) * iw1;
weights[2][1] = jw3 * iw1;
weights[3][1] = jw3 * iw2;
weights[0][2] = jw2 * (1.0-iw3);
weights[1][2] = jw2 * iw3;
weights[2][2] = jw1 * iw3;
weights[3][2] = jw1 * (1.0-iw3);
weights[0][3] = jw2 * iw2;
weights[1][3] = jw2 * iw1;
weights[2][3] = jw1 * iw1;
weights[3][3] = jw1 * iw2;
weights[0][0] = (1.0-jw3) * (1.0-iw3);
weights[1][0] = (1.0-jw3) * iw3;
weights[2][0] = jw3 * iw3;
weights[3][0] = jw3 * (1.0-iw3);
weights[0][1] = (1.0-jw3) * iw2;
weights[1][1] = (1.0-jw3) * iw1;
weights[2][1] = jw3 * iw1;
weights[3][1] = jw3 * iw2;
weights[0][2] = jw2 * (1.0-iw3);
weights[1][2] = jw2 * iw3;
weights[2][2] = jw1 * iw3;
weights[3][2] = jw1 * (1.0-iw3);
weights[0][3] = jw2 * iw2;
weights[1][3] = jw2 * iw1;
weights[2][3] = jw1 * iw1;
weights[3][3] = jw1 * iw2;
// clang-format on
}
......
......@@ -175,10 +175,8 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
case RemapMethod::UNDEF: break;
}
/*
if ( rv.num_links == 0 )
cdoAbort("Number of remap links is 0, no remap weights found!");
*/
// if (rv.num_links == 0) cdoAbort("Number of remap links is 0, no remap weights found!");
{
size_t nlinks = rv.num_links;
size_t nele1 = 4 * 8 + 4;
......@@ -408,7 +406,7 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
nce(nc_put_var_double(nc_file_id, nc_srcgrdfrac_id, &src_grid.cell_frac[0]));
/*
if ( luse_cell_area )
if (luse_cell_area)
nce(nc_put_var_double(nc_file_id, nc_dstgrdarea_id, tgt_grid.cell_area_in));
else
*/
......@@ -438,7 +436,7 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
#ifdef HAVE_LIBNETCDF
RemapMethod
getMapType(int nc_file_id, SubmapType *submapType, int *numNeighbors, int &remapOrder)
getMapType(int nc_file_id, SubmapType &submapType, int &numNeighbors, int &remapOrder)
{
// Map method
size_t attlen;
......@@ -447,7 +445,7 @@ getMapType(int nc_file_id, SubmapType *submapType, int *numNeighbors, int &remap
nce(nc_inq_attlen(nc_file_id, NC_GLOBAL, "map_method", &attlen));
map_method[attlen] = 0;
*submapType = SubmapType::NONE;
submapType = SubmapType::NONE;
remapOrder = 1;
RemapMethod mapType = RemapMethod::UNDEF;
......@@ -469,17 +467,17 @@ getMapType(int nc_file_id, SubmapType *submapType, int *numNeighbors, int &remap
else if (cdo_cmpstrLenRhs(map_method, "Distance"))
{
mapType = RemapMethod::DISTWGT;
*numNeighbors = 4;
numNeighbors = 4;
}
else if (cdo_cmpstrLenRhs(map_method, "Nearest"))
{
mapType = RemapMethod::DISTWGT;
*numNeighbors = 1;
numNeighbors = 1;
}
else if (cdo_cmpstrLenRhs(map_method, "Largest"))
{
mapType = RemapMethod::CONSERV_SCRIP;
*submapType = SubmapType::LAF;
submapType = SubmapType::LAF;
}
else
{
......@@ -494,8 +492,8 @@ getMapType(int nc_file_id, SubmapType *submapType, int *numNeighbors, int &remap
#endif
void
remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMethod *mapType, SubmapType *submapType,
int *numNeighbors, int &remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &rv)
remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMethod &mapType, SubmapType &submapType,
int &numNeighbors, int &remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &rv)
{
// The routine reads a NetCDF file to extract remapping info in SCRIP format
......@@ -544,7 +542,7 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
// Open file and read some global information
int nc_file_id = cdo_cdf_openread(interp_file);
const auto nc_file_id = cdo_cdf_openread(interp_file);
// Map name
......@@ -559,13 +557,13 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
}
// Map Tyoe
*mapType = getMapType(nc_file_id, submapType, numNeighbors, remapOrder);
mapType = getMapType(nc_file_id, submapType, numNeighbors, remapOrder);
if (*mapType == RemapMethod::CONSERV_SCRIP) lgridarea = true;
if (mapType == RemapMethod::CONSERV_SCRIP) lgridarea = true;
remapVarsInit(*mapType, remapOrder, rv);
remapVarsInit(mapType, remapOrder, rv);
rv.mapType = *mapType;
rv.mapType = mapType;
rv.links_per_value = -1;
rv.sort_add = false;
......@@ -623,17 +621,13 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
nce(nc_inq_dimid(nc_file_id, "src_grid_size", &nc_srcgrdsize_id));
nce(nc_inq_dimlen(nc_file_id, nc_srcgrdsize_id, &dimlen));
src_grid.size = dimlen;
/*
if ( src_grid.size != gridInqSize(gridID1) )
cdoAbort("Source grids have different size!");
*/
// if (src_grid.size != gridInqSize(gridID1)) cdoAbort("Source grids have different size!");
nce(nc_inq_dimid(nc_file_id, "dst_grid_size", &nc_dstgrdsize_id));
nce(nc_inq_dimlen(nc_file_id, nc_dstgrdsize_id, &dimlen));
tgt_grid.size = dimlen;
/*
if ( tgt_grid.size != gridInqSize(gridID2) )
cdoAbort("Target grids have different size!");
*/
// if (tgt_grid.size != gridInqSize(gridID2)) cdoAbort("Target grids have different size!");
status = nc_inq_dimid(nc_file_id, "src_grid_corners", &nc_srcgrdcorn_id);
if (status == NC_NOERR)
{
......@@ -663,10 +657,8 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
nce(nc_inq_dimid(nc_file_id, "num_links", &nc_numlinks_id));
nce(nc_inq_dimlen(nc_file_id, nc_numlinks_id, &dimlen));
rv.num_links = dimlen;
/*
if ( rv.num_links == 0 )
cdoAbort("Number of remap links is 0, no remap weights found!");
*/
// if (rv.num_links == 0) cdoAbort("Number of remap links is 0, no remap weights found!");
nce(nc_inq_dimid(nc_file_id, "num_wgts", &nc_numwgts_id));
nce(nc_inq_dimlen(nc_file_id, nc_numwgts_id, &dimlen));
rv.num_wts = dimlen;
......
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