FFSM++ 1.1.0
French Forest Sector Model ++
Loading...
Searching...
No Matches
ModelData Class Reference

Regional data, including macros and settings. More...

#include <ModelData.h>

Inheritance diagram for ModelData:
Collaboration diagram for ModelData:

Public Member Functions

 ModelData (ThreadManager *MTHREAD_h)
 
 ~ModelData ()
 
void loadInput ()
 Unzip the OpenOffice input file (NEW 2008.05.13)
 
LLData getTableFromFile (string tablename, string filename_h)
 Load and return a data table from a file (instead that from a spreadsheet sheet)
 
vector< string > getScenarios ()
 
int getScenarioIndex ()
 
bool delDir (QString dirname)
 Recursivelly delete a directory.
 
void setScenarioData ()
 Set the infos about this scenario (long description and overriding tables)
 
void setDefaultSettings ()
 
void setScenarioSettings ()
 
void createRegions ()
 
void setDefaultForData ()
 
void setScenarioForData ()
 
void setDefaultProdData ()
 
void setScenarioProdData ()
 
void setDefaultProductResourceMatrixLink ()
 
void setScenarioProductResourceMatrixLink ()
 
void setForestTypes ()
 
void setReclassificationRules ()
 
void setDefaultPathogenRules ()
 
void setScenarioPathogenRules ()
 
void applyOverrides ()
 Cancel all reg1 level data and trasform them in reg2 level if not already existing.
 
void applyDebugMode ()
 Works only a specified subset of regions and products.
 
void setSpace ()
 
string getOutputDirectory () const
 Return a vector of objects that together provide the specified resource in the specified quantity.
 
int getFilenamesByDir (const string &dir, vector< string > &files, const string &filter="")
 Return a list of files in a directory.
 
string getFilenameByType (string type_h)
 
LLData getTable (string tableName_h, int debugLevel=MSG_CRITICAL_ERROR)
 
vector< IFilesgetIFilesVector () const
 
string getBaseDirectory () const
 
ModelRegiongetRegion (int regId_h)
 
bool regionExist (const int &regId_h) const
 
vector< ModelRegion * > getAllRegions (bool excludeResidual=true)
 
vector< int > getRegionIds (int level_h, bool excludeResidual=true)
 
vector< vector< int > > getRegionIds (bool excludeResidual=true)
 
string regId2RegSName (const int &regId_h) const
 
int regSName2RegId (const string &regSName_h) const
 
int getNForTypes ()
 
int getNReclRules ()
 
forTypegetForType (int position)
 
forTypegetForType (string &forTypeId_h)
 
int getForTypeCounter (string &forTypeId_h, bool all=false)
 By default it doesn't return forTypes used only as input.
 
vector< string > getForTypeIds (bool all=false)
 By default it doesn't return forTypes used only as input.
 
string getForTypeParentId (const string &forTypeId_h)
 
vector< string > getForTypeChilds (const string &forTypeId_h)
 
vector< int > getForTypeChilds_pos (const string &forTypeId_h, bool all=false)
 
vector< string > getForTypeParents ()
 
int getNForTypesChilds (const string &forTypeId_h)
 
reclRulegetReclRule (int position)
 
vector< string > getDiameterClasses (bool productionOnly=false)
 
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 class.
 
const int getMaxYearUsableDeathTimber (const string &prod_h, const string &forType_h, const string &dClass_h)
 
const int getMaxYearUsableDeathTimber ()
 
void setErrorLevel (int errorLevel_h)
 
int getErrorLevel ()
 
bool getTempBool ()
 
void setTempBool (bool tempBool_h)
 
bool getValueFoundBool ()
 
void setValueFoundBool (bool valueFoundBool_h)
 
vector< vector< int > > createCombinationsVector (const int &nItems)
 Return a vector containing any possible combination of nItems items (including any possible subset). The returned vector has in each slot the items present in that specific combination.
 
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 smaller than the required position.
 
void setTimedData (const double &value_h, vector< double > &dated_vector, const int &year_h, const int &MSG_LEVEL=MSG_WARNING)
 
int getIntSetting (const string &name_h, int position=0, int reg=WORLD) const
 
double getDoubleSetting (const string &name_h, int position=0, int reg=WORLD) const
 
string getStringSetting (const string &name_h, int position=0, int reg=WORLD) const
 
bool getBoolSetting (const string &name_h, int position=0, int reg=WORLD) const
 
vector< int > getIntVectorSetting (const string &name_h, int reg=WORLD) const
 
vector< double > getDoubleVectorSetting (const string &name_h, int reg=WORLD) const
 
vector< string > getStringVectorSetting (const string &name_h, int reg=WORLD) const
 
vector< bool > getBoolVectorSetting (const string &name_h, int reg=WORLD) const
 
const double getProdData (const string &type_h, const int &regId_h, const string &prodId_h, const int &year=DATA_NOW, const string &freeDim_h="")
 
const double getForData (const string &type_h, const int &regId_h, const string &forType_h, const string &freeDim_h, const int &year=DATA_NOW)
 
void setProdData (const double &value_h, const string &type_h, const int &regId_h, const string &prodId_h, const int &year=DATA_NOW, const bool &allowCreate=false, const string &freeDim_h="")
 
void setForData (const double &value_h, const string &type_h, const int &regId_h, const string &forType_h, const string &freeDim_h, const int &year=DATA_NOW, const bool &allowCreate=false)
 
string makeKeyProdData (const string &parName, const string &regId, const string &prod, const string &freeDim="") const
 
string makeKeyForData (const string &parName, const string &regId, const string &forType, const string &diamClass) const
 
void unpackKeyProdData (const string &key, string &parName, int &regId, string &prod, string &freeDim) const
 
void unpackKeyForData (const string &key, string &parName, int &regId, string &forType, string &diamClass) 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 pathogen could be found)
 
double calculateAnnualisedEquivalent (const double &amount_h, const int &years_h, const double &ir) const
 Calculate the annual equivalent flow.
 
double calculateAnnualisedEquivalent (const double &amount_h, const double &years_h, const double &ir) const
 Transform the double to the highest integer and call calculateAnnualisedEquivalent(double amount_h, int years_h)
 
void setOutputDirectory (const char *output_dirname_h)
 
void setBaseDiretory (string baseDirectory_h)
 
void addSetting (string name_h, vector< string > values_h, int type_h, string comment_h)
 
void addSetting (string name_h, string value_h, int type_h, string comment_h)
 
void cacheSettings ()
 Called after input reading, it fix frequently used data;.
 
int getCachedInitialYear ()
 
void deathTimberInventory_incrOrAdd (const iisskey &thekey, double value_h)
 
void deathTimberInventory_incr (const iisskey &thekey, double value_h)
 
double deathTimberInventory_get (const iisskey &thekey)
 
map< iisskey, double > * getDeathTimberInventory ()
 
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 deathTimberInventory map.
 
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.
 
vector< int > getAllocableProductIdsFromDeathTimber (const int &regId_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 the specific year, ft, dc combination.
 
- Public Member Functions inherited from BaseClass
 BaseClass ()
 
 ~BaseClass ()
 
void msgOut (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log.
 
void msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log.
 
void msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log.
 
int s2i (const string &string_h) const
 string to integer conversion
 
double s2d (const string &string_h) const
 string to double conversion
 
double s2d (const string &string_h, const bool &replaceComma) const
 string to double conversion
 
bool s2b (const string &string_h) const
 string to bool conversion
 
string i2s (const int &int_h) const
 integer to string conversion
 
string d2s (const double &double_h) const
 double to string conversion
 
string b2s (const bool &bool_h) const
 bool to string conversion
 
vector< int > s2i (const vector< string > &string_h) const
 string to integer conversion (vector)
 
vector< double > s2d (const vector< string > &string_h, const bool &replaceComma=false) const
 string to double conversion (vector)
 
vector< bool > s2b (const vector< string > &string_h) const
 string to bool conversion (vector)
 
vector< string > i2s (const vector< int > &int_h) const
 integer to string conversion (vector)
 
vector< string > d2s (const vector< double > &double_h) const
 double to string conversion (vector)
 
vector< string > b2s (const vector< bool > &bool_h) const
 bool to string conversion (vector)
 
int getType (const string &type_h) const
 Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2))
 
void refreshGUI () const
 Ping to periodically return the control to the GUI.
 
template<typename T >
string toString (const T &x) const
 
template<typename T >
stringTo (const std::string &s) const
 
int vSum (const vector< int > &vector_h) const
 
double vSum (const vector< double > &vector_h) const
 
int vSum (const vector< vector< int > > &vector_h) const
 
double vSum (const vector< vector< double > > &vector_h) const
 
void tokenize (const string &str, vector< string > &tokens, const string &delimiter=" ") const
 Tokenize a string using a delimiter (default is space)
 
void untokenize (string &str, vector< string > &tokens, const string &delimiter=" ") const
 
template<typename K , typename V >
findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V &notFoundValue=numeric_limits< V >::min()) const
 Lookup a map for a value. Return the value starting from the key.
 
template<typename K , typename V >
void changeMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Change the value stored in a map given the key and the new value.
 
template<typename K , typename V >
void incrMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Increments a value stored in a map of the specified value, given the key.
 
template<typename K , typename V >
void incrOrAddMapValue (map< K, V > &mymap, const K &key, const V &value)
 Increments a value stored in a map of the specified value, given the key.
 
template<typename K , typename V >
void resetMapValues (map< K, V > &mymap, const V &value)
 Reset all values stored in a map to the specified one.
 
template<typename K , typename V >
map< K, V > vectorToMap (const vector< K > &keys, const V &value=0.0)
 Returns a map built using the given vector and the given (scalar) value as keys/values pairs.
 
template<typename T >
vector< T > positionsToContent (const vector< T > &vector_h, const vector< int > &positions)
 Return a vector of content from a vector and a vector of positions (int)
 
template<typename V >
void debugMap (const map< iisskey, V > &mymap)
 Debug a map.
 
template<typename K , typename V >
void debugMap (const map< K, V > &mymap, const K &key)
 
template<typename K >
int getMaxPos (const vector< K > &v)
 Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima)
 
template<typename K >
int getMinPos (const vector< K > &v)
 Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima)
 
template<typename K >
getMax (const vector< K > &v)
 Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima)
 
template<typename K >
getMin (const vector< K > &v)
 Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima)
 
template<typename K >
double getAvg (const vector< K > &v)
 Returns the average of the elements in the vector.
 
template<typename K >
double getSd (const vector< K > &v, bool sample=true)
 
template<typename K >
int getPos (const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR)
 
template<typename K >
bool inVector (const K &element, const vector< K > &v)
 
double normSample (const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
 Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops).
 
template<typename K >
normSample (normal_distribution< K > &d, std::mt19937 &gen, const K &minval=NULL, const K &maxval=NULL) const
 Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once.
 
template<typename T >
std::string toString (const T &x) const
 

Public Attributes

scenarioData scenario
 

Private Member Functions

string getBaseData (const string &name_h, int type_h, int position=0, int regId_h=WORLD)
 
vector< string > getVectorBaseData (const string &name_h, int type_h, int regId_h=WORLD)
 
bool dataMapCheckExist (const DataMap &map, const string &search_for, const bool &exactMatch=true) const
 
double dataMapGetValue (const DataMap &map, const string &search_for, const int &year_h, const bool &exactMatch=true)
 
int dataMapSetValue (DataMap &map, const string &search_for, const double &value_h, const int &year_h, const bool &exactMatch=true)
 

Private Attributes

string inputFilename
 
string outputDirname
 
string baseDirectory
 
map< string, vector< double > > forDataMap
 Forestry data.
 
map< string, vector< double > > prodDataMap
 Product data.
 
vector< forToProdforToProdVector
 Vector of coefficients from forest resources to primary products.
 
vector< IFilesiFilesVector
 List of all input files. Simple (struct)
 
vector< BasicDataprogramSettingsVector
 Setting data. Simple (struct)
 
vector< LLDataLLDataVector
 Vector of Low Level Data.
 
vector< ModelRegionregionsVector
 Vector of modelled regions.
 
vector< forTypeforTypes
 Vector of forest types.
 
vector< reclRulereclRules
 Vector of reclassification rules.
 
vector< pathRulepathRules
 Vector of pathogen rules.
 
vector< vector< int > > l2r
 Region2 ids.
 
map< iisskey, double > deathTimberInventory
 Map that register the death of biomass still usable as timber by year, l2_region, forest type and diameter class [Mm^3 wood].
 
vector< string > diamClasses
 Diameter classes.
 
int cached_initialYear
 
vector< string > priProducts
 
vector< string > secProducts
 
vector< string > allProducts
 
bool tempBool
 a temporary bool variable used for various functions
 
bool valueFoundBool
 a bool used in getForData() and getProdData() to communicate they didn't found a variable
 
InputNode mainDocument
 For each agricultural soil type (as defined in the setting "agrLandTypes") this list define the objects that can be placed on that soil type.
 
int errorLevel
 

Friends

void Output::printForestData (bool finalFlush)
 
void Output::printProductData (bool finalFlush)
 

Additional Inherited Members

- Protected Attributes inherited from BaseClass
ThreadManagerMTHREAD
 Pointer to the Thread manager.
 

Detailed Description

Regional data, including macros and settings.

All regional data are within this class. It may have linked other data-classes.
On some variables ModelData has just the definition of the objects, but the values may change at the agent-level. This is why each agent has a "personal copy" of them.

Author
Antonello Lobianco

Definition at line 80 of file ModelData.h.

Constructor & Destructor Documentation

◆ ModelData()

ModelData ( ThreadManager MTHREAD_h)

Definition at line 61 of file ModelData.cpp.

61 {
62 MTHREAD = MTHREAD_h;
64 tempBool = true;
65 valueFoundBool = true;
66}
@ MSG_ERROR
Print an ERROR message, but don't stop the model.
Definition BaseClass.h:61
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition BaseClass.h:467
int errorLevel
Definition ModelData.h:244
bool tempBool
a temporary bool variable used for various functions
Definition ModelData.h:239
bool valueFoundBool
a bool used in getForData() and getProdData() to communicate they didn't found a variable
Definition ModelData.h:240

◆ ~ModelData()

~ModelData ( )

Definition at line 68 of file ModelData.cpp.

68 {
69
70}

Member Function Documentation

◆ addSetting() [1/2]

void addSetting ( string  name_h,
string  value_h,
int  type_h,
string  comment_h 
)

Definition at line 298 of file ModelData.cpp.

298 {
299 vector <string> values;
300 values.push_back(value_h);
301 addSetting(name_h, values, type_h, comment_h);
302}
void addSetting(string name_h, vector< string > values_h, int type_h, string comment_h)
Here is the call graph for this function:

◆ addSetting() [2/2]

void addSetting ( string  name_h,
vector< string >  values_h,
int  type_h,
string  comment_h 
)

Definition at line 281 of file ModelData.cpp.

