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

matfile/matfile_concepts/src/Writers/ArraySparseWrapper.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 ARRAYSPARSEWRAPPERWRITER_HPP_
00021 #define ARRAYSPARSEWRAPPERWRITER_HPP_
00022 
00023 template<class WrapperClass> class Writer<WrapperClass, ArraySparseWrapper>
00024 {
00025 public:
00026 
00027   static void write(std::ostream& out, const std::string& name, const WrapperClass& wrapper)
00028   {
00029     
00030    
00031     int beginpos = out.tellp();
00032   
00033     // Parameter werden gelesen
00034       bool isComplex = wrapper.isComplex();
00035       miINT32_t nnz = wrapper.nnz();
00036       miINT32_t rows, cols;
00037       wrapper.size(rows, cols);
00038       const MATtype realType = wrapper.realType();
00039       const MATtype imagType = wrapper.imagType();
00040       const miINT32_t realScalarSize = typeSize(realType);
00041       const miINT32_t imagScalarSize = typeSize(imagType);
00042      
00043 
00044     // Write tag
00045     miINT32_t tag[2];
00046     tag[0] = miMATRIX;
00047     tag[1] = 0;
00048     out.write(reinterpret_cast<char*>(tag), 8);
00049   
00050 
00051     // Write flags
00052     miINT32_t flagstag[2];
00053     flagstag[0] = miUINT32;
00054     flagstag[1] = 8;
00055     miUINT32_t flags[2];
00056     flags[0] = mxSPARSE_CLASS;
00057     flags[0] += 2048 * isComplex;
00058     flags[1] = nnz;
00059     out.write(reinterpret_cast<char*>(flagstag), 8).write(reinterpret_cast<char*>(flags), 8);
00060 
00061 
00062     // Write dimensions
00063     miINT32_t dimensions[4];
00064     dimensions[0] = miINT32;
00065     dimensions[1] = 8;
00066     dimensions[2] = rows;
00067     dimensions[3] = cols;
00068     out.write(reinterpret_cast<char*>(dimensions), 16);
00069 
00070 
00071     // Write name
00072     miINT32_t nametag[2];
00073     nametag[0] = miINT8;
00074     nametag[1] = name.size();
00075     out.write(reinterpret_cast<char*>(nametag), 8).write(name.data(), name.size());
00076     for (miINT32_t i = name.size(); i % 8 != 0; ++i)
00077       out.put(' ');
00078 
00079   
00080     // Write ir
00081     miINT32_t irtag[2];
00082     irtag[0] = miINT32;
00083     irtag[1] = 4*nnz;
00084     out.write(reinterpret_cast<char*>(irtag), 8).write(wrapper.ir(), irtag[1]);
00085     if (irtag[1] % 8 != 0)
00086       out.write("    ", 4);
00087 
00088     // Write jc
00089     miINT32_t jctag[2];
00090     jctag[0] = miINT32;
00091     jctag[1] = 4*(cols+1);
00092     out.write(reinterpret_cast<char*>(jctag), 8).write(wrapper.jc(), jctag[1]);
00093     if (jctag[1] % 8 != 0)
00094       out.write("    ", 4);
00095 
00096     // Write pr
00097     miINT32_t prtag[2];
00098     prtag[0] = realType;
00099     prtag[1] = nnz * realScalarSize;
00100     out.write(reinterpret_cast<char*>(prtag), 8).write(wrapper.pr(), prtag[1]);
00101     for (miINT32_t i = prtag[1]; i % 8 != 0; ++i)
00102       out.put(' ');
00103 
00104     // Write pi
00105     if (isComplex) {
00106       miINT32_t pitag[2];
00107       pitag[0] = imagType;
00108       pitag[1] = nnz * imagScalarSize;
00109       out.write(reinterpret_cast<char*>(pitag), 8).write(wrapper.pi(), pitag[1]);
00110       for (miINT32_t i = pitag[1]; i % 8 != 0; ++i)
00111         out.put(' ');
00112     }
00113 
00114     // Seek back and write size
00115     int endpos = out.tellp();
00116     out.seekp(beginpos+4);
00117     miINT32_t size = endpos-beginpos-8;
00118     out.write(reinterpret_cast<char*>(&size), 4);
00119     out.seekp(endpos);
00120     
00121   }
00122 };
00123 
00124 #endif /* ARRAYSPARSEWRAPPERWRITER_HPP_ */

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