Commit f218ca25 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Changed remap links to size_t.

parent f5d437c9
......@@ -277,9 +277,9 @@ void fillmiss_one_step(field_type *field1, field_type *field2, int maxfill)
}
int grid_search_nbr(struct gridsearch *gs, int num_neighbors, int *restrict nbr_add, double *restrict nbr_dist, double plon, double plat);
double nbr_compute_weights(unsigned num_neighbors, const int *restrict src_grid_mask, bool *restrict nbr_mask, const int *restrict nbr_add, double *restrict nbr_dist);
unsigned nbr_normalize_weights(unsigned num_neighbors, double dist_tot, const bool *restrict nbr_mask, int *restrict nbr_add, double *restrict nbr_dist);
int grid_search_nbr(struct gridsearch *gs, size_t num_neighbors, size_t *restrict nbr_add, double *restrict nbr_dist, double plon, double plat);
double nbr_compute_weights(size_t num_neighbors, const int *restrict src_grid_mask, bool *restrict nbr_mask, const size_t *restrict nbr_add, double *restrict nbr_dist);
size_t nbr_normalize_weights(size_t num_neighbors, double dist_tot, const bool *restrict nbr_mask, size_t *restrict nbr_add, double *restrict nbr_dist);
static
void setmisstodis(field_type *field1, field_type *field2, int num_neighbors)
......@@ -313,8 +313,8 @@ void setmisstodis(field_type *field1, field_type *field2, int num_neighbors)
gridInqYunits(gridID, units);
grid_to_radian(units, gridsize, yvals, "grid center lat");
unsigned *mindex = nmiss ? (unsigned *) Calloc(1, nmiss*sizeof(unsigned)) : NULL;
unsigned *vindex = nvals ? (unsigned *) Calloc(1, nvals*sizeof(unsigned)) : NULL;
size_t *mindex = nmiss ? (size_t *) Calloc(1, nmiss*sizeof(size_t)) : NULL;
size_t *vindex = nvals ? (size_t *) Calloc(1, nvals*sizeof(size_t)) : NULL;
double *lons = nvals ? (double *) Malloc(nvals*sizeof(double)) : NULL;
double *lats = nvals ? (double *) Malloc(nvals*sizeof(double)) : NULL;
......@@ -339,7 +339,7 @@ void setmisstodis(field_type *field1, field_type *field2, int num_neighbors)
if ( nv != nvals ) cdoAbort("Internal problem, number of valid values differ!");
bool nbr_mask[num_neighbors]; /* mask at nearest neighbors */
int nbr_add[num_neighbors]; /* source address at nearest neighbors */
size_t nbr_add[num_neighbors]; /* source address at nearest neighbors */
double nbr_dist[num_neighbors]; /* angular distance four nearest neighbors */
clock_t start, finish;
......@@ -381,11 +381,11 @@ void setmisstodis(field_type *field1, field_type *field2, int num_neighbors)
double dist_tot = nbr_compute_weights(num_neighbors, NULL, nbr_mask, nbr_add, nbr_dist);
/* Normalize weights and store the link */
unsigned nadds = nbr_normalize_weights(num_neighbors, dist_tot, nbr_mask, nbr_add, nbr_dist);
size_t nadds = nbr_normalize_weights(num_neighbors, dist_tot, nbr_mask, nbr_add, nbr_dist);
if ( nadds )
{
double result = 0;
for ( unsigned n = 0; n < nadds; ++n ) result += array1[vindex[nbr_add[n]]]*nbr_dist[n];
for ( size_t n = 0; n < nadds; ++n ) result += array1[vindex[nbr_add[n]]]*nbr_dist[n];
array2[mindex[i]] = result;
}
}
......
......@@ -439,16 +439,16 @@ void get_remap_env(void)
}
static
void set_halo_to_missval(int nx, int ny, double *array, double missval)
void set_halo_to_missval(size_t nx, size_t ny, double *array, double missval)
{
for ( int j = 0; j < ny+4; j++ ) array[j*(nx+4)+0] = missval;
for ( int j = 0; j < ny+4; j++ ) array[j*(nx+4)+1] = missval;
for ( int j = 0; j < ny+4; j++ ) array[j*(nx+4)+nx+2] = missval;
for ( int j = 0; j < ny+4; j++ ) array[j*(nx+4)+nx+3] = missval;
for ( int i = 0; i < nx+4; i++ ) array[ 0*(nx+4)+i] = missval;
for ( int i = 0; i < nx+4; i++ ) array[ 1*(nx+4)+i] = missval;
for ( int i = 0; i < nx+4; i++ ) array[(ny+2)*(nx+4)+i] = missval;
for ( int i = 0; i < nx+4; i++ ) array[(ny+3)*(nx+4)+i] = missval;
for ( size_t j = 0; j < ny+4; j++ ) array[j*(nx+4)+0] = missval;
for ( size_t j = 0; j < ny+4; j++ ) array[j*(nx+4)+1] = missval;
for ( size_t j = 0; j < ny+4; j++ ) array[j*(nx+4)+nx+2] = missval;
for ( size_t j = 0; j < ny+4; j++ ) array[j*(nx+4)+nx+3] = missval;
for ( size_t i = 0; i < nx+4; i++ ) array[ 0*(nx+4)+i] = missval;
for ( size_t i = 0; i < nx+4; i++ ) array[ 1*(nx+4)+i] = missval;
for ( size_t i = 0; i < nx+4; i++ ) array[(ny+2)*(nx+4)+i] = missval;
for ( size_t i = 0; i < nx+4; i++ ) array[(ny+3)*(nx+4)+i] = missval;
}
static
......@@ -470,15 +470,15 @@ bool is_global_grid(int gridID)
}
static
void scale_gridbox_area(long gridsize, const double *restrict array1, long gridsize2, double *restrict array2, const double *restrict grid2_area)
void scale_gridbox_area(size_t gridsize, const double *restrict array1, size_t gridsize2, double *restrict array2, const double *restrict grid2_area)
{
double array1sum = 0;
for ( long i = 0; i < gridsize; i++ ) array1sum += array1[i];
for ( size_t i = 0; i < gridsize; i++ ) array1sum += array1[i];
double array2sum = 0;
for ( long i = 0; i < gridsize2; i++ ) array2sum += grid2_area[i];
for ( size_t i = 0; i < gridsize2; i++ ) array2sum += grid2_area[i];
for ( long i = 0; i < gridsize2; i++ ) array2[i] = grid2_area[i]/array2sum*array1sum;
for ( size_t i = 0; i < gridsize2; i++ ) array2[i] = grid2_area[i]/array2sum*array1sum;
static bool lgridboxinfo = true;
if ( lgridboxinfo )
......@@ -599,14 +599,14 @@ int get_norm_opt(void)
}
static
void remap_normalize(int norm_opt, int gridsize, double *array, double missval, remapgrid_t *tgt_grid)
void remap_normalize(int norm_opt, size_t gridsize, double *array, double missval, remapgrid_t *tgt_grid)
{
/* used only to check the result of remapcon */
double grid_err;
if ( norm_opt == NORM_OPT_NONE )
{
for ( int i = 0; i < gridsize; i++ )
for ( size_t i = 0; i < gridsize; i++ )
{
if ( !DBL_IS_EQUAL(array[i], missval) )
{
......@@ -621,7 +621,7 @@ void remap_normalize(int norm_opt, int gridsize, double *array, double missval,
}
else if ( norm_opt == NORM_OPT_DESTAREA )
{
for ( int i = 0; i < gridsize; i++ )
for ( size_t i = 0; i < gridsize; i++ )
{
if ( !DBL_IS_EQUAL(array[i], missval) )
{
......@@ -635,13 +635,13 @@ void remap_normalize(int norm_opt, int gridsize, double *array, double missval,
}
static
void remap_set_frac_min(int gridsize, double *array, double missval, remapgrid_t *tgt_grid)
void remap_set_frac_min(size_t gridsize, double *array, double missval, remapgrid_t *tgt_grid)
{
if ( remap_frac_min > 0 )
{
for ( int i = 0; i < gridsize; i++ )
for ( size_t i = 0; i < gridsize; i++ )
{
//printf("%d %g %g\n", i, remaps[r].tgt_grid.cell_frac[i], remaps[r].tgt_grid.cell_area[i]);
//printf("%zu %g %g\n", i, remaps[r].tgt_grid.cell_frac[i], remaps[r].tgt_grid.cell_area[i]);
if ( tgt_grid->cell_frac[i] < remap_frac_min ) array[i] = missval;
}
}
......@@ -668,79 +668,81 @@ void init_remap_timer(void)
static
void links_per_value(remapvars_t *remapvars)
{
long num_links = remapvars->num_links;
int lpv = -1;
long lpv = -1;
remapvars->links_per_value = lpv;
return;
/*
size_t num_links = remapvars->num_links;
if ( num_links > 0 )
{
lpv = 1;
const int *restrict dst_add = remapvars->tgt_cell_add;
long n = 0;
int ival = dst_add[n];
const size_t *restrict dst_add = remapvars->tgt_cell_add;
size_t n = 0;
size_t ival = dst_add[n];
for ( n = 1; n < num_links; ++n )
if ( dst_add[n] == ival ) lpv++;
else break;
printf("lpv %d\n", lpv);
printf("lpv %zu\n", lpv);
if ( num_links%lpv != 0 ) lpv = -1;
if ( num_links%lpv != 0 ) lpv = 0;
n++;
if ( n < num_links )
{
int lpv2 = -1;
int ival2 = dst_add[n];
size_t lpv2 = 0;
size_t ival2 = dst_add[n];
for ( ; n < num_links; ++n )
if ( dst_add[n] == ival2 ) lpv2++;
else if ( lpv == lpv2 )
{
lpv2 = -1;
lpv2 = 0;
ival2 = dst_add[n];
}
else
{
lpv = -1;
lpv = 0;
break;
}
}
printf("lpv %d\n", lpv);
printf("lpv %zu\n", lpv);
if ( lpv == 1 )
{
for ( long n = 1; n < num_links; ++n )
for ( size_t n = 1; n < num_links; ++n )
{
if ( dst_add[n] == dst_add[n-1] )
{
lpv = -1;
lpv = 0;
break;
}
}
}
else if ( lpv > 1 )
{
for ( long n = 1; n < num_links/lpv; ++n )
for ( size_t n = 1; n < num_links/lpv; ++n )
{
ival = dst_add[n*lpv];
for ( int k = 1; k < lpv; ++k )
for ( size_t k = 1; k < lpv; ++k )
{
if ( dst_add[n*lpv+k] != ival )
{
lpv = -1;
lpv = 0;
break;
}
}
if ( lpv == -1 ) break;
if ( lpv == 0 ) break;
}
}
}
printf("lpv %d\n", lpv);
printf("lpv %zu\n", lpv);
remapvars->links_per_value = lpv;
*/
}
static
......@@ -772,9 +774,11 @@ void *Remap(void *argument)
int streamID2 = -1;
int nrecs;
int varID, levelID;
int gridsize, gridsize2;
size_t gridsize, gridsize2;
int gridID1 = -1, gridID2;
int nmiss1, nmiss2, i, j, r = -1;
int nmiss1, nmiss2;
size_t i, j;
int r = -1;
int nremaps = 0;
int norm_opt = NORM_OPT_NONE;
int map_type = -1;
......@@ -897,12 +901,12 @@ void *Remap(void *argument)
if ( lremapxxx )
{
int gridsize2;
size_t gridsize2;
read_remap_scrip(remap_file, gridID1, gridID2, &map_type, &submap_type, &num_neighbors,
&remap_order, &remaps[0].src_grid, &remaps[0].tgt_grid, &remaps[0].vars);
if ( remaps[0].vars.links_per_value == -1 ) links_per_value(&remaps[0].vars);
if ( remaps[0].vars.links_per_value == 0 ) links_per_value(&remaps[0].vars);
nremaps = 1;
gridsize = remaps[0].src_grid.size;
......@@ -936,13 +940,13 @@ void *Remap(void *argument)
remaps[0].tgt_grid.vgpm = (int*) Realloc(remaps[0].tgt_grid.vgpm, gridInqSize(gridID2)*sizeof(int));
int gridID2_gme = gridToUnstructured(gridID2, 1);
gridInqMaskGME(gridID2_gme, remaps[0].tgt_grid.vgpm);
int isize = 0;
for ( int i = 0; i < gridsize2; ++i )
size_t isize = 0;
for ( size_t i = 0; i < gridsize2; ++i )
if ( remaps[0].tgt_grid.vgpm[i] ) isize++;
gridsize2 = isize;
}
/*
printf("grid2 %d %d %d\n", gridsize2, remaps[0].tgt_grid.nvgp, remaps[0].tgt_grid.size);
printf("grid2 %zu %d %zu\n", gridsize2, remaps[0].tgt_grid.nvgp, remaps[0].tgt_grid.size);
*/
if ( remaps[0].tgt_grid.size != gridsize2 )
cdoAbort("Size of target grid and weights from %s differ!", remap_file);
......@@ -965,7 +969,7 @@ void *Remap(void *argument)
if ( map_type == MAP_TYPE_CONSERV || map_type == MAP_TYPE_CONSERV_YAC ) norm_opt = get_norm_opt();
int grid1sizemax = vlistGridsizeMax(vlistID1);
size_t grid1sizemax = vlistGridsizeMax(vlistID1);
if ( map_type == MAP_TYPE_BICUBIC ) need_gradiants = TRUE;
if ( map_type == MAP_TYPE_CONSERV && remap_order == 2 )
......@@ -1028,9 +1032,9 @@ 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) )
{
int nx = gridInqXsize(gridID1);
int ny = gridInqYsize(gridID1);
int gridsize_new = gridsize + 4*(nx+2) + 4*(ny+2);
long nx = gridInqXsize(gridID1);
long ny = gridInqYsize(gridID1);
size_t gridsize_new = gridsize + 4*(nx+2) + 4*(ny+2);
if ( gridsize_new > grid1sizemax )
{
grid1sizemax = gridsize_new;
......@@ -1045,8 +1049,8 @@ void *Remap(void *argument)
}
}
for ( j = ny-1; j >= 0; j-- )
for ( i = nx-1; i >= 0; i-- )
for ( long j = ny-1; j >= 0; j-- )
for ( long i = nx-1; i >= 0; i-- )
array1[(j+2)*(nx+4)+i+2] = array1[j*nx+i];
set_halo_to_missval(nx, ny, array1, missval);
......@@ -1235,13 +1239,13 @@ void *Remap(void *argument)
if ( operfunc == REMAPSUM )
{
for ( i = 0; i < gridsize; i++ )
printf("1 %d %g %g %g %g\n", i, array1[i], remaps[r].src_grid.cell_frac[i], remaps[r].src_grid.cell_area[i],remaps[r].src_grid.cell_frac[i]);
printf("1 %zd %g %g %g %g\n", i, array1[i], remaps[r].src_grid.cell_frac[i], remaps[r].src_grid.cell_area[i],remaps[r].src_grid.cell_frac[i]);
double array1sum = 0;
for ( i = 0; i < gridsize; i++ )
array1sum += remaps[r].src_grid.cell_area[i];
for ( i = 0; i < gridsize2; i++ )
printf("2 %d %g %g %g %g\n", i, array2[i], remaps[r].tgt_grid.cell_frac[i],remaps[r].tgt_grid.cell_area[i],remaps[r].tgt_grid.cell_frac[i]);
printf("2 %zd %g %g %g %g\n", i, array2[i], remaps[r].tgt_grid.cell_frac[i],remaps[r].tgt_grid.cell_area[i],remaps[r].tgt_grid.cell_frac[i]);
double array2sum = 0;
for ( i = 0; i < gridsize2; i++ )
array2sum += remaps[r].tgt_grid.cell_area[i];
......@@ -1266,8 +1270,8 @@ void *Remap(void *argument)
gridInqParamGME(gridID2, &nd, &ni, &ni2, &ni3);
j = remaps[r].tgt_grid.size;
for ( i = gridsize2-1; i >=0 ; i-- )
if ( remaps[r].tgt_grid.vgpm[i] ) array2[i] = array2[--j];
for ( i = gridsize2; i > 0 ; i-- )
if ( remaps[r].tgt_grid.vgpm[i-1] ) array2[i-1] = array2[--j];
gme_grid_restore(array2, ni, nd);
}
......
......@@ -46,16 +46,16 @@ typedef struct {
double intlin(double x, double y1, double x1, double y2, double x2);
double smooth_knn_compute_weights(unsigned num_neighbors, const bool *restrict src_grid_mask, struct gsknn *knn, double search_radius, double weight0, double weightR)
double smooth_knn_compute_weights(size_t num_neighbors, const bool *restrict src_grid_mask, struct gsknn *knn, double search_radius, double weight0, double weightR)
{
bool *restrict nbr_mask = knn->mask;
const int *restrict nbr_add = knn->add;
const size_t *restrict nbr_add = knn->add;
double *restrict nbr_dist = knn->dist;
// Compute weights based on inverse distance if mask is false, eliminate those points
double dist_tot = 0.; // sum of neighbor distances (for normalizing)
for ( unsigned n = 0; n < num_neighbors; ++n )
for ( size_t n = 0; n < num_neighbors; ++n )
{
nbr_mask[n] = false;
if ( nbr_add[n] >= 0 && src_grid_mask[nbr_add[n]] )
......@@ -70,16 +70,16 @@ double smooth_knn_compute_weights(unsigned num_neighbors, const bool *restrict s
}
unsigned smooth_knn_normalize_weights(unsigned num_neighbors, double dist_tot, struct gsknn *knn)
size_t smooth_knn_normalize_weights(unsigned num_neighbors, double dist_tot, struct gsknn *knn)
{
const bool *restrict nbr_mask = knn->mask;
int *restrict nbr_add = knn->add;
size_t *restrict nbr_add = knn->add;
double *restrict nbr_dist = knn->dist;
// Normalize weights and store the link
unsigned nadds = 0;
for ( unsigned n = 0; n < num_neighbors; ++n )
for ( size_t n = 0; n < num_neighbors; ++n )
{
if ( nbr_mask[n] )
{
......@@ -97,12 +97,12 @@ void smooth(int gridID, double missval, const double *restrict array1, double *r
{
*nmiss = 0;
int gridID0 = gridID;
unsigned gridsize = gridInqSize(gridID);
unsigned num_neighbors = spoint.maxpoints;
size_t gridsize = gridInqSize(gridID);
size_t num_neighbors = spoint.maxpoints;
if ( num_neighbors > gridsize ) num_neighbors = gridsize;
bool *mask = (bool*) Malloc(gridsize*sizeof(bool));
for ( unsigned i = 0; i < gridsize; ++i )
for ( size_t i = 0; i < gridsize; ++i )
mask[i] = !DBL_IS_EQUAL(array1[i], missval);
double *xvals = (double*) Malloc(gridsize*sizeof(double));
......@@ -153,7 +153,7 @@ void smooth(int gridID, double missval, const double *restrict array1, double *r
#if defined(_OPENMP)
#pragma omp parallel for schedule(dynamic) default(none) shared(cdoVerbose, knn, spoint, findex, mask, array1, array2, xvals, yvals, gs, gridsize, nmiss, missval)
#endif
for ( unsigned i = 0; i < gridsize; ++i )
for ( size_t i = 0; i < gridsize; ++i )
{
int ompthID = cdo_omp_get_thread_num();
......@@ -163,7 +163,7 @@ void smooth(int gridID, double missval, const double *restrict array1, double *r
findex++;
if ( cdoVerbose && cdo_omp_get_thread_num() == 0 ) progressStatus(0, 1, findex/gridsize);
unsigned nadds = gridsearch_knn(gs, knn[ompthID], xvals[i], yvals[i]);
size_t nadds = gridsearch_knn(gs, knn[ompthID], xvals[i], yvals[i]);
// Compute weights based on inverse distance if mask is false, eliminate those points
double dist_tot = smooth_knn_compute_weights(nadds, mask, knn[ompthID], spoint.radius, spoint.weight0, spoint.weightR);
......@@ -172,7 +172,7 @@ void smooth(int gridID, double missval, const double *restrict array1, double *r
nadds = smooth_knn_normalize_weights(nadds, dist_tot, knn[ompthID]);
if ( nadds )
{
const int *restrict nbr_add = knn[ompthID]->add;
const size_t *restrict nbr_add = knn[ompthID]->add;
const double *restrict nbr_dist = knn[ompthID]->dist;
/*
printf("n %u %d nadds %u dis %g\n", i, nbr_add[0], nadds, nbr_dist[0]);
......@@ -180,7 +180,7 @@ void smooth(int gridID, double missval, const double *restrict array1, double *r
printf(" n %u add %d dis %g\n", n, nbr_add[n], nbr_dist[n]);
*/
double result = 0;
for ( unsigned n = 0; n < nadds; ++n ) result += array1[nbr_add[n]]*nbr_dist[n];
for ( size_t n = 0; n < nadds; ++n ) result += array1[nbr_add[n]]*nbr_dist[n];
array2[i] = result;
}
else
......
......@@ -74,7 +74,7 @@ void gridsearch_set_method(const char *methodstr)
}
struct gridsearch *gridsearch_create_reg2d(bool lcyclic, unsigned nx, unsigned ny, const double *restrict lons, const double *restrict lats)
struct gridsearch *gridsearch_create_reg2d(bool lcyclic, size_t nx, size_t ny, const double *restrict lons, const double *restrict lats)
{
struct gridsearch *gs = (struct gridsearch *) Calloc(1, sizeof(struct gridsearch));
......@@ -95,7 +95,7 @@ struct gridsearch *gridsearch_create_reg2d(bool lcyclic, unsigned nx, unsigned n
double *coslat = (double *) Malloc(ny*sizeof(double));
double *sinlat = (double *) Malloc(ny*sizeof(double));
for ( unsigned n = 0; n < nx; ++n )
for ( size_t n = 0; n < nx; ++n )
{
double rlon = lons[n];
if ( rlon > PI2 ) rlon -= PI2;
......@@ -103,7 +103,7 @@ struct gridsearch *gridsearch_create_reg2d(bool lcyclic, unsigned nx, unsigned n
coslon[n] = cos(rlon);
sinlon[n] = sin(rlon);
}
for ( unsigned n = 0; n < ny; ++n )
for ( size_t n = 0; n < ny; ++n )
{
coslat[n] = cos(lats[n]);
sinlat[n] = sin(lats[n]);
......@@ -123,11 +123,11 @@ struct gridsearch *gridsearch_create_reg2d(bool lcyclic, unsigned nx, unsigned n
}
struct kdNode *gs_create_kdtree(unsigned n, const double *restrict lons, const double *restrict lats)
struct kdNode *gs_create_kdtree(size_t n, const double *restrict lons, const double *restrict lats)
{
struct kd_point *pointlist = (struct kd_point *) Malloc(n * sizeof(struct kd_point));
// see example_cartesian.c
if ( cdoVerbose ) printf("kdtree lib init 3D: n=%d nthreads=%d\n", n, ompNumThreads);
if ( cdoVerbose ) printf("kdtree lib init 3D: n=%zu nthreads=%d\n", n, ompNumThreads);
kdata_t min[3], max[3];
min[0] = min[1] = min[2] = 1e9;
max[0] = max[1] = max[2] = -1e9;
......@@ -135,11 +135,11 @@ struct kdNode *gs_create_kdtree(unsigned n, const double *restrict lons, const d
#if defined(HAVE_OPENMP4)
#pragma omp simd
#endif
for ( unsigned i = 0; i < n; i++ )
for ( size_t i = 0; i < n; i++ )
{
point = pointlist[i].point;
LLtoXYZ_kd(lons[i], lats[i], point);
for ( unsigned j = 0; j < 3; ++j )
for ( size_t j = 0; j < 3; ++j )
{
min[j] = point[j] < min[j] ? point[j] : min[j];
max[j] = point[j] > max[j] ? point[j] : max[j];
......@@ -172,20 +172,20 @@ void gs_destroy_nearpt3(struct gsNear *near)
}
struct gsNear *gs_create_nearpt3(unsigned n, const double *restrict lons, const double *restrict lats)
struct gsNear *gs_create_nearpt3(size_t n, const double *restrict lons, const double *restrict lats)
{
struct gsNear *near = (struct gsNear *) Calloc(1, sizeof(struct gsNear));
Coord_T **p = (Coord_T **) Malloc(n*sizeof(Coord_T *));
p[0] = (Coord_T *) Malloc(3*n*sizeof(Coord_T));
for ( unsigned i = 1; i < n; i++ ) p[i] = p[0] + i*3;
for ( size_t i = 1; i < n; i++ ) p[i] = p[0] + i*3;
float point[3];
#if defined(HAVE_OPENMP4)
#pragma omp simd
#endif
for ( unsigned i = 0; i < n; i++ )
for ( size_t i = 0; i < n; i++ )
{
LLtoXYZ_f(lons[i], lats[i], point);
......@@ -223,18 +223,18 @@ void gs_destroy_full(struct gsFull *full)
}
struct gsFull *gs_create_full(unsigned n, const double *restrict lons, const double *restrict lats)
struct gsFull *gs_create_full(size_t n, const double *restrict lons, const double *restrict lats)
{
struct gsFull *full = (struct gsFull *) Calloc(1, sizeof(struct gsFull));
float **p = (float **) Malloc(n*sizeof(float *));
p[0] = (float *) Malloc(3*n*sizeof(float));
for ( unsigned i = 1; i < n; i++ ) p[i] = p[0] + i*3;
for ( size_t i = 1; i < n; i++ ) p[i] = p[0] + i*3;
#if defined(HAVE_OPENMP4)
#pragma omp simd
#endif
for ( unsigned i = 0; i < n; i++ )
for ( size_t i = 0; i < n; i++ )
{
LLtoXYZ_f(lons[i], lats[i], p[i]);
}
......@@ -248,7 +248,7 @@ struct gsFull *gs_create_full(unsigned n, const double *restrict lons, const dou
}
struct gridsearch *gridsearch_create(unsigned n, 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 *gs = (struct gridsearch *) Calloc(1, sizeof(struct gridsearch));
......@@ -263,7 +263,7 @@ struct gridsearch *gridsearch_create(unsigned n, const double *restrict lons, co
}
struct gridsearch *gridsearch_create_nn(unsigned 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)
{
struct gridsearch *gs = (struct gridsearch *) Calloc(1, sizeof(struct gridsearch));
......@@ -341,7 +341,7 @@ kdNode *gs_nearest_kdtree(kdNode *kdt, double lon, double lat, double *prange)
unsigned gs_nearest_nearpt3(struct gsNear *near, double lon, double lat, double *prange)
{
unsigned index = GS_NOT_FOUND;
size_t index = GS_NOT_FOUND;
if ( near == NULL ) return index;
#if defined(ENABLE_NEARPT3)
......@@ -379,9 +379,9 @@ unsigned gs_nearest_nearpt3(struct gsNear *near, double lon, double lat, double
}
unsigned gs_nearest_full(struct gsFull *full, double lon, double lat, double *prange)
size_t gs_nearest_full(struct gsFull *full, double lon, double lat, double *prange)
{
unsigned index = GS_NOT_FOUND;
size_t index = GS_NOT_FOUND;
if ( full == NULL ) return index;
float range0 = gs_set_range(prange);
......@@ -389,26 +389,26 @@ unsigned gs_nearest_full(struct gsFull *full, double lon, double lat, double *p
float point[3];
LLtoXYZ_f(lon, lat, point);
int n = full->n;
size_t n = full->n;
float **pts = full->pts;
int closestpt = -1;
size_t closestpt = n;
float dist = FLT_MAX;
for ( int i = 0; i < n; i++ )
for ( size_t i = 0; i < n; i++ )
{
float d = distance(point, pts[i]);
if ( closestpt < 0 || d < dist || (d<=dist && i < closestpt) )
if ( closestpt >=n || d < dist || (d<=dist && i < closestpt) )
{
dist = d;
closestpt = i;
}
}
if ( closestpt >= 0 )
if ( closestpt < n )
{
if ( dist < range0 )
{
*prange = dist;
index = (unsigned) closestpt;
index = closestpt;
}
}
......@@ -416,9 +416,9 @@ unsigned gs_nearest_full(struct gsFull *full, double lon, double lat, double *p
}
unsigned gridsearch_nearest(struct gridsearch *gs, double lon