33 typedef map<string, vector <double> >
DataMap;
34 typedef pair<string, vector <double> >
DataPair;
116 for(uint i=0;i<
l1regIds.size();i++){
117 std::vector<int> l2ChildrenIds;
119 std::vector<ModelRegion*> l2Childrens = l1Region->
getChildren(
true);
120 for(uint j=0;j<l2Childrens.size();j++){
121 l2ChildrenIds.push_back(l2Childrens[j]->getRegId());
123 if(l2ChildrenIds.size()){
124 l2r.push_back(l2ChildrenIds);
150 struct tm *current = localtime(&now);
151 string timemessage =
i2s(current->tm_hour)+
":"+
i2s(current->tm_min)+
":"+
i2s(current->tm_sec);
159 out <<
"scenario" <<
d <<
"year" <<
d <<
"time" <<
d <<
"opt flag" <<
d <<
"iterations" <<
d <<
"\n";
162 struct tm *current = localtime(&now);
163 string timemessage =
i2s(current->tm_hour)+
":"+
i2s(current->tm_min)+
":"+
i2s(current->tm_sec);
164 out <<
scenarioName << d <<
"0000" << d << timemessage << d << d << d <<
"\n";
200 out <<
"scenario" <<
d <<
"year" <<
d <<
"region or pixel" <<
d <<
"forType" <<
d <<
"freeDim" <<
d <<
"prod" <<
d <<
"parName" <<
d <<
"value" <<
d <<
"\n";
228 out <<
"scenario" <<
d <<
"year" <<
d <<
"region" <<
d <<
"pxId" <<
d <<
"pxX" <<
d <<
"pxY" <<
d ;
241 for(uint f=0;f<
fTypes.size();f++){
243 for (uint u=0;u<
dClasses.size();u++){
245 string header = ft+
"_"+dc;
249 for(uint f=0;f<
fTypes.size()+1;f++){
250 string ft1 = (f ==
fTypes.size()) ?
"NonFor" :
fTypes[f];
251 for(uint f2=0;f2<
fTypes.size()+1;f2++){
252 string ft2 = (f2 ==
fTypes.size()) ?
"NonFor" :
fTypes[f2];
253 string header = ft1+
"_2_"+ft2;
315 out <<
"scen" <<
d <<
"parName" <<
d <<
"country" <<
d <<
"region" <<
d <<
"forType" <<
d <<
"freeDim" <<
d;
317 for(
int i=0;i<
nYears;i++){
321 out <<
"year" << d <<
"value" <<
d;
331 outHV <<
"scen" << d <<
"parName" << d <<
"country" << d <<
"region" << d <<
"forType" << d <<
"freeDim" << d <<
"prod" << d <<
"year" << d <<
"value" <<
d;
357 out <<
"scen" <<
d <<
"parName" <<
d <<
"country" <<
d <<
"region" <<
d <<
"prod" <<
d <<
"freeDim" <<
d;
359 for(
int i=0;i<
nYears;i++){
363 out <<
"year" << d <<
"value" <<
d;
388 out <<
"scen" <<
d <<
"country" <<
d <<
"region" <<
d <<
"balItem" <<
d;
394 out <<
"year" << d <<
"value" <<
d;
409 string filenameToSaveScenarioName = mapBaseDirectory+
"scenarioNames/"+
scenarioName;
410 string filenameListIntLayers = mapBaseDirectory+
"integerListLayers/"+
scenarioName;
411 string filenameListFloatLayers = mapBaseDirectory+
"floatListLayers/"+
scenarioName;
414 ofstream outSN(filenameToSaveScenarioName.c_str(), ios::out);
415 if (!outSN){
msgOut(
MSG_ERROR,
"Error in opening the file "+filenameToSaveScenarioName+
".");}
416 outSN << scenarioName <<
"\n";
419 ofstream outi(filenameListIntLayers.c_str(), ios::out);
421 ofstream outf(filenameListFloatLayers.c_str(), ios::out);
431 cout << cYear <<
" not printed" << endl;
434 bool printThisYear =
false;
435 for(uint i=0;i<
oYears.size();i++){
490 vector<string>fTypes_temp =
fTypes;
492 fTypes_temp.push_back(
"");
494 fTypes_temp.insert(fTypes_temp.end(),ftParents.begin(),ftParents.end());
496 for (uint r1=0;r1<
l2r.size();r1++){
497 for (uint r2=0;r2<
l2r[r1].size();r2++){
498 for(uint ft=0;ft<fTypes_temp.size();ft++){
500 for(uint dc=0;dc<
dClasses.size();dc++){
505 out << fTypes_temp[ft] <<
d;
508 for(
int y=0;y<
nYears;y++){
510 out << outvalue <<
d;
515 out << currentYear <<
d;
516 out << outvalue <<
d;
525 out << fTypes_temp[ft] <<
d;
528 for(
int y=0;y<
nYears;y++){
530 out << outvalue <<
d;
535 out << currentYear <<
d;
536 out << outvalue <<
d;
619 for (uint r1=0;r1<
l2r.size();r1++){
620 for (uint r2=0;r2<
l2r[r1].size();r2++){
621 for(uint p=0;p<
allPr.size();p++){
624 for(uint r2b=0;r2b<
l2r[r1].size();r2b++){
630 out <<
l2r[r1][r2b] <<
d;
632 for(
int y=0;y<
nYears;y++){
634 out << outvalue <<
d;
643 out << currentYear <<
d;
644 out << outvalue <<
d;
656 for(
int y=0;y<
nYears;y++){
658 out << outvalue <<
d;
663 out << currentYear <<
d;
664 out << outvalue <<
d;
731 if (currentYear ==
inYear) {
return;}
746 for (uint r1=0;r1<
l2r.size();r1++){
747 for (uint r2=0;r2<
l2r[r1].size();r2++){
748 int regId =
l2r[r1][r2];
749 for (uint b=0;b<balItems.size();b++){
753 string balItemString;
756 balItemString =
"STOCK_INV";
761 balItemString =
"STOCK_EXTRA";
766 balItemString =
"STOCK_PRODUCTS";
771 balItemString =
"EM_ENSUB";
776 balItemString =
"EM_MATSUB";
781 balItemString =
"EM_FOROP";
788 out << balItemString <<
d;
789 out << currentYear <<
d;
790 out << outvalue <<
d;
804 switch (delimiterID) {
821 msgOut(
MSG_ERROR,
"You have specified an unknow output file field delimiter. Using \";\".");
834 struct tm *current = localtime(&now);
835 string timemessage =
i2s(current->tm_hour)+
":"+
i2s(current->tm_min)+
":"+
i2s(current->tm_sec);
837 out <<
d << nIterations <<
d << obj <<
"\n";
854 for (uint r2=0;r2<regIds2.size();r2++){
855 for(uint ft=0;ft<
fTypes.size();ft++){
856 for(uint dc=0;dc<(
dClasses.size()-1);dc++){
857 for(uint pp=0;pp<
priPr.size();pp++){
860 double outputValue =
expReturnsDebug.at(r2).at(ft).at(dc).at(pp).at(dv);
862 out << currentYear <<
d;
868 out << outputValue <<
d;
891 for (uint r=0;r<regIds2.size();r++){
892 int rId = regIds2[r];
896 for (uint p=0;p<regPx.size();p++){
897 Pixel* px = regPx[p];
898 int pxID = px->
getID();
899 int pxX = px->
getX();
900 int pxY = px->
getY();
930 if (std::find(outVars.begin(), outVars.end(),
"vol") != outVars.end()){
931 out << common <<
"vol" <<
d;
932 for(uint f=0;f<
fTypes.size();f++){
933 for(uint u=0;u<
dClasses.size()-1;u++){
934 out << px->
vol[f][u]<<
d;
941 if (std::find(outVars.begin(), outVars.end(),
"area") != outVars.end()){
942 out << common <<
"area" <<
d;
943 for(uint f=0;f<
fTypes.size();f++){
944 for(uint u=0;u<
dClasses.size()-1;u++){
945 out << px->
area[f][u]<<
d;
952 if (std::find(outVars.begin(), outVars.end(),
"hArea") != outVars.end()){
953 out << common <<
"hArea" <<
d;
954 for(uint f=0;f<
fTypes.size();f++){
955 for(uint u=0;u<
dClasses.size()-1;u++){
956 out << px->
hArea[f][u]<<
d;
963 if (std::find(outVars.begin(), outVars.end(),
"hVol") != outVars.end()){
964 out << common <<
"hVol" <<
d;
965 for(uint f=0;f<
fTypes.size();f++){
966 for(uint u=0;u<
dClasses.size()-1;u++){
967 out << px->
hVol[f][u]<<
d;
974 if (std::find(outVars.begin(), outVars.end(),
"tp") != outVars.end()){
975 out << common <<
"tp" <<
d;
976 for(uint f=0;f<
fTypes.size();f++){
977 for(uint u=0;u<
dClasses.size()-1;u++){
978 out << px->
tp[f][u]<<
d;
985 if (std::find(outVars.begin(), outVars.end(),
"mort") != outVars.end()){
986 out << common <<
"mort" <<
d;
987 for(uint f=0;f<
fTypes.size();f++){
988 for(uint u=0;u<
dClasses.size()-1;u++){
989 out << px->
mort[f][u]<<
d;
996 if (std::find(outVars.begin(), outVars.end(),
"tp_multiplier") != outVars.end()){
997 out << common <<
"tp_multiplier" <<
d;
998 for(uint f=0;f<
fTypes.size();f++){
999 for(uint u=0;u<
dClasses.size()-1;u++){
1007 if (std::find(outVars.begin(), outVars.end(),
"mortCoef_multiplier") != outVars.end()){
1008 out << common <<
"mortCoef_multiplier" <<
d;
1009 for(uint f=0;f<
fTypes.size();f++){
1010 for(uint u=0;u<
dClasses.size()-1;u++){
1018 if (std::find(outVars.begin(), outVars.end(),
"vMort") != outVars.end()){
1019 out << common <<
"vMort" <<
d;
1020 for(uint f=0;f<
fTypes.size();f++){
1021 for(uint u=0;u<
dClasses.size()-1;u++){
1022 out << px->
vMort[f][u]<<
d;
1029 if (std::find(outVars.begin(), outVars.end(),
"vMortAdd") != outVars.end()){
1030 out << common <<
"vMortAdd" <<
d;
1031 for(uint f=0;f<
fTypes.size();f++){
1032 for(uint u=0;u<
dClasses.size()-1;u++){
1040 if (std::find(outVars.begin(), outVars.end(),
"optDc") != outVars.end()){
1041 out << common <<
"optDc" <<
d;
1042 for(uint f=0;f<
fTypes.size();f++){
1043 for(uint u=0;u<
dClasses.size()-1;u++){
1046 out << px->
optDc[f] <<
d;
1051 if (std::find(outVars.begin(), outVars.end(),
"expectedAnnualIncome_timber") != outVars.end()){
1052 out << common <<
"expectedAnnualIncome_timber" <<
d;
1053 for(uint f=0;f<
fTypes.size();f++){
1054 for(uint u=0;u<
dClasses.size()-1;u++){
1062 if (std::find(outVars.begin(), outVars.end(),
"expectedAnnualIncome_carbon") != outVars.end()){
1063 out << common <<
"expectedAnnualIncome_carbon" <<
d;
1064 for(uint f=0;f<
fTypes.size();f++){
1065 for(uint u=0;u<
dClasses.size()-1;u++){
1073 if (std::find(outVars.begin(), outVars.end(),
"expectedReturnsNotCorrByRa") != outVars.end()){
1074 out << common <<
"expectedReturnsNotCorrByRa" <<
d;
1075 for(uint f=0;f<
fTypes.size();f++){
1076 for(uint u=0;u<
dClasses.size()-1;u++){
1084 if (std::find(outVars.begin(), outVars.end(),
"expectedReturns") != outVars.end()){
1085 out << common <<
"expectedReturns" <<
d;
1086 for(uint f=0;f<
fTypes.size();f++){
1087 for(uint u=0;u<
dClasses.size()-1;u++){
1095 if (std::find(outVars.begin(), outVars.end(),
"optFtChosen") != outVars.end()){
1096 out << common <<
"optFtChosen" <<
d;
1097 for(uint f=0;f<
fTypes.size();f++){
1098 for(uint u=0;u<
dClasses.size()-1;u++){
1106 if (std::find(outVars.begin(), outVars.end(),
"optDcChosen") != outVars.end()){
1107 out << common <<
"optDcChosen" <<
d;
1108 for(uint f=0;f<
fTypes.size();f++){
1109 for(uint u=0;u<
dClasses.size()-1;u++){
1117 if (std::find(outVars.begin(), outVars.end(),
"deltaAreas") != outVars.end()){
1118 out << common <<
"deltaAreas" <<
d;
1119 for(uint f=0;f<
fTypes.size();f++){
1120 for(uint u=0;u<
dClasses.size()-1;u++){
1125 for(uint f=0;f<
fTypes.size()+1;f++){
1126 for(uint f2=0;f2<
fTypes.size()+1;f2++){
1151 vector <string> rows;
1153 ifstream inFile (fileName.c_str(), ios::in);
1155 msgOut(
MSG_ERROR,
"Error in opening the file "+fileName+
" for reading.");
1158 while( getline (inFile,tempRow) ){
1159 vector<string> tokens;
1161 if(tokens[0] != scenarioName)
1162 rows.push_back( tempRow );
1165 ofstream out(fileName.c_str(), ios::out);
1166 for(uint i=0;i<rows.size();i++){
1180 for (uint r1=0;r1<
l2r.size();r1++){
1183 for (uint r2=0;r2<
l2r[r1].size();r2++){
1184 string reg2Id =
i2s(
l2r[r1][r2]);
1186 for(uint j=0;j<
fTypes.size();j++){
1188 for(uint u=0;u<
dClasses.size();u++){
1190 if(dc ==
"")
continue;
1191 for(uint p=0;p<
priPr.size();p++){
1192 string prd =
priPr[p];
1193 tr1::array<string, 4> hVKey = {reg2Id, ft, dc, prd};
1194 double value =
findMap(hVol_byPrd,hVKey);
1196 outHV <<
"hVbyPrd" <<
d;
1197 outHV << reg1Name <<
d;
1198 outHV << reg2Name <<
d;
1202 outHV << currentYear <<
d;
1203 outHV << value <<
d;
vector< vector< double > > deltaArea
Print an ERROR message, but don't stop the model.
The required data is for the current year.
void initOutputProductData()
int getIntSetting(const string &name_h, int position=0, int reg=WORLD) const
vector< vector< double > > area
void initOutputForestData()
vector< string > getForTypeParents()
vector< string > dClasses
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
Do not actually output any message.
void printCarbonBalance()
string i2s(const int &int_h) const
integer to string conversion
Output(ThreadManager *MTHREAD_h)
Constructor.
ThreadManager * MTHREAD
Pointer to the Thread manager.
void printDebugPixelValues()
ModelData * MD
the model data object
string getBaseDirectory() const
void tokenize(const string &str, vector< string > &tokens, const string &delimiter=" ") const
Tokenize a string using a delimiter (default is space)
double getCumSavedEmissions(const int ®Id, const int &em_type) const
Returns the current cumulative saved emissions by type [Mt CO2].
Output verbosity level print everything.
pair< string, vector< double > > DataPair
vector< string > expReturnsDebugVariables
double getStock(const int ®Id, const int &stock_type) const
Returns the current stock of carbon [Mt CO2].
vector< string > pDClasses
includes an empty string for variables without diameter attribute
Output verbosity level print (also) the maps in ascii grid format.
void initDebugPixelValues()
vector< vector< double > > mort
void printOptLog(bool optimal, int &nIterations, double &obj)
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
vector< vector< double > > vMort
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
string debugPxValuesFilename
vector< double > expectedAnnualIncome_carbon
Gis * GIS
GIS information and methods.
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
vector< string > getStringVectorSetting(const string &name_h, int reg=WORLD) const
void initOptimisationLog()
void printProductData(bool finalFlush)
Output verbosity level print aggregated output (e.g. optimisation log)
string getStringSetting(const string &name_h, int position=0, int reg=WORLD) const
const double getProdData(const string &type_h, const int ®Id_h, const string &prodId_h, const int &year=DATA_NOW, const string &freeDim_h="")
Output verbosity level print (also) detailed output.
map< string, vector< double > > DataMap
Print an error message and stop the model.
vector< vector< int > > l2r
Output verbosity level print (also) binary (png) maps.
vector< vector< double > > vMortAdd
vector< int > optDcChosen
Flow from forest operations.
void printBinMaps(string layerName_h="")
Save an image in standard png format.
vector< double > expectedAnnualIncome_timber
const double getForData(const string &type_h, const int ®Id_h, const string &forType_h, const string &freeDim_h, const int &year=DATA_NOW)
int vSum(const vector< int > &vector_h) const
void cleanScenario(string fileName, string scenarioName, char d)
Invetoried biomass (live and death tree logs)
Extra biomass (soils, branches..)
vector< vector< double > > vol
double getMultiplier(const string &multiplierName, const string &forName, int year=DATA_NOW)
char getOutputFieldDelimiter()
Carbon * CBAL
Module for the Carbon Balance.
vector< string > getForTypeIds(bool all=false)
By default it doesn't return forTypes used only as input.
void printLayers(string layerName_h="")
Print the specified layer or all layers (if param layerName_h is missing).
vector< int > optFtChosen
vector< double > expectedReturns
vector< string > outProdVariables
V findMap(const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V ¬FoundValue=numeric_limits< V >::min()) const
Lookup a map for a value. Return the value starting from the key.
vector< vector< double > > tp
void printDetailedHV(map< tr1::array< string, 4 >, double > hVol_byPrd)
vector< double > expectedReturnsNotCorrByRa
by ft. Attenction, reported expReturns at "forest" level (compared with those at forest type level) d...
vector< vector< double > > hVol
vector< int > getIntVectorSetting(const string &name_h, int reg=WORLD) const
void setErrorLevel(int errorLevel_h)
vector< int > getRegionIds(int level_h, bool excludeResidual=true)
void print(bool earlyPrint=true)
Print output. If earlyPrinting it doesn't print some stuff for which we don't yet have values...
bool forestDiamDetailedOutput
vector< vector< double > > hArea
vector< ModelRegion * > getChildren(bool excludeResidual=true)
Returns a pointer to the parent regions.
string getOutputDirectory() const
Return a vector of objects that together provide the specified resource in the specified quantity...
vector< vector< vector< vector< vector< double > > > > > expReturnsDebug
l2_region, for type, d.c., pr prod, variable name
vector< Pixel * > getMyPixels()
ModelRegion * getRegion(int regId_h)
Biomass in forest products (sawns, pannels..)
#define DIAM_ALL
All diameter classes.
void printForestData(bool finalFlush)
string regId2RegSName(const int ®Id_h) const
vector< string > outForVariables