Commit 87abbffe authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

remapgrid_get_lonlat: changed interface.

parent 78b41490
......@@ -56,6 +56,13 @@ enum class SubmapType
SUM
};
struct LonLatPoint
{
double lon, lat;
LonLatPoint() {};
LonLatPoint(double _lon, double _lat) : lon(_lon), lat(_lat) {};
};
struct RemapGrid
{
int gridID;
......@@ -76,7 +83,6 @@ struct RemapGrid
int nvgp; // size of vgpm
std::vector<int> vgpm; // flag which cells are valid
std::vector<int> mask; // flag which cells participate
double *reg2d_center_lon; // reg2d lon/lat coordinates for
......@@ -188,7 +194,7 @@ int gridSearchSquareCurv2dScrip(RemapGrid *src_grid, size_t *src_add, double *sr
bool remapFindWeights(double plon, double plat, double *src_lons, double *src_lats, double *ig, double *jg);
int rect_grid_search(size_t *ii, size_t *jj, double x, double y, size_t nxm, size_t nym, const double *xm, const double *ym);
void remapgrid_get_lonlat(RemapGrid *grid, size_t cell_add, double *plon, double *plat);
LonLatPoint remapgrid_get_lonlat(RemapGrid *grid, size_t cell_add);
void remapCheckArea(size_t grid_size, double *cell_area, const char *name);
......
......@@ -136,8 +136,7 @@ remapBicubicWeights(RemapSearch &rsearch, RemapVars &rv)
if (!tgt_grid->mask[tgt_cell_add]) continue;
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
const auto llp = remapgrid_get_lonlat(tgt_grid, tgt_cell_add);
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
......@@ -145,7 +144,7 @@ remapBicubicWeights(RemapSearch &rsearch, RemapVars &rv)
double wgts[4][4]; // bicubic weights for four corners
// Find nearest square of grid points on source grid
int search_result = remapSearchSquare(rsearch, plon, plat, src_add, src_lats, src_lons);
int search_result = remapSearchSquare(rsearch, llp.lon, llp.lat, src_add, src_lats, src_lons);
// Check to see if points are mask points
if (search_result > 0)
......@@ -160,7 +159,7 @@ remapBicubicWeights(RemapSearch &rsearch, RemapVars &rv)
tgt_grid->cell_frac[tgt_cell_add] = 1.;
double iw, jw; // current guess for bilinear coordinate
if (remapFindWeights(plon, plat, src_lons, src_lats, &iw, &jw))
if (remapFindWeights(llp.lon, llp.lat, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bicubicSetWeights(iw, jw, wgts);
......@@ -253,8 +252,7 @@ remapBicubic(RemapSearch &rsearch, const double *restrict src_array, double *res
if (!tgt_grid->mask[tgt_cell_add]) continue;
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
const auto llp = remapgrid_get_lonlat(tgt_grid, tgt_cell_add);
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
......@@ -262,7 +260,7 @@ remapBicubic(RemapSearch &rsearch, const double *restrict src_array, double *res
double wgts[4][4]; // bicubic weights for four corners
// Find nearest square of grid points on source grid
int search_result = remapSearchSquare(rsearch, plon, plat, src_add, src_lats, src_lons);
int search_result = remapSearchSquare(rsearch, llp.lon, llp.lat, src_add, src_lats, src_lons);
// Check to see if points are mask points
if (search_result > 0)
......@@ -277,7 +275,7 @@ remapBicubic(RemapSearch &rsearch, const double *restrict src_array, double *res
tgt_grid->cell_frac[tgt_cell_add] = 1.;
double iw, jw; // current guess for bilinear coordinate
if (remapFindWeights(plon, plat, src_lons, src_lats, &iw, &jw))
if (remapFindWeights(llp.lon, llp.lat, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bicubicSetWeights(iw, jw, wgts);
......
......@@ -206,8 +206,7 @@ remapBilinearWeights(RemapSearch &rsearch, RemapVars &rv)
if (!tgt_grid->mask[tgt_cell_add]) continue;
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
const auto llp = remapgrid_get_lonlat(tgt_grid, tgt_cell_add);
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
......@@ -215,7 +214,7 @@ remapBilinearWeights(RemapSearch &rsearch, RemapVars &rv)
double wgts[4]; // bilinear weights for four corners
// Find nearest square of grid points on source grid
int search_result = remapSearchSquare(rsearch, plon, plat, src_add, src_lats, src_lons);
int search_result = remapSearchSquare(rsearch, llp.lon, llp.lat, src_add, src_lats, src_lons);
// Check to see if points are mask points
if (search_result > 0)
......@@ -230,7 +229,7 @@ remapBilinearWeights(RemapSearch &rsearch, RemapVars &rv)
tgt_grid->cell_frac[tgt_cell_add] = 1.;
double iw, jw; // current guess for bilinear coordinate
if (remapFindWeights(plon, plat, src_lons, src_lats, &iw, &jw))
if (remapFindWeights(llp.lon, llp.lat, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bilinearSetWeights(iw, jw, wgts);
......@@ -313,8 +312,7 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
if (!tgt_grid->mask[tgt_cell_add]) continue;
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
const auto llp = remapgrid_get_lonlat(tgt_grid, tgt_cell_add);
size_t src_add[4]; // address for the four source points
double src_lats[4]; // latitudes of four bilinear corners
......@@ -322,7 +320,7 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
double wgts[4]; // bilinear weights for four corners
// Find nearest square of grid points on source grid
int search_result = remapSearchSquare(rsearch, plon, plat, src_add, src_lats, src_lons);
int search_result = remapSearchSquare(rsearch, llp.lon, llp.lat, src_add, src_lats, src_lons);
// Check to see if points are mask points
if (search_result > 0)
......@@ -337,7 +335,7 @@ remapBilinear(RemapSearch &rsearch, const double *restrict src_array, double *re
tgt_grid->cell_frac[tgt_cell_add] = 1.;
double iw, jw; // current guess for bilinear coordinate
if (remapFindWeights(plon, plat, src_lons, src_lats, &iw, &jw))
if (remapFindWeights(llp.lon, llp.lat, src_lons, src_lats, &iw, &jw))
{
// Successfully found iw,jw - compute weights
bilinearSetWeights(iw, jw, wgts);
......
......@@ -70,14 +70,13 @@ remapDistwgtWeights(size_t numNeighbors, RemapSearch &rsearch, RemapVars &rv)
if (!tgt_grid->mask[tgt_cell_add]) continue;
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
const auto llp = remapgrid_get_lonlat(tgt_grid, tgt_cell_add);
// Find nearest grid points on source grid and distances to each point
remapSearchPoints(rsearch, plon, plat, knnWeights[ompthID]);
remapSearchPoints(rsearch, llp.lon, llp.lat, knnWeights[ompthID]);
// Compute weights based on inverse distance if mask is false, eliminate those points
const size_t nadds = knnWeights[ompthID].computeWeights(src_grid->mask);
const auto nadds = knnWeights[ompthID].computeWeights(src_grid->mask);
for (size_t n = 0; n < nadds; ++n)
if (knnWeights[ompthID].m_mask[n]) tgt_grid->cell_frac[tgt_cell_add] = 1.0;
......@@ -146,14 +145,13 @@ remapDistwgt(size_t numNeighbors, RemapSearch &rsearch, const double *restrict s
if (!tgt_grid->mask[tgt_cell_add]) continue;
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
const auto llp = remapgrid_get_lonlat(tgt_grid, tgt_cell_add);
// Find nearest grid points on source grid and distances to each point
remapSearchPoints(rsearch, plon, plat, knnWeights[ompthID]);
remapSearchPoints(rsearch, llp.lon, llp.lat, knnWeights[ompthID]);
// Compute weights based on inverse distance if mask is false, eliminate those points
const size_t nadds = knnWeights[ompthID].computeWeights(src_grid_mask);
const auto nadds = knnWeights[ompthID].computeWeights(src_grid_mask);
if (nadds) tgt_array[tgt_cell_add] = knnWeights[ompthID].arrayWeightsSum(src_array);
}
......@@ -218,11 +216,10 @@ intgriddis(Field &field1, Field &field2, size_t numNeighbors)
if (!tgt_mask[tgt_cell_add]) continue;
double plon = 0, plat = 0;
remapgrid_get_lonlat(&remap.tgt_grid, tgt_cell_add, &plon, &plat);
const auto llp = remapgrid_get_lonlat(&remap.tgt_grid, tgt_cell_add);
// Find nearest grid points on source grid and distances to each point
remapSearchPoints(remap.search, plon, plat, knnWeights[ompthID]);
remapSearchPoints(remap.search, llp.lon, llp.lat, knnWeights[ompthID]);
// Compute weights based on inverse distance if mask is false, eliminate those points
const auto nadds = knnWeights[ompthID].computeWeights(src_mask);
......
......@@ -174,23 +174,27 @@ boundboxFromCenter(bool lonIsCyclic, size_t size, size_t nx, size_t ny, const do
}
}
void
remapgrid_get_lonlat(RemapGrid *grid, size_t cell_add, double *plon, double *plat)
LonLatPoint
remapgrid_get_lonlat(RemapGrid *grid, size_t cell_add)
{
double lon, lat;
if (grid->type == RemapGridType::Reg2D)
{
size_t nx = grid->dims[0];
size_t iy = cell_add / nx;
size_t ix = cell_add - iy * nx;
*plat = grid->reg2d_center_lat[iy];
*plon = grid->reg2d_center_lon[ix];
if (*plon < 0) *plon += PI2;
const auto nx = grid->dims[0];
const auto iy = cell_add / nx;
const auto ix = cell_add - iy * nx;
lat = grid->reg2d_center_lat[iy];
lon = grid->reg2d_center_lon[ix];
if (lon < 0) lon += PI2;
}
else
{
*plat = grid->cell_center_lat[cell_add];
*plon = grid->cell_center_lon[cell_add];
lat = grid->cell_center_lat[cell_add];
lon = grid->cell_center_lon[cell_add];
}
return LonLatPoint(lon, lat);
}
void
......
Supports Markdown
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