WSL/SLF GitLab Repository

Commit 5cfb7b0e authored by Mathias Bavay's avatar Mathias Bavay
Browse files

A few extra checks have been added for grid rescaling. Some indentation has...

A few extra checks have been added for grid rescaling. Some indentation has been fixed and lots of variables made const. The documentation is now linked to the general plugins documentation.
parent aa993ae2
......@@ -114,6 +114,7 @@ namespace mio {
* <tr><td>\subpage gribio "GRIB"</td><td>meteo, dem, grid2d</td><td>GRIB meteo grid files</td><td><A HREF="http://www.ecmwf.int/products/data/software/grib_api.html">grib-api</A></td></tr>
* <tr><td>\subpage gsn "GSN"</td><td>meteo</td><td>connects to the Global Sensor Network web service interface</td><td><A HREF="http://curl.haxx.se/libcurl/">libcurl</A></td></tr>
* <tr><td>\subpage imis "IMIS"</td><td>meteo</td><td>connects to the IMIS database</td><td><A HREF="http://docs.oracle.com/cd/B12037_01/appdev.101/b10778/introduction.htm">Oracle's OCCI library</A></td></tr>
* <tr><td>\subpage netcdf "NETCDF"</td><td>meteo, dem, grid2d</td><td>NetCDF grids and meteorological timeseries</td><td><A HREF="http://www.unidata.ucar.edu/downloads/netcdf/index.jsp">NetCDF-C library</A></td></tr>
* <tr><td>\subpage pgmio "PGM"</td><td>dem, grid2d</td><td>PGM grid files</td><td></td></tr>
* <tr><td>\subpage pngio "PNG"</td><td>dem, grid2d</td><td>PNG grid files</td><td><A HREF="http://www.libpng.org/pub/png/libpng.html">libpng</A></td></tr>
* <tr><td>\subpage psqlio "PSQL"</td><td>meteo</td><td>connects to PostgreSQL database</td><td><A HREF="http://www.postgresql.org/">PostgreSQL</A>'s libpq</td></tr>
......
......@@ -19,6 +19,7 @@
#include <meteoio/MathOptim.h>
#include <meteoio/ResamplingAlgorithms2D.h>
#include <cmath>
#include <sstream>
using namespace std;
......@@ -29,6 +30,11 @@ namespace mio {
*/
const Grid2DObject ResamplingAlgorithms2D::BilinearResampling(const Grid2DObject &i_grid, const double &factor)
{
if (factor<=0) {
ostringstream ss;
ss << "Rescaling factor " << factor << " is invalid!";
throw InvalidArgumentException(ss.str(), AT);
}
const double cellsize = i_grid.cellsize/factor;
const size_t ncols = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.ncols)*factor ));
const size_t nrows = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.nrows)*factor ));
......@@ -40,6 +46,11 @@ const Grid2DObject ResamplingAlgorithms2D::BilinearResampling(const Grid2DObject
const Grid2DObject ResamplingAlgorithms2D::cubicBSplineResampling(const Grid2DObject &i_grid, const double &factor)
{
if (factor<=0) {
ostringstream ss;
ss << "Rescaling factor " << factor << " is invalid!";
throw InvalidArgumentException(ss.str(), AT);
}
const double cellsize = i_grid.cellsize/factor;
const size_t ncols = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.ncols)*factor ));
const size_t nrows = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.nrows)*factor ));
......@@ -51,6 +62,11 @@ const Grid2DObject ResamplingAlgorithms2D::cubicBSplineResampling(const Grid2DOb
const Grid2DObject ResamplingAlgorithms2D::NearestNeighbour(const Grid2DObject &i_grid, const double &factor)
{
if (factor<=0) {
ostringstream ss;
ss << "Rescaling factor " << factor << " is invalid!";
throw InvalidArgumentException(ss.str(), AT);
}
const double cellsize = i_grid.cellsize/factor;
const size_t ncols = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.ncols)*factor ));
const size_t nrows = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.nrows)*factor ));
......@@ -61,6 +77,11 @@ const Grid2DObject ResamplingAlgorithms2D::NearestNeighbour(const Grid2DObject &
}
const Array2D<double> ResamplingAlgorithms2D::NearestNeighbour(const Array2D<double> &i_grid, const double &factor_x, const double &factor_y) {
if (factor_x<=0 || factor_y<=0) {
ostringstream ss;
ss << "Rescaling factors (" << factor_x << "," << factor_y << ") are invalid!";
throw InvalidArgumentException(ss.str(), AT);
}
const size_t nx = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.getNx())*factor_x ));
const size_t ny = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.getNy())*factor_y ));
Array2D<double> o_grid(nx, ny);
......@@ -70,15 +91,24 @@ const Array2D<double> ResamplingAlgorithms2D::NearestNeighbour(const Array2D<dou
}
const Array2D<double> ResamplingAlgorithms2D::BilinearResampling(const Array2D<double> &i_grid, const double &factor_x, const double &factor_y) {
if (factor_x<=0 || factor_y<=0) {
ostringstream ss;
ss << "Rescaling factors (" << factor_x << "," << factor_y << ") are invalid!";
throw InvalidArgumentException(ss.str(), AT);
}
const size_t nx = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.getNx())*factor_x ));
const size_t ny = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.getNy())*factor_y ));
Array2D<double> o_grid(nx, ny);
Bilinear(o_grid, i_grid);
return o_grid;
}
const Array2D<double> ResamplingAlgorithms2D::cubicBSplineResampling(const Array2D<double> &i_grid, const double &factor_x, const double &factor_y) {
if (factor_x<=0 || factor_y<=0) {
ostringstream ss;
ss << "Rescaling factors (" << factor_x << "," << factor_y << ") are invalid!";
throw InvalidArgumentException(ss.str(), AT);
}
const size_t nx = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.getNx())*factor_x ));
const size_t ny = static_cast<size_t>(Optim::round( static_cast<double>(i_grid.getNy())*factor_y ));
Array2D<double> o_grid(nx, ny);
......
This diff is collapsed.
Supports Markdown
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