281 {
282
283 for (uint i=0;i<programSettingsVector.size();i++){
284 if (programSettingsVector.at(i).name == name_h){
285 msgOut(MSG_ERROR, "I already have setting "+name_h+".. Nothing is added..");
286 return;
287 }
288 }
289 BasicData SETT;
290 SETT.name = name_h;
291 SETT.values = values_h;
292 SETT.type= type_h;
293 SETT.comment = comment_h;
294 programSettingsVector.push_back(SETT);
295}
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition BaseClass.cpp:50
vector< BasicData > programSettingsVector
Setting data. Simple (struct)
Definition ModelData.h:222
Basic data units (struct)
Definition ModelData.h:267
string name
Definition ModelData.h:268
string comment
Definition ModelData.h:273
vector< string > values
Values are stored as "string" because we don't yet know at this point if they are string,...
Definition ModelData.h:270

Referenced by addSetting().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyDebugMode()

void applyDebugMode ( )

Works only a specified subset of regions and products.

The applyDebugMode flag all level2 regions not in the "debugRegions" option as "residual" (so they are in the map but not in the model code) and remove the primary and secondary products that are not included in the debugPriProducts and debugSecProducts options.

Definition at line 957 of file ModelData.cpp.

957 {
958 if(! getBoolSetting("debugFlag")) return;
959
960 vector <int> debugRegions = getIntVectorSetting("debugRegions");
961 vector <string> debugPriProducts = getStringVectorSetting("debugPriProducts");
962 vector <string> debugSecProducts = getStringVectorSetting("debugSecProducts");
963
964 for(uint i=0;i< regionsVector.size();i++){
965 if (regionsVector[i].getRegLevel()==2){
966 bool found= false;
967 for(uint j=0;j<debugRegions.size();j++){
968 if (debugRegions[j] == regionsVector[i].getRegId()){
969 found = true;
970 break;
971 }
972 }
973 if(!found){ // not in the list to keep
974 regionsVector[i].setIsResidual(true);
975 }
976 }
977 }
978
979 for (uint i=0; i<programSettingsVector.size();i++){
980 if (programSettingsVector.at(i).name == "priProducts"){
981 programSettingsVector.at(i).values = debugPriProducts;
982 } else if (programSettingsVector.at(i).name == "secProducts"){
983 programSettingsVector.at(i).values = debugSecProducts;
984 }
985 }
986
987}
vector< int > getIntVectorSetting(const string &name_h, int reg=WORLD) const
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
vector< ModelRegion > regionsVector
Vector of modelled regions.
Definition ModelData.h:224
vector< string > getStringVectorSetting(const string &name_h, int reg=WORLD) const

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyOverrides()

void applyOverrides ( )

Cancel all reg1 level data and trasform them in reg2 level if not already existing.

Definition at line 749 of file ModelData.cpp.

749 {
750
751 if(!getBoolSetting("applyOverriding")) return;
752 msgOut(MSG_INFO, "Starting regional overriding analysis..");
753
754 DataMap::iterator p;
755 string parName,prod,freeDim,forType,diamClass, key;
756 int regId;
757 DataMap toBeAdded;
758 vector <string> keysToRemove;
759
760
761 //apply override from level 0 to level 1 for forestry data
762 toBeAdded.clear();
763 keysToRemove.clear();
764 for(p=forDataMap.begin();p!=forDataMap.end();p++){
765 unpackKeyForData(p->first,parName,regId,forType,diamClass);
766 if(!regionExist(regId)){
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));
768 continue;
769 }
770 if(getRegion(regId)->getRegLevel() == 0){
771 vector<ModelRegion*> childs = getRegion(regId)->getChildren(false);
772 for(uint j=0;j<childs.size();j++){
773 bool found = false;
774 key = makeKeyForData(parName,i2s(childs[j]->getRegId()),forType,diamClass);
775 if (!dataMapCheckExist(forDataMap,key,true)){
776 toBeAdded.insert(DataPair(key,p->second));
777 }
778 }
779 keysToRemove.push_back(p->first);
780 }
781 }
782 forDataMap.insert(toBeAdded.begin(),toBeAdded.end());
783 for(uint i=0;i<keysToRemove.size();i++){
784 DataMap::iterator rem = forDataMap.find(keysToRemove[i]);
785 if(rem != forDataMap.end()){
786 forDataMap.erase(rem);
787 }
788 }
789
790
791
792
793 //apply override from level 1 to level 2 for forestry data
794 toBeAdded.clear();
795 keysToRemove.clear();
796 for(p=forDataMap.begin();p!=forDataMap.end();p++){
797 unpackKeyForData(p->first,parName,regId,forType,diamClass);
798 if(!regionExist(regId)){
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));
800 continue;
801 }
802 if(getRegion(regId)->getRegLevel() == 1){
803 vector<ModelRegion*> childs = getRegion(regId)->getChildren(false);
804 for(uint j=0;j<childs.size();j++){
805 bool found = false;
806 key = makeKeyForData(parName,i2s(childs[j]->getRegId()),forType,diamClass);
807 if (!dataMapCheckExist(forDataMap,key,true)){
808 toBeAdded.insert(DataPair(key,p->second));
809 }
810 }
811 keysToRemove.push_back(p->first);
812 }
813 }
814 forDataMap.insert(toBeAdded.begin(),toBeAdded.end());
815 for(uint i=0;i<keysToRemove.size();i++){
816 DataMap::iterator rem = forDataMap.find(keysToRemove[i]);
817 if(rem != forDataMap.end()){
818 forDataMap.erase(rem);
819 }
820 }
821
822 //apply override from level 0 to level 1 for production data
823 toBeAdded.clear();
824 keysToRemove.clear();
825 for(p=prodDataMap.begin();p!=prodDataMap.end();p++){
826 unpackKeyProdData(p->first,parName,regId,prod,freeDim);
827 if(!regionExist(regId)){
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));
829 continue;
830 }
831 if(getRegion(regId)->getRegLevel() == 0){
832 vector<ModelRegion*> childs = getRegion(regId)->getChildren(false);
833 for(uint j=0;j<childs.size();j++){
834 bool found = false;
835 key = makeKeyProdData(parName,i2s(childs[j]->getRegId()),prod,freeDim);
836 if (!dataMapCheckExist(prodDataMap,key,true)){
837 toBeAdded.insert(DataPair(key,p->second));
838 }
839 }
840 //prodDataMap.erase(p);
841 //p--;
842 keysToRemove.push_back(p->first);
843 }
844 }
845 prodDataMap.insert(toBeAdded.begin(),toBeAdded.end());
846 for(uint i=0;i<keysToRemove.size();i++){
847 DataMap::iterator rem = prodDataMap.find(keysToRemove[i]);
848 if(rem != prodDataMap.end()){
849 prodDataMap.erase(rem);
850 }
851 }
852
853
854 //apply override from level 1 to level 2 for production data
855 toBeAdded.clear();
856 keysToRemove.clear();
857 for(p=prodDataMap.begin();p!=prodDataMap.end();p++){
858 string debug = p->first;
859 unpackKeyProdData(p->first,parName,regId,prod,freeDim);
860 if(!regionExist(regId)){
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));
862 continue;
863 }
864 if(getRegion(regId)->getRegLevel() == 1){
865 vector<ModelRegion*> childs = getRegion(regId)->getChildren(false);
866 for(uint j=0;j<childs.size();j++){
867 bool found = false;
868 key = makeKeyProdData(parName,i2s(childs[j]->getRegId()),prod,freeDim);
869 if (!dataMapCheckExist(prodDataMap,key,true)){
870 toBeAdded.insert(DataPair(key,p->second));
871 }
872 }
873 //prodDataMap.erase(p);
874 //p--;
875 keysToRemove.push_back(p->first);
876 }
877 }
878 prodDataMap.insert(toBeAdded.begin(),toBeAdded.end());
879 for(uint i=0;i<keysToRemove.size();i++){
880 DataMap::iterator rem = prodDataMap.find(keysToRemove[i]);
881 if(rem != prodDataMap.end()){
882 prodDataMap.erase(rem);
883 }
884 }
885
886 //apply override from level 0 to level 1 for reclassification rules
887 for(uint i=0;i<reclRules.size();i++){
888 if(reclRules[i].regId == 0){
889 if(!regionExist(reclRules[i].regId)){
890 msgOut(MSG_CRITICAL_ERROR,"Reclassification rule has a unknown region code If you want not to model a region, set residual=true.: "+i2s(reclRules[i].regId));
891 continue;
892 }
893 for(uint j=0;j<getRegion(reclRules[i].regId)->getNChildren(false);j++){
894 vector<ModelRegion*> childs = getRegion(reclRules[i].regId)->getChildren(false);
895 bool found = 0;
896 for(uint z=0;z<reclRules.size();z++){
897 if( reclRules[z].regId == childs[j]->getRegId()
898 && reclRules[z].forTypeIn == reclRules[i].forTypeIn
899 && reclRules[z].forTypeOut == reclRules[i].forTypeOut
900 ){
901 found = true; // do nothing, this child has been already manually overritten
902 break;
903 }
904 }
905 if(!found){
906 reclRule RR;
907 RR.regId = childs[j]->getRegId();
908 RR.forTypeIn = reclRules[i].forTypeIn;
909 RR.forTypeOut = reclRules[i].forTypeOut;
910 RR.coeff = reclRules[i].coeff;
911 reclRules.push_back(RR);
912 }
913 }
914 reclRules.erase(reclRules.begin()+i);
915 i--;
916 }
917 }
918
919 //apply override from level 1 to level 2 for reclassification rules
920 for(uint i=0;i<reclRules.size();i++){
921 if(!regionExist(reclRules[i].regId)){
922 msgOut(MSG_CRITICAL_ERROR,"Reclassification rule has a unknown region code. If you want not to model a region, set residual=true.: "+i2s(reclRules[i].regId));
923 continue;
924 }
925 if(getRegion(reclRules[i].regId)->getRegLevel() == 1){
926 for(uint j=0;j<getRegion(reclRules[i].regId)->getNChildren(false);j++){
927 vector<ModelRegion*> childs = getRegion(reclRules[i].regId)->getChildren(false);
928 bool found = 0;
929 for(uint z=0;z<reclRules.size();z++){
930 if( reclRules[z].regId == childs[j]->getRegId()
931 && reclRules[z].forTypeIn == reclRules[i].forTypeIn
932 && reclRules[z].forTypeOut == reclRules[i].forTypeOut
933 ){
934 found = true; // do nothing, this child has been already manually overritten
935 break;
936 }
937 }
938 if(!found){
939 reclRule RR;
940 RR.regId = childs[j]->getRegId();
941 RR.forTypeIn = reclRules[i].forTypeIn;
942 RR.forTypeOut = reclRules[i].forTypeOut;
943 RR.coeff = reclRules[i].coeff;
944 reclRules.push_back(RR);
945 }
946 }
947 reclRules.erase(reclRules.begin()+i);
948 i--;
949 }
950 }
951}
@ MSG_CRITICAL_ERROR
Print an error message and stop the model.
Definition BaseClass.h:62
@ MSG_INFO
Print an INFO message.
Definition BaseClass.h:59
map< string, vector< double > > DataMap
Definition ModelData.cpp:56
pair< string, vector< double > > DataPair
Definition ModelData.h:44
string i2s(const int &int_h) const
integer to string conversion
bool regionExist(const int &regId_h) const
string makeKeyProdData(const string &parName, const string &regId, const string &prod, const string &freeDim="") const
Definition ModelData.h:172
string makeKeyForData(const string &parName, const string &regId, const string &forType, const string &diamClass) const
Definition ModelData.h:173
ModelRegion * getRegion(int regId_h)
void unpackKeyForData(const string &key, string &parName, int &regId, string &forType, string &diamClass) const
void unpackKeyProdData(const string &key, string &parName, int &regId, string &prod, string &freeDim) const
vector< reclRule > reclRules
Vector of reclassification rules.
Definition ModelData.h:227
map< string, vector< double > > prodDataMap
Product data.
Definition ModelData.h:218
map< string, vector< double > > forDataMap
Forestry data.
Definition ModelData.h:217
bool dataMapCheckExist(const DataMap &map, const string &search_for, const bool &exactMatch=true) const
vector< ModelRegion * > getChildren(bool excludeResidual=true)
Returns a pointer to the parent regions.
int getNChildren(bool excludeResidual=true)
Forest types (struct)
Definition ModelData.h:293
IO production matrix between the forest resources and the primary products (struct)
Definition ModelData.h:306
string forTypeOut
Definition ModelData.h:309
int regId
Definition ModelData.h:307
string forTypeIn
Definition ModelData.h:308
double coeff
Definition ModelData.h:310

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ assessProdPossibility()

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 class.

Definition at line 441 of file ModelData.cpp.

441 {
442 bool ok=false;
443 for(uint i=0;i<forToProdVector.size();i++){
444 if( forToProdVector[i].product == prod_h
445 && forToProdVector[i].forType == forType_h
446 && forToProdVector[i].dClass == dClass_h
447 ){
448 return true;
449 }
450 }
451 return false;
452}
vector< forToProd > forToProdVector
Vector of coefficients from forest resources to primary products.
Definition ModelData.h:219

Referenced by ModelCore::app(), ModelCoreSpatial::app(), Opt::app(), getAllocableProductIdsFromDeathTimber(), getAvailableAliveTimber(), and getAvailableDeathTimber().

Here is the caller graph for this function:

◆ cacheSettings()

void cacheSettings ( )

Called after input reading, it fix frequently used data;.

Definition at line 305 of file ModelData.cpp.

305 {
306 cached_initialYear = getIntSetting("initialYear");
308 priProducts = getStringVectorSetting("priProducts");
309 secProducts = getStringVectorSetting("secProducts");
311 allProducts.insert( allProducts.end(), secProducts.begin(), secProducts.end() );
312}
vector< string > allProducts
Definition ModelData.h:237
vector< string > priProducts
Definition ModelData.h:235
int getIntSetting(const string &name_h, int position=0, int reg=WORLD) const
vector< string > secProducts
Definition ModelData.h:236
int cached_initialYear
Definition ModelData.h:234
vector< string > diamClasses
Diameter classes.
Definition ModelData.h:233

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateAnnualisedEquivalent() [1/2]

double calculateAnnualisedEquivalent ( const double &  amount_h,
const double &  years_h,
const double &  ir 
) const

Transform the double to the highest integer and call calculateAnnualisedEquivalent(double amount_h, int years_h)

Definition at line 2000 of file ModelData.cpp.

2000 {
2001 //ceil(x) DNLP returns the smallest integer number greater than or equal to x
2002 //loop( (u,i,lambda,essence),
2003 // cumTp(u,i,lambda,essence) = ceil(cumTp(u,i,lambda,essence));
2004 //);
2005 int ceiledYear = ceil(years_h);
2006 return calculateAnnualisedEquivalent(amount_h, ceiledYear, ir);
2007}
double calculateAnnualisedEquivalent(const double &amount_h, const int &years_h, const double &ir) const
Calculate the annual equivalent flow.
Here is the call graph for this function:

◆ calculateAnnualisedEquivalent() [2/2]

double calculateAnnualisedEquivalent ( const double &  amount_h,
const int &  years_h,
const double &  ir 
) const

Calculate the annual equivalent flow.

