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

MatrixDouble.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:       MatrixDouble.h (formerly matrix9.h)
00012 //
00013 //  Contents:   Matrix class, implemented for floating points
00014 //
00015 //
00016 //
00017 //------------------------------------------------------------------------------
00018 
00019 
00020 
00021 // This is the header file for a class: MATRIX
00022 //              (file: matrix9.cpp)
00023 //              
00024 //   It was done to handle matrizes. Functions include: 
00025 //                                      -  initialization
00026 //                                      -  information on MatrixDouble
00027 //                                      -  handling of MatrixDouble size, 
00028 //                                      -  overloading operators (simple calculation)
00029 //                                      -  reading and writing MatrixDouble to file
00030 //                                      -  printing MatrixDouble or MatrixDouble components to screen,
00031 //                                         in different formats
00032 //                                      -  Accessing the content of the MatrixDouble
00033 //                                         (element, row, column, ...)
00034 //                                      -  Send and receive MatrixDouble through Typed Data Transfer
00035 //                                              library (TDT, see:
00036 //                                               http://www.pik-potsdam.de/software/tdt
00037 //                                      - perform simple MatrixDouble tasks (sort, histogram,
00038 //                                              allocate certain values within MatrixDouble)
00039 //
00040 //      -------------------------------------------------------------
00041 //                              NOTE: A PRECOMPILER FLAG "`DO_TDT"'
00042 //                                         IS USED FOR INCLUDING TDT
00043 //      -------------------------------------------------------------
00044 
00045 #ifndef _MatrixDouble_h
00046 #define _MatrixDouble_h
00047 
00048 #include <stdio.h>
00049 #include <stdlib.h>
00050 #include <iostream>
00051 
00052 #include <string>
00053 using namespace std; // fuer C++-Compiler, damit cin nicht als std::cin eingelesen werden muss
00054 
00055 
00056 //DEPENDING ON OTHER FILES ALREADY INCLUDED..
00057 #ifndef EPS
00058         #define EPS 1.0e-6   //precision, OSL seems to work with 1.0e-7
00059                                                         // (see "ekk_c_api.h")
00060 #endif
00061 
00062 
00063 #ifdef DO_TDT
00064 extern "C" {
00065    #include "tdt.h"
00066 }
00067 #endif
00068 
00069 class MatrixDouble
00070 {       protected:     //public
00071         double** ptr;
00072         int z_anzahl; //rows
00073         int s_anzahl; // columns
00074 
00075 public:
00076    //CONSTRUCTOR without memory allocation
00077    // --> Everything set to 'NULL' / NOTDEFINED
00078         MatrixDouble (void)
00079         {       setEmpty();
00080         }
00081 
00082    MatrixDouble ( const MatrixDouble& other );
00083       
00084    //CONSTRUCTOR with memory allocation
00085    // --> memory allocated,
00086    MatrixDouble (int r, int c)
00087         {       setEmpty();
00088       allocate(r,c);
00089         }
00090 
00091     //DESTRUCTOR
00092     // calls 'deallocate()'
00093         virtual ~MatrixDouble();
00094 
00095    // --> pointer set to 'NULL' everything else to NOTDEFINED
00096    // z_anzahl, s_anzahl are ZERO
00097    void setEmpty(void);
00098    // Free memory of **ptr;  setEmpty
00099    virtual void deallocate(void);
00100         virtual void deallokieren(void); // calls 'deallocate'   
00101 
00102 
00104    // FUNKTIONs TO MODIFY THE DIMENSIONS OF MATRIX
00105         //allocate(z,s);
00106         //setValueExp(r, c, val)  --> expands MatrixDouble automaticall,
00107         //      if r, c not within MatrixDouble!
00108         //addRow()
00109         //addRows(4)
00110         //addCol()
00111         //addCols(2)
00112 
00113    // if dimensions are [0][0] - or loose all values
00114         virtual void allokieren (int z, int s);
00115         virtual void allocate(int row, int col);
00116    // Vector
00117         virtual void allocate(int elems);
00118    //Immediately initialize with val
00119    virtual void allocate (int z, int s, double val);
00120    virtual void allocate (MatrixDouble& m2); // Allocates same dimensions as m2
00121 
00122    // RESIZING MATRIX
00123    //Function expands MatrixDouble by "zus_z" rows
00124         virtual void matrix_vergroessern_z(int zus_z);
00125 
00126    //Function expands MatrixDouble by "zus_s" columns
00127         virtual void matrix_vergroessern_s(int zus_s);
00128 
00129    // increase MatrixDouble size by adding more than one row
00130    virtual void addRows(int newR);
00131 
00132    // increase MatrixDouble size by adding  more than one column
00133    virtual void addCols(int newC);
00134    // increase MatrixDouble size by adding  one row
00135    virtual void addRow(void);
00136    // increase MatrixDouble size by adding  one column
00137    virtual void addCol(void);
00138 
00139    // deletes row with number 'row' (any, from within)
00140    virtual void deleteRow(int row);
00141    // deletes one col (any, from within)
00142 //   virtual void deleteCol(int col);
00143    // deletes first row
00144    virtual void deleteFirstRow(void);
00145    // deletes first row
00146    virtual void deleteLastRow(void);
00147 
00148    // insertRow
00149    // Searches column 'col' until val is larger then first entry (to maintain order!)
00150    // Then, one row is added into that position
00151    virtual int insertRow(int col, double val);
00152 
00153 
00154    // Increase MatrixDouble size by adding  row vector to MatrixDouble (complying with row number)
00155    virtual void addRow(MatrixDouble& m);
00156    // Increase MatrixDouble size by adding column vector to MatrixDouble (complying with row number)
00157    virtual void addCol(MatrixDouble& m);
00158 
00159 
00161    // INFORMATION ON MATRIX SIZE
00162    // access size of MatrixDouble
00163    virtual int zeilen(void);
00164    virtual int spalten(void);
00165    virtual int rows() const;
00166    virtual int cols() const;
00167    // <length()> returns maximum  of (rows()) and (cols())
00168    virtual int length() const;
00169    // <width()> returns minimum of (rows()) and (cols())
00170    virtual int width() const;
00171 
00172    // returns <true> if width() == 1
00173    virtual bool isvector();
00174    virtual bool isVector(); // rename of above
00175 
00177    // INFORMATION ON MATRIX: KEYS
00178    // --> get information on values
00179    //
00180    // Functions to transform MatrixDouble into PositionMatrix (Sparse Matrix notaiton)
00181    // MatrixDouble 'posMat' contains numValues rows, three columns
00182    //  row   col  getValue(row, col)
00183    //
00184    //Then,the number of entries is returned
00185    //
00186    //Writes all values equal to 'val' into posMAT
00187    virtual int findAllEntriesEquallingValue(MatrixDouble& posMat, double value);
00188 
00189    //Writes all values not equal to 'noVal' into posMAT
00190    virtual int getAllValPos(MatrixDouble& posMat, double noVal);
00191 
00192    virtual void shiftPosMat(
00193                int rowShift,   // shift of rows
00194                int colShift    // shift of cols
00195               );
00196               
00197    virtual void makeTableHeader(string fn);
00198    virtual void makeTableHeader(char* d);
00199 
00200    // Count entries that are not NODATA
00201    virtual int countNOT_NODATA(double NODATA);
00202    virtual int countDATA(double DATA);
00203 
00204    //Function deletes on row from MatrixDouble and shrinks MatrixDouble
00205         virtual void cutMatrixRow(int crow);//neu 2004
00206    //Function deletes on column from MatrixDouble and shrinks MatrixDouble
00207         virtual void cutMatrixCol(int ccol);//neu 2004
00208    // Matrix copies all elements from matrix2 into mother MatrixDouble. 
00209    //Both matrixes need same dimension
00210         virtual void copy(MatrixDouble& matrix2);
00211    //Arnold2006_200
00212    virtual void copyInto(MatrixDouble& matrixTarg);
00213 
00214    // Operators
00215         virtual MatrixDouble& operator+= (MatrixDouble& matrix2);
00216         virtual MatrixDouble& operator-= (MatrixDouble& matrix2);
00217         // Multiply MatrixDouble piecewise
00218         virtual MatrixDouble& operator*= (MatrixDouble& matrix2); 
00219         // Multiply MatrixDouble with scalar
00220    virtual MatrixDouble& operator*= (double fact);
00221 #ifdef AIX
00222         virtual MatrixDouble& operator= (MatrixDouble& matrix2);
00223 #endif   
00224         virtual MatrixDouble& operator= (const MatrixDouble& matrix2);
00225 
00226    // READING & WRITING TO FILE -----------------------------//
00227    // Matrix is read from closed file, to be passed name of file
00228         //virtual void readInputFromFile(char* filename);
00229    // Matrix is read from open file (C-Notation)
00230 
00231 
00232 
00233         virtual void readInputFromFile(char* fn, int z, int s);
00234    virtual void readInputFromFile(string fn, int z, int s);
00235 //   virtual void readFromFile(string fn, int z, int s); // RENAME from above only
00236 
00237 
00238    // VERY DIRTY ... reads part of matrix only, error if not upper left corner... please dont use!
00239    virtual void readTopMatrixCorner(FILE*, int ,int);
00240 
00241    // Already allocated
00242    virtual void readInputFromFile(FILE*);
00243    // Vector function ...
00244         //virtual void readInputFromFile(FILE*, int);
00245    virtual void readInputFromFile(char* fn, int pos);
00246    virtual void readMatrix_FILE(string filename);
00247    virtual void readMatrix_FILE_INT(string filename);
00248    virtual void readInputFromFile_INT(FILE* datei);
00249    // Function reads line and dissects it char by char...
00250 
00251    // Matrix is read from open file (C-Notation)
00252    virtual void readInputFromFile(ifstream&); // Matrix has to be allocated already!
00253         //virtual void readInputFromFile(ifstream&, int ,int);
00254         //virtual void readInputFromFile(ifstream&, int);
00255 
00256    // Function reads line and dissects it char by char...
00257    // Carefull: Delimits tabs '\t', space and semicolon.
00258    virtual void readDelimNums(ifstream& streamData, int numVals);
00259 
00260    //Arnold2006, Mai 19
00261    virtual void appendRowFromFile(ifstream& in, int numValues);
00262    // Assumes full row
00263    virtual void appendRowFromFile(ifstream& in);
00264 
00265    
00266    virtual void appendColToFileAsRow(int col, string fn);
00267    virtual void appendColToFileAsRow(int col, char* fn);
00268    
00269    virtual void appendRowToFile(int row, string fn);   
00270    virtual void appendRowToFile(int row, char* fn);
00271    virtual void appendRowToOpenStream(ofstream& outStream, int row);   
00272 
00273    virtual void appendVecToFile(char* fn);
00274    virtual void appendVecToFile(string fn);
00275    virtual void appendVecToFile(ofstream& out);
00276 
00277    virtual void appendColToFileAsRow(int col, ofstream& out);
00278    
00279    
00280    
00281 
00282 
00283    // Function writes MatrixDouble to file (C-notation=
00284    // normal format
00285    virtual void in_datei_schreiben(FILE*);
00286    // scientific format
00287         virtual void in_datei_schreibenE(FILE*);
00288    // transposed (useful if loading into xls sometimes...)
00289         virtual void in_datei_schreibenT(FILE*);
00290 
00291    // Writing into file, using "filename"
00292         virtual void datei_schreiben(char* filename);
00293 
00294  
00295         virtual void writeRowToFile_NoLineEnd(FILE* datei, int row);
00296         virtual void writeRowToFile_WithLineEnd(FILE* datei, int row);
00297         
00298         virtual void writeRowToFile_NoLineEnd(ofstream& datei, int row);
00299         virtual void writeRowToFile_WithLineEnd(ofstream& datei, int row);
00300         
00301         
00302         virtual void writeColToOpenFileAsRow_WithLineEnd(ofstream& datei, int row);
00303 
00304         virtual void writeColToOpenFileAsRow_NoLineEnd(FILE* datei, int col);
00305         virtual void writeColToOpenFileAsRow_WithLineEnd(FILE* datei, int col);
00306 
00307 
00308         //Arnold2006_10
00309    // WRITING TO OPEN STREAM, USING C++-FILE STREAM & NOTATION
00310         virtual void writeToFile(ofstream& out);
00311         virtual void writeToFile(char* filen);
00312    virtual void writeToFile(string filen);
00313    virtual void writeToFileTransposed(string fn);
00314    
00315         
00316 // First: Filename 
00317 //      (default: 
00318 //                      - FILENAMES(keyLOG) for DOLONG==false, 
00319 //                      - FILENAMES(keyLOG2)  for DOLONG==true )
00320 // Name of TDT configuration file
00321 // type of communication: 1 SEND, 0 RECEIVE
00322 // DOLONG: Also write some content of MatrixDouble
00323         virtual void writeLogfileTDT(string fn, char*  configFile, int type, bool dolong);
00324         virtual void writeLogfileRW(string , char* , int type);
00325 
00326         
00327         virtual void writeToFileT(ofstream& out);
00328    // Into first row, writes two entries: number of rows,
00329    // and number of columns
00330    // Leaves empty row in second line
00331    virtual void readFromFileWithDims(string fn);
00332    virtual void readFromFileWithDims(char* fn);   
00333    virtual void readFromFileWithDims(ifstream& in);
00334 
00335    virtual int readVectorDyn(string fn);
00336    virtual int readVectorDyn(char* fn);
00337    virtual int readVectorDyn(ifstream& in);
00338 
00339    // This function does not yet know anything about MatrixDouble size.
00340    // - The size is determined according to an analysis of the first line
00341    // - Empty lines (during and in the end) are ignored
00342    // - Check: Line should have appropiate number of entries!
00343    virtual int readMatDyn(string fn);
00344    virtual int readMatDyn(char* fn);
00345    virtual int readMatDyn(ifstream& in);
00346  
00347    virtual void readFromFileDimsAndHeader(string fn);
00348    virtual void readFromFileDimsAndHeader(char* fn);
00349    virtual void readFromFileDimsAndHeader(ifstream& in);
00350 
00351    virtual void writeToFileWithDims(string fn);
00352    virtual void writeToFileWithDims(char* fn);   
00353    virtual void writeToFileWithDims(ofstream& out);
00354 
00355    // Write in sparse MatrixDouble notation (often simpler for reading)
00356    // If MatrixDouble only: Start with dimensions (ROW, COL)
00357    //    header (normal)
00358    //    row  col  val
00359    virtual void writeToFile_sparse(string fn, int nodata);
00360    virtual void writeToFile_sparse(char* fn, int nodata);
00361    virtual void writeToFile_sparse(ofstream& out, int nodata);
00362    // Only for internal use, does not write dimension of MatrixDouble
00363    virtual void writeToFile_sparse_values(ofstream& out, int nodata);
00364 
00365    virtual void loadFromFile_sparse_values(ifstream& streamData, int nodata);
00366 
00367    virtual void loadFromFile_sparse(string fn, int nodata);
00368    virtual void loadFromFile_sparse(char* fn, int nodata);
00369    virtual void loadFromFile_sparse(ifstream& streamData, int nodata);
00370 
00372    // WRITING TO SCREEN
00373    // Write complete MatrixDouble  to screen
00374         virtual void printToScreen(void);
00375    // Print only subset of MatrixDouble
00376    virtual void printToScreen(int rlu, int clu, int rdr, int cdr);
00377 
00378 
00379    virtual void ausschreiben (void);   //(german)
00380 
00381         //Write all rows, as integers
00382    //   (using pTS_row_compact(int z); )
00383    //    as integer value if whole values
00384    //    as 3.2  if double values (cuts of larger numbers...)
00385         virtual void printToScreen_compact(void);
00386    virtual void printToScreen_compact(int numDigits);
00387 
00388    // Print only subset of MatrixDouble
00389    virtual void printToScreen_compact(int rlu, int clu, int rdr, int cdr); // assumes 2 digits
00390    virtual void printToScreen_compact(int rlu, int clu, int rdr, int cdr, int numDigits);
00391 
00392 
00393 
00394 
00395 
00396 
00397 //      virtual void printToScreen_compactT(void);
00398         virtual void printToScreenInt(void);
00399         //Write column as integer value
00400         virtual void printToScreen_col_compact(int c);
00401 
00402    //Write row or part of row
00403    virtual void printToScreen_row(int z);
00404    virtual void printToScreen_row(int z, int startC, int endC);
00405         //Write row in compact form
00406 
00407    //    as integer value if whole values
00408    //    as 3.2  if double values (cuts of larger numbers...)
00409         virtual void printToScreen_row_compact (void);     // assumes to print last row / vector, 2 digits, full row
00410         virtual void printToScreen_row_compact (int z); // assuming 2 digites, full row
00411    virtual void printToScreen_row_compact (int z, int numDigits);
00412    virtual void printToScreen_row_compact (int z, int startC, int endC, int numDigits);
00413    virtual void printToScreen_row_compact (int z, int startC, int endC); // assuming 2 digites
00414 
00415 
00416    // Print size of MatrixDouble
00417    virtual void printSize();
00418         // Print only "active" rows
00419    // --> ignores all entries equal to "noval", uses sparse MatrixDouble notation
00420    //    r   c   val
00421    //    3   5   0.234
00422         virtual void printToScreen_col_valuesOnly(int c, double noval);
00423 
00424         virtual void printSparse(double NODATA);
00425         
00426    // Prints a row if the col "c" does NOT have value "noval"
00427         virtual void printToScreen_ifColActive(int c, double noval);
00428 
00429         //wichtig: die Nummerierung der Zeilen und Spalten beginnt mit 0
00430         virtual void wert_ausschreiben(int, int); //(write column, German)
00431         virtual void zeile_ausschreiben(int);     //(write row, German)
00432         virtual void spalte_ausschreiben(int);
00433 
00434    // -----------------------------------------------------
00435    // ACCESSING VALUES
00436    // -----------------------------------------------------
00437 
00439    // SETTING VALUES
00440    //
00441    // Access within existing MatrixDouble only, with value
00442    // both equal (historical)
00443         virtual void wert_eintragen (int, int, double wert);
00444         virtual void setValue(int row, int col, double value);
00445    // Vector function
00446    // (only possible if one-dimensional,
00447    //    menaing rows() or cols() is 1
00448    virtual void setValue(int pos, double val);
00449    // INITIALIZE MATRIX WITH OTHER MATRIX
00450    //   allocate same dimensions if necessary
00451    virtual void setValue(MatrixDouble& m1);
00452 
00453    // If position of value is out of range of the MatrixDouble,
00454    // it is expanded with additional rows and  columns
00455    // (carefull: difficult to debugg function afterwards!)
00456    virtual void setValueExp(int r, int c, double val);
00457 
00458    // Vector function
00459    // Set complete column to one value
00460    // --> set all values in column to val
00461    virtual void setCol(int c, double v);
00462    // Set complete row to one value
00463    virtual void setRow(int row, double val);
00464    
00465    // Overwrite one row  with a MatrixDouble (dimensions need to match)
00466    virtual void setRow(int row, MatrixDouble& vec);//<overwriteRowInMatrix>
00467     // Overwrite one column with a MatrixDouble (dimensions need to match)
00468    virtual void setCol(int col, MatrixDouble& vec);//<overwriteColumnInMatrix>
00469 
00470    // Set all values of initilaized MatrixDouble to 'val'
00471     virtual void setAllValues(double val);
00472 
00473    virtual void extractSubmatrixColKey(MatrixDouble& target, MatrixDouble& colKey);
00474    virtual void extract(MatrixDouble& empt,
00475       int row_left_up, int col_left_up,
00476       int dimR, int dimC);
00477    virtual void extract(MatrixDouble& empt, MatrixDouble& minmax);
00478 
00479 
00480    // Set all elements of MatrixDouble with one value
00481         virtual void initialisieren (double startwert); // (same in German)
00482    virtual void initialisieren (int startwert); // cast to double
00483 
00484 
00486    // ACCESS CONTENT OF MATRIX
00488    // returns content of element[r][c]
00489    virtual double getValue(int r, int c) const;
00490    virtual double wert_holen(int z, int s) const; //(german, historical)
00491 
00492    // Vector function
00493    // This function returns col OR row, 
00494    // if MatrixDouble is a vector otherwise: returns error
00495    virtual double getValue(int pos) const;
00496 
00497    // Function requests empty matrixes as argument (passed by reference)
00498    // Then, values are written into them.
00499    virtual void getCol(int col, MatrixDouble& mCol );//<insertColumnIntoMatrix>
00500    virtual void getRow(int row, MatrixDouble& mRow );//<insertRowIntoMatrix>
00501 
00502    // -------------------------------------------------------
00503    // Other access function - Calculatons
00504    // renamed from wert_hinzuaddieren
00505    virtual void addValue(int, int, double);
00506    virtual void addValue(int, double);
00507 
00508    virtual void divideValue(int, int, double);
00509    virtual void divideValue(int, double);
00510 
00511    // Increases specified value by one
00512    virtual void increment(int r, int c); // add one
00513 
00514    // Add the column 'pCol' of 'matPassed' to column 'thisCol' of *THIS
00515    virtual void addColValues(int pCol, int thisCol, MatrixDouble& matPassed);
00516 
00517    // Multiply one element in matrix
00518    virtual void wert_multiplizieren(int, int, double);
00519    // Scalar multiplication of complete matrix
00520    virtual void skalar_multiplizieren(double);
00521    // Divide one element in matrix
00522    virtual void wert_dividieren(int, int, double);
00523 
00524         // Component-wise multiplication
00525    virtual void mult(MatrixDouble& m1, MatrixDouble& m2);
00526 
00527    // Calculate elementwise
00528    // All assume same matrix dimensions, and return NODATAVALUE.
00529    // If one of the matrixes contains "NODATAVALUE", then THIS will be NODATAVALUE
00530    // Operator performed on m1 - / + / * / div m2
00531    virtual double subtractMatrix(MatrixDouble& m1, MatrixDouble& m2, int noData1 , int noData2);
00532    virtual double addMatrix(MatrixDouble& m1, MatrixDouble& m2, int noData1, int noData2);
00533    // Division by zero --> NODATAVAL
00534    virtual double divideMatrix(MatrixDouble& m1, MatrixDouble& m2, int noData1, int noData2);
00535    virtual double multMatrix(MatrixDouble& m1, MatrixDouble& m2, int noData1, int noData2);
00536 
00537 
00538    // Returns sum of one row
00539    virtual double sumRow(int);
00540    // Returns sum of one column
00541    virtual double sumCol(int);
00542 
00543    virtual double spaltensumme(int); // not used
00544    virtual double zeilensumme(int);  // not used
00545 
00546    //Arnold2006_84
00547    // Copies one row to another row
00548    virtual void copyRow(int originRow, int targetRow);
00549 
00550    // Copy originRow from THIS to target MatrixDouble (targetRow)
00551    virtual void copyRow(int originRow, MatrixDouble& mTarg, int targetRow);
00552 
00553    // Copy transposed: column <originCol> from THIS to row target MatrixDouble (targetRow)
00554    virtual void copyCol2Row(int originCol, MatrixDouble& mTarg, int targetRow);
00555    virtual void copyCol2Col(int originCol, MatrixDouble& mTarg, int targetCol);
00556 
00557    //Arnold2006_86
00558    // Functions return maximum value from
00559    // --- complete MatrixDouble
00560    virtual double getMax(void);
00561    // --- MatrixDouble  row specified
00562    virtual double getMax_row(int row);
00563    // --- MatrixDouble  column specified
00564    virtual double getMax_col(int col);
00565 
00566    // Functions position of maximum value from
00567    // --- complete MatrixDouble
00568    virtual int findMax_row(int row);
00569    // --- MatrixDouble  column specified
00570    virtual int findMax_col(int col);
00571    virtual int findMax_col_nonempty(int col, double emptVal, int emptCol);
00572    // Functions return maximum value from
00573    // --- complete MatrixDouble
00574 
00575 
00576 
00577    virtual double getMin(void);
00578    virtual double getMinNotNodata(int nodata);
00579    // --- MatrixDouble  row specified
00580    virtual double getMin_row(int row);
00581    virtual double getMin_row(int row, int nodata);
00582    // --- MatrixDouble  column specified
00583    virtual double getMin_col(int col);
00584 
00585 
00586    // Swaps the content of two pointers
00587    virtual void swap (double *pa,double *pb);
00588 
00589    // Function returns smaller MatrixDouble MEXTRACT with all rows
00590    // specified in ACTIVE
00591    virtual void mextract(MatrixDouble& ACTIVE, MatrixDouble& MEXTRACT);
00592 
00594    //    OTHER MATRIX OPERATIONS
00596    // findPos searches the MatrixDouble for "val" and writes the position
00597    // into FOUNDPOS (passed by reference)
00598    //
00599    // FINDPOS then has two columns: One for the row, one for the column of val.
00600    // Each row corresponds to one value.
00601    //
00602    // Function returns number of values (FOUNDPOS.rows())  or -1 (not found
00603    //
00604    // Example call:
00605    //    MatrixDouble m, pos;
00606    //    [m = ...]
00607    //    double val = -1;
00608    //    m.findPos(-1, pos);
00609    virtual int findPos(double val, MatrixDouble& FOUNDPOS);
00610    virtual int findPos_col(int col, double val, MatrixDouble& FOUNDPOS);
00611 
00612    // Finds all values that are not equal to 'noData', and writes those into FOUND
00613    // FOUND has Sparse Matrix notation
00614    virtual int findIsValue(double noData, MatrixDouble& FOUND);
00615 
00616         // Matrix returns position vector to all data that are NOT equal to the value 'val',
00617         // and also different to noData'
00618    virtual int findDifferent(double val, double noData, MatrixDouble& FOUNDPOS);
00619 
00620 
00621 
00622    // Function returns first row in which the value of col (getValue(?,col)==val
00623    // Then, returns row or -1 (not found)
00624    virtual int findfirstCol(int colSearch, double val); // (old)
00625    virtual int findfirstMatchInCol(int colSearch, double val); // (new)
00626    virtual int findfirstMatchInRow(int rowSearch, double val);
00627 
00628 
00629 
00630    // ?????????
00631    // Calculates median for all columns.
00632    //   - and assigns it to MatrixDouble passed by reference
00633    virtual void medianAllCols(MatrixDouble& medM);
00634    virtual double medianCol(int col);
00635    
00636    virtual double varianceOfCol(int col, double mean);
00637    virtual double standardDeviationOfCol(int _col, double mean);
00638    virtual double giniOfCol(int _col);
00639 
00640    virtual double getVariabceIfNotNodata(double nodata_, double mean_);
00641    virtual double getStandardDeviationIfNotNodata(double nodata_, double mean_);
00642    virtual double getMeanIfNotNodata(double nodata_);
00643 
00644 
00645    // Sorts rows in ascending order
00646    // Sorts ALL columns in ascending order
00647    virtual void sortColumns(void);
00648    // (historical, not supported any more)
00649    virtual void spalten_aufsteigend_sortieren (int z, int s)            ;
00650 
00651 // Sorts one column in ascending order
00652 // and connects all other columns according to this column 'col'
00653    virtual void sortAfterOneColumn(int col);
00654 
00655 
00656 // Sorts one column in ascending order
00657 // and connects all other columns according to this column 'col'
00658 // The order of the columns is retuzrned in the MatrixDouble 'matPos'
00659    virtual void sortAfterOneColumn(int col, MatrixDouble& matPos);
00660    //Arnold2006_200
00661    virtual void sortAfterOneColumn_B(int col, MatrixDouble& POSITION);   
00662 
00663 
00664    //Arnold - send complete MatrixDouble (both equal, renamed only)
00665    virtual void sendMatrixViaTDT(char* configFile);
00666    virtual void sendViaTDT(char* configFile);
00667    virtual void sendViaTDT(string configFile);
00668    //
00669    virtual void receiveViaTDT(char* configFile);
00670    virtual void receiveViaTDT(string configFile);
00671 
00672 #ifdef DO_TDT
00673    virtual void sendMatrixViaTDT_open(TDTConfig& tc, TDTState& ts);
00674    virtual void receiveViaTDT_open(TDTConfig& tc, TDTState& ts);
00675 
00676 #endif
00677 
00678    virtual void readWasimStatisticFile(string fn, int numGages, int numHeaderRows, bool withSum);
00679    virtual int getNumGages(string fn, int numHeaderRows);
00680    virtual int findDateRow(MatrixDouble& DateRow, int row);
00681   
00682    
00683 
00684 
00685    //Mast2006_05
00686    virtual void readFromTranslationMatrix(int z, int s, ifstream& in);
00687    virtual void readFromTranslationMatrix(ifstream& in);
00688    virtual void readFromTranslationMatrix(char* fn);
00689 
00690    virtual void printToScreenTranslationMatrix(int z, int s);
00691    virtual void printToScreenTranslationMatrix();
00692 
00694    // SEARCH FUNCTIONS
00696    // returns position in column
00697    //TODO: Rename getPosCol
00698    //TODO: inmplement getPosRow
00699    //TODO: inmplement MatrixDouble& getAllPos; MatrixDouble has two columns: r, c
00700    virtual int getPositionInColumn(double val, int col);
00701    virtual int getPositionInColumn(int val, int col);
00702 
00703    // ASSUME THAT MATRIX IS A VECTOR
00704    virtual int getPositionInColumn(int val);     // cast to double
00705    virtual int getPositionInColumn(double val);
00706 
00707    // CREATE HISTOGRAM
00708    // An empty MatrixDouble is passed (or, if not empty, it is re-initialized)
00709    // Then, all values that occur are written into the first column
00710    // The quantity of these values are written to the second column
00711    // TODO: ORDER BY SIZE
00712    //
00713    // EXAMPLE CALL:
00714         //    MatrixDouble matHist;
00715    //    // initialize with any values
00716         //    MatrixDouble gisMat; gisMat.readFromFile(filename);
00717         //    gisMat.makeHist(matHist);
00718         //    matHist.printToScreenInt();
00719 
00720    virtual void makeHist(MatrixDouble& histMat);
00721    virtual void makeHist(MatrixDouble& histMat, double first);
00722    // writes vector into the MatrixDouble uniqueM (passed by reference)
00723    virtual void unique(MatrixDouble& uniqueM);
00724    virtual void unique(int col, MatrixDouble& uniqueM);
00725 
00726    // Transposes THIS into m
00727    virtual void transpose(MatrixDouble& m);
00728 
00729    // Function to extract a number of columns from matOrig,
00730    // then reorder and write to matTarget.
00731    //
00732    // The vector transKey has dimensions
00733    //         transKey.length()==matTarget.cols();
00734    //         The maximum integer entry in transKey.max() <= matOrig.cols();
00735    //
00736    virtual void extractColumns(MatrixDouble& matTarget, MatrixDouble& transKey);
00737 
00738    // Function determines minimum row / col and maximum row / col
00739    // and writes it into MatrixDouble minmax
00740    //
00741    //  minmax  [ minRow,  maxRow ]
00742    //          [ minCol,  maxCol ]
00743    virtual void findMinMax(MatrixDouble& minmax, double nodata);
00744 
00745 
00746    // Filter function.
00747    // Of all values of vector <isTrue> that are FALSE,
00748    // find maximum value
00749    //
00750    // argument <isTrue> is vector of bools (MatrixDouble)
00751    //
00752    // Returns row index into THIS with maximum value that is FALSE in isTrue
00753    //
00754    virtual int findMaxNotTrue(int col, MatrixDouble& isTrue);
00755 
00756    // Returns MatrixDouble as string
00757    virtual string mat2string();
00758    virtual void string2mat(string s);
00759 
00760 
00761     // Developed from "TestGlobalSesitivity.cpp"
00762     virtual void copyToLargerMatrix(int row, int startCol,  MatrixDouble& fullVector);
00763     virtual void copyToLargerMatrix(int startCol, MatrixDouble& fullVector) ;
00764     virtual double sumVector();
00765     virtual void roundToInteger();
00766     
00767     virtual void writeErrorToLogfile(string fn, char* fehlertext, int type);
00768     
00769     
00770 };
00771 
00772 #ifdef DO_TDT
00773 
00774 void sendStringViaTDT_open(string s, TDTConfig& tc, TDTState& ts);
00775 void sendStringViaTDT(string s, char* configFile);
00776 
00777 string receiveStringViaTDT_open(TDTConfig& tc, TDTState& ts);
00778 string receiveStringViaTDT(char* configFile);
00779 
00780 
00781 #endif
00782 
00783 #endif
00784 
00785 
00786 
00787 
00788 

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