Cantera  2.0
LogPrintCtrl.cpp
Go to the documentation of this file.
1 /**
2  * @file LogPrintCtrl.cpp
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 #include <cmath>
14 
15 #include <iostream>
16 #include <fstream>
17 
18 #include "LogPrintCtrl.h"
19 #include "cantera/base/global.h"
20 
21 using namespace std;
22 
23 namespace Cantera
24 {
25 
26 LogPrintCtrl::LogPrintCtrl(int Ndec) :
27  m_ffss(0),
28  m_pc(0)
29 {
30  m_ffss = new std::ostream(m_os.rdbuf());
31  m_pc = new PrintCtrl(*m_ffss, Ndec);
32 }
33 
35 {
36  delete m_pc;
37  delete m_ffss;
38 }
39 
40 // Print a double using scientific notation
41 /*
42  * Prints a double using scientific notation in a
43  * fixed number of spaces
44  *
45  *
46  * @param d double to be printed
47  * @param w Number of spaces to use
48  * @param p Precision
49  *
50  *
51  */
52 void LogPrintCtrl::pr_de_c10(const double din, int p, const int wMin,
53  const int wMax)
54 {
55  m_pc->pr_de_c10(din, p, wMin, wMax);
56  writelog(m_os.str());
57  m_os.str("");
58 }
59 
60 // Print a double using scientific notation
61 /*
62  * Prints a double using scientific notation in a
63  * fixed number of spaces. Rounding of the last digit is carried out
64  * by the standard c++ printing utilities.
65  *
66  * @param d double to be printed
67  * @param w Number of spaces to use
68  * @param p Precision
69  */
70 void LogPrintCtrl::pr_de(const double d, int sigDigIn, const int wMinIn,
71  const int wMaxIn)
72 {
73  m_pc->pr_de(d, sigDigIn, wMinIn, wMaxIn);
74  writelog(m_os.str());
75  m_os.str("");
76 }
77 
78 // Croup a double at a certain decade level
79 /*
80  * This routine will crop a floating point number at a certain
81  * decade lvl. In other words everything below a power of 10^Ndec
82  * will be deleted.
83  * Note, it currently does not do rounding of the last digit.
84  *
85  * @param d Double to be cropped
86  * @param nSig Number of significant digits
87  * example:
88  * d = 1.1305E-15;
89  * Ndec = -16;
90  * This routine will return 1.1E-15
91  *
92  * d = 8.0E-17
93  * Ndec = -16
94  * This routine will return 0.0
95  */
96 double LogPrintCtrl::cropAbs10(const double d, int Ndec) const
97 {
98  return m_pc->cropAbs10(d, Ndec);
99 }
100 
101 // Crop a double at a certain number of significant digits
102 /*
103  * This routine will crop a floating point number at a certain
104  * number of significant digits. Note, it currently does
105  * rounding up of the last digit.
106  *
107  * example:
108  * d = 1.0305E-15;
109  * nsig = 3;
110  * This routine will return 1.03E-15
111  */
112 double LogPrintCtrl::cropSigDigits(const double d, int nSig) const
113 {
114  return m_pc->cropSigDigits(d, nSig);
115 }
116 
117 // Set the default value of N decade
118 /*
119  * @param Ndec new value of Ndec
120  *
121  * @return returns the old value of Ndec
122  */
124 {
125  return m_pc->setNdec(Ndec);
126 }
127 
128 // Set the default significant digits to output
129 /*
130  * @param nSigDigits new value of the sig digits
131  *
132  * @return returns the old value of Ndec
133  */
134 int LogPrintCtrl::setSigDigits(int nSigDigits)
135 {
136  return m_pc->setSigDigits(nSigDigits);
137 }
138 
139 // Set the default minimum width
140 /*
141  * @param wmin Default minimum width
142  *
143  * @return returns the old default
144  */
146 {
147  return m_pc->setWmin(wmin);
148 }
149 
150 
151 // Set the default maximum width
152 /*
153  * @param wmin Default maximum width
154  *
155  * @return returns the old default
156  */
158 {
159  return m_pc->setWmax(wmax);
160 }
161 
162 
163 }