56typedef map<string, vector <double> >
DataMap;
57typedef pair<string, vector <double> >
DataPair;
83 for(
int i=0;i<fTIds.size();i++){
84 if(fTIds[i]==forTypeId_h)
return i;
99 vector<string> childs;
101 if(
forTypes[i].ereditatedFrom==forTypeId_h) {
102 childs.push_back(
forTypes[i].forTypeId);
112 for(
int i=0;i<fTIds.size();i++){
123 vector<string> parents;
125 string parent =
forTypes[i].ereditatedFrom;
126 if(!
inVector(parent,parents) && parent !=
""){
127 parents.push_back(parent);
138 if(
forTypes[i].ereditatedFrom==forTypeId_h) {
147 vector<string> toReturn;
149 for(
int i=0;i<table.
nrecords();i++){
150 string scenarioName = table.
getData(i,
"id");
151 toReturn.push_back(scenarioName);
160 for(
int i=0;i<scenarios.size();i++){
161 if (currentScenario == scenarios[i]){
165 msgOut(
MSG_CRITICAL_ERROR,
"function getScenarioIndex() didn't found the current scenarioName within those returned by getScenarios().");
173 for(
int i=0;i<table.
nrecords();i++){
174 string recordScenarioName = table.
getData(i,
"id");
175 if (recordScenarioName == choosenScenario){
198 for (
int i=0; i< table.
nrecords();i++){
201 string type = table.
getData(i,
"type");
203 string region_s= table.
getData(i,
"region");
206 vector <string> values;
207 for (
int z=0;z<nheaders-4;z++){
208 string toSearch =
"value_"+
i2s(z);
209 string value = table.
getData(i,toSearch);
211 values.push_back(value);
228 msgOut(
MSG_CRITICAL_ERROR,
"Scenario-specific settings has been indicated to be loaded from BOTH from the spreadsheet and a file. Choose one of them.");
240 for(
int i=0; i< table.
nrecords(); i++){
241 string name = table.
getData(i,
"name");
242 string stype = table.
getData(i,
"type");
244 string region_s= table.
getData(i,
"region");
246 string comment = table.
getData(i,
"comment");
247 vector <string> values;
248 for (
int z=0;z<nheaders-4;z++){
249 string toSearch =
"value_"+
i2s(z);
250 string value = table.
getData(i,toSearch);
252 values.push_back(value);
285 msgOut(
MSG_ERROR,
"I already have setting "+name_h+
".. Nothing is added..");
299 vector <string> values;
300 values.push_back(value_h);
301 addSetting(name_h, values, type_h, comment_h);
320 for (
int i=0; i< table.
nrecords();i++){
335 vector<ModelRegion*> kids;
367 vector <int> toReturn;
370 if( (!excludeResidual) || (!
regionsVector[i].getIsResidual())){
380 vector <ModelRegion*> toReturn;
382 if( (!excludeResidual) || (!
regionsVector[i].getIsResidual())){
389vector < vector <int> >
391 vector < vector <int> > toReturn;
393 for(uint i=0;i<l1regIds.size();i++){
394 vector<int> l2ChildrenIds;
396 vector<ModelRegion*> l2Childrens = l1Region->
getChildren(excludeResidual);
397 for(uint j=0;j<l2Childrens.size();j++){
398 l2ChildrenIds.push_back(l2Childrens[j]->getRegId());
400 if(l2ChildrenIds.size()){
401 toReturn.push_back(l2ChildrenIds);
416 for(uint i=0; i<3; i++){
418 for(uint j=0;j<regIds.size();j++){
420 if(reg->
getRegSName()==regSName_h) {
return regIds[j];}
431 vector <string> toReturn;
432 for(uint i=0;i<
forTypes.size();i++){
434 toReturn.push_back(
forTypes[i].forTypeId);
477 msgOut(
MSG_CRITICAL_ERROR,
"In getMaxYearUsableDeathTimber() I has been asked of a combination that I don't know how to handle.");
485 for (
int i=0; i< table.
nrecords();i++){
486 vector <double> values;
487 for (
int z=0;z<nheaders-4;z++){
488 string toSearch =
"value_"+
i2s(z);
489 string value = table.
getData(i,toSearch);
491 values.push_back(
s2d(value));
495 forDataMap.insert(std::pair<
string, vector<double> >(keys, values));
506 for(
int i=0; i< table.
nrecords(); i++){
509 vector <double> values;
510 for (
int z=0;z<nheaders-4;z++){
511 string toSearch =
"value_"+
i2s(z);
512 string value = table.
getData(i,toSearch);
514 values.push_back(
s2d(value));
517 map <string, vector < double > >::iterator p;
525 forDataMap.insert(std::pair<
string, vector<double> >(key, values));
537 for (
int i=0; i< table.
nrecords();i++){
543 vector <double> values;
544 for (
int z=0;z<nheaders-4;z++){
545 string toSearch =
"value_"+
i2s(z);
546 string value = table.
getData(i,toSearch);
548 values.push_back(
s2d(value));
554 prodDataMap.insert(std::pair<
string, vector<double> >(keys, values));
568 for(
int i=0; i< table.
nrecords(); i++){
577 vector <double> values;
578 for (
int z=0;z<nheaders-4;z++){
579 string toSearch =
"value_"+
i2s(z);
580 string value = table.
getData(i,toSearch);
582 values.push_back(
s2d(value));
604 map <string, vector < double > >::iterator p;
612 prodDataMap.insert(std::pair<
string, vector<double> >(key, values));
619 msgOut(
MSG_DEBUG,
"Loading forest resource to primary products io matrix..");
621 for (
int i=0; i< table.
nrecords();i++){
638 for (
int i=0; i< table.
nrecords();i++){
650 for (
int i=0; i< table.
nrecords();i++){
665 msgOut(
MSG_DEBUG,
"Loading (but not yet applying) reclassification rules..");
667 for (
int i=0; i< table.
nrecords();i++){
684 for (
int i=0; i< table.
nrecords();i++){
691 vector <double> values;
692 for (
int z=0;z<nheaders-4;z++){
693 string toSearch =
"year_"+
i2s(z);
694 string value = table.
getData(i,toSearch);
696 values.push_back(
s2d(value));
712 for (
int i=0; i< table.
nrecords();i++){
719 vector <double> values;
720 for (
int z=0;z<nheaders-4;z++){
721 string toSearch =
"year_"+
i2s(z);
722 string value = table.
getData(i,toSearch);
724 values.push_back(
s2d(value));
755 string parName,prod,freeDim,
forType,diamClass, key;
758 vector <string> keysToRemove;
763 keysToRemove.clear();
767 msgOut(
MSG_CRITICAL_ERROR,
"Forest variable has a unknown region code If you want not to model a region, set residual=true.: "+parName+
"\t"+
i2s(regId));
770 if(
getRegion(regId)->getRegLevel() == 0){
772 for(uint j=0;j<childs.size();j++){
776 toBeAdded.insert(
DataPair(key,p->second));
779 keysToRemove.push_back(p->first);
782 forDataMap.insert(toBeAdded.begin(),toBeAdded.end());
783 for(uint i=0;i<keysToRemove.size();i++){
784 DataMap::iterator rem =
forDataMap.find(keysToRemove[i]);
795 keysToRemove.clear();
799 msgOut(
MSG_CRITICAL_ERROR,
"Forest variable has a unknown region code If you want not to model a region, set residual=true.: "+parName+
"\t"+
i2s(regId));
802 if(
getRegion(regId)->getRegLevel() == 1){
804 for(uint j=0;j<childs.size();j++){
808 toBeAdded.insert(
DataPair(key,p->second));
811 keysToRemove.push_back(p->first);
814 forDataMap.insert(toBeAdded.begin(),toBeAdded.end());
815 for(uint i=0;i<keysToRemove.size();i++){
816 DataMap::iterator rem =
forDataMap.find(keysToRemove[i]);
824 keysToRemove.clear();
828 msgOut(
MSG_CRITICAL_ERROR,
"Product variable has a unknown region code If you want not to model a region, set residual=true.: "+parName+
"\t"+
i2s(regId));
831 if(
getRegion(regId)->getRegLevel() == 0){
833 for(uint j=0;j<childs.size();j++){
837 toBeAdded.insert(
DataPair(key,p->second));
842 keysToRemove.push_back(p->first);
845 prodDataMap.insert(toBeAdded.begin(),toBeAdded.end());
846 for(uint i=0;i<keysToRemove.size();i++){
847 DataMap::iterator rem =
prodDataMap.find(keysToRemove[i]);
856 keysToRemove.clear();
858 string debug = p->first;
861 msgOut(
MSG_CRITICAL_ERROR,
"Product variable has a unknown region code If you want not to model a region, set residual=true.: "+parName+
"\t"+
i2s(regId));
864 if(
getRegion(regId)->getRegLevel() == 1){
866 for(uint j=0;j<childs.size();j++){
870 toBeAdded.insert(
DataPair(key,p->second));
875 keysToRemove.push_back(p->first);
878 prodDataMap.insert(toBeAdded.begin(),toBeAdded.end());
879 for(uint i=0;i<keysToRemove.size();i++){
880 DataMap::iterator rem =
prodDataMap.find(keysToRemove[i]);
897 if(
reclRules[z].regId == childs[j]->getRegId()
907 RR.
regId = childs[j]->getRegId();
930 if(
reclRules[z].regId == childs[j]->getRegId()
940 RR.
regId = childs[j]->getRegId();
967 for(uint j=0;j<debugRegions.size();j++){
992 if (strlen(output_dirname_h)==0){
1021 vector <int> regIds;
1023 if(regId_h ==
WORLD){
1024 regIds.push_back(
WORLD);
1025 }
else if (
getRegion(regId_h)->getRegLevel()==1){
1026 regIds.push_back(regId_h);
1027 regIds.push_back(
WORLD);
1028 }
else if (
getRegion(regId_h)->getRegLevel()==2) {
1029 regIds.push_back(regId_h);
1030 regIds.push_back(
getRegion(regId_h)->getParRegId());
1031 regIds.push_back(
WORLD);
1037 for (uint j=0; j<regIds.size();j++){
1038 int regId = regIds[j];
1054 msgOut(
MSG_CRITICAL_ERROR,
"Error calling getBaseData() for "+ name_h +
". No setting option or macro data found with this name.");
1074 vector <int> regIds;
1075 if(regId_h ==
WORLD){
1076 regIds.push_back(
WORLD);
1077 }
else if(
getRegion(regId_h)->getRegLevel()==1){
1078 regIds.push_back(regId_h);
1079 regIds.push_back(
WORLD);
1080 }
else if (
getRegion(regId_h)->getRegLevel()==2) {
1081 regIds.push_back(regId_h);
1082 regIds.push_back(
getRegion(regId_h)->getParRegId());
1083 regIds.push_back(
WORLD);
1088 for (uint j=0; j<regIds.size();j++){
1089 int regId = regIds[j];
1098 msgOut(
MSG_CRITICAL_ERROR,
"Error calling getVectorBaseData() for "+ name_h +
". No setting option or macro data found with this name.");
1099 vector <string> toReturn;
1176 std::string directory;
1177 std::string filename;
1178 std::string filename_complete;
1187 return filename_complete;
1198 vector <string> toReturn;
1216ModelData::getProdData(
const string &type_h,
const int& regId_h,
const string &prodId_h,
const int& year,
const string &freeDim_h) {
1219 vector <int> regIds;
1221 DataMap::const_iterator p;
1224 vector <string> products;
1225 bool exactMatch=
true;
1231 }
else if (prodId_h ==
PROD_ALL || prodId_h ==
""){
1233 products.push_back(
"");
1235 products.push_back(prodId_h);
1237 if(freeDim_h==
"") exactMatch=
false;
1240 if(
getRegion(regId_h)->getRegLevel()==2){
1241 regIds.push_back(regId_h);
1242 }
else if (
getRegion(regId_h)->getRegLevel()==1) {
1249 int regIdsS = regIds.size();
1252 for(uint r=0;r<regIdsS;r++){
1253 for(uint i=0;i<products.size();i++){
1255 if (!exactMatch && key.size () > 0) key.resize (key.size () - 1);
1263 msgOut(
errorLevel,
"Error in getProdData: no combination found for "+type_h+
", "+
i2s(regId_h)+
", "+prodId_h+
", "+
i2s(year)+
", "+freeDim_h+
". Returning 0, but double check that this is ok for your model.");
1281ModelData::getForData(
const string &type_h,
const int& regId_h,
const string &forType_h,
const string &freeDim_h,
const int& year){
1283 vector <string> dClasses;
1284 vector <string> fTypes;
1286 DataMap::const_iterator p;
1291 if (forType_h ==
FT_ALL){
1293 fTypes.push_back(
"");
1295 fTypes.push_back(forType_h);
1299 dClasses.push_back(
"");
1305 dClasses.push_back(freeDim_h);
1308 if(
getRegion(regId_h)->getRegLevel()==2){
1309 regIds.push_back(regId_h);
1310 }
else if (
getRegion(regId_h)->getRegLevel()==1) {
1317 int regIdsS = regIds.size();
1320 for(uint r=0;r< regIds.size();r++){
1321 for(uint i=0;i<dClasses.size();i++){
1322 for (uint y=0;y<fTypes.size();y++){
1332 msgOut(
errorLevel,
"Error in getForData(): no combination found for "+type_h+
", "+
i2s(regId_h)+
", "+forType_h+
", "+
i2s(year)+
", "+freeDim_h+
". Returning 0, but double check that this is ok for your model.");
1352ModelData::setProdData(
const double& value_h,
const string &type_h,
const int& regId_h,
const string &prodId_h,
const int& year,
const bool& allowCreate,
const string &freeDim_h){
1356 DataMap::const_iterator p;
1357 vector <string> products;
1366 products.push_back(prodId_h);
1370 if(
getRegion(regId_h)->getRegLevel()==2){
1371 regIds.push_back(regId_h);
1372 }
else if (
getRegion(regId_h)->getRegLevel()==1) {
1381 bool tempFound =
false;
1383 for(uint r=0;r< regIds.size();r++){
1384 for(uint i=0;i<products.size();i++){
1387 if(tempFound) found =
true;
1393 msgOut(
MSG_CRITICAL_ERROR,
"Error in setProdData: no combination found for "+type_h+
", "+
i2s(regId_h)+
", "+prodId_h+
", "+
i2s(year)+
", "+freeDim_h+
". You can allow new variables to be created using the \"allowCreate\" flag.");
1395 for(uint r=0;r< regIds.size();r++){
1396 for(uint i=0;i<products.size();i++){
1398 vector <double> values;
1412ModelData::setForData(
const double& value_h,
const string &type_h,
const int& regId_h,
const string &forType_h,
const string &freeDim_h,
const int& year,
const bool& allowCreate){
1415 vector <string> dClasses;
1416 vector <string> fTypes;
1418 DataMap::const_iterator p;
1420 bool tempFound =
false;
1422 if (forType_h ==
FT_ALL){
1425 fTypes.push_back(forType_h);
1435 dClasses.push_back(freeDim_h);
1439 if(
getRegion(regId_h)->getRegLevel()==2){
1440 regIds.push_back(regId_h);
1441 }
else if (
getRegion(regId_h)->getRegLevel()==1) {
1448 int regIdsS = regIds.size();
1450 for(uint r=0;r< regIds.size();r++){
1451 for(uint i=0;i<dClasses.size();i++){
1452 for (uint y=0;y<fTypes.size();y++){
1455 if(tempFound) found =
true;
1462 msgOut(
MSG_CRITICAL_ERROR,
"Error in setForData: no combination found for "+type_h+
", "+
i2s(regId_h)+
", "+forType_h+
", "+
i2s(year)+
", "+freeDim_h+
". You can allow new variables to be created using the \"allowCreate\" flag.");
1464 for(uint r=0;r< regIds.size();r++){
1465 for(uint i=0;i<dClasses.size();i++){
1466 for (uint y=0;y<fTypes.size();y++){
1468 vector <double> values;
1489 if(dated_vector.size() > position) {
1490 return dated_vector[position];
1491 }
else if (dated_vector.size() > 0 ){
1493 return dated_vector[dated_vector.size()-1];
1495 msgOut(
MSG_CRITICAL_ERROR,
"Error in getTimedData: requested value doesn't have any value, even on the first position(year)!");
1510 int originalVectorSize = dated_vector.size();
1511 if(dated_vector.size() > position) {
1512 dated_vector[position]=value_h;
1516 for(uint i=0;i<position-originalVectorSize+1;i++){
1517 dated_vector.push_back(value_h);
1519 if(position-originalVectorSize > 0 ){
1520 msgOut(MSG_LEVEL,
"setTimedData: a dated vector has been filled several years ("+
i2s(1+position-originalVectorSize)+
") with incoming values to reach desidered position in time.");
1528 msgOut(
MSG_INFO,
"Loading input files (this can take a few minutes)...");
1535 std::mt19937 localgen(time(0));
1536 std::uniform_int_distribution<> dis(10, 1000000);
1537 int randomNumber = dis(localgen);
1546 if(oQtDir.exists()){
1549 if(deleted){
msgOut(
MSG_DEBUG,
"Correctly deleted old temporary data");}
1550 else {
msgOut(
MSG_WARNING,
"I could not delete old temporary data dir (hopefully we'll overrite the input files)");}
1553 if (!QFile::exists(iFile))
1555 cout <<
"File does not exist." << endl << endl;
1563 cout <<
"Failed to open archive: " << uz.
formatError(ec).toLatin1().data() << endl << endl;
1569 cout <<
"Extraction failed: " << uz.
formatError(ec).toLatin1().data() << endl << endl;
1589 for(uint i=0;i<tables.size();i++){
1590 string tableName = tables[i].getStringAttributeByName(
"name");
1592 if( (tableName ==
"forData" || tableName ==
"prodData") && QFile::exists(forDataCachedFilename.c_str()) ) {
1593 msgOut(
MSG_INFO,
"Attenction, using cached data (csv) for "+tableName);
1598 LLData data(
MTHREAD,tables[i].getStringAttributeByName(
"name"));
1599 vector <InputNode> rows = tables[i].getNodesByName(
"table-row",
MSG_NO_MSG,
true);
1600 if(rows.size()<2)
continue;
1602 vector <InputNode> cells = rows[0].getNodesByName(
"table-cell",
MSG_NO_MSG,
true);
1603 for (uint y=0; y<cells.size(); y++){
1605 if( cells[y].hasAttributeByName(
"number-columns-repeated")){
1606 repeated = cells[y].getIntAttributeByName(
"number-columns-repeated");
1608 for (
int q=0;q<repeated;q++){
1609 if( !cells[y].hasChildNode(
"p") ){
1612 data.
headers.push_back(cells[y].getNodeByName(
"p",
MSG_NO_MSG,
true).getStringContent());
1617 for (uint j=1; j<rows.size();j++){
1619 vector <InputNode> cells = rows[j].getNodesByName(
"table-cell",
MSG_NO_MSG,
true);
1621 if (cells.size()<1)
continue;
1622 vector<string> record;
1624 int childCount = cells[0].getChildNodesCount();
1625 if (childCount == 0 || !cells[0].hasChildNode(
"p"))
continue;
1626 string fistCol = cells[0].getNodeByName(
"p",
MSG_NO_MSG,
true).getStringContent();
1628 z = fistCol.find(
"#");
1629 if( z!=string::npos && z == 0)
continue;
1630 for (uint y=0; y<cells.size(); y++){
1632 if( cells[y].hasAttributeByName(
"number-columns-repeated")){
1633 repeated = cells[y].getIntAttributeByName(
"number-columns-repeated");
1635 for (
int q=0;q<repeated;q++){
1636 if( !cells[y].hasChildNode(
"p") ){
1637 record.push_back(
"");
1641 if(cells[y].getStringAttributeByName(
"value-type")==
"float"){
1642 record.push_back(cells[y].getStringAttributeByName(
"value"));
1644 record.push_back(cells[y].getNodeByName(
"p",
MSG_NO_MSG,
true).getStringContent());
1649 data.
records.push_back(record);
1683 if(oQtDir.exists()){
1686 if(deleted){
msgOut(
MSG_DEBUG,
"Correctly deleted old temporary data");}
1687 else {
msgOut(
MSG_WARNING,
"I could not delete old temporary data dir (hopefully we'll overrite the input files)");}
1733 QFile file(fileName.c_str());
1734 if (!file.open(QFile::ReadOnly)) {
1737 QTextStream in(&file);
1740 while (!in.atEnd()) {
1741 QString line = in.readLine();
1742 if(line==
"")
continue;
1743 QStringList fields = line.split(
';');
1744 bool emptyLine =
true;
1746 for(uint i =0;i<fields.size();i++){
1747 data.
headers.push_back(fields.at(i).toStdString());
1750 vector<string> record ;
1751 unsigned int z = fields[0].toStdString().find(
"#");
1752 if( z!=string::npos && z == 0)
continue;
1753 for(uint i =0;i<fields.size();i++){
1754 string field = fields.at(i).toStdString();
1755 replace(field.begin(), field.end(),
',',
'.');
1756 record.push_back(field);
1757 if(field!=
"") emptyLine =
false;
1759 if(!emptyLine){data.
records.push_back(record);};
1770 bool deleted =
false;
1773 dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
1774 QFileInfoList list = dir.entryInfoList();
1775 deleted = dir.rmdir(dir.absolutePath());
1776 if (deleted)
return true;
1778 for (
int i = 0; i < list.size(); ++i) {
1779 QFileInfo fileInfo = list.at(i);
1780 if (fileInfo.isFile()){
1782 QFile targetFile(fileInfo.absoluteFilePath());
1783 bool fileDeleted = targetFile.remove();
1788 else if (fileInfo.isDir()){
1790 delDir(fileInfo.absoluteFilePath());
1791 dir.rmdir(fileInfo.absoluteFilePath());
1795 deleted = dir.rmdir(dir.absolutePath());
1796 if (deleted)
return true;
1806 msgOut(debugLevel,
"No table found with name "+tableName_h);
1822 DataMap::const_iterator i;
1824 i = map.lower_bound(search_for);
1825 for(;i != map.end();i++){
1826 const string& key = i->first;
1827 if (key.compare(0, search_for.size(), search_for) == 0) {
1834 i = map.find(search_for);
1845 double toReturn = 0;
1847 DataMap::const_iterator i;
1849 i = map.lower_bound(search_for);
1850 for(;i != map.end();i++){
1851 const string& key = i->first;
1852 if (key.compare(0, search_for.size(), search_for) == 0) {
1860 i = map.find(search_for);
1874 DataMap::iterator i;
1876 i = map.lower_bound(search_for);
1877 for(;i != map.end();i++){
1878 const string& key = i->first;
1879 if (key.compare(0, search_for.size(), search_for) == 0) {
1887 i = map.find(search_for);
1905 int parNameDelimiter = key.find(
"#",0);
1906 int regIdDelimiter = key.find(
"#",parNameDelimiter+1);
1907 int prodDelimiter = key.find(
"#",regIdDelimiter+1);
1908 int freeDimDelimiter = key.find(
"#",prodDelimiter+1);
1909 if (freeDimDelimiter == string::npos){
1912 parName.assign(key,0,parNameDelimiter);
1913 string regIdString=
"";
1914 regIdString.assign(key,parNameDelimiter+1,regIdDelimiter-parNameDelimiter-1);
1915 regId =
s2i(regIdString);
1916 prod.assign(key,regIdDelimiter+1,prodDelimiter-regIdDelimiter-1);
1917 freeDim.assign(key,prodDelimiter+1,freeDimDelimiter-prodDelimiter-1);
1923 int parNameDelimiter = key.find(
"#",0);
1924 int regIdDelimiter = key.find(
"#",parNameDelimiter+1);
1925 int forTypeDelimiter = key.find(
"#",regIdDelimiter+1);
1926 int diamClassDelimiter = key.find(
"#",forTypeDelimiter+1);
1927 if (diamClassDelimiter == string::npos){
1930 parName.assign(key,0,parNameDelimiter);
1931 string regIdString=
"";
1932 regIdString.assign(key,parNameDelimiter+1,regIdDelimiter-parNameDelimiter-1);
1933 regId =
s2i(regIdString);
1934 forType.assign(key,regIdDelimiter+1,forTypeDelimiter-regIdDelimiter-1);
1935 diamClass.assign(key,forTypeDelimiter+1,diamClassDelimiter-forTypeDelimiter-1);
1972 if(years_h<0)
return 0.;
1973 if(years_h==0)
return amount_h;
1975 double eai = amount_h * ir / (pow(1.0+ir,years_h)-1.0);
2005 int ceiledYear = ceil(years_h);
2013 struct dirent *dirp;
2014 if((dp = opendir(dir.c_str())) == NULL) {
2019 while ((dirp = readdir(dp)) != NULL) {
2020 string filename = dirp->d_name;
2022 (filter !=
"" && filename.substr(filename.find_last_of(
".")) == filter)
2023 || (filter ==
"" && filename.substr(filename.find_last_of(
".") + 1) !=
"")
2025 files.push_back(
string(dirp->d_name));
2035 vector<pathRule*> toReturn;
2054vector < vector <int> >
2058 vector < vector <int> > toReturn;
2059 int nCombs = pow(2,nItems);
2061 for (uint i=0; i<nCombs; i++){
2062 vector<int> thisCombItems;
2063 for(uint j=0;j<nItems;j++){
2066 thisCombItems.push_back(j);
2069 toReturn.push_back(thisCombItems);
2078 double toReturn = 0.0;
2080 for (uint i=0;i<forTypesIds.size();i++){
2081 string ft = forTypesIds[i];
2084 bool possible =
false;
2086 for (
int p=0; p<primProd_h.size();p++){
2087 string primProd = primProd_h[p];
2094 for(
int y=year_h;y>year_h-maxYears;y--){
2106 vector<int> allocableProductIds;
2113 if (request_year-harvesting_year < maxYears){
2114 allocableProductIds.push_back(p);
2118 return allocableProductIds;
2125 double toReturn = 0.0;
2129 for (uint i=0;i<forTypesIds.size();i++){
2130 string ft = forTypesIds[i];
2133 bool possible =
false;
2134 for (
int p=0; p<primProd_h.size();p++){
2135 string primProd = primProd_h[p];
2141 for (uint p=0;p<regPx.size();p++){
2142 Pixel* px = regPx[p];
2167 for (uint i=0;i<
records.size();i++){
2168 if(
records[i].size() != hsize){
2169 vector <string> record =
records[i];
2174 for (
int i=
headers.size()-1;i>=0;i--){
2177 for (uint j=0;j<
records.size();j++){
2189 msgOut(debugLevel,
"Requested position "+
i2s(pos_h)+
" too high! Not enought records !!");
2193 for (uint i=0;i<hsize;i++){
2196 msgOut(debugLevel,
"Header string "+header_h+
" not found!");
@ WORLD
Request something that is not region-specific.
@ DATA_NOW
The required data is for the current year.
#define PROD_PRI
Primary products.
#define PROD_ALL
All primary and transformed products.
#define FT_ALL
All forest types.
@ TYPE_DOUBLE
The required data is a double.
@ TYPE_BOOL
The required data is a bool.
@ TYPE_INT
The required data is an integer.
@ TYPE_STRING
The required data is a string.
#define DIAM_ALL
All diameter classes.
#define PROD_SEC
Secondary products.
#define DIAM_PROD
Diameter classes used for production (e.g. excluded the first one)
#define DIAM_FIRST
First diameter class (NOT used for production)
@ MSG_CRITICAL_ERROR
Print an error message and stop the model.
@ MSG_ERROR
Print an ERROR message, but don't stop the model.
@ MSG_DEBUG
Print a debug message, normally filtered out.
@ MSG_WARNING
Print a WARNING message.
@ MSG_INFO
Print an INFO message.
@ MSG_NO_MSG
Do not actually output any message.
map< string, vector< double > > DataMap
pair< string, vector< double > > DataPair
map< string, vector< double > > DataMap
pair< string, vector< double > > DataPair
ThreadManager * MTHREAD
Pointer to the Thread manager.
int s2i(const string &string_h) const
string to integer conversion
V findMap(const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V ¬FoundValue=numeric_limits< V >::min()) const
Lookup a map for a value. Return the value starting from the key.
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
bool inVector(const K &element, const vector< K > &v)
bool s2b(const string &string_h) const
string to bool conversion
int getType(const string &type_h) const
Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2))
string i2s(const int &int_h) const
integer to string conversion
double s2d(const string &string_h) const
string to double conversion
Low level data. XML input is reversed here after unzipping oocalc file and parsing content....
LLData(ThreadManager *MTHREAD_h, string tableName_h)
string getData(const int &pos_h, const string &header_h, const int &debugLevel=MSG_CRITICAL_ERROR) const
vector< vector< string > > records
bool regionExist(const int ®Id_h) const
vector< string > getForTypeParents()
forType * getForType(int position)
vector< pathRule > pathRules
Vector of pathogen rules.
vector< string > allProducts
vector< int > getIntVectorSetting(const string &name_h, int reg=WORLD) const
vector< int > getAllocableProductIdsFromDeathTimber(const int ®Id_h, const string &ft, const string &dc, const int &harvesting_year, int request_year=DATA_NOW)
Returns the ids of the primary products that is possible to obtain using the timber recorded death in...
double getAvailableAliveTimber(const vector< string > &primProd_h, int regId_h)
Returns the timber available for a given set of primary products as stored in the px->vol_l vector.
void cacheSettings()
Called after input reading, it fix frequently used data;.
void setProdData(const double &value_h, const string &type_h, const int ®Id_h, const string &prodId_h, const int &year=DATA_NOW, const bool &allowCreate=false, const string &freeDim_h="")
int getForTypeCounter(string &forTypeId_h, bool all=false)
By default it doesn't return forTypes used only as input.
double dataMapGetValue(const DataMap &map, const string &search_for, const int &year_h, const bool &exactMatch=true)
void setTimedData(const double &value_h, vector< double > &dated_vector, const int &year_h, const int &MSG_LEVEL=MSG_WARNING)
vector< string > getScenarios()
vector< IFiles > iFilesVector
List of all input files. Simple (struct)
void setScenarioData()
Set the infos about this scenario (long description and overriding tables)
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
vector< ModelRegion > regionsVector
Vector of modelled regions.
vector< bool > getBoolVectorSetting(const string &name_h, int reg=WORLD) const
vector< pathRule * > getPathMortalityRule(const string &forType, const string &dC)
Return the pathogen mortality rule(s) associated with a given ft and dc (plural as more than a single...
string makeKeyProdData(const string &parName, const string ®Id, const string &prod, const string &freeDim="") const
string makeKeyForData(const string &parName, const string ®Id, const string &forType, const string &diamClass) const
void setDefaultSettings()
void setScenarioProdData()
void applyDebugMode()
Works only a specified subset of regions and products.
vector< forType > forTypes
Vector of forest types.
void setDefaultPathogenRules()
map< iisskey, double > deathTimberInventory
Map that register the death of biomass still usable as timber by year, l2_region, forest type and dia...
double getDoubleSetting(const string &name_h, int position=0, int reg=WORLD) const
void setScenarioPathogenRules()
vector< string > getForTypeIds(bool all=false)
By default it doesn't return forTypes used only as input.
vector< vector< int > > createCombinationsVector(const int &nItems)
Return a vector containing any possible combination of nItems items (including any possible subset)....
string getBaseData(const string &name_h, int type_h, int position=0, int regId_h=WORLD)
InputNode mainDocument
For each agricultural soil type (as defined in the setting "agrLandTypes") this list define the objec...
vector< int > getForTypeChilds_pos(const string &forTypeId_h, bool all=false)
void setDefaultProdData()
string getForTypeParentId(const string &forTypeId_h)
vector< string > getStringVectorSetting(const string &name_h, int reg=WORLD) const
bool delDir(QString dirname)
Recursivelly delete a directory.
vector< double > getDoubleVectorSetting(const string &name_h, int reg=WORLD) const
vector< string > getForTypeChilds(const string &forTypeId_h)
vector< string > priProducts
void setScenarioProductResourceMatrixLink()
void setReclassificationRules()
const int getMaxYearUsableDeathTimber()
const double getForData(const string &type_h, const int ®Id_h, const string &forType_h, const string &freeDim_h, const int &year=DATA_NOW)
void setScenarioSettings()
vector< LLData > LLDataVector
Vector of Low Level Data.
LLData getTableFromFile(string tablename, string filename_h)
Load and return a data table from a file (instead that from a spreadsheet sheet)
void setOutputDirectory(const char *output_dirname_h)
vector< int > getRegionIds(int level_h, bool excludeResidual=true)
ModelRegion * getRegion(int regId_h)
int getNForTypesChilds(const string &forTypeId_h)
vector< ModelRegion * > getAllRegions(bool excludeResidual=true)
void unpackKeyForData(const string &key, string &parName, int ®Id, string &forType, string &diamClass) const
string getFilenameByType(string type_h)
bool tempBool
a temporary bool variable used for various functions
int getIntSetting(const string &name_h, int position=0, int reg=WORLD) const
vector< string > getDiameterClasses(bool productionOnly=false)
void setDefaultProductResourceMatrixLink()
void applyOverrides()
Cancel all reg1 level data and trasform them in reg2 level if not already existing.
void setForData(const double &value_h, const string &type_h, const int ®Id_h, const string &forType_h, const string &freeDim_h, const int &year=DATA_NOW, const bool &allowCreate=false)
vector< string > secProducts
void unpackKeyProdData(const string &key, string &parName, int ®Id, string &prod, string &freeDim) const
void addSetting(string name_h, vector< string > values_h, int type_h, string comment_h)
double getTimedData(const vector< double > &dated_vector, const int &year_h) const
Return the value for the specified year in a timelly ordered vector, taking the last value if this is...
string getStringSetting(const string &name_h, int position=0, int reg=WORLD) const
bool valueFoundBool
a bool used in getForData() and getProdData() to communicate they didn't found a variable
string regId2RegSName(const int ®Id_h) const
int regSName2RegId(const string ®SName_h) const
const bool assessProdPossibility(const string &prod_h, const string &forType_h, const string &dClass_h)
A simple function to assess if a specified product can be made by a certain forest type and diameter ...
void loadInput()
Unzip the OpenOffice input file (NEW 2008.05.13)
vector< reclRule > reclRules
Vector of reclassification rules.
vector< string > getVectorBaseData(const string &name_h, int type_h, int regId_h=WORLD)
map< string, vector< double > > prodDataMap
Product data.
const double getProdData(const string &type_h, const int ®Id_h, const string &prodId_h, const int &year=DATA_NOW, const string &freeDim_h="")
map< string, vector< double > > forDataMap
Forestry data.
LLData getTable(string tableName_h, int debugLevel=MSG_CRITICAL_ERROR)
bool dataMapCheckExist(const DataMap &map, const string &search_for, const bool &exactMatch=true) const
int getFilenamesByDir(const string &dir, vector< string > &files, const string &filter="")
Return a list of files in a directory.
ModelData(ThreadManager *MTHREAD_h)
void setScenarioForData()
double calculateAnnualisedEquivalent(const double &amount_h, const int &years_h, const double &ir) const
Calculate the annual equivalent flow.
int dataMapSetValue(DataMap &map, const string &search_for, const double &value_h, const int &year_h, const bool &exactMatch=true)
vector< string > diamClasses
Diameter classes.
vector< forToProd > forToProdVector
Vector of coefficients from forest resources to primary products.
double getAvailableDeathTimber(const vector< string > &primProd_h, int regId_h, int year_h)
Returns the timber available for a given set of primary products as stored in the deathTimberInventor...
vector< BasicData > programSettingsVector
Setting data. Simple (struct)
vector< Pixel * > getMyPixels()
vector< ModelRegion * > getChildren(bool excludeResidual=true)
Returns a pointer to the parent regions.
string getRegSName() const
int getNChildren(bool excludeResidual=true)
vector< double > avalCoef
Availability (of wood resources) coefficient. A [0,1] coefficient (new: by forest type) that reduces ...
vector< vector< double > > vol_l
store the volumes of the previous year
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
string getInputFileName()
string getBaseDirectory()
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
ModelData * MD
the model data object
void setOutputDirName(string outputDirname_h)
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
ErrorCode openArchive(const QString &filename)
QString formatError(UnZip::ErrorCode c) const
ErrorCode extractAll(const QString &dirname, ExtractionOptions options=ExtractPaths)
Class to provide a simple integer-integer-string-string key in std maps.
Basic data units (struct)
vector< string > values
Values are stored as "string" because we don't yet know at this point if they are string,...
IO production matrix between the forest resources and the primary products (struct)
int maxYears
The maximum year for a tree collapse that this product can be harvested from. E.g....
Pathogen rule (how pathogen presense influence mortality) for a given forest type and diameter class ...
vector< double > mortCoefficents
Mortality coefficients ordered by number of presence of the pathogen, e.g. first value is the mortali...
double pres_min
Minimum level of presence of the pathogen to be counted as present (tolerance threshold)
string pathId
Pathogen id (name)
IO production matrix between the forest resources and the primary products (struct)