core/vnl/vnl_matlab_filewrite.h
Go to the documentation of this file.
00001 // This is core/vnl/vnl_matlab_filewrite.h
00002 #ifndef vnl_matlab_filewrite_h_
00003 #define vnl_matlab_filewrite_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 //  \file
00009 //  \author David Capel, Oxford RRG
00010 //  \date   17 August 1998
00011 //
00012 // \verbatim
00013 // Modifications
00014 // LSB (Manchester) 23/3/01  Tidied documentation
00015 //   Feb.2002 - Peter Vanroose - brief doxygen comment placed on single line
00016 // \endverbatim
00017 
00018 #include <vcl_string.h>
00019 #include <vcl_fstream.h>
00020 #include <vcl_complex.h>
00021 
00022 #include <vnl/vnl_vector.h>
00023 #include <vnl/vnl_matrix.h>
00024 
00025 //: Code to perform MATLAB binary file operations
00026 //    vnl_matlab_filewrite is a collection of I/O functions for reading/writing
00027 //    matrices in the compact MATLAB binary format (.mat)
00028 
00029 class vnl_matlab_filewrite
00030 {
00031  public:
00032   vnl_matlab_filewrite (char const* file_name, char const *basename = 0);
00033 
00034   //: Add scalar/vector/matrix variable to the MAT file using specified variable name.
00035   // If no name is given, variables will be generated by
00036   // appending 0,1,2 etc to the given basename.
00037   void write(double v, char const* variable_name = 0);
00038 
00039   void write(vnl_vector<double> const & v, char const* variable_name = 0);
00040   void write(vnl_vector<vcl_complex<double> > const & v, char const* variable_name = 0);
00041 
00042   void write(vnl_matrix<float> const & M, char const* variable_name = 0);
00043   void write(vnl_matrix<double> const & M, char const* variable_name = 0);
00044   void write(vnl_matrix<vcl_complex<float> > const & M, char const* variable_name = 0);
00045   void write(vnl_matrix<vcl_complex<double> > const & M, char const* variable_name = 0);
00046 
00047   void write(double const * const *M, int rows, int cols, char const* variable_name = 0);
00048 
00049  protected:
00050   vcl_string basename_;
00051   int variable_int_;
00052   vcl_fstream out_;
00053 
00054   vcl_string make_var_name(char const* variable_name);
00055 };
00056 
00057 #endif // vnl_matlab_filewrite_h_