calculating the discount factor

Revenues at years n will be transforemed as average year rate as

av.y.rev = rev(n)/ ( (1+ir)^(n-1)+(1+ir)^(n-2)+(1+ir)^(n-3)+...+(1+ir)^(n-n) )

Objective is to have the present value of the final harvest (A) equal to the sum pf the present values of yearly activities (B):

Comparing present values

\[ PV(A) = SUM(PV(B) \]

\[ A/(1+r)^n = B/(1+r)^1 + B/(1+r)^2 + … + B/(1+r)^n \]

\[ A/(1+r)^n = B * ( 1/(1+r)^1 + 1/(1+r)^2 + … + 1/(1+r)^n ) \]

\[ A/(1+r)^n = B * ( (1+r)^(n-1) + (1+r)^(n-2) + … + (1+r)^(n-n) ) \]

\[ B = A / ( (1+r)^(n-1) + (1+r)^(n-2) + … + (1+r)^(n-n) ) \]

  1. Changed for the equivalent but simpler eai = rev(t)*i / ((1+i)^t-1)

Definition at line 1961 of file ModelData.cpp.

1961 {
1962 // modified and tested 20120912. Before it was running this formula instead:
1963 // av.y.rev = rev(n)/ ( (1+ir)^1+(1+ir)^2+(1+ir)^3+...+(1+ir)^n )
1964 // the difference is that in this way the annual equivalent that is calulated doesn't need to be further discounted for yearly activites (e.g. agric)
1965
1966 //loop(fy$(ord(fy)=1),
1967 // df(fy)= (1+ir)**(ord(fy));
1968 //);
1969 //loop(fy$(ord(fy)>1),
1970 // df(fy)=df(fy-1)+(1+ir)**(ord(fy));
1971 //);
1972 if(years_h<0) return 0.;
1973 if(years_h==0) return amount_h;
1974 //double ir = getDoubleSetting("ir",DATA_NOW);
1975 double eai = amount_h * ir / (pow(1.0+ir,years_h)-1.0);
1976
1977 return eai;
1978
1979 /*
1980 vector <double> df_by;
1981 for(int y=0;y<years_h;y++){
1982 double df;
1983 if(y==0){
1984 df = pow((1+ir),y);
1985 } else {
1986 df = df_by.at(y-1)+pow((1+ir),y);
1987 }
1988 if (y==years_h-1) {
1989 cout << eai << " " << amount_h/df << endl;
1990 return amount_h/df; // big bug 20120904
1991 }
1992 df_by.push_back(df);
1993 }
1994 exit(1);
1995 return 0; // never reached, just to avoid compilation warnings
1996 */
1997}

Referenced by calculateAnnualisedEquivalent(), ModelCore::runManagementModule(), and ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ createCombinationsVector()

vector< vector< int > > createCombinationsVector ( const int &  nItems)

Return a vector containing any possible combination of nItems items (including any possible subset). The returned vector has in each slot the items present in that specific combination.

ModelData::createCombinationsVector Return a vector containing any possible combination of nItems items (including all subsets).

For example with nItems = 3: 0: []; 1: [0]; 2: [1]; 3: [0,1]; 4: [2]; 5: [0,2]; 6: [1,2]; 7: [0,1,2]

Parameters
nItemsnumber of items to create p
Returns
A vector with in each slot the items present in that specific combination subset.

Definition at line 2055 of file ModelData.cpp.

2055 {
2056 // Not confuse combination with permutation where order matter. Here it doesn't matter, as much as the algorithm is the same and returns
2057 // to as each position always the same subset
2058 vector < vector <int> > toReturn;
2059 int nCombs = pow(2,nItems);
2060 //int nCombs = nItems;
2061 for (uint i=0; i<nCombs; i++){
2062 vector<int> thisCombItems; //concernedPriProducts;
2063 for(uint j=0;j<nItems;j++){
2064 uint j2 = pow(2,j);
2065 if(i & j2){ // bit a bit operator, p217 C++ book
2066 thisCombItems.push_back(j);
2067 }
2068 }
2069 toReturn.push_back(thisCombItems);
2070 }
2071 return toReturn;
2072}

Referenced by ModelCoreSpatial::computeInventary(), Opt::get_nlp_info(), and ModelCoreSpatial::runMarketModule().

Here is the caller graph for this function:

◆ createRegions()

void createRegions ( )

Definition at line 317 of file ModelData.cpp.

317 {
318 // first create regions and assign basic data...
319 LLData table = getTable("regions");
320 for (int i=0; i< table.nrecords();i++){
321 ModelRegion REGION(MTHREAD,
322 s2i(table.getData(i,"regId")),
323 table.getData(i,"regSName"),
324 table.getData(i,"regLName"),
325 s2i(table.getData(i,"regLevel")),
326 s2i(table.getData(i,"parRegId")),
327 s2b(table.getData(i,"isResidual")));
328 regionsVector.push_back(REGION);
329 }
330 // Now let's assign the parent/children pointers..
331 for (int i=0; i< regionsVector.size();i++){
332 // let's assign the parent:
333 regionsVector[i].setParent(this->getRegion(regionsVector[i].getParRegId()));
334 // let's assign the children:
335 vector<ModelRegion*> kids;
336 for (int y=0; y< regionsVector.size();y++){
337 if(regionsVector[y].getParRegId() == regionsVector[i].getRegId() ){
338 kids.push_back(&regionsVector[y]);
339 }
340 }
341 regionsVector[i].setChildren(kids);
342 }
343}
int s2i(const string &string_h) const
string to integer conversion
bool s2b(const string &string_h) const
string to bool conversion
Low level data. XML input is reversed here after unzipping oocalc file and parsing content....
Definition ModelData.h:329
string getData(const int &pos_h, const string &header_h, const int &debugLevel=MSG_CRITICAL_ERROR) const
int nrecords()
Definition ModelData.h:336
LLData getTable(string tableName_h, int debugLevel=MSG_CRITICAL_ERROR)

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dataMapCheckExist()

bool dataMapCheckExist ( const DataMap map,
const string &  search_for,
const bool &  exactMatch = true 
) const
private

Definition at line 1812 of file ModelData.cpp.

1812 {
1813 /*int dummyYear=MTHREAD->SCD->getYear();
1814 if(dataMapGetValue(map, search_for, dummyYear, exactMatch)==DATA_ERROR) {
1815 return false;
1816 } else {
1817 return true;
1818 }
1819 return false;
1820}*/
1821 bool found = false;
1822 DataMap::const_iterator i;
1823 if(!exactMatch){
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) {// Really a prefix?
1828 return true;
1829 } else {
1830 return false;
1831 }
1832 }
1833 } else {
1834 i = map.find(search_for);
1835 if (i!=map.end()){
1836 return true;
1837 }
1838 }
1839 return false;
1840}

Referenced by applyOverrides().

Here is the caller graph for this function:

◆ dataMapGetValue()

double dataMapGetValue ( const DataMap map,
const string &  search_for,
const int &  year_h,
const bool &  exactMatch = true 
)
private

Definition at line 1844 of file ModelData.cpp.

1844 {
1845 double toReturn = 0;
1846 tempBool = false;
1847 DataMap::const_iterator i;
1848 if(!exactMatch){
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) {// Really a prefix?
1853 tempBool = true;
1854 toReturn += getTimedData( i->second, year_h );
1855 } else {
1856 break;
1857 }
1858 }
1859 } else {
1860 i = map.find(search_for);
1861 if (i!=map.end()){
1862 tempBool = true;
1863 return getTimedData( i->second, year_h );
1864 }
1865 }
1866 return toReturn;
1867}
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...

Referenced by getForData(), and getProdData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dataMapSetValue()

int dataMapSetValue ( DataMap map,
const string &  search_for,
const double &  value_h,
const int &  year_h,
const bool &  exactMatch = true 
)
private

Definition at line 1872 of file ModelData.cpp.

1872 {
1873 bool found = false;
1874 DataMap::iterator i;
1875 if(!exactMatch){
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) {// Really a prefix?
1880 found = true;
1881 setTimedData(value_h, i->second, year_h);
1882 } else {
1883 break;
1884 }
1885 }
1886 } else {
1887 i = map.find(search_for);
1888 if (i!=map.end()){
1889 found = true;
1890 setTimedData(value_h, i->second, year_h, errorLevel);
1891 }
1892 }
1893 // removed 20120903 as the insertion of new values must be explicitly done, not in all cases we want a new insertion
1894 /*if(!found){
1895 vector < double> newValues;
1896 setTimedData(value_h, newValues, year_h, MSG_NO_MSG); // don't warning if we are making a multi-year value vector, as it is a new one
1897 map.insert(DataPair (search_for,newValues));
1898 }*/
1899 return found;
1900}
void setTimedData(const double &value_h, vector< double > &dated_vector, const int &year_h, const int &MSG_LEVEL=MSG_WARNING)

Referenced by setForData(), and setProdData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deathTimberInventory_get()

double deathTimberInventory_get ( const iisskey thekey)
inline

Definition at line 197 of file ModelData.h.

197{return findMap(deathTimberInventory, thekey);}
V findMap(const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V &notFoundValue=numeric_limits< V >::min()) const
Lookup a map for a value. Return the value starting from the key.
Definition BaseClass.h:286
map< iisskey, double > deathTimberInventory
Map that register the death of biomass still usable as timber by year, l2_region, forest type and dia...
Definition ModelData.h:230

Referenced by ModelCoreSpatial::allocateHarvesting().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deathTimberInventory_incr()

void deathTimberInventory_incr ( const iisskey thekey,
double  value_h 
)
inline

Definition at line 196 of file ModelData.h.

