Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

matfile/matfileOutput.hh
Go to the documentation of this file.
00001 #ifndef matfileoutput_hh
00002 #define matfileoutput_hh
00003 
00004 /*Matfile includes*/
00005 #include "matfile_concepts/Output"
00006 /*concepts includes*/
00007 #include "basics.hh"
00008 #include "sparseOWrapper.hh"
00009 #include "denseOWrapper.hh"
00010 #include "operator.hh"
00011 
00012 #define Matfile_ending_test 0
00013 using namespace matfile;
00014 
00015 namespace concepts {
00016 
00027 class MatfileOutput {
00028 
00036 public:
00037 
00041   MatfileOutput() {
00042     _odevice = 0;
00043   }
00044 
00051   MatfileOutput(const std::string str) {
00052     //  DEBUGL(1,matfileEnding(str.c_str()));
00053     _odevice = new matfile::OutputDevice(matfileEnding(str.c_str()));
00054   }
00055 
00059   virtual ~MatfileOutput() {
00060     if (_odevice != 0)
00061       _odevice->close();
00062     delete (_odevice);
00063   }
00064 
00070   void openMatfile(const std::string str) {
00071     if (_odevice != 0)
00072       delete (_odevice);
00073     _odevice = new OutputDevice(matfileEnding(str.c_str()));
00074   }
00075 
00079   void closeMatfile() {
00080     delete (_odevice);
00081     _odevice = 0;
00082   }
00083 
00091   template<class T>
00092   void addSparse(concepts::SparseMatrix<T> *sparse, const std::string str) {
00093     if (_odevice == 0)
00094       _odevice = new OutputDevice(matfileEnding(str.c_str()));
00095 
00096     SparseOWrapper wrapper(*sparse);
00097 //    if (wrapper.nnz() == 0) {
00098 //      DenseMatrix<Real> zeroMat = 0;
00099 //    } else
00100       _odevice->writeArray(str.c_str(), wrapper);
00101   }
00102 
00109   template<class T>
00110   void addDense(concepts::DenseMatrix<T> *dense, const std::string str) {
00111     if (_odevice == 0)
00112       _odevice = new OutputDevice(matfileEnding(str.c_str()));
00113 
00114     DenseOWrapper wrapper(*dense);
00115     _odevice->writeArray(str.c_str(), wrapper);
00116   }
00117 
00118 private:
00119 
00123   std::string matfileEnding(const std::string& filename) {
00124     uint size = filename.size();
00125     if (size < 4 || std::string(filename, size - 4, 4) != ".mat")
00126       return (filename + ".mat");
00127     return filename;
00128   }
00129 
00133   matfile::OutputDevice *_odevice;
00134 
00135 };/*class_end*/
00136 }/*namespace_concepts_end*/
00137 #endif 

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)