]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add filtering small values to LogStream
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Fri, 8 Apr 2005 09:16:43 +0000 (09:16 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Fri, 8 Apr 2005 09:16:43 +0000 (09:16 +0000)
git-svn-id: https://svn.dealii.org/trunk@10425 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/logstream.h
deal.II/base/source/log.cc

index 1675f1a1b845a1a5af6804d1da64f7a3b2bf9505..3faea5d3e9aff86c896fdc733c923a1037f28c86 100644 (file)
@@ -182,6 +182,15 @@ class LogStream
                                      * parameter is returned.
                                      */
     bool log_time_differences (const bool flag);
+
+                                    /**
+                                     * Set a threshold for the
+                                     * minimal absolute value of
+                                     * double values. All numbers
+                                     * with a smaller absolute value
+                                     * will be printed as zero.
+                                     */
+    void threshold_double(const double t);
     
                                     /**
                                      * Output a constant something
@@ -190,6 +199,18 @@ class LogStream
     template <typename T>
     LogStream & operator << (const T &t);
 
+                                    /**
+                                     * Output double precision
+                                     * numbers through this
+                                     * stream. This function
+                                     * eliminates floating point
+                                     * numbers smaller than
+                                     * #double_threshold, which can
+                                     * be changed using
+                                     * threshold_double().
+                                     */
+    LogStream & operator << (const double t);
+
                                     /**
                                      * Treat ostream
                                      * manipulators. This passes on
@@ -314,6 +335,12 @@ class LogStream
                                      */
     double last_time;
 
+                                    /**
+                                     * Threshold for printing double
+                                     * values.
+                                     */
+    double double_threshold;
+    
                                     /**
                                      * Original buffer of
                                      * <tt>std::cerr</tt>. We store
@@ -361,6 +388,22 @@ LogStream::operator<< (const T& t)
 
 
 
+inline
+LogStream &
+LogStream::operator<< (const double t)
+{
+                                  // do the work that is common to
+                                  // the two operator<< functions
+  if (std::fabs(t) > double_threshold)
+    print (t);
+  else
+    print('0');
+  
+  return *this;
+}
+
+
+
 inline
 LogStream &
 LogStream::operator<< (std::ostream& (*p) (std::ostream&))
index c8b9e9da0968c59f94420eb55fdee77798cbfacb..204220f1a0bebe5383ce3c2eff969bc7d4f3bca3 100644 (file)
@@ -50,7 +50,7 @@ LogStream::LogStream()
                std_out(&std::cerr), file(0), was_endl(true),
                std_depth(10000), file_depth(10000),
                print_utime(false), diff_utime(false),
-               last_time (0.), old_cerr(0)
+               last_time (0.), double_threshold(0.), old_cerr(0)
 {
   prefixes.push("DEAL:");
   std_out->setf(std::ios::showpoint | std::ios::left);
@@ -148,6 +148,13 @@ LogStream::depth_file (const unsigned n)
 }
 
 
+void
+LogStream::threshold_double (const double t)
+{
+  double_threshold = t;
+}
+
+
 bool
 LogStream::log_execution_time (const bool flag)
 {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.