196{incrMapValue(deathTimberInventory,thekey, value_h);}
void incrMapValue(map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
Increments a value stored in a map of the specified value, given the key.
Definition BaseClass.h:312
Here is the call graph for this function:

◆ deathTimberInventory_incrOrAdd()

void deathTimberInventory_incrOrAdd ( const iisskey thekey,
double  value_h 
)
inline

Definition at line 195 of file ModelData.h.

195{incrOrAddMapValue(deathTimberInventory,thekey, value_h);}
void incrOrAddMapValue(map< K, V > &mymap, const K &key, const V &value)
Increments a value stored in a map of the specified value, given the key.
Definition BaseClass.h:325

Referenced by ModelCoreSpatial::allocateHarvesting(), ModelCoreSpatial::initialiseDeathTimber(), and ModelCoreSpatial::runBiologicalModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delDir()

bool delDir ( QString  dirname)

Recursivelly delete a directory.

Definition at line 1769 of file ModelData.cpp.

1769 {
1770 bool deleted = false;
1771 QDir dir(dirname);
1772 //msgOut(MSG_DEBUG, dir.absolutePath().toStdString());
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;
1777
1778 for (int i = 0; i < list.size(); ++i) {
1779 QFileInfo fileInfo = list.at(i);
1780 if (fileInfo.isFile()){
1781 //msgOut(MSG_DEBUG, "A file, gonna remove it: "+fileInfo.absoluteFilePath().toStdString());
1782 QFile targetFile(fileInfo.absoluteFilePath());
1783 bool fileDeleted = targetFile.remove();
1784 if (!fileDeleted){
1785 msgOut(MSG_CRITICAL_ERROR, "We have a problem: can't delete file "+fileInfo.absoluteFilePath().toStdString());
1786 }
1787 }
1788 else if (fileInfo.isDir()){
1789 //msgOut(MSG_DEBUG, "A directory, gonna go inside it: "+fileInfo.absoluteFilePath().toStdString());
1790 delDir(fileInfo.absoluteFilePath());
1791 dir.rmdir(fileInfo.absoluteFilePath());
1792 }
1793 }
1794
1795 deleted = dir.rmdir(dir.absolutePath());
1796 if (deleted) return true;
1797 return false;
1798}
bool delDir(QString dirname)
Recursivelly delete a directory.

Referenced by delDir(), and loadInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAllocableProductIdsFromDeathTimber()

vector< int > getAllocableProductIdsFromDeathTimber ( const int &  regId_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 the specific year, ft, dc combination.

Definition at line 2105 of file ModelData.cpp.

2105 {
2106 vector<int> allocableProductIds;
2107 if (!getBoolSetting("useDeathTimber",DATA_NOW)) return allocableProductIds;
2108 if (request_year == DATA_NOW) request_year = MTHREAD->SCD->getYear();
2109 for(uint p=0;p<priProducts.size();p++){
2110 string primProd = priProducts[p];
2111 if(assessProdPossibility(primProd,ft, dc)){
2112 int maxYears = getMaxYearUsableDeathTimber(primProd, ft, dc);
2113 if (request_year-harvesting_year < maxYears){
2114 allocableProductIds.push_back(p);
2115 }
2116 }
2117 }
2118 return allocableProductIds;
2119}
@ DATA_NOW
The required data is for the current year.
Definition BaseClass.h:73
const int getMaxYearUsableDeathTimber()
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 ...
int getYear()
Definition Scheduler.h:49
Scheduler * SCD
the scheduler object (simulation-loops scheduler)

Referenced by ModelCoreSpatial::allocateHarvesting().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAllRegions()

vector< ModelRegion * > getAllRegions ( bool  excludeResidual = true)

Definition at line 379 of file ModelData.cpp.

379 {
380 vector <ModelRegion*> toReturn;
381 for(uint i=0;i<regionsVector.size();i++){
382 if( (!excludeResidual) || (!regionsVector[i].getIsResidual())){
383 toReturn.push_back(&regionsVector[i]);
384 }
385 }
386 return toReturn;
387}

Referenced by ModelRegion::getSiblings(), and Gis::setSpace().

Here is the caller graph for this function:

◆ getAvailableAliveTimber()

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.

Definition at line 2124 of file ModelData.cpp.

2124 {
2125 double toReturn = 0.0;
2126 ModelRegion* REG = MTHREAD->MD->getRegion(regId_h);
2127 vector <Pixel*> regPx = REG->getMyPixels();
2128 vector <string> forTypesIds = getForTypeIds();
2129 for (uint i=0;i<forTypesIds.size();i++){
2130 string ft = forTypesIds[i];
2131 for(uint u=0;u<diamClasses.size();u++){
2132 string dc = diamClasses[u];
2133 bool possible = false;
2134 for (int p=0; p<primProd_h.size();p++){
2135 string primProd = primProd_h[p];
2136 if(assessProdPossibility(primProd,ft, dc)){
2137 possible = true;
2138 }
2139 }
2140 if(possible){
2141 for (uint p=0;p<regPx.size();p++){
2142 Pixel* px = regPx[p];
2143 toReturn += px->vol_l.at(i).at(u)*px->avalCoef.at(i);
2144 }
2145 }
2146 }
2147 }
2148 return toReturn;
2149}
vector< string > getForTypeIds(bool all=false)
By default it doesn't return forTypes used only as input.
vector< Pixel * > getMyPixels()
Definition ModelRegion.h:86
Pixel-level class.
Definition Pixel.h:47
vector< double > avalCoef
Availability (of wood resources) coefficient. A [0,1] coefficient (new: by forest type) that reduces ...
Definition Pixel.h:148
vector< vector< double > > vol_l
store the volumes of the previous year
Definition Pixel.h:129
ModelData * MD
the model data object

Referenced by ModelCoreSpatial::computeInventary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAvailableDeathTimber()

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 deathTimberInventory map.

Definition at line 2076 of file ModelData.cpp.

2076 {
2077 if (!getBoolSetting("useDeathTimber",DATA_NOW)) return 0;
2078 double toReturn = 0.0;
2079 vector <string> forTypesIds = getForTypeIds();
2080 for (uint i=0;i<forTypesIds.size();i++){
2081 string ft = forTypesIds[i];
2082 for(uint u=0;u<diamClasses.size();u++){
2083 string dc = diamClasses[u];
2084 bool possible = false;
2085 int maxYears = 0;
2086 for (int p=0; p<primProd_h.size();p++){
2087 string primProd = primProd_h[p];
2088 if(assessProdPossibility(primProd,ft, dc)){
2089 possible = true;
2090 maxYears=max(maxYears,getMaxYearUsableDeathTimber(primProd, ft, dc));
2091 }
2092 }
2093 if(possible){
2094 for(int y=year_h;y>year_h-maxYears;y--){
2095 iisskey key(y,regId_h,ft,dc);
2096 toReturn += findMap(deathTimberInventory,key,MSG_NO_MSG,0.0);
2097 }
2098 }
2099 }
2100 }
2101 return toReturn;
2102}
@ MSG_NO_MSG
Do not actually output any message.
Definition BaseClass.h:57
Class to provide a simple integer-integer-string-string key in std maps.
Definition BaseClass.h:213

Referenced by ModelCoreSpatial::computeInventary(), and ModelCoreSpatial::sumRegionalForData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBaseData()

string getBaseData ( const string &  name_h,
int  type_h,
int  position = 0,
int  regId_h = WORLD 
)
private

Returns the value stored in the settings database.

Regional overriding.

Concerning the param regId_h: it expect either world (default), a L2 or L1 region. Settings in the memory are stored also with data in one or more of these levels (e.g. we may have a general WORLD value and then a more specific L2 value. The function is done such that if WORLD is used to query it, it returns only a world value, if L1 is used instead, it looks for this L1 value and then eventually (if nothing is found) for WORLD. Finally, if L2 is used, it query, in the order, for L2, L1 or world levels.

Definition at line 1015 of file ModelData.cpp.

1015 {
1016 // If the data is called with DATA_NOW we interpret the array of values as a temporal array and we return the value at the current time.
1017 if(position == DATA_NOW) {
1018 position = MTHREAD->SCD->getIteration();
1019 }
1020
1021 vector <int> regIds;
1022
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);
1032 } else {
1033 msgOut(MSG_CRITICAL_ERROR, "Error in getBaseData(). Data requested for a unknown region level.");
1034 }
1035
1036
1037 for (uint j=0; j<regIds.size();j++){
1038 int regId = regIds[j];
1039 for (uint i=0; i<programSettingsVector.size();i++){
1040 if (programSettingsVector.at(i).name == name_h & programSettingsVector.at(i).regId == regId){
1041 int type = programSettingsVector.at(i).type;
1042 if(type != type_h){msgOut(MSG_CRITICAL_ERROR, "mismatching type in calling getBaseData() for "+name_h);}
1043 if(programSettingsVector.at(i).values.size() > ((uint)position)) {
1044 return programSettingsVector.at(i).values.at(position);
1045 } else if (programSettingsVector.at(i).values.size() > 0 ){
1046 // returning the last available value...
1047 return programSettingsVector.at(i).values.at( programSettingsVector.at(i).values.size()-1 );
1048 }
1049 else {msgOut(MSG_CRITICAL_ERROR, "Error: "+name_h+" doesn't have any value, even on the first position(year)!"); }
1050 }
1051 }
1052 }
1053
1054 msgOut(MSG_CRITICAL_ERROR, "Error calling getBaseData() for "+ name_h +". No setting option or macro data found with this name.");
1055
1056// switch(type_h){
1057// case TYPE_BOOL:
1058// return "0";
1059// case TYPE_INT:
1060// return "0";
1061// case TYPE_DOUBLE:
1062// return "0.0";
1063// case TYPE_STRING:
1064// return "";
1065// default:
1066// msgOut(MSG_CRITICAL_ERROR, "Error calling getBaseData() for "+ i2s(type_h) +". I don't know this type.");
1067// }
1068 return "";
1069}
@ WORLD
Request something that is not region-specific.
Definition BaseClass.h:80
int getIteration()
Definition Scheduler.h:48

Referenced by getBoolSetting(), getDoubleSetting(), getIntSetting(), and getStringSetting().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBaseDirectory()

string getBaseDirectory ( ) const
inline

Definition at line 118 of file ModelData.h.

118{return baseDirectory;}
string baseDirectory
Definition ModelData.h:215

Referenced by Output::commonInit(), Gis::initLayers(), Gis::initLayersPixelData(), Layers::print(), and Layers::printBinMap().

Here is the caller graph for this function:

◆ getBoolSetting()

bool getBoolSetting ( const string &  name_h,
int  position = 0,
int  reg = WORLD 
) const

◆ getBoolVectorSetting()

vector< bool > getBoolVectorSetting ( const string &  name_h,
int  reg = WORLD 
) const

Definition at line 1133 of file ModelData.cpp.

1133 {
1134 return s2b(MTHREAD->MD->getVectorBaseData(name_h,TYPE_BOOL,reg));
1135}
vector< string > getVectorBaseData(const string &name_h, int type_h, int regId_h=WORLD)
Here is the call graph for this function:

◆ getCachedInitialYear()

int getCachedInitialYear ( )
inline

Definition at line 187 of file ModelData.h.

187{return cached_initialYear;}

Referenced by Scheduler::run().

Here is the caller graph for this function:

◆ getDeathTimberInventory()

map< iisskey, double > * getDeathTimberInventory ( )
inline

Definition at line 198 of file ModelData.h.

198{return &deathTimberInventory;};

◆ getDiameterClasses()

vector< string > getDiameterClasses ( bool  productionOnly = false)

Definition at line 1191 of file ModelData.cpp.

1191 {
1192 int i;
1193 if(productionOnly){
1194 i=1;
1195 } else {
1196 i=0;
1197 }
1198 vector <string> toReturn;
1199 for (i;i<diamClasses.size();i++){
1200 toReturn.push_back(diamClasses[i]);
1201 }
1202 return toReturn;
1203}

Referenced by getForData(), and setForData().

Here is the caller graph for this function:

◆ getDoubleSetting()

double getDoubleSetting ( const string &  name_h,
int  position = 0,
int  reg = WORLD 
) const

Definition at line 1109 of file ModelData.cpp.

1109 {
1110 return s2d( MTHREAD->MD->getBaseData(name_h,TYPE_DOUBLE,position,reg) );
1111}
@ TYPE_DOUBLE
The required data is a double.
Definition BaseClass.h:67
double s2d(const string &string_h) const
string to double conversion

Referenced by Gis::applySpatialStochasticValues(), Gis::applyStochasticRiskAdversion(), ModelCoreSpatial::cacheDynamicSettings(), ModelCoreSpatial::cachePixelExogenousData(), ModelCore::cacheSettings(), Opt::eval_constraints(), Opt::get_nlp_info(), Pixel::getMultiplier(), Pixel::getSTData(), Carbon::registerTransports(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCoreSpatial::runMarketModule(), and Gis::setSpace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDoubleVectorSetting()

vector< double > getDoubleVectorSetting ( const string &  name_h,
int  reg = WORLD 
) const

Definition at line 1125 of file ModelData.cpp.

1125 {
1126 return s2d(MTHREAD->MD->getVectorBaseData(name_h,TYPE_DOUBLE,reg));
1127}
Here is the call graph for this function:

◆ getErrorLevel()

int getErrorLevel ( )
inline

Definition at line 144 of file ModelData.h.

144{return errorLevel;}

Referenced by ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ getFilenameByType()

std::string getFilenameByType ( std::string  type_h)

Definition at line 1175 of file ModelData.cpp.

1175 {
1176 std::string directory;
1177 std::string filename;
1178 std::string filename_complete;
1179 for (uint i=0; i<iFilesVector.size(); i++){
1180 if (iFilesVector.at(i).type == type_h){
1181 directory=iFilesVector.at(i).directory;
1182 filename=iFilesVector.at(i).name;
1183 break;
1184 }
1185 }
1186 filename_complete = baseDirectory+directory+filename;
1187 return filename_complete;
1188}
vector< IFiles > iFilesVector
List of all input files. Simple (struct)
Definition ModelData.h:221

◆ getFilenamesByDir()

int getFilenamesByDir ( const string &  dir,
vector< string > &  files,
const string &  filter = "" 
)

Return a list of files in a directory.

Get a list of files in a directory

Definition at line 2011 of file ModelData.cpp.

2011 {
2012 DIR *dp;
2013 struct dirent *dirp;
2014 if((dp = opendir(dir.c_str())) == NULL) {
2015 msgOut(MSG_ERROR, "Error " + i2s(errno) + " opening the " + dir + " directory.");
2016 //cout << "Error(" << errno << ") opening " << dir << endl;
2017 return errno;
2018 }
2019 while ((dirp = readdir(dp)) != NULL) {
2020 string filename = dirp->d_name;
2021 if(
2022 (filter != "" && filename.substr(filename.find_last_of(".")) == filter) // there is a filter and the last bit of the filename match the filter
2023 || (filter == "" && filename.substr(filename.find_last_of(".") + 1) != "") // there isn't any filter but we don't want stuff like ".." or "."
2024 ) {
2025 files.push_back(string(dirp->d_name));
2026 }
2027 }
2028 closedir(dp);
2029 return 0;
2030}

Referenced by Gis::initLayersPixelData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getForData()

const double getForData ( const string &  type_h,
const int &  regId_h,
const string &  forType_h,
const string &  freeDim_h,
const int &  year = DATA_NOW 
)

Basic function to retrieve forest-related data. It addmits the following "filters": @type_h Name of the specific parameter requested @regId_h Look for a level1 or level2 region @forType_h If specified, look exactly for the specified forest type, otherwise accept the keyword FT_ALL for summing all of them @freeDim_h Normally used for diameter class, but occasionally used for other uses (changed 20140514). It accepts three keywords, for summing up all diameters, production-ready diameters or sub-production ones, namelly DIAM_ALL, DIAM_PROD, DIAM_FIRST.\ If a diameter-independed variable is required, put it in the data with an empty diameter class and retrieve it here using DIAM_ALL. @year Unless specified, get the value of the current year. If array is smaller (e.g. because it is time-independent), get the last value.

Definition at line 1281 of file ModelData.cpp.

1281 {
1282 vector<int> regIds;
1283 vector <string> dClasses;
1284 vector <string> fTypes;
1285 string key;
1286 DataMap::const_iterator p;
1287 bool found = false;
1288 double value = 0;
1289
1290 // creating the arrays to look up if keywords were specified..
1291 if (forType_h == FT_ALL){ // || forType_h == ""){
1292 fTypes = getForTypeIds();
1293 fTypes.push_back("");
1294 } else {
1295 fTypes.push_back(forType_h);
1296 }
1297 if(freeDim_h == DIAM_ALL){ // || freeDim_h == ""){
1298 dClasses = diamClasses;
1299 dClasses.push_back("");
1300 } else if (freeDim_h == DIAM_PROD){
1301 dClasses = getDiameterClasses(true);
1302 } else if (freeDim_h == DIAM_FIRST){
1303 dClasses.push_back(diamClasses.at(0));
1304 } else {
1305 dClasses.push_back(freeDim_h);
1306 }
1307 // Make sure to set the new value to all l2 regions if requested for a reg1 level
1308 if(getRegion(regId_h)->getRegLevel()==2){
1309 regIds.push_back(regId_h);
1310 } else if (getRegion(regId_h)->getRegLevel()==1) {
1311 for(uint i=0;i<getRegion(regId_h)->getNChildren();i++){
1312 regIds.push_back(getRegion(regId_h)->getChildren()[i]->getRegId());
1313 }
1314 } else {
1315 msgOut(MSG_CRITICAL_ERROR, "Error in getProdData(). Setting a value for the whole World is not supported.");
1316 }
1317 int regIdsS = regIds.size();
1318
1319 // getting the actual data...
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++){
1323 key = makeKeyForData(type_h,i2s(regIds[r]),fTypes[y],dClasses[i]);
1324 value += dataMapGetValue(forDataMap,key,year,true);
1325 if(tempBool) found = true;
1326 }
1327 }
1328 }
1329
1330 if(!found){
1331 valueFoundBool = false;
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.");
1333 }
1334 return value;
1335}
#define FT_ALL
All forest types.
Definition BaseClass.h:166
#define DIAM_ALL
All diameter classes.
Definition BaseClass.h:157
#define DIAM_PROD
Diameter classes used for production (e.g. excluded the first one)
Definition BaseClass.h:160
#define DIAM_FIRST
First diameter class (NOT used for production)
Definition BaseClass.h:163
double dataMapGetValue(const DataMap &map, const string &search_for, const int &year_h, const bool &exactMatch=true)
vector< string > getDiameterClasses(bool productionOnly=false)

Referenced by Gis::applySpatialStochasticValues(), Pixel::getMultiplier(), Carbon::getStock(), Opt::gfd(), ModelCore::gfd(), ModelCoreSpatial::gfd(), Carbon::initialiseDeathBiomassStocks(), Output::printForestData(), Carbon::registerDeathBiomass(), Carbon::registerHarvesting(), and ModelCoreSpatial::runManagementModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getForType() [1/2]

forType * getForType ( int  position)
inline

Definition at line 128 of file ModelData.h.

128{return &forTypes[position];}
vector< forType > forTypes
Vector of forest types.
Definition ModelData.h:226

Referenced by Gis::applyForestReclassification(), getForTypeChilds_pos(), ModelCoreSpatial::loadExogenousForestLayers(), and ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ getForType() [2/2]

forType * getForType ( string &  forTypeId_h)

Definition at line 73 of file ModelData.cpp.

73 {
74 for(int i=0;i<forTypes.size();i++){
75 if(forTypes[i].forTypeId==forTypeId_h) return &forTypes[i];
76 }
77 msgOut(MSG_CRITICAL_ERROR,"forTypeId "+forTypeId_h+" not found. Aborting.");
78}
Here is the call graph for this function:

◆ getForTypeChilds()

vector< string > getForTypeChilds ( const string &  forTypeId_h)

Definition at line 98 of file ModelData.cpp.

98 {
99 vector<string> childs;
100 for(int i=0;i<forTypes.size();i++){
101 if(forTypes[i].ereditatedFrom==forTypeId_h) {
102 childs.push_back(forTypes[i].forTypeId);
103 }
104 }
105 return childs;
106}

Referenced by ModelCoreSpatial::runManagementModule(), and ModelCoreSpatial::sumRegionalForData().

Here is the caller graph for this function:

◆ getForTypeChilds_pos()

