diff --git a/Code/Mantid/API/inc/MantidAPI/IDataFileChecker.h b/Code/Mantid/API/inc/MantidAPI/IDataFileChecker.h index e89cd04c1be92635aa6b4cce12fab3612b23f35a..30f89f48247337880268f4d4c14f8ced41fb720a 100644 --- a/Code/Mantid/API/inc/MantidAPI/IDataFileChecker.h +++ b/Code/Mantid/API/inc/MantidAPI/IDataFileChecker.h @@ -3,7 +3,9 @@ #include<string> #include "MantidAPI/Algorithm.h" - +static const unsigned char hdf5_signature[] = { '\211', 'H', 'D', 'F', '\r', '\n', '\032', '\n' }; +static const int bufferSize=100; + namespace Mantid { namespace API @@ -39,10 +41,7 @@ namespace Mantid Code Documentation is available at: <http://doxygen.mantidproject.org> */ -static const unsigned char hdf5_signature[] = { '\211', 'H', 'D', 'F', '\r', '\n', '\032', '\n' }; -static const int bufferSize=100; - class DLLExport IDataFileChecker: public API::Algorithm { public: diff --git a/Code/Mantid/DataHandling/inc/MantidDataHandling/Load.h b/Code/Mantid/DataHandling/inc/MantidDataHandling/Load.h index 23d6f5c257a86df016c38e41bcf14b08a461b0fd..bc7a39fdd96bf9a2528b49697da01df6cf644e08 100644 --- a/Code/Mantid/DataHandling/inc/MantidDataHandling/Load.h +++ b/Code/Mantid/DataHandling/inc/MantidDataHandling/Load.h @@ -6,10 +6,13 @@ //---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" #include "MantidAPI/IDataFileChecker.h" + + namespace Mantid { namespace DataHandling - { + { + /** Loads a workspace from a data file. The algorithm tries to determine the actual type of the file (raw, nxs, ...) and use the specialized loading algorith to load it. @@ -38,7 +41,7 @@ namespace Mantid Code Documentation is available at: <http://doxygen.mantidproject.org> */ - static const int bufferSize=100; + class DLLExport Load : public API::Algorithm { public: diff --git a/Code/Mantid/DataHandling/src/Load.cpp b/Code/Mantid/DataHandling/src/Load.cpp index dc3aef2fc3ac3d537e9cdaec1b72cbb2e8c4d314..64bf0ca1afddf661bae4f5764a42e42df9f23f52 100644 --- a/Code/Mantid/DataHandling/src/Load.cpp +++ b/Code/Mantid/DataHandling/src/Load.cpp @@ -9,6 +9,7 @@ #include "MantidAPI/LoadAlgorithmFactory.h" #include<algorithm> + namespace Mantid { namespace DataHandling @@ -52,15 +53,25 @@ namespace Mantid declareProperty("SpectrumMax", EMPTY_INT(), mustBePositive->clone()); declareProperty(new ArrayProperty<int>("SpectrumList")); } - + /** checks this property exists in the list of algorithm properties. + */ struct hasProperty { + /** constructor which takes 1 arguement. + *@param name - name of the property + */ hasProperty(const std::string name):m_name(name){} + + /**This method comapres teh property name + *@param prop - shared pointer to property + *@return true if the property exists in the list of properties. + */ bool operator()(Mantid::Kernel::Property* prop) { std::string name=prop->name(); return (!name.compare(m_name)); } + /// name of teh property std::string m_name; }; @@ -80,7 +91,7 @@ namespace Mantid { throw std::runtime_error("Cannot load file " + fileName); } - g_log.debug()<<"The sub algorithm name is "<<alg->name()<<std::endl; + g_log.information()<<"The sub load algorithm created to execute is "<<alg->name()<<" and it version is "<<alg->version()<<std::endl; double startProgress=0,endProgress=1; // set the load algorithm as a child algorithm initialiseLoadSubAlgorithm(alg,startProgress,endProgress,true,-1); @@ -98,13 +109,14 @@ namespace Mantid //if the load sub algorithm has the same property then set it. prop=std::find_if(loader_props.begin(),loader_props.end(),hasProperty((*itr)->name())); if(prop!=loader_props.end()) - { + { + alg->setPropertyValue((*prop)->name(),getPropertyValue((*prop)->name())); - } + } } //execute the load sub algorithm - alg->execute(); + alg->execute(); //se the workspace setOutputWorkspace(alg); @@ -209,7 +221,7 @@ namespace Mantid /** * Set the output workspace(s) if the load's return workspace * has type API::Workspace - *@param shared pointer to load algorithm + *@param load shared pointer to load algorithm */ void Load::setOutputWorkspace(API::IAlgorithm_sptr& load) { diff --git a/Code/Mantid/DataHandling/src/LoadAscii.cpp b/Code/Mantid/DataHandling/src/LoadAscii.cpp index 72092280c80ffb637ae1928e5a2b6beeb4874415..3e2ce799d8a09a025ba90df1c9985b15748d38ce 100644 --- a/Code/Mantid/DataHandling/src/LoadAscii.cpp +++ b/Code/Mantid/DataHandling/src/LoadAscii.cpp @@ -199,14 +199,6 @@ namespace Mantid g_log.error("Unable to open file: " + filePath); throw Exception::FileError("Unable to open file: " , filePath); } - //set up the separators - /*std::map<std::string,const char*>::const_iterator it; - std::string separators; - for(it=m_separatormap.begin();it!=m_separatormap.end();++it) - { - separators+=it->second; - } -*/ std::string separators(","); int ncols=0; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; @@ -216,44 +208,23 @@ namespace Mantid while(!file.eof()) { getline(file,line) ; - if (line.empty()) + if (line.empty()||line[0] == '#') { continue; } - - if(line.at(0) == '#') - { - try - { - if(line.at(1)=='L') - { - return 0; - } - } - catch(std::out_of_range&) - { - continue; - } - } else { - //break at a non empty line + //break at a non empty/non comment line is teh 1st data line break; } } + //iterarte through the first line cloumns boost::tokenizer<boost::char_separator<char> > values(line, seps); for (tokenizer::iterator it = values.begin(); it != values.end(); ++it) { ++ncols; } - - //if the line has odd number of coulmns with mantid supported separators - // this is considered as ascci file - if (ncols % 2 == 1 && ncols>2) - { - bret+=40; - } bool bloadAscii(true); //if the data is of double type this file can be loaded by loadascci double data; @@ -268,10 +239,16 @@ namespace Mantid } } - if(bloadAscii) + //if the line has odd number of coulmns with mantid supported separators + // this is considered as ascci file + if (ncols % 2 == 1 && ncols>2 && bloadAscii) + { + bret=80; + } + /*if(bloadAscii) { bret+=40; - } + }*/ return bret; } diff --git a/Code/Mantid/DataHandling/src/LoadSNSspec.cpp b/Code/Mantid/DataHandling/src/LoadSNSspec.cpp index ce774d988ce69031ae5eb6a3092974029ba431fa..8f6e03528d7a59032964d1fdc2f29521987468c9 100644 --- a/Code/Mantid/DataHandling/src/LoadSNSspec.cpp +++ b/Code/Mantid/DataHandling/src/LoadSNSspec.cpp @@ -195,7 +195,7 @@ namespace Mantid } /**checks the file by opening it and reading few lines - * @param filePath name of the file inluding its path + * @param filePath name of the file including its path * @return an integer value how much this algorithm can load the file */ int LoadSNSspec::fileCheck(const std::string& filePath) @@ -208,11 +208,12 @@ namespace Mantid } int bret=0; - int ncols=0; + int axiscols=0; + int datacols=0; std::string str; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" "); - + bool bsnsspec(false); while(!file.eof()) { //read line @@ -231,28 +232,24 @@ namespace Mantid tokenizer tok(str, sep); for (tokenizer::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { - ++ncols; + ++axiscols; } //if the file contains a comment line starting with "#L" followed - //by three columns this could be load spec file - if(ncols>3) - { - bret+=40; + //by three columns this could be loadsnsspec file + if(axiscols>2) + { + bsnsspec=true; } } } - else //first non comment line is data line - { - ncols=0; + else + { + //check first data line is a 3 column line tokenizer tok(str, sep); for (tokenizer::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { - ++ncols; + ++datacols; } - if(ncols==3) - { - bret+=40; - } break; } } @@ -260,7 +257,10 @@ namespace Mantid { } } - + if(bsnsspec && datacols==3 )//three column data + { + bret=80; + } return bret; } } // namespace DataHandling diff --git a/Code/Mantid/DataHandling/src/LoadSPE.cpp b/Code/Mantid/DataHandling/src/LoadSPE.cpp index ca469d1d15aadaec0adff7c54c22468760462565..17b9da0b510124e2aa842b0e85254b82fdda612e 100644 --- a/Code/Mantid/DataHandling/src/LoadSPE.cpp +++ b/Code/Mantid/DataHandling/src/LoadSPE.cpp @@ -260,31 +260,44 @@ int LoadSPE::fileCheck(const std::string& filePath) g_log.error("Unable to open file: " + filePath); throw Exception::FileError("Unable to open file: " , filePath); } - int bret=0; std::string fileline; //read first line getline(file,fileline); boost::char_separator<char> sep(" "); int ncols=0; + bool isnumeric(false); + bool b(true); typedef boost::tokenizer<boost::char_separator<char> > tokenizer; tokenizer tok(fileline,sep); + //in the spe file first line is expecetd to be a line 2 colomns which is histogram & bin numbers for (tokenizer::iterator beg=tok.begin();beg!=tok.end();++beg) { ++ncols; + std::stringstream stream(*beg); + unsigned int hist_bin; + stream>>hist_bin; + b=b&&(!stream.fail()); + } - if(ncols==2) + isnumeric =b; + bool bspe(false); + //if the first line has two numeric data columns + if(ncols==2 && isnumeric) { - bret+=40; + bspe=true; } // Next line should be comment line: "### Phi Grid" or "### Q Grid" std::string commentline; getline(file,commentline); if(commentline.find("Phi Grid")!=std::string::npos|| commentline.find("Q Grid")!=std::string::npos ) { - bret+=40; + if(bspe) + { + return 80; + } } - return bret; + return 0; } diff --git a/Code/Mantid/DataHandling/test/runTests.bat b/Code/Mantid/DataHandling/test/runTests.bat index e06ab95ad48a071525d01aecf848a95e7e5f50ae..5f148f3ee320c83995538263b2cd050a9b8b2286 100644 --- a/Code/Mantid/DataHandling/test/runTests.bat +++ b/Code/Mantid/DataHandling/test/runTests.bat @@ -13,12 +13,12 @@ echo "Generating the source from the test header files..." IF "%1" == "" GOTO BUILD_ALL ELSE GOTO BUILD_ONE :BUILD_ONE ECHO Building only %1 -python ..\..\..\Third_Party\src\cxxtest\cxxtestgen.py --error-printer -o runner.cpp %1 +python ..\..\..\Third_Party\src\cxxtest\cxxtestgen.py --runner=MantidPrinter -o runner.cpp %1 GOTO COMPILE :BUILD_ALL ECHO Building all .h files -python ..\..\..\Third_Party\src\cxxtest\cxxtestgen.py --error-printer -o runner.cpp *.h +python ..\..\..\Third_Party\src\cxxtest\cxxtestgen.py --runner=MantidPrinter -o runner.cpp *.h GOTO COMPILE :COMPILE