acado_mat_file.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00033 #include <acado/matrix_vector/acado_mat_file.hpp>
00034 
00035 BEGIN_NAMESPACE_ACADO
00036 
00037 template<typename T>
00038 void MatFile< T >::write(       std::ostream& stream,
00039                                                 const GenericMatrix< T >& mat,
00040                                                 const char* name
00041                                                 )
00042 {
00043         Fmatrix x;
00044         double tmp;
00045         
00046         x.type = 0000;  // IEEE Little Endian - reserved - double precision (64 bits) - numeric full matrix
00047         x.mrows = mat.getNumRows();  // number of rows
00048         x.ncols = mat.getNumCols();  // number of columns
00049         x.imagf = 0;  // no imaginary part
00050         x.namelen = 1+strlen(name); // matrix name length 
00051         
00052         stream.write( (char*) &x, sizeof(Fmatrix));
00053         stream.write(name, x.namelen);
00054         
00055         // mat files store data in column-major format
00056         for (uint col = 0; col < mat.getNumCols(); ++col)
00057         {
00058                 for (uint row = 0; row < mat.getNumRows(); ++row)
00059                 {
00060                         tmp = mat(row, col);
00061                         stream.write((char*) &tmp, sizeof(double));
00062                 }
00063         }
00064         
00065         // imaginary numbers should be stored just after the real ones
00066 }
00067 
00068 template<typename T>
00069 void MatFile< T >::write(       std::ostream& stream,
00070                                                 const GenericVector< T >& vec,
00071                                                 const char* name
00072                                                 )
00073 {
00074         Fmatrix x;
00075         double tmp;
00076         
00077         x.type = 0000;  // IEEE Big Endian - reserved - double precision (64 bits) - numeric full matrix
00078         x.mrows = vec.getDim();  // number of rows
00079         x.ncols = 1;  // number of columns
00080         x.imagf = 0;  // no imaginary part
00081         x.namelen = 1+strlen(name); // matrix name length 
00082         
00083         stream.write( (char*) &x, sizeof(Fmatrix));
00084         stream.write(name, x.namelen);
00085         
00086         // mat files store data in column-major format
00087         for (uint row=0; row<vec.getDim(); ++row)
00088         {
00089                 tmp = vec( row );
00090                 stream.write((char*) &tmp, sizeof(double));
00091         }
00092         
00093         // imaginary numbers should be stored just after the real ones
00094 }
00095 
00096 //
00097 // Explicit instantiations of templates.
00098 //
00099 template class MatFile< double >;
00100 template class MatFile< int >;
00101 template class MatFile< bool >;
00102 
00103 CLOSE_NAMESPACE_ACADO


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:36:41