vector< int > getForTypeChilds_pos ( const string &  forTypeId_h,
bool  all = false 
)

Definition at line 109 of file ModelData.cpp.

109 {
110 vector <int> childs;
111 vector <string> fTIds = getForTypeIds(all);
112 for(int i=0;i<fTIds.size();i++){
113 forType* ft = getForType(fTIds[i]);
114 if(ft->ereditatedFrom==forTypeId_h) {
115 childs.push_back(i);
116 }
117 }
118 return childs;
119}
forType * getForType(int position)
Definition ModelData.h:128
string ereditatedFrom
Definition ModelData.h:298

Referenced by ModelCoreSpatial::sumRegionalForData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getForTypeCounter()

int getForTypeCounter ( string &  forTypeId_h,
bool  all = false 
)

By default it doesn't return forTypes used only as input.

Definition at line 81 of file ModelData.cpp.

81 {
82 vector <string> fTIds = getForTypeIds(all);
83 for(int i=0;i<fTIds.size();i++){
84 if(fTIds[i]==forTypeId_h) return i;
85 }
86 msgOut(MSG_CRITICAL_ERROR,"forTypeId "+forTypeId_h+" not found in "+((string) __func__ )+". Aborting.");
87}
Here is the call graph for this function:

◆ getForTypeIds()

vector< string > getForTypeIds ( bool  all = false)

◆ getForTypeParentId()

string getForTypeParentId ( const string &  forTypeId_h)

Definition at line 90 of file ModelData.cpp.

90 {
91 for(int i=0;i<forTypes.size();i++){
92 if(forTypes[i].forTypeId==forTypeId_h) return forTypes[i].ereditatedFrom;
93 }
94 msgOut(MSG_CRITICAL_ERROR,"forTypeId "+forTypeId_h+" not found. Aborting.");
95}

Referenced by ModelCoreSpatial::runManagementModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getForTypeParents()

vector< string > getForTypeParents ( )

Definition at line 122 of file ModelData.cpp.

122 {
123 vector<string> parents;
124 for(int i=0;i<forTypes.size();i++){
125 string parent = forTypes[i].ereditatedFrom;
126 if(!inVector(parent,parents) && parent != ""){
127 parents.push_back(parent);
128 }
129 }
130 return parents;
131}
bool inVector(const K &element, const vector< K > &v)
Definition BaseClass.h:429

Referenced by Output::printForestData(), and ModelCoreSpatial::sumRegionalForData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIFilesVector()

vector< IFiles > getIFilesVector ( ) const
inline

Definition at line 117 of file ModelData.h.

117{return iFilesVector;}

◆ getIntSetting()

int getIntSetting ( const string &  name_h,
int  position = 0,
int  reg = WORLD 
) const

◆ getIntVectorSetting()

vector< int > getIntVectorSetting ( const string &  name_h,
int  reg = WORLD 
) const

Definition at line 1121 of file ModelData.cpp.

1121 {
1122 return s2i(MTHREAD->MD->getVectorBaseData(name_h,TYPE_INT,reg));
1123}

Referenced by applyDebugMode(), and Output::commonInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMaxYearUsableDeathTimber() [1/2]

const int getMaxYearUsableDeathTimber ( )

Definition at line 456 of file ModelData.cpp.

456 {
457 int maxMaxYears = 0;
458 for(uint i=0;i<forToProdVector.size();i++){
459 if(forToProdVector[i].maxYears > maxMaxYears){
460 maxMaxYears = forToProdVector[i].maxYears;
461 }
462 }
463 return maxMaxYears;
464}

Referenced by getAllocableProductIdsFromDeathTimber(), and getAvailableDeathTimber().

Here is the caller graph for this function:

◆ getMaxYearUsableDeathTimber() [2/2]

const int getMaxYearUsableDeathTimber ( const string &  prod_h,
const string &  forType_h,
const string &  dClass_h 
)

Definition at line 468 of file ModelData.cpp.

468 {
469 for(uint i=0;i<forToProdVector.size();i++){
470 if( forToProdVector[i].product == prod_h
471 && forToProdVector[i].forType == forType_h
472 && forToProdVector[i].dClass == dClass_h
473 ){
474 return forToProdVector[i].maxYears;
475 }
476 }
477 msgOut(MSG_CRITICAL_ERROR,"In getMaxYearUsableDeathTimber() I has been asked of a combination that I don't know how to handle.");
478}

Referenced by ModelCoreSpatial::allocateHarvesting().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNForTypes()

int getNForTypes ( )
inline

Definition at line 126 of file ModelData.h.

126{return forTypes.size();}

Referenced by Gis::applyForestReclassification().

Here is the caller graph for this function:

◆ getNForTypesChilds()

int getNForTypesChilds ( const string &  forTypeId_h)

Definition at line 135 of file ModelData.cpp.

135 {
136 int nChilds = 0;
137 for(int i=0;i<forTypes.size();i++){
138 if(forTypes[i].ereditatedFrom==forTypeId_h) {
139 nChilds ++;
140 }
141 }
142 return nChilds;
143}

Referenced by ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ getNReclRules()

int getNReclRules ( )
inline

Definition at line 127 of file ModelData.h.

127{return reclRules.size();}

Referenced by Gis::applyForestReclassification().

Here is the caller graph for this function:

◆ getOutputDirectory()

string getOutputDirectory ( ) const
inline

Return a vector of objects that together provide the specified resource in the specified quantity.

Definition at line 113 of file ModelData.h.

113{return outputDirname;}
string outputDirname
Definition ModelData.h:214

Referenced by Output::commonInit(), Layers::print(), and Layers::printBinMap().

Here is the caller graph for this function:

◆ getPathMortalityRule()

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 pathogen could be found)

Definition at line 2034 of file ModelData.cpp.

2034 {
2035 vector<pathRule*> toReturn;
2036 for(uint i=0;i<pathRules.size();i++){
2037 if(pathRules[i].forType == forType && pathRules[i].dClass == dC){
2038 toReturn.push_back(&pathRules[i]);
2039 }
2040 }
2041 return toReturn;
2042}
vector< pathRule > pathRules
Vector of pathogen rules.
Definition ModelData.h:228

Referenced by Pixel::getPathMortality().

Here is the caller graph for this function:

◆ getProdData()

const double getProdData ( const string &  type_h,
const int &  regId_h,
const string &  prodId_h,
const int &  year = DATA_NOW,
const string &  freeDim_h = "" 
)

Basic function to retrieve products-related data. It addmits the following "filters": @type_h Name of the specific parameter requested @regId_h Look for level1 or level 2 region. @prodId_h Product. It accept three keywords, for summing up all products, primary products or secondary products, namelly PROD_ALL, PROD_PRI, PROD_SEC. @year Unless specified, get the value of the current year. If array is smaller (e.g. because it is time-independent), get the last value. @freeDim_h If specified, look exactly for it, otherwise simply doesn't filter for it.

Definition at line 1216 of file ModelData.cpp.

1216 {
1217
1218 double value=0;
1219 vector <int> regIds;
1220 string key;
1221 DataMap::const_iterator p;
1222
1223 bool found = false;
1224 vector <string> products;
1225 bool exactMatch=true;
1226
1227 if(prodId_h == PROD_PRI){
1228 products = priProducts;
1229 } else if (prodId_h == PROD_SEC){
1230 products = secProducts;
1231 } else if (prodId_h == PROD_ALL || prodId_h == ""){
1232 products = allProducts;
1233 products.push_back("");
1234 } else {
1235 products.push_back(prodId_h);
1236 }
1237 if(freeDim_h=="") exactMatch=false;
1238
1239 // Make sure to set the new value to all l2 regions if requested for a reg1 level
1240 if(getRegion(regId_h)->getRegLevel()==2){
1241 regIds.push_back(regId_h);
1242 } else if (getRegion(regId_h)->getRegLevel()==1) {
1243 for(uint i=0;i<getRegion(regId_h)->getNChildren();i++){
1244 regIds.push_back(getRegion(regId_h)->getChildren()[i]->getRegId());
1245 }
1246 } else {
1247 msgOut(MSG_CRITICAL_ERROR, "Error in setProdData(). Setting a value for the whole World is not supported.");
1248 }
1249 int regIdsS = regIds.size();
1250
1251
1252 for(uint r=0;r<regIdsS;r++){
1253 for(uint i=0;i<products.size();i++){
1254 key = makeKeyProdData(type_h,i2s(regIds[r]),products[i],freeDim_h);
1255 if (!exactMatch && key.size () > 0) key.resize (key.size () - 1); // bug 20140402, removing the last #
1256 value += dataMapGetValue(prodDataMap,key,year,exactMatch);
1257 if(tempBool) found = true;
1258 }
1259 }
1260
1261 if(!found){
1262 valueFoundBool = false;
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.");
1264 }
1265 return value;
1266
1267
1268}
#define PROD_PRI
Primary products.
Definition BaseClass.h:151
#define PROD_ALL
All primary and transformed products.
Definition BaseClass.h:148
#define PROD_SEC
Secondary products.
Definition BaseClass.h:154

Referenced by Carbon::getStock(), ModelCore::gpd(), ModelCoreSpatial::gpd(), Opt::gpd(), Carbon::HWP_eol2energy(), Carbon::initialiseProductsStocks(), Output::printProductData(), and Carbon::registerProducts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getReclRule()

reclRule * getReclRule ( int  position)
inline

Definition at line 137 of file ModelData.h.

137{return &reclRules[position];}

Referenced by Gis::applyForestReclassification().

Here is the caller graph for this function:

◆ getRegion()

◆ getRegionIds() [1/2]

vector< vector< int > > getRegionIds ( bool  excludeResidual = true)

Definition at line 390 of file ModelData.cpp.

390 {
391 vector < vector <int> > toReturn;
392 vector <int> l1regIds = MTHREAD->MD->getRegionIds(1, excludeResidual);
393 for(uint i=0;i<l1regIds.size();i++){
394 vector<int> l2ChildrenIds;
395 ModelRegion* l1Region = MTHREAD->MD->getRegion(l1regIds[i]);
396 vector<ModelRegion*> l2Childrens = l1Region->getChildren(excludeResidual);
397 for(uint j=0;j<l2Childrens.size();j++){
398 l2ChildrenIds.push_back(l2Childrens[j]->getRegId());
399 }
400 if(l2ChildrenIds.size()){
401 toReturn.push_back(l2ChildrenIds);
402 }
403 }
404 return toReturn;
405}
vector< int > getRegionIds(int level_h, bool excludeResidual=true)
Here is the call graph for this function:

◆ getRegionIds() [2/2]

vector< int > getRegionIds ( int  level_h,
bool  excludeResidual = true 
)

Definition at line 366 of file ModelData.cpp.

366 {
367 vector <int> toReturn;
368 for(uint i=0;i<regionsVector.size();i++){
369 if(regionsVector[i].getRegLevel()==level_h){
370 if( (!excludeResidual) || (!regionsVector[i].getIsResidual())){
371 toReturn.push_back(regionsVector[i].getRegId());
372 }
373 }
374 }
375 return toReturn;
376}

Referenced by Gis::applySpatialStochasticValues(), Gis::applyStochasticRiskAdversion(), ModelCore::cacheSettings(), ModelCoreSpatial::cacheSettings(), Output::commonInit(), Opt::get_nlp_info(), Gis::getAllPlots(), getRegionIds(), Carbon::HWP_eol2energy(), Carbon::initialiseEmissionCounters(), Output::printDebugOutput(), Output::printDebugPixelValues(), regSName2RegId(), ModelCore::updateMapAreas(), ModelCoreSpatial::updateMapAreas(), and ModelCoreSpatial::updateOtherMapData().

Here is the caller graph for this function:

◆ getScenarioIndex()

int getScenarioIndex ( )
Todo:
Check that I can call this function all around the model and not only at the beginning

Definition at line 157 of file ModelData.cpp.

157 {
158 vector<string> scenarios = getScenarios(); /// \todo Check that I can call this function all around the model and not only at the beginning
159 string currentScenario = MTHREAD->getScenarioName();
160 for(int i=0;i<scenarios.size();i++){
161 if (currentScenario == scenarios[i]){
162 return i;
163 }
164 }
165 msgOut(MSG_CRITICAL_ERROR, "function getScenarioIndex() didn't found the current scenarioName within those returned by getScenarios().");
166 return 0;
167}
vector< string > getScenarios()
string getScenarioName()
Here is the call graph for this function:

◆ getScenarios()

vector< string > getScenarios ( )

Definition at line 146 of file ModelData.cpp.

146 {
147 vector<string> toReturn;
148 LLData table = getTable("scenarios");
149 for(int i=0;i<table.nrecords();i++){
150 string scenarioName = table.getData(i,"id");
151 toReturn.push_back(scenarioName);
152 }
153 return toReturn;
154}

Referenced by getScenarioIndex(), ThreadManager::run(), and ThreadManager::runFromConsole().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStringSetting()

string getStringSetting ( const string &  name_h,
int  position = 0,
int  reg = WORLD 
) const

Definition at line 1113 of file ModelData.cpp.

1113 {
1114 return MTHREAD->MD->getBaseData(name_h,TYPE_STRING,position,reg);
1115}
@ TYPE_STRING
The required data is a string.
Definition BaseClass.h:68

Referenced by ModelCoreSpatial::cacheDynamicSettings(), ModelCore::cacheSettings(), Output::commonInit(), Gis::initLayers(), Gis::initLayersPixelData(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), setDefaultSettings(), and setScenarioSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStringVectorSetting()

vector< string > getStringVectorSetting ( const string &  name_h,
int  reg = WORLD 
) const

◆ getTable()

LLData getTable ( string  tableName_h,
int  debugLevel = MSG_CRITICAL_ERROR 
)

Definition at line 1801 of file ModelData.cpp.

1801 {
1802 LLData toReturn(MTHREAD,"");
1803 for(uint i=0;i<LLDataVector.size();i++){
1804 if (LLDataVector[i].getTableName() == tableName_h)return LLDataVector[i];
1805 }
1806 msgOut(debugLevel,"No table found with name "+tableName_h);
1807 return toReturn;
1808}
vector< LLData > LLDataVector
Vector of Low Level Data.
Definition ModelData.h:223

Referenced by createRegions(), getScenarios(), setDefaultForData(), setDefaultPathogenRules(), setDefaultProdData(), setDefaultProductResourceMatrixLink(), setDefaultSettings(), setForestTypes(), setReclassificationRules(), setScenarioData(), setScenarioForData(), setScenarioPathogenRules(), setScenarioProdData(), setScenarioProductResourceMatrixLink(), and setScenarioSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTableFromFile()

LLData getTableFromFile ( string  tablename,
string  filename_h 
)

Load and return a data table from a file (instead that from a spreadsheet sheet)

Definition at line 1731 of file ModelData.cpp.

