WSL/SLF GitLab Repository

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

Fixed a warning with XCode 4.3 on osX. Tried to make a more standard use of...

Fixed a warning with XCode 4.3 on osX. Tried to make a more standard use of c++ (relying on std::fill for filling vectors, relying on vector.resize(sixe, value) instead of manually initializing a vector, etc). A few more const added where appropriate. It makes the benchmarks slightly faster...
parent bf2860e3
......@@ -37,7 +37,10 @@ ELSE(MSVC)
#we consider that all other compilers support "-" options and silently ignore what they don't know
SET(WARNINGS "-Wall")
SET(PROFILING "-pg -fprofile-arcs")
SET(EXTRA_WARNINGS "-Wextra -ansi -pedantic")
SET(EXTRA_WARNINGS "-Wextra -pedantic")
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(EXTRA_WARNINGS "${EXTRA_WARNINGS} -ansi")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
SET(OPTIM "-g -O3 -DNDEBUG -DNOSAFECHECKS")
EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
IF (GCC_VERSION VERSION_GREATER 4.2 OR GCC_VERSION VERSION_EQUAL 4.2)
......
......@@ -165,8 +165,8 @@ template<class T> void Array<T>::resize(const unsigned int& asize) {
}
template<class T> void Array<T>::resize(const unsigned int& asize, const T& init) {
resize(asize);
std::fill(vecData.begin(), vecData.end(), init);
vecData.resize(asize, init);
nx = asize;
}
......
......@@ -350,8 +350,9 @@ template<class T> void Array2D<T>::resize(const unsigned int& anx, const unsigne
}
template<class T> void Array2D<T>::resize(const unsigned int& anx, const unsigned int& any, const T& init) {
resize(anx, any);
std::fill(vecData.begin(), vecData.end(), init);
vecData.resize(anx*any, init);
nx = anx;
ny = any;
}
template<class T> void Array2D<T>::size(unsigned int& anx, unsigned int& any) const {
......@@ -509,8 +510,8 @@ template<class T> Array2D<T>& Array2D<T>::operator=(const Array2D<T>& source) {
}
template<class T> Array2D<T>& Array2D<T>::operator=(const T& value) {
//std::fill(vecData.begin(), vecData.end(), value);
for(unsigned int i=0; i<vecData.size(); i++) vecData[i] = value;
std::fill(vecData.begin(), vecData.end(), value);
//for(unsigned int i=0; i<vecData.size(); i++) vecData[i] = value;
return *this;
}
......
......@@ -400,8 +400,11 @@ template<class T> void Array3D<T>::resize(const unsigned int& anx, const unsigne
}
template<class T> void Array3D<T>::resize(const unsigned int& anx, const unsigned int& any, const unsigned int& anz, const T& init) {
resize(anx, any, anz);
std::fill(vecData.begin(), vecData.end(), init);
vecData.resize(anx*any*anz, init);
nx = anx;
ny = any;
nz = anz;
nxny = nx*ny;
}
template<class T> void Array3D<T>::size(unsigned int& anx, unsigned int& any, unsigned int& anz) const {
......
......@@ -65,7 +65,8 @@ 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;
dst = false;
setDate(julian_in, in_timezone, in_dst);
......
......@@ -91,28 +91,27 @@ double IOUtils::angle_to_bearing(const double& angle) {
return (fmod( 90.-angle*Cst::to_deg+360. , 360. ));
}
double IOUtils::bearing(const std::string& bearing_str)
double IOUtils::bearing(std::string bearing_str)
{
std::string s=bearing_str;
trim(s);
toUpper(s);
if(s=="N") return 0.;
if(s=="NNE") return 22.5;
if(s=="NE") return 45.;
if(s=="ENE") return 67.5;
if(s=="E") return 90.;
if(s=="ESE") return 112.5;
if(s=="SE") return 135.;
if(s=="SSE") return 157.5;
if(s=="S") return 180.;
if(s=="SSW") return 202.5;
if(s=="SW") return 225.;
if(s=="WSW") return 247.5;
if(s=="W") return 270.;
if(s=="WNW") return 292.5;
if(s=="NW") return 315.;
if(s=="NNW") return 337.5;
trim(bearing_str);
toUpper(bearing_str);
if(bearing_str=="N") return 0.;
if(bearing_str=="NNE") return 22.5;
if(bearing_str=="NE") return 45.;
if(bearing_str=="ENE") return 67.5;
if(bearing_str=="E") return 90.;
if(bearing_str=="ESE") return 112.5;
if(bearing_str=="SE") return 135.;
if(bearing_str=="SSE") return 157.5;
if(bearing_str=="S") return 180.;
if(bearing_str=="SSW") return 202.5;
if(bearing_str=="SW") return 225.;
if(bearing_str=="WSW") return 247.5;
if(bearing_str=="W") return 270.;
if(bearing_str=="WNW") return 292.5;
if(bearing_str=="NW") return 315.;
if(bearing_str=="NNW") return 337.5;
//no match
return nodata;
......@@ -120,7 +119,7 @@ double IOUtils::bearing(const std::string& bearing_str)
void IOUtils::stripComments(std::string& str)
{
size_t found = str.find_first_of("#;");
const size_t found = str.find_first_of("#;");
if (found != std::string::npos){
str.erase(found); //rest of line disregarded
}
......@@ -203,11 +202,10 @@ void IOUtils::toLower(std::string& str){
std::transform(str.begin(), str.end(),str.begin(), ::tolower);
}
bool IOUtils::isNumeric(const std::string& str, const unsigned int& nBase)
bool IOUtils::isNumeric(std::string str, const unsigned int& nBase)
{
std::string s = str;
trim(s); //delete trailing and leading whitespaces and tabs
std::istringstream iss(s);
trim(str); //delete trailing and leading whitespaces and tabs
std::istringstream iss(str);
if( nBase == 10 ) {
double tmp;
......@@ -227,8 +225,6 @@ bool IOUtils::isNumeric(const std::string& str, const unsigned int& nBase)
bool IOUtils::readKeyValuePair(const std::string& in_line, const std::string& delimiter,
std::map<std::string,std::string>& out_map, const std::string& keyprefix, const bool& setToUpperCase)
{
//size_t pos = in_line.find(delimiter); //first occurence of '='
size_t pos = std::string::npos;
if ((delimiter==" ") || (delimiter=="\t")) {
pos = in_line.find_first_of(" \t", 0);
......@@ -243,7 +239,6 @@ bool IOUtils::readKeyValuePair(const std::string& in_line, const std::string& de
IOUtils::trim(key);
IOUtils::trim(value);
//cerr << "key:" << key << " val:" << value << endl;
if ((key == "") || (value=="")) {
return false;
......@@ -256,7 +251,6 @@ bool IOUtils::readKeyValuePair(const std::string& in_line, const std::string& de
out_map[keyprefix + key] = value;
} else {
return false;
//cerr << "line:" << in_line << "delimiter" << endl;
}
return true;
......@@ -299,7 +293,7 @@ void IOUtils::readDirectory(const std::string& path, std::list<std::string>& dir
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
//this is a directory -> do nothing
} else {
std::string filename(ffd.cFileName);
const std::string filename(ffd.cFileName);
dirlist.push_back(filename);
}
}
......@@ -375,12 +369,12 @@ void IOUtils::readKeyValueHeader(std::map<std::string,std::string>& headermap,
std::string line="";
//make a test for end of line encoding:
char eol = IOUtils::getEoln(fin);
const char eol = IOUtils::getEoln(fin);
for (size_t ii=0; ii< linecount; ii++){
if (std::getline(fin, line, eol)) {
linenr++;
bool result = IOUtils::readKeyValuePair(line, delimiter, headermap);
const bool result = IOUtils::readKeyValuePair(line, delimiter, headermap);
if (!result) { // means if ((key == "") || (value==""))
std::stringstream out;
......@@ -399,7 +393,7 @@ char IOUtils::getEoln(std::istream& fin)
char tmp = '0';
int chars = 0;
const std::streampos position = fin.tellg();
const std::streampos file_start = fin.tellg();
do {
fin.get(tmp);
......@@ -413,14 +407,14 @@ char IOUtils::getEoln(std::istream& fin)
chars++;
}
pbuf = fin.rdbuf();
pbuf->pubseekpos(position); //rewind
pbuf->pubseekpos(file_start); //rewind
fin.clear(); //reset eof flag, etc
return tmp;
}
} while ((chars < 3000) && (!fin.eof()));
pbuf = fin.rdbuf();
pbuf->pubseekpos(position); //rewind
pbuf->pubseekpos(file_start); //rewind
fin.clear(); //reset eof flag, etc
return '\n';
......@@ -523,7 +517,7 @@ template<> bool IOUtils::convertString<bool>(bool& t, const std::string& str, st
t = (i != 0);
}
std::string::size_type pos = s.find_first_not_of(ALPHANUM);
const std::string::size_type pos = s.find_first_not_of(ALPHANUM);
if (pos != std::string::npos) {
std::string tmp = s.substr(pos);
trim(tmp);
......@@ -637,7 +631,7 @@ template<> bool IOUtils::convertString<Coords>(Coords& t, const std::string& str
(void)f;
double lat, lon;
try {
Coords::parseLatLon(s,lat, lon);
Coords::parseLatLon(s, lat, lon);
} catch(const IOException&) {
return false;
}
......@@ -683,13 +677,12 @@ size_t IOUtils::seek(const Date& soughtdate, const std::vector<MeteoData>& vecM,
}
//if we reach this point: the date is spanned by the buffer and there are at least two elements
//HACK: would it be better to create a timeseries object and call vector's binary search on it?
if (exactmatch){
size_t first = 1, last = vecM.size()-1;
//perform binary search
while (first <= last) {
size_t mid = (first + last) / 2; // compute mid point
const size_t mid = (first + last) / 2; // compute mid point
if (soughtdate > vecM[mid].date)
first = mid + 1; // repeat search in top half
else if (soughtdate < vecM[mid].date)
......@@ -702,7 +695,7 @@ size_t IOUtils::seek(const Date& soughtdate, const std::vector<MeteoData>& vecM,
//perform binary search
while (first <= last) {
size_t mid = (first + last) / 2; // compute mid point
const size_t mid = (first + last) / 2; // compute mid point
if (mid < (vecM.size()-1))
if ((soughtdate > vecM[mid].date) && (soughtdate < vecM[mid+1].date))
......
......@@ -119,7 +119,7 @@ namespace IOUtils {
* @param bearing_str as N, NE, SSW, etc
* @return bearing (0° on top, clockwise, in [0°, 360°[)
*/
double bearing(const std::string& bearing_str);
double bearing(std::string bearing_str);
/**
* @brief Build a list of file in a given directory.
......@@ -194,7 +194,7 @@ namespace IOUtils {
void toUpper(std::string& str);
void toLower(std::string& str);
bool isNumeric(const std::string& input, const unsigned int& nBase=10);
bool isNumeric(std::string input, const unsigned int& nBase=10);
size_t readLineToVec(const std::string& line_in, std::vector<double>& vec_data);
size_t readLineToVec(const std::string& line_in, std::vector<std::string>& vecString);
size_t readLineToVec(const std::string& line_in, std::vector<std::string>& vecString, const char& delim);
......
......@@ -129,7 +129,7 @@ const std::string& MeteoData::getNameForParameter(const size_t& parindex) const
bool MeteoData::param_exists(const std::string& i_paramname) const
{
size_t current_size = param_name.size();
const size_t current_size = param_name.size();
for (size_t ii = 0; ii<current_size; ii++) {
if (param_name[ii] == i_paramname)
return true;
......@@ -141,7 +141,7 @@ bool MeteoData::param_exists(const std::string& i_paramname) const
size_t MeteoData::addParameter(const std::string& i_paramname)
{
//check if name is already taken
size_t current_index = getParameterIndex(i_paramname);
const size_t current_index = getParameterIndex(i_paramname);
if (current_index != IOUtils::npos)
return current_index; //do nothing, because parameter is already present
......@@ -160,16 +160,16 @@ size_t MeteoData::getNrOfParameters() const
return nrOfAllParameters;
}
MeteoData::MeteoData() : date(0.0, 0.), meta(), nrOfAllParameters(MeteoData::nrOfParameters), resampled(false)
MeteoData::MeteoData() : date(0.0, 0.), meta(), resampled(false), nrOfAllParameters(MeteoData::nrOfParameters), param_name(s_default_paramname), data(nrOfAllParameters, IOUtils::nodata)
{
param_name = s_default_paramname;
data = vector<double>(nrOfAllParameters, IOUtils::nodata);
/*param_name = s_default_paramname;
data.resize(nrOfAllParameters, IOUtils::nodata);*/
}
MeteoData::MeteoData(const Date& date_in) : date(date_in), meta(), nrOfAllParameters(MeteoData::nrOfParameters), resampled(false)
MeteoData::MeteoData(const Date& date_in) : date(date_in), meta(), resampled(false), nrOfAllParameters(MeteoData::nrOfParameters), param_name(s_default_paramname), data(nrOfAllParameters, IOUtils::nodata)
{
param_name = s_default_paramname;
data = vector<double>(nrOfAllParameters, IOUtils::nodata);
/*param_name = s_default_paramname;
data.resize(nrOfAllParameters, IOUtils::nodata);*/
}
void MeteoData::setDate(const Date& in_date)
......@@ -179,9 +179,7 @@ void MeteoData::setDate(const Date& in_date)
void MeteoData::reset()
{
for (size_t ii=0; ii<nrOfAllParameters; ii++) {
data[ii] = IOUtils::nodata;
}
std::fill(data.begin(), data.end(), IOUtils::nodata);
}
/**
......
......@@ -184,11 +184,11 @@ class MeteoData {
static const bool __init; ///<helper variable to enable the init of static collection data
static bool initStaticData();///<initialize the static map meteoparamname
//private data members
//private data members, please keep the order consistent with declaration lists and logic!
bool resampled; ///<set this to true if MeteoData is result of resampling
size_t nrOfAllParameters;
std::vector<std::string> param_name;
std::vector<double> data;
size_t nrOfAllParameters;
bool resampled; ///<set this to true if MeteoData is result of resampling
};
typedef std::vector<MeteoData> METEO_TIMESERIE;
......
......@@ -26,10 +26,10 @@ namespace mio {
StationData::StationData() : position("NULL", "NULL"), stationID(""), stationName(""),
slope(IOUtils::nodata), azi(IOUtils::nodata) {}
StationData::StationData(const Coords& i_position, const std::string& i_id, const std::string& i_name)
StationData::StationData(const Coords& i_position, const std::string& i_id, const std::string& i_name) : position(i_position), stationID(i_id), stationName(i_name), slope(IOUtils::nodata), azi(IOUtils::nodata)
{
setStationData(i_position, i_id, i_name);
setSlope(IOUtils::nodata, IOUtils::nodata);
/*setStationData(i_position, i_id, i_name);
setSlope(IOUtils::nodata, IOUtils::nodata);*/
}
void StationData::setStationData(const Coords& i_position, const std::string& i_id, const std::string& i_name)
......@@ -105,8 +105,8 @@ double StationData::getAzimuth() const {
std::ostream& operator<<(std::ostream& os, const StationData& station) {
os << "<station>" << endl
<< std::setprecision(10) << station.position
<< "ID: " << station.getStationID() << endl
<< std::setprecision(10) << station.position
<< "ID: " << station.getStationID() << endl
<< "Name: " << station.getStationName() << endl
<< "Slope: " << station.getSlopeAngle() << " bearing: " << station.getAzimuth() << endl
<< "</station>" << endl;
......
......@@ -185,14 +185,14 @@ double Atmosphere::heatIndex(const double& TA, const double& RH)
double Atmosphere::waterSaturationPressure(const double& T) {
double c2, c3; // varying constants
if ( T < 273.16 ) { // for a flat ice surface
if ( T < Cst::t_water_triple_pt ) { // for a flat ice surface
c2 = 21.88;
c3 = 7.66;
} else { // for a flat water surface
c2 = 17.27;
c3 = 35.86;
}
const double exp_p_sat = c2 * (T - 273.16) / (T - c3); //exponent
const double exp_p_sat = c2 * (T - Cst::t_water_triple_pt) / (T - c3); //exponent
return( Cst::p_water_triple_pt * exp( exp_p_sat ) );
}
......
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