From 57b9665af69f3b83e1fadbd7914136f3fa90f4eb Mon Sep 17 00:00:00 2001
From: Jesper Andersson <jesper@fmrib.ox.ac.uk>
Date: Tue, 11 Mar 2008 17:33:33 +0000
Subject: [PATCH] Changed .Print() function for SparseBFMatrix to use  row col
 val  format

---
 bfmatrix.cpp | 29 +++++++----------------------
 bfmatrix.h   |  6 +++---
 2 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/bfmatrix.cpp b/bfmatrix.cpp
index 85a8408..68ea5d9 100644
--- a/bfmatrix.cpp
+++ b/bfmatrix.cpp
@@ -12,32 +12,11 @@
 #include <boost/shared_ptr.hpp>
 #include "newmat.h"
 #include "newmatio.h"
+#include "miscmaths/miscmaths.h"
 #include "bfmatrix.h"
 
 namespace MISCMATHS {
 
-//
-// Member functions for BFMatrix
-//
-
-void BFMatrix::print(const NEWMAT::Matrix&  m,
-                     const std::string&     fname) const
-{
-  if (!fname.length()) {
-    cout << endl << m << endl;
-  }
-  else {
-    try {
-      ofstream  fout(fname.c_str());
-      fout << setprecision(10) << m;
-    }
-    catch(...) {
-      std::string  errmsg("BFMatrix::print: Failed to write to file " + fname);
-      throw BFMatrixException(errmsg);
-    }
-  }
-}
-
 //
 // Member functions for SparseBFMatrix
 //
@@ -252,6 +231,12 @@ NEWMAT::ReturnMatrix SparseBFMatrix::SolveForx(const NEWMAT::ColumnVector& b,
 // Member functions for FullBFMatrix
 //
 
+void FullBFMatrix::Print(const std::string fname) const
+{
+  if (!fname.length()) cout << endl << *mp << endl;
+  else write_ascii_matrix(fname,*mp);
+}
+
 boost::shared_ptr<BFMatrix> FullBFMatrix::Transpose() 
 const
 {
diff --git a/bfmatrix.h b/bfmatrix.h
index 847701d..a6032a7 100644
--- a/bfmatrix.h
+++ b/bfmatrix.h
@@ -52,7 +52,7 @@ public:
 class BFMatrix
 {
 protected:
-virtual void print(const NEWMAT::Matrix& m, const std::string& fname) const;
+
 public:
   // Constructors, destructors and stuff
   BFMatrix() {}
@@ -144,7 +144,7 @@ public:
   virtual unsigned int Ncols() const {return(mp->Ncols());}
 
   // Print matrix (for debugging)
-  virtual void Print(const std::string fname=std::string("")) const {print(mp->AsNEWMAT(),fname);}
+  virtual void Print(const std::string fname=std::string("")) const {mp->Print(fname);}
 
   // Setting, deleting or resizing the whole sparse matrix.
   virtual void SetMatrix(const MISCMATHS::SpMat<double>& M) {mp = boost::shared_ptr<MISCMATHS::SpMat<double> >(new MISCMATHS::SpMat<double>(M));}
@@ -217,7 +217,7 @@ public:
   virtual unsigned int Ncols() const {return(mp->Ncols());}
 
   // Print matrix (for debugging)
-  virtual void Print(const std::string fname=std::string("")) const {print(*mp,fname);}
+  virtual void Print(const std::string fname=std::string("")) const;
 
   // Setting, deleting or resizing the whole matrix.
   virtual void SetMatrix(const MISCMATHS::SpMat<double>& M) {mp = boost::shared_ptr<NEWMAT::Matrix>(new NEWMAT::Matrix(M.AsNEWMAT()));} 
-- 
GitLab