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

remap_scrip_io.cc: cleanup.

parent c8b493bd
Pipeline #4975 passed with stages
in 24 minutes and 33 seconds
......@@ -181,9 +181,9 @@ cdo_compute_concave_overlap_areas(size_t N, search_t &search, const grid_cell &t
auto overlap_cells = search.overlap_buffer.data();
auto source_cell = search.src_grid_cells.data();
double coordinates_x[3] = { -1, -1, -1 };
double coordinates_y[3] = { -1, -1, -1 };
double coordinates_xyz[3][3] = { { -1, -1, -1 }, { -1, -1, -1 }, { -1, -1, -1 } };
double coordinates_x[3] = { -1.0, -1.0, -1.0 };
double coordinates_y[3] = { -1.0, -1.0, -1.0 };
double coordinates_xyz[3][3] = { { -1.0, -1.0, -1.0 }, { -1.0, -1.0, -1.0 }, { -1.0, -1.0, -1.0 } };
enum yac_edge_type edge_types[3] = { GREAT_CIRCLE, GREAT_CIRCLE, GREAT_CIRCLE };
grid_cell target_partial_cell;
......
......@@ -46,7 +46,7 @@ remapDistwgtWeights(size_t numNeighbors, RemapSearch &rsearch, RemapVars &rv)
std::vector<knnWeightsType> knnWeights;
for (int i = 0; i < Threading::ompNumThreads; ++i) knnWeights.push_back(knnWeightsType(numNeighbors));
double start = Options::cdoVerbose ? cdo_get_wtime() : 0;
double start = Options::cdoVerbose ? cdo_get_wtime() : 0.0;
// Loop over destination grid
......@@ -197,7 +197,7 @@ intgriddis(Field &field1, Field &field2, size_t numNeighbors)
remapSearchInit(mapType, remap.search, remap.src_grid, remap.tgt_grid);
double start = Options::cdoVerbose ? cdo_get_wtime() : 0;
double start = Options::cdoVerbose ? cdo_get_wtime() : 0.0;
// Loop over destination grid
......
......@@ -86,35 +86,6 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
#ifdef HAVE_LIBNETCDF
int nc_file_id = -1; /* id for NetCDF file */
int nc_srcgrdsize_id = -1; /* id for source grid size */
int nc_dstgrdsize_id = -1; /* id for destination grid size */
int nc_srcgrdcorn_id = 0; /* id for number of source grid corners */
int nc_dstgrdcorn_id = 0; /* id for number of dest grid corners */
int nc_srcgrdrank_id = -1; /* id for source grid rank */
int nc_dstgrdrank_id = -1; /* id for dest grid rank */
int nc_numlinks_id = -1; /* id for number of links in mapping */
int nc_numwgts_id = -1; /* id for number of weights for mapping */
int nc_srcgrddims_id = -1; /* id for source grid dimensions */
int nc_dstgrddims_id = -1; /* id for dest grid dimensions */
int nc_srcgrdcntrlat_id = -1; /* id for source grid center latitude */
int nc_dstgrdcntrlat_id = -1; /* id for dest grid center latitude */
int nc_srcgrdcntrlon_id = -1; /* id for source grid center longitude */
int nc_dstgrdcntrlon_id = -1; /* id for dest grid center longitude */
int nc_srcgrdimask_id = -1; /* id for source grid mask */
int nc_dstgrdimask_id = -1; /* id for dest grid mask */
int nc_srcgrdcrnrlat_id = -1; /* id for latitude of source grid corners */
int nc_srcgrdcrnrlon_id = -1; /* id for longitude of source grid corners */
int nc_dstgrdcrnrlat_id = -1; /* id for latitude of dest grid corners */
int nc_dstgrdcrnrlon_id = -1; /* id for longitude of dest grid corners */
int nc_srcgrdarea_id = -1; /* id for area of source grid cells */
int nc_dstgrdarea_id = -1; /* id for area of dest grid cells */
int nc_srcgrdfrac_id = -1; /* id for area fraction on source grid */
int nc_dstgrdfrac_id = -1; /* id for area fraction on dest grid */
int nc_srcadd_id = -1; /* id for map source address */
int nc_dstadd_id = -1; /* id for map destination address */
int nc_rmpmatrix_id = -1; /* id for remapping matrix */
int nc_dims2_id[2]; /* NetCDF ids for 2d array dims */
const char *map_name = "SCRIP remapping with CDO";
......@@ -221,6 +192,7 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
}
// Create NetCDF file for mapping and define some global attributes
int nc_file_id = -1;
nce(nc_create(interp_file, writemode, &nc_file_id));
// Map name
......@@ -263,32 +235,39 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
// Prepare NetCDF dimension info
// Define grid size dimensions
int nc_srcgrdsize_id = -1, nc_dstgrdsize_id = -1;
nce(nc_def_dim(nc_file_id, "src_grid_size", src_grid.size, &nc_srcgrdsize_id));
nce(nc_def_dim(nc_file_id, "dst_grid_size", tgt_grid.size, &nc_dstgrdsize_id));
// Define grid corner dimension
int nc_srcgrdcorn_id = -1, nc_dstgrdcorn_id = -1;
if (src_grid.lneed_cell_corners) nce(nc_def_dim(nc_file_id, "src_grid_corners", src_grid.num_cell_corners, &nc_srcgrdcorn_id));
if (tgt_grid.lneed_cell_corners) nce(nc_def_dim(nc_file_id, "dst_grid_corners", tgt_grid.num_cell_corners, &nc_dstgrdcorn_id));
// Define grid rank dimension
int nc_srcgrdrank_id = -1, nc_dstgrdrank_id = -1;
nce(nc_def_dim(nc_file_id, "src_grid_rank", src_grid.rank, &nc_srcgrdrank_id));
nce(nc_def_dim(nc_file_id, "dst_grid_rank", tgt_grid.rank, &nc_dstgrdrank_id));
// Define map size dimensions
int nc_numlinks_id = -1, nc_numwgts_id = -1;
nce(nc_def_dim(nc_file_id, "num_links", rv.num_links, &nc_numlinks_id));
nce(nc_def_dim(nc_file_id, "num_wgts", rv.num_wts, &nc_numwgts_id));
// Define grid dimensions
int nc_srcgrddims_id = -1, nc_dstgrddims_id = -1;
nce(nc_def_var(nc_file_id, "src_grid_dims", sizetype, 1, &nc_srcgrdrank_id, &nc_srcgrddims_id));
nce(nc_def_var(nc_file_id, "dst_grid_dims", sizetype, 1, &nc_dstgrdrank_id, &nc_dstgrddims_id));
// Define all arrays for NetCDF descriptors
// Define grid center latitude array
int nc_srcgrdcntrlat_id = -1, nc_dstgrdcntrlat_id = -1;
nce(nc_def_var(nc_file_id, "src_grid_center_lat", NC_DOUBLE, 1, &nc_srcgrdsize_id, &nc_srcgrdcntrlat_id));
nce(nc_def_var(nc_file_id, "dst_grid_center_lat", NC_DOUBLE, 1, &nc_dstgrdsize_id, &nc_dstgrdcntrlat_id));
// Define grid center longitude array
int nc_srcgrdcntrlon_id = -1, nc_dstgrdcntrlon_id = -1;
nce(nc_def_var(nc_file_id, "src_grid_center_lon", NC_DOUBLE, 1, &nc_srcgrdsize_id, &nc_srcgrdcntrlon_id));
nce(nc_def_var(nc_file_id, "dst_grid_center_lon", NC_DOUBLE, 1, &nc_dstgrdsize_id, &nc_dstgrdcntrlon_id));
......@@ -297,6 +276,7 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
nc_dims2_id[0] = nc_srcgrdsize_id;
nc_dims2_id[1] = nc_srcgrdcorn_id;
int nc_srcgrdcrnrlat_id = -1, nc_srcgrdcrnrlon_id = -1;
if (src_grid.lneed_cell_corners)
{
nce(nc_def_var(nc_file_id, "src_grid_corner_lat", NC_DOUBLE, 2, nc_dims2_id, &nc_srcgrdcrnrlat_id));
......@@ -306,6 +286,7 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
nc_dims2_id[0] = nc_dstgrdsize_id;
nc_dims2_id[1] = nc_dstgrdcorn_id;
int nc_dstgrdcrnrlat_id = -1, nc_dstgrdcrnrlon_id = -1;
if (tgt_grid.lneed_cell_corners)
{
nce(nc_def_var(nc_file_id, "dst_grid_corner_lat", NC_DOUBLE, 2, nc_dims2_id, &nc_dstgrdcrnrlat_id));
......@@ -331,14 +312,17 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
// Define grid mask
int nc_srcgrdimask_id = -1;
nce(nc_def_var(nc_file_id, "src_grid_imask", NC_INT, 1, &nc_srcgrdsize_id, &nc_srcgrdimask_id));
nce(nc_put_att_text(nc_file_id, nc_srcgrdimask_id, "units", 8, "unitless"));
int nc_dstgrdimask_id = -1;
nce(nc_def_var(nc_file_id, "dst_grid_imask", NC_INT, 1, &nc_dstgrdsize_id, &nc_dstgrdimask_id));
nce(nc_put_att_text(nc_file_id, nc_dstgrdimask_id, "units", 8, "unitless"));
// Define grid area arrays
int nc_srcgrdarea_id = -1, nc_dstgrdarea_id = -1;
if (lgridarea)
{
nce(nc_def_var(nc_file_id, "src_grid_area", NC_DOUBLE, 1, &nc_srcgrdsize_id, &nc_srcgrdarea_id));
......@@ -350,20 +334,24 @@ remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType sub
// Define grid fraction arrays
int nc_srcgrdfrac_id = -1;
nce(nc_def_var(nc_file_id, "src_grid_frac", NC_DOUBLE, 1, &nc_srcgrdsize_id, &nc_srcgrdfrac_id));
nce(nc_put_att_text(nc_file_id, nc_srcgrdfrac_id, "units", 8, "unitless"));
int nc_dstgrdfrac_id = -1;
nce(nc_def_var(nc_file_id, "dst_grid_frac", NC_DOUBLE, 1, &nc_dstgrdsize_id, &nc_dstgrdfrac_id));
nce(nc_put_att_text(nc_file_id, nc_dstgrdfrac_id, "units", 8, "unitless"));
// Define mapping arrays
int nc_srcadd_id = -1, nc_dstadd_id = -1;
nce(nc_def_var(nc_file_id, "src_address", sizetype, 1, &nc_numlinks_id, &nc_srcadd_id));
nce(nc_def_var(nc_file_id, "dst_address", sizetype, 1, &nc_numlinks_id, &nc_dstadd_id));
nc_dims2_id[0] = nc_numlinks_id;
nc_dims2_id[1] = nc_numwgts_id;
int nc_rmpmatrix_id = -1;
nce(nc_def_var(nc_file_id, "remap_matrix", NC_DOUBLE, 2, nc_dims2_id, &nc_rmpmatrix_id));
// End definition stage
......@@ -501,33 +489,6 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
bool lgridarea = false;
int status;
int nc_srcgrdsize_id; /* id for source grid size */
int nc_dstgrdsize_id; /* id for destination grid size */
int nc_srcgrdcorn_id; /* id for number of source grid corners */
int nc_dstgrdcorn_id; /* id for number of dest grid corners */
int nc_srcgrdrank_id; /* id for source grid rank */
int nc_dstgrdrank_id; /* id for dest grid rank */
int nc_numlinks_id; /* id for number of links in mapping */
int nc_numwgts_id; /* id for number of weights for mapping */
int nc_srcgrddims_id; /* id for source grid dimensions */
int nc_dstgrddims_id; /* id for dest grid dimensions */
int nc_srcgrdcntrlat_id; /* id for source grid center latitude */
int nc_dstgrdcntrlat_id; /* id for dest grid center latitude */
int nc_srcgrdcntrlon_id; /* id for source grid center longitude */
int nc_dstgrdcntrlon_id; /* id for dest grid center longitude */
int nc_srcgrdimask_id; /* id for source grid mask */
int nc_dstgrdimask_id; /* id for dest grid mask */
int nc_srcgrdcrnrlat_id = -1; /* id for latitude of source grid corners */
int nc_srcgrdcrnrlon_id = -1; /* id for longitude of source grid corners */
int nc_dstgrdcrnrlat_id = -1; /* id for latitude of dest grid corners */
int nc_dstgrdcrnrlon_id = -1; /* id for longitude of dest grid corners */
int nc_srcgrdarea_id; /* id for area of source grid cells */
int nc_dstgrdarea_id; /* id for area of dest grid cells */
int nc_srcgrdfrac_id; /* id for area fraction on source grid */
int nc_dstgrdfrac_id; /* id for area fraction on dest grid */
int nc_srcadd_id; /* id for map source address */
int nc_dstadd_id; /* id for map destination address */
int nc_rmpmatrix_id; /* id for remapping matrix */
char map_name[1024];
char normalize_opt[64]; /* character string for normalization option */
......@@ -618,16 +579,19 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
remapGridInit(tgt_grid);
// Read dimension information
int nc_srcgrdsize_id;
nce(nc_inq_dimid(nc_file_id, "src_grid_size", &nc_srcgrdsize_id));
nce(nc_inq_dimlen(nc_file_id, nc_srcgrdsize_id, &dimlen));
src_grid.size = dimlen;
// if (src_grid.size != gridInqSize(gridID1)) cdoAbort("Source grids have different size!");
int nc_dstgrdsize_id;
nce(nc_inq_dimid(nc_file_id, "dst_grid_size", &nc_dstgrdsize_id));
nce(nc_inq_dimlen(nc_file_id, nc_dstgrdsize_id, &dimlen));
tgt_grid.size = dimlen;
// if (tgt_grid.size != gridInqSize(gridID2)) cdoAbort("Target grids have different size!");
int nc_srcgrdcorn_id;
status = nc_inq_dimid(nc_file_id, "src_grid_corners", &nc_srcgrdcorn_id);
if (status == NC_NOERR)
{
......@@ -637,6 +601,7 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
src_grid.lneed_cell_corners = true;
}
int nc_dstgrdcorn_id;
status = nc_inq_dimid(nc_file_id, "dst_grid_corners", &nc_dstgrdcorn_id);
if (status == NC_NOERR)
{
......@@ -646,19 +611,23 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
tgt_grid.lneed_cell_corners = true;
}
int nc_srcgrdrank_id;
nce(nc_inq_dimid(nc_file_id, "src_grid_rank", &nc_srcgrdrank_id));
nce(nc_inq_dimlen(nc_file_id, nc_srcgrdrank_id, &dimlen));
src_grid.rank = dimlen;
int nc_dstgrdrank_id;
nce(nc_inq_dimid(nc_file_id, "dst_grid_rank", &nc_dstgrdrank_id));
nce(nc_inq_dimlen(nc_file_id, nc_dstgrdrank_id, &dimlen));
tgt_grid.rank = dimlen;
int nc_numlinks_id;
nce(nc_inq_dimid(nc_file_id, "num_links", &nc_numlinks_id));
nce(nc_inq_dimlen(nc_file_id, nc_numlinks_id, &dimlen));
rv.num_links = dimlen;
// if (rv.num_links == 0) cdoAbort("Number of remap links is 0, no remap weights found!");
int nc_numwgts_id;
nce(nc_inq_dimid(nc_file_id, "num_wgts", &nc_numwgts_id));
nce(nc_inq_dimlen(nc_file_id, nc_numwgts_id, &dimlen));
rv.num_wts = dimlen;
......@@ -688,34 +657,44 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
// Get variable ids
int nc_srcgrddims_id, nc_srcgrdimask_id;
int nc_srcgrdcntrlat_id, nc_srcgrdcntrlon_id;
nce(nc_inq_varid(nc_file_id, "src_grid_dims", &nc_srcgrddims_id));
nce(nc_inq_varid(nc_file_id, "src_grid_imask", &nc_srcgrdimask_id));
nce(nc_inq_varid(nc_file_id, "src_grid_center_lat", &nc_srcgrdcntrlat_id));
nce(nc_inq_varid(nc_file_id, "src_grid_center_lon", &nc_srcgrdcntrlon_id));
int nc_srcgrdcrnrlat_id = -1, nc_srcgrdcrnrlon_id = -1;
if (src_grid.num_cell_corners)
{
nce(nc_inq_varid(nc_file_id, "src_grid_corner_lat", &nc_srcgrdcrnrlat_id));
nce(nc_inq_varid(nc_file_id, "src_grid_corner_lon", &nc_srcgrdcrnrlon_id));
}
int nc_srcgrdarea_id = -1, nc_srcgrdfrac_id;
if (lgridarea) nce(nc_inq_varid(nc_file_id, "src_grid_area", &nc_srcgrdarea_id));
nce(nc_inq_varid(nc_file_id, "src_grid_frac", &nc_srcgrdfrac_id));
int nc_dstgrddims_id, nc_dstgrdimask_id;
int nc_dstgrdcntrlat_id, nc_dstgrdcntrlon_id;
nce(nc_inq_varid(nc_file_id, "dst_grid_dims", &nc_dstgrddims_id));
nce(nc_inq_varid(nc_file_id, "dst_grid_imask", &nc_dstgrdimask_id));
nce(nc_inq_varid(nc_file_id, "dst_grid_center_lat", &nc_dstgrdcntrlat_id));
nce(nc_inq_varid(nc_file_id, "dst_grid_center_lon", &nc_dstgrdcntrlon_id));
int nc_dstgrdcrnrlat_id = -1, nc_dstgrdcrnrlon_id = -1;
if (tgt_grid.num_cell_corners)
{
nce(nc_inq_varid(nc_file_id, "dst_grid_corner_lat", &nc_dstgrdcrnrlat_id));
nce(nc_inq_varid(nc_file_id, "dst_grid_corner_lon", &nc_dstgrdcrnrlon_id));
}
int nc_dstgrdarea_id = -1, nc_dstgrdfrac_id;
if (lgridarea) nce(nc_inq_varid(nc_file_id, "dst_grid_area", &nc_dstgrdarea_id));
nce(nc_inq_varid(nc_file_id, "dst_grid_frac", &nc_dstgrdfrac_id));
int nc_srcadd_id, nc_dstadd_id;
int nc_rmpmatrix_id;
nce(nc_inq_varid(nc_file_id, "src_address", &nc_srcadd_id));
nce(nc_inq_varid(nc_file_id, "dst_address", &nc_dstadd_id));
nce(nc_inq_varid(nc_file_id, "remap_matrix", &nc_rmpmatrix_id));
......
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