Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

BasicData.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //
00003 //  Thomas Berger (main author), Pepijn Schreinemachers, and Thorsten Arnold
00004 //
00005 //
00006 //  Hohenheim University (490d)
00007 //  Professorship for Land Use Economics in the Tropics and Subtropics
00008 //
00009 //  May not be distributed without permission by main author
00010 //
00011 //  File:       BasicData.h (formerly allgem9.h)
00012 //
00013 //  Contents:   Basic model data, such as model configuration switches
00014 //
00015 //
00016 //
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef _BasicData_h
00020 #define _BasicData_h
00021 
00022 
00023 // The following (low-level) header should be included always
00024 // Contains enums
00025 
00026 // LINUX / WINDOWS specific definitions
00027 #ifdef AIX
00028    #include <unistd.h>
00029 #else
00030         #include <dos.h>
00031 #endif /* AIX */
00032 
00033 #include "BasicStrings.h"
00034 
00035 #ifdef AIX
00036    long getTimeDiffInSecAIX(time_t t2, time_t t1);
00037 #else
00038    
00039 #ifndef _MSC_VER
00040         void zeitdifferenz(struct time* t2, struct time* t1); //Tbe Feb23
00041    double getTimeDiffInSecWIN(struct time* t2, struct time* t1);//Tbe Feb23
00042 #endif
00043 
00044 #endif
00045 
00046 
00047 // This function needs to be declared in MAIN
00048 void exitfun();
00049 
00050 
00051 //General parameters, formerly defines
00052 //Maximum number of catchments (formerly subcatchments)
00053 int NUM_CATCHMENTS();     
00054 void    setNUM_CATCHMENTS(int numC);
00055 
00056 
00057 //Maximum number of catchment sectors
00058 int NUM_SECTORS();     
00059 void    setNUM_SECTORS(int numS);
00060 
00061 //Maximum number of river inflows
00062 int NUMINFLOWS(void);
00063 void setNUMINFLOWS(int numInflows);
00064 
00065 int MONATE();           //Maximum number of irrigation months
00066 int NW_ANZAHL();        //Maximum number of innovation networks
00067 int SEG_ANZAHL();       //Maximum number of segments per network
00068 int POP_ANZAHL();       //Maximum number of agent populations
00069 int CLU_ANZAHL();       //Maximum number of clusters per population
00070 int MAXLOOP();          //Maximum number of loops before lottery is stopped
00071 double SHARE_DEMAND_MET();      //Minimum share of water demand to be met in lottery
00072 
00073 void setSHARE_DEMAND_MET(double share);
00074 
00075 //Arnold2006_14
00076 void NODATAVAL_def(int);  // Defines Not A Value within program
00077 int NODATAVAL();        // Return NaValue
00078 
00079 void set_MONATE(int maxM);
00080 
00081 //flag for water rights assignment
00082 void setWATER_RIGHTS(int flag);
00083 int WATER_RIGHTS();
00084 
00085 
00086 //Parameters for innovation decision
00087 int MAXINVEST();        //Tentative number of investments per farm
00088 int HOECHSTALTER();     //Maximum age of assets in period 0
00089 int MINDESTALTER();     //Minimum age of assets in period 0
00090 int KOMM();             //Type of communication process (Default = 0)
00091 int KUMM();             //Cumulative adoption  ("classical" diffusion curve)
00092 double LAMBDA();        //Parameter for expectations (Brandes et al., 1997: 382)
00093 double MARGE();         //Safe rounding factor for indivisible assets (Default = 1.0)
00094 double MINUMFANG();     //Minimum investment in permanent crops [ha]
00095 double OVERLAP();       //Overlap of network thresholds (Default = 1.0)
00096 double RESERVE();       //Liquidity reserve factor (Default = 0.0)
00097 int SYM_ANZAHL();       //Number of "symbolic" investment objects
00098 double WAEHRUNG();      //Currency units
00099 
00100 //Parameters for rental markets
00101 double MINPACHT();      //Minimum bid (relative to average shadow prices)
00102 double PACHTABSCHLAG(); //Activity factor for renting-out decisions (< 1.0)
00103 double PACHTZUSCHLAG(); //Activity factor for renting-in decisions  (> 1.0)
00104 
00105 //Policy parameters
00106 int BONUSALTER();       //Maximum age of subsidized permanent crops (Default = 0)
00107 int BONUSDAUER();       //Duration of policy measure (Default = 0)
00108 int IRRIGATIONPROJECTS();//initial number of irrigation infrastructure projects
00109 
00110 //Switches for various modules (= components)
00111 int CONS_MDL();         //Type of consumption module
00112 int CROPG_MDL();        //Type of crop growth module
00113 void setCROPG_MDL(int _crop_mdl);
00114 //    0: EDIC
00115 //    1: TSPC
00116 //    2: Coupling with WASIM
00117 int HYDRO_MDL();        //Type of hydrology module
00118 void setHYDRO_MDL(int _hydro_mdl);
00119 //    0: EDIC
00120 //    1: No hydrology
00121 //    2: Coupling with WASIM
00122 int LIVST_MDL();        //Livestock module
00123 int PERMC_MDL();        //Permanent crops module
00124 int LANDM_MDL();        //Land markets module
00125 int INPUT_GIS();        //Type of GIS input
00126 
00127 
00128 int SPECL_MDL();        //Country-specific module
00129 
00130 //Soil types and soil classes
00131 double PLOTSIZE();      //Size of 1 gridcell (=parcel) [ha]
00132 void    setPLOTSIZE(double _plotsize);
00133 
00134 double  CELLLENGTH();  // Converts PLOTTSIZE to length of one cell
00135 double DIST_COSTS();    //Unit transport costs [ZT$]
00136 int TYPEN();            //Number of soil types
00137 int KLASSEN();          //Number of soil classes
00138 
00140 int DBG_INFOS();        //debug information (yes/no)
00141 int DYNAMICS_OFF_ALL();                         //switches off all dynamics (aging, liquidity, soil porcesses)
00142 int DYNAMICS_OFF_HOUSEHOLDS();  //switches off aging of household members
00143 int DYNAMICS_OFF_LIVESTOCK();           //switches off aging of livestock
00144 int DYNAMICS_OFF_ASSETS();                      //switches off aging of assets
00145 int DYNAMICS_OFF_SOIL_PROCESSES();//switches off updating of soil processes
00146 
00147 int get_NUMBER_SPIN_UP_ROUNDS();
00148 void set_NUMBER_SPIN_UP_ROUNDS(int numSpinUpRounds);
00149 
00150 //Special debug info for Milp
00151 double MIN_OBJV();      //minimum objective value
00152 int SAVE_MILP(int IdOfMilp);//returns 'true' if MILP has to be saved
00153 int SAVE_AGENT(int farmsteadID);//returns 'true' if agent data have to be saved
00154 
00155 //Fine-tuning of OSL Solver
00156 int OSL_TUNE();         //fine tuning (yes/no)
00157 double MAX_TIME();      //maximum time allowed for solving
00158 void SET_MAX_TIME(double max_time_);//set maximum time
00159 int MAX_ITER();         //maximum iterations
00160 int MAX_NODE();         //maximum nodes
00161 
00162 
00164 // GENERAL FUNCTIONS
00165 // ===========================================================
00166 
00167 
00168 
00169 //Arnold2006_93
00170 //EDIC_RELEVANT
00171 int   totMonth2actMonth(int mTot);
00172 
00173 
00174 
00175 
00176 
00177 
00178 typedef struct
00179 {
00180    char* sectorName;
00181    int lenDoubles;
00182    int lenInts;
00183    double* doubleVals;
00184    int* integerVals;
00185 } EDICtable;
00186 
00187 //Arnold2006
00188 /*
00189 int numSectorsTot();
00190 void countUpSectorsOne();
00191 */
00192 
00193 
00194 
00195 
00196 // SWITCH:
00197 // read input flows from separate file at monthly timesteps,
00198 // or from Catchment Fuile (EDIC version) ?
00199 void setDYNAMICINFLOWS(bool);
00200 int DYNAMICINFLOWS();
00201 
00202 bool SPATIAL_ON();
00203 void set_SPATIAL_ON(bool b);
00204 
00205 bool DOPOSTPROCESSING();
00206 void set_DOPOSTPROCESSING(bool);
00207 
00208 int WASIM_DELTAMONTH(); // Shifts month from MAS (0: Okt) to WASIM (10: Okt)numeration
00209 
00210 
00211 
00212 
00213 // Read WASIM filenames
00214 void ReadWasimFilenames();
00215 void PrintWasimFilenames();
00216 
00217 
00218 //reads/writes basic constants them from/in a file and returns their values
00219 void readBasicData();
00220 void writeBasicData(char* filename);
00221 
00222 void readAllDefaults(string fn);
00223 
00224 
00226 // --> TESTFUN functions
00227 // =====================================================================
00228 
00229 //-------------------------------------
00230 
00231 // This function returns TRUE if a certain output should be made.
00232 // Internally, it uses a vector (of class MatrixDouble) which contains only zeros and ones (false / true)
00233 // USE:
00234 // 1) The vector is first initialized at the beginning of the program, by definint the dimension with
00235 //        TestFunInit(int max);
00236 //       By default, all entries are FALSE
00237 
00238 // 2) Then, any test output level can be chosen and set to TRUE with
00239 //          TestFun_setTrue(int testNr);
00240 //
00241 // 3) The optional function <getReturnIf99();> checks if TestFun(99) == true,
00242 //    interrupts the program execution and promps for an input by the user
00243 //    By convention, it is only used WITHIN other error outputs so the program runs through if only 99 is set TRUE!
00244 //
00245 // 4) Error outputs are optional now:
00246 //      int val = 4;
00247 //      if (TestFun(val))
00248 //      {       cout << " blablabla" << endl;
00249 //                 getReturnIf99();
00250 //          exit(1);
00251 //      }
00252 //
00253 bool TestFun(int testNr);
00254 // This function is identical to above, but does not give warnings, for use in destructors (After TestFun was destructed, while closing the program)
00255 bool TestFunDestr(int testNr);
00256 
00257 void TestFunInit(int max);
00258 int TestFun_getMax();
00259 void TestFun_setFalse(int testNr);
00260 void TestFun_setTrue(int testNr);
00261 void TestFun_printAllActive();
00262 
00263 // Function for spatial export. Clone of TestFun!
00264 bool SpatialExport(int v_);
00265 void SpatialExportDealloc();
00266 
00267 void SpatialExportInit();
00268 int SpatialExport_getMax();
00269 void SpatialExport_setFalse(int v_);
00270 void SpatialExport_setTrue(int v_);
00271 void SpatialExport_printAllActive();
00272 
00273 // Request return (iun Test-Files)
00274 void getReturnIf99();
00275 void getReturnIf99(int);
00276 
00277 // Content 
00278 string getCONTSTR(Content contIn);
00279 void printContString(Content cont);
00280 string returnContString(Content cont);
00281 
00282 // ONLY RENAMED FROM ABOVE
00283 string cont2string(Content cont);
00284 string exptp2string(ExportType tp);
00285 
00287 // Filter Function 
00288 bool FilterFun(int filterNr);
00289 void FilterFunInit(int max);
00290 void FilterFunDealloc();
00291 int FilterFun_getMax();
00292 void FilterFun_setFalse(int filterNr);
00293 void FilterFun_setTrue(int filterNr);
00294 void FilterFun_printAllActive();
00295 
00297 // --> STRING, FILE  AND DIRECTORY TREATMENT
00298 // =====================================================================
00299 char* const2char(const char* exp);
00300 void const2char(const char* exp, char* out);
00301 
00302 
00303 string getOnlyNums(string& fn);
00304 string getOneToken(string& fn, string& rest);
00305 string getOneToken(string& fn);
00306 
00307 
00308 //Arnold2006_91
00309 void makeCharFrom3Int(char* irrigIDstr, int crA, int irrTech, int clusterNum);
00310 
00311 
00312 
00314 // --> SOME SMALL MISC FUNCTIONS
00315 // =====================================================================
00316 
00317 
00318 
00320 // --> ExportType functions (ExportViaTDT, ExportTable)
00321 // =====================================================================
00322 
00323 // The function <ExportViaTDT> is analogous to TestFun, but applies to an enum type ExportType.
00324 // It is used to govern the import and exort of files via TDT in both the controller and the MPMAS
00325 // INITIALIZE IN MAIN:
00326 //      int maxExports = 7;
00327 //      ExportViaTDT_Init(maxExports);
00328 //           ExportViaTDT_readFromFile("./iniFiles/dataexchange.ini")
00329 //
00330 //      // IN PROGRAM:
00331 //      if (ExportViaTDT(expSoilMoist))
00332 //      {
00333 //              Raster2D soilMoist;
00334 //              soilMoist.receiveViaTDT(configName);
00335 //              // [oder irgendein anderes Handling]
00336 //      }
00337 bool ExportViaTDT(ExportType tp);
00338 void ExportViaTDT_readFromFile(string fn);
00339 
00340 int ExportViaTDT_getMax();
00341 void ExportViaTDT_setFalse(ExportType testNr);
00342 void ExportViaTDT_setTrue(ExportType testNr);
00343 void ExportViaTDT_printToScreen();
00344 // The array "tableFlags" is used to decide which WASIM files are loaded and
00345 // exported  into table format  
00346 bool ExportTable(ExportType tp);
00347 void ExportTable_printToScreen();
00348 
00349 int ExportTable_getMax();
00350 void ExportTable_setFalse(ExportType testNr);
00351 void ExportTable_setTrue(ExportType testNr);
00352 void ExportTable_printToScreen();
00353 
00354 // First value which contains only WaSiM additional data
00355 // --> Hard-wired, now: 5
00356 int ExportType_firstAdditional();
00357 
00359 // Factor used to convert irrigation quanitities into quantities used by
00360 // ======================================================================
00362 // TREAT OF IRRIGATION AND INFLOWS (globally)
00364 void setIRRIGMETHOD(int in);
00365 int IRRIGMETHOD();
00366 
00367 void setIRRIGMETHOD(int in);
00368 int IRRIGMETHOD();
00369 
00370 string FILENAME_InflowKey();
00371 void setFILENAME_InflowKey(string s);
00372 
00373 
00374 
00375 // PASSED AS ARGUMENT TO MPMAS (-R## with TYPE)
00376 // Currently, there are two "conversion types":
00377 //    - Type 1: The conversion from MPMAS input (Activity-Key / LP-block on hydrology   --> Irrigation Table )
00378 //    - Type 2: Conversion (WASIM abstractions / files as read from Disk  --> Sector inflows
00379 //
00380 // -->
00381 //ARNOLD_IRRIGATIONFACTOR
00382 enum enumIrrigationFactorType {
00383    typeIrrig_cropWat2WasimIrrigationTable, 
00384    typeIrrig_externalInflow2LiterPerSecond, 
00385    typeIrrig_cropWatGross2LiterPerSecond, 
00386    typeIrrig_cropWatExpected2LiterPerSecond,
00387    typeIrrig_activityKey2LiterPerSecond,
00388    typeIrrig_activityKey2mmPerDay,
00389    typeIrrig_CropKey2mmPerDay, // not used
00390    typeIrrig_MAX, 
00391    typeIrrig_ErrorOutput     
00392 } ;
00393 
00394 // output
00395 void irrigationFactors_printOptions();
00396 void irrigationFactors_printCurrentSetting();
00397 
00398 // input
00399 void setIrrigationDefaults();
00400 int readIrrigationFactors(string fn);
00401 void setIRRIGFACTOR(int unitType, enumIrrigationFactorType conversionType);
00402 
00403 // access
00404 double IRRIGFACTOR(enumIrrigationFactorType conversionType);
00405 int getIrrigationUnitType(enumIrrigationFactorType conversionType);
00406 int getIrrigUnitForWasimUnit(int conversionID); //int getIRRIGfactorValue(int unitType);
00407 double getFactorFromUnitType(int conversionID);
00408 
00409 // string
00410 string irrigationUnitToString(int conversionID); // irrigationFactorUnitAsStringFromType
00411 string getIrrigationFactorDescription(enumIrrigationFactorType);
00412 
00413 // <--
00414 
00415 
00416 
00417 
00419 // --> MEMORY ALLOCATION FUNCTIONS
00420 // =====================================================================
00421 
00422 // Quit program after deallocating
00423 void deallocateUtilities();
00424 
00425 //Misc.
00426 void TestFunDealloc();
00427 
00428 
00429 
00430 
00431 // ###############################
00432 // ## allgHigher.h HIGHER
00433 // ###############################
00434 
00435 
00436 
00437 // Only destruction, to avoid inclusion within deallocateUtilities()
00438 
00439 void ExportTable_readFromFile(string fn);
00440 
00441 void setINFLOWINFO(int pos, int val, string name);
00442 
00443 
00444 // Read from ABSTRFILE_fn();
00445 int readInflowKey(string fn);
00446 
00448 // Access to content of INFLOW KEY
00450 // To a value of the inflow (as defined in InputKey.txt), the name
00451 // is returned
00452 string INFLOW_val2name(int val);
00453 
00454 // To the index of the inflow (order of InputKey.txt), the name
00455 // is returned
00456 string INFLOW_pos2name(int pos);
00457 
00458 // To the index of the inflow (order of InputKey.txt), value returned
00459 int INFLOW_pos2val(int pos);
00460 
00461 // To the value of an inflow (as defined in InputKey.txt or in
00462 // MEDIAN_FLOW passed by data manager), the position in RegionFile
00463 // (InputKey.txt or Region.dat) is returned
00464 // If not found: _NODATADEF_
00465 int INFLOW_val2pos(int pos);
00466 
00467 void printINFLOWS(void);
00468 // <--
00469 
00470 // Translate soil type into soil suitabiltiy class 
00471 bool checkClassCorrespondsWithType(int cl, int tp);
00472 
00473 
00474 int soilClassOrder(int priority);
00475 void set_soilClassOrder();
00476 
00477 void readSoilclass(FILE* bdata);
00478 void   writeSoilClass(FILE* bdata);
00479 
00480 
00481 // Functions --> Header
00482 string getFullMpmasFilename(
00483       EnumFileType fileTypeEnum_,
00484       Content cont,
00485       int CatchmentID, int year, int month);
00486 string getTestFilename(string s, int CatchmentID);
00487 
00488 int SEED();
00489 void setSEED(int seed_);
00490 
00491 // CFor controlling numbr of model runs  with flag Y
00492 void setSTOPYEAR(int stopyear_);
00493 int STOPYEAR();
00494 
00495 void setIDUM(long idum_);
00496 long IDUM();
00497 
00498 int MAXPERIODIN();
00499 void setMAXPERIODIN(int maxPeriodIn_);
00500 
00501 string getTDTConfigFilename(TypeDataExchangeChannel,  TypeDataExchangeType);
00502 string filenameConfigFile(TypeRoleInCoupling roleInCoupling);
00503 
00504 void printAllIrrigationMethods();
00505 string getStringIrrigationMethods(typeIrrigationMethod);
00506 
00507 // --------------------------------------------
00508 // ... Canal model
00509 void setCANAL_MODEL(int _canalModelType);
00510 int CANAL_MODEL();
00511 
00512 // Used in Mode 0, 3, 4
00513 void setCANAL_INTERNAL_REUSE(int _canalModelType);
00514 int getCANAL_INTERNAL_REUSE();
00515 // Used for mode 0,3,4
00516 void setCANAL_BETA_SHARE(double _betaShare);
00517 double getCANAL_BETA_SHARE();
00518 // Used in Mode 1, 3, 4
00519 void setCANAL_LOSSFACTOR(double _canalLosses);
00520 double getCANAL_LOSSFACTOR();
00521 // Used in Mode 1, 3, 4
00522 void setCANAL_LAMBDA(double _canalLambda);
00523 double getCANAL_LAMBDA();
00524 
00525 void initializeCanalDefault();
00526 void readCanalFile(string fn);
00527 
00528 void setCanalFilename(string fn);
00529 string getCanalFilename();
00530 
00531 void setWASIM_SPINUP(string fn);
00532 string WASIM_SPINUP();
00533 
00534 
00535 #endif
00536 
00537 
00538 
00539 

Generated on Thu Aug 28 12:38:44 2008 for MPMAS by  doxygen 1.3.9.1