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++){
441 cout <<
"printing " << cYear << endl;
492 vector<string>fTypes_temp =
fTypes;
494 fTypes_temp.push_back(
"");
496 fTypes_temp.insert(fTypes_temp.end(),ftParents.begin(),ftParents.end());
498 for (uint r1=0;r1<
l2r.size();r1++){
499 for (uint r2=0;r2<
l2r[r1].size();r2++){
500 for(uint ft=0;ft<fTypes_temp.size();ft++){
502 for(uint dc=0;dc<
dClasses.size();dc++){
507 out << fTypes_temp[ft] <<
d;
510 for(
int y=0;y<
nYears;y++){
512 out << outvalue <<
d;
517 out << currentYear <<
d;
518 out << outvalue <<
d;
527 out << fTypes_temp[ft] <<
d;
530 for(
int y=0;y<
nYears;y++){
532 out << outvalue <<
d;
537 out << currentYear <<
d;
538 out << outvalue <<
d;
621 for (uint r1=0;r1<
l2r.size();r1++){
622 for (uint r2=0;r2<
l2r[r1].size();r2++){
623 for(uint p=0;p<
allPr.size();p++){
626 for(uint r2b=0;r2b<
l2r[r1].size();r2b++){
632 out <<
l2r[r1][r2b] <<
d;
634 for(
int y=0;y<
nYears;y++){
636 out << outvalue <<
d;
645 out << currentYear <<
d;
646 out << outvalue <<
d;
658 for(
int y=0;y<
nYears;y++){
660 out << outvalue <<
d;
665 out << currentYear <<
d;
666 out << outvalue <<
d;
733 if (currentYear ==
inYear) {
return;}
748 for (uint r1=0;r1<
l2r.size();r1++){
749 for (uint r2=0;r2<
l2r[r1].size();r2++){
750 int regId =
l2r[r1][r2];
751 for (uint b=0;b<balItems.size();b++){
755 string balItemString;
758 balItemString =
"STOCK_INV";
763 balItemString =
"STOCK_EXTRA";
768 balItemString =
"STOCK_PRODUCTS";
773 balItemString =
"EM_ENSUB";
778 balItemString =
"EM_MATSUB";
783 balItemString =
"EM_FOROP";
790 out << balItemString <<
d;
791 out << currentYear <<
d;
792 out << outvalue <<
d;
806 switch (delimiterID) {
823 msgOut(
MSG_ERROR,
"You have specified an unknow output file field delimiter. Using \";\".");
836 struct tm *current = localtime(&now);
837 string timemessage =
i2s(current->tm_hour)+
":"+
i2s(current->tm_min)+
":"+
i2s(current->tm_sec);
839 out <<
d << nIterations <<
d << obj <<
"\n";
856 for (uint r2=0;r2<regIds2.size();r2++){
857 for(uint ft=0;ft<
fTypes.size();ft++){
858 for(uint dc=0;dc<(
dClasses.size()-1);dc++){
859 for(uint pp=0;pp<
priPr.size();pp++){
862 double outputValue =
expReturnsDebug.at(r2).at(ft).at(dc).at(pp).at(dv);
864 out << currentYear <<
d;
870 out << outputValue <<
d;
893 for (uint r=0;r<regIds2.size();r++){
894 int rId = regIds2[r];
898 for (uint p=0;p<regPx.size();p++){
899 Pixel* px = regPx[p];
900 int pxID = px->
getID();
901 int pxX = px->
getX();
902 int pxY = px->
getY();
929 out << common <<
"vol" <<
d;
930 for(uint f=0;f<
fTypes.size();f++){
931 for(uint u=0;u<
dClasses.size()-1;u++){
932 out << px->
vol[f][u]<<
d;
938 out << common <<
"area" <<
d;
939 for(uint f=0;f<
fTypes.size();f++){
940 for(uint u=0;u<
dClasses.size()-1;u++){
941 out << px->
area[f][u]<<
d;
965 out << common <<
"hArea" <<
d;
966 for(uint f=0;f<
fTypes.size();f++){
967 for(uint u=0;u<
dClasses.size()-1;u++){
968 out << px->
hArea[f][u]<<
d;
973 out << common <<
"hVol" <<
d;
974 for(uint f=0;f<
fTypes.size();f++){
975 for(uint u=0;u<
dClasses.size()-1;u++){
976 out << px->
hVol[f][u]<<
d;
982 out << common <<
"tp" <<
d;
983 for(uint f=0;f<
fTypes.size();f++){
984 for(uint u=0;u<
dClasses.size()-1;u++){
985 out << px->
tp[f][u]<<
d;
990 out << common <<
"mort" <<
d;
991 for(uint f=0;f<
fTypes.size();f++){
992 for(uint u=0;u<
dClasses.size()-1;u++){
993 out << px->
mort[f][u]<<
d;
999 out << common <<
"tp_multiplier" <<
d;
1000 for(uint f=0;f<
fTypes.size();f++){
1001 for(uint u=0;u<
dClasses.size()-1;u++){
1007 out << common <<
"mortCoef_multiplier" <<
d;
1008 for(uint f=0;f<
fTypes.size();f++){
1009 for(uint u=0;u<
dClasses.size()-1;u++){
1017 out << common <<
"vMort" <<
d;
1018 for(uint f=0;f<
fTypes.size();f++){
1019 for(uint u=0;u<
dClasses.size()-1;u++){
1020 out << px->
vMort[f][u]<<
d;
1026 out << common <<
"optDc" <<
d;
1027 for(uint f=0;f<
fTypes.size();f++){
1028 for(uint u=0;u<
dClasses.size()-1;u++){
1031 out << px->
optDc[f] <<
d;
1035 out << common <<
"expectedAnnualIncome_timber" <<
d;
1036 for(uint f=0;f<
fTypes.size();f++){
1037 for(uint u=0;u<
dClasses.size()-1;u++){
1044 out << common <<
"expectedAnnualIncome_carbon" <<
d;
1045 for(uint f=0;f<
fTypes.size();f++){
1046 for(uint u=0;u<
dClasses.size()-1;u++){
1054 out << common <<
"expectedReturnsNotCorrByRa" <<
d;
1055 for(uint f=0;f<
fTypes.size();f++){
1056 for(uint u=0;u<
dClasses.size()-1;u++){
1063 out << common <<
"expectedReturns" <<
d;
1064 for(uint f=0;f<
fTypes.size();f++){
1065 for(uint u=0;u<
dClasses.size()-1;u++){
1073 out << common <<
"optFtChosen" <<
d;
1074 for(uint f=0;f<
fTypes.size();f++){
1075 for(uint u=0;u<
dClasses.size()-1;u++){
1082 out << common <<
"optDcChosen" <<
d;
1083 for(uint f=0;f<
fTypes.size();f++){
1084 for(uint u=0;u<
dClasses.size()-1;u++){
1092 out << common <<
"deltaAreas" <<
d;
1093 for(uint f=0;f<
fTypes.size();f++){
1094 for(uint u=0;u<
dClasses.size()-1;u++){
1099 for(uint f=0;f<
fTypes.size()+1;f++){
1100 for(uint f2=0;f2<
fTypes.size()+1;f2++){
1125 vector <string> rows;
1127 ifstream inFile (fileName.c_str(), ios::in);
1129 msgOut(
MSG_ERROR,
"Error in opening the file "+fileName+
" for reading.");
1132 while( getline (inFile,tempRow) ){
1133 vector<string> tokens;
1135 if(tokens[0] != scenarioName)
1136 rows.push_back( tempRow );
1139 ofstream out(fileName.c_str(), ios::out);
1140 for(uint i=0;i<rows.size();i++){
1154 for (uint r1=0;r1<
l2r.size();r1++){
1157 for (uint r2=0;r2<
l2r[r1].size();r2++){
1158 string reg2Id =
i2s(
l2r[r1][r2]);
1160 for(uint j=0;j<
fTypes.size();j++){
1162 for(uint u=0;u<
dClasses.size();u++){
1164 if(dc ==
"")
continue;
1165 for(uint p=0;p<
priPr.size();p++){
1166 string prd =
priPr[p];
1167 tr1::array<string, 4> hVKey = {reg2Id, ft, dc, prd};
1168 double value =
findMap(hVol_byPrd,hVKey);
1170 outHV <<
"hVbyPrd" <<
d;
1171 outHV << reg1Name <<
d;
1172 outHV << reg2Name <<
d;
1176 outHV << currentYear <<
d;
1177 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< 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