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

old_InputDataTable.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:       InputDataTable.h (formerly inputTable.h)
00012 //
00013 //  Contents:   Auxiliary class for reading input files
00014 //
00015 //
00016 //
00017 //------------------------------------------------------------------------------
00018 
00019 
00020 #ifndef _InputDataTable_h
00021 #define _InputDataTable_h
00022 
00023 #include <stdio.h>
00024 //#include <stdlib.h>
00025 
00026 //Arnold2006_10
00027 // Libraries C++
00028 #include <iostream>
00029 
00030 #include <fstream>   // new 2005
00031 #include <string>    // new 2005
00032 #include "MatrixDouble.h"
00033 
00034 #define _NUMDATATYPES_ 4
00035 enum DataType {typeEMPTY, typeDouble, typeString, typeInteger, typeValue};
00036 #define _NUMCOLS_ 50  // maximum number of columns
00037 #define _MAXROWS_ 1000  // maximum number of columns
00038 #define _NUM_COLINFO_ 2
00039 enum enumTableCol{colType, colCol};
00040 
00041 
00069 class classInputTable
00070 {
00071 
00072 public:
00073 
00075 
00076 
00077 
00078    // READ functions
00079    virtual void readFromFile(ifstream& s);
00080    virtual void readFromFile(char* s);
00081    virtual void readFromFile(string s);
00082 
00083 
00084    //---------------------------------------------------------------------------
00085 
00087 
00088 
00089    //  info on data types, columns, etc
00090    int rows() {return hasNumberOfRows;}
00091    int cols() {return hasNumberOfCols;}
00092 
00093    int getStringCols(){return hasNumberOfStringCols;};
00094    int strings(){return getStringCols();};
00095    int getNumCols(DataType dt);
00096    
00097    // Returns data type by column in original data table
00098    DataType getTypeFromAbsCol(int cAbs)
00099       {return (DataType)(int)KEY.getValue(cAbs, colType);}
00100 
00101    // Returns (INTERNAL) column in storage class by column in original data table
00102    // (not to be used, as the use of internall columns might become confusing)
00103    int getInternalColFromAbsCol(int cAbs)
00104       {return (int)KEY.getValue(cAbs, colCol);}
00105 
00106    // Returns column in original data table
00107    virtual int findAbsColumnByName(string varname);
00108    virtual DataType getTypeByVarname(string varname);
00110    //---------------------------------------------------------------------------
00111 
00113 
00114    //  All functions require the column in the original table
00115    virtual int getInt(int r, int colAbs);
00116    virtual double getDouble(int r, int colAbs);
00117    virtual string getString(int r, int colAbs);
00118 
00119    virtual int getInt(int r, string varname);
00120    virtual double getDouble(int r, string varname);
00121    virtual string getString(int r, string varname);
00123    //---------------------------------------------------------------------------
00124 
00126 
00127    virtual void writeToFile(ofstream&);
00128    virtual void writeToFile(char* s);
00129    virtual void writeToFile(string s);
00130 
00132    //---------------------------------------------------------------------------
00133 
00135 
00136       
00138    //  info on data types, columns, etc
00139    virtual DataType getCol(string varname, MatrixDouble& mat);
00140    virtual DataType getCol(string varname, string*& names);
00141    // Column in original table
00142    virtual DataType getCol(int col, MatrixDouble& mat);
00143    virtual DataType getCol(int col, string*& mat);
00144    
00145    void getMatrixFromTable(int startVal, int endVal, MatrixDouble& monthlyWaterRequirements );
00147    //---------------------------------------------------------------------------
00148 
00150 
00151    void printKeyToScreen();
00152    void printAllInfo();
00153    void printStrings();
00154    void printCell(int r, int colAbs);
00155    void printCellToStream(int r, int colAbs, ofstream& out);
00156    void printRowToStream(int r, ofstream& out);
00157    void printRow(int r);
00158    void printCol(int cAbs);
00159    void printCol(string varn);
00160    void printVarNames();
00161    void printVarNamesToStream(ofstream& out);
00162    void printTypesToStream(ofstream& out);
00163    void printTypes();
00165    //---------------------------------------------------------------------------
00166 
00168 
00169    virtual int findAllRowsWithVal(int colAbs, double val, MatrixDouble& foundVals);
00170    virtual int findAllRowsWithVal(string varNm, double val, MatrixDouble& foundVals);
00171 
00172    virtual int findAllRowsWithVal(int colAbs, int val, MatrixDouble& foundVals);
00173    virtual int findAllRowsWithVal(string varNm, int val, MatrixDouble& foundVals);
00174 
00175 
00176    virtual void shrinkKeyToActualSize();
00178    //---------------------------------------------------------------------------
00179 
00181 
00182 
00183         classInputTable(void)
00184         {       isvirgine=true;
00185       initializeEmpty();
00186         }
00187    void initializeEmpty();
00188 
00189    classInputTable(classInputTable& tab)
00190    { isvirgine=true;
00191      copyToThis(tab);
00192    }
00193 
00194 
00195     //DESTRUCTOR
00196     // calls 'deallocate()'
00197         virtual ~classInputTable();
00198 
00199    void copyToThis(classInputTable& tab);
00200 
00201    virtual void deallocate();
00202 
00203    //virtual void joinIntoThis(classInputTable& tab);
00204 
00205    // Operators
00206         virtual classInputTable& operator= (classInputTable& tab);
00208    //---------------------------------------------------------------------------
00209         
00210         
00211    
00212 private:
00213 
00214  virtual void setAllZero();
00215 
00216 protected:     //public
00218    bool isvirgine;
00219    // Number of rows, cols
00220    int hasNumberOfCols;
00221    int hasNumberOfRows;
00222    int hasNumberOfStringCols;
00223    int hasNumberOfDoubles;
00224    int hasNumberOfInts;
00225 
00226    // Storage of variable names
00227    string* varNames;    // a vector of strings
00228 
00229    // Storage of all string-entries 
00230         string** str;
00231    
00232         // Storage of value-entries in a double class "MatrixDouble"
00233         MatrixDouble mat;
00234 
00235    // KEY contains same number of columns as table.
00236    // Thus, each entry represents one column.
00237    //
00238    // KEY has two rows, specifying 
00239    //    (a) the data type of that column
00240    //    (b) the column in internal storage class
00241    // line <enumTableCol> colType : (double)DataType
00242    // line <enumTableCol> colCol  : (double)Column
00243    MatrixDouble KEY;
00244 
00245    // Copy constructors. Carefull: These protected functions do not clear memory,
00246    // thus the function <initializeEmpty> has to be called before!
00247    // Then, the number of cols and rows have to be set
00248    void copyStr(string** s);
00249    void copyVarNames(string* varNames);
00250    void setRows(int r) {hasNumberOfRows=r;}
00251    void setCols(int c) {hasNumberOfCols=c;}
00252 
00253         virtual void copyMat(MatrixDouble& m);
00254    virtual void copyKey(MatrixDouble k);
00255    virtual int getInternalColByVarname(string varname);
00256 
00257    // produces error output if dt is not integer or double
00258    virtual bool testForMatType(DataType dt); 
00259    virtual bool testForMatType(DataType dt, bool doOutput);    
00260 
00261 };
00262 
00263 string makeCapitalLetter(string s);
00264    // Append to closed / open file
00265 void appendToFileBackgroundIrrig(classInputTable& tab, MatrixDouble& foundVals, string outFile);
00266 void appendToFileBackgroundIrrig(classInputTable& tab, MatrixDouble& foundVals, ofstream& out);
00267 void writeToFileBackgroundIrrig(classInputTable& tab, MatrixDouble& foundVals, string outFile);
00268 
00269 string convertTypeAsString(DataType dt);
00270 #endif

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