Skip to content

Commit

Permalink
Fix EventPreNexus & RKH file checks. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jul 4, 2013
1 parent 7d124b9 commit 0e0bd35
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadEventPreNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ int LoadEventPreNexus::confidence(Kernel::FileDescriptor & descriptor) const

// If this looks like a binary file where the exact file length is a multiple
// of the DasEvent struct then we're probably okay.
if(descriptor.isAscii()) return 0;

const size_t objSize = sizeof(DasEvent);
auto &handle = descriptor.data();
// get the size of the file in bytes and reset the handle back to the beginning
handle.seekg(0, std::ios::end);
const size_t filesize = static_cast<size_t>(handle.tellg());
handle.seekg(0, std::ios::beg);

if (filesize % objSize != 0) return 80;
if (filesize % objSize == 0) return 80;
else return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,16 @@ int LoadEventPreNexus2::confidence(Kernel::FileDescriptor & descriptor) const

// If this looks like a binary file where the exact file length is a multiple
// of the DasEvent struct then we're probably okay.
if(descriptor.isAscii()) return 0;

const size_t objSize = sizeof(DasEvent);
auto &handle = descriptor.data();
// get the size of the file in bytes and reset the handle back to the beginning
handle.seekg(0, std::ios::end);
const size_t filesize = static_cast<size_t>(handle.tellg());
handle.seekg(0, std::ios::beg);

if (filesize % objSize != 0) return 80;
if (filesize % objSize == 0) return 80;
else return 0;
}

Expand Down
18 changes: 8 additions & 10 deletions Code/Mantid/Framework/DataHandling/src/LoadRKH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ int LoadRKH::confidence(Kernel::FileDescriptor & descriptor) const
{
if(!descriptor.isAscii()) return 0;

typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(" ");

auto &file = descriptor.data();
std::string fileline("");

Expand All @@ -54,15 +51,16 @@ int LoadRKH::confidence(Kernel::FileDescriptor & descriptor) const

// -- First line --
std::getline(file, fileline);
// LOQ or SANS2D
if(fileline.find("LOQ") == std::string::npos && fileline.find("SANS2D") == std::string::npos) return 0;
// LOQ or SANS2D (case insensitive)
if(boost::ifind_first(fileline, "loq").empty() && boost::ifind_first(fileline, "sans2d").empty()) return 0;

// Next should be date time string
static const char* MONTHS[12] = {"-JAN-", "-FEB-", "-MAR-", "-APR-", "-MAY-", "-JUN-", "-JUL-", "-AUG-", "-SEP-", "-OCT-", "-NOV-", "-DEC-"};

bool foundMonth(false);
for(size_t i = 0 ; i < 12; ++i)
{
if(fileline.find(MONTHS[i]) != std::string::npos)
if(!boost::ifind_first(fileline, MONTHS[i]).empty())
{
foundMonth = true;
break;
Expand All @@ -73,13 +71,13 @@ int LoadRKH::confidence(Kernel::FileDescriptor & descriptor) const
// there are no constraints on the second line
std::getline(file, fileline);

// read 3rd line - should contain sequence " 0 0 0 1"
// read 3rd line - should contain sequence "0 0 0 1"
std::getline(file, fileline);
if(fileline.find(" 0 0 0 1") == std::string::npos) return 0;
if(fileline.find("0 0 0 1") == std::string::npos) return 0;

// read 4th line - should contain sequence " 0 0 0 1"
// read 4th line - should contain sequence ""0 0 0 0"
std::getline(file, fileline);
if(fileline.find(" 0 0 0 0") == std::string::npos) return 0;
if(fileline.find("0 0 0 0") == std::string::npos) return 0;

// read 5th line - should contain sequence "3 (F12.5,2E16.6)"
std::getline(file, fileline);
Expand Down

0 comments on commit 0e0bd35

Please sign in to comment.