Commit 5888c8fb authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added Remapweights.cc.

parent 7be244c5
......@@ -339,6 +339,7 @@ cdo_SOURCES += Adisit.cc \
Recttocomplex.cc \
Regres.cc \
Remap.cc \
Remapweights.cc \
Remapeta.cc \
Replace.cc \
Replacevalues.cc \
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2019 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_LIBNETCDF
#include "netcdf.h"
#endif
#include "cdo_int.h"
#ifdef HAVE_LIBNETCDF
static void
nce(int istat)
{
// This routine provides a simple interface to NetCDF error message routine.
if (istat != NC_NOERR) cdoAbort(nc_strerror(istat));
}
static
void verifyWeights(const char *weights_file)
{
// int nc_file_id = cdf_openread(weights_file);
// nce(nc_close(nc_file_id));
//remapReadDataScrip(weights_file, gridID1, gridID2, &mapType, &submapType, &numNeighbors, remapOrder, remaps[0].src_grid,
// remaps[0].tgt_grid, remaps[0].vars);
}
#endif
void *
Remapweights(void *argument)
{
cdoInitialize(argument);
#ifdef HAVE_LIBNETCDF
int VERIFYWEIGHTS = cdoOperatorAdd("verifyweights", 0, 0, nullptr);
int operatorID = cdoOperatorID();
const char *weights_file = cdoGetStreamName(0);
if (operatorID == VERIFYWEIGHTS) verifyWeights(weights_file);
#else
cdoAbort("NetCDF support not compiled in!");
#endif
cdoFinish();
return nullptr;
}
......@@ -1505,6 +1505,7 @@ void init_modules()
add_module("Remapcon2" , {Remap , Remapcon2Help , Remapcon2Operators , 1 , CDI_REAL , 1 , 1 });
add_module("Remaplaf" , {Remap , RemaplafHelp , RemaplafOperators , 1 , CDI_REAL , 1 , 1 });
add_module("Remapgrid" , {Remap , {} , RemapgridOperators , 1 , CDI_REAL , 1 , 1 });
add_module("Remapweights" , {Remapweights , {} , RemapweightsOperators , 1 , CDI_REAL , 1 , 0 });
add_module("Remapeta" , {Remapeta , RemapetaHelp , RemapetaOperators , 1 , CDI_REAL , 1 , 1 });
add_module("Replace" , {Replace , ReplaceHelp , ReplaceOperators , 1 , CDI_REAL , 2 , 1 });
add_module("Replacevalues" , {Replacevalues , ReplacevaluesHelp , ReplacevaluesOperators , 1 , CDI_REAL , 1 , 1 });
......
......@@ -60,7 +60,6 @@ gridFromNCfile(const char *gridfile)
{
int gridID = -1;
#ifdef HAVE_LIBNETCDF
int nc_file_id; /* NetCDF grid file id */
int nc_gridsize_id; /* NetCDF grid size dim id */
int nc_gridcorn_id; /* NetCDF grid corner dim id */
int nc_gridrank_id; /* NetCDF grid rank dim id */
......@@ -77,9 +76,9 @@ gridFromNCfile(const char *gridfile)
int grid_dims[2];
GridDesciption grid;
/* open grid file and read grid size/name data */
// open grid file and read grid size/name data
nc_file_id = cdf_openread(gridfile);
int nc_file_id = cdf_openread(gridfile);
if (nc_inq_dimid(nc_file_id, "grid_size", &nc_gridsize_id) == NC_NOERR
&& nc_inq_dimid(nc_file_id, "grid_rank", &nc_gridrank_id) == NC_NOERR
......
......@@ -120,6 +120,7 @@ void *Pressure(void *argument);
void *Recttocomplex(void *argument);
void *Regres(void *argument);
void *Remap(void *argument);
void *Remapweights(void *argument);
void *Remapeta(void *argument);
void *Replace(void *argument);
void *Replacevalues(void *argument);
......
......@@ -135,7 +135,8 @@
#define RemapsconOperators {"remapscon", "genscon"}
#define Remapcon2Operators {"remapcon2", "gencon2"}
#define RemaplafOperators {"remaplaf", "genlaf"}
#define RemapgridOperators {"remapsum"}
#define RemapgridOperators {"remapsum"}
#define RemapweightsOperators {"verifyweights"}
#define RemapetaOperators {"remapeta", "remapeta_s", "remapeta_z"}
#define ReplaceOperators {"replace"}
#define ReplacevaluesOperators {"setvals", "setrtoc", "setrtoc2"}
......
......@@ -82,12 +82,10 @@ void
remapWriteDataScrip(const char *interp_file, RemapMethod mapType, SubmapType submapType, int numNeighbors, int remapOrder,
RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &rv)
{
// Writes remap data to a NetCDF file using SCRIP conventions
// Writes remap data to a NetCDF file using SCRIP conventions
#ifdef HAVE_LIBNETCDF
// Local variables
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 */
......@@ -499,12 +497,10 @@ void
remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMethod *mapType, SubmapType *submapType,
int *numNeighbors, int &remapOrder, RemapGrid &src_grid, RemapGrid &tgt_grid, RemapVars &rv)
{
// The routine reads a NetCDF file to extract remapping info in SCRIP format
// The routine reads a NetCDF file to extract remapping info in SCRIP format
#ifdef HAVE_LIBNETCDF
// Local variables
bool lgridarea = false;
int status;
int nc_srcgrdsize_id; /* id for source grid size */
......@@ -707,30 +703,28 @@ remapReadDataScrip(const char *interp_file, int gridID1, int gridID2, RemapMetho
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));
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));
}
if (lgridarea)
{
nce(nc_inq_varid(nc_file_id, "src_grid_area", &nc_srcgrdarea_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));
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));
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));
}
if (lgridarea)
{
nce(nc_inq_varid(nc_file_id, "dst_grid_area", &nc_dstgrdarea_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));
nce(nc_inq_varid(nc_file_id, "src_address", &nc_srcadd_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