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

Remplaced defines to enum struct RemapType.

parent b57b85a7
......@@ -313,10 +313,7 @@ void *Intgrid(void *argument)
/* && gridInqType(gridID1) != GRID_CURVILINEAR */ )
cdoAbort("Interpolation of %s data unsupported!", gridNamePtr(gridtype) );
if ( operatorID == BOXAVG )
gridID2 = genBoxavgGrid(gridID1, xinc, yinc);
else
gridID2 = genThinoutGrid(gridID1, xinc, yinc);
gridID2 = operatorID == BOXAVG ? genBoxavgGrid(gridID1, xinc, yinc) : genThinoutGrid(gridID1, xinc, yinc);
}
else
cdoAbort("Too many different grids!");
......
......@@ -49,50 +49,50 @@ enum {REMAPCON, REMAPCON2, REMAPBIL, REMAPBIC, REMAPDIS, REMAPNN, REMAPLAF, REMA
enum {HEAP_SORT, MERGE_SORT};
static
void get_map_type(int operfunc, int *map_type, int *submap_type, int *num_neighbors, int *remap_order)
void get_maptype(int operfunc, RemapType *mapType, SubmapType *submapType, int *num_neighbors, int *remap_order)
{
switch ( operfunc )
{
case REMAPYCON:
case GENYCON:
*map_type = MAP_TYPE_CONSERV_YAC;
*mapType = RemapType::CONSERV_YAC;
*remap_order = 1;
break;
case REMAPCON:
case GENCON:
*map_type = MAP_TYPE_CONSERV;
*mapType = RemapType::CONSERV;
*remap_order = 1;
break;
case REMAPCON2:
case GENCON2:
*map_type = MAP_TYPE_CONSERV;
*mapType = RemapType::CONSERV;
*remap_order = 2;
break;
case REMAPLAF:
case GENLAF:
*map_type = MAP_TYPE_CONSERV_YAC;
*submap_type = SUBMAP_TYPE_LAF;
*mapType = RemapType::CONSERV_YAC;
*submapType = SubmapType::LAF;
break;
case REMAPSUM:
*map_type = MAP_TYPE_CONSERV;
*submap_type = SUBMAP_TYPE_SUM;
*mapType = RemapType::CONSERV;
*submapType = SubmapType::SUM;
break;
case REMAPBIL:
case GENBIL:
*map_type = MAP_TYPE_BILINEAR;
*mapType = RemapType::BILINEAR;
break;
case REMAPBIC:
case GENBIC:
*map_type = MAP_TYPE_BICUBIC;
*mapType = RemapType::BICUBIC;
break;
case REMAPDIS:
case GENDIS:
*map_type = MAP_TYPE_DISTWGT;
*mapType = RemapType::DISTWGT;
if ( *num_neighbors == 0 ) *num_neighbors = 4;
break;
case REMAPNN:
case GENNN:
*map_type = MAP_TYPE_DISTWGT;
*mapType = RemapType::DISTWGT;
*num_neighbors = 1;
break;
default:
......@@ -102,16 +102,16 @@ void get_map_type(int operfunc, int *map_type, int *submap_type, int *num_neighb
}
static
int maptype2operfunc(int map_type, int submap_type, int num_neighbors, int remap_order)
int maptype2operfunc(RemapType mapType, SubmapType submapType, int num_neighbors, int remap_order)
{
int operfunc = -1;
if ( map_type == MAP_TYPE_CONSERV ) operfunc = (remap_order == 2) ? REMAPCON2 : REMAPCON;
else if ( map_type == MAP_TYPE_CONSERV_YAC ) operfunc = (submap_type == SUBMAP_TYPE_LAF) ? REMAPLAF : REMAPYCON;
else if ( map_type == MAP_TYPE_BILINEAR ) operfunc = REMAPBIL;
else if ( map_type == MAP_TYPE_BICUBIC ) operfunc = REMAPBIC;
else if ( map_type == MAP_TYPE_DISTWGT ) operfunc = (num_neighbors == 1) ? REMAPNN : REMAPDIS;
else cdoAbort("Unsupported mapping method (map_type = %d)", map_type);
if ( mapType == RemapType::CONSERV ) operfunc = (remap_order == 2) ? REMAPCON2 : REMAPCON;
else if ( mapType == RemapType::CONSERV_YAC ) operfunc = (submapType == SubmapType::LAF) ? REMAPLAF : REMAPYCON;
else if ( mapType == RemapType::BILINEAR ) operfunc = REMAPBIL;
else if ( mapType == RemapType::BICUBIC ) operfunc = REMAPBIC;
else if ( mapType == RemapType::DISTWGT ) operfunc = (num_neighbors == 1) ? REMAPNN : REMAPDIS;
else cdoAbort("Unsupported mapping method (mapType = %d)", mapType);
return operfunc;
}
......@@ -764,8 +764,8 @@ void *Remap(void *argument)
int r = -1;
int nremaps = 0;
int norm_opt = NORM_OPT_NONE;
int map_type = -1;
int submap_type = SUBMAP_TYPE_NONE;
RemapType mapType(RemapType::UNDEF);
SubmapType submapType = SubmapType::NONE;
int num_neighbors = 0;
char varname[CDI_MAX_NAME];
double missval;
......@@ -875,7 +875,7 @@ void *Remap(void *argument)
if ( lremapxxx )
{
read_remap_scrip(remap_file, gridID1, gridID2, &map_type, &submap_type, &num_neighbors,
read_remap_scrip(remap_file, gridID1, gridID2, &mapType, &submapType, &num_neighbors,
&remap_order, &remaps[0].src_grid, &remaps[0].tgt_grid, &remaps[0].vars);
if ( remaps[0].vars.links_per_value == 0 ) links_per_value(&remaps[0].vars);
......@@ -885,8 +885,8 @@ void *Remap(void *argument)
remaps[0].gridID = gridID1;
remaps[0].gridsize = gridInqSize(gridID1);
if ( map_type == MAP_TYPE_DISTWGT && !lextrapolate ) remap_extrapolate = true;
if ( gridIsCircular(gridID1) && !lextrapolate ) remap_extrapolate = true;
if ( mapType == RemapType::DISTWGT && !lextrapolate ) remap_extrapolate = true;
if ( gridIsCircular(gridID1) && !lextrapolate ) remap_extrapolate = true;
if ( gridInqType(gridID1) == GRID_GME ) gridsize = remaps[0].src_grid.nvgp;
......@@ -917,29 +917,26 @@ void *Remap(void *argument)
if ( remaps[0].tgt_grid.size != gridsize2 )
cdoAbort("Size of target grid and weights from %s differ!", remap_file);
operfunc = maptype2operfunc(map_type, submap_type, num_neighbors, remap_order);
operfunc = maptype2operfunc(mapType, submapType, num_neighbors, remap_order);
if ( remap_test ) reorder_links(&remaps[0].vars);
}
else
{
get_map_type(operfunc, &map_type, &submap_type, &num_neighbors, &remap_order);
get_maptype(operfunc, &mapType, &submapType, &num_neighbors, &remap_order);
}
if ( !remap_genweights &&
map_type != MAP_TYPE_BILINEAR && map_type != MAP_TYPE_BICUBIC &&
map_type != MAP_TYPE_DISTWGT && map_type != MAP_TYPE_CONSERV_YAC )
remap_genweights = true;
if ( !remap_genweights && mapType != RemapType::CONSERV ) remap_genweights = true;
remap_set_int(REMAP_GENWEIGHTS, (int)remap_genweights);
if ( map_type == MAP_TYPE_CONSERV || map_type == MAP_TYPE_CONSERV_YAC ) norm_opt = get_norm_opt();
if ( mapType == RemapType::CONSERV || mapType == RemapType::CONSERV_YAC ) norm_opt = get_norm_opt();
size_t grid1sizemax = vlistGridsizeMax(vlistID1);
bool need_gradiants = false;
if ( map_type == MAP_TYPE_BICUBIC ) need_gradiants = true;
if ( map_type == MAP_TYPE_CONSERV && remap_order == 2 )
if ( mapType == RemapType::BICUBIC ) need_gradiants = true;
if ( mapType == RemapType::CONSERV && remap_order == 2 )
{
if ( cdoVerbose ) cdoPrint("Second order remapping");
need_gradiants = true;
......@@ -989,7 +986,7 @@ void *Remap(void *argument)
}
}
if ( map_type != MAP_TYPE_CONSERV && map_type != MAP_TYPE_CONSERV_YAC &&
if ( mapType != RemapType::CONSERV && mapType != RemapType::CONSERV_YAC &&
gridInqType(gridID1) == GRID_GME && gridInqType(gridID2) == GRID_GME )
cdoAbort("Only conservative remapping is available to remap between GME grids!");
......@@ -1041,7 +1038,7 @@ void *Remap(void *argument)
{
if ( gridIsCircular(gridID1) && !lextrapolate ) remap_extrapolate = true;
remaps[r].src_grid.non_global = false;
if ( map_type == MAP_TYPE_DISTWGT && !remap_extrapolate && gridInqSize(gridID1) > 1 && !is_global_grid(gridID1) )
if ( mapType == RemapType::DISTWGT && !remap_extrapolate && gridInqSize(gridID1) > 1 && !is_global_grid(gridID1) )
remaps[r].src_grid.non_global = true;
/*
remaps[r].src_grid.luse_cell_area = FALSE;
......@@ -1049,7 +1046,7 @@ void *Remap(void *argument)
*/
if ( gridInqType(gridID1) != GRID_UNSTRUCTURED && lremap_num_srch_bins == false )
{
if ( !remap_extrapolate && map_type == MAP_TYPE_DISTWGT )
if ( !remap_extrapolate && mapType == RemapType::DISTWGT )
{
remap_num_srch_bins = 1;
}
......@@ -1068,13 +1065,13 @@ void *Remap(void *argument)
remaps[r].vars.norm_opt = norm_opt;
remaps[r].vars.pinit = false;
if ( (map_type == MAP_TYPE_BILINEAR || map_type == MAP_TYPE_BICUBIC) &&
if ( (mapType == RemapType::BILINEAR || mapType == RemapType::BICUBIC) &&
(gridInqType(gridID1) == GRID_GME || gridInqType(gridID1) == GRID_UNSTRUCTURED) )
cdoAbort("Bilinear/bicubic interpolation doesn't support unstructured source grids!");
// Initialize grid information for both grids
if ( cdoTimer ) timer_start(timer_remap_init);
remap_grids_init(map_type, remap_extrapolate, gridID1, &remaps[r].src_grid, gridID2, &remaps[r].tgt_grid);
remap_grids_init(mapType, remap_extrapolate, gridID1, &remaps[r].src_grid, gridID2, &remaps[r].tgt_grid);
if ( cdoTimer ) timer_stop(timer_remap_init);
}
......@@ -1090,7 +1087,7 @@ void *Remap(void *argument)
memcpy(remaps[r].src_grid.mask, imask, remaps[r].src_grid.size*sizeof(int));
if ( map_type == MAP_TYPE_CONSERV || map_type == MAP_TYPE_CONSERV_YAC )
if ( mapType == RemapType::CONSERV || mapType == RemapType::CONSERV_YAC )
{
memset(remaps[r].src_grid.cell_area, 0, remaps[r].src_grid.size*sizeof(double));
memset(remaps[r].src_grid.cell_frac, 0, remaps[r].src_grid.size*sizeof(double));
......@@ -1098,22 +1095,22 @@ void *Remap(void *argument)
}
memset(remaps[r].tgt_grid.cell_frac, 0, remaps[r].tgt_grid.size*sizeof(double));
/* initialize some remapping variables */
// initialize some remapping variables
if ( cdoTimer ) timer_start(timer_remap_init);
remap_vars_init(map_type, remaps[r].src_grid.size, remaps[r].tgt_grid.size, &remaps[r].vars);
remap_vars_init(mapType, remaps[r].src_grid.size, remaps[r].tgt_grid.size, &remaps[r].vars);
if ( cdoTimer ) timer_stop(timer_remap_init);
print_remap_info(operfunc, remap_genweights, &remaps[r].src_grid, &remaps[r].tgt_grid, nmiss1);
if ( remap_genweights )
{
if ( map_type == MAP_TYPE_CONSERV ) scrip_remap_conserv_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( map_type == MAP_TYPE_BILINEAR ) scrip_remap_bilinear_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( map_type == MAP_TYPE_BICUBIC ) scrip_remap_bicubic_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( map_type == MAP_TYPE_DISTWGT ) remap_distwgt_weights(num_neighbors, &remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( map_type == MAP_TYPE_CONSERV_YAC ) remap_conserv_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
if ( mapType == RemapType::CONSERV ) scrip_remap_conserv_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( mapType == RemapType::BILINEAR ) scrip_remap_bilinear_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( mapType == RemapType::BICUBIC ) scrip_remap_bicubic_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( mapType == RemapType::DISTWGT ) remap_distwgt_weights(num_neighbors, &remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
else if ( mapType == RemapType::CONSERV_YAC ) remap_conserv_weights(&remaps[r].src_grid, &remaps[r].tgt_grid, &remaps[r].vars);
if ( map_type == MAP_TYPE_CONSERV && remaps[r].vars.num_links != remaps[r].vars.max_links )
if ( mapType == RemapType::CONSERV && remaps[r].vars.num_links != remaps[r].vars.max_links )
resize_remap_vars(&remaps[r].vars, remaps[r].vars.num_links-remaps[r].vars.max_links);
if ( remaps[r].vars.sort_add ) sort_remap_add(&remaps[r].vars);
......@@ -1157,10 +1154,10 @@ void *Remap(void *argument)
}
else
{
if ( map_type == MAP_TYPE_BILINEAR ) scrip_remap_bilinear(&remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
else if ( map_type == MAP_TYPE_BICUBIC ) scrip_remap_bicubic(&remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
else if ( map_type == MAP_TYPE_DISTWGT ) remap_distwgt(num_neighbors, &remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
else if ( map_type == MAP_TYPE_CONSERV_YAC ) remap_conserv(&remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
if ( mapType == RemapType::BILINEAR ) scrip_remap_bilinear(&remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
else if ( mapType == RemapType::BICUBIC ) scrip_remap_bicubic(&remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
else if ( mapType == RemapType::DISTWGT ) remap_distwgt(num_neighbors, &remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
else if ( mapType == RemapType::CONSERV_YAC ) remap_conserv(&remaps[r].src_grid, &remaps[r].tgt_grid, array1, array2, missval);
}
gridsize2 = gridInqSize(gridID2);
......@@ -1231,7 +1228,7 @@ void *Remap(void *argument)
WRITE_REMAP:
if ( lwrite_remap )
write_remap_scrip(cdoStreamName(1)->args, map_type, submap_type, num_neighbors, remap_order,
write_remap_scrip(cdoStreamName(1)->args, mapType, submapType, num_neighbors, remap_order,
remaps[r].src_grid, remaps[r].tgt_grid, remaps[r].vars);
pstreamClose(streamID1);
......
......@@ -154,8 +154,8 @@ void yar_remap_bil(field_type *field1, field_type *field2)
remap.vars.pinit = false;
if ( cdoTimer ) timer_start(timer_yar_remap_init);
remap_grids_init(MAP_TYPE_BILINEAR, 0, gridIDin, &remap.src_grid, gridIDout, &remap.tgt_grid);
remap_vars_init(MAP_TYPE_BILINEAR, remap.src_grid.size, remap.tgt_grid.size, &remap.vars);
remap_grids_init(RemapType::BILINEAR, 0, gridIDin, &remap.src_grid, gridIDout, &remap.tgt_grid);
remap_vars_init(RemapType::BILINEAR, remap.src_grid.size, remap.tgt_grid.size, &remap.vars);
if ( cdoTimer ) timer_stop(timer_yar_remap_init);
......@@ -396,8 +396,8 @@ void yar_remap_con(field_type *field1, field_type *field2)
remap.vars.pinit = false;
if ( cdoTimer ) timer_start(timer_yar_remap_init);
remap_grids_init(MAP_TYPE_CONSERV, 0, gridIDin, &remap.src_grid, gridIDout, &remap.tgt_grid);
remap_vars_init(MAP_TYPE_CONSERV, remap.src_grid.size, remap.tgt_grid.size, &remap.vars);
remap_grids_init(RemapType::CONSERV, 0, gridIDin, &remap.src_grid, gridIDout, &remap.tgt_grid);
remap_vars_init(RemapType::CONSERV, remap.src_grid.size, remap.tgt_grid.size, &remap.vars);
if ( cdoTimer ) timer_stop(timer_yar_remap_init);
......
......@@ -62,15 +62,8 @@ typedef RESTR_TYPE restr_t;
#define NORM_OPT_DESTAREA 2
#define NORM_OPT_FRACAREA 3
#define MAP_TYPE_CONSERV 1
#define MAP_TYPE_BILINEAR 2
#define MAP_TYPE_BICUBIC 3
#define MAP_TYPE_DISTWGT 4
#define MAP_TYPE_CONSERV_YAC 5
#define SUBMAP_TYPE_NONE 0
#define SUBMAP_TYPE_LAF 1
#define SUBMAP_TYPE_SUM 2
enum struct RemapType {UNDEF, BILINEAR, BICUBIC, DISTWGT, CONSERV, CONSERV_YAC};
enum struct SubmapType {NONE, LAF, SUM};
typedef struct {
......@@ -129,20 +122,20 @@ typedef struct {
remaplink_t;
typedef struct {
long links_per_value;
bool sort_add;
bool pinit; /* true: if the pointers are initialized */
size_t max_links; /* current size of link arrays */
size_t num_links; /* actual number of links for remapping */
size_t num_wts; /* num of weights used in remapping */
int map_type; /* identifier for remapping method */
int norm_opt; /* option for normalization (conserv only) */
size_t resize_increment; /* default amount to increase array size */
long links_per_value;
bool sort_add;
bool pinit; /* true: if the pointers are initialized */
size_t max_links; /* current size of link arrays */
size_t num_links; /* actual number of links for remapping */
size_t num_wts; /* num of weights used in remapping */
RemapType mapType; /* identifier for remapping method */
int norm_opt; /* option for normalization (conserv only) */
size_t resize_increment; /* default amount to increase array size */
size_t *src_cell_add; /* source grid address for each link */
size_t *tgt_cell_add; /* target grid address for each link */
size_t *src_cell_add; /* source grid address for each link */
size_t *tgt_cell_add; /* target grid address for each link */
double *wts; /* map weights for each link [max_links*num_wts] */
double *wts; /* map weights for each link [max_links*num_wts] */
remaplink_t links;
}
......@@ -169,8 +162,8 @@ void remap_set_threshhold(double threshhold);
void remap_set_int(int remapvar, int value);
void remap_grids_init(int map_type, bool lextrapolate, int gridID1, remapgrid_t *src_grid, int gridID2, remapgrid_t *tgt_grid);
void remap_vars_init(int map_type, size_t src_grid_size, size_t tgt_grid_size, remapvars_t *rv);
void remap_grids_init(RemapType mapType, bool lextrapolate, int gridID1, remapgrid_t *src_grid, int gridID2, remapgrid_t *tgt_grid);
void remap_vars_init(RemapType mapType, size_t src_grid_size, size_t tgt_grid_size, remapvars_t *rv);
void remapVarsFree(remapvars_t *rv);
void remapGridFree(remapgrid_t *grid);
......@@ -210,12 +203,12 @@ void reorder_links(remapvars_t *rv);
void sort_add(size_t num_links, size_t num_wts, size_t *restrict add1, size_t *restrict add2, double *restrict weights);
void sort_iter(size_t num_links, size_t num_wts, size_t *restrict add1, size_t *restrict add2, double *restrict weights, int parent);
void write_remap_scrip(const char *interp_file, int map_type, int submap_type, int num_neighbors,
void write_remap_scrip(const char *interp_file, RemapType mapType, SubmapType submapType, int num_neighbors,
int remap_order, remapgrid_t src_grid, remapgrid_t tgt_grid, remapvars_t rv);
void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *map_type, int *submap_type, int *num_neighbors,
void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, RemapType *mapType, SubmapType *submapType, int *num_neighbors,
int *remap_order, remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapvars_t *rv);
void calc_lat_bins(remapgrid_t* src_grid, remapgrid_t* tgt_grid, int map_type);
void calc_lat_bins(remapgrid_t* src_grid, remapgrid_t* tgt_grid, RemapType mapType);
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);
......
......@@ -16,7 +16,7 @@
void remapgrid_init(remapgrid_t *grid);
void remapgrid_alloc(int map_type, remapgrid_t *grid);
void remapgrid_alloc(RemapType mapType, remapgrid_t *grid);
#if defined(HAVE_LIBNETCDF)
......@@ -67,7 +67,7 @@ void read_links(int nc_file_id, int nc_add_id, size_t num_links, size_t *cell_ad
#endif
void write_remap_scrip(const char *interp_file, int map_type, int submap_type, int num_neighbors,
void write_remap_scrip(const char *interp_file, RemapType mapType, SubmapType submapType, int num_neighbors,
int remap_order, remapgrid_t src_grid, remapgrid_t tgt_grid, remapvars_t rv)
{
// Writes remap data to a NetCDF file using SCRIP conventions
......@@ -136,11 +136,11 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
break;
}
switch ( map_type )
switch ( mapType )
{
case MAP_TYPE_CONSERV:
case RemapType::CONSERV:
lgridarea = true;
if ( submap_type == SUBMAP_TYPE_LAF )
if ( submapType == SubmapType::LAF )
{
strcpy(map_method, "Largest area fraction");
break;
......@@ -150,10 +150,10 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
strcpy(map_method, "Conservative remapping");
break;
}
case MAP_TYPE_CONSERV_YAC:
case RemapType::CONSERV_YAC:
lgridarea = true;
/*
if ( submap_type == SUBMAP_TYPE_LAF )
if ( submapType == SubmapType::LAF )
{
strcpy(map_method, "Largest area fraction");
break;
......@@ -164,18 +164,20 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
strcpy(map_method, "Conservative remapping using clipping on sphere");
break;
}
case MAP_TYPE_BILINEAR:
case RemapType::BILINEAR:
strcpy(map_method, "Bilinear remapping");
break;
case MAP_TYPE_BICUBIC:
case RemapType::BICUBIC:
strcpy(map_method, "Bicubic remapping");
break;
case MAP_TYPE_DISTWGT:
case RemapType::DISTWGT:
if ( num_neighbors == 1 )
strcpy(map_method, "Nearest neighbor");
else
strcpy(map_method, "Distance weighted avg of nearest neighbors");
break;
case RemapType::UNDEF:
break;
}
/*
......@@ -241,7 +243,7 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
nce(nc_put_att_text(nc_file_id, NC_GLOBAL, "map_method", strlen(map_method), map_method));
// Remap order
if ( map_type == MAP_TYPE_CONSERV && submap_type == SUBMAP_TYPE_NONE )
if ( mapType == RemapType::CONSERV && submapType == SubmapType::NONE )
nce(nc_put_att_int(nc_file_id, NC_GLOBAL, "remap_order", NC_INT, 1L, &remap_order));
// File convention
......@@ -447,7 +449,7 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
/*****************************************************************************/
void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *map_type, int *submap_type, int *num_neighbors,
void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, RemapType *mapType, SubmapType *submapType, int *num_neighbors,
int *remap_order, remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapvars_t *rv)
{
// The routine reads a NetCDF file to extract remapping info in SCRIP format
......@@ -492,7 +494,7 @@ void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *ma
int nc_rmpmatrix_id; /* id for remapping matrix */
char map_name[1024];
char map_method[64]; /* character string for map_type */
char map_method[64]; /* character string for mapType */
char normalize_opt[64]; /* character string for normalization option */
char convention[64]; /* character string for output convention */
char src_grid_name[64]; /* grid name for source grid */
......@@ -548,49 +550,49 @@ void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *ma
nce(nc_inq_attlen(nc_file_id, NC_GLOBAL, "map_method", &attlen));
map_method[attlen] = 0;
*submap_type = SUBMAP_TYPE_NONE;
*submapType = SubmapType::NONE;
*remap_order = 1;
if ( cmpstr(map_method, "Conservative") == 0 )
{
int iatt;
if ( cmpstr(map_method, "Conservative remapping using clipping on sphere") == 0 )
rv->map_type = MAP_TYPE_CONSERV_YAC;
rv->mapType = RemapType::CONSERV_YAC;
else
rv->map_type = MAP_TYPE_CONSERV;
rv->mapType = RemapType::CONSERV;
status = nc_get_att_int(nc_file_id, NC_GLOBAL, "remap_order", &iatt);
if ( status == NC_NOERR ) *remap_order = iatt;
}
else if ( cmpstr(map_method, "Bilinear") == 0 ) rv->map_type = MAP_TYPE_BILINEAR;
else if ( cmpstr(map_method, "Bicubic") == 0 ) rv->map_type = MAP_TYPE_BICUBIC;
else if ( cmpstr(map_method, "Bilinear") == 0 ) rv->mapType = RemapType::BILINEAR;
else if ( cmpstr(map_method, "Bicubic") == 0 ) rv->mapType = RemapType::BICUBIC;
else if ( cmpstr(map_method, "Distance") == 0 )
{
rv->map_type = MAP_TYPE_DISTWGT;
rv->mapType = RemapType::DISTWGT;
*num_neighbors = 4;
}
else if ( cmpstr(map_method, "Nearest") == 0 )
{
rv->map_type = MAP_TYPE_DISTWGT;
rv->mapType = RemapType::DISTWGT;
*num_neighbors = 1;
}
else if ( cmpstr(map_method, "Largest") == 0 )
{
rv->map_type = MAP_TYPE_CONSERV;
*submap_type = SUBMAP_TYPE_LAF;
rv->mapType = RemapType::CONSERV;
*submapType = SubmapType::LAF;
}
else
{
cdoPrint("map_type = %s", map_method);
cdoPrint("mapType = %s", map_method);
cdoAbort("Invalid Map Type");
}
if ( cdoVerbose )
cdoPrint("map_type = %s", map_method);
cdoPrint("mapType = %s", map_method);
if ( rv->map_type == MAP_TYPE_CONSERV ) lgridarea = true;
if ( rv->mapType == RemapType::CONSERV ) lgridarea = true;
*map_type = rv->map_type;
*mapType = rv->mapType;
// File convention
nce(nc_get_att_text (nc_file_id, NC_GLOBAL, "conventions", convention));
......@@ -687,8 +689,8 @@ void read_remap_scrip(const char *interp_file, int gridID1, int gridID2, int *ma
gridID1_gme_c = gridToUnstructured(gridID1, 1);
}
remapgrid_alloc(rv->map_type, src_grid);
remapgrid_alloc(rv->map_type, tgt_grid);
remapgrid_alloc(rv->mapType, src_grid);
remapgrid_alloc(rv->mapType, tgt_grid);
if ( gridInqType(gridID1) == GRID_GME ) gridInqMaskGME(gridID1_gme_c, src_grid->vgpm);
......
......@@ -46,7 +46,7 @@ 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)
void calc_lat_bins(remapgrid_t* src_grid, remapgrid_t* tgt_grid, RemapType mapType)
{
size_t n2;
size_t nbins = src_grid->num_srch_bins;
......@@ -69,7 +69,7 @@ void calc_lat_bins(remapgrid_t* src_grid, remapgrid_t* tgt_grid, int map_type)
calc_bin_addr(src_grid->size, nbins, bin_lats, src_grid->cell_bound_box, src_grid->bin_addr);
if ( map_type == MAP_TYPE_CONSERV || map_type == MAP_TYPE_CONSERV_YAC )
if ( mapType == RemapType::CONSERV || mapType == RemapType::CONSERV_YAC )
{
tgt_grid->bin_addr = (size_t*) Realloc(tgt_grid->bin_addr, 2*nbins*sizeof(size_t));
......@@ -79,12 +79,12 @@ void calc_lat_bins(remapgrid_t* src_grid, remapgrid_t* tgt_grid, int map_type)
}
}
if ( map_type == MAP_TYPE_CONSERV_YAC )
if ( mapType == RemapType::CONSERV_YAC )
{
Free(tgt_grid->cell_bound_box); tgt_grid->cell_bound_box = NULL;
}
if ( map_type == MAP_TYPE_DISTWGT )
if ( mapType == RemapType::DISTWGT )
{
Free(src_grid->cell_bound_box); src_grid->cell_bound_box = NULL;
}
......
......@@ -182,7 +182,7 @@ void remapgrid_init(remapgrid_t *grid)
/*****************************************************************************/
void remapgrid_alloc(int map_type, remapgrid_t *grid)
void remapgrid_alloc(RemapType mapType, remapgrid_t *grid)
{
if ( grid->nvgp )
grid->vgpm = (int*) Malloc(grid->nvgp*sizeof(int));
......@@ -195,7 +195,7 @@ void remapgrid_alloc(int map_type, remapgrid_t *grid)
grid->cell_center_lat = (double*) Malloc(grid->size*sizeof(double));
}
if ( map_type == MAP_TYPE_CONSERV || map_type == MAP_TYPE_CONSERV_YAC )
if ( mapType == RemapType::CONSERV || mapType == RemapType::CONSERV_YAC )
{
grid->cell_area = (double*) Malloc(grid->size*sizeof(double));
memset(grid->cell_area, 0, grid->size*sizeof(double));
......@@ -516,7 +516,7 @@ void remap_define_reg2d(int gridID, remapgrid_t *grid)
}
static
void remap_define_grid(int map_type, int gridID, remapgrid_t *grid, const char *txt)
void remap_define_grid(RemapType mapType, int gridID, remapgrid_t *grid, const char *txt)
{
bool lgrid_destroy = false;