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};
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
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
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
00098 DataType getTypeFromAbsCol(int cAbs)
00099 {return (DataType)(int)KEY.getValue(cAbs, colType);}
00100
00101
00102
00103 int getInternalColFromAbsCol(int cAbs)
00104 {return (int)KEY.getValue(cAbs, colCol);}
00105
00106
00107 virtual int findAbsColumnByName(string varname);
00108 virtual DataType getTypeByVarname(string varname);
00110
00111
00113
00114
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
00139 virtual DataType getCol(string varname, MatrixDouble& mat);
00140 virtual DataType getCol(string varname, string*& names);
00141
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
00196
00197 virtual ~classInputTable();
00198
00199 void copyToThis(classInputTable& tab);
00200
00201 virtual void deallocate();
00202
00203
00204
00205
00206 virtual classInputTable& operator= (classInputTable& tab);
00208
00209
00210
00211
00212 private:
00213
00214 virtual void setAllZero();
00215
00216 protected:
00218 bool isvirgine;
00219
00220 int hasNumberOfCols;
00221 int hasNumberOfRows;
00222 int hasNumberOfStringCols;
00223 int hasNumberOfDoubles;
00224 int hasNumberOfInts;
00225
00226
00227 string* varNames;
00228
00229
00230 string** str;
00231
00232
00233 MatrixDouble mat;
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 MatrixDouble KEY;
00244
00245
00246
00247
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
00258 virtual bool testForMatType(DataType dt);
00259 virtual bool testForMatType(DataType dt, bool doOutput);
00260
00261 };
00262
00263 string makeCapitalLetter(string s);
00264
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