Skip to content

Commit

Permalink
Resolved conflict. Refs #7948.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Oct 2, 2013
2 parents c203577 + 796c101 commit 7c4e090
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 196 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ set ( SRC_FILES
src/FindDetectorsOutsideLimits.cpp
src/FindPeakBackground.cpp
src/FindPeaks.cpp
src/FixGSASInstrumentFile.cpp
src/FlatBackground.cpp
src/FlatPlateAbsorption.cpp
src/GeneralisedSecondDifference.cpp
Expand Down Expand Up @@ -329,6 +330,7 @@ set ( INC_FILES
inc/MantidAlgorithms/FindDetectorsOutsideLimits.h
inc/MantidAlgorithms/FindPeakBackground.h
inc/MantidAlgorithms/FindPeaks.h
inc/MantidAlgorithms/FixGSASInstrumentFile.h
inc/MantidAlgorithms/FlatBackground.h
inc/MantidAlgorithms/FlatPlateAbsorption.h
inc/MantidAlgorithms/GSLFunctions.h
Expand Down Expand Up @@ -558,6 +560,7 @@ set ( TEST_FILES
FindDetectorsOutsideLimitsTest.h
FindPeakBackgroundTest.h
FindPeaksTest.h
FixGSASInstrumentFileTest.h
FlatBackgroundTest.h
FlatPlateAbsorptionTest.h
GenerateEventsFilterTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef MANTID_ALGORITHMS_FIXGSASINSTRUMENTFILE_H_
#define MANTID_ALGORITHMS_FIXGSASINSTRUMENTFILE_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"


namespace Mantid
{
namespace Algorithms
{

/** FixGSASInstrumentFile : TODO: DESCRIPTION
Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport FixGSASInstrumentFile : public API::Algorithm
{
public:
FixGSASInstrumentFile();
virtual ~FixGSASInstrumentFile();


/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "FixGSASInstrumentFile";}

/// Algorithm's version for identification overriding a virtual method
virtual int version() const { return 1;}

/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "Diffraction";}

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
/// Implement abstract Algorithm methods
void init();
/// Implement abstract Algorithm methods
void exec();

};


} // namespace Algorithms
} // namespace Mantid

#endif /* MANTID_ALGORITHMS_FIXGSASINSTRUMENTFILE_H_ */
139 changes: 139 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/FixGSASInstrumentFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "MantidAlgorithms/FixGSASInstrumentFile.h"

#include "MantidAPI/FileProperty.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/TableRow.h"

#include <fstream>

#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/iter_find.hpp>
#include <boost/algorithm/string/finder.hpp>
#include <boost/algorithm/string/predicate.hpp>

using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;

using namespace std;

namespace Mantid
{
namespace Algorithms
{

DECLARE_ALGORITHM(FixGSASInstrumentFile)

const size_t LINESIZE = 80;

//----------------------------------------------------------------------------------------------
/** Constructor
*/
FixGSASInstrumentFile::FixGSASInstrumentFile()
{
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
FixGSASInstrumentFile::~FixGSASInstrumentFile()
{
}

//----------------------------------------------------------------------------------------------
/** Sets documentation strings for this algorithm
*/
void FixGSASInstrumentFile::initDocs()
{
setWikiSummary("Fix format error in an GSAS instrument file.");
setOptionalMessage("Fix format error in an GSAS instrument file.");

return;
}

//----------------------------------------------------------------------------------------------
/** Implement abstract Algorithm methods
*/
void FixGSASInstrumentFile::init()
{
// Input file
vector<std::string> exts;
exts.push_back(".prm");
exts.push_back(".iparm");
declareProperty(new FileProperty("InputFilename", "", FileProperty::Load, exts),
"Name of the GSAS instrument parameter file to get fixed for format. ");

// Output file
declareProperty(new FileProperty("OutputFilename", "", FileProperty::Save, exts),
"Name of the output GSAS instrument parameter file to have format fixed. ");

return;
}

//----------------------------------------------------------------------------------------------
/** Execution
*/
void FixGSASInstrumentFile::exec()
{
// Properties
string infilename = getProperty("InputFilename");

// Parse file
vector<string> vec_line;
ifstream infile;
infile.open(infilename, ios::in);
if (!infile.is_open())
{
stringstream errss;
errss << "File " << infilename << " cannot be opened for reading. " << ".\n";
g_log.error(errss.str());
throw runtime_error(errss.str());
}
string line;
while (getline(infile, line))
{
// Split "\n"
vector <string> fields;

g_log.information() << "Original = \"" << line << "\"\n";

boost::algorithm::split( fields, line, boost::algorithm::is_any_of( "\n" ) );
if (fields.size() == 0)
throw runtime_error("Impossible to have an empty line. ");
vec_line.push_back(fields[0]);
}
infile.close();

// Write out
string outfilename = getPropertyValue("OutputFilename");
ofstream ofile;
ofile.open(outfilename, ios::out);
if (!ofile.is_open())
{
stringstream errss;
errss << "File " << outfilename << " cannot be opened for writing. " << ".\n";
g_log.error(errss.str());
throw runtime_error(errss.str());
}


for (size_t i = 0; i < vec_line.size(); ++i)
{
string& line = vec_line[i];
ofile << line;
for (size_t j = line.size(); j < LINESIZE; ++j)
ofile << " ";
ofile << "\n";
}

ofile.close();

return;
}



} // namespace Algorithms
} // namespace Mantid
20 changes: 20 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/SaveGSASInstrumentFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ There are 2 places in this algorithm that can set the value of <math>L_1</math>
*WIKI*/

#include "MantidAlgorithms/SaveGSASInstrumentFile.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/FileProperty.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/ArrayProperty.h"
Expand Down Expand Up @@ -429,6 +430,25 @@ ChopperConfiguration::ChopperConfiguration(const int freq, const std::string& ba
// Convert to GSAS
convertToGSAS(m_vecBankID2File, m_gsasFileName, bankprofileparammap);

// Fix?
Mantid::API::FrameworkManager::Instance();
IAlgorithm_sptr fit;
try
{
// Fitting the candidate peaks to a Gaussian
fit = createChildAlgorithm("FixGSASInstrumentFile", -1, -1, true);
fit->initialize();
fit->setProperty("InputFilename", m_gsasFileName);
fit->setProperty("OutputFilename", m_gsasFileName);
fit->execute();
}
catch (Exception::NotFoundError &)
{
std::string errorstr("FindPeaks algorithm requires the CurveFitting library");
g_log.error(errorstr);
throw std::runtime_error(errorstr);
}

return;
}

Expand Down

0 comments on commit 7c4e090

Please sign in to comment.