Chaste  Release::2017.1
NumericFileComparison Class Reference

#include <NumericFileComparison.hpp>

+ Inheritance diagram for NumericFileComparison:
+ Collaboration diagram for NumericFileComparison:

Public Member Functions

 NumericFileComparison (std::string fileName1, std::string fileName2, bool calledCollectively=true, bool suppressOutput=false)
 
 NumericFileComparison (const FileFinder &rFileName1, const FileFinder &rFileName2, bool calledCollectively=true, bool suppressOutput=false)
 
bool CompareFiles (double absTol=DBL_EPSILON, unsigned ignoreFirstFewLines=0, double relTol=DBL_EPSILON, bool doTsAssert=true)
 
- Public Member Functions inherited from AbstractFileComparison
 AbstractFileComparison (const FileFinder &rFileFinder1, const FileFinder &rFileFinder2, bool calledCollectively, bool suppressOutput)
 
 AbstractFileComparison (std::string fileName1, std::string fileName2, bool calledCollectively, bool suppressOutput)
 
virtual ~AbstractFileComparison ()
 

Private Member Functions

void ReadNextToken (std::ifstream *pFile, double &rData)
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractFileComparison
void ResetFiles ()
 
void SkipHeaderLines (unsigned numLinesToSkip)
 
- Protected Attributes inherited from AbstractFileComparison
std::string mFilename1
 
std::string mFilename2
 
std::ifstream * mpFile1
 
std::ifstream * mpFile2
 
unsigned mLineNum
 
bool mCalledCollectively
 
bool mSuppressOutput
 

Detailed Description

Compare files of numbers to see if they match to within a given tolerance.

Any differences in words are ignored, as are comment lines starting with '#' or '!'.

Definition at line 52 of file NumericFileComparison.hpp.

Constructor & Destructor Documentation

NumericFileComparison::NumericFileComparison ( std::string  fileName1,
std::string  fileName2,
bool  calledCollectively = true,
bool  suppressOutput = false 
)
inline

Specify two files to compare, and open them for reading. Actual comparison is done by calling CompareFiles.

Parameters
fileName1first file
fileName2second file
calledCollectivelyIf true there will be a barrier before opening files, and only master compares contents.
suppressOutputIf true then no errors will go to TS_TRACE(). Should only be set for the test of this class.

Definition at line 100 of file NumericFileComparison.hpp.

NumericFileComparison::NumericFileComparison ( const FileFinder rFileName1,
const FileFinder rFileName2,
bool  calledCollectively = true,
bool  suppressOutput = false 
)
inline

Specify two files to compare, and open them for reading. Actual comparison is done by calling CompareFiles.

Parameters
rFileName1first file
rFileName2second file
calledCollectivelyIf true there will be a barrier before opening files, and only master compares contents.
suppressOutputIf true then no errors will go to TS_TRACE(). Should only be set for the test of this class.

Definition at line 114 of file NumericFileComparison.hpp.

Member Function Documentation

bool NumericFileComparison::CompareFiles ( double  absTol = DBL_EPSILON,
unsigned  ignoreFirstFewLines = 0,
double  relTol = DBL_EPSILON,
bool  doTsAssert = true 
)
inline
Returns
true if the files are identical to within tolerance. Compare the files under both relative and absolute tolerances. The comparison only fails if neither tolerance holds. The default settings effectively require numbers to match exactly.
Parameters
absTolabsolute tolerance on difference between numbers
ignoreFirstFewLineshow many lines to ignore from the comparison
relTolrelative tolerance on difference between numbers
doTsAssertWhether to throw a TS_ASSERT internally (switched off for testing only)

Definition at line 131 of file NumericFileComparison.hpp.

References PetscTools::AmMaster(), AbstractFileComparison::mCalledCollectively, AbstractFileComparison::mFilename1, AbstractFileComparison::mFilename2, AbstractFileComparison::mpFile1, AbstractFileComparison::mpFile2, AbstractFileComparison::mSuppressOutput, ReadNextToken(), AbstractFileComparison::ResetFiles(), AbstractFileComparison::SkipHeaderLines(), and CompareDoubles::WithinAnyTolerance().

void NumericFileComparison::ReadNextToken ( std::ifstream *  pFile,
double rData 
)
inlineprivate

Read the next token in the file as a double.

If we detect a comment skip the line. If we detect a word assign the value A_WORD. If we find nothing to read assign NOTHING_TO_READ.

Parameters
pFileThe file from which to attempt to read a double.
rDataThe double to assign a value to.

Definition at line 65 of file NumericFileComparison.hpp.

Referenced by CompareFiles().


The documentation for this class was generated from the following file: