13 #ifndef OCRA_UTIL_FILE_OPERATIONS_H 14 #define OCRA_UTIL_FILE_OPERATIONS_H 26 template <
class Derived>
27 inline void writeInFile(
const MatrixBase<Derived>& m,
const std::string& fileName,
bool app=
false)
32 aof.open(fileName.c_str(), std::ios_base::app);
36 aof.open(fileName.c_str());
41 aof << m << std::endl;
43 aof << m.transpose() << std::endl;
49 template<
class Derived>
50 inline std::ostream&
writeInFile(std::ostream & s,
const MatrixBase<Derived>& m,
int precision = -1,
const std::string& coeffSeparator =
" ",
51 const std::string& rowSeparator =
"\n",
const std::string& rowPrefix=
"",
const std::string& rowSuffix=
"",
52 const std::string& matPrefix=
"",
const std::string& matSuffix=
"")
54 std::string rowSpacer =
"";
55 int i = int(matSuffix.length())-1;
56 while (i>=0 && matSuffix[i]!=
'\n')
62 std::streamsize old_precision = 0;
63 if(precision > 0) old_precision = s.precision(precision);
65 for(
int i = 0; i < (int)m.get_nrows(); ++i)
71 for(
int j = 1; j < (int)m.get_ncols(); ++j)
77 if( i <(
int) m.get_nrows() - 1)
81 if(precision>0) s.precision(old_precision);
87 template<
class Derived>
88 inline std::ostream&
writeInFile(std::ostream & s,
const MatrixBase<Derived>& v,
int precision = -1,
const std::string& coeffSeparator =
" ",
89 const std::string& vectPrefix=
"",
const std::string& vectSuffix=
"")
91 assert(v.rows() == 1 || v.cols() == 1);
92 std::streamsize old_precision = 0;
93 if(precision > 0) old_precision = s.precision(precision);
96 for(
int j = 1; j < (int)v.getSize(); ++j)
102 if(precision>0) s.precision(old_precision);
106 template<
class Derived>
109 if (m.rows() == 1 || m.cols() == 1)
110 return writeInFile(s, m, precision,
", ",
"[",
"];");
112 return writeInFile(s, m, precision,
", ",
";\n",
"[",
"]",
"[",
"];");
119 #endif //OCRA_UTIL_FILE_OPERATIONS_H void writeInFile(const MatrixBase< Derived > &m, const std::string &fileName, bool app=false)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
std::ostream & writeInFileForScilab(std::ostream &s, const MatrixBase< Derived > &m, int precision=-1)
Declaration file of the OptimizationVariable class.