Cantera  2.0
LogPrintCtrl.h
Go to the documentation of this file.
1 /**
2  * @file LogPrintCtrl.h
3  * Declarations for a simple class that augments the logfile printing capabilities
4  * (see \ref Cantera::LogPrintCtrl).
5  */
6 /*
7  * Copyright 2004 Sandia Corporation. Under the terms of Contract
8  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
9  * retains certain rights in this software.
10  * See file License.txt for licensing information.
11  */
12 
13 #ifndef CT_LOGPRINTCTRL_H
14 #define CT_LOGPRINTCTRL_H
15 
16 #include <sstream>
17 
18 #include "cantera/base/PrintCtrl.h"
19 
20 namespace Cantera
21 {
22 
23 //! This class provides some printing and cropping utilities
24 //! for writing to the logfile.
25 /*!
26  * This class writes its output to Cantera's logfile
27  * utility. It's a wrapper around PrintCtrl object.
28  * First, we direct PrintCtrl to write to a string
29  * and then we redirect the string to the logfile utility.
30  * This is a first cut, and it's pretty much a kluge.
31  * The logfile utility, however, demands a string, and this
32  * is what I came up with.
33  *
34  * @ingroup globalUtilFuncs
35  *
36  */
38 {
39 public:
40 
41  //! Constructor
42  /*!
43  * This also serves to initialize the ticks within the object
44  *
45  * @param Ndec value of Ndec. Defaults to -1000, i.e.,
46  * no decade cropping
47  */
48  LogPrintCtrl(int Ndec = -1000);
49 
50  //! Destructor
51  ~LogPrintCtrl();
52 
53  //! Print a double using scientific notation
54  /*!
55  * Prints a double using scientific notation in a
56  * fixed number of spaces.
57  *
58  * The precision of the number will be adjusted to
59  * fit into the maximum space.
60  *
61  * @param d double to be printed
62  * @param sigDigits Number of significant digits
63  * (-1 = default, means to use the default
64  * number for the object, which is initially
65  * set to 13.
66  * @param wMin Minimum number of spaces to print out
67  * @param wMax Maximum number of spaces to print out
68  */
69  void pr_de(const double d, int sigDigits = -1,
70  const int wMin = -1, const int wMax = -1);
71 
72  //! Print a double using scientific notation cropping
73  //! decade values
74  /*!
75  * Prints a double using scientific notation in a
76  * fixed number of spaces. This routine also crops
77  * number below the default decade level.
78  *
79  * The precision of the number will be adjusted to
80  * fit into the maximum space.
81  *
82  * @param d double to be printed
83  * @param sigDigits Number of significant digits
84  * (-1 = default, means to use the default
85  * number for the object, which is initially
86  * set to 13.
87  * @param wMin Minimum number of spaces to print out
88  * @param wMax Maximum number of spaces to print out
89  */
90  void pr_de_c10(const double d, int sigDigits = -1,
91  const int wMin = -1, const int wMax = -1);
92 
93  //! Crop a double at a certain number of significant digits
94  /*!
95  * This routine will crop a floating point number at a certain
96  * number of significant digits. Note, it does
97  * rounding up of the last digit.
98  *
99  * @param d Double to be cropped
100  * @param sigDigits Number of significant digits
101  * example:
102  * d = 1.0305E-15;
103  * nsig = 3;
104  * This routine will return 1.03E-15
105  */
106  double cropSigDigits(const double d, int sigDigits) const;
107 
108  //! Crop a double at a certain decade level
109  /*!
110  * This routine will crop a floating point number at a certain
111  * decade lvl. In other words everything below a power of 10^Ndec
112  * will be deleted.
113  * Note, it does rounding up of the last digit.
114  *
115  * @param d Double to be cropped
116  * @param nDecades Number of significant digits
117  * example:
118  * d = 1.1305E-15;
119  * nDecades = -16;
120  * This routine will return 1.1E-15
121  *
122  * d = 8.0E-17
123  * nDecades = -16
124  * This routine will return 0.0
125  */
126  double cropAbs10(const double d, const int nDecades) const;
127 
128  //! Set the default value of N decade
129  /*!
130  * @param nDecades new value of Ndec
131  *
132  * @return returns the old value of Ndec
133  */
134  int setNdec(int nDecades);
135 
136 
137  //! Set the default significant digits to output
138  /*!
139  * @param sigDigits new value of the sig digits
140  *
141  * @return returns the old value of Ndec
142  */
143  int setSigDigits(int sigDigits);
144 
145  //! Set the default minimum width
146  /*!
147  * @param wMin Default minimum width
148  *
149  * @return returns the old default
150  */
151  int setWmin(int wMin);
152 
153  //! Set the default maximum width
154  /*!
155  * @param wMax Default maximum width
156  *
157  * @return returns the old default
158  */
159  int setWmax(int wMax);
160 
161 
162 private:
163 
164  //! local stringstream class for temp output
165  std::ostringstream m_os;
166 
167  //! Pointer to the ostream where this class actually
168  //! prints its information
169  std::ostream* m_ffss;
170 
171  //! Pointer to the PrintCtrl class
173 
174 
175 
176 };
177 }
178 
179 #endif
180