Commit 36113f59 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced variable length array by std::vector.

parent 0ce734ef
......@@ -214,7 +214,7 @@ void scrip_remap_bilinear_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid,
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
/* Find nearest square of grid points on source grid */
// Find nearest square of grid points on source grid
if ( remap_grid_type == REMAP_GRID_TYPE_REG2D )
search_result = grid_search_reg2d(src_grid, src_add, src_lats, src_lons,
plat, plon, src_grid->dims,
......@@ -225,23 +225,23 @@ void scrip_remap_bilinear_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid,
src_grid->cell_center_lat, src_grid->cell_center_lon,
src_grid->cell_bound_box, src_grid->bin_addr);
/* Check to see if points are land points */
// Check to see if points are mask points
if ( search_result > 0 )
{
for ( int n = 0; n < 4; ++n )
if ( ! src_grid->mask[src_add[n]] ) search_result = 0;
}
/* If point found, find local iw,jw coordinates for weights */
// If point found, find local iw,jw coordinates for weights
if ( search_result > 0 )
{
double iw, jw; /* current guess for bilinear coordinate */
double iw, jw; // current guess for bilinear coordinate
tgt_grid->cell_frac[tgt_cell_add] = 1.;
if ( find_ij_weights(plon, plat, src_lats, src_lons, &iw, &jw) )
{
/* Successfully found iw,jw - compute weights */
// Successfully found iw,jw - compute weights
set_bilinear_weights(iw, jw, wgts);
store_weightlinks(0, 4, src_add, wgts, tgt_cell_add, weightlinks);
......@@ -276,7 +276,7 @@ void scrip_remap_bilinear_weights(remapgrid_t *src_grid, remapgrid_t *tgt_grid,
if ( weightlinks ) Free(weightlinks);
if ( cdoTimer ) timer_stop(timer_remap_bil);
} /* scrip_remap_weights_bilinear */
} // scrip_remap_weights_bilinear
/*
-----------------------------------------------------------------------
......@@ -334,7 +334,7 @@ void scrip_remap_bilinear(remapgrid_t *src_grid, remapgrid_t *tgt_grid, const do
double plon = 0, plat = 0;
remapgrid_get_lonlat(tgt_grid, tgt_cell_add, &plon, &plat);
/* Find nearest square of grid points on source grid */
// Find nearest square of grid points on source grid
if ( remap_grid_type == REMAP_GRID_TYPE_REG2D )
search_result = grid_search_reg2d(src_grid, src_add, src_lats, src_lons,
plat, plon, src_grid->dims,
......@@ -345,23 +345,23 @@ void scrip_remap_bilinear(remapgrid_t *src_grid, remapgrid_t *tgt_grid, const do
src_grid->cell_center_lat, src_grid->cell_center_lon,
src_grid->cell_bound_box, src_grid->bin_addr);
/* Check to see if points are land points */
// Check to see if points are mask points
if ( search_result > 0 )
{
for ( int n = 0; n < 4; ++n )
if ( ! src_grid->mask[src_add[n]] ) search_result = 0;
}
/* If point found, find local iw,jw coordinates for weights */
// If point found, find local iw,jw coordinates for weights
if ( search_result > 0 )
{
double iw, jw; /* current guess for bilinear coordinate */
double iw, jw; // current guess for bilinear coordinate
tgt_grid->cell_frac[tgt_cell_add] = 1.;
if ( find_ij_weights(plon, plat, src_lats, src_lons, &iw, &jw) )
{
/* Successfully found iw,jw - compute weights */
// Successfully found iw,jw - compute weights
set_bilinear_weights(iw, jw, wgts);
sort_add_and_wgts(4, src_add, wgts);
......@@ -396,4 +396,4 @@ void scrip_remap_bilinear(remapgrid_t *src_grid, remapgrid_t *tgt_grid, const do
}
if ( cdoTimer ) timer_stop(timer_remap_bil);
} /* scrip_remap_bilinear */
} // scrip_remap_bilinear
......@@ -168,7 +168,7 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
writemode |= NC_NETCDF4 | NC_CLASSIC_MODEL;
if ( cdoVerbose ) cdoPrint("Store weights and links to NetCDF4!");
#else
cdoPrint("Number of remap links %lz exceeds maximum of %lz and NetCDF 4 not available!",
cdoPrint("Number of remap links %lz exceeds maximum of %lz and NetCDF 4 is not available!",
nlinks, maxlinks);
#endif
}
......
......@@ -13,7 +13,7 @@ int cmp_adds(const void *s1, const void *s2)
if ( c1->add < c2->add ) cmp = -1;
else if ( c1->add > c2->add ) cmp = 1;
return (cmp);
return cmp;
}
static
......@@ -26,7 +26,7 @@ int cmp_adds4(const void *s1, const void *s2)
if ( c1->add < c2->add ) cmp = -1;
else if ( c1->add > c2->add ) cmp = 1;
return (cmp);
return cmp;
}
static
......@@ -64,7 +64,7 @@ void sort_add_and_wgts(unsigned num_weights, int *src_add, double *wgts)
if ( num_weights )
{
addweight_t addweights[num_weights];
std::vector<addweight_t> addweights(num_weights);
for ( n = 0; n < num_weights; ++n )
{
......@@ -72,7 +72,7 @@ void sort_add_and_wgts(unsigned num_weights, int *src_add, double *wgts)
addweights[n].weight = wgts[n];
}
qsort(addweights, num_weights, sizeof(addweight_t), cmp_adds);
qsort(addweights.data(), num_weights, sizeof(addweight_t), cmp_adds);
for ( n = 0; n < num_weights; ++n )
{
......@@ -93,16 +93,16 @@ void sort_add_and_wgts4(unsigned num_weights, int *src_add, double wgts[4][4])
if ( num_weights )
{
addweight4_t addweights[num_weights];
std::vector<addweight4_t> addweights(num_weights);
for ( n = 0; n < num_weights; ++n )
{
addweights[n].add = src_add[n];
addweights[n].add = src_add[n];
for ( unsigned k = 0; k < 4; ++k )
addweights[n].weight[k] = wgts[n][k];
}
qsort(addweights, num_weights, sizeof(addweight4_t), cmp_adds4);
qsort(addweights.data(), num_weights, sizeof(addweight4_t), cmp_adds4);
for ( n = 0; n < num_weights; ++n )
{
......@@ -114,7 +114,7 @@ void sort_add_and_wgts4(unsigned num_weights, int *src_add, double wgts[4][4])
}
void store_weightlinks(int lalloc, unsigned num_weights, int *srch_add, double *weights, unsigned cell_add, weightlinks_t *weightlinks)
void store_weightlinks(int lalloc, unsigned num_weights, int *srch_add, double *weights, size_t cell_add, weightlinks_t *weightlinks)
{
weightlinks[cell_add].nlinks = 0;
weightlinks[cell_add].offset = 0;
......@@ -142,7 +142,7 @@ void store_weightlinks(int lalloc, unsigned num_weights, int *srch_add, double *
}
void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4], unsigned cell_add, weightlinks4_t *weightlinks)
void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4], size_t cell_add, weightlinks4_t *weightlinks)
{
weightlinks[cell_add].nlinks = 0;
weightlinks[cell_add].offset = 0;
......@@ -153,23 +153,23 @@ void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4
for ( unsigned n = 0; n < num_weights; ++n )
{
addweights[n].add = srch_add[n];
addweights[n].add = srch_add[n];
for ( unsigned k = 0; k < 4; ++k )
addweights[n].weight[k] = weights[n][k];
}
sort_addweights4(num_weights, addweights);
weightlinks[cell_add].nlinks = num_weights;
weightlinks[cell_add].nlinks = num_weights;
}
}
void weightlinks2remaplinks(int lalloc, unsigned tgt_grid_size, weightlinks_t *weightlinks, remapvars_t *rv)
void weightlinks2remaplinks(int lalloc, size_t tgt_grid_size, weightlinks_t *weightlinks, remapvars_t *rv)
{
unsigned nlinks = 0;
size_t nlinks = 0;
for ( unsigned tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
for ( size_t tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
{
if ( weightlinks[tgt_cell_add].nlinks )
{
......@@ -192,14 +192,14 @@ void weightlinks2remaplinks(int lalloc, unsigned tgt_grid_size, weightlinks_t *w
#if defined(_OPENMP)
#pragma omp parallel for schedule(static) default(none) shared(src_cell_adds,tgt_cell_adds,wts,weightlinks,tgt_grid_size)
#endif
for ( unsigned tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
for ( size_t tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
{
unsigned num_links = weightlinks[tgt_cell_add].nlinks;
size_t num_links = weightlinks[tgt_cell_add].nlinks;
if ( num_links )
{
unsigned offset = weightlinks[tgt_cell_add].offset;
size_t offset = weightlinks[tgt_cell_add].offset;
addweight_t *addweights = weightlinks[tgt_cell_add].addweights;
for ( unsigned ilink = 0; ilink < num_links; ++ilink )
for ( size_t ilink = 0; ilink < num_links; ++ilink )
{
src_cell_adds[offset+ilink] = addweights[ilink].add;
tgt_cell_adds[offset+ilink] = tgt_cell_add;
......@@ -210,9 +210,9 @@ void weightlinks2remaplinks(int lalloc, unsigned tgt_grid_size, weightlinks_t *w
if ( lalloc )
{
for ( unsigned tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
for ( size_t tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
{
unsigned num_links = weightlinks[tgt_cell_add].nlinks;
size_t num_links = weightlinks[tgt_cell_add].nlinks;
if ( num_links ) Free(weightlinks[tgt_cell_add].addweights);
}
}
......@@ -224,11 +224,11 @@ void weightlinks2remaplinks(int lalloc, unsigned tgt_grid_size, weightlinks_t *w
}
void weightlinks2remaplinks4(unsigned tgt_grid_size, weightlinks4_t *weightlinks, remapvars_t *rv)
void weightlinks2remaplinks4(size_t tgt_grid_size, weightlinks4_t *weightlinks, remapvars_t *rv)
{
unsigned nlinks = 0;
size_t nlinks = 0;
for ( unsigned tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
for ( size_t tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
{
if ( weightlinks[tgt_cell_add].nlinks )
{
......@@ -251,18 +251,18 @@ void weightlinks2remaplinks4(unsigned tgt_grid_size, weightlinks4_t *weightlinks
#if defined(_OPENMP)
#pragma omp parallel for default(none) shared(src_cell_adds,tgt_cell_adds,wts,weightlinks,tgt_grid_size)
#endif
for ( unsigned tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
for ( size_t tgt_cell_add = 0; tgt_cell_add < tgt_grid_size; ++tgt_cell_add )
{
unsigned num_links = weightlinks[tgt_cell_add].nlinks;
size_t num_links = weightlinks[tgt_cell_add].nlinks;
if ( num_links )
{
unsigned offset = weightlinks[tgt_cell_add].offset;
size_t offset = weightlinks[tgt_cell_add].offset;
addweight4_t *addweights = weightlinks[tgt_cell_add].addweights;
for ( unsigned ilink = 0; ilink < num_links; ++ilink )
for ( size_t ilink = 0; ilink < num_links; ++ilink )
{
src_cell_adds[offset+ilink] = addweights[ilink].add;
tgt_cell_adds[offset+ilink] = tgt_cell_add;
for ( unsigned k = 0; k < 4; ++k )
for ( size_t k = 0; k < 4; ++k )
wts[(offset+ilink)*4+k] = addweights[ilink].weight[k];
}
}
......
......@@ -27,10 +27,10 @@ typedef struct {
} weightlinks4_t;
void store_weightlinks(int lalloc, unsigned num_weights, int *srch_add, double *weights, unsigned cell_add, weightlinks_t *weightlinks);
void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4], unsigned cell_add, weightlinks4_t *weightlinks);
void weightlinks2remaplinks(int lalloc, unsigned tgt_grid_size, weightlinks_t *weightlinks, remapvars_t *rv);
void weightlinks2remaplinks4(unsigned tgt_grid_size, weightlinks4_t *weightlinks, remapvars_t *rv);
void store_weightlinks(int lalloc, unsigned num_weights, int *srch_add, double *weights, size_t cell_add, weightlinks_t *weightlinks);
void store_weightlinks4(unsigned num_weights, int *srch_add, double weights[4][4], size_t cell_add, weightlinks4_t *weightlinks);
void weightlinks2remaplinks(int lalloc, size_t tgt_grid_size, weightlinks_t *weightlinks, remapvars_t *rv);
void weightlinks2remaplinks4(size_t tgt_grid_size, weightlinks4_t *weightlinks, remapvars_t *rv);
void sort_add_and_wgts(unsigned num_weights, int *src_add, double *wgts);
void sort_add_and_wgts4(unsigned num_weights, int *src_add, double wgts[4][4]);
......
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