1731 {
1732 string fileName = MTHREAD->getBaseDirectory()+filename_h;
1733 QFile file(fileName.c_str());
1734 if (!file.open(QFile::ReadOnly)) {
1735 msgOut(MSG_ERROR, "Cannot open file "+fileName+" for reading.");
1736 }
1737 QTextStream in(&file);
1738 LLData data(MTHREAD, tablename);
1739 int countRow = 0;
1740 while (!in.atEnd()) {
1741 QString line = in.readLine();
1742 if(line=="") continue; //skipping completelly empty lines, even without separators
1743 QStringList fields = line.split(';');
1744 bool emptyLine = true;
1745 if (countRow==0){ // building headers
1746 for(uint i =0;i<fields.size();i++){
1747 data.headers.push_back(fields.at(i).toStdString());
1748 }
1749 } else {
1750 vector<string> record ; //= fields.toVector().toStdVector();
1751 unsigned int z = fields[0].toStdString().find("#");
1752 if( z!=string::npos && z == 0) continue; // found "#" on fist position, it's a comment!
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;
1758 }
1759 if(!emptyLine){data.records.push_back(record);};
1760 }
1761 countRow++;
1762 }
1763 data.clean();
1764 return data;
1765}
string getBaseDirectory()

Referenced by loadInput(), and setScenarioSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTempBool()

bool getTempBool ( )
inline

Definition at line 145 of file ModelData.h.

145{return tempBool;}

Referenced by ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ getTimedData()

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 smaller than the required position.

Definition at line 1480 of file ModelData.cpp.

1480 {
1481
1482 int position;
1483 if(year_h==DATA_NOW){
1484 position = MTHREAD->SCD->getYear()-cached_initialYear;
1485 } else {
1486 position = year_h-cached_initialYear;
1487 }
1488
1489 if(dated_vector.size() > position) {
1490 return dated_vector[position];
1491 } else if (dated_vector.size() > 0 ){
1492 // returning the last available value...
1493 return dated_vector[dated_vector.size()-1];
1494 } else {
1495 msgOut(MSG_CRITICAL_ERROR, "Error in getTimedData: requested value doesn't have any value, even on the first position(year)!");
1496 }
1497 return 0;
1498}

Referenced by dataMapGetValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getValueFoundBool()

bool getValueFoundBool ( )
inline

Definition at line 147 of file ModelData.h.

147{return valueFoundBool;}

◆ getVectorBaseData()

vector< string > getVectorBaseData ( const string &  name_h,
int  type_h,
int  regId_h = WORLD 
)
private

Definition at line 1073 of file ModelData.cpp.

1073 {
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);
1084 } else {
1085 msgOut(MSG_CRITICAL_ERROR, "Error in getBaseData(). Data requested for a unknown region level.");
1086 }
1087
1088 for (uint j=0; j<regIds.size();j++){
1089 int regId = regIds[j];
1090 for (uint i=0; i<programSettingsVector.size();i++){
1091 if (programSettingsVector.at(i).name == name_h & programSettingsVector.at(i).regId == regId){
1092 int type = programSettingsVector.at(i).type;
1093 if(type != type_h){msgOut(MSG_CRITICAL_ERROR, "mismatching type in calling getVectorBaseData() for "+name_h);}
1094 return programSettingsVector.at(i).values;
1095 }
1096 }
1097 }
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;
1100 return toReturn;
1101}

Referenced by getBoolVectorSetting(), getDoubleVectorSetting(), getIntVectorSetting(), and getStringVectorSetting().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadInput()

void loadInput ( )

Unzip the OpenOffice input file (NEW 2008.05.13)

Definition at line 1527 of file ModelData.cpp.

1527 {
1528 msgOut(MSG_INFO, "Loading input files (this can take a few minutes)...");
1529 //QString iFile("data/ffsmInput.ods");
1530 QString iFile(MTHREAD->getInputFileName().c_str());
1531 //cout << "PIPPO !!!!! " << MTHREAD->getInputFileName().c_str() << endl;
1532
1533 //std::random_device rd;
1534 //std::mt19937 localgen(rd());
1535 std::mt19937 localgen(time(0));
1536 std::uniform_int_distribution<> dis(10, 1000000);
1537 int randomNumber = dis(localgen);
1538
1539 QString oDir((MTHREAD->getBaseDirectory()+"tempInput-"+MTHREAD->getScenarioName()+i2s(randomNumber)).c_str());
1540 string forDataCachedFilename = MTHREAD->getBaseDirectory()+"cachedInput/forData.csv";
1541 string prodDataCachedFilename = MTHREAD->getBaseDirectory()+"cachedInput/prodData.csv";
1542
1543 // removing output directory if exist..
1544 QDir oQtDir(oDir);
1545
1546 if(oQtDir.exists()){
1547 bool deleted;
1548 deleted = delDir(oDir);
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)");}
1551 }
1552
1553 if (!QFile::exists(iFile))
1554 {
1555 cout << "File does not exist." << endl << endl;
1556 //return false;
1557 }
1559 UnZip uz;
1560 ec = uz.openArchive(iFile);
1561 if (ec != UnZip::Ok) {
1562 //cout << "Failed to open archive: " << uz.formatError(ec).toAscii().data() << endl << endl; // Qt4
1563 cout << "Failed to open archive: " << uz.formatError(ec).toLatin1().data() << endl << endl; // Qt5
1564 //return false;
1565 }
1566 ec = uz.extractAll(oDir);
1567 if (ec != UnZip::Ok){
1568 //cout << "Extraction failed: " << uz.formatError(ec).toAscii().data() << endl << endl; // Qt4
1569 cout << "Extraction failed: " << uz.formatError(ec).toLatin1().data() << endl << endl; // Qt5
1570 uz.closeArchive();
1571 //return false;
1572 }
1573
1574 // loading input file into memory...
1575 string inputXMLFileName = MTHREAD->getBaseDirectory()+"tempInput-"+MTHREAD->getScenarioName()+i2s(randomNumber)+"/content.xml";
1576 //string inputXMLFileName = MTHREAD->getBaseDirectory()+"test/content.xml";
1577 //cout << "inputXMLFileName: " << inputXMLFileName << endl;
1578 //mainDocument = new InputDocument();
1579 mainDocument.setWorkingFile(inputXMLFileName);
1580 //InputNode documentContent = mainDocument.getNodeByName("office:document-content");
1581 //InputNode documentBody = mainDocument.getNodeByName("office:body");
1582 //InputNode mainNode = mainDocument.getNodeByName("spreadsheet");
1583 //InputNode pippo = mainDocument.getNodeByName("pippo-pippo");
1584 //InputNode table = mainDocument.getNodeByName("table");
1585 //cout << "Test result: " << table.getStringContent() << endl;
1586
1587
1588 vector <InputNode> tables = mainDocument.getNodesByName("table");
1589 for(uint i=0;i<tables.size();i++){
1590 string tableName = tables[i].getStringAttributeByName("name");
1591 //cout <<tableName<<endl;
1592 if( (tableName == "forData" || tableName == "prodData") && QFile::exists(forDataCachedFilename.c_str()) ) {
1593 msgOut(MSG_INFO,"Attenction, using cached data (csv) for "+tableName);
1594 string fileName = MTHREAD->getBaseDirectory()+"cachedInput/"+tableName+".csv";
1595 LLDataVector.push_back(MTHREAD->MD->getTableFromFile(tableName, fileName));
1596 continue;
1597 }
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; //empty table or only with headers
1601 // building headers..
1602 vector <InputNode> cells = rows[0].getNodesByName("table-cell",MSG_NO_MSG,true);
1603 for (uint y=0; y<cells.size(); y++){
1604 int repeated = 1;
1605 if( cells[y].hasAttributeByName("number-columns-repeated")){
1606 repeated = cells[y].getIntAttributeByName("number-columns-repeated");
1607 }
1608 for (int q=0;q<repeated;q++){
1609 if( !cells[y].hasChildNode("p") ){
1610 data.headers.push_back(""); // empty header
1611 } else {
1612 data.headers.push_back(cells[y].getNodeByName("p",MSG_NO_MSG,true).getStringContent());
1613 }
1614 }
1615 }
1616 // loading data...
1617 for (uint j=1; j<rows.size();j++){
1618 //cout << j << endl;
1619 vector <InputNode> cells = rows[j].getNodesByName("table-cell",MSG_NO_MSG,true);
1620 //vector <InputNode> cells = rows[j].getChildNodes();
1621 if (cells.size()<1) continue;
1622 vector<string> record;
1623 // checking the first cell is not a comment nor is empty..
1624 int childCount = cells[0].getChildNodesCount();
1625 if (childCount == 0 || !cells[0].hasChildNode("p")) continue; // empty line, first column empty!
1626 string fistCol = cells[0].getNodeByName("p",MSG_NO_MSG,true).getStringContent();
1627 unsigned int z;
1628 z = fistCol.find("#");
1629 if( z!=string::npos && z == 0) continue; // found "#" on fist position, it's a comment!
1630 for (uint y=0; y<cells.size(); y++){
1631 int repeated = 1;
1632 if( cells[y].hasAttributeByName("number-columns-repeated")){
1633 repeated = cells[y].getIntAttributeByName("number-columns-repeated");
1634 }
1635 for (int q=0;q<repeated;q++){
1636 if( !cells[y].hasChildNode("p") ){
1637 record.push_back(""); // empty header
1638 } else {
1639 // changed 20120625 as for float values the content of p is the visualised value, not the full memorised one.
1640 // this is strange because tought I already tested it.. but maybe is changed the format??
1641 if(cells[y].getStringAttributeByName("value-type")=="float"){
1642 record.push_back(cells[y].getStringAttributeByName("value"));
1643 } else {
1644 record.push_back(cells[y].getNodeByName("p",MSG_NO_MSG,true).getStringContent());
1645 }
1646 }
1647 }
1648 }
1649 data.records.push_back(record);
1650 }
1651 data.clean();
1652 LLDataVector.push_back(data);
1653 }
1654
1655 //debug !!!
1656 /*for (uint i=0; i<LLDataVector.size();i++){
1657 cout << "***************** NEW TABLE: " << LLDataVector[i].tableName << endl;
1658 //cout << "***** Headers: "<< endl;
1659 int headerSize = LLDataVector[i].headers.size();
1660 bool ok = true;
1661 cout << "Header size: " << headerSize << endl;
1662 //for (uint j=0; j<LLDataVector[i].headers.size();j++){
1663 // cout << "["<<j<<"] " << LLDataVector[i].headers[j] << endl;
1664 //}
1665 //cout << "***** Records: " << endl;
1666 for (uint j=0; j<LLDataVector[i].records.size();j++){
1667 //cout << "** Record "<<j<<":"<<endl;
1668 if(LLDataVector[i].records[j].size() != headerSize){
1669 cout << "There is a problem on record " << j <<"!"<< endl;
1670 cout << "His size is: "<< LLDataVector[i].records[j].size() << endl;
1671 ok = false;
1672 }
1673 //for (uint y=0; y<LLDataVector[i].records[j].size();y++){
1674 // cout << "["<<y<<"] " << LLDataVector[i].records[j][y] << endl;
1675 //}
1676 }
1677 if(!ok) {cout <<"Problems with this table :-( !"<<endl;}
1678 }*/
1679
1680
1681
1682 // deleting output directory if exist...
1683 if(oQtDir.exists()){
1684 bool deleted;
1685 deleted = delDir(oDir);
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)");}
1688 }
1689}
@ MSG_DEBUG
Print a debug message, normally filtered out.
Definition BaseClass.h:58
@ MSG_WARNING
Print a WARNING message.
Definition BaseClass.h:60
bool setWorkingFile(std::string filename_h)
Load the file on memory. Return false if no success.
Definition InputNode.cpp:37
vector< InputNode > getNodesByName(string nodeName_h, int debugLevel=MSG_WARNING, bool childFlag=false)
InputNode mainDocument
For each agricultural soil type (as defined in the setting "agrLandTypes") this list define the objec...
Definition ModelData.h:243
LLData getTableFromFile(string tablename, string filename_h)
Load and return a data table from a file (instead that from a spreadsheet sheet)
string getInputFileName()
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
Definition unzip.h:46
void closeArchive()
Definition unzip.cpp:226
ErrorCode openArchive(const QString &filename)
Definition unzip.cpp:190
QString formatError(UnZip::ErrorCode c) const
Definition unzip.cpp:241
ErrorCode
Definition unzip.h:49
@ Ok
Definition unzip.h:50
ErrorCode extractAll(const QString &dirname, ExtractionOptions options=ExtractPaths)
Definition unzip.cpp:325

Referenced by MainProgram::MainProgram().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeKeyForData()

string makeKeyForData ( const string &  parName,
const string &  regId,
const string &  forType,
const string &  diamClass 
) const
inline

Definition at line 173 of file ModelData.h.

173{return parName+"#"+regId+"#"+forType+"#"+diamClass+"#";}

Referenced by applyOverrides(), getForData(), setDefaultForData(), setForData(), and setScenarioForData().

Here is the caller graph for this function:

◆ makeKeyProdData()

string makeKeyProdData ( const string &  parName,
const string &  regId,
const string &  prod,
const string &  freeDim = "" 
) const
inline

Definition at line 172 of file ModelData.h.

172{return parName+"#"+regId+"#"+prod+"#"+freeDim+"#";}

Referenced by applyOverrides(), getProdData(), setDefaultProdData(), setProdData(), and setScenarioProdData().

Here is the caller graph for this function:

◆ regId2RegSName()

string regId2RegSName ( const int &  regId_h) const

Definition at line 408 of file ModelData.cpp.

408 {
409 ModelRegion* reg = MTHREAD->MD->getRegion(regId_h);
410 return reg->getRegSName();
411}
string getRegSName() const
Definition ModelRegion.h:67

Referenced by Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDetailedHV(), Output::printForestData(), and Output::printProductData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ regionExist()

bool regionExist ( const int &  regId_h) const

Definition at line 356 of file ModelData.cpp.

356 {
357 for (int i=0; i< regionsVector.size();i++){
358 if(regionsVector[i].getRegId()==regId_h){
359 return true;
360 }
361 }
362 return false;
363}

Referenced by applyOverrides().

Here is the caller graph for this function:

◆ regSName2RegId()

int regSName2RegId ( const string &  regSName_h) const

Definition at line 414 of file ModelData.cpp.

414 {
415 ModelRegion* reg;
416 for(uint i=0; i<3; i++){
417 vector <int> regIds = MTHREAD->MD->getRegionIds(i, false);
418 for(uint j=0;j<regIds.size();j++){
419 reg = MTHREAD->MD->getRegion(regIds[j]);
420 if(reg->getRegSName()==regSName_h) {return regIds[j];}
421 }
422 }
423 msgOut(MSG_CRITICAL_ERROR,"Regional short name not found.");
424}
Here is the call graph for this function:

◆ setBaseDiretory()

void setBaseDiretory ( string  baseDirectory_h)
inline

Definition at line 183 of file ModelData.h.

183{baseDirectory=baseDirectory_h;}

Referenced by MainProgram::MainProgram().

Here is the caller graph for this function:

◆ setDefaultForData()

void setDefaultForData ( )

Definition at line 481 of file ModelData.cpp.

