HDF5Serie

Project Page
/home/user/MBSimWindows/hdf5serie/hdf5serie/hdf5serie/matrixserie.h
00001 /* Copyright (C) 2009 Markus Friedrich
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact:
00018  *   friedrich.at.gc@googlemail.com
00019  *
00020  */
00021 
00022 #ifndef _HDF5SERIE_MATRIXSERIE_H_
00023 #define _HDF5SERIE_MATRIXSERIE_H_
00024 
00025 #include <H5Cpp.h>
00026 #include <vector>
00027 #include <string>
00028 #include <assert.h>
00029 #include <hdf5serie/simpleattribute.h>
00030 #include <hdf5serie/fileserie.h>
00031 
00032 namespace H5 {
00033 
00034 
00035    
00066   template<class T>
00067   class MatrixSerie : public DataSet {
00068     private:
00069       DataType memDataType;
00070       DataSpace memDataSpace;
00071       hsize_t dims[3];
00072     public:
00077       MatrixSerie();
00078 
00080       MatrixSerie(const MatrixSerie<T>& dataset);
00081 
00086       MatrixSerie(const CommonFG& parent, const std::string& name);
00087 
00092       MatrixSerie(const CommonFG& parent, const std::string& name, const int rows, const int cols, int compression=FileSerie::getDefaultCompression(), int chunkSize=FileSerie::getDefaultChunkSize());
00093 
00100       void create(const CommonFG& parent, const std::string& name, const int rows, const int cols, int compression=FileSerie::getDefaultCompression(), int chunksize=FileSerie::getDefaultChunkSize());
00101 
00106       void open(const CommonFG& parent, const std::string& name);
00107 
00112       void setDescription(const std::string& desc);
00113 
00119       void append(const std::vector<std::vector<T> > &matrix);
00120 
00122       inline unsigned int getNumberOfMatrices();
00123 
00125       inline unsigned int getRows();
00126 
00128       inline unsigned int getColumns();
00129 
00134       std::vector<std::vector<T> > getMatrix(const int number);
00135 
00140       std::string getDescription();
00141 
00142       void extend(const hsize_t* size);
00143   };
00144 
00145 
00146 
00147   // inline definitions
00148 
00149   template<class T>
00150   unsigned int MatrixSerie<T>::getNumberOfMatrices() {
00151     return dims[0];
00152   }
00153 
00154   template<class T>
00155   unsigned int MatrixSerie<T>::getRows() {
00156     // get current dims from dataspace (maybe another (single-)writer process has increased the number of rows)
00157     DataSpace fileDataSpace=getSpace();
00158     fileDataSpace.getSimpleExtentDims(dims);
00159     // return current value
00160     return dims[1];
00161   }
00162 
00163   template<class T>
00164   unsigned int MatrixSerie<T>::getColumns() {
00165     return dims[2];
00166   }
00167 
00168 }
00169 
00170 #endif