Commit 5a6908a8 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

remap.h: changed type of dims to size_t.

parent 44facf60
......@@ -1031,6 +1031,7 @@ void *Remap(void *argument)
if ( gridIsCircular(gridID1) && !lextrapolate ) remap_extrapolate = true;
if ( map_type == MAP_TYPE_DISTWGT && !remap_extrapolate && gridInqSize(gridID1) > 1 && !is_global_grid(gridID1) )
{
if ( cdoVerbose ) cdoPrint("---> Expand array!");
long nx = gridInqXsize(gridID1);
long ny = gridInqYsize(gridID1);
size_t gridsize_new = gridsize + 4*(nx+2) + 4*(ny+2);
......
......@@ -83,16 +83,19 @@ void gridsearch_extrapolate(struct gridsearch *gs)
}
struct gridsearch *gridsearch_create_reg2d(bool lcyclic, size_t nx, size_t ny, const double *restrict lons, const double *restrict lats)
struct gridsearch *gridsearch_create_reg2d(bool is_cyclic, size_t dims[2], const double *restrict lons, const double *restrict lats)
{
struct gridsearch *gs = (struct gridsearch *) Calloc(1, sizeof(struct gridsearch));
gs->reg2d = true;
gs->nx = nx;
gs->ny = ny;
gs->is_cyclic = is_cyclic;
gs->is_reg2d = true;
gs->dims[0] = dims[0];
gs->dims[1] = dims[1];
size_t nx = dims[0];
size_t ny = dims[0];
size_t nxm = nx;
if ( lcyclic ) nxm++;
if ( is_cyclic ) nxm++;
double *reg2d_center_lon = (double *) Malloc(nxm*sizeof(double));
double *reg2d_center_lat = (double *) Malloc(ny*sizeof(double));
......
......@@ -27,10 +27,11 @@ struct gsNear {
struct gridsearch {
bool extrapolate;
bool reg2d;
bool is_cyclic;
bool is_reg2d;
int method_nn;
size_t n;
size_t nx, ny;
size_t dims[2];
struct gsNear *near;
struct kdNode *kdt;
......@@ -58,7 +59,7 @@ struct gsknn *gridsearch_knn_new(size_t size);
void gridsearch_knn_delete(struct gsknn *knn);
size_t gridsearch_knn(struct gridsearch *gs, struct gsknn *knn, double plon, double plat);
struct gridsearch *gridsearch_create_reg2d(bool lcyclic, size_t nx, size_t ny, const double *restrict lons, const double *restrict lats);
struct gridsearch *gridsearch_create_reg2d(bool is_cyclic, size_t dims[2], const double *restrict lons, const double *restrict lats);
struct gridsearch *gridsearch_create(size_t n, const double *restrict lons, const double *restrict lats);
struct gridsearch *gridsearch_create_nn(size_t n, const double *restrict lons, const double *restrict lats);
void gridsearch_delete(struct gridsearch *gs);
......
......@@ -87,7 +87,7 @@ typedef struct {
bool non_global;
bool is_cyclic;
int dims[2]; /* size of grid dimension */
size_t dims[2]; /* size of grid dimension */
int nvgp; /* size of vgpm */
int* vgpm; /* flag which cells are valid */
......@@ -223,11 +223,11 @@ int grid_search_reg2d_nn(size_t nx, size_t ny, size_t *restrict nbr_add, double
const double *restrict src_center_lat, const double *restrict src_center_lon);
int grid_search_reg2d(remapgrid_t *src_grid, size_t *restrict src_add, double *restrict src_lats,
double *restrict src_lons, double plat, double plon, const int *restrict src_grid_dims,
double *restrict src_lons, double plat, double plon, const size_t *restrict src_grid_dims,
const double *restrict src_center_lat, const double *restrict src_center_lon);
int grid_search(remapgrid_t *src_grid, size_t *restrict src_add, double *restrict src_lats,
double *restrict src_lons, double plat, double plon, const int *restrict src_grid_dims,
double *restrict src_lons, double plat, double plon, const size_t *restrict src_grid_dims,
const double *restrict src_center_lat, const double *restrict src_center_lon,
const restr_t *restrict src_grid_bound_box, const size_t *restrict src_bin_add);
......
......@@ -108,7 +108,7 @@ void search_free(search_t *search)
int rect_grid_search2(long *imin, long *imax, double xmin, double xmax, long nxm, const double *restrict xm);
static
size_t get_srch_cells_reg2d(const int *restrict src_grid_dims,
size_t get_srch_cells_reg2d(const size_t *restrict src_grid_dims,
const double *restrict src_corner_lat, const double *restrict src_corner_lon,
const double *restrict tgt_cell_bound_box, size_t *srch_add)
{
......@@ -219,7 +219,7 @@ void restrict_boundbox(const double *restrict grid_bound_box, double *restrict b
}
static
void boundbox_from_corners_reg2d(size_t grid_add, const int *restrict grid_dims, const double *restrict corner_lon,
void boundbox_from_corners_reg2d(size_t grid_add, const size_t *restrict grid_dims, const double *restrict corner_lon,
const double *restrict corner_lat, double *restrict bound_box)
{
size_t nx = grid_dims[0];
......
......@@ -113,8 +113,8 @@ size_t nbr_normalize_weights(size_t num_neighbors, double dist_tot, const bool *
#define MAX_SEARCH_CELLS 25
static
void grid_search_nbr_reg2d(struct gridsearch *gs, size_t num_neighbors, remapgrid_t *src_grid, size_t *restrict nbr_add, double *restrict nbr_dist,
double plon, double plat, const int *restrict src_grid_dims)
void grid_search_nbr_reg2d(struct gridsearch *gs, size_t num_neighbors, size_t *restrict nbr_add, double *restrict nbr_dist,
double plon, double plat)
{
/*
Output variables:
......@@ -146,11 +146,11 @@ void grid_search_nbr_reg2d(struct gridsearch *gs, size_t num_neighbors, remapgri
double *restrict src_center_lon = gs->reg2d_center_lon;
double *restrict src_center_lat = gs->reg2d_center_lat;
long nx = src_grid_dims[0];
long ny = src_grid_dims[1];
long nx = gs->dims[0];
long ny = gs->dims[1];
size_t nxm = nx;
if ( src_grid->is_cyclic ) nxm++;
if ( gs->is_cyclic ) nxm++;
if ( plon < src_center_lon[0] ) plon += PI2;
if ( plon > src_center_lon[nxm-1] ) plon -= PI2;
......@@ -159,7 +159,7 @@ void grid_search_nbr_reg2d(struct gridsearch *gs, size_t num_neighbors, remapgri
if ( lfound )
{
if ( src_grid->is_cyclic && ii == (nxm-1) ) ii = 0;
if ( gs->is_cyclic && ii == (nxm-1) ) ii = 0;
long k;
for ( k = 3; k < 10000; k+=2 )
......@@ -182,7 +182,7 @@ void grid_search_nbr_reg2d(struct gridsearch *gs, size_t num_neighbors, remapgri
{
ix = i;
if ( src_grid->is_cyclic )
if ( gs->is_cyclic )
{
if ( ix < 0 ) ix += nx;
if ( ix >= nx ) ix -= nx;
......@@ -371,9 +371,6 @@ void remap_distwgt_weights(size_t num_neighbors, remapgrid_t *src_grid, remapgri
size_t src_grid_size = src_grid->size;
size_t tgt_grid_size = tgt_grid->size;
size_t nx = src_grid->dims[0];
size_t ny = src_grid->dims[1];
bool lcyclic = src_grid->is_cyclic;
weightlinks_t *weightlinks = (weightlinks_t *) Malloc(tgt_grid_size*sizeof(weightlinks_t));
weightlinks[0].addweights = (addweight_t *) Malloc(num_neighbors*tgt_grid_size*sizeof(addweight_t));
......@@ -391,7 +388,7 @@ void remap_distwgt_weights(size_t num_neighbors, remapgrid_t *src_grid, remapgri
struct gridsearch *gs = NULL;
if ( remap_grid_type == REMAP_GRID_TYPE_REG2D )
gs = gridsearch_create_reg2d(lcyclic, nx, ny, src_grid->reg2d_center_lon, src_grid->reg2d_center_lat);
gs = gridsearch_create_reg2d(src_grid->is_cyclic, src_grid->dims, src_grid->reg2d_center_lon, src_grid->reg2d_center_lat);
else if ( num_neighbors == 1 )
gs = gridsearch_create_nn(src_grid_size, src_grid->cell_center_lon, src_grid->cell_center_lat);
else
......@@ -432,8 +429,7 @@ void remap_distwgt_weights(size_t num_neighbors, remapgrid_t *src_grid, remapgri
// Find nearest grid points on source grid and distances to each point
if ( remap_grid_type == REMAP_GRID_TYPE_REG2D )
grid_search_nbr_reg2d(gs, num_neighbors, src_grid, nbr_add[ompthID], nbr_dist[ompthID],
plon, plat, src_grid->dims);
grid_search_nbr_reg2d(gs, num_neighbors, nbr_add[ompthID], nbr_dist[ompthID], plon, plat);
else
grid_search_nbr(gs, num_neighbors, nbr_add[ompthID], nbr_dist[ompthID], plon, plat);
......@@ -487,9 +483,6 @@ void remap_distwgt(size_t num_neighbors, remapgrid_t *src_grid, remapgrid_t *tgt
size_t src_grid_size = src_grid->size;
size_t tgt_grid_size = tgt_grid->size;
size_t nx = src_grid->dims[0];
size_t ny = src_grid->dims[1];
bool lcyclic = src_grid->is_cyclic;
NEW_2D(bool, nbr_mask, ompNumThreads, num_neighbors); // mask at nearest neighbors
NEW_2D(size_t, nbr_add, ompNumThreads, num_neighbors); // source address at nearest neighbors
......@@ -502,7 +495,7 @@ void remap_distwgt(size_t num_neighbors, remapgrid_t *src_grid, remapgrid_t *tgt
struct gridsearch *gs = NULL;
if ( src_remap_grid_type == REMAP_GRID_TYPE_REG2D )
gs = gridsearch_create_reg2d(lcyclic, nx, ny, src_grid->reg2d_center_lon, src_grid->reg2d_center_lat);
gs = gridsearch_create_reg2d(src_grid->is_cyclic, src_grid->dims, src_grid->reg2d_center_lon, src_grid->reg2d_center_lat);
else if ( num_neighbors == 1 )
gs = gridsearch_create_nn(src_grid_size, src_grid->cell_center_lon, src_grid->cell_center_lat);
else
......@@ -543,8 +536,7 @@ void remap_distwgt(size_t num_neighbors, remapgrid_t *src_grid, remapgrid_t *tgt
// Find nearest grid points on source grid and distances to each point
if ( src_remap_grid_type == REMAP_GRID_TYPE_REG2D )
grid_search_nbr_reg2d(gs, num_neighbors, src_grid, nbr_add[ompthID], nbr_dist[ompthID],
plon, plat, src_grid->dims);
grid_search_nbr_reg2d(gs, num_neighbors, nbr_add[ompthID], nbr_dist[ompthID], plon, plat);
else
grid_search_nbr(gs, num_neighbors, nbr_add[ompthID], nbr_dist[ompthID], plon, plat);
......
......@@ -384,8 +384,11 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
// Write mapping data
nce(nc_put_var_int(nc_file_id, nc_srcgrddims_id, src_grid.dims));
nce(nc_put_var_int(nc_file_id, nc_dstgrddims_id, tgt_grid.dims));
int dims[2];
dims[0] = (int)src_grid.dims[0]; dims[1] = (int)src_grid.dims[1];
nce(nc_put_var_int(nc_file_id, nc_srcgrddims_id, dims));
dims[0] = (int)tgt_grid.dims[0]; dims[1] = (int)tgt_grid.dims[1];
nce(nc_put_var_int(nc_file_id, nc_dstgrddims_id, dims));
nce(nc_put_var_int(nc_file_id, nc_srcgrdimask_id, src_grid.mask));
nce(nc_put_var_int(nc_file_id, nc_dstgrdimask_id, tgt_grid.mask));
......@@ -747,7 +750,9 @@ void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *ma
// Read all variables
nce(nc_get_var_int(nc_file_id, nc_srcgrddims_id, src_grid->dims));
int dims[2];
nce(nc_get_var_int(nc_file_id, nc_srcgrddims_id, dims));
src_grid->dims[0] = dims[0]; src_grid->dims[1] = dims[1];
nce(nc_get_var_int(nc_file_id, nc_srcgrdimask_id, src_grid->mask));
......@@ -779,7 +784,8 @@ void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *ma
nce(nc_get_var_double(nc_file_id, nc_srcgrdfrac_id, src_grid->cell_frac));
nce(nc_get_var_int(nc_file_id, nc_dstgrddims_id, tgt_grid->dims));
nce(nc_get_var_int(nc_file_id, nc_dstgrddims_id, dims));
tgt_grid->dims[0] = dims[0]; tgt_grid->dims[1] = dims[1];
nce(nc_get_var_int(nc_file_id, nc_dstgrdimask_id, tgt_grid->mask));
......
......@@ -223,7 +223,7 @@ int grid_search_nn(size_t min_add, size_t max_add, size_t *restrict nbr_add, dou
int grid_search(remapgrid_t *src_grid, size_t *restrict src_add, double *restrict src_lats,
double *restrict src_lons, double plat, double plon, const int *restrict src_grid_dims,
double *restrict src_lons, double plat, double plon, const size_t *restrict src_grid_dims,
const double *restrict src_center_lat, const double *restrict src_center_lon,
const restr_t *restrict src_grid_bound_box, const size_t *restrict src_bin_add)
{
......
......@@ -85,7 +85,7 @@ int grid_search_reg2d_nn(size_t nx, size_t ny, size_t *restrict nbr_add, double
int grid_search_reg2d(remapgrid_t *src_grid, size_t *restrict src_add, double *restrict src_lats,
double *restrict src_lons, double plat, double plon, const int *restrict src_grid_dims,
double *restrict src_lons, double plat, double plon, const size_t *restrict src_grid_dims,
const double *restrict src_center_lat, const double *restrict src_center_lon)
{
/*
......
......@@ -413,6 +413,7 @@ void check_lat_boundbox_range(size_t nlats, restr_t *restrict bound_box, double
static
int expand_lonlat_grid(int gridID)
{
if ( cdoVerbose ) cdoPrint("expand_lonlat_grid");
size_t nx = gridInqXsize(gridID);
size_t ny = gridInqYsize(gridID);
size_t nxp4 = nx+4;
......@@ -459,6 +460,7 @@ int expand_lonlat_grid(int gridID)
static
int expand_curvilinear_grid(int gridID)
{
if ( cdoVerbose ) cdoPrint("expand_curvilinear_grid");
size_t gridsize = gridInqSize(gridID);
long nx = (long) gridInqXsize(gridID);
long ny = (long) gridInqYsize(gridID);
......
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