481 {
482 msgOut(MSG_DEBUG,"Loading forest sector data..");
483 LLData table = getTable("forData");
484 int nheaders = table.nheaders();
485 for (int i=0; i< table.nrecords();i++){
486 vector <double> values;
487 for (int z=0;z<nheaders-4;z++){ // don't consider parName, region, forType and diamClass headers
488 string toSearch = "value_"+i2s(z);
489 string value = table.getData(i,toSearch);
490 if (value != ""){
491 values.push_back(s2d(value));
492 }
493 }
494 string keys = makeKeyForData(table.getData(i,"parName"), table.getData(i,"region"),table.getData(i,"forType"),table.getData(i,"freeDim"));
495 forDataMap.insert(std::pair<string, vector<double> >(keys, values));
496 }
497}
int nheaders()
Definition ModelData.h:337

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDefaultPathogenRules()

void setDefaultPathogenRules ( )

Definition at line 678 of file ModelData.cpp.

678 {
679
680 if(!getBoolSetting("usePathogenModule")) return;
681 msgOut(MSG_DEBUG,"Loading pathogen rules..");
682 LLData table = getTable("pathRules");
683 int nheaders = table.nheaders();
684 for (int i=0; i< table.nrecords();i++){
685 pathRule PR;
686 PR.forType = table.getData(i,"forType");
687 PR.dClass = table.getData(i,"dClass");
688 PR.pathId = table.getData(i,"path_name");
689 PR.pres_min = s2d(table.getData(i,"pres_min"));
690
691 vector <double> values;
692 for (int z=0;z<nheaders-4;z++){ // don't consider forType, dClass, path_name and pres_min headers
693 string toSearch = "year_"+i2s(z);
694 string value = table.getData(i,toSearch);
695 if (value != ""){
696 values.push_back(s2d(value));
697 }
698 }
699 PR.mortCoefficents = values;
700
701 pathRules.push_back(PR);
702 }
703}
Pathogen rule (how pathogen presense influence mortality) for a given forest type and diameter class ...
Definition ModelData.h:318
string dClass
Definition ModelData.h:320
string forType
Definition ModelData.h:319
vector< double > mortCoefficents
Mortality coefficients ordered by number of presence of the pathogen, e.g. first value is the mortali...
Definition ModelData.h:323
double pres_min
Minimum level of presence of the pathogen to be counted as present (tolerance threshold)
Definition ModelData.h:322
string pathId
Pathogen id (name)
Definition ModelData.h:321

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDefaultProdData()

void setDefaultProdData ( )

Definition at line 531 of file ModelData.cpp.

531 {
532
533 msgOut(MSG_DEBUG,"Loading products data..");
534 LLData table = getTable("prodData");
535 int nheaders = table.nheaders();
536
537 for (int i=0; i< table.nrecords();i++){
538// prodData PDATA;
539// PDATA.parName = table.getData(i,"parName");
540// PDATA.region = s2i(table.getData(i,"region"));
541// PDATA.prod = table.getData(i,"prod");
542// PDATA.freeDim = table.getData(i,"freeDim");
543 vector <double> values;
544 for (int z=0;z<nheaders-4;z++){ // don't consider parName, region, prod and freeDim headers
545 string toSearch = "value_"+i2s(z);
546 string value = table.getData(i,toSearch);
547 if (value != ""){
548 values.push_back(s2d(value));
549 }
550 }
551// PDATA.values = values;
552// prodDataVector.push_back(PDATA);
553 string keys = makeKeyProdData(table.getData(i,"parName"), table.getData(i,"region"),table.getData(i,"prod"),table.getData(i,"freeDim"));
554 prodDataMap.insert(std::pair<string, vector<double> >(keys, values));
555 //giving a link to it to its own region:
556// getRegion(PDATA.region)->addProdData(&PDATA);
557 }
558}

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDefaultProductResourceMatrixLink()

void setDefaultProductResourceMatrixLink ( )

Definition at line 618 of file ModelData.cpp.

618 {
619 msgOut(MSG_DEBUG,"Loading forest resource to primary products io matrix..");
620 LLData table = getTable("forToProd");
621 for (int i=0; i< table.nrecords();i++){
622 forToProd F2PDATA;
623 F2PDATA.product = table.getData(i,"product");
624 F2PDATA.forType = table.getData(i,"forType");
625 F2PDATA.dClass = table.getData(i,"dClass");
626 F2PDATA.maxYears = s2i(table.getData(i,"maxYears"));
627 forToProdVector.push_back(F2PDATA);
628 }
629}
IO production matrix between the forest resources and the primary products (struct)
Definition ModelData.h:280
string dClass
Definition ModelData.h:283
string product
Definition ModelData.h:281
int maxYears
The maximum year for a tree collapse that this product can be harvested from. E.g....
Definition ModelData.h:285
string forType
Definition ModelData.h:282

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDefaultSettings()

void setDefaultSettings ( )

Definition at line 194 of file ModelData.cpp.

194 {
195
196 LLData table = getTable("settings");
197 int nheaders = table.nheaders();
198 for (int i=0; i< table.nrecords();i++){
199 BasicData SETT;
200 SETT.name = table.getData(i,"name");
201 string type = table.getData(i,"type");
202 SETT.type = getType(type);
203 string region_s= table.getData(i,"region");
204 SETT.regId = region_s==""?WORLD:s2i(table.getData(i,"region"));
205 SETT.comment = table.getData(i,"comment");
206 vector <string> values;
207 for (int z=0;z<nheaders-4;z++){ // don't consider name, type, comment and region headers
208 string toSearch = "value_"+i2s(z);
209 string value = table.getData(i,toSearch);
210 if (value != ""){
211 values.push_back(value);
212 }
213 }
214 SETT.values = values;
215 programSettingsVector.push_back(SETT);
216 }
217
218 msgOut(MSG_INFO,"### USING SCENARIO: "+MTHREAD->getScenarioName()+" ###");
219
220 setOutputDirectory(getStringSetting("outputDirname").c_str());
221}
int getType(const string &type_h) const
Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2))
void setOutputDirectory(const char *output_dirname_h)
string getStringSetting(const string &name_h, int position=0, int reg=WORLD) const

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setErrorLevel()

void setErrorLevel ( int  errorLevel_h)
inline

Definition at line 143 of file ModelData.h.

143{errorLevel=errorLevel_h;}

Referenced by ModelCore::computeCumulativeData(), ModelCoreSpatial::computeCumulativeData(), Output::print(), Output::printFinalOutput(), and ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ setForData()

void setForData ( const double &  value_h,
const string &  type_h,
const int &  regId_h,
const string &  forType_h,
const string &  freeDim_h,
const int &  year = DATA_NOW,
const bool &  allowCreate = false 
)

Definition at line 1412 of file ModelData.cpp.

1412 {
1413
1414 vector<int> regIds;
1415 vector <string> dClasses;
1416 vector <string> fTypes;
1417 string key;
1418 DataMap::const_iterator p;
1419 bool found = false;
1420 bool tempFound = false;
1421
1422 if (forType_h == FT_ALL){
1423 fTypes = getForTypeIds();
1424 } else {
1425 fTypes.push_back(forType_h);
1426 }
1427
1428 if(freeDim_h == DIAM_ALL){
1429 dClasses = diamClasses;
1430 } else if (freeDim_h == DIAM_PROD){
1431 dClasses = getDiameterClasses(true);
1432 } else if (freeDim_h == DIAM_FIRST){
1433 dClasses.push_back(diamClasses.at(0));
1434 } else {
1435 dClasses.push_back(freeDim_h);
1436 }
1437
1438 // Make sure to set the new value to all l2 regions if requested for a reg1 level
1439 if(getRegion(regId_h)->getRegLevel()==2){
1440 regIds.push_back(regId_h);
1441 } else if (getRegion(regId_h)->getRegLevel()==1) {
1442 for(uint i=0;i<getRegion(regId_h)->getNChildren();i++){
1443 regIds.push_back(getRegion(regId_h)->getChildren()[i]->getRegId());
1444 }
1445 } else {
1446 msgOut(MSG_CRITICAL_ERROR, "Error in setProdData(). Setting a value for the whole World is not supported.");
1447 }
1448 int regIdsS = regIds.size();
1449
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++){
1453 key = makeKeyForData(type_h,i2s(regIds[r]),fTypes[y],dClasses[i]);
1454 tempFound = dataMapSetValue(forDataMap,key,value_h, year,true);
1455 if(tempFound) found = true;
1456 }
1457 }
1458 }
1459
1460 if(!found){
1461 if(!allowCreate){
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.");
1463 } else {
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++){
1467 key = makeKeyForData(type_h,i2s(regIds[r]),fTypes[y],dClasses[i]);
1468 vector <double> values;
1469 setTimedData(value_h,values,year,MSG_NO_MSG);
1470 forDataMap.insert(DataPair(key,values));
1471 }
1472 }
1473 }
1474 }
1475 }
1476}
int dataMapSetValue(DataMap &map, const string &search_for, const double &value_h, const int &year_h, const bool &exactMatch=true)

Referenced by Opt::sfd(), ModelCore::sfd(), and ModelCoreSpatial::sfd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setForestTypes()

void setForestTypes ( )

Definition at line 648 of file ModelData.cpp.

648 {
649 LLData table = getTable("forTypes");
650 for (int i=0; i< table.nrecords();i++){
651 forType FTYPE;
652 FTYPE.forTypeId = table.getData(i,"forTypeId");
653 FTYPE.forLabel = table.getData(i,"forLabel");
654 FTYPE.memType = s2i(table.getData(i,"memType"));
655 FTYPE.forLayer = table.getData(i,"forLayer");
656 FTYPE.ereditatedFrom = table.getData(i,"ereditatedFrom");
657 if(FTYPE.memType == 3 && !getBoolSetting("useSpExplicitForestTypes")) continue;
658 forTypes.push_back(FTYPE);
659 }
660}
string forTypeId
Definition ModelData.h:294
string forLayer
Definition ModelData.h:297
string forLabel
Definition ModelData.h:295
int memType
Definition ModelData.h:296

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setOutputDirectory()

void setOutputDirectory ( const char *  output_dirname_h)

Definition at line 990 of file ModelData.cpp.

990 {
991
992 if (strlen(output_dirname_h)==0){
994 }
995 else {
996 outputDirname=output_dirname_h;
997 }
998 MTHREAD->setOutputDirName(outputDirname); //for the GUI
999}
void setOutputDirName(string outputDirname_h)

Referenced by setDefaultSettings(), and setScenarioSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setProdData()

void setProdData ( const double &  value_h,
const string &  type_h,
const int &  regId_h,
const string &  prodId_h,
const int &  year = DATA_NOW,
const bool &  allowCreate = false,
const string &  freeDim_h = "" 
)

Basic function to set products-related data. It can change an existing value or extend in time a serie, but it requires the keys (par. name/regId/prodId/freedim) to be already present in the data. @value_h New value to change with/add It addmits the following "filters": @type_h Name of the specific parameter requested @regId_h Set a specific level 2 region, or all its childred l2 region if a reg1 level is specified. @prodId_h Product. It accept three keywords, for changing/inserting the new value to all products, primary products or secondary products, namelly PROD_ALL, PROD_PRI, PROD_SEC. @year Unless specified, set the value of the current year. If array is smaller (e.g. because it is time-independent) fill all the values till the requested one. @create If true, allow creation of new data if not found. Default false (rise an error) @freeDim_h If specified, look exactly for it, otherwise simply doesn't filter for it.

Definition at line 1352 of file ModelData.cpp.

1352 {
1353
1354 vector<int> regIds;
1355 string key;
1356 DataMap::const_iterator p;
1357 vector <string> products;
1358
1359 if(prodId_h == PROD_PRI){
1360 products = priProducts;
1361 } else if (prodId_h == PROD_SEC){
1362 products = secProducts;
1363 } else if (prodId_h == PROD_ALL){
1364 products = allProducts;
1365 } else {
1366 products.push_back(prodId_h);
1367 }
1368
1369 // Make sure to set the new value to all l2 regions if requested fora reg1 level
1370 if(getRegion(regId_h)->getRegLevel()==2){
1371 regIds.push_back(regId_h);
1372 } else if (getRegion(regId_h)->getRegLevel()==1) {
1373 for(uint i=0;i<getRegion(regId_h)->getNChildren();i++){
1374 regIds.push_back(getRegion(regId_h)->getChildren()[i]->getRegId());
1375 }
1376 } else {
1377 msgOut(MSG_CRITICAL_ERROR, "Error in setProdData(). Setting a value for the whole World is not supported.");
1378 }
1379
1380 bool found = false;
1381 bool tempFound = false;
1382
1383 for(uint r=0;r< regIds.size();r++){
1384 for(uint i=0;i<products.size();i++){
1385 key = makeKeyProdData(type_h,i2s(regIds[r]),products[i],freeDim_h);
1386 tempFound = dataMapSetValue(prodDataMap,key,value_h, year,true);
1387 if(tempFound) found = true;
1388 }
1389 }
1390
1391 if(!found){
1392 if(!allowCreate){
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.");
1394 } else {
1395 for(uint r=0;r< regIds.size();r++){
1396 for(uint i=0;i<products.size();i++){
1397 key = makeKeyProdData(type_h,i2s(regIds[r]),products[i],freeDim_h);
1398 vector <double> values;
1399 setTimedData(value_h,values,year,MSG_NO_MSG);
1400 prodDataMap.insert(DataPair(key,values));
1401 }
1402 }
1403 }
1404 }
1405
1406}

Referenced by ModelCore::spd(), ModelCoreSpatial::spd(), and Opt::spd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setReclassificationRules()

void setReclassificationRules ( )

Definition at line 663 of file ModelData.cpp.

663 {
664
665 msgOut(MSG_DEBUG,"Loading (but not yet applying) reclassification rules..");
666 LLData table = getTable("reclRules");
667 for (int i=0; i< table.nrecords();i++){
668 reclRule RL;
669 RL.regId = s2i(table.getData(i,"regID"));
670 RL.forTypeIn = table.getData(i,"forTypeIn");
671 RL.forTypeOut = table.getData(i,"forTypeOut");
672 RL.coeff = s2d(table.getData(i,"coeff"));
673 reclRules.push_back(RL);
674 }
675}

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScenarioData()

void setScenarioData ( )

Set the infos about this scenario (long description and overriding tables)

Definition at line 170 of file ModelData.cpp.

170 {
171 LLData table = getTable("scenarios");
172 string choosenScenario = MTHREAD->getScenarioName();
173 for(int i=0;i<table.nrecords();i++){
174 string recordScenarioName = table.getData(i,"id");
175 if (recordScenarioName == choosenScenario){
176 scenario.id = recordScenarioName;
177 scenario.shortDesc = table.getData(i,"shortDesc");
178 scenario.longDesc = table.getData(i,"longDesc");
179 scenario.settingTable = table.getData(i,"settingTable");
180 scenario.forDataTable = table.getData(i,"forDataTable");
181 scenario.prodDataTable = table.getData(i,"prodDataTable");
182 scenario.forToProdTable = table.getData(i,"forToProdTable");
183 scenario.pathTable = table.getData(i,"pathTable");
184 scenario.settingFile = table.getData(i,"settingFile");
185 return;
186 }
187 }
188 msgOut(MSG_CRITICAL_ERROR, "Scenario not found!");
189
190
191}
scenarioData scenario
Definition ModelData.h:202
string longDesc
Definition ModelData.h:63
string prodDataTable
Definition ModelData.h:66
string forDataTable
Definition ModelData.h:65
string settingFile
Definition ModelData.h:69
string forToProdTable
Definition ModelData.h:67
string pathTable
Definition ModelData.h:68
string settingTable
Definition ModelData.h:64
string shortDesc
Definition ModelData.h:62
string id
Definition ModelData.h:61

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScenarioForData()

