WSL/SLF GitLab Repository

Commit e1164d41 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

After compiling with -Weffc++, it appeared that lots of things could be done...

After compiling with -Weffc++, it appeared that lots of things could be done in initialization lists. Some of it has been done for this commit (but quite a few remain).
parent 30803f55
......@@ -139,14 +139,16 @@ template<class T> class Array1D {
bool keep_nodata;
};
template<class T> Array1D<T>::Array1D(const unsigned int& asize) {
keep_nodata = true;
resize(asize);
template<class T> Array1D<T>::Array1D(const unsigned int& asize)
: vecData(asize), nx(asize), keep_nodata(true)
{
//resize(asize);
}
template<class T> Array1D<T>::Array1D(const unsigned int& asize, const T& init) {
keep_nodata = true;
resize(asize, init);
template<class T> Array1D<T>::Array1D(const unsigned int& asize, const T& init)
: vecData(asize, init), nx(asize), keep_nodata(true)
{
//resize(asize, init);
}
template<class T> void Array1D<T>::setKeepNodata(const bool i_keep_nodata) {
......
......@@ -256,17 +256,16 @@ template<class T> Array2DProxy<T> Array2D<T>::operator[](const unsigned int& i)
return Array2DProxy<T>(*this, i);
}
template<class T> Array2D<T>::Array2D() {
nx = ny = 0;
keep_nodata = true;
template<class T> Array2D<T>::Array2D() : vecData(), nx(0), ny(0), keep_nodata(true)
{
}
template<class T> Array2D<T>::~Array2D() { }
template<class T> Array2D<T>::Array2D(const Array2D<T>& i_array2D, const unsigned int& i_nx, const unsigned int& i_ny,
const unsigned int& i_ncols, const unsigned int& i_nrows)
const unsigned int& i_ncols, const unsigned int& i_nrows) :
vecData(i_ncols*i_nrows), nx(i_ncols), ny(i_nrows), keep_nodata(true)
{
keep_nodata = true;
subset(i_array2D, i_nx, i_ny, i_ncols, i_nrows);
}
......@@ -322,16 +321,16 @@ template<class T> void Array2D<T>::fill(const Array2D<T>& i_array2D, const unsig
}
}
template<class T> Array2D<T>::Array2D(const unsigned int& anx, const unsigned int& any, const T& init) {
nx = ny = 0;
keep_nodata = true;
resize(anx,any,init);
template<class T> Array2D<T>::Array2D(const unsigned int& anx, const unsigned int& any, const T& init) :
vecData(anx*any, init), nx(anx), ny(any), keep_nodata(true)
{
//resize(anx,any,init);
}
template<class T> Array2D<T>::Array2D(const unsigned int& anx, const unsigned int& any) {
nx = ny = 0;
keep_nodata = true;
resize(anx,any);
template<class T> Array2D<T>::Array2D(const unsigned int& anx, const unsigned int& any) :
vecData(anx*any), nx(anx), ny(any), keep_nodata(true)
{
//resize(anx,any);
}
template<class T> void Array2D<T>::setKeepNodata(const bool i_keep_nodata) {
......
......@@ -294,16 +294,15 @@ template<class T> Array3DProxy<T> Array3D<T>::operator[](const unsigned int& i)
}
template<class T> Array3D<T>::Array3D() {
nx = ny = nz = nxny = 0;
keep_nodata = true;
template<class T> Array3D<T>::Array3D() : vecData(), nx(0), ny(0), nz(0), nxny(0), keep_nodata(true)
{
}
template<class T> Array3D<T>::Array3D(const Array3D<T>& i_array3D,
const unsigned int& i_nx, const unsigned int& i_ny, const unsigned int& i_nz,
const unsigned int& i_ncols, const unsigned int& i_nrows, const unsigned int& i_ndepth)
: vecData(i_ncols*i_nrows*i_ndepth), nx(i_ncols), ny(i_nrows), nz(i_ndepth), nxny(i_ncols*i_nrows), keep_nodata(true)
{
keep_nodata = true;
subset(i_array3D, i_nx, i_ny, i_nz, i_ncols, i_nrows, i_ndepth);
}
......@@ -372,14 +371,16 @@ template<class T> void Array3D<T>::fill(const Array3D<T>& i_array3D,
}
template<class T> Array3D<T>::Array3D(const unsigned int& anx, const unsigned int& any, const unsigned int& anz) {
resize(anx, any, anz);
keep_nodata = true;
template<class T> Array3D<T>::Array3D(const unsigned int& anx, const unsigned int& any, const unsigned int& anz)
: vecData(anx*any*anz), nx(anx), ny(any), nz(anz), nxny(anx*any), keep_nodata(true)
{
//resize(anx, any, anz);
}
template<class T> Array3D<T>::Array3D(const unsigned int& anx, const unsigned int& any, const unsigned int& anz, const T& init) {
resize(anx, any, anz, init);
keep_nodata = true;
template<class T> Array3D<T>::Array3D(const unsigned int& anx, const unsigned int& any, const unsigned int& anz, const T& init)
: vecData(anx*any*anz, init), nx(anx), ny(any), nz(anz), nxny(anx*any), keep_nodata(true)
{
//resize(anx, any, anz, init);
}
template<class T> void Array3D<T>::setKeepNodata(const bool i_keep_nodata) {
......
......@@ -24,12 +24,12 @@ namespace mio {
const std::string Config::defaultSection = "GENERAL";
//Constructors
Config::Config()
Config::Config() : properties(), sourcename()
{
//nothing is even put in the property map, the user will have to fill it by himself
}
Config::Config(const std::string& i_filename)
Config::Config(const std::string& i_filename) : properties(), sourcename(i_filename)
{
addFile(i_filename);
}
......
......@@ -262,9 +262,16 @@ std::ostream& operator<<(std::ostream &os, const Coords& coord)
* This constructor builds a dummy object that performs no conversions but can be used for comparison
* purpose. This is more or less the equivalent of NULL for a pointer...
*/
Coords::Coords() {
setDefaultValues();
setProj("NULL", "NULL");
Coords::Coords() : ref_latitude(IOUtils::nodata), ref_longitude(IOUtils::nodata),
altitude(IOUtils::nodata), latitude(IOUtils::nodata), longitude(IOUtils::nodata),
easting(IOUtils::nodata), northing(IOUtils::nodata),
grid_i(IOUtils::inodata), grid_j(IOUtils::inodata), grid_k(IOUtils::inodata),
coordsystem("NULL"), coordparam("NULL"),
convToWGS84(&Coords::NULL_to_WGS84), convFromWGS84(&Coords::WGS84_to_NULL), distance_algo(GEO_COSINE)
{
//setDefaultValues();
//setProj("NULL", "NULL");
}
/**
......@@ -274,8 +281,15 @@ Coords::Coords() {
*
* See setProj() for a full description of these strings
*/
Coords::Coords(const std::string& in_coordinatesystem, const std::string& in_parameters) {
setDefaultValues();
Coords::Coords(const std::string& in_coordinatesystem, const std::string& in_parameters) :
ref_latitude(IOUtils::nodata), ref_longitude(IOUtils::nodata),
altitude(IOUtils::nodata), latitude(IOUtils::nodata), longitude(IOUtils::nodata),
easting(IOUtils::nodata), northing(IOUtils::nodata),
grid_i(IOUtils::inodata), grid_j(IOUtils::inodata), grid_k(IOUtils::inodata),
coordsystem(in_coordinatesystem), coordparam(in_parameters),
convToWGS84(&Coords::NULL_to_WGS84), convFromWGS84(&Coords::WGS84_to_NULL), distance_algo(GEO_COSINE)
{
//setDefaultValues();
setProj(in_coordinatesystem, in_parameters);
}
......@@ -286,9 +300,15 @@ Coords::Coords(const std::string& in_coordinatesystem, const std::string& in_par
* @param[in] in_lat_ref latitude of the reference point
* @param[in] in_long_ref longitude of the reference point
*/
Coords::Coords(const double& in_lat_ref, const double& in_long_ref)
Coords::Coords(const double& in_lat_ref, const double& in_long_ref) :
ref_latitude(in_lat_ref), ref_longitude(in_long_ref),
altitude(IOUtils::nodata), latitude(IOUtils::nodata), longitude(IOUtils::nodata),
easting(IOUtils::nodata), northing(IOUtils::nodata),
grid_i(IOUtils::inodata), grid_j(IOUtils::inodata), grid_k(IOUtils::inodata),
coordsystem("LOCAL"), coordparam(""),
convToWGS84(&Coords::local_to_WGS84), convFromWGS84(&Coords::WGS84_to_local), distance_algo(GEO_COSINE)
{
setDefaultValues();
//setDefaultValues();
setLocalRef(in_lat_ref, in_long_ref);
setProj("LOCAL", "");
}
......
......@@ -55,9 +55,10 @@ const double Date::epsilon=1./(24.*3600.); ///< minimum difference between two d
/**
* @brief Default constructor: timezone is set to GMT without DST, julian date is set to 0 (meaning -4713-01-01T12:00)
*/
Date::Date() {
dst = false;
undef = true;
Date::Date() : timezone(0.), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
}
/**
......@@ -66,10 +67,11 @@ Date::Date() {
* @param in_timezone timezone as an offset to GMT (in hours, optional)
* @param in_dst is it DST? (default: no)
*/
Date::Date(const double& julian_in, const double& in_timezone, const bool& in_dst)
Date::Date(const double& julian_in, const double& in_timezone, const bool& in_dst) :
timezone(0.), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
timezone = 0;
dst = false;
setDate(julian_in, in_timezone, in_dst);
}
......@@ -78,8 +80,11 @@ Date::Date(const double& julian_in, const double& in_timezone, const bool& in_ds
* @param in_time unix time (ie: as number of seconds since Unix Epoch, always UTC)
* @param in_dst is it DST? (default: no)
*/
Date::Date(const time_t& in_time, const bool& in_dst) {
dst = false;
Date::Date(const time_t& in_time, const bool& in_dst) :
timezone(in_dst), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
setDate(in_time, in_dst);
}
......@@ -94,10 +99,11 @@ Date::Date(const time_t& in_time, const bool& in_dst) {
* @param in_timezone timezone as an offset to GMT (in hours, optional)
* @param in_dst is it DST? (default: no)
*/
Date::Date(const int& in_year, const int& in_month, const int& in_day, const int& in_hour, const int& in_minute, const double& in_timezone, const bool& in_dst)
Date::Date(const int& in_year, const int& in_month, const int& in_day, const int& in_hour, const int& in_minute, const double& in_timezone, const bool& in_dst) :
timezone(in_timezone), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
timezone = 0;
dst = false;
setDate(in_year, in_month, in_day, in_hour, in_minute, in_timezone, in_dst);
}
......
......@@ -37,42 +37,39 @@ Grid2DObject& Grid2DObject::operator=(const Grid2DObject& source) {
* Default constructor.
* grid2D attribute is initialized by Array2D default constructor.
*/
Grid2DObject::Grid2DObject() : grid2D()
Grid2DObject::Grid2DObject() : grid2D(), ncols(0), nrows(0), cellsize(0), llcorner()
{
ncols = 0;
nrows = 0;
cellsize = 0.0;
}
Grid2DObject::Grid2DObject(const unsigned int& i_ncols, const unsigned int& i_nrows,
const double& i_cellsize, const Coords& i_llcorner) : grid2D(i_ncols, i_nrows, IOUtils::nodata)
const double& i_cellsize, const Coords& i_llcorner) : grid2D(i_ncols, i_nrows, IOUtils::nodata), ncols(i_ncols), nrows(i_nrows), cellsize(i_cellsize), llcorner(i_llcorner)
{
//set metadata, grid2D already successfully created
setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
//setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
}
Grid2DObject::Grid2DObject(const unsigned int& i_ncols, const unsigned int& i_nrows,
const double& i_cellsize, const Coords& i_llcorner, const Array2D<double>& i_grid2D) : grid2D()
const double& i_cellsize, const Coords& i_llcorner, const Array2D<double>& i_grid2D) : grid2D(i_grid2D), ncols(i_ncols), nrows(i_nrows), cellsize(i_cellsize), llcorner(i_llcorner)
{
set(i_ncols, i_nrows, i_cellsize, i_llcorner, i_grid2D);
//set(i_ncols, i_nrows, i_cellsize, i_llcorner, i_grid2D);
}
Grid2DObject::Grid2DObject(const unsigned int& i_ncols, const unsigned int& i_nrows,
const double& i_cellsize, const Coords& i_llcorner, const double& init) : grid2D(i_ncols, i_nrows, init)
const double& i_cellsize, const Coords& i_llcorner, const double& init) : grid2D(i_ncols, i_nrows, init), ncols(i_ncols), nrows(i_nrows), cellsize(i_cellsize), llcorner(i_llcorner)
{
//set metadata, grid2D already successfully created
setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
//setValues(i_ncols, i_nrows, i_cellsize, i_llcorner);
}
Grid2DObject::Grid2DObject(const Grid2DObject& i_grid2Dobj, const unsigned int& i_nx, const unsigned int& i_ny,
const unsigned int& i_ncols, const unsigned int& i_nrows)
: grid2D(i_grid2Dobj.grid2D, i_nx,i_ny, i_ncols,i_nrows)
: grid2D(i_grid2Dobj.grid2D, i_nx,i_ny, i_ncols,i_nrows), ncols(i_ncols), nrows(i_nrows), cellsize(i_grid2Dobj.cellsize), llcorner(i_grid2Dobj.llcorner)
{
setValues(i_ncols, i_nrows, i_grid2Dobj.cellsize);
//setValues(i_ncols, i_nrows, i_grid2Dobj.cellsize);
//we take the previous corner (so we use the same projection parameters)
//and we shift it by the correct X and Y distance
llcorner = i_grid2Dobj.llcorner;
//llcorner = i_grid2Dobj.llcorner;
if( (llcorner.getEasting()!=IOUtils::nodata) && (llcorner.getNorthing()!=IOUtils::nodata) ) {
llcorner.setXY( llcorner.getEasting()+i_nx*i_grid2Dobj.cellsize,
llcorner.getNorthing()+i_ny*i_grid2Dobj.cellsize, IOUtils::nodata);
......
......@@ -29,7 +29,7 @@ namespace mio {
#ifdef _POPC_
IOException::IOException(const std::string& message, const std::string& position) : POPException(STD_EXCEPTION)
#else
IOException::IOException(const std::string& message, const std::string& position)
IOException::IOException(const std::string& message, const std::string& position) : msg()
#endif
{
if (position=="") {
......
......@@ -23,10 +23,12 @@ using namespace std;
namespace mio {
IOManager::IOManager(const Config& i_cfg) : cfg(i_cfg), rawio(cfg), bufferedio(rawio, cfg),
meteoprocessor(cfg), interpolator(cfg)
meteoprocessor(cfg), interpolator(cfg),
proc_properties(), point_cache(), filtered_cache(),
fcache_start(Date(0.0, 0.)), fcache_end(Date(0.0, 0.)), //this should not matter, since 0 is still way back before any real data...
processing_level(IOManager::filtered | IOManager::resampled)
{
setProcessingLevel(IOManager::filtered | IOManager::resampled);
fcache_start = fcache_end = Date(0.0, 0.); //this should not matter, since 0 is still way back before any real data...
//setProcessingLevel(IOManager::filtered | IOManager::resampled);
meteoprocessor.getWindowSize(proc_properties);
interpolator.setIOManager(*this); //because "*this" does not necessarily exist in the initialization list...
}
......
......@@ -96,15 +96,25 @@ InterpolationAlgorithm* AlgorithmFactory::getAlgorithm(const std::string& i_algo
}
}
MeteoData::Parameters param; ///<the parameter that we will interpolate
std::vector<MeteoData> vecMeteo;
std::vector<double> vecData; ///<store the measurement for the given parameter
std::vector<StationData> vecMeta; ///<store the station data for the given parameter
std::stringstream info; ///<to store some extra information about the interoplation process
size_t nrOfMeasurments; ///<the available number of measurements
InterpolationAlgorithm::InterpolationAlgorithm(Meteo2DInterpolator& i_mi,
const Date& i_date,
const DEMObject& i_dem,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: mi(i_mi), date(i_date), dem(i_dem), vecArgs(i_vecArgs), algo(i_algo), iomanager(iom)
: mi(i_mi), date(i_date), dem(i_dem), vecArgs(i_vecArgs), algo(i_algo), iomanager(iom),
param(MeteoData::firstparam), vecMeteo(), vecData(), vecMeta(), info(), nrOfMeasurments(0)
{
nrOfMeasurments = 0;
param = MeteoData::firstparam; //this is a stupid default value, but since we never check it...
//the default value for param is quite stupid, but since we never check it...
iomanager.getMeteoData(date, vecMeteo);
}
......
......@@ -325,7 +325,7 @@ class RHAlgorithm : public InterpolationAlgorithm {
const DEMObject& i_dem,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom) {}
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom), vecDataTA(), vecDataRH() {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -349,7 +349,7 @@ class ILWRAlgorithm : public InterpolationAlgorithm {
const DEMObject& i_dem,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom) {}
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom), vecDataEA() {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -373,7 +373,7 @@ class SimpleWindInterpolationAlgorithm : public InterpolationAlgorithm {
const DEMObject& i_dem,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom) {}
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom), vecDataVW(), vecDataDW() {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -475,7 +475,7 @@ class OrdinaryKrigingAlgorithm : public InterpolationAlgorithm {
const DEMObject& i_dem,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom) {}
: InterpolationAlgorithm(i_mi, i_date, i_dem, i_vecArgs, i_algo, iom), variogram() {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......
......@@ -21,7 +21,11 @@ using namespace std;
namespace mio {
Meteo1DInterpolator::Meteo1DInterpolator(const Config& in_cfg) : cfg(in_cfg) {
Meteo1DInterpolator::Meteo1DInterpolator(const Config& in_cfg)
: cfg(in_cfg), window_size(10.*86400.),
tasklist(), taskargs(), extended_tasklist()
{
//default window_size is 10 julian days
/*
* By reading the Config object build up a list of user configured resampling algorithm
* for each MeteoData::Parameters parameter (i.e. each member variable like ta, p, hnw, ...)
......@@ -38,7 +42,6 @@ Meteo1DInterpolator::Meteo1DInterpolator(const Config& in_cfg) : cfg(in_cfg) {
taskargs.push_back(vecResamplingArguments);
}
window_size = 10.*86400.; //default size is 10 julian days
cfg.getValue("WINDOW_SIZE", "Interpolations1D", window_size, Config::nothrow);
window_size /= 86400; //user uses seconds, internally julian day is used
if (window_size <= 0.01)
......
......@@ -22,15 +22,13 @@ using namespace std;
namespace mio {
Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg, IOManager& i_iom) : cfg(i_cfg)
Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg, IOManager& i_iom) : cfg(i_cfg), iomanager(&i_iom), mapAlgorithms()
{
iomanager = &i_iom;
setAlgorithms();
}
Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg) : cfg(i_cfg)
Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg) : cfg(i_cfg), iomanager(NULL), mapAlgorithms()
{
iomanager = NULL;
setAlgorithms();
}
......
......@@ -21,7 +21,7 @@ using namespace std;
namespace mio {
MeteoProcessor::MeteoProcessor(const Config& cfg) : mi1d(cfg)
MeteoProcessor::MeteoProcessor(const Config& cfg) : mi1d(cfg), processing_stack()
{
//Parse [Filters] section, create processing stack for each configured parameter
set<string> set_of_used_parameters;
......
......@@ -36,10 +36,8 @@ namespace mio {
* @brief Default constructor.
* Initialize internal variables. It does NOT start timing.
*/
Timer::Timer() {
isRunning=false;
start_point=0;
elapsed=0;
Timer::Timer() : start_point(0.), elapsed(0.), isRunning(false)
{
}
/**
......
......@@ -82,10 +82,6 @@ const unsigned int FitLeastSquare::max_iter = 50; //maximum number of iterations
//default constructor
FitLeastSquare::FitLeastSquare() {
fit_ready = false;
nParam = 0;
min_nb_pts = 0;
regname = "none";
}
void FitLeastSquare::setData(const std::vector<double>& in_X, const std::vector<double>& in_Y) {
......
......@@ -29,7 +29,7 @@ namespace mio {
//purely virtual class to use as an interface
class FitModel {
public:
FitModel() {};
FitModel() : Lambda(), X(), Y(), infoString(), regname(), nPts(0), nParam(0), min_nb_pts(0), fit_ready(false) {};
FitModel(const FitModel& source);
virtual ~FitModel() {};
virtual void setData(const std::vector<double>& in_X, const std::vector<double>& in_Y) = 0;
......
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