WSL/SLF GitLab Repository

Commit 4802ecd0 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Added a better support of Clang on osX in Cmake; fixed lots of the warnings...

Added a better support of Clang on osX in Cmake; fixed lots of the warnings generated by the "Weveryting" option. Still some work left to do, though\!
parent d0bdd366
......@@ -21,7 +21,7 @@ ENDIF(WIN32)
INCLUDE("${CMAKE_SOURCE_DIR}/tools/cmake/BuildVersion.cmake")
BuildVersion()
IF(MSVC)
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
#SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE)
SET(WARNINGS "/W4 /D_CRT_SECURE_NO_WARNINGS /EHsc") #Za: strict ansi EHsc: handle c++ exceptions
#SET(EXTRA_WARNINGS "/Wp64") #/Wall
......@@ -36,7 +36,7 @@ IF(MSVC)
IF(GUI_EXCEPTIONS)
SET(MSG_BOX "/DMESG_BOX")
ENDIF(GUI_EXCEPTIONS)
ELSE(MSVC)
ELSE()
#we consider that all other compilers support "-" options and silently ignore what they don't know
SET(WARNINGS "-Wall -Wno-long-long")
SET(DEEP_WARNINGS "-Wunused-value -Wshadow -Wpointer-arith -Wconversion -Winline -Wdisabled-optimization") #-Wfloat-equal -Wpadded
......@@ -48,8 +48,8 @@ ELSE(MSVC)
#IF(BUILD_SHARED_LIBS)
# ADD_DEFINITIONS(-DMIO_DLL)
#ENDIF(BUILD_SHARED_LIBS)
IF(CMAKE_COMPILER_IS_GNUCXX)
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(PROFILING "-pg -fprofile-arcs") #add ${PROFILING} to the CFLAGS when necessary
IF(NOT ANDROID)
SET(EXTRA_WARNINGS "${EXTRA_WARNINGS} -ansi")
......@@ -64,16 +64,28 @@ ELSE(MSVC)
ENDIF()
IF(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
SET(OPTIM "${OPTIM} -flto") #for gcc>4.5, but first implementations were slow, so it is safe to enforce 4.8
# if set to ON, all binaries depending on the library have to be compiled the same way.
# if set to ON, all binaries depending on the library have to be compiled the same way.
#Then, do an "export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4" and run with "ASAN_OPTIONS=symbolize=1"
SET(LEAKS_CHECK OFF CACHE BOOL "Set to ON to dynamically check for memory corruption (and do the same for applications linked with MeteoIO)")
IF (LEAKS_CHECK)
SET(EXTRA "${EXTRA} -fsanitize=address -fno-omit-frame-pointer")
ENDIF(LEAKS_CHECK)
ENDIF()
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF(MSVC)
ENDIF()
IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(PROFILING "-pg") #add ${PROFILING} to the CFLAGS when necessary
SET(EXTRA "${EXTRA} -fcolor-diagnostics") #-fapple-pragma-pack does not seems necessary; -ftrapv should be replaced by sanitize=integer
SET(OPTIM "${OPTIM} -flto")
SET(WARNINGS "${WARNINGS} -Weverything -Wno-date-time -Wno-float-equal -Wno-documentation -Wno-old-style-cast -Wno-padded -Wno-missing-noreturn -Wno-weak-vtables") #obviously, we should try to fix the warnings!
SET(DEEP_WARNINGS "${DEEP_WARNINGS} -Rpass=.*")
SET(LEAKS_CHECK OFF CACHE BOOL "Set to ON to dynamically check for memory corruption (and do the same for applications linked with MeteoIO)")
IF (LEAKS_CHECK)
SET(EXTRA "${EXTRA} -ftrapv -fno-omit-frame-pointer") #-fsanitize=address,undefined,integer,undefined-trap but this is currently not supported by Apple
ENDIF(LEAKS_CHECK)
SET(ARCH_OPTIM "-march=native")
ENDIF()
ENDIF()
#The following pre-processor variables are automatically defined:
# __linux, __GNUC__, __CYGWIN__, _WIN32, __MINGW32__, __APPLE__
......
......@@ -64,7 +64,7 @@ class Config {
*/
Config();
virtual ~Config() {};
virtual ~Config() {}
/**
* @brief Main constructor. The file is parsed and a key/value map object is internally created
......@@ -97,7 +97,7 @@ class Config {
* @param[in] value string representing the matching value to be added
*/
void addKey(const std::string& key, const std::string& value);
/**
* @brief Add a specific key/value pair to the internal key/value map object.
* key and section are case insensitive
......
......@@ -101,7 +101,7 @@ class DataGenerator {
public:
DataGenerator(const Config& cfg);
DataGenerator(const DataGenerator& c) : mapGenerators(c.mapGenerators), mapCreators(c.mapCreators),
generators_defined(c.generators_defined), creators_defined(c.creators_defined) {};
generators_defined(c.generators_defined), creators_defined(c.creators_defined) {}
~DataGenerator();
void fillMissing(METEO_SET& vecMeteo) const;
......
......@@ -45,7 +45,7 @@ namespace IOUtils {
* @param pattern optional pattern that must be part of the file names
*/
void readDirectory(const std::string& path, std::list<std::string>& dirlist, const std::string& pattern="");
std::list<std::string> readDirectory(const std::string& path, const std::string& pattern="");
bool validFileAndPath(const std::string& filename);
......@@ -126,7 +126,7 @@ namespace IOUtils {
*/
class FileIndexer {
public:
FileIndexer() : vecIndex() {};
FileIndexer() : vecIndex() {}
/**
* @brief Add a new position to the index
......@@ -151,7 +151,7 @@ namespace IOUtils {
private:
struct file_index {
file_index(const Date& i_date, const std::streampos& i_pos) : date(i_date), pos(i_pos) {};
file_index(const Date& i_date, const std::streampos& i_pos) : date(i_date), pos(i_pos) {}
bool operator<(const file_index& a) const {
return date < a.date;
}
......
......@@ -97,7 +97,7 @@ namespace mio {
* Downwelling Longwave Radiation"</i>, Journal of Applied Meteorology, <b>38</b>, 1999, pp 474-480
* - Unsworth and Monteith -- <i>"Long-wave radiation at the ground"</i>, Q. J. R. Meteorolo. Soc., Vol. 101, 1975, pp 13-24
* - Meeus -- <i>"Astronomical Algorithms"</i>, second edition, 1998, Willmann-Bell, Inc., Richmond, VA, USA
* - Mair et al. -- <i>" ESOLIP–estimate of solid and liquid precipitation at sub-daily time resolution by combining snow height
* - Mair et al. -- <i>" ESOLIP–estimate of solid and liquid precipitation at sub-daily time resolution by combining snow height
* and rain gauge measurements"</i>, Hydrology and Earth System Sciences Discussions, <b>10(7)</b>, 8683-8714, 2013.
*
*
......@@ -120,7 +120,7 @@ namespace mio {
class GeneratorAlgorithm {
public:
GeneratorAlgorithm(const std::vector<std::string>& /*vecArgs*/, const std::string& i_algo) : algo(i_algo) {};
GeneratorAlgorithm(const std::vector<std::string>& /*vecArgs*/, const std::string& i_algo) : algo(i_algo) {}
virtual ~GeneratorAlgorithm() {}
//fill one MeteoData, for one station
virtual bool generate(const size_t& param, MeteoData& md) = 0;
......@@ -388,17 +388,17 @@ class AllSkySWGenerator : public GeneratorAlgorithm {
/**
* @class ESOLIPGenerator
* @brief Generate precipitation from changes in snow height.
* This implements the approach laid out in
* Mair et al., <i>" ESOLIP–estimate of solid and liquid precipitation at sub-daily time resolution by combining snow height
* This implements the approach laid out in
* Mair et al., <i>" ESOLIP–estimate of solid and liquid precipitation at sub-daily time resolution by combining snow height
* and rain gauge measurements"</i>, Hydrology and Earth System Sciences Discussions, <b>10(7)</b>, 8683-8714, 2013. or
* Mair E., Leitinger G., Della Chiesa S., Niedrist G., Tappeiner U., Bertoldi G., <i>"A simple method to combine snow height and
* meteorological observations to estimate winter precipitation at sub-daily resolution"</i>, Journal of Hydrological Sciences,
* Mair E., Leitinger G., Della Chiesa S., Niedrist G., Tappeiner U., Bertoldi G., <i>"A simple method to combine snow height and
* meteorological observations to estimate winter precipitation at sub-daily resolution"</i>, Journal of Hydrological Sciences,
* in revision, 2015.
* The snow density relies on Zwart, <i>"Significance of new-snow properties for snowcover development"</i>,master's thesis,
* The snow density relies on Zwart, <i>"Significance of new-snow properties for snowcover development"</i>,master's thesis,
* Institute for Marine and Atmospheric Research, University of Utrecht, 78 pp, 2007.
*
* @note only identified precipitation events are written out, this means that it is recommended to run through a Cst=0 data generator afterward
*
*
* @note only identified precipitation events are written out, this means that it is recommended to run through a Cst=0 data generator afterward
*
* @code
* PSUM::generators = ESOLIP
* @endcode
......@@ -420,7 +420,7 @@ class ESOLIPGenerator : public GeneratorAlgorithm {
* @brief Generate precipitation splitting according to the selected method
* The methods that are offered are currently the following:
* - THRESH: a provided fixed air temperature threshold splits precipitation as either fully solid or fully liquid
* - RANGE: two air temperature thresholds provide the lower and upper range for fully solid / fully liquid precipitation.
* - RANGE: two air temperature thresholds provide the lower and upper range for fully solid / fully liquid precipitation.
* Within the provided range, a linear transition is assumed.
*
* @code
......@@ -431,15 +431,15 @@ class ESOLIPGenerator : public GeneratorAlgorithm {
class PPhaseGenerator : public GeneratorAlgorithm {
public:
PPhaseGenerator(const std::vector<std::string>& vecArgs, const std::string& i_algo)
: GeneratorAlgorithm(vecArgs, i_algo), model(THRESH), fixed_thresh(IOUtils::nodata),
: GeneratorAlgorithm(vecArgs, i_algo), model(THRESH), fixed_thresh(IOUtils::nodata),
range_start(IOUtils::nodata), range_norm(IOUtils::nodata) { parse_args(vecArgs); }
bool generate(const size_t& param, MeteoData& md);
bool generate(const size_t& param, std::vector<MeteoData>& vecMeteo);
private:
void parse_args(const std::vector<std::string>& vecArgs);
typedef enum PARAMETRIZATION {
THRESH,
RANGE
......
......@@ -132,9 +132,9 @@ namespace Color {
//Gradients scale between 0 and 1, but might receive some out of range values for special effects (below sea level, above snow line, etc)
class Gradient_model {
public:
Gradient_model() : X(), v_h(), v_s(), v_v() {}; //do not use this constructor!
virtual ~Gradient_model() {};
Gradient_model(const double& i_min, const double& i_max, const bool& i_autoscale) : X(), v_h(), v_s(), v_v() { (void)i_min; (void)i_max; (void)i_autoscale;};
Gradient_model() : X(), v_h(), v_s(), v_v() {} //do not use this constructor!
virtual ~Gradient_model() {}
Gradient_model(const double& i_min, const double& i_max, const bool& i_autoscale) : X(), v_h(), v_s(), v_v() { (void)i_min; (void)i_max; (void)i_autoscale;}
//setBgColor()
//setFgColor()
......@@ -200,7 +200,7 @@ class Gradient {
* @brief Default Constructor.
* This should be followed by a call to set() before calling getColor
*/
Gradient() : min(0.), max(0.), delta(0.), type(none), model(NULL), nr_unique_cols(0), autoscale(true) { };
Gradient() : min(0.), max(0.), delta(0.), type(none), model(NULL), nr_unique_cols(0), autoscale(true) {}
/**
* @brief Constructor.
......@@ -214,7 +214,7 @@ class Gradient {
Gradient(const Gradient& c);
~Gradient() {delete model;};
~Gradient() {delete model;}
/**
* @brief Setter
......@@ -284,7 +284,7 @@ class Gradient {
class gr_heat : public Gradient_model {
public:
gr_heat(const double& i_min, const double& i_max, const bool& i_autoscale) {(void)i_min; (void)i_max; (void)i_autoscale;};
gr_heat(const double& i_min, const double& i_max, const bool& i_autoscale) {(void)i_min; (void)i_max; (void)i_autoscale;}
void getColor(const double &i_val, double &r, double &g, double &b) const;
};
......
......@@ -137,8 +137,6 @@ IOException::IOException(const std::string& message, const std::string& position
#endif
}
IOException::~IOException() throw() {}
const char* IOException::what() const throw()
{
#if defined(MSG_BOX)
......
......@@ -41,7 +41,7 @@ namespace mio {
class IOException : public std::exception {
public:
IOException(const std::string& message="IOException occured", const std::string& position="");
~IOException() throw();
~IOException() throw() {}
virtual const char* what() const throw();
protected:
......
......@@ -89,7 +89,7 @@ namespace mio {
*/
class IOInterface {
public:
virtual ~IOInterface() {};
virtual ~IOInterface() {}
/**
* @brief A generic function for parsing 2D grids into a Grid2DObject. The string parameter shall be used for addressing the
......
......@@ -729,7 +729,7 @@ double unitsConversion(const double& val, std::string unitIn, std::string unitOu
const double ratio = inFactor / outFactor;
return val*ratio;
}
throw ConversionFailedException("Unable to perform unit conversion.", AT);
//throw ConversionFailedException("Unable to perform unit conversion.", AT);
}
} //namespace IOUtils
......
......@@ -59,10 +59,10 @@ namespace IOUtils {
enum ThrowOptions { dothrow, nothrow };
const double nodata = -999.0; ///<This is the internal nodata value
//const double not_set = std::numeric_limits<double>::max()-2.;
const unsigned int unodata = (unsigned int)-1;
const unsigned int unodata = static_cast<unsigned int>(-1);
const int inodata = -999;
const short int snodata = -999;
const size_t npos = (size_t)-1; ///<npos is the out-of-range value
const size_t npos = static_cast<size_t>(-1); ///<npos is the out-of-range value
const double grid_epsilon = 5.; ///<What is an acceptable small distance on a grid, in meters
const double lon_epsilon = grid_epsilon / Cst::earth_R0 * Cst::to_deg; ///<in degrees. Small angle for longitudes, so sin(x)=x
......
......@@ -153,8 +153,8 @@ class InterpolationAlgorithm {
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, TimeSeriesManager& i_tsmanager, GridsManager& i_gridsmanager) :
algo(i_algo), mi(i_mi), tsmanager(i_tsmanager), gridsmanager(i_gridsmanager), date(0., 0), vecArgs(i_vecArgs), vecMeteo(), vecData(),
vecMeta(), info(), param(MeteoData::firstparam), nrOfMeasurments(0) {};
virtual ~InterpolationAlgorithm() {};
vecMeta(), info(), param(MeteoData::firstparam), nrOfMeasurments(0) {}
virtual ~InterpolationAlgorithm() {}
//if anything is not ok (wrong parameter for this algo, insufficient data, etc) -> return zero
virtual double getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param) = 0;
virtual void calculate(const DEMObject& dem, Grid2DObject& grid) = 0;
......@@ -251,7 +251,7 @@ class StandardPressureAlgorithm : public InterpolationAlgorithm {
/**
* @class ConstLapseRateAlgorithm
* @brief Constant filling with elevation lapse rate interpolation algorithm.
* The grid is filled with the average of the detrended measured values and then re-trended. Or to put it
* The grid is filled with the average of the detrended measured values and then re-trended. Or to put it
* differently, the following operations are performed: detrending - averaging - re-trending.
* The lapse rate is either calculated from the data
* (if no extra argument is provided), or given by the user-provided the optional argument <i>"cst_lapse"</i>.
......@@ -506,10 +506,10 @@ class USERInterpolation : public InterpolationAlgorithm {
* @brief Precipitation phase splitting generation
* This does not interpolate any measured precipitation phase but generates it for each point based on parametrizations, similarly to the PPHASE generator
* (see PPhaseGenerator).
*
*
* The methods that are offered are currently the following:
* - THRESH: a provided fixed air temperature threshold splits precipitation as either fully solid or fully liquid
* - RANGE: two air temperature thresholds provide the lower and upper range for fully solid / fully liquid precipitation.
* - RANGE: two air temperature thresholds provide the lower and upper range for fully solid / fully liquid precipitation.
* Within the provided range, a linear transition is assumed.
* @code
* PSUM::algorithms = PPHASE
......@@ -521,7 +521,7 @@ class PPHASEInterpolation : public InterpolationAlgorithm {
PPHASEInterpolation(Meteo2DInterpolator& i_mi,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, TimeSeriesManager& i_tsmanager, GridsManager& i_gridsmanager)
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, i_tsmanager, i_gridsmanager),
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, i_tsmanager, i_gridsmanager),
model(THRESH), fixed_thresh(IOUtils::nodata), range_start(IOUtils::nodata), range_norm(IOUtils::nodata) {}
virtual double getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param);
virtual void calculate(const DEMObject& dem, Grid2DObject& grid);
......
......@@ -177,6 +177,8 @@ namespace Optim {
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundefined-reinterpret-cast"
//see http://metamerist.com/cbrt/cbrt.htm
template <int n> inline float nth_rootf(float x) {
const bool sgn = (x<0.)? true : false;
......@@ -205,6 +207,7 @@ namespace Optim {
if (sgn) return -x;
else return x;
}
#pragma clang diagnostic pop
/**
* @brief Optimized version of cubic root
......
......@@ -97,11 +97,11 @@ class ResamplingAlgorithms {
};
ResamplingAlgorithms(const std::string& i_algoname, const std::string& i_parname, const double& dflt_window_size, const std::vector<std::string>& /*vecArgs*/)
: algo(i_algoname), parname(i_parname), window_size(dflt_window_size) {};
: algo(i_algoname), parname(i_parname), window_size(dflt_window_size) {}
virtual ~ResamplingAlgorithms() {};
virtual ~ResamplingAlgorithms() {}
const std::string getAlgo() const {return algo;};
const std::string getAlgo() const {return algo;}
virtual void resample(const size_t& index, const ResamplingPosition& position, const size_t& paramindex,
const std::vector<MeteoData>& vecM, MeteoData& md) = 0;
......@@ -260,18 +260,18 @@ class Daily_solar : public ResamplingAlgorithms {
/**
* @brief Generate daily variations of a given amplitude around a single daily average.
* The paremeter to be interpolated is assumed to be a daily average and a sinusoidal variation of the
* amplitude given as argument will be generated (it is also possible to provide the "phase" or the
* amplitude given as argument will be generated (it is also possible to provide the "phase" or the
* fraction of the day when the minimum is reached). If data bearing the same name followed by "_MIN" or "_MAX"
* exist, there is no need to provide an amplitude as they will be used instead (but if the amplitude is provided, it
* will be used as a fallback when no min or max is available).
*
*
* @code
* [Interpolations1D]
* TA::resample = daily_avg
* TA::daily_avg = 5 .25 ;assume that TA varies +/- 5K around its average during the day and reaches its minimum at 6am
* @endcode
* @note If both the average (the parameter itself in the data set),
* min and max are provided, an error message will be returned.
* @note If both the average (the parameter itself in the data set),
* min and max are provided, an error message will be returned.
*/
class DailyAverage : public ResamplingAlgorithms {
public:
......
......@@ -367,4 +367,4 @@ const std::string GridBuffer::toString() const
}
} //end namespace
\ No newline at end of file
} //end namespace
......@@ -37,7 +37,7 @@ namespace mio {
*/
class MeteoBuffer {
public:
MeteoBuffer() : ts_buffer(), ts_start(), ts_end() {};
MeteoBuffer() : ts_buffer(), ts_start(), ts_end() {}
/**
* @brief Get buffer data for a specific date
......@@ -127,25 +127,25 @@ class MeteoBuffer {
class GridBuffer {
public:
GridBuffer(const size_t& in_max_grids);
bool empty() const {return IndexBufferedGrids.empty();};
void clear() {mapBufferedGrids.clear(); mapBufferedInfos.clear(); IndexBufferedGrids.clear();};
size_t size() const {return IndexBufferedGrids.size();};
void setMaxGrids(const size_t& in_max_grids) {max_grids=in_max_grids;};
bool empty() const {return IndexBufferedGrids.empty();}
void clear() {mapBufferedGrids.clear(); mapBufferedInfos.clear(); IndexBufferedGrids.clear();}
size_t size() const {return IndexBufferedGrids.size();}
void setMaxGrids(const size_t& in_max_grids) {max_grids=in_max_grids;}
bool get(DEMObject& grid, const std::string& grid_hash) const;
bool get(Grid2DObject& grid, const std::string& grid_hash) const;
bool get(Grid2DObject& grid, const std::string& grid_hash, std::string& grid_info) const;
bool get(Grid2DObject& grid, const MeteoGrids::Parameters& parameter, const Date& date) const;
void push(const DEMObject& grid, const std::string& grid_hash);
void push(const Grid2DObject& grid, const std::string& grid_hash);
void push(const Grid2DObject& grid, const std::string& grid_hash, const std::string& grid_info);
void push(const Grid2DObject& grid, const MeteoGrids::Parameters& parameter, const Date& date);
const std::string toString() const;
private:
private:
std::map<std::string, Grid2DObject> mapBufferedGrids; ///< Buffer interpolated grids
std::map<std::string, DEMObject> mapBufferedDEMs; ///< Buffer interpolated grids
std::map<std::string, std::string> mapBufferedInfos; ///< Buffer interpolations info messages
......@@ -155,4 +155,4 @@ class GridBuffer {
};
}
#endif
\ No newline at end of file
#endif
......@@ -162,8 +162,7 @@ void Coords::moveByBearing(const double& i_bearing, const double& i_distance) {
case GEO_VINCENTY:
VincentyInverse(latitude, longitude, i_distance, i_bearing, new_lat, new_lon);
break;
default:
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
}
setLatLon(new_lat, new_lon, altitude, true);
......@@ -1577,8 +1576,7 @@ void Coords::distance(const Coords& destination, double& o_distance, double& o_b
case GEO_VINCENTY:
o_distance = VincentyDistance(latitude, longitude, destination.getLat(), destination.getLon(), o_bearing);
break;
default:
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
}
}
}
......@@ -1607,8 +1605,7 @@ void Coords::WGS84_to_local(double lat_in, double long_in, double& east_out, dou
case GEO_VINCENTY:
dist = VincentyDistance(ref_latitude, ref_longitude, lat_in, long_in, alpha);
break;
default:
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
}
east_out = dist*sin(alpha*Cst::to_rad);
......@@ -1641,8 +1638,7 @@ void Coords::local_to_WGS84(double east_in, double north_in, double& lat_out, do
case GEO_VINCENTY:
VincentyInverse(ref_latitude, ref_longitude, dist, bearing, lat_out, long_out);
break;
default:
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
throw InvalidArgumentException("Unrecognized geodesic distance algorithm selected", AT);
}
}
}
......
......@@ -693,11 +693,11 @@ unsigned short Date::getISOWeekNr(int &ISO_year, const bool& gmt) const
const unsigned short newYear_dow = newYear.getDayOfWeek(gmt);
const int firstThursday = (7 - newYear_dow + 4) % 7 + 1; //first Thursday of the year belongs to week 1
const int firstWeekMonday = firstThursday - 3; //this could be <0, for example if Jan 01 is a Thursday
if (jdn>=359) { //handle the last few days before the new year that might belong to week 1
const bool is_leapYear = isLeapYear();
const int jdn_last = (is_leapYear)? 366 : 365;
const unsigned char week_offset = (is_leapYear)? 1 : 0; //for leap years, dec. 31 is one dow later as jan. 1st
const unsigned char week_offset = (is_leapYear)? 1 : 0; //for leap years, dec. 31 is one dow later as jan. 1st
const double lastDay_dow = (newYear_dow + week_offset - 1) % 7 + 1;
const double lastMonday = jdn_last - lastDay_dow + 1; //dow starts at 1
if (jdn>=lastMonday && lastDay_dow<4) {
......@@ -705,7 +705,7 @@ unsigned short Date::getISOWeekNr(int &ISO_year, const bool& gmt) const
return 1;
}
}
//these are certainly normal days, ie no special case
if (jdn>=firstWeekMonday) { //at worst, we are in week 01, otherwise after...
return static_cast<unsigned short>( Optim::intPart( (jdn+3-(double)firstThursday) / 7 ) + 1);
......@@ -716,7 +716,7 @@ unsigned short Date::getISOWeekNr(int &ISO_year, const bool& gmt) const
ISO_year--;
if (newYear_dow==5) return 53; // Friday indicates a leap year
if (newYear_dow==7) return 52; // Sunday is no leap year
//Saturday depends on the year before...
if (isLeapYear(ISO_year)) return 53;
else return 52;
......@@ -1083,6 +1083,7 @@ const string Date::toString(FORMATS type, const bool& gmt) const
day_out = gmt_day;
hour_out = gmt_hour;
minute_out = gmt_minute;
second_out = gmt_second;
} else {
julian_out = GMTToLocal(gmt_julian);
calculateValues(julian_out, year_out, month_out, day_out, hour_out, minute_out, second_out);
......@@ -1148,7 +1149,7 @@ const string Date::toString(FORMATS type, const bool& gmt) const
<< setw(2) << setfill('0') << minute_out << ":"
<< setw(2) << setfill('0') << second_out;
break;
case(ISO_WEEK):
case(ISO_WEEK):
{
int ISO_year;
const int ISO_week = getISOWeekNr(ISO_year, gmt);
......@@ -1158,8 +1159,7 @@ const string Date::toString(FORMATS type, const bool& gmt) const
<< setw(2) << setfill('0') << getDayOfWeek(gmt);
break;
}
default:
throw InvalidArgumentException("Wrong date conversion format requested", AT);
throw InvalidArgumentException("Wrong date conversion format requested", AT);
}
return tmpstr.str();
......@@ -1250,11 +1250,11 @@ void Date::calculateValues(const double& i_julian, int& o_year, int& o_month, in
// Correct for BC years -> astronomical year, that is from year -1 to year 0
if ( o_year <= 0 ) o_year--;
double integral;
const double frac = modf(tmp_julian+.5, &integral); //the julian date reference is at 12:00
const int sec = static_cast<int>(Optim::round(frac*(24.*3600.)));
o_hour = static_cast<int>(double(sec)/3600.);
o_minute = static_cast<int>(double(sec - 3600*o_hour)/60.);
o_second = sec - 3600*o_hour - 60*o_minute;
......
......@@ -68,7 +68,7 @@ class Grid2DObject {
Grid2DObject(const double& cellsize, const Coords& i_llcorner, const Array2D<double>& grid2D_in);
virtual ~Grid2DObject() {};
virtual ~Grid2DObject() {}
/**
* @brief constructs an object as a subset of another grid object
......
......@@ -71,7 +71,7 @@ void Matrix::clear() {
}
void Matrix::random(const double& range) {
srand((unsigned)time(0));
srand(static_cast<unsigned>(time(0)));
for(size_t ii=0; ii<vecData.size(); ii++)
vecData[ii] = (double)rand()/(double)RAND_MAX*range;
......
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