void setScenarioForData ( )

Definition at line 500 of file ModelData.cpp.

500 {
501
502 if(scenario.forDataTable==""){return;}
504
505 int nheaders = table.nheaders();
506 for(int i=0; i< table.nrecords(); i++){
507 bool found = false;
508 string key = makeKeyForData(table.getData(i,"parName"),table.getData(i,"region"),table.getData(i,"forType"),table.getData(i,"freeDim"));
509 vector <double> values;
510 for (int z=0;z<nheaders-4;z++){ // don't consider parName, region, forType and diamClass headers
511 string toSearch = "value_"+i2s(z);
512 string value = table.getData(i,toSearch);
513 if (value != ""){
514 values.push_back(s2d(value));
515 }
516 }
517 map <string, vector < double > >::iterator p;
518 p=forDataMap.find(key);
519 if(p != forDataMap.end()) {
520 // updating an existing record
521 p->second = values;
522 }
523 else {
524 // new one, adding it
525 forDataMap.insert(std::pair<string, vector<double> >(key, values));
526 }
527 }
528}

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScenarioPathogenRules()

void setScenarioPathogenRules ( )

Definition at line 706 of file ModelData.cpp.

706 {
707
708 if(scenario.pathTable==""){return;}
709 LLData table = getTable(scenario.pathTable, MSG_CRITICAL_ERROR); //this scenario could not have an associated setting sheet
710
711 int nheaders = table.nheaders();
712 for (int i=0; i< table.nrecords();i++){
713 pathRule PR;
714 PR.forType = table.getData(i,"forType");
715 PR.dClass = table.getData(i,"dClass");
716 PR.pathId = table.getData(i,"path_name");
717 PR.pres_min = s2d(table.getData(i,"pres_min"));
718
719 vector <double> values;
720 for (int z=0;z<nheaders-4;z++){ // don't consider forType, dClass, path_name and pres_min headers
721 string toSearch = "year_"+i2s(z);
722 string value = table.getData(i,toSearch);
723 if (value != ""){
724 values.push_back(s2d(value));
725 }
726 }
727 PR.mortCoefficents = values;
728
729 bool found = false;
730 for(uint i=0;i<pathRules.size();i++){
731 if( pathRules[i].forType == PR.forType
732 && pathRules[i].dClass == PR.dClass
733 && pathRules[i].pathId == PR.pathId
734 ){
735 pathRules[i].pres_min = PR.pres_min;
736 pathRules[i].mortCoefficents = PR.mortCoefficents;
737 found = true;
738 break;
739 }
740 }
741 if(!found){
742 pathRules.push_back(PR);
743 }
744 } // end for each table record
745}

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScenarioProdData()

void setScenarioProdData ( )

Definition at line 561 of file ModelData.cpp.

561 {
562
563 if(scenario.prodDataTable==""){return;}
564 LLData table = getTable(scenario.prodDataTable, MSG_CRITICAL_ERROR); //this scenario could not have an associated setting sheet
565
566 int nheaders = table.nheaders();
567 int debug = table.nrecords();
568 for(int i=0; i< table.nrecords(); i++){
569 //prodData PDATA;
570 bool found = false;
571 string key = makeKeyProdData(table.getData(i,"parName"),table.getData(i,"region"),table.getData(i,"prod"),table.getData(i,"freeDim"));
572
573 //PDATA.parName = table.getData(i,"parName");
574 //PDATA.region = s2i(table.getData(i,"region"));
575 //PDATA.prod = table.getData(i,"prod");
576 //PDATA.freeDim = table.getData(i,"freeDim");
577 vector <double> values;
578 for (int z=0;z<nheaders-4;z++){// don't consider parName, region, prod and freeDim headers
579 string toSearch = "value_"+i2s(z);
580 string value = table.getData(i,toSearch);
581 if (value != ""){
582 values.push_back(s2d(value));
583 }
584 }
585 //PDATA.values = values;
586 //for(uint i=0;i<prodDataVector.size();i++){
587 // if(prodDataVector[i].parName == PDATA.parName
588 // && prodDataVector[i].region == PDATA.region
589 // && prodDataVector[i].prod == PDATA.prod
590 // && prodDataVector[i].freeDim == PDATA.freeDim){
591 // // existing prodData..
592 // prodDataVector[i].values = PDATA.values;
593 // found = true;
594 // break;
595 // }
596 //}
597 //if(!found){
598 // // new one, adding it
599 // prodDataVector.push_back(PDATA);
600 // //giving a link to it to its own region:
601 // getRegion(PDATA.region)->addProdData(&PDATA);
602 //}
603
604 map <string, vector < double > >::iterator p;
605 p=prodDataMap.find(key);
606 if(p != prodDataMap.end()) {
607 // updating an existing record
608 p->second = values;
609 }
610 else {
611 // new one, adding it
612 prodDataMap.insert(std::pair<string, vector<double> >(key, values));
613 }
614 }
615}

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScenarioProductResourceMatrixLink()

void setScenarioProductResourceMatrixLink ( )

Definition at line 632 of file ModelData.cpp.

632 {
633 if(scenario.forToProdTable==""){return;}
634 LLData table = getTable(scenario.forToProdTable, MSG_CRITICAL_ERROR); //this scenario could not have an associated setting sheet
635
636 int nheaders = table.nheaders();
637 forToProdVector.clear();
638 for (int i=0; i< table.nrecords();i++){
639 forToProd F2PDATA;
640 F2PDATA.product = table.getData(i,"product");
641 F2PDATA.forType = table.getData(i,"forType");
642 F2PDATA.dClass = table.getData(i,"dClass");
643 forToProdVector.push_back(F2PDATA);
644 }
645}

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScenarioSettings()

void setScenarioSettings ( )

Definition at line 224 of file ModelData.cpp.

224 {
225
226 if(scenario.settingTable=="" && scenario.settingFile=="") {return;}
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.");
229 }
230 LLData table(MTHREAD,"settings");
231 if(scenario.settingTable!=""){
232 table = getTable(scenario.settingTable, MSG_CRITICAL_ERROR); //this scenario could not have an associated setting sheet
233 } else {
234 table = getTableFromFile("settings",scenario.settingFile);
235 }
236
237
238
239 int nheaders = table.nheaders();
240 for(int i=0; i< table.nrecords(); i++){
241 string name = table.getData(i,"name");
242 string stype = table.getData(i,"type");
243 int type = getType(stype);
244 string region_s= table.getData(i,"region");
245 int regId = region_s==""?WORLD:s2i(table.getData(i,"region"));
246 string comment = table.getData(i,"comment");
247 vector <string> values;
248 for (int z=0;z<nheaders-4;z++){ // don't consider name, type and comment headers
249 string toSearch = "value_"+i2s(z);
250 string value = table.getData(i,toSearch);
251 if (value != ""){
252 values.push_back(value);
253 }
254 }
255 bool found = false;
256 for(uint i=0;i<programSettingsVector.size();i++){
257 if(programSettingsVector[i].name == name && programSettingsVector[i].regId == regId){
258 programSettingsVector[i].values = values;
259 programSettingsVector[i].type = type;
260 programSettingsVector[i].comment = comment;
261 found = true;
262 break;
263 }
264 }
265 if(!found){
266 BasicData SETT;
267 SETT.name = name;
268 SETT.type = type;
269 SETT.regId = regId;
270 SETT.comment = comment;
271 SETT.values = values;
272 programSettingsVector.push_back(SETT);
273 }
274
275 }
276
277 setOutputDirectory(getStringSetting("outputDirname").c_str());
278}

Referenced by Init::setInitLevel1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSpace()

void setSpace ( )

◆ setTempBool()

void setTempBool ( bool  tempBool_h)
inline

Definition at line 146 of file ModelData.h.

146{tempBool = tempBool_h;}

Referenced by ModelCoreSpatial::runManagementModule().

Here is the caller graph for this function:

◆ setTimedData()

void setTimedData ( const double &  value_h,
vector< double > &  dated_vector,
const int &  year_h,
const int &  MSG_LEVEL = MSG_WARNING 
)

Definition at line 1501 of file ModelData.cpp.

1501 {
1502
1503 int position;
1504 if(year_h==DATA_NOW){
1505 position = MTHREAD->SCD->getYear()-cached_initialYear;
1506 } else {
1507 position = year_h-cached_initialYear;
1508 }
1509
1510 int originalVectorSize = dated_vector.size();
1511 if(dated_vector.size() > position) {
1512 dated_vector[position]=value_h;
1513 } else {
1514 // extending the vector and filling it with the incoming value, but issuing a warning if done for more than one year
1515
1516 for(uint i=0;i<position-originalVectorSize+1;i++){
1517 dated_vector.push_back(value_h);
1518 }
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.");
1521 }
1522 }
1523}

Referenced by dataMapSetValue(), setForData(), and setProdData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setValueFoundBool()

void setValueFoundBool ( bool  valueFoundBool_h)
inline

Definition at line 148 of file ModelData.h.

148{valueFoundBool = valueFoundBool_h;}

◆ unpackKeyForData()

void unpackKeyForData ( const string &  key,
string &  parName,
int &  regId,
string &  forType,
string &  diamClass 
) const

Definition at line 1922 of file ModelData.cpp.

1922 {
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){
1928 msgOut(MSG_CRITICAL_ERROR, "Error in unpacking a key in the map of production data.");
1929 }
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);
1936
1937}

Referenced by applyOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unpackKeyProdData()

void unpackKeyProdData ( const string &  key,
string &  parName,
int &  regId,
string &  prod,
string &  freeDim 
) const

Definition at line 1903 of file ModelData.cpp.

1903 {
1904
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){
1910 msgOut(MSG_CRITICAL_ERROR, "Error in unpacking a key in the map of production data.");
1911 }
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);
1918
1919}

Referenced by applyOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ Output::printForestData

void Output::printForestData ( bool  finalFlush)
friend

◆ Output::printProductData

void Output::printProductData ( bool  finalFlush)
friend

Member Data Documentation

◆ allProducts

vector<string> allProducts
private

Definition at line 237 of file ModelData.h.

Referenced by cacheSettings(), getProdData(), and setProdData().

◆ baseDirectory

string baseDirectory
private

◆ cached_initialYear

int cached_initialYear
private

Definition at line 234 of file ModelData.h.

Referenced by cacheSettings(), getCachedInitialYear(), getTimedData(), and setTimedData().

◆ deathTimberInventory

map<iisskey, double > deathTimberInventory
private

Map that register the death of biomass still usable as timber by year, l2_region, forest type and diameter class [Mm^3 wood].

Definition at line 230 of file ModelData.h.

Referenced by deathTimberInventory_get(), deathTimberInventory_incr(), deathTimberInventory_incrOrAdd(), getAvailableDeathTimber(), and getDeathTimberInventory().

◆ diamClasses

vector<string> diamClasses
private

◆ errorLevel

int errorLevel
private

◆ forDataMap

map<string, vector<double> > forDataMap
private

Forestry data.

Definition at line 217 of file ModelData.h.

Referenced by applyOverrides(), getForData(), setDefaultForData(), setForData(), and setScenarioForData().

◆ forToProdVector

vector<forToProd> forToProdVector
private

Vector of coefficients from forest resources to primary products.

Definition at line 219 of file ModelData.h.

Referenced by assessProdPossibility(), getMaxYearUsableDeathTimber(), getMaxYearUsableDeathTimber(), setDefaultProductResourceMatrixLink(), and setScenarioProductResourceMatrixLink().

◆ forTypes

vector<forType> forTypes
private

◆ iFilesVector

vector<IFiles> iFilesVector
private

List of all input files. Simple (struct)

Definition at line 221 of file ModelData.h.

Referenced by getFilenameByType(), and getIFilesVector().

◆ inputFilename

string inputFilename
private

Definition at line 213 of file ModelData.h.

◆ l2r

vector< vector <int> > l2r
private

Region2 ids.

Definition at line 229 of file ModelData.h.

◆ LLDataVector

vector<LLData> LLDataVector
private

Vector of Low Level Data.

Definition at line 223 of file ModelData.h.

Referenced by getTable(), and loadInput().

◆ mainDocument

InputNode mainDocument
private

For each agricultural soil type (as defined in the setting "agrLandTypes") this list define the objects that can be placed on that soil type.

the main input document, loaded in memory at unzipping stage

Definition at line 243 of file ModelData.h.

Referenced by loadInput().

◆ outputDirname

string outputDirname
private

Definition at line 214 of file ModelData.h.

Referenced by getOutputDirectory(), and setOutputDirectory().

◆ pathRules

vector<pathRule> pathRules
private

Vector of pathogen rules.

Definition at line 228 of file ModelData.h.

Referenced by getPathMortalityRule(), setDefaultPathogenRules(), and setScenarioPathogenRules().

◆ priProducts

vector<string> priProducts
private

◆ prodDataMap

map<string, vector<double> > prodDataMap
private

Product data.

Definition at line 218 of file ModelData.h.

Referenced by applyOverrides(), getProdData(), setDefaultProdData(), setProdData(), and setScenarioProdData().

◆ programSettingsVector

vector<BasicData> programSettingsVector
private

Setting data. Simple (struct)

Definition at line 222 of file ModelData.h.

Referenced by addSetting(), applyDebugMode(), getBaseData(), getVectorBaseData(), setDefaultSettings(), and setScenarioSettings().

◆ reclRules

vector<reclRule> reclRules
private

Vector of reclassification rules.

Definition at line 227 of file ModelData.h.

Referenced by applyOverrides(), getNReclRules(), getReclRule(), and setReclassificationRules().

◆ regionsVector

vector<ModelRegion> regionsVector
private

Vector of modelled regions.

Definition at line 224 of file ModelData.h.

Referenced by applyDebugMode(), createRegions(), getAllRegions(), getRegion(), getRegionIds(), and regionExist().

◆ scenario

◆ secProducts

vector<string> secProducts
private

Definition at line 236 of file ModelData.h.

Referenced by cacheSettings(), getProdData(), and setProdData().

◆ tempBool

bool tempBool
private

a temporary bool variable used for various functions

Definition at line 239 of file ModelData.h.

Referenced by dataMapGetValue(), getForData(), getProdData(), getTempBool(), ModelData(), and setTempBool().

◆ valueFoundBool

bool valueFoundBool
private

a bool used in getForData() and getProdData() to communicate they didn't found a variable

Definition at line 240 of file ModelData.h.

Referenced by getForData(), getProdData(), getValueFoundBool(), ModelData(), and setValueFoundBool().


The documentation for this class was generated from the following files: