Homepage Demos Overview Downloads Tutorials Reference
Credits

newmat9.cpp

Go to the documentation of this file.
00001 //$$ newmat9.cpp         Input and output
00002 
00003 // Copyright (C) 1991,2,3,4: R B Davies
00004 
00005 
00006 #ifndef WANT_STREAM
00007 #define WANT_STREAM
00008 #endif
00009 
00010 #include "include.h"
00011 
00012 #include "newmat.h"
00013 #include "newmatio.h"
00014 #include "newmatrc.h"
00015 #include <iomanip>
00016 
00017 #ifdef use_namespace
00018 namespace NEWMAT {
00019 #endif
00020 
00021 
00022 
00023 #ifdef DO_REPORT
00024 #define REPORT { static ExeCounter ExeCount(__LINE__,9); ++ExeCount; }
00025 #else
00026 #define REPORT {}
00027 #endif
00028 
00029 // for G++ 3.01
00030 #ifndef ios_format_flags
00031 #define ios_format_flags long
00032 #endif
00033 
00034 ostream& operator<<(ostream& s, const BaseMatrix& X)
00035 {
00036    GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate(); operator<<(s, *gm);
00037    gm->tDelete(); return s;
00038 }
00039 
00040 
00041 ostream& operator<<(ostream& s, const GeneralMatrix& X)
00042 {
00043    MatrixRow mr(const_cast<GeneralMatrix*>(&X), LoadOnEntry);
00044    int w = s.width();  int nr = X.Nrows();  ios_format_flags f = s.flags();
00045    s.setf(ios::fixed, ios::floatfield);
00046    for (int i=1; i<=nr; i++)
00047    {
00048       int skip = mr.skip;  int storage = mr.storage;
00049       Real* store = mr.data;  skip *= w+1;
00050       while (skip--) s << " ";
00051       while (storage--) { s.width(w); s << *store++ << " "; }
00052 //      while (storage--) s << setw(w) << *store++ << " ";
00053       mr.Next();  s << "\n";
00054    }
00055    s << flush;  s.flags(f); return s;
00056 }
00057 
00058 ostream& operator<<(ostream& s, const printmat& p) {
00059   const int printwidth = s.width();
00060   s.width(0);
00061   s << "[";
00062   for (int i = 1; i <= p.mat.Nrows(); i++) {
00063     if (i > 1) s << "; ";
00064     for (int j = 1; j <= p.mat.Ncols(); j++) {
00065       if ( j > 1 ) s << ", ";
00066       s << setw(printwidth) << p.mat(i,j);
00067     }
00068   }
00069   s << "]";
00070   return s;
00071 }
00072 
00073 
00074 // include this stuff if you are using an old version of G++
00075 // with an incomplete io library
00076 
00077 /*
00078 
00079 ostream& operator<<(ostream& os, Omanip_precision i)
00080    { os.precision(i.x); return os; }
00081 
00082 Omanip_precision setprecision(int i) { return Omanip_precision(i); }
00083 
00084 ostream& operator<<(ostream& os, Omanip_width i)
00085    { os.width(i.x); return os; }
00086 
00087 Omanip_width setw(int i) { return Omanip_width(i); }
00088 
00089 */
00090 
00091 #ifdef use_namespace
00092 }
00093 #endif
00094 
00095 

newmat11b
Generated Tue Aug 16 16:32:01 2005 by Doxygen 1.4.4