BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IOUtil Namespace Reference

Functions

bool filesAgree (const std::string &datFileName, const std::string &refFileName, double tol)
 Returns true if data in both files agree. More...
 

Function Documentation

◆ filesAgree()

bool IOUtil::filesAgree ( const std::string &  datFileName,
const std::string &  refFileName,
double  tol 
)

Returns true if data in both files agree.

Definition at line 189 of file IOFactory.cpp.

190 {
191  std::unique_ptr<Datafield> datDat;
192  try {
193  datDat.reset(IOFactory::readDatafield(datFileName));
194  } catch (const std::runtime_error& ex) {
195  std::cerr << "File comparison: Could not read data from file " << datFileName
196  << ". Runtime error: " << ex.what() << std::endl;
197  } catch (const std::exception& ex) {
198  std::cerr << "File comparison: Could not read data from file " << datFileName
199  << ". Exception: " << ex.what() << std::endl;
200  } catch (...) {
201  std::cerr << "File comparison: Could not read data from file " << datFileName
202  << ". Unknown exception." << std::endl;
203  return false;
204  }
205  ASSERT(datDat);
206 
207  std::unique_ptr<Datafield> refDat;
208  try {
209  refDat.reset(IOFactory::readDatafield(refFileName));
210  } catch (...) {
211  std::cerr << "File comparison: Could not read reference data from file " << refFileName
212  << std::endl;
213  return false;
214  }
215  ASSERT(refDat);
216 
217  return DiffUtil::checkRelativeDifference(datDat->flatVector(), refDat->flatVector(), tol);
218 }
#define ASSERT(condition)
Definition: Assert.h:45
static Datafield * readDatafield(const std::string &file_name, LoaderSelector selector=automatic)
Reads file and returns newly created Datafield object. If selector is automatic, then the file extens...
Definition: IOFactory.cpp:41
bool checkRelativeDifference(const std::vector< double > &dat, const std::vector< double > &ref, double threshold)
Returns true is relative difference is below threshold; prints informative output.
Definition: DiffUtil.cpp:64

References ASSERT, DiffUtil::checkRelativeDifference(), and IOFactory::readDatafield().

Here is the call graph for this function: