Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00040 miINT32_t tag[2];
00041 tag[0] = miMATRIX;
00042 tag[1] = 0;
00043 out.write(reinterpret_cast<char*>(tag), 8);
00044
00045
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
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
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
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
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
00085
00086
00087 for (miINT32_t i = realtag[1]; i % 8 != 0; ++i)
00088 out.put(' ');
00089
00090
00091
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
00104
00105
00106
00107
00108 for (miINT32_t i = imagtag[1]; i % 8 != 0; ++i)
00109 out.put(' ');
00110 }
00111
00112
00113
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