From: Wolfgang Bangerth Date: Wed, 15 Apr 1998 12:04:27 +0000 (+0000) Subject: Finish support for formatted output. X-Git-Tag: v8.0.0~23080 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faf41ffff4ab471860297aa505a96f59f128f149;p=dealii.git Finish support for formatted output. git-svn-id: https://svn.dealii.org/trunk@174 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/dsmatrix.h b/deal.II/lac/include/lac/dsmatrix.h index 7ee18cddb5..d8eef99fd6 100644 --- a/deal.II/lac/include/lac/dsmatrix.h +++ b/deal.II/lac/include/lac/dsmatrix.h @@ -329,15 +329,24 @@ class dSMatrix * matrix elements which are explicitely * set to zero are displayed as such. * - * Each entry is printed as a six character - * wide field, with one space following. + * Each entry is printed in scientific + * format, with one pre-comma digit and + * the number of digits given by + * #precision# after the comma, with one + * space following. + * The precision defaults to four, which + * suffices for most cases. The precision + * and output format are {\it not} + * properly reset to the old values + * when the function exits. * * You should be aware that this function * may produce {\bf large} amounts of * output if applied to a large matrix! * Be careful with it. */ - void print_formatted (ostream &out) const; + void print_formatted (ostream &out, + const unsigned int presicion=3) const; /** * Exception diff --git a/deal.II/lac/source/dsmatrix.cc b/deal.II/lac/source/dsmatrix.cc index fadb3854d1..be393ca0a1 100644 --- a/deal.II/lac/source/dsmatrix.cc +++ b/deal.II/lac/source/dsmatrix.cc @@ -628,14 +628,20 @@ void dSMatrix::print (ostream &out) const { -void dSMatrix::print_formatted (ostream &out) const { +void dSMatrix::print_formatted (ostream &out, const unsigned int precision) const { + out.precision (precision); + out.setf (ios::scientific, ios::floatfield); // set output format + for (unsigned int i=0; ioperator()(i,j)] << " "; + out << setw(precision+7) + << val[cols->operator()(i,j)] << ' '; else - out << " "; + out << setw(precision+8) << " "; out << endl; }; + + out.setf (0, ios::floatfield); // reset output format };