SWE
/import/home/rettenbs/src/SWE/src/tools/help.hh
Go to the documentation of this file.
00001 
00029 #ifndef __HELP_HH
00030 #define __HELP_HH
00031 
00032 #include <cstring>
00033 #include <iostream>
00034 #include <fstream>
00035 #include <sstream>
00036 
00048 class Float1D
00049 {
00050   public:
00051         Float1D(float* _elem, int _rows, int _stride = 1) 
00052         : rows(_rows),stride(_stride),elem(_elem)
00053         {
00054         }
00055 
00056         ~Float1D()
00057         {
00058         }
00059 
00060         inline float& operator[](int i) { 
00061                 return elem[i*stride]; 
00062         }
00063 
00064         inline const float& operator[](int i) const {
00065                 return elem[i*stride]; 
00066         }
00067 
00068         inline float* elemVector() {
00069                 return elem;
00070         }
00071 
00072         inline int getSize() const { return rows; }; 
00073 
00074   private:
00075     int rows;
00076     int stride;
00077     float* elem;
00078 };
00079 
00088 class Float2D
00089 {
00090 public:
00096         Float2D(int _cols, int _rows) : rows(_rows),cols(_cols)
00097         {
00098                 elem = new float[rows*cols];
00099                 for (int i = 0; i < rows*cols; i++)
00100                         elem[i] = 0;
00101         }
00102 
00103         ~Float2D()
00104         {
00105                 delete[] elem;
00106         }
00107 
00108         inline float* operator[](int i) { 
00109                 return (elem + (rows * i)); 
00110         }
00111 
00112         inline float const* operator[](int i) const {
00113                 return (elem + (rows * i)); 
00114         }
00115 
00116         inline float* elemVector() {
00117                 return elem;
00118         }
00119 
00120         inline int getRows() const { return rows; }; 
00121         inline int getCols() const { return cols; }; 
00122 
00123         inline Float1D getColProxy(int i) {
00124                 // subarray elem[i][*]:
00125                 // starting at elem[i][0] with rows elements and unit stride
00126                 return Float1D(elem + (rows * i), rows);
00127         };
00128         
00129         inline Float1D getRowProxy(int j) {
00130                 // subarray elem[*][j]
00131                 // starting at elem[0][j] with cols elements and stride rows
00132                 return Float1D(elem + j, cols, rows);
00133         };
00134 
00135   private:
00136     int rows;
00137     int cols;
00138     float* elem; 
00139 };
00140 
00141 //-------- Methods for Visualistion of Results --------
00142 
00150 inline std::string generateFileName(std::string baseName, int timeStep) {
00151 
00152         std::ostringstream FileName;
00153         FileName << baseName <<timeStep<<".vtk";
00154         return FileName.str();
00155 };
00156 
00168 inline std::string generateFileName( std::string i_baseName,
00169                                      int i_blockPositionX, int i_blockPositionY,
00170                                      std::string i_fileExtension=".nc" ) {
00171 
00172   std::ostringstream l_fileName;
00173 
00174   l_fileName << i_baseName << "_" << i_blockPositionX << i_blockPositionY << i_fileExtension;
00175   return l_fileName.str();
00176 };
00177 
00186 inline std::string generateFileName(std::string baseName, int timeStep, int block_X, int block_Y, std::string i_fileExtension=".vts") {
00187 
00188         std::ostringstream FileName;
00189         FileName << baseName <<"_"<< block_X<<"_"<<block_Y<<"_"<<timeStep<<i_fileExtension;
00190         return FileName.str();
00191 };
00192 
00202 inline
00203 std::string generateBaseFileName(std::string &i_baseName, int i_blockPositionX , int i_blockPositionY)
00204 {
00205           std::ostringstream l_fileName;
00206 
00207           l_fileName << i_baseName << "_" << i_blockPositionX << i_blockPositionY;
00208           return l_fileName.str();
00209 }
00210 
00215 inline std::string generateContainerFileName(std::string baseName, int timeStep) {
00216 
00217         std::ostringstream FileName;
00218         FileName << baseName<<"_"<<timeStep<<".pvts";
00219         return FileName.str();
00220 };
00221 
00222 
00223 #endif
00224 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends