00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _InputDataTable_h
00021 #define _InputDataTable_h
00022
00023 #include <stdio.h>
00024
00025
00026
00027
00028 #include <iostream>
00029
00030 #include <fstream>
00031 #include <string>
00032 #include "MatrixDouble.h"
00033
00034 #define _NUMDATATYPES_ 4
00035 enum DataType {typeEMPTY, typeDouble, typeString, typeInteger, typeValue, typeMAX};
00036 string getStringDataType(DataType tp);
00037 void printDataTypeToScreen();
00038 bool checkDataType(DataType tp, DataType typeExpected, string nameOfFunction);
00039
00040 #define _NUMCOLS_ 200 // maximum number of columns
00041 #define _MAXROWS_ 1000 // maximum number of columns
00042 #define _NUM_COLINFO_ 2
00043 enum enumTableCol{colType, colCol};
00044
00045
00046
00075 class classInputTable
00076 {
00077
00078 public:
00079
00081
00082
00083
00084
00085 virtual void readFromFile(ifstream& s);
00086 virtual void readFromFile(char* s);
00087 virtual void readFromFile(string s);
00088
00089
00090
00091
00093
00094
00095
00096 int rows() {return hasNumberOfRows;}
00097 int cols() {return hasNumberOfCols;}
00098
00099 void checkDimension(int r, int cAbs, string nameOfFunction);
00100
00101
00102 int getStringCols(){return hasNumberOfStringCols;};
00103 int strings(){return getStringCols();};
00104 int getNumCols(DataType dt);
00105
00106
00107 DataType getTypeFromAbsCol(int cAbs)
00108 {return (DataType)(int)KEY.getValue(cAbs, colType);}
00109
00110
00111
00112 int getInternalColFromAbsCol(int cAbs)
00113 {return (int)KEY.getValue(cAbs, colCol);}
00114
00115
00116 virtual int findAbsColumnByName(string varname);
00117 virtual DataType getTypeByVarname(string varname);
00118 virtual string getVariableName(int cAbs);
00120
00121
00123
00124
00125 virtual int getInt(int r, int colAbs);
00126 virtual double getDouble(int r, int colAbs);
00127 virtual string getString(int r, int colAbs);
00128
00129 virtual int getInt(int r, string varname);
00130 virtual double getDouble(int r, string varname);
00131 virtual string getString(int r, string varname);
00133
00134
00136
00137
00138 virtual void setValue(int r, int c, double value);
00139 virtual void setString(int r, int c, string str);
00141
00142
00144
00145 virtual void writeToFile(ofstream&);
00146 virtual void writeToFile(char* s);
00147 virtual void writeToFile(string s);
00148 void writeToFile_RowsWhereColUnequals(string fn, string nm, double valCol);
00149
00151
00152
00154
00155
00157
00158 virtual DataType getCol(string varname, MatrixDouble& matrixTarget);
00159 virtual DataType copyColumnIntoVector(string varname, MatrixDouble& matrixTarget);
00160
00161 virtual DataType getCol(string varname, string*& stringArrayTarget);
00162
00163
00164 virtual DataType getCol(int col, MatrixDouble& matrixTarget, int colOfMat);
00165 virtual DataType copyColumnIntoMatrix(int col, MatrixDouble& matrixTarget, int colOfMat);
00166
00167
00168 virtual DataType getCol(int col, MatrixDouble& matrixTarget);
00169 virtual DataType getCol(int col, string*& names);
00170
00171 void getMatrixFromTable(int startVal, int endVal, MatrixDouble& indexValueAndColumn, MatrixDouble& monthlyWaterRequirements );
00172
00174 void getMatrixWithStartString(string startStr, MatrixDouble& indexValueAndColumn, MatrixDouble& matrixReturned);
00175
00177
00178
00180
00181 void printKeyToScreen();
00182 void printAllInfo();
00183 void printStrings();
00184 void printCell(int r, int colAbs);
00185 void printCellToStream(int r, int colAbs, ofstream& out);
00186 void printRowToStream(int r, ofstream& out);
00187 void printRow(int r);
00188 void printCol(int columnAbsolute);
00189 void printCol(string varn);
00190 void printVarNames();
00191 void printVarNamesToStream(ofstream& out);
00192 void printTypesToStream(ofstream& out);
00193 void printTypes();
00195
00196
00198
00199 virtual int findAllRowsWithVal(int colAbs, double val, MatrixDouble& foundVals);
00200 virtual int findAllRowsWithVal(string varNm, double val, MatrixDouble& foundVals);
00201
00202 virtual int findAllRowsWithVal(int colAbs, int val, MatrixDouble& foundVals);
00203 virtual int findAllRowsWithVal(string varNm, int val, MatrixDouble& foundVals);
00204
00205
00206
00207 virtual void shrinkKeyToActualSize();
00209
00210
00212
00213
00214 classInputTable(void)
00215 { isvirgine=true;
00216 initializeEmpty();
00217 }
00218 void initializeEmpty();
00219
00220 classInputTable(classInputTable& tab)
00221 { isvirgine=true;
00222 copyToThis(tab);
00223 }
00224
00225 void allocate(int rows_, int numberOfcolumns_, MatrixDouble& vectorOfColumnTypes, string*& namesOfColumns);
00226
00227
00228
00229 virtual ~classInputTable();
00230
00231 void copyToThis(classInputTable& tab);
00232
00233 virtual void deallocate();
00234
00235
00236
00237
00238 virtual classInputTable& operator= (classInputTable& tab);
00240
00241
00242
00243
00244 private:
00245
00246 virtual void setAllZero();
00247
00248 protected:
00250 bool isvirgine;
00251
00252 int hasNumberOfCols;
00253 int hasNumberOfRows;
00254 int hasNumberOfStringCols;
00255 int hasNumberOfDoubles;
00256 int hasNumberOfInts;
00257
00258
00259 string* varNames;
00260
00261
00262 string** str;
00263
00264
00265 MatrixDouble mat;
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 MatrixDouble KEY;
00276
00277
00278
00279
00280 void copyStr(string** s);
00281 void copyVarNames(string* varNames);
00282 void setRows(int r) {hasNumberOfRows=r;}
00283 void setCols(int c) {hasNumberOfCols=c;}
00284
00285 virtual void copyMat(MatrixDouble& m);
00286 virtual void copyKey(MatrixDouble k);
00287 virtual int getInternalColByVarname(string varname);
00288
00289
00290 virtual bool testForMatType(DataType dt);
00291 virtual bool testForMatType(DataType dt, bool doOutput);
00292
00293 };
00294
00295 string makeCapitalLetter(string s);
00296
00297 void appendToFileBackgroundIrrig(classInputTable& tab, MatrixDouble& foundVals, string outFile);
00298 void appendToFileBackgroundIrrig(classInputTable& tab, MatrixDouble& foundVals, ofstream& out);
00299 void writeToFileBackgroundIrrig(classInputTable& tab, MatrixDouble& foundVals, string outFile);
00300
00301 string convertTypeAsString(DataType dt);
00302
00303
00304
00305
00306
00307
00308 #endif