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

matfile/matfile_concepts/src/Writers/ArrayDenseWrapper.hh
Go to the documentation of this file.
00001 /*
00002     This file is part of matfile.
00003 
00004     Copyright (C) 2010-2011 Andrea Arteaga <arteagaa@student.ethz.ch>
00005 
00006     matfile is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published
00008     by the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     matfile is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public License
00017     along with matfile.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #ifndef ARRAYDENSEWRAPPERWRITER_hh_
00021 #define ARRAYDENSEWRAPPERWRITER_hh_
00022 
00023 template<class WrapperClass> class Writer<WrapperClass, ArrayDenseWrapper>
00024 {
00025 public:
00026   static void write(std::ostream& out, const std::string& name, const WrapperClass& wrapper)
00027   {
00028     int beginpos = out.tellp();
00029 
00030     // Parameters
00031       bool isComplex = wrapper.isComplex();
00032       miINT32_t rows, cols;
00033       wrapper.size(rows, cols);
00034       const MATtype realType = wrapper.realType();
00035       const MATtype imagType = wrapper.imagType();
00036       const miINT32_t realScalarSize = typeSize(realType);
00037       const miINT32_t imagScalarSize = typeSize(imagType);
00038        
00039     // Write tag
00040     miINT32_t tag[2];
00041     tag[0] = miMATRIX;
00042     tag[1] = 0;
00043     out.write(reinterpret_cast<char*>(tag), 8);
00044 
00045     // Write flags
00046     miINT32_t flagstag[2];
00047     flagstag[0] = miUINT32;
00048     flagstag[1] = 8;
00049     miUINT32_t flags[2];
00050     flags[0] = mxDOUBLE_CLASS;
00051     flags[0] += 2048 * isComplex;
00052     out.write(reinterpret_cast<char*>(flagstag), 8).write(reinterpret_cast<char*>(flags), 8);
00053 
00054     // Write dimensions
00055     miINT32_t dimensions[4];
00056     dimensions[0] = miINT32;
00057     dimensions[1] = 8;
00058     dimensions[2] = rows;
00059     dimensions[3] = cols;
00060     out.write(reinterpret_cast<char*>(dimensions), 16);
00061 
00062     // Write name
00063     miINT32_t nametag[2];
00064     nametag[0] = miINT8;
00065     nametag[1] = name.size();
00066     out.write(reinterpret_cast<char*>(nametag), 8).write(name.data(), name.size());
00067     for (miINT32_t i = name.size(); i % 8 != 0; ++i)
00068       out.put(' ');
00069         
00070 
00071     // Write real part
00072     
00073     
00074     miINT32_t realtag[2];
00075     realtag[0] = wrapper.realType();
00076     realtag[1] = realScalarSize * rows * cols;
00077     out.write(reinterpret_cast<char*>(realtag), 8);
00078     
00079     //Einen Versuch ist es Wert.
00080         for (miINT32_t c = 0; c < cols; ++c)
00081           for (miINT32_t r = 0; r < rows; ++r){
00082           out.write(reinterpret_cast<const char*>(wrapper.realData(r,c)), realScalarSize);
00083         } 
00084     //.. endet der Versuch hier
00085     
00086     //out.write(wrapper.realData(), realtag[1]);
00087     for (miINT32_t i = realtag[1]; i % 8 != 0; ++i)
00088       out.put(' ');
00089     
00090 
00091     // Write imaginary part
00092     if (isComplex) {
00093       miINT32_t imagtag[2];
00094       imagtag[0] = wrapper.imagType();
00095       imagtag[1] = imagScalarSize * rows*cols;
00096       out.write(reinterpret_cast<char*>(imagtag), 8);
00097       //
00098       for (miINT32_t c = 0; c < cols; ++c)
00099         for (miINT32_t r = 0; r < rows; ++r){
00100           out.write(reinterpret_cast<const char*>((wrapper.complexData(r,c))) , realScalarSize);
00101         } 
00102       
00103        //.. endet der Versuch hier
00104        
00105        
00106             
00107       //out.write(wrapper.imagData(), imagtag[1]);
00108       for (miINT32_t i = imagtag[1]; i % 8 != 0; ++i)
00109         out.put(' ');
00110     }
00111     
00112     
00113     // Seek back and write size
00114     int endpos = out.tellp();
00115     out.seekp(beginpos+4);
00116     miINT32_t size = endpos-beginpos-8;
00117     out.write(reinterpret_cast<char*>(&size), 4);
00118     out.seekp(endpos);
00119     
00120 
00121   }
00122 };
00123 
00124 #endif /* ARRAYDENSEWRAPPERWRITER_HH_ */

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