Cantera  2.1.2
PrintCtrl.h
Go to the documentation of this file.
1 /**
2  * @file PrintCtrl.h
3  * Declarations for a simple class that augments the streams printing capabilities
4  * (see \ref Cantera::PrintCtrl).
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_PRINTCTRL_H
14 #define CT_PRINTCTRL_H
15 
16 #include <iostream>
17 
18 namespace Cantera
19 {
20 
21 //! This class provides some printing and cropping utilities
22 /*!
23  * The class is used to provide some formatting options for
24  * printing out real numbers to files and to standard output.
25  * Specifically, it can make sure that a max and min field
26  * width is honored when conducting IO of numbers and strings.
27  * Basically, it's the spot to house all wrappers around
28  * commonly used printing facilities.
29  *
30  * It can also handle cropping of numbers below a certain
31  * decade level. This is useful for IO for testing purposes.
32  * For example, if you don't care about anything below
33  * 1.0E-20, you can set up the IO so that it won't print out
34  * any digits below 1.0E-20, even digits that are in numbers
35  * greater than 1.0E-20. In other words the number
36  *
37  * 1.12345E-19
38  *
39  * would be cropped to the value
40  *
41  * 1.1000E-19
42  *
43  * The class wraps around a single std::ostream class. Its
44  * cropping functions are also available as a "double"
45  * conversion utility.
46  *
47  * @ingroup globalUtilFuncs
48  * @deprecated To be removed in Cantera 2.2.
49  */
50 class PrintCtrl
51 {
52 public:
53  //! enum for cropping control
54  enum CROP_TYPE {
55  //! Turn off cropping always
56  CT_OFF=0,
57  //! Turn off cropping, unless the global toggle is turned on
59  //! Turn on cropping unless the global toggle is turned off
61  //! Turn on cropping always
63  };
64 
65  //! enum for global cropping control
67  //! no preference for global cropping
69  //! global toggle for turning on cropping
71  //! global toggle for turning off cropping
73  };
74 
75  //! static enum for turning on and off cropping
76  /*!
77  * The default is to not have a preference for cropping
78  */
80 
81  //! Constructor
82  /*!
83  * This also serves to initialize the ticks within the object
84  *
85  * @param coutProxy This is a reference to the ostream
86  * to use for all IO from ths object.
87  * @param Ndec value of Ndec. Defaults to -1000, i.e., no decade cropping
88  * @param ctlocal The default is to turn on cropping all the time.
89  */
90  PrintCtrl(std::ostream& coutProxy = std::cout, int Ndec = -1000,
91  CROP_TYPE ctlocal = CT_ON);
92 
93  //! Print a double using scientific notation
94  /*!
95  * Prints a double using scientific notation in a
96  * fixed number of spaces.
97  *
98  * The precision of the number will be adjusted to
99  * fit into the maximum space.
100  *
101  * @param d double to be printed
102  * @param sigDigits Number of significant digits (-1 = default, means to
103  * use the default number for the object, which is initially set
104  * to 13.
105  * @param wMin Minimum number of spaces to print out
106  * @param wMax Maximum number of spaces to print out
107  */
108  void pr_de(const double d, int sigDigits = -1,
109  const int wMin = -1, const int wMax = -1);
110 
111  //! Print a double using scientific notation cropping
112  //! decade values
113  /*!
114  * Prints a double using scientific notation in a
115  * fixed number of spaces. This routine also crops
116  * number below the default decade level.
117  *
118  * The precision of the number will be adjusted to
119  * fit into the maximum space.
120  *
121  * @param d double to be printed
122  * @param sigDigits Number of significant digits (-1 = default, means to
123  * use the default number for the object, which is initially set
124  * to 13.
125  * @param wMin Minimum number of spaces to print out
126  * @param wMax Maximum number of spaces to print out
127  */
128  void pr_de_c10(const double d, int sigDigits = -1,
129  const int wMin = -1, const int wMax = -1);
130 
131  //! Crop a double at a certain number of significant digits
132  /*!
133  * This routine will crop a floating point number at a certain
134  * number of significant digits. Note, it does
135  * rounding up of the last digit.
136  *
137  * @param d Double to be cropped
138  * @param sigDigits Number of significant digits
139  * example:
140  * d = 1.0305E-15;
141  * nsig = 3;
142  * This routine will return 1.03E-15
143  */
144  double cropSigDigits(const double d, int sigDigits) const;
145 
146  //! Crop a double at a certain decade level
147  /*!
148  * This routine will crop a floating point number at a certain decade
149  * lvl. In other words everything below a power of 10^Ndec will be
150  * deleted. Note, it does rounding up of the last digit.
151  *
152  * @param d Double to be cropped
153  * @param nDecades Number of significant digits
154  * example:
155  * d = 1.1305E-15;
156  * nDecades = -16;
157  * This routine will return 1.1E-15
158  *
159  * d = 8.0E-17
160  * nDecades = -16
161  * This routine will return 0.0
162  */
163  double cropAbs10(const double d, const int nDecades) const;
164 
165  //! Set the default value of N decade
166  /*!
167  * @param nDecades new value of Ndec
168  * @return returns the old value of Ndec
169  */
170  int setNdec(int nDecades);
171 
172  //! Set the default significant digits to output
173  /*!
174  * @param sigDigits new value of the sig digits
175  * @return returns the old value of Ndec
176  */
177  int setSigDigits(int sigDigits);
178 
179  //! Set the default minimum width
180  /*!
181  * @param wMin Default minimum width
182  * @return returns the old default
183  */
184  int setWmin(int wMin);
185 
186  //! Set the default maximum width
187  /*!
188  * @param wMax Default maximum width
189  * @return returns the old default
190  */
191  int setWmax(int wMax);
192 
193  //! Set the cropping control flag
194  /*!
195  * @param ctlocal Local enum value for the cropping type
196  */
197  void setCropCntrl(CROP_TYPE ctlocal);
198 
199 private:
200  //! private function to figure out cropping logic
201  /*!
202  * @return Returns the decision as to whether to crop or not
203  */
204  bool doCrop() const;
205 
206  //! This is the ostream to send all output from the object
207  /*!
208  * It defaults to cout
209  */
210  std::ostream& m_cout;
211 
212  //! Default decade level to use for decade cropping
213  /*!
214  * This is initially set to -1000, which means that
215  * no cropping will be carried out
216  */
217  int m_Ndec;
218 
219  //! default precision level to use in printing
220  /*!
221  * This actually is one less than the number of significant digits.
222  *
223  * Initially set to 12
224  */
226 
227  //! default minimimum field width
228  /*!
229  * Initially, this is set to 9
230  */
231  int m_wMin;
232 
233  //! Default maximum field width
234  /*!
235  * Initially this is set to 19
236  */
237  int m_wMax;
238 
239  //! Local Cropping Control
241 };
242 }
243 
244 #endif
Turn on cropping unless the global toggle is turned off.
Definition: PrintCtrl.h:60
CROP_TYPE
enum for cropping control
Definition: PrintCtrl.h:54
global toggle for turning off cropping
Definition: PrintCtrl.h:72
int m_wMin
default minimimum field width
Definition: PrintCtrl.h:231
double cropAbs10(const double d, const int nDecades) const
Crop a double at a certain decade level.
Definition: PrintCtrl.cpp:111
void setCropCntrl(CROP_TYPE ctlocal)
Set the cropping control flag.
Definition: PrintCtrl.cpp:213
bool doCrop() const
private function to figure out cropping logic
Definition: PrintCtrl.cpp:198
void pr_de_c10(const double d, int sigDigits=-1, const int wMin=-1, const int wMax=-1)
Print a double using scientific notation cropping decade values.
Definition: PrintCtrl.cpp:37
Turn off cropping, unless the global toggle is turned on.
Definition: PrintCtrl.h:58
int setWmin(int wMin)
Set the default minimum width.
Definition: PrintCtrl.cpp:184
double cropSigDigits(const double d, int sigDigits) const
Crop a double at a certain number of significant digits.
Definition: PrintCtrl.cpp:133
int m_wMax
Default maximum field width.
Definition: PrintCtrl.h:237
CROP_TYPE_GLOBAL
enum for global cropping control
Definition: PrintCtrl.h:66
int m_Ndec
Default decade level to use for decade cropping.
Definition: PrintCtrl.h:217
global toggle for turning on cropping
Definition: PrintCtrl.h:70
void pr_de(const double d, int sigDigits=-1, const int wMin=-1, const int wMax=-1)
Print a double using scientific notation.
Definition: PrintCtrl.cpp:44
std::ostream & m_cout
This is the ostream to send all output from the object.
Definition: PrintCtrl.h:210
int setSigDigits(int sigDigits)
Set the default significant digits to output.
Definition: PrintCtrl.cpp:174
CROP_TYPE m_cropCntrl
Local Cropping Control.
Definition: PrintCtrl.h:240
Turn off cropping always.
Definition: PrintCtrl.h:56
PrintCtrl(std::ostream &coutProxy=std::cout, int Ndec=-1000, CROP_TYPE ctlocal=CT_ON)
Constructor.
Definition: PrintCtrl.cpp:25
int setWmax(int wMax)
Set the default maximum width.
Definition: PrintCtrl.cpp:191
int setNdec(int nDecades)
Set the default value of N decade.
Definition: PrintCtrl.cpp:167
This class provides some printing and cropping utilities.
Definition: PrintCtrl.h:50
int m_precision
default precision level to use in printing
Definition: PrintCtrl.h:225
static CROP_TYPE_GLOBAL GlobalCrop
static enum for turning on and off cropping
Definition: PrintCtrl.h:79
Turn on cropping always.
Definition: PrintCtrl.h:62
no preference for global cropping
Definition: PrintCtrl.h:68