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

MpmasWasimInterface.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:       MpmasWasimInterface.h (formerly translation.h)
00012 //
00013 //  Contents:   Handles the interface between MP-MAS and WASIM-ETH
00014 //
00015 //
00016 //
00017 //------------------------------------------------------------------------------
00018 
00019 
00020 #ifndef _MpmasWasimInterface_h
00021 #define _MpmasWasimInterface_h
00022 //for class FileType
00023 
00024 #include <string>
00025 
00026 #include <stdio.h>
00027 #include <iostream>
00028 #include <fstream>
00029 using namespace std;  // std::stream  --> stream (simpler)
00030 
00031 class ausgabe;
00032 // LINUX / WINDOWS specific definitions
00033 #ifdef AIX
00034    #include <unistd.h>
00035 #else
00036         #include <dos.h>
00037 #endif /* AIX */
00038 
00039 class MatrixDouble;
00040 class Raster2D;
00041 class Raster3D;
00042 class classInputTable;
00043 
00044 
00045 enum enumActivityKeyNames
00046 {typeAKeyActivityID, typeAKeyLPCOL, typeAKeyPRICECOL,   typeAKeyLPROW, typeAKeySOILCLASS, typeAKeyIPG, 
00047 typeAKeyKRTYPE, typeAKeyKY, typeAKeyCROPTYPE, typeAKeyIRRMETHOD, typeAKeyYIELDMAX, 
00048 typeAKeyIrrigEfficiency, typeAKeyLanduseMpmas, typeAKeyLanduseWasim, typeAKeyCropID, 
00049 typeAKeyEND, 
00050 matrixTypeAKeyMonthlyDemand, matrixTypeAKeyExpectations, 
00051 finalAKey};
00052 
00054 // --> TRANSLATTION FUNCTIONS USED BY ALL COMPONENTS
00055 // =====================================================================
00056 
00057 void readActivityKey(ifstream& stream, string*& colNamesActivityKey, classInputTable& activityKey, MatrixDouble& matrixMonthlyWaterDemand, MatrixDouble& matrixMonthlyWaterExpectations);
00058 void readActivityKey(string fn, string*&  colNamesActivityKey, classInputTable& activityKey, MatrixDouble& matrixMonthlyWaterDemand, MatrixDouble& matrixMonthlyWaterExpectations);
00059 void getKeyfileColumnNames(string*& colNamesActivityKey);
00060 
00061 int readTable_ActivityKey_Lookup(MatrixDouble& lookup_CroppingActivity2WasimLanduse, string fnActivityKey);
00062 int readTable_CropKey_Lookup( MatrixDouble& lookupMatrix_LuMpmas_2_LuWASIM, string fnCropKey);
00063 
00064 void addToLookup_CropKey(MatrixDouble& lookup_CroppingActivity2WasimLanduse, MatrixDouble& lookupMatrix_LuMpmas_2_LuWASIM);
00065 
00066 
00067 void translateIrrigQuant2WASIM(Raster2D& irrigIDs, Raster2D& gisCropAct, 
00068                 // in: Irrig quantity in mm, translation MatrixDouble,  number of "bins" per activity
00069                 Raster2D& gisIrrigQuant, MatrixDouble& MAT_IRRIGID, int maxExpansion);
00070 
00071 
00072 
00073 
00075 // --> DEFINITION OF RESCALING FUNCTIONS
00076 // =====================================================================
00077 //Arnold2006_12_31_c
00078 // returns ratio of both cells
00079 // link-MatrixDouble linkss g-> G, thus to recover f, we still need shift_f2g_row, col
00080 //
00081 
00082 // Shift C->G is recalculated during rescaling!
00083 int rescale_CREATEMAP(
00084                Raster2D& C,      // original data
00085                Raster2D& f,       // original data
00086                Raster2D& gisLink_g2G,  // reference
00087                Raster2D& g,           // reference
00088                Raster2D& G,           // reference
00089                int& shift_f2g_row,   // reference
00090                int& shift_f2g_col    // reference
00091                );
00092 
00093 // assuming that gisOrig is already initialized and contains NODATA everywhere
00094 void rescale_G2f_old(
00095                Raster2D& G,           // data
00096                Raster2D& gisLink_g2G,  // data
00097                int shift_f2g_row,   // data
00098                int shift_f2g_col,    // data
00099                int ratio,
00100                Raster2D& gisTarget     // reference to final data struct
00101                );
00102 
00103 // NEW FUNCTION TO TRANSLATE GIS FROM TWO RESOLUTIONS
00104 //
00105 // Example executable: SEE allgem9.cpp
00106 //                
00107 // Function creates direct link MatrixDouble that connects C to some data MatrixDouble.
00108 // Since link MatrixDouble does not refer to g any more, the link numbers are directly
00109 // linking f to G.
00110 // If a function receives a data source of dimension C instead of G, the shift C2G
00111 // has to be considered!
00112 // returns ratio of both cells
00113 int rescale_CREATEMAP_f2G(
00114                Raster2D& C,      // original data
00115                Raster2D& f,       // original data
00116                                  Raster2D& G,            // return large MatrixDouble
00117                Raster2D& gis_Link_f2G,  // reference
00118                MatrixDouble& mSHIFT   // reference
00119                );
00120 
00121 // gisTarget will have same dimensions as gisLink
00122 void rescale_C2f(
00123                Raster2D& C,           // data
00124                Raster2D& gisLink_f2G,  // data
00125                int Y_shift_C2G,   // data
00126                int X_shift_C2G,    // data
00127                Raster2D& gisTarget     // reference to final data struct
00128                );
00129 
00130 void rescale_f2G(Raster2D& gis_f, Raster2D& gis_L, Raster2D& gis_Gorig, Raster2D& gis_G);
00131 
00132 void rescale_saveAll(string dirOut,
00133       Raster2D& gis_L,    // Link MatrixDouble, will be saved to "gis_L"
00134       Raster2D& gis_G,    // Coarse extracted MatrixDouble around gis_L, will be saved to "gis_G"
00135       Raster2D& gis_C,    // Coarse full MatrixDouble, only passed for x/y-coordinates
00136       int Y_shift_C2G,     // Shift of row: full MatrixDouble C to G
00137       int X_shift_C2G,     // Shift of col: full MatrixDouble C to G
00138       int ratio            // Ratio of cellsize gis_L to gis_C
00139       );
00140 
00141 void rescale_loadAll(string dirOut,   // only input, rest loaded
00142       Raster2D& gis_L,    // Link MatrixDouble,  loaded from "gis_L"
00143       Raster2D& gis_G,    // Coarse extracted MatrixDouble around gis_L, loaded from "gis_G"
00144       int C_ycoord,    // Coarse full MatrixDouble,  x/y-coordinates
00145       int C_xcoord,    // Coarse full MatrixDouble, x/y-coordinates
00146       int Y_shift_C2G,     // Shift of row: full MatrixDouble C to G
00147       int X_shift_C2G,     // Shift of col: full MatrixDouble C to G
00148       int ratio            // Ratio of cellsize gis_L to gis_C
00149       );
00150 
00151 int ratio_getAndCheck(double nom, double div);
00152 int ratio_getAndCheck(int nom, int div);
00153 
00154 
00155       
00156 
00157 /* TODO -oArnold -cimplement : Eventually better to use other precompiler define: "ifndef MAS" or "ifdef COUPL" */
00158 
00159 
00160 // ------------------------------------------------------------
00161 //    Functions around COUPLING
00162 // --> start
00163 // ------------------------------------------------------------
00164 
00165 void MAS_initCoupling();
00166 
00167 int DOWASIM_loadKeyFile(string fn, MatrixDouble& keyMat);
00168 
00169 
00170 void initTDTvariables();
00171 
00172 //void receiveInflowMat_andExtract2(MatrixDouble& target);
00173 void receiveInflowMat_andExtract(MatrixDouble& medianMat);
00174 
00175 // Both Functions call COMMUNICATE_ALL_DATA, to ensure mirror order of data exchange
00176 // flag_SENDorRECEIVE == true  : SEND
00177 // flag_SENDorRECEIVE == false  : RECEIVE
00178 
00179 void receiveRaster3D_couplingData(Raster3D& gis3D,  bool RECEIVE_TDT,  bool doprocessing, bool isIrrig);
00180 void sendViaTDT_Raster3D_couplingData( bool RECEIVE_TDT, bool doprocessing, bool isIrrig);
00181 
00182 
00183 int receiveIntFromController(void);
00184 void sendIntToController(int val);
00185 
00186 
00187 //void extractColumns_initializeFromFile(string fn, MatrixDouble& transKey);
00188 //int extractColumns_initializeFromFile(ifstream& stream, MatrixDouble& transKey);
00189 string updateraster3D_filenames(Raster3D& gis3D, string irrigYN);
00190 
00192 // --> Functions used in coupling and also in MPMAS internally
00193 // =====================================================================
00194 //Arnold2006_83
00195 //Master function, calls next three functions
00196 // Filenames specified here!
00197 //void  readMAS2WASIM(int expandFact, MatrixDouble& MAT_IRRIGID);
00198 
00199 // Read cropping activity table
00200 //int readTable_cropAct(MatrixDouble& MAS2WASIM, char* keyname);
00201 //int readTable_LU_mas2wasim(MatrixDouble& LUmas2Wasim, char* filename);
00202    
00203 void  readMAS2WASIM_byKey(int expandFact,  MatrixDouble& MAT_IRRIGID);
00204 
00205 void readActivityKey(ifstream& stream,  classInputTable& activityKey, 
00206       MatrixDouble& matrixMonthlyWaterDemand, 
00207       MatrixDouble& indexMonthlyWaterDemand,
00208       MatrixDouble& matrixMonthlyWaterExpectations, 
00209       MatrixDouble& indexMonthlyWaterExpectations);
00210 void readActivityKey(string fn,  classInputTable& activityKey, 
00211       MatrixDouble& matrixMonthlyWaterDemand, 
00212       MatrixDouble& indexMonthlyWaterDemand,
00213       MatrixDouble& matrixMonthlyWaterExpectations, 
00214       MatrixDouble& indexMonthlyWaterExpectations);
00215       
00216 string getKeyfileColumnNames(enumActivityKeyNames type);
00217 int readTable_ActivityKey_MAS2WASIM(MatrixDouble& MAS2WASIM, string fnActivityKey);
00218 int readTable_CropID2WasimLU(MatrixDouble& LUmas2Wasim, string fnCropKey);
00219 
00220 
00221 void addToMas2Wasim_LU_mas2wasim(MatrixDouble& MAS2WASIM, MatrixDouble& LUmas2Wasim);
00222 // ------------------------------------------------------------
00223 //    Functions around COUPLING
00224 // <-- end
00225 // ------------------------------------------------------------
00226 
00227 #endif

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