MathTL
io/matrix_io.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner                                     |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_MATRIX_IO_H
00011 #define _MATHTL_MATRIX_IO_H
00012 
00013 #include <iostream>
00014 #include <iomanip>
00015 
00016 namespace MathTL
00017 {
00018   /*
00019     generic input/output routines for MATRIX classes with a standard
00020     signature
00021     We use the row_dimension() and column_dimension() routines
00022     for determining the dimensions of the matrix.
00023   */
00024   
00029   template <class MATRIX>
00030   void print_matrix(const MATRIX& M, std::ostream& os)
00031   {
00032     os << "[";
00033     unsigned int precision=15, tabwidth=10;
00034     unsigned int old_precision = os.precision(precision);
00035     for (unsigned int row(0); row < M.row_dimension(); row++)
00036       {
00037         for (unsigned int column(0); column < M.column_dimension(); column++)
00038           {
00039             os << std::setw(tabwidth) << std::setprecision(precision)
00040                << M.get_entry(row, column);
00041             if (column < M.column_dimension()-1)
00042               os << " ";
00043           }
00044         if (row < M.row_dimension()-1)
00045           os << "; ";
00046       }
00047     os << "];" << std::endl;
00048     os.precision(old_precision);
00049   }
00050 }
00051 
00052 #endif
 All Classes Functions Variables Typedefs Enumerations