Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008 #include "vnl_matlab_filewrite.h"
00009
00010 #include <vcl_sstream.h>
00011 #include <vcl_iostream.h>
00012 #include <vcl_complex.h>
00013
00014 #include <vnl/vnl_vector.h>
00015 #include <vnl/vnl_matrix.h>
00016 #include <vnl/vnl_matlab_write.h>
00017
00018 vnl_matlab_filewrite::vnl_matlab_filewrite(char const *file_name,
00019 char const *basename)
00020 : basename_(basename ? basename : "targetvar"), variable_int_(0)
00021 {
00022 out_.open(file_name, vcl_ios_out | vcl_ios_binary);
00023 if (out_.bad())
00024 vcl_cerr << __FILE__ << ':' << __LINE__ << ", WARNING : output stream is bad\n";
00025 }
00026
00027 vcl_string vnl_matlab_filewrite::make_var_name(char const* variable_name)
00028 {
00029 if (variable_name)
00030 return vcl_string(variable_name);
00031 else {
00032 vcl_stringstream ss;
00033 ss << variable_int_++;
00034 return basename_ + ss.str();
00035 }
00036 }
00037
00038
00039
00040
00041 void vnl_matlab_filewrite::write(double v, char const* variable_name)
00042 {
00043 vnl_matlab_write(out_, v, make_var_name(variable_name).c_str());
00044 }
00045
00046
00047 void vnl_matlab_filewrite::write(vnl_vector<double> const& v, char const* variable_name)
00048 {
00049 vnl_matlab_write(out_, v.data_block(), v.size(), make_var_name(variable_name).c_str());
00050 }
00051
00052 void vnl_matlab_filewrite::write(vnl_vector<vcl_complex<double> > const& v, char const* variable_name)
00053 {
00054 vnl_matlab_write(out_, v.data_block(), v.size(), make_var_name(variable_name).c_str());
00055 }
00056
00057
00058 void vnl_matlab_filewrite::write(vnl_matrix<float> const& M, char const* variable_name)
00059 {
00060 vnl_matlab_write(out_, M.data_array(), M.rows(), M.cols(), make_var_name(variable_name).c_str());
00061 }
00062
00063 void vnl_matlab_filewrite::write(vnl_matrix<double> const& M, char const* variable_name)
00064 {
00065 vnl_matlab_write(out_, M.data_array(), M.rows(), M.cols(), make_var_name(variable_name).c_str());
00066 }
00067
00068 void vnl_matlab_filewrite::write(vnl_matrix<vcl_complex<float> > const& M, char const* variable_name)
00069 {
00070 vnl_matlab_write(out_, M.data_array(), M.rows(), M.cols(), make_var_name(variable_name).c_str());
00071 }
00072
00073 void vnl_matlab_filewrite::write(vnl_matrix<vcl_complex<double> > const& M, char const* variable_name)
00074 {
00075 vnl_matlab_write(out_, M.data_array(), M.rows(), M.cols(), make_var_name(variable_name).c_str());
00076 }
00077
00078 void vnl_matlab_filewrite::write(double const * const *M, int rows, int cols, char const* variable_name)
00079 {
00080 vnl_matlab_write(out_, M, rows, cols, make_var_name(variable_name).c_str());
00081 }