Remove previously-deprecated 'PrintCtrl' and 'LogPrintCtrl' classes.
This commit is contained in:
parent
54ded64e4b
commit
7fff65cecd
8 changed files with 0 additions and 1385 deletions
|
|
@ -1,244 +0,0 @@
|
||||||
/**
|
|
||||||
* @file PrintCtrl.h
|
|
||||||
* Declarations for a simple class that augments the streams printing capabilities
|
|
||||||
* (see \ref Cantera::PrintCtrl).
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright 2004 Sandia Corporation. Under the terms of Contract
|
|
||||||
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
|
|
||||||
* retains certain rights in this software.
|
|
||||||
* See file License.txt for licensing information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CT_PRINTCTRL_H
|
|
||||||
#define CT_PRINTCTRL_H
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace Cantera
|
|
||||||
{
|
|
||||||
|
|
||||||
//! This class provides some printing and cropping utilities
|
|
||||||
/*!
|
|
||||||
* The class is used to provide some formatting options for
|
|
||||||
* printing out real numbers to files and to standard output.
|
|
||||||
* Specifically, it can make sure that a max and min field
|
|
||||||
* width is honored when conducting IO of numbers and strings.
|
|
||||||
* Basically, it's the spot to house all wrappers around
|
|
||||||
* commonly used printing facilities.
|
|
||||||
*
|
|
||||||
* It can also handle cropping of numbers below a certain
|
|
||||||
* decade level. This is useful for IO for testing purposes.
|
|
||||||
* For example, if you don't care about anything below
|
|
||||||
* 1.0E-20, you can set up the IO so that it won't print out
|
|
||||||
* any digits below 1.0E-20, even digits that are in numbers
|
|
||||||
* greater than 1.0E-20. In other words the number
|
|
||||||
*
|
|
||||||
* 1.12345E-19
|
|
||||||
*
|
|
||||||
* would be cropped to the value
|
|
||||||
*
|
|
||||||
* 1.1000E-19
|
|
||||||
*
|
|
||||||
* The class wraps around a single std::ostream class. Its
|
|
||||||
* cropping functions are also available as a "double"
|
|
||||||
* conversion utility.
|
|
||||||
*
|
|
||||||
* @ingroup globalUtilFuncs
|
|
||||||
* @deprecated To be removed in Cantera 2.2.
|
|
||||||
*/
|
|
||||||
class PrintCtrl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
//! enum for cropping control
|
|
||||||
enum CROP_TYPE {
|
|
||||||
//! Turn off cropping always
|
|
||||||
CT_OFF=0,
|
|
||||||
//! Turn off cropping, unless the global toggle is turned on
|
|
||||||
CT_OFF_GLOBALOBEY,
|
|
||||||
//! Turn on cropping unless the global toggle is turned off
|
|
||||||
CT_ON_GLOBALOBEY,
|
|
||||||
//! Turn on cropping always
|
|
||||||
CT_ON
|
|
||||||
};
|
|
||||||
|
|
||||||
//! enum for global cropping control
|
|
||||||
enum CROP_TYPE_GLOBAL {
|
|
||||||
//! no preference for global cropping
|
|
||||||
GCT_NOPREF = 0,
|
|
||||||
//! global toggle for turning on cropping
|
|
||||||
GCT_CROP,
|
|
||||||
//! global toggle for turning off cropping
|
|
||||||
GCT_NOCROP
|
|
||||||
};
|
|
||||||
|
|
||||||
//! static enum for turning on and off cropping
|
|
||||||
/*!
|
|
||||||
* The default is to not have a preference for cropping
|
|
||||||
*/
|
|
||||||
static CROP_TYPE_GLOBAL GlobalCrop;
|
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
/*!
|
|
||||||
* This also serves to initialize the ticks within the object
|
|
||||||
*
|
|
||||||
* @param coutProxy This is a reference to the ostream
|
|
||||||
* to use for all IO from ths object.
|
|
||||||
* @param Ndec value of Ndec. Defaults to -1000, i.e., no decade cropping
|
|
||||||
* @param ctlocal The default is to turn on cropping all the time.
|
|
||||||
*/
|
|
||||||
PrintCtrl(std::ostream& coutProxy = std::cout, int Ndec = -1000,
|
|
||||||
CROP_TYPE ctlocal = CT_ON);
|
|
||||||
|
|
||||||
//! Print a double using scientific notation
|
|
||||||
/*!
|
|
||||||
* Prints a double using scientific notation in a
|
|
||||||
* fixed number of spaces.
|
|
||||||
*
|
|
||||||
* The precision of the number will be adjusted to
|
|
||||||
* fit into the maximum space.
|
|
||||||
*
|
|
||||||
* @param d double to be printed
|
|
||||||
* @param sigDigits Number of significant digits (-1 = default, means to
|
|
||||||
* use the default number for the object, which is initially set
|
|
||||||
* to 13.
|
|
||||||
* @param wMin Minimum number of spaces to print out
|
|
||||||
* @param wMax Maximum number of spaces to print out
|
|
||||||
*/
|
|
||||||
void pr_de(const double d, int sigDigits = -1,
|
|
||||||
const int wMin = -1, const int wMax = -1);
|
|
||||||
|
|
||||||
//! Print a double using scientific notation cropping
|
|
||||||
//! decade values
|
|
||||||
/*!
|
|
||||||
* Prints a double using scientific notation in a
|
|
||||||
* fixed number of spaces. This routine also crops
|
|
||||||
* number below the default decade level.
|
|
||||||
*
|
|
||||||
* The precision of the number will be adjusted to
|
|
||||||
* fit into the maximum space.
|
|
||||||
*
|
|
||||||
* @param d double to be printed
|
|
||||||
* @param sigDigits Number of significant digits (-1 = default, means to
|
|
||||||
* use the default number for the object, which is initially set
|
|
||||||
* to 13.
|
|
||||||
* @param wMin Minimum number of spaces to print out
|
|
||||||
* @param wMax Maximum number of spaces to print out
|
|
||||||
*/
|
|
||||||
void pr_de_c10(const double d, int sigDigits = -1,
|
|
||||||
const int wMin = -1, const int wMax = -1);
|
|
||||||
|
|
||||||
//! Crop a double at a certain number of significant digits
|
|
||||||
/*!
|
|
||||||
* This routine will crop a floating point number at a certain
|
|
||||||
* number of significant digits. Note, it does
|
|
||||||
* rounding up of the last digit.
|
|
||||||
*
|
|
||||||
* @param d Double to be cropped
|
|
||||||
* @param sigDigits Number of significant digits
|
|
||||||
* example:
|
|
||||||
* d = 1.0305E-15;
|
|
||||||
* nsig = 3;
|
|
||||||
* This routine will return 1.03E-15
|
|
||||||
*/
|
|
||||||
double cropSigDigits(const double d, int sigDigits) const;
|
|
||||||
|
|
||||||
//! Crop a double at a certain decade level
|
|
||||||
/*!
|
|
||||||
* This routine will crop a floating point number at a certain decade
|
|
||||||
* lvl. In other words everything below a power of 10^Ndec will be
|
|
||||||
* deleted. Note, it does rounding up of the last digit.
|
|
||||||
*
|
|
||||||
* @param d Double to be cropped
|
|
||||||
* @param nDecades Number of significant digits
|
|
||||||
* example:
|
|
||||||
* d = 1.1305E-15;
|
|
||||||
* nDecades = -16;
|
|
||||||
* This routine will return 1.1E-15
|
|
||||||
*
|
|
||||||
* d = 8.0E-17
|
|
||||||
* nDecades = -16
|
|
||||||
* This routine will return 0.0
|
|
||||||
*/
|
|
||||||
double cropAbs10(const double d, const int nDecades) const;
|
|
||||||
|
|
||||||
//! Set the default value of N decade
|
|
||||||
/*!
|
|
||||||
* @param nDecades new value of Ndec
|
|
||||||
* @return returns the old value of Ndec
|
|
||||||
*/
|
|
||||||
int setNdec(int nDecades);
|
|
||||||
|
|
||||||
//! Set the default significant digits to output
|
|
||||||
/*!
|
|
||||||
* @param sigDigits new value of the sig digits
|
|
||||||
* @return returns the old value of Ndec
|
|
||||||
*/
|
|
||||||
int setSigDigits(int sigDigits);
|
|
||||||
|
|
||||||
//! Set the default minimum width
|
|
||||||
/*!
|
|
||||||
* @param wMin Default minimum width
|
|
||||||
* @return returns the old default
|
|
||||||
*/
|
|
||||||
int setWmin(int wMin);
|
|
||||||
|
|
||||||
//! Set the default maximum width
|
|
||||||
/*!
|
|
||||||
* @param wMax Default maximum width
|
|
||||||
* @return returns the old default
|
|
||||||
*/
|
|
||||||
int setWmax(int wMax);
|
|
||||||
|
|
||||||
//! Set the cropping control flag
|
|
||||||
/*!
|
|
||||||
* @param ctlocal Local enum value for the cropping type
|
|
||||||
*/
|
|
||||||
void setCropCntrl(CROP_TYPE ctlocal);
|
|
||||||
|
|
||||||
private:
|
|
||||||
//! private function to figure out cropping logic
|
|
||||||
/*!
|
|
||||||
* @return Returns the decision as to whether to crop or not
|
|
||||||
*/
|
|
||||||
bool doCrop() const;
|
|
||||||
|
|
||||||
//! This is the ostream to send all output from the object
|
|
||||||
/*!
|
|
||||||
* It defaults to cout
|
|
||||||
*/
|
|
||||||
std::ostream& m_cout;
|
|
||||||
|
|
||||||
//! Default decade level to use for decade cropping
|
|
||||||
/*!
|
|
||||||
* This is initially set to -1000, which means that
|
|
||||||
* no cropping will be carried out
|
|
||||||
*/
|
|
||||||
int m_Ndec;
|
|
||||||
|
|
||||||
//! default precision level to use in printing
|
|
||||||
/*!
|
|
||||||
* This actually is one less than the number of significant digits.
|
|
||||||
*
|
|
||||||
* Initially set to 12
|
|
||||||
*/
|
|
||||||
int m_precision;
|
|
||||||
|
|
||||||
//! default minimimum field width
|
|
||||||
/*!
|
|
||||||
* Initially, this is set to 9
|
|
||||||
*/
|
|
||||||
int m_wMin;
|
|
||||||
|
|
||||||
//! Default maximum field width
|
|
||||||
/*!
|
|
||||||
* Initially this is set to 19
|
|
||||||
*/
|
|
||||||
int m_wMax;
|
|
||||||
|
|
||||||
//! Local Cropping Control
|
|
||||||
CROP_TYPE m_cropCntrl;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
/**
|
|
||||||
* @file LogPrintCtrl.cpp
|
|
||||||
* Declarations for a simple class that augments the logfile printing capabilities
|
|
||||||
* (see \ref Cantera::LogPrintCtrl).
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright 2004 Sandia Corporation. Under the terms of Contract
|
|
||||||
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
|
|
||||||
* retains certain rights in this software.
|
|
||||||
* See file License.txt for licensing information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "LogPrintCtrl.h"
|
|
||||||
#include "cantera/base/global.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace Cantera
|
|
||||||
{
|
|
||||||
|
|
||||||
LogPrintCtrl::LogPrintCtrl(int Ndec) :
|
|
||||||
m_ffss(0),
|
|
||||||
m_pc(0)
|
|
||||||
{
|
|
||||||
warn_deprecated("class LogPrintCtrl");
|
|
||||||
m_ffss = new std::ostream(m_os.rdbuf());
|
|
||||||
m_pc = new PrintCtrl(*m_ffss, Ndec);
|
|
||||||
}
|
|
||||||
|
|
||||||
LogPrintCtrl::~LogPrintCtrl()
|
|
||||||
{
|
|
||||||
delete m_pc;
|
|
||||||
delete m_ffss;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogPrintCtrl::pr_de_c10(const double din, int p, const int wMin,
|
|
||||||
const int wMax)
|
|
||||||
{
|
|
||||||
m_pc->pr_de_c10(din, p, wMin, wMax);
|
|
||||||
writelog(m_os.str());
|
|
||||||
m_os.str("");
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogPrintCtrl::pr_de(const double d, int sigDigIn, const int wMinIn,
|
|
||||||
const int wMaxIn)
|
|
||||||
{
|
|
||||||
m_pc->pr_de(d, sigDigIn, wMinIn, wMaxIn);
|
|
||||||
writelog(m_os.str());
|
|
||||||
m_os.str("");
|
|
||||||
}
|
|
||||||
|
|
||||||
double LogPrintCtrl::cropAbs10(const double d, int Ndec) const
|
|
||||||
{
|
|
||||||
return m_pc->cropAbs10(d, Ndec);
|
|
||||||
}
|
|
||||||
|
|
||||||
double LogPrintCtrl::cropSigDigits(const double d, int nSig) const
|
|
||||||
{
|
|
||||||
return m_pc->cropSigDigits(d, nSig);
|
|
||||||
}
|
|
||||||
|
|
||||||
int LogPrintCtrl::setNdec(int Ndec)
|
|
||||||
{
|
|
||||||
return m_pc->setNdec(Ndec);
|
|
||||||
}
|
|
||||||
|
|
||||||
int LogPrintCtrl::setSigDigits(int nSigDigits)
|
|
||||||
{
|
|
||||||
return m_pc->setSigDigits(nSigDigits);
|
|
||||||
}
|
|
||||||
|
|
||||||
int LogPrintCtrl::setWmin(int wmin)
|
|
||||||
{
|
|
||||||
return m_pc->setWmin(wmin);
|
|
||||||
}
|
|
||||||
|
|
||||||
int LogPrintCtrl::setWmax(int wmax)
|
|
||||||
{
|
|
||||||
return m_pc->setWmax(wmax);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,165 +0,0 @@
|
||||||
/**
|
|
||||||
* @file LogPrintCtrl.h
|
|
||||||
* Declarations for a simple class that augments the logfile printing capabilities
|
|
||||||
* (see \ref Cantera::LogPrintCtrl).
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright 2004 Sandia Corporation. Under the terms of Contract
|
|
||||||
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
|
|
||||||
* retains certain rights in this software.
|
|
||||||
* See file License.txt for licensing information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CT_LOGPRINTCTRL_H
|
|
||||||
#define CT_LOGPRINTCTRL_H
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "cantera/base/PrintCtrl.h"
|
|
||||||
|
|
||||||
namespace Cantera
|
|
||||||
{
|
|
||||||
|
|
||||||
//! This class provides some printing and cropping utilities
|
|
||||||
//! for writing to the logfile.
|
|
||||||
/*!
|
|
||||||
* This class writes its output to Cantera's logfile
|
|
||||||
* utility. It's a wrapper around PrintCtrl object.
|
|
||||||
* First, we direct PrintCtrl to write to a string
|
|
||||||
* and then we redirect the string to the logfile utility.
|
|
||||||
* This is a first cut, and it's pretty much a kluge.
|
|
||||||
* The logfile utility, however, demands a string, and this
|
|
||||||
* is what I came up with.
|
|
||||||
*
|
|
||||||
* @ingroup globalUtilFuncs
|
|
||||||
* @deprecated To be removed in Cantera 2.2.
|
|
||||||
*/
|
|
||||||
class LogPrintCtrl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
//! Constructor
|
|
||||||
/*!
|
|
||||||
* This also serves to initialize the ticks within the object
|
|
||||||
*
|
|
||||||
* @param Ndec value of Ndec. Defaults to -1000, i.e., no decade cropping
|
|
||||||
*/
|
|
||||||
LogPrintCtrl(int Ndec = -1000);
|
|
||||||
|
|
||||||
//! Destructor
|
|
||||||
~LogPrintCtrl();
|
|
||||||
|
|
||||||
//! Print a double using scientific notation
|
|
||||||
/*!
|
|
||||||
* Prints a double using scientific notation in a
|
|
||||||
* fixed number of spaces.
|
|
||||||
*
|
|
||||||
* The precision of the number will be adjusted to
|
|
||||||
* fit into the maximum space.
|
|
||||||
*
|
|
||||||
* @param d double to be printed
|
|
||||||
* @param sigDigits Number of significant digits (-1 = default, means to
|
|
||||||
* use the default number for the object, which is initially set
|
|
||||||
* to 13.
|
|
||||||
* @param wMin Minimum number of spaces to print out
|
|
||||||
* @param wMax Maximum number of spaces to print out
|
|
||||||
*/
|
|
||||||
void pr_de(const double d, int sigDigits = -1,
|
|
||||||
const int wMin = -1, const int wMax = -1);
|
|
||||||
|
|
||||||
//! Print a double using scientific notation cropping
|
|
||||||
//! decade values
|
|
||||||
/*!
|
|
||||||
* Prints a double using scientific notation in a
|
|
||||||
* fixed number of spaces. This routine also crops
|
|
||||||
* number below the default decade level.
|
|
||||||
*
|
|
||||||
* The precision of the number will be adjusted to
|
|
||||||
* fit into the maximum space.
|
|
||||||
*
|
|
||||||
* @param d double to be printed
|
|
||||||
* @param sigDigits Number of significant digits (-1 = default, means to
|
|
||||||
* use the default number for the object, which is initially set
|
|
||||||
* to 13.
|
|
||||||
* @param wMin Minimum number of spaces to print out
|
|
||||||
* @param wMax Maximum number of spaces to print out
|
|
||||||
*/
|
|
||||||
void pr_de_c10(const double d, int sigDigits = -1,
|
|
||||||
const int wMin = -1, const int wMax = -1);
|
|
||||||
|
|
||||||
//! Crop a double at a certain number of significant digits
|
|
||||||
/*!
|
|
||||||
* This routine will crop a floating point number at a certain
|
|
||||||
* number of significant digits. Note, it does
|
|
||||||
* rounding up of the last digit.
|
|
||||||
*
|
|
||||||
* @param d Double to be cropped
|
|
||||||
* @param sigDigits Number of significant digits
|
|
||||||
* example:
|
|
||||||
* d = 1.0305E-15;
|
|
||||||
* nsig = 3;
|
|
||||||
* This routine will return 1.03E-15
|
|
||||||
*/
|
|
||||||
double cropSigDigits(const double d, int sigDigits) const;
|
|
||||||
|
|
||||||
//! Crop a double at a certain decade level
|
|
||||||
/*!
|
|
||||||
* This routine will crop a floating point number at a certain decade
|
|
||||||
* lvl. In other words everything below a power of 10^Ndec will be
|
|
||||||
* deleted. Note, it does rounding up of the last digit.
|
|
||||||
*
|
|
||||||
* @param d Double to be cropped
|
|
||||||
* @param nDecades Number of significant digits
|
|
||||||
* example:
|
|
||||||
* d = 1.1305E-15;
|
|
||||||
* nDecades = -16;
|
|
||||||
* This routine will return 1.1E-15
|
|
||||||
*
|
|
||||||
* d = 8.0E-17
|
|
||||||
* nDecades = -16
|
|
||||||
* This routine will return 0.0
|
|
||||||
*/
|
|
||||||
double cropAbs10(const double d, const int nDecades) const;
|
|
||||||
|
|
||||||
//! Set the default value of N decade
|
|
||||||
/*!
|
|
||||||
* @param nDecades new value of Ndec
|
|
||||||
* @return returns the old value of Ndec
|
|
||||||
*/
|
|
||||||
int setNdec(int nDecades);
|
|
||||||
|
|
||||||
|
|
||||||
//! Set the default significant digits to output
|
|
||||||
/*!
|
|
||||||
* @param sigDigits new value of the sig digits
|
|
||||||
* @return returns the old value of Ndec
|
|
||||||
*/
|
|
||||||
int setSigDigits(int sigDigits);
|
|
||||||
|
|
||||||
//! Set the default minimum width
|
|
||||||
/*!
|
|
||||||
* @param wMin Default minimum width
|
|
||||||
* @return returns the old default
|
|
||||||
*/
|
|
||||||
int setWmin(int wMin);
|
|
||||||
|
|
||||||
//! Set the default maximum width
|
|
||||||
/*!
|
|
||||||
* @param wMax Default maximum width
|
|
||||||
* @return returns the old default
|
|
||||||
*/
|
|
||||||
int setWmax(int wMax);
|
|
||||||
|
|
||||||
private:
|
|
||||||
//! local stringstream class for temp output
|
|
||||||
std::ostringstream m_os;
|
|
||||||
|
|
||||||
//! Pointer to the ostream where this class actually
|
|
||||||
//! prints its information
|
|
||||||
std::ostream* m_ffss;
|
|
||||||
|
|
||||||
//! Pointer to the PrintCtrl class
|
|
||||||
PrintCtrl* m_pc;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,217 +0,0 @@
|
||||||
/**
|
|
||||||
* @file PrintCtrl.cpp
|
|
||||||
* Definitions for a simple class that augments the streams printing capabilities
|
|
||||||
* (see \ref Cantera::PrintCtrl).
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright 2004 Sandia Corporation. Under the terms of Contract
|
|
||||||
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
|
|
||||||
* retains certain rights in this software.
|
|
||||||
* See file License.txt for licensing information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "cantera/base/PrintCtrl.h"
|
|
||||||
#include "cantera/base/global.h"
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace Cantera
|
|
||||||
{
|
|
||||||
|
|
||||||
// Storage for the global crop flag
|
|
||||||
PrintCtrl::CROP_TYPE_GLOBAL PrintCtrl::GlobalCrop = GCT_NOPREF;
|
|
||||||
|
|
||||||
PrintCtrl::PrintCtrl(std::ostream& coutProxy, int Ndec,
|
|
||||||
CROP_TYPE ctlocal) :
|
|
||||||
m_cout(coutProxy),
|
|
||||||
m_Ndec(Ndec),
|
|
||||||
m_precision(12),
|
|
||||||
m_wMin(9),
|
|
||||||
m_wMax(19),
|
|
||||||
m_cropCntrl(ctlocal)
|
|
||||||
{
|
|
||||||
warn_deprecated("class PrintCtrl");
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintCtrl::pr_de_c10(const double din, int p, const int wMin,
|
|
||||||
const int wMax)
|
|
||||||
{
|
|
||||||
double d = cropAbs10(din, m_Ndec);
|
|
||||||
pr_de(d, p, wMin, wMax);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintCtrl::pr_de(const double d, int sigDigIn, const int wMinIn,
|
|
||||||
const int wMaxIn)
|
|
||||||
{
|
|
||||||
int p = m_precision;
|
|
||||||
if (sigDigIn != -1) {
|
|
||||||
p = sigDigIn-1;
|
|
||||||
if (p < 0) {
|
|
||||||
p = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int wMin = m_wMin;
|
|
||||||
if (wMinIn != -1) {
|
|
||||||
wMin = wMinIn;
|
|
||||||
if (wMin < 1) {
|
|
||||||
wMin = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int wMax = m_wMax;
|
|
||||||
if (wMaxIn != -1) {
|
|
||||||
wMax = wMaxIn;
|
|
||||||
if (wMax < 1) {
|
|
||||||
wMax = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wMin > wMax) {
|
|
||||||
wMax = wMin;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Have to do the wMax ourselves, since C++ doesn't seem to
|
|
||||||
// have a streams manipulator to do this !?!
|
|
||||||
double dfabs = fabs(d);
|
|
||||||
// This is the normal length assuming no sign and an 1.0E+04
|
|
||||||
// formated exponented
|
|
||||||
int requestedLength = 6 + p;
|
|
||||||
if (d < 0.0) {
|
|
||||||
requestedLength++;
|
|
||||||
}
|
|
||||||
if (dfabs < 9.9999999999E-99) {
|
|
||||||
requestedLength++;
|
|
||||||
}
|
|
||||||
if (dfabs > 9.9999999999E99) {
|
|
||||||
requestedLength++;
|
|
||||||
}
|
|
||||||
if (requestedLength > wMax) {
|
|
||||||
p -= (requestedLength - wMax);
|
|
||||||
if (p < 0) {
|
|
||||||
p = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set to upper case and scientific notation
|
|
||||||
m_cout.setf(ios_base::scientific | ios_base::uppercase);
|
|
||||||
int wold = (int) m_cout.width(wMin);
|
|
||||||
int pold = (int) m_cout.precision(p);
|
|
||||||
|
|
||||||
m_cout << d;
|
|
||||||
// Return the precision to the previous value;
|
|
||||||
m_cout.precision(pold);
|
|
||||||
m_cout.unsetf(ios_base::scientific);
|
|
||||||
|
|
||||||
// Return width to original
|
|
||||||
m_cout.width(wold);
|
|
||||||
}
|
|
||||||
|
|
||||||
double PrintCtrl::cropAbs10(const double d, int Ndec) const
|
|
||||||
{
|
|
||||||
if (!doCrop()) {
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
if (Ndec < -301 || Ndec > 301) {
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
double dfabs = fabs(d);
|
|
||||||
double pdec = pow(10.0, (double) Ndec);
|
|
||||||
if (dfabs < pdec) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
double dl10 = log10(dfabs);
|
|
||||||
int N10 = (int) dl10;
|
|
||||||
if (dl10 > -0.0) {
|
|
||||||
N10 += 1;
|
|
||||||
}
|
|
||||||
int nsig = N10 - Ndec;
|
|
||||||
return cropSigDigits(d, nsig);
|
|
||||||
}
|
|
||||||
|
|
||||||
double PrintCtrl::cropSigDigits(const double d, int nSig) const
|
|
||||||
{
|
|
||||||
if (!doCrop()) {
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
if (nSig <=0) {
|
|
||||||
nSig = 1;
|
|
||||||
}
|
|
||||||
if (nSig >=9) {
|
|
||||||
nSig = 9;
|
|
||||||
}
|
|
||||||
double sgn = 1.0;
|
|
||||||
if (d < 0.0) {
|
|
||||||
sgn = -1.0;
|
|
||||||
}
|
|
||||||
double dfabs = fabs(d);
|
|
||||||
double dl10 = log10(dfabs);
|
|
||||||
int N10 = (int) dl10;
|
|
||||||
if (dl10 > -0.0) {
|
|
||||||
N10 += 1;
|
|
||||||
}
|
|
||||||
int E10 = -N10 + nSig ;
|
|
||||||
double pfabs = dfabs * pow(10.0, (double) E10);
|
|
||||||
pfabs *= (1.0 + 1.0E-14);
|
|
||||||
long int nfabs = (long int) pfabs;
|
|
||||||
double remainder = pfabs - nfabs;
|
|
||||||
if (remainder > 0.5) {
|
|
||||||
nfabs++;
|
|
||||||
}
|
|
||||||
double paltabs = (double) nfabs;
|
|
||||||
double daltabs = paltabs * pow(10.0, (double) -E10);
|
|
||||||
return sgn * daltabs;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PrintCtrl::setNdec(int Ndec)
|
|
||||||
{
|
|
||||||
int nold = m_Ndec;
|
|
||||||
m_Ndec = Ndec;
|
|
||||||
return nold;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PrintCtrl::setSigDigits(int nSigDigits)
|
|
||||||
{
|
|
||||||
int nold = m_precision + 1;
|
|
||||||
m_precision = nSigDigits - 1;
|
|
||||||
if (m_precision < 0) {
|
|
||||||
m_precision = 0;
|
|
||||||
}
|
|
||||||
return nold;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PrintCtrl::setWmin(int wmin)
|
|
||||||
{
|
|
||||||
int nold = m_wMin;
|
|
||||||
m_wMin = wmin;
|
|
||||||
return nold;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PrintCtrl::setWmax(int wmax)
|
|
||||||
{
|
|
||||||
int nold = m_wMax;
|
|
||||||
m_wMax = wmax;
|
|
||||||
return nold;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PrintCtrl::doCrop() const
|
|
||||||
{
|
|
||||||
bool retn = ((m_cropCntrl == CT_ON) || (m_cropCntrl == CT_ON_GLOBALOBEY));
|
|
||||||
if (m_cropCntrl == CT_ON_GLOBALOBEY) {
|
|
||||||
if (GlobalCrop == GCT_NOCROP) {
|
|
||||||
retn = false;
|
|
||||||
}
|
|
||||||
} else if (m_cropCntrl == CT_OFF_GLOBALOBEY) {
|
|
||||||
if (GlobalCrop == GCT_CROP) {
|
|
||||||
retn = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retn;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintCtrl::setCropCntrl(CROP_TYPE ctlocal)
|
|
||||||
{
|
|
||||||
m_cropCntrl = ctlocal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -276,7 +276,6 @@ if haveConverters:
|
||||||
options='noxNeg.cti', artifacts=negA_name)
|
options='noxNeg.cti', artifacts=negA_name)
|
||||||
|
|
||||||
CompileAndTest('pecosTransport', 'PecosTransport', 'pecosTransport', 'output_blessed.txt')
|
CompileAndTest('pecosTransport', 'PecosTransport', 'pecosTransport', 'output_blessed.txt')
|
||||||
CompileAndTest('printUtil', 'printUtilUnitTest', 'pUtest', 'output_blessed.txt')
|
|
||||||
CompileAndTest('pureFluid', 'pureFluidTest', 'testPureWater', 'output_blessed.txt')
|
CompileAndTest('pureFluid', 'pureFluidTest', 'testPureWater', 'output_blessed.txt')
|
||||||
if haveConverters:
|
if haveConverters:
|
||||||
CompileAndTest('rankine_democxx', 'rankine_democxx', 'rankine', 'output_blessed.txt')
|
CompileAndTest('rankine_democxx', 'rankine_democxx', 'rankine', 'output_blessed.txt')
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
good: dg = 1.2000000000000e-01 eq 0.12
|
|
||||||
error dg = -1.0400000000000e+15 ne -1.03e+15
|
|
||||||
good: dg = 1.0345000000000e-270 eq 1.0345e-270
|
|
||||||
good: dg = 1.0300000000000e-15 eq 1.03e-15
|
|
||||||
good: dg = 1.0345000000000e-15 eq 1.0345e-15
|
|
||||||
good: dg = 1.0000000000000e-15 eq 1e-15
|
|
||||||
good: dg = -1.0000000000000e-15 eq -1e-15
|
|
||||||
good: dg = -1.0300000000000e-15 eq -1.03e-15
|
|
||||||
good: dg = -1.0345000000000e-15 eq -1.0345e-15
|
|
||||||
good: dg = -1.0345000000000e-15 eq -1.0345e-15
|
|
||||||
good: dg = 1.0345000000000e+15 eq 1.0345e+15
|
|
||||||
good: dg = -1.0345000000000e+15 eq -1.0345e+15
|
|
||||||
good: dg = -1.0000000000000e+15 eq -1e+15
|
|
||||||
good: dg = -1.0000000000000e-02 eq -0.01
|
|
||||||
good: dg = 1.2000000000000e+00 eq 1.2
|
|
||||||
good: dg = 1.2000000000000e+01 eq 12
|
|
||||||
error dg = 1.0000000000000e+00 ne 0.99
|
|
||||||
good: dg = 1.1200000000000e+00 eq 1.12
|
|
||||||
good: dg = 1.0000000000000e-15 eq 1e-15
|
|
||||||
good: dg = 1.1000000000000e-15 eq 1.1e-15
|
|
||||||
good: dg = 0.0000000000000e+00 eq 0
|
|
||||||
good: dg = 1.1200000000000e+08 eq 1.12e+08
|
|
||||||
1.1000E-14 -- should be 1.1000E-14
|
|
||||||
1.0000E-14 -- should be 1.0000E-14
|
|
||||||
" 0.0000E+00" -- should be " 0.0000E+00"
|
|
||||||
" 1.1235E-14" -- should be 1.1235E-14
|
|
||||||
" 1.12E-14" -- should be " 1.12E-14"
|
|
||||||
"1.12E-14" -- should be "1.12E-14"
|
|
||||||
1.12E-04 -- should be 1.12E-14
|
|
||||||
1.1E-109 -- should be 1.1E-109
|
|
||||||
1.123E-19 -- should be 1.123E-19
|
|
||||||
-1.100E-19 -- should be -1.00E-19
|
|
||||||
-1.1000E-19 -- should be -1.1000E-19
|
|
||||||
-1.13E-19 -- should be -1.13E-19
|
|
||||||
-1.130E-19 -- should be -1.130E-19
|
|
||||||
"-1.130E-19" -- should be "-1.130E-19"
|
|
||||||
good: dg = 1.2000000000000e-01 eq 0.12
|
|
||||||
error dg = -1.0400000000000e+15 ne -1.03e+15
|
|
||||||
good: dg = 1.0345000000000e-270 eq 1.0345e-270
|
|
||||||
good: dg = 1.0300000000000e-15 eq 1.03e-15
|
|
||||||
good: dg = 1.0345000000000e-15 eq 1.0345e-15
|
|
||||||
good: dg = 1.0000000000000e-15 eq 1e-15
|
|
||||||
good: dg = -1.0000000000000e-15 eq -1e-15
|
|
||||||
good: dg = -1.0300000000000e-15 eq -1.03e-15
|
|
||||||
good: dg = -1.0345000000000e-15 eq -1.0345e-15
|
|
||||||
good: dg = -1.0345000000000e-15 eq -1.0345e-15
|
|
||||||
good: dg = 1.0345000000000e+15 eq 1.0345e+15
|
|
||||||
good: dg = -1.0345000000000e+15 eq -1.0345e+15
|
|
||||||
good: dg = -1.0000000000000e+15 eq -1e+15
|
|
||||||
good: dg = -1.0000000000000e-02 eq -0.01
|
|
||||||
good: dg = 1.2000000000000e+00 eq 1.2
|
|
||||||
good: dg = 1.2000000000000e+01 eq 12
|
|
||||||
error dg = 1.0000000000000e+00 ne 0.99
|
|
||||||
good: dg = 1.1200000000000e+00 eq 1.12
|
|
||||||
good: dg = 1.0000000000000e-15 eq 1e-15
|
|
||||||
good: dg = 1.1000000000000e-15 eq 1.1e-15
|
|
||||||
good: dg = 0.0000000000000e+00 eq 0
|
|
||||||
good: dg = 1.1200000000000e+08 eq 1.12e+08
|
|
||||||
1.1000E-14 -- should be 1.1000E-14
|
|
||||||
1.0000E-14 -- should be 1.0000E-14
|
|
||||||
" 0.0000E+00" -- should be " 0.0000E+00"
|
|
||||||
" 1.1235E-14" -- should be 1.1235E-14
|
|
||||||
" 1.12E-14" -- should be " 1.12E-14"
|
|
||||||
"1.12E-14" -- should be "1.12E-14"
|
|
||||||
1.12E-04 -- should be 1.12E-14
|
|
||||||
1.1E-109 -- should be 1.1E-109
|
|
||||||
1.123E-19 -- should be 1.123E-19
|
|
||||||
-1.100E-19 -- should be -1.00E-19
|
|
||||||
-1.1000E-19 -- should be -1.1000E-19
|
|
||||||
-1.13E-19 -- should be -1.13E-19
|
|
||||||
-1.130E-19 -- should be -1.130E-19
|
|
||||||
|
|
@ -1,569 +0,0 @@
|
||||||
#include <fstream>
|
|
||||||
#include <cmath>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "cantera/base/PrintCtrl.h"
|
|
||||||
#include "base/LogPrintCtrl.h"
|
|
||||||
#include "cantera/base/global.h"
|
|
||||||
|
|
||||||
using namespace Cantera;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
bool dnequl(const double a, const double b, int isig)
|
|
||||||
{
|
|
||||||
|
|
||||||
double atol = fabs(a) + fabs(b);
|
|
||||||
double asig = pow(10.0, -isig);
|
|
||||||
if (asig > 1.0E-6) {
|
|
||||||
asig = 1.0E-6;
|
|
||||||
}
|
|
||||||
|
|
||||||
double c = fabs(a - b);
|
|
||||||
if (c > atol * asig) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void doCheck(const double a, const double b, int isig)
|
|
||||||
{
|
|
||||||
if (dnequl(a, b, isig)) {
|
|
||||||
printf("error dg = %20.13e ne %g \n", a, b);
|
|
||||||
} else {
|
|
||||||
printf("good: dg = %20.13e eq %g \n", a, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void doLogger()
|
|
||||||
{
|
|
||||||
|
|
||||||
LogPrintCtrl ppc;
|
|
||||||
ostream ffs(cout.rdbuf());
|
|
||||||
double d, dg;
|
|
||||||
int nsig, p, w, wMax, wMin;
|
|
||||||
int Ncrop10;
|
|
||||||
|
|
||||||
d = 0.12345;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 0.12, nsig);
|
|
||||||
|
|
||||||
d = -1.0375E15;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.03E15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.0345E-270;
|
|
||||||
nsig = 5;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0345E-270, nsig);
|
|
||||||
|
|
||||||
d = 1.0345E-15;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.03E-15, nsig);
|
|
||||||
|
|
||||||
d = 1.0345E-15;
|
|
||||||
nsig = 5;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0345E-15, nsig);
|
|
||||||
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.03E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 5;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0345E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 7;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0345E-15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.0345E15;
|
|
||||||
nsig = 7;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0345E15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E15;
|
|
||||||
nsig = 7;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0345E15, nsig);
|
|
||||||
|
|
||||||
d = -1.0305E15;
|
|
||||||
nsig = 1;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0E15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = -10.E-3;
|
|
||||||
nsig = 4;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -10E-3, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.2345;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.2, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 12.345;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 12., nsig);
|
|
||||||
|
|
||||||
d = 0.9999;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 0.99, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.1234;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.12, nsig);
|
|
||||||
|
|
||||||
Ncrop10 = -15;
|
|
||||||
d = 1.1234E-15;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 1.0E-15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
Ncrop10 = -16;
|
|
||||||
d = 1.1234E-15;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 1.1E-15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ncrop10 = -14;
|
|
||||||
d = 1.1234E-15;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 0.0, nsig);
|
|
||||||
|
|
||||||
Ncrop10 = 6;
|
|
||||||
d = 1.1234E8;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 1.12E8, nsig);
|
|
||||||
|
|
||||||
ppc.setNdec(-15);
|
|
||||||
d = 1.1234E-14;
|
|
||||||
p = 5;
|
|
||||||
w = 20;
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << " -- should be 1.1000E-14" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-14);
|
|
||||||
d = 1.1234E-14;
|
|
||||||
p = 5;
|
|
||||||
w = 20;
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << " -- should be 1.0000E-14" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-13);
|
|
||||||
d = 1.1234E-14;
|
|
||||||
p = 5;
|
|
||||||
wMin = 20;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, wMin);
|
|
||||||
ffs << "\" -- should be \" 0.0000E+00\" " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-14;
|
|
||||||
p = 5;
|
|
||||||
w = 20;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << "\" -- should be 1.1235E-14" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-14;
|
|
||||||
p = 3;
|
|
||||||
w = 17;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << "\" -- should be \" 1.12E-14\"" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-14;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 8;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << "\" -- should be \"1.12E-14\" " << endl;
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-4;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 8;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be 1.12E-14 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-120);
|
|
||||||
d = 1.1234567E-109;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 8;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be 1.1E-109 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-120);
|
|
||||||
d = 1.1234567E-19;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 9;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be 1.123E-19 " << endl;
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = -1.1234567E-19;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 10;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.00E-19 " << endl;
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = -1.1234567E-19;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 11;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.1000E-19 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-25);
|
|
||||||
d = -1.1274567E-19;
|
|
||||||
p = 3;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 10;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.13E-19 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-25);
|
|
||||||
d = -1.127401E-19;
|
|
||||||
double dd = ppc.cropSigDigits(d, 3);
|
|
||||||
p = 4;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 10;
|
|
||||||
ppc.pr_de_c10(dd, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.130E-19 " << endl;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
suppress_deprecation_warnings();
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
_set_output_format(_TWO_DIGIT_EXPONENT);
|
|
||||||
#endif
|
|
||||||
// How to connect to a file:
|
|
||||||
// ofstream fff("redirect.txt");
|
|
||||||
// ostream ffs(fff.rdbuf());
|
|
||||||
|
|
||||||
// How to connect to a string:
|
|
||||||
// std::ostringstream os;
|
|
||||||
// ostream ffss(os.rdbuf());
|
|
||||||
|
|
||||||
ostream ffs(cout.rdbuf());
|
|
||||||
|
|
||||||
PrintCtrl ppc(ffs);
|
|
||||||
|
|
||||||
double d, dg;
|
|
||||||
int nsig, p, w, wMax, wMin;
|
|
||||||
int Ncrop10;
|
|
||||||
|
|
||||||
d = 0.12345;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 0.12, nsig);
|
|
||||||
|
|
||||||
d = -1.0375E15;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.03E15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.0345E-270;
|
|
||||||
nsig = 5;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0345E-270, nsig);
|
|
||||||
|
|
||||||
d = 1.0345E-15;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.03E-15, nsig);
|
|
||||||
|
|
||||||
d = 1.0345E-15;
|
|
||||||
nsig = 5;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0345E-15, nsig);
|
|
||||||
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.03E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 5;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0345E-15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E-15;
|
|
||||||
nsig = 7;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0345E-15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.0345E15;
|
|
||||||
nsig = 7;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.0345E15, nsig);
|
|
||||||
|
|
||||||
d = -1.0345E15;
|
|
||||||
nsig = 7;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0345E15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = -1.0305E15;
|
|
||||||
nsig = 1;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -1.0E15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = -10.E-3;
|
|
||||||
nsig = 4;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, -10E-3, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.2345;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.2, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 12.345;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 12., nsig);
|
|
||||||
|
|
||||||
d = 0.9999;
|
|
||||||
nsig = 2;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 0.99, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
d = 1.1234;
|
|
||||||
nsig = 3;
|
|
||||||
dg = ppc.cropSigDigits(d, nsig);
|
|
||||||
doCheck(dg, 1.12, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
Ncrop10 = -15;
|
|
||||||
d = 1.1234E-15;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 1.0E-15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
Ncrop10 = -16;
|
|
||||||
d = 1.1234E-15;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 1.1E-15, nsig);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ncrop10 = -14;
|
|
||||||
d = 1.1234E-15;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 0.0, nsig);
|
|
||||||
|
|
||||||
Ncrop10 = 6;
|
|
||||||
d = 1.1234E8;
|
|
||||||
|
|
||||||
dg = ppc.cropAbs10(d, Ncrop10);
|
|
||||||
doCheck(dg, 1.12E8, nsig);
|
|
||||||
|
|
||||||
ppc.setNdec(-15);
|
|
||||||
d = 1.1234E-14;
|
|
||||||
p = 5;
|
|
||||||
w = 20;
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << " -- should be 1.1000E-14" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-14);
|
|
||||||
d = 1.1234E-14;
|
|
||||||
p = 5;
|
|
||||||
w = 20;
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << " -- should be 1.0000E-14" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-13);
|
|
||||||
d = 1.1234E-14;
|
|
||||||
p = 5;
|
|
||||||
wMin = 20;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, wMin);
|
|
||||||
ffs << "\" -- should be \" 0.0000E+00\" " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-14;
|
|
||||||
p = 5;
|
|
||||||
w = 20;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << "\" -- should be 1.1235E-14" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-14;
|
|
||||||
p = 3;
|
|
||||||
w = 17;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, w);
|
|
||||||
ffs << "\" -- should be \" 1.12E-14\"" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-14;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 8;
|
|
||||||
ffs << "\"";
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << "\" -- should be \"1.12E-14\" " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = 1.1234567E-4;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 8;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be 1.12E-14 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-120);
|
|
||||||
d = 1.1234567E-109;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 8;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be 1.1E-109 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-120);
|
|
||||||
d = 1.1234567E-19;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 9;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be 1.123E-19 " << endl;
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = -1.1234567E-19;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 10;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.00E-19 " << endl;
|
|
||||||
|
|
||||||
ppc.setNdec(-20);
|
|
||||||
d = -1.1234567E-19;
|
|
||||||
p = 5;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 11;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.1000E-19 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-25);
|
|
||||||
d = -1.1274567E-19;
|
|
||||||
p = 3;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 10;
|
|
||||||
ppc.pr_de_c10(d, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.13E-19 " << endl;
|
|
||||||
|
|
||||||
|
|
||||||
ppc.setNdec(-25);
|
|
||||||
d = -1.127401E-19;
|
|
||||||
double dd = ppc.cropSigDigits(d, 3);
|
|
||||||
p = 4;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 10;
|
|
||||||
ppc.pr_de_c10(dd, p, wMin, wMax);
|
|
||||||
ffs << " -- should be -1.130E-19 " << endl;
|
|
||||||
|
|
||||||
// Example of attaching to a stringstream and then outputting
|
|
||||||
// from the string.
|
|
||||||
std::ostringstream os;
|
|
||||||
ostream ffss(os.rdbuf());
|
|
||||||
PrintCtrl ppss(ffss);
|
|
||||||
|
|
||||||
ppss.setNdec(-25);
|
|
||||||
d = -1.127401E-19;
|
|
||||||
dd = ppss.cropSigDigits(d, 3);
|
|
||||||
p = 4;
|
|
||||||
wMin = 3;
|
|
||||||
wMax = 10;
|
|
||||||
ppss.pr_de_c10(dd, p, wMin, wMax);
|
|
||||||
ffs << "\"";
|
|
||||||
ffs << os.str();
|
|
||||||
ffs << "\" -- should be \"-1.130E-19\" " << endl;
|
|
||||||
|
|
||||||
doLogger();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
temp_success="1"
|
|
||||||
/bin/rm -f output.txt outputa.txt
|
|
||||||
tname="printUtilUnitTest"
|
|
||||||
|
|
||||||
#################################################################
|
|
||||||
#
|
|
||||||
#################################################################
|
|
||||||
CANTERA_DATA=${CANTERA_DATA:=../../data/inputs}; export CANTERA_DATA
|
|
||||||
|
|
||||||
CANTERA_BIN=${CANTERA_BIN:=../../bin}
|
|
||||||
./pUtest > output.txt
|
|
||||||
retnStat=$?
|
|
||||||
if [ $retnStat != "0" ]
|
|
||||||
then
|
|
||||||
temp_success="0"
|
|
||||||
echo "$tname ($tname test) returned with bad status, $retnStat, check output"
|
|
||||||
fi
|
|
||||||
|
|
||||||
../../bin/exp3to2.sh output.txt > outputa.txt
|
|
||||||
diff -w outputa.txt output_blessed.txt > diff_test.out
|
|
||||||
retnStat=$?
|
|
||||||
if [ $retnStat = "0" ]
|
|
||||||
then
|
|
||||||
echo "successful diff comparison on $tname test"
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo "unsuccessful diff comparison on $tname test"
|
|
||||||
echo "FAILED" > csvCode.txt
|
|
||||||
temp_success="0"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue