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

Merge declaration and initialization.

parent 84438d97
#ifndef _REMAP_H
#define _REMAP_H
#ifndef REMAP_H
#define REMAP_H
#include <stdint.h>
#include <math.h>
#ifndef M_PI
......@@ -197,7 +198,7 @@ void remap_distwgt(size_t num_neighbors, remapgrid_t *src_grid, remapgrid_t *tgt
void remap_conserv(remapgrid_t *src_grid, remapgrid_t *tgt_grid, const double *restrict src_array, double *restrict tgt_array, double missval);
void resize_remap_vars(remapvars_t *rv, int increment);
void resize_remap_vars(remapvars_t *rv, int64_t increment);
void remap_stat(int remap_order, remapgrid_t src_grid, remapgrid_t tgt_grid, remapvars_t rv, const double *restrict array1,
const double *restrict array2, double missval);
......@@ -238,4 +239,4 @@ void remapgrid_get_lonlat(remapgrid_t *grid, size_t cell_add, double *plon, doub
void remapCheckArea(size_t grid_size, double *restrict cell_area, const char *name);
void remapCheckWeights(size_t num_links, size_t num_wts, int norm_opt, size_t *src_cell_add, size_t *tgt_cell_add, double *wts);
#endif /* _REMAP_H */
#endif /* REMAP_H */
......@@ -694,7 +694,7 @@ void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *ma
rv->max_links = rv->num_links;
rv->resize_increment = (int) (0.1 * MAX(src_grid->size, tgt_grid->size));
rv->resize_increment = (size_t) (0.1 * MAX(src_grid->size, tgt_grid->size));
// Allocate address and weight arrays for mapping 1
......
......@@ -45,22 +45,17 @@ void calc_bin_addr(size_t gridsize, size_t nbins, const restr_t* restrict bin_la
void calc_lat_bins(remapgrid_t* src_grid, remapgrid_t* tgt_grid, int map_type)
{
size_t nbins;
size_t n; /* Loop counter */
size_t n2;
double dlat; /* lat/lon intervals for search bins */
restr_t *bin_lats = NULL;
nbins = src_grid->num_srch_bins;
dlat = PI/nbins;
size_t nbins = src_grid->num_srch_bins;
double dlat = PI/nbins; // lat/lon intervals for search bins
if ( cdoVerbose ) cdoPrint("Using %d latitude bins to restrict search.", nbins);
if ( nbins > 0 )
{
bin_lats = src_grid->bin_lats = (restr_t*) Realloc(src_grid->bin_lats, 2*nbins*sizeof(restr_t));
restr_t *bin_lats = src_grid->bin_lats = (restr_t*) Realloc(src_grid->bin_lats, 2*nbins*sizeof(restr_t));
for ( n = 0; n < nbins; ++n )
for ( size_t n = 0; n < nbins; ++n )
{
n2 = n<<1;
bin_lats[n2 ] = RESTR_SCALE((n )*dlat - PIH);
......@@ -96,20 +91,15 @@ void calc_lat_bins(remapgrid_t* src_grid, remapgrid_t* tgt_grid, int map_type)
size_t get_srch_cells(size_t tgt_cell_add, size_t nbins, size_t *bin_addr1, size_t *bin_addr2,
restr_t *tgt_cell_bound_box, restr_t *src_cell_bound_box, size_t src_grid_size, size_t *srch_add)
{
size_t num_srch_cells; /* num cells in restricted search arrays */
size_t min_add; /* addresses for restricting search of */
size_t max_add; /* destination grid */
size_t n, n2; /* generic counters */
size_t src_cell_add; /* current linear address for src cell */
size_t n2;
size_t src_cell_addm4;
restr_t bound_box_lat1, bound_box_lat2, bound_box_lon1, bound_box_lon2;
/* Restrict searches first using search bins */
min_add = src_grid_size - 1;
max_add = 0;
size_t min_add = src_grid_size - 1;
size_t max_add = 0;
for ( n = 0; n < nbins; ++n )
for ( size_t n = 0; n < nbins; ++n )
{
n2 = n<<1;
if ( tgt_cell_add >= bin_addr1[n2] && tgt_cell_add <= bin_addr1[n2+1] )
......@@ -121,13 +111,13 @@ size_t get_srch_cells(size_t tgt_cell_add, size_t nbins, size_t *bin_addr1, size
/* Further restrict searches using bounding boxes */
bound_box_lat1 = tgt_cell_bound_box[0];
bound_box_lat2 = tgt_cell_bound_box[1];
bound_box_lon1 = tgt_cell_bound_box[2];
bound_box_lon2 = tgt_cell_bound_box[3];
restr_t bound_box_lat1 = tgt_cell_bound_box[0];
restr_t bound_box_lat2 = tgt_cell_bound_box[1];
restr_t bound_box_lon1 = tgt_cell_bound_box[2];
restr_t bound_box_lon2 = tgt_cell_bound_box[3];
num_srch_cells = 0;
for ( src_cell_add = min_add; src_cell_add <= max_add; ++src_cell_add )
size_t num_srch_cells = 0;
for ( size_t src_cell_add = min_add; src_cell_add <= max_add; ++src_cell_add )
{
src_cell_addm4 = src_cell_add<<2;
if ( (src_cell_bound_box[src_cell_addm4+2] <= bound_box_lon2) &&
......@@ -155,7 +145,7 @@ size_t get_srch_cells(size_t tgt_cell_add, size_t nbins, size_t *bin_addr1, size
bound_box_lon2 -= RESTR_SCALE(PI2);
}
for ( src_cell_add = min_add; src_cell_add <= max_add; ++src_cell_add )
for ( size_t src_cell_add = min_add; src_cell_add <= max_add; ++src_cell_add )
{
src_cell_addm4 = src_cell_add<<2;
if ( (src_cell_bound_box[src_cell_addm4+2] <= bound_box_lon2) &&
......@@ -187,17 +177,15 @@ int grid_search_nn(size_t min_add, size_t max_add, size_t *restrict nbr_add, dou
const double *restrict src_center_lat, const double *restrict src_center_lon)
{
int search_result = 0;
size_t n, srch_add;
size_t i;
double dist_min, distance; /* For computing dist-weighted avg */
double distance; /* For computing dist-weighted avg */
double coslat_dst = cos(plat);
double sinlat_dst = sin(plat);
double coslon_dst = cos(plon);
double sinlon_dst = sin(plon);
dist_min = BIGNUM;
for ( n = 0; n < 4; ++n ) nbr_dist[n] = BIGNUM;
for ( srch_add = min_add; srch_add <= max_add; ++srch_add )
double dist_min = BIGNUM;
for ( unsigned n = 0; n < 4; ++n ) nbr_dist[n] = BIGNUM;
for ( size_t srch_add = min_add; srch_add <= max_add; ++srch_add )
{
distance = acos(coslat_dst*cos(src_center_lat[srch_add])*
(coslon_dst*cos(src_center_lon[srch_add]) +
......@@ -206,11 +194,11 @@ int grid_search_nn(size_t min_add, size_t max_add, size_t *restrict nbr_add, dou
if ( distance < dist_min )
{
for ( n = 0; n < 4; ++n )
for ( unsigned n = 0; n < 4; ++n )
{
if ( distance < nbr_dist[n] )
{
for ( i = 3; i > n; --i )
for ( unsigned i = 3; i > n; --i )
{
nbr_add [i] = nbr_add [i-1];
nbr_dist[i] = nbr_dist[i-1];
......@@ -225,10 +213,10 @@ int grid_search_nn(size_t min_add, size_t max_add, size_t *restrict nbr_add, dou
}
}
for ( n = 0; n < 4; ++n ) nbr_dist[n] = ONE/(nbr_dist[n] + TINY);
for ( unsigned n = 0; n < 4; ++n ) nbr_dist[n] = ONE/(nbr_dist[n] + TINY);
distance = 0.0;
for ( n = 0; n < 4; ++n ) distance += nbr_dist[n];
for ( n = 0; n < 4; ++n ) nbr_dist[n] /= distance;
for ( unsigned n = 0; n < 4; ++n ) distance += nbr_dist[n];
for ( unsigned n = 0; n < 4; ++n ) nbr_dist[n] /= distance;
return search_result;
}
......@@ -261,7 +249,7 @@ int grid_search(remapgrid_t *src_grid, size_t *restrict src_add, double *restric
int src_bin_add[][2] ! latitude bins for restricting
*/
/* Local variables */
size_t n, n2, next_n, srch_add, srch_add4; /* dummy indices */
size_t n2, next_n, srch_add, srch_add4; /* dummy indices */
/* Vectors for cross-product check */
double vec1_lat, vec1_lon;
double vec2_lat, vec2_lon;
......@@ -276,7 +264,7 @@ int grid_search(remapgrid_t *src_grid, size_t *restrict src_add, double *restric
// restrict search first using bins
for ( n = 0; n < 4; ++n ) src_add[n] = 0;
for ( unsigned n = 0; n < 4; ++n ) src_add[n] = 0;
// addresses for restricting search
size_t min_add = src_grid->size-1;
......@@ -307,6 +295,8 @@ int grid_search(remapgrid_t *src_grid, size_t *restrict src_add, double *restric
rlat >= src_grid_bound_box[srch_add4 ] &&
rlat <= src_grid_bound_box[srch_add4+1])
{
unsigned n;
/* We are within bounding box so get really serious */
/* Determine neighbor addresses */
......
......@@ -523,7 +523,7 @@ int expand_curvilinear_grid(int gridID)
/*****************************************************************************/
static
void grid_check_lat_borders_rad(int n, double *ybounds)
void grid_check_lat_borders_rad(size_t n, double *ybounds)
{
#define YLIM (88*DEG2RAD)
if ( ybounds[0] > ybounds[n-1] )
......@@ -982,7 +982,7 @@ void remap_vars_init(int map_type, size_t src_grid_size, size_t tgt_grid_size, r
/*
This routine resizes remapping arrays by increasing(decreasing) the max_links by increment
*/
void resize_remap_vars(remapvars_t *rv, int increment)
void resize_remap_vars(remapvars_t *rv, int64_t increment)
{
/*
Input variables:
......@@ -1171,7 +1171,7 @@ size_t get_max_add(size_t num_links, size_t size, const size_t *restrict add)
static
size_t binary_search_int(const size_t *array, size_t len, size_t value)
{
long low = 0, high = len - 1, midpoint = 0;
int64_t low = 0, high = len - 1, midpoint = 0;
while ( low <= high )
{
......
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