WSL/SLF GitLab Repository

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

Code cleanup and fix for IMIS: now the ENET stations receive the number 1 for...

Code cleanup and fix for IMIS: now the ENET stations receive the number 1 for the automatic stations instead of 0.
parent c0ff5b87
......@@ -147,7 +147,7 @@ std::iostream& operator>>(std::iostream& is, Config& cfg) {
cfg.properties.clear();
size_t s_map;
is.read(reinterpret_cast<char*>(&s_map), sizeof(size_t));
for(size_t ii=0; ii<s_map; ii++) {
for (size_t ii=0; ii<s_map; ii++) {
size_t s_key, s_value;
is.read(reinterpret_cast<char*>(&s_key), sizeof(size_t));
string key;
......@@ -196,7 +196,7 @@ void Config::parseFile(const std::string& filename)
std::string line;
getline(fin, line, eoln); //read complete line
parseLine(linenr++, import_after, accept_import_before, line, section);
} while(!fin.eof());
} while (!fin.eof());
fin.close();
} catch(const std::exception&){
if (fin.is_open()) {//close fin if open
......
......@@ -265,7 +265,7 @@ class Config {
const std::string new_section( IOUtils::strToUpper(section) );
const size_t nr_keys = findKeys(vecKeys, keystart, new_section);
for(size_t ii=0; ii<nr_keys; ++ii) {
for (size_t ii=0; ii<nr_keys; ++ii) {
const std::string full_key = new_section + "::" + vecKeys[ii];
T tmp;
try {
......
......@@ -40,22 +40,22 @@ DataGenerator::~DataGenerator()
{ //we have to deallocate the memory allocated by "new GeneratorAlgorithm()"
std::map< std::string, std::vector<GeneratorAlgorithm*> >::iterator it;
for(it=mapGenerators.begin(); it!=mapGenerators.end(); ++it) {
for (it=mapGenerators.begin(); it!=mapGenerators.end(); ++it) {
std::vector<GeneratorAlgorithm*> &vec( it->second );
for(size_t ii=0; ii<vec.size(); ii++)
for (size_t ii=0; ii<vec.size(); ii++)
delete vec[ii];
}
for(it=mapCreators.begin(); it!=mapCreators.end(); ++it) {
for (it=mapCreators.begin(); it!=mapCreators.end(); ++it) {
std::vector<GeneratorAlgorithm*> &vec( it->second );
for(size_t ii=0; ii<vec.size(); ii++)
for (size_t ii=0; ii<vec.size(); ii++)
delete vec[ii];
}
}
DataGenerator& DataGenerator::operator=(const DataGenerator& source)
{
if(this != &source) {
if (this != &source) {
mapGenerators = source.mapGenerators;
mapCreators = source.mapCreators;
generators_defined = source.generators_defined;
......@@ -73,15 +73,15 @@ DataGenerator& DataGenerator::operator=(const DataGenerator& source)
*/
void DataGenerator::fillMissing(METEO_SET& vecMeteo) const
{
if(!generators_defined) return; //no generators defined by the end user
if (!generators_defined) return; //no generators defined by the end user
std::map< std::string, std::vector<GeneratorAlgorithm*> >::const_iterator it;
for(it=mapGenerators.begin(); it!=mapGenerators.end(); ++it) {
for (it=mapGenerators.begin(); it!=mapGenerators.end(); ++it) {
const std::vector<GeneratorAlgorithm*> vecGenerators( it->second );
for(size_t station=0; station<vecMeteo.size(); ++station) { //process this parameter on all stations
for (size_t station=0; station<vecMeteo.size(); ++station) { //process this parameter on all stations
const size_t param = vecMeteo[station].getParameterIndex(it->first);
if(param==IOUtils::npos) continue;
if (param==IOUtils::npos) continue;
#ifdef DATA_QA
double old_val = vecMeteo[station](param);
......@@ -117,15 +117,15 @@ void DataGenerator::fillMissing(METEO_SET& vecMeteo) const
*/
void DataGenerator::fillMissing(std::vector<METEO_SET>& vecVecMeteo) const
{
if(!generators_defined) return; //no generators defined by the end user
if (!generators_defined) return; //no generators defined by the end user
std::map< std::string, std::vector<GeneratorAlgorithm*> >::const_iterator it;
for(it=mapGenerators.begin(); it!=mapGenerators.end(); ++it) {
for (it=mapGenerators.begin(); it!=mapGenerators.end(); ++it) {
const std::vector<GeneratorAlgorithm*> vecGenerators( it->second );
for(size_t station=0; station<vecVecMeteo.size(); ++station) { //process this parameter on all stations
for (size_t station=0; station<vecVecMeteo.size(); ++station) { //process this parameter on all stations
const size_t param = vecVecMeteo[station][0].getParameterIndex(it->first);
if(param==IOUtils::npos) continue;
if (param==IOUtils::npos) continue;
#ifdef DATA_QA
METEO_SET old_val = vecVecMeteo[station];
......@@ -162,13 +162,13 @@ void DataGenerator::fillMissing(std::vector<METEO_SET>& vecVecMeteo) const
*/
void DataGenerator::createParameters(METEO_SET& vecMeteo) const
{
if(!creators_defined) return; //no creators defined by the end user
if (!creators_defined) return; //no creators defined by the end user
std::map< std::string, std::vector<GeneratorAlgorithm*> >::const_iterator it;
for(it=mapCreators.begin(); it!=mapCreators.end(); ++it) {
for (it=mapCreators.begin(); it!=mapCreators.end(); ++it) {
const std::vector<GeneratorAlgorithm*> vecGenerators( it->second );
for(size_t station=0; station<vecMeteo.size(); ++station) { //process this parameter on all stations
for (size_t station=0; station<vecMeteo.size(); ++station) { //process this parameter on all stations
const size_t param = vecMeteo[station].addParameter( it->first );
size_t jj=0;
......@@ -186,15 +186,15 @@ void DataGenerator::createParameters(METEO_SET& vecMeteo) const
*/
void DataGenerator::createParameters(std::vector<METEO_SET>& vecVecMeteo) const
{
if(!creators_defined) return; //no creators defined by the end user
if (!creators_defined) return; //no creators defined by the end user
std::map< std::string, std::vector<GeneratorAlgorithm*> >::const_iterator it;
for(it=mapCreators.begin(); it!=mapCreators.end(); ++it) {
for (it=mapCreators.begin(); it!=mapCreators.end(); ++it) {
const std::vector<GeneratorAlgorithm*> vecGenerators( it->second );
for(size_t station=0; station<vecVecMeteo.size(); ++station) { //process this parameter on all stations
for (size_t station=0; station<vecVecMeteo.size(); ++station) { //process this parameter on all stations
//create the new parameter
for(size_t ii=0; ii<vecVecMeteo[station].size(); ++ii) {
for (size_t ii=0; ii<vecVecMeteo[station].size(); ++ii) {
vecVecMeteo[station][ii].addParameter( it->first );
}
const size_t param = vecVecMeteo[station][0].getParameterIndex(it->first);
......@@ -227,13 +227,13 @@ void DataGenerator::setAlgorithms(const Config& cfg, const std::string& key_patt
const size_t nrOfAlgorithms = getAlgorithmsForParameter(cfg, key_pattern, parname, tmpAlgorithms);
std::vector<GeneratorAlgorithm*> vecGenerators(nrOfAlgorithms);
for(size_t jj=0; jj<nrOfAlgorithms; jj++) {
for (size_t jj=0; jj<nrOfAlgorithms; jj++) {
std::vector<std::string> vecArgs;
getArgumentsForAlgorithm(cfg, parname, tmpAlgorithms[jj], vecArgs);
vecGenerators[jj] = GeneratorAlgorithmFactory::getAlgorithm( tmpAlgorithms[jj], vecArgs);
}
if(nrOfAlgorithms>0) {
if (nrOfAlgorithms>0) {
mapAlgorithms[parname] = vecGenerators;
}
}
......@@ -293,7 +293,7 @@ const std::string DataGenerator::toString() const {
os << "User list of generators:\n";
for (std::map< std::string, std::vector<GeneratorAlgorithm*> >::const_iterator iter = mapGenerators.begin(); iter != mapGenerators.end(); ++iter) {
os << setw(10) << iter->first << " :: ";
for(size_t jj=0; jj<iter->second.size(); jj++) {
for (size_t jj=0; jj<iter->second.size(); jj++) {
os << iter->second[jj]->getAlgo() << " ";
}
os << "\n";
......@@ -305,7 +305,7 @@ const std::string DataGenerator::toString() const {
os << "User list of creators:\n";
for (std::map< std::string, std::vector<GeneratorAlgorithm*> >::const_iterator iter = mapCreators.begin(); iter != mapCreators.end(); ++iter) {
os << setw(10) << iter->first << " :: ";
for(size_t jj=0; jj<iter->second.size(); jj++) {
for (size_t jj=0; jj<iter->second.size(); jj++) {
os << iter->second[jj]->getAlgo() << " ";
}
os << "\n";
......
......@@ -98,8 +98,8 @@ std::string getExtension(const std::string& filename)
{
const size_t start_basename = filename.find_last_of("/\\"); //we will skip the path
const size_t startpos = filename.find_last_of('.');
if( startpos==std::string::npos ) return std::string();
if( start_basename!=std::string::npos && startpos<start_basename ) return std::string();
if ( startpos==std::string::npos ) return std::string();
if ( start_basename!=std::string::npos && startpos<start_basename ) return std::string();
const std::string whitespaces(" \t\f\v\n\r");
const size_t endpos = filename.find_last_not_of(whitespaces); // Find the first character position from reverse af
......@@ -253,14 +253,14 @@ bool fileExists(const std::string& filename)
void readDirectory(const std::string& path, std::list<std::string>& dirlist, const std::string& pattern)
{
DIR *dp = opendir(path.c_str());
if(dp == NULL) {
if (dp == NULL) {
throw FileAccessException("Error opening directory " + path, AT);
}
struct dirent *dirp;
while ((dirp = readdir(dp)) != NULL) {
const std::string tmp(dirp->d_name);
if( tmp.compare(".")!=0 && tmp.compare("..")!=0 ) { //skip "." and ".."
if ( tmp.compare(".")!=0 && tmp.compare("..")!=0 ) { //skip "." and ".."
if (pattern.empty()) {
dirlist.push_back(tmp);
} else {
......@@ -312,7 +312,7 @@ void skipLines(std::istream& fin, const size_t& nbLines, const char& eoln)
{
std::string dummy;
for (size_t ii=0; ii<nbLines; ii++) {
if(!getline(fin, dummy, eoln)) {
if (!getline(fin, dummy, eoln)) {
throw InvalidFormatException("Premature EOF while skipping lines", AT);
}
}
......@@ -325,14 +325,14 @@ void FileIndexer::setIndex(const Date& i_date, const std::streampos& i_pos)
const file_index elem(i_date, i_pos);
//check if we can simply append the new index
if(vecIndex.empty() || elem>vecIndex.back()) {
if (vecIndex.empty() || elem>vecIndex.back()) {
vecIndex.push_back(elem);
return;
}
//look for the proper position for insertion of the new index
const std::vector< struct file_index >::iterator it = std::upper_bound(vecIndex.begin(), vecIndex.end(), elem);
if(it>vecIndex.begin() && (it-1)->date!=elem.date) { //check that we don't try to insert a duplicate
if (it>vecIndex.begin() && (it-1)->date!=elem.date) { //check that we don't try to insert a duplicate
vecIndex.insert(it, elem); //insertion is at the proper place -> remains ordered
return;
}
......@@ -354,7 +354,7 @@ void FileIndexer::setIndex(const double& i_date, const std::streampos& i_pos)
std::streampos FileIndexer::getIndex(const Date& i_date) const
{
const size_t foundIdx = binarySearch(i_date);
if(foundIdx==static_cast<size_t>(-1)) return static_cast<std::streampos>(-1);
if (foundIdx==static_cast<size_t>(-1)) return static_cast<std::streampos>(-1);
else return vecIndex[foundIdx].pos;
}
......@@ -373,14 +373,14 @@ std::streampos FileIndexer::getIndex(const double& i_date) const
size_t FileIndexer::binarySearch(const Date& soughtdate) const
{//perform binary search, return the first element that is GREATER than the provided value
if(vecIndex.empty()) return static_cast<size_t>(-1);
if(soughtdate<vecIndex.front().date) return static_cast<size_t>(-1);
if(soughtdate>=vecIndex.back().date) return vecIndex.size()-1;
if (vecIndex.empty()) return static_cast<size_t>(-1);
if (soughtdate<vecIndex.front().date) return static_cast<size_t>(-1);
if (soughtdate>=vecIndex.back().date) return vecIndex.size()-1;
const file_index elem(soughtdate, 0);
//returns the first element that is GREATER than the provided value
const std::vector< struct file_index >::const_iterator it = std::upper_bound(vecIndex.begin(), vecIndex.end(), elem);
if(it>vecIndex.begin()) return it-vecIndex.begin()-1;
if (it>vecIndex.begin()) return it-vecIndex.begin()-1;
else return static_cast<size_t>(-1);
}
......@@ -388,7 +388,7 @@ const std::string FileIndexer::toString() const
{
std::ostringstream os;
os << "<FileIndexer>\n";
for(size_t ii=0; ii<vecIndex.size(); ii++)
for (size_t ii=0; ii<vecIndex.size(); ii++)
os << "\t" << "[" << ii << "] - " << vecIndex[ii].date.toString(Date::ISO) << " -> #" << std::hex << vecIndex[ii].pos << std::dec << "\n";
os << "</FileIndexer>\n";
return os.str();
......
......@@ -65,7 +65,7 @@ std::string GeneratorAlgorithm::getAlgo() const {
void GeneratorAlgorithm::parse_args(const std::vector<std::string>& vecArgs)
{
if(!vecArgs.empty()) { //incorrect arguments, throw an exception
if (!vecArgs.empty()) { //incorrect arguments, throw an exception
throw InvalidArgumentException("Wrong number of arguments supplied for the "+algo+" generator", AT);
}
}
......@@ -75,7 +75,7 @@ void GeneratorAlgorithm::parse_args(const std::vector<std::string>& vecArgs)
void ConstGenerator::parse_args(const std::vector<std::string>& vecArgs)
{
//Get the optional arguments for the algorithm: constant value to use
if(vecArgs.size()==1) {
if (vecArgs.size()==1) {
IOUtils::convertString(constant, vecArgs[0]);
} else { //incorrect arguments, throw an exception
throw InvalidArgumentException("Wrong number of arguments supplied for the "+algo+" generator", AT);
......@@ -85,7 +85,7 @@ void ConstGenerator::parse_args(const std::vector<std::string>& vecArgs)
bool ConstGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if(value == IOUtils::nodata)
if (value == IOUtils::nodata)
value = constant;
return true; //all missing values could be filled
......@@ -93,9 +93,9 @@ bool ConstGenerator::generate(const size_t& param, MeteoData& md)
bool ConstGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
generate(param, vecMeteo[ii]);
}
......@@ -105,10 +105,10 @@ bool ConstGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMe
void SinGenerator::parse_args(const std::vector<std::string>& vecArgs)
{
//Get the optional arguments for the algorithm: constant value to use
if(vecArgs.size()==4) {
if (vecArgs.size()==4) {
const string type_str=IOUtils::strToUpper(vecArgs[0]);
if( type_str=="YEARLY" ) type='y';
else if( type_str=="DAILY" ) type='d';
if ( type_str=="YEARLY" ) type='y';
else if ( type_str=="DAILY" ) type='d';
else
throw InvalidArgumentException("Invalid period \""+type_str+"\" specified for the "+algo+" generator", AT);
......@@ -126,11 +126,11 @@ void SinGenerator::parse_args(const std::vector<std::string>& vecArgs)
bool SinGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
double t; //also, the minimum must occur at 0 if phase=0
if(type=='y') {
if (type=='y') {
t = (static_cast<double>(md.date.getJulianDayNumber()) - phase*365.25) / 366.25 - .25;
} else if(type=='d') {
} else if (type=='d') {
const double julian = md.date.getJulian();
t = (julian - Optim::intPart(julian) - phase) + .25; //watch out: julian day starts at noon!
} else {
......@@ -148,9 +148,9 @@ bool SinGenerator::generate(const size_t& param, MeteoData& md)
bool SinGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
generate(param, vecMeteo[ii]);
}
......@@ -161,9 +161,9 @@ bool SinGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMete
bool StandardPressureGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
const double altitude = md.meta.position.getAltitude();
if(altitude==IOUtils::nodata) return false;
if (altitude==IOUtils::nodata) return false;
value = Atmosphere::stdAirPressure(altitude);
}
......@@ -172,14 +172,14 @@ bool StandardPressureGenerator::generate(const size_t& param, MeteoData& md)
bool StandardPressureGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
const double altitude = vecMeteo.front().meta.position.getAltitude(); //if the stations move, this has to be in the loop
if(altitude==IOUtils::nodata) return false;
if (altitude==IOUtils::nodata) return false;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
double &value = vecMeteo[ii](param);
if(value == IOUtils::nodata)
if (value == IOUtils::nodata)
value = Atmosphere::stdAirPressure(altitude);
}
......@@ -190,7 +190,7 @@ bool StandardPressureGenerator::generate(const size_t& param, std::vector<MeteoD
bool RhGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
const double TA = md(MeteoData::TA);
if (TA==IOUtils::nodata) //nothing else we can do here
return false;
......@@ -218,14 +218,14 @@ bool RhGenerator::generate(const size_t& param, MeteoData& md)
bool RhGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
const double altitude = vecMeteo.front().meta.position.getAltitude(); //if the stations move, this has to be in the loop
bool all_filled = true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
double &value = vecMeteo[ii](param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
const double TA = vecMeteo[ii](MeteoData::TA);
if (TA==IOUtils::nodata) { //nothing else we can do here
all_filled=false;
......@@ -261,7 +261,7 @@ const double TsGenerator::snow_thresh = .1; //if snow height greater than this t
bool TsGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
const double olwr = md("OLWR");
if (olwr==IOUtils::nodata) //nothing else we can do here
return false;
......@@ -280,10 +280,10 @@ bool TsGenerator::generate(const size_t& param, MeteoData& md)
bool TsGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
bool status = true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
if (!generate(param, vecMeteo[ii]))
status = false;
}
......@@ -299,7 +299,7 @@ const double IswrAlbedoGenerator::snow_thresh = .1; //if snow height greater tha
bool IswrAlbedoGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
const double HS=md(MeteoData::HS), RSWR=md(MeteoData::RSWR), ISWR=md(MeteoData::ISWR);
double albedo = .5;
......@@ -324,10 +324,10 @@ bool IswrAlbedoGenerator::generate(const size_t& param, MeteoData& md)
bool IswrAlbedoGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
bool status = true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
if (!generate(param, vecMeteo[ii]))
status = false;
}
......@@ -339,7 +339,7 @@ bool IswrAlbedoGenerator::generate(const size_t& param, std::vector<MeteoData>&
void ClearSkyLWGenerator::parse_args(const std::vector<std::string>& vecArgs)
{
//Get the optional arguments for the algorithm: constant value to use
if(vecArgs.size()==1) {
if (vecArgs.size()==1) {
const std::string user_algo = IOUtils::strToUpper(vecArgs[0]);
if (user_algo=="BRUTSAERT") model = BRUTSAERT;
......@@ -381,12 +381,12 @@ bool ClearSkyLWGenerator::generate(const size_t& param, MeteoData& md)
bool ClearSkyLWGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
bool all_filled = true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
const bool status = generate(param, vecMeteo[ii]);
if(status==false) all_filled=false;
if (status==false) all_filled=false;
}
return all_filled;
......@@ -528,12 +528,12 @@ bool AllSkyLWGenerator::generate(const size_t& param, MeteoData& md)
bool AllSkyLWGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
bool all_filled = true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
const bool status = generate(param, vecMeteo[ii]);
if(status==false) all_filled=false;
if (status==false) all_filled=false;
}
return all_filled;
......@@ -546,7 +546,7 @@ const double AllSkySWGenerator::snow_thresh = .1; //if snow height greater than
void AllSkySWGenerator::parse_args(const std::vector<std::string>& vecArgs)
{
//Get the optional arguments for the algorithm: constant value to use
if(!vecArgs.empty()) { //incorrect arguments, throw an exception
if (!vecArgs.empty()) { //incorrect arguments, throw an exception
throw InvalidArgumentException("Wrong number of arguments supplied for the "+algo+" generator", AT);
}
}
......@@ -554,26 +554,26 @@ void AllSkySWGenerator::parse_args(const std::vector<std::string>& vecArgs)
bool AllSkySWGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
const double ISWR=md(MeteoData::ISWR), RSWR=md(MeteoData::RSWR), HS=md(MeteoData::HS), TAU_CLD=md(MeteoData::TAU_CLD);
double TA=md(MeteoData::TA), RH=md(MeteoData::RH), ILWR=md(MeteoData::ILWR);
const double lat = md.meta.position.getLat();
const double lon = md.meta.position.getLon();
const double alt = md.meta.position.getAltitude();
if(lat==IOUtils::nodata || lon==IOUtils::nodata || alt==IOUtils::nodata) return false;
if (lat==IOUtils::nodata || lon==IOUtils::nodata || alt==IOUtils::nodata) return false;
double albedo = .5;
if(RSWR==IOUtils::nodata || ISWR==IOUtils::nodata) {
if(HS!=IOUtils::nodata) //no big deal if we can not adapt the albedo
if (RSWR==IOUtils::nodata || ISWR==IOUtils::nodata) {
if (HS!=IOUtils::nodata) //no big deal if we can not adapt the albedo
albedo = (HS>=snow_thresh)? snow_albedo : soil_albedo;
} else if(ISWR>0. && RSWR>0.) { //this could happen if the user calls this generator for a copy parameter, etc
} else if (ISWR>0. && RSWR>0.) { //this could happen if the user calls this generator for a copy parameter, etc
albedo = RSWR / ISWR;
if(albedo>=1.) albedo=0.99;
if(albedo<=0.) albedo=0.01;
if (albedo>=1.) albedo=0.99;
if (albedo<=0.) albedo=0.01;
}
if(TA==IOUtils::nodata || RH==IOUtils::nodata) {
if (TA==IOUtils::nodata || RH==IOUtils::nodata) {
//set TA & RH so the reduced precipitable water will get an average value
TA=274.98;
RH=0.666;
......@@ -585,14 +585,14 @@ bool AllSkySWGenerator::generate(const size_t& param, MeteoData& md)
const double solarIndex = (TAU_CLD!=IOUtils::nodata)? TAU_CLD : (ILWR!=IOUtils::nodata)? getSolarIndex(TA, RH, ILWR) : 1.;
const double P=md(MeteoData::P);
if(P==IOUtils::nodata)
if (P==IOUtils::nodata)
sun.calculateRadiation(TA, RH, albedo);
else
sun.calculateRadiation(TA, RH, P, albedo);
double toa, direct, diffuse;
sun.getHorizontalRadiation(toa, direct, diffuse);
if(param!=MeteoData::RSWR)
if (param!=MeteoData::RSWR)
value = (direct+diffuse)*solarIndex; //ISWR
else
value = (direct+diffuse)*albedo*solarIndex; //RSWR
......@@ -603,32 +603,32 @@ bool AllSkySWGenerator::generate(const size_t& param, MeteoData& md)
bool AllSkySWGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if(vecMeteo.empty()) return true;
if (vecMeteo.empty()) return true;
const double lat = vecMeteo.front().meta.position.getLat();
const double lon = vecMeteo.front().meta.position.getLon();
const double alt = vecMeteo.front().meta.position.getAltitude();
if(lat==IOUtils::nodata || lon==IOUtils::nodata || alt==IOUtils::nodata) return false;
if (lat==IOUtils::nodata || lon==IOUtils::nodata || alt==IOUtils::nodata) return false;
sun.setLatLon(lat, lon, alt);
bool all_filled = true;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
double &value = vecMeteo[ii](param);
if(value == IOUtils::nodata) {
if (value == IOUtils::nodata) {
const double ISWR=vecMeteo[ii](MeteoData::ISWR), RSWR=vecMeteo[ii](MeteoData::RSWR), HS=vecMeteo[ii](MeteoData::HS);
double TA=vecMeteo[ii](MeteoData::TA), RH=vecMeteo[ii](MeteoData::RH), ILWR=vecMeteo[ii](MeteoData::ILWR);
double albedo = .5;
if(RSWR==IOUtils::nodata || ISWR==IOUtils::nodata) {
if(HS!=IOUtils::nodata) //no big deal if we can not adapt the albedo
if (RSWR==IOUtils::nodata || ISWR==IOUtils::nodata) {
if (HS!=IOUtils::nodata) //no big deal if we can not adapt the albedo
albedo = (HS>=snow_thresh)? snow_albedo : soil_albedo;
} else if(ISWR>0. && RSWR>0.) { //this could happen if the user calls this generator for a copy parameter, etc
} else if (ISWR>0. && RSWR>0.) { //this could happen if the user calls this generator for a copy parameter, etc
albedo = RSWR / ISWR;
if(albedo>=1.) albedo=0.99;
if(albedo<=0.) albedo=0.01;
if (albedo>=1.) albedo=0.99;
if (albedo<=0.) albedo=0.01;
}
if(TA==IOUtils::nodata || RH==IOUtils::nodata) {
if (TA==IOUtils::nodata || RH==IOUtils::nodata) {
//set TA & RH so the reduced precipitable water will get an average value
TA=274.98;
RH=0.666;
......@@ -639,14 +639,14 @@ bool AllSkySWGenerator::generate(const size_t& param, std::vector<MeteoData>& ve
const double solarIndex = (ILWR!=IOUtils::nodata)? getSolarIndex(TA, RH, ILWR) : 1.;
const double P=vecMeteo[ii](MeteoData::P);
if(P==IOUtils::nodata)
if (P==IOUtils::nodata)
sun.calculateRadiation(TA, RH, albedo);
else
sun.calculateRadiation(TA, RH, P, albedo);
double toa, direct, diffuse;
sun.getHorizontalRadiation(toa, direct, diffuse);