Newer
Older
/* Log.h
Mark Woolrich, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */
/* CCOPYRIGHT */
#include "newmat/newmatap.h"
#include "newmat/newmatio.h"
using namespace NEWMAT;
namespace UTILS{
#if !defined(__Log_h)
#define __Log_h
class Log
{
public:
static Log& getInstance();
~Log() { delete logger; }
void establishDir(const string& name);
void setDir(const string& name);
void setLogFile(const string& name) {logfilename = name;}
const string& getDir() const { return dir; }
void out(const string& p_fname, const Matrix& p_mat, bool p_addMatrixString = true);
void out(const string& p_fname, const RowVector& p_mat);
void out(const string& p_fname, const ColumnVector& p_mat);
ofstream& str() { return logfileout; }
private:
Log() {}
const Log& operator=(Log&);
Log(Log&);
static Log* logger;
string dir;
ofstream logfileout;
string logfilename;
};
inline void Log::out(const string& p_fname, const Matrix& p_mat, bool p_addMatrixString)
{
ofstream out;
out.open((dir + "/" + p_fname).c_str(), ios::out);
out.setf(ios::scientific, ios::floatfield);
if(p_addMatrixString)
out << "/Matrix" << endl;
for(int i=1; i<=p_mat.Nrows(); i++)
{
for(int j=1; j<=p_mat.Ncols(); j++)
{
out << p_mat(i,j) << " ";
}
out << endl;
}
out.close();
}
inline void Log::out(const string& p_fname, const ColumnVector& p_mat)
{
ofstream out;
out.open((dir + "/" + p_fname).c_str(), ios::out);
out.setf(ios::scientific, ios::floatfield);
for(int j=1; j<=p_mat.Nrows(); j++)
{
out << p_mat(j);
out << endl;
}
out.close();
}
inline void Log::out(const string& p_fname, const RowVector& p_mat)
{
ofstream out;
out.open((dir + "/" + p_fname).c_str(), ios::out);
out.setf(ios::scientific, ios::floatfield);
for(int j=1; j<=p_mat.Ncols(); j++)
{
out << p_mat(j) << " ";
}
out << endl;