Skip to content

Commit

Permalink
Merge remote branch 'origin/feature/7948_correct_gsas_format'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vickie Lynch committed Oct 29, 2013
2 parents 1386048 + 851f1f7 commit c559327
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 14 deletions.
9 changes: 6 additions & 3 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ set ( SRC_FILES
src/FindCenterOfMassPosition2.cpp
src/FindDeadDetectors.cpp
src/FindDetectorsOutsideLimits.cpp
src/FindPeaks.cpp
src/FindPeakBackground.cpp
src/FitPeak.cpp
src/FindPeaks.cpp
src/FixGSASInstrumentFile.cpp
src/FlatPlateAbsorption.cpp
src/GeneralisedSecondDifference.cpp
src/GenerateEventsFilter.cpp
Expand Down Expand Up @@ -318,9 +319,10 @@ set ( INC_FILES
inc/MantidAlgorithms/FindCenterOfMassPosition2.h
inc/MantidAlgorithms/FindDeadDetectors.h
inc/MantidAlgorithms/FindDetectorsOutsideLimits.h
inc/MantidAlgorithms/FindPeaks.h
inc/MantidAlgorithms/FindPeakBackground.h
inc/MantidAlgorithms/FitPeak.h
inc/MantidAlgorithms/FindPeaks.h
inc/MantidAlgorithms/FixGSASInstrumentFile.h
inc/MantidAlgorithms/FlatPlateAbsorption.h
inc/MantidAlgorithms/GSLFunctions.h
inc/MantidAlgorithms/GeneralisedSecondDifference.h
Expand Down Expand Up @@ -543,9 +545,10 @@ set ( TEST_FILES
FindCenterOfMassPositionTest.h
FindDeadDetectorsTest.h
FindDetectorsOutsideLimitsTest.h
FindPeaksTest.h
FindPeakBackgroundTest.h
FitPeakTest.h
FindPeaksTest.h
FixGSASInstrumentFileTest.h
FlatPlateAbsorptionTest.h
GenerateEventsFilterTest.h
GeneratePeaksTest.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_ */
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidDataObjects/TableWorkspace.h"

namespace Mantid
Expand Down Expand Up @@ -71,7 +72,7 @@ class DLLExport SaveGSASInstrumentFile : public API::Algorithm
boost::shared_ptr<ChopperConfiguration> setupNOMConstants(int intfrequency);

/// Parse profile table workspace to a map
void parseProfileTableWorkspace(DataObjects::TableWorkspace_sptr ws,
void parseProfileTableWorkspace(API::ITableWorkspace_sptr ws,
std::map<unsigned int, std::map<std::string, double> >& profilemap);

/// Convert to GSAS instrument file
Expand Down Expand Up @@ -114,7 +115,8 @@ class DLLExport SaveGSASInstrumentFile : public API::Algorithm
double erfc(double xx);

/// Input workspace
DataObjects::TableWorkspace_sptr m_inpWS;
API::ITableWorkspace_sptr m_inpWS;
// DataObjects::TableWorkspace_sptr m_inpWS;

/// Instrument
std::string m_instrument;
Expand Down
136 changes: 136 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/FixGSASInstrumentFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#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.c_str(), 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;
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.c_str(), 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
26 changes: 23 additions & 3 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 @@ -351,7 +352,7 @@ ChopperConfiguration::ChopperConfiguration(const int freq, const std::string& ba
*/
void SaveGSASInstrumentFile::init()
{
declareProperty(new WorkspaceProperty<TableWorkspace>("InputWorkspace", "", Direction::Input, PropertyMode::Optional),
declareProperty(new WorkspaceProperty<ITableWorkspace>("InputWorkspace", "", Direction::Input, PropertyMode::Optional),
"Name of the table workspace containing the parameters.");

vector<string> infileexts;
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 Expand Up @@ -551,7 +571,7 @@ ChopperConfiguration::ChopperConfiguration(const int freq, const std::string& ba
//----------------------------------------------------------------------------------------------
/** Parse profile table workspace to a map (the new ...
*/
void SaveGSASInstrumentFile::parseProfileTableWorkspace(TableWorkspace_sptr ws,
void SaveGSASInstrumentFile::parseProfileTableWorkspace(ITableWorkspace_sptr ws,
map<unsigned int, map<string, double> >& profilemap)
{
size_t numbanks = ws->columnCount()-1;
Expand Down Expand Up @@ -959,7 +979,7 @@ ChopperConfiguration::ChopperConfiguration(const int freq, const std::string& ba
throw runtime_error(errss.str());
}

fprintf(pFile, "INS %2d ICONS%10.3f%10.3f%10.3f%10.3f%5d%10.3f\n", bankid, instC*1.00009, 0.0, zero,0.0, 0, 0.0);
fprintf(pFile, "INS %2d ICONS%10.3f%10.3f%10.3f %10.3f%5d%10.3f\n", bankid, instC*1.00009, 0.0, zero, 0.0, 0, 0.0);
fprintf(pFile, "INS %2dBNKPAR%10.3f%10.3f%10.3f%10.3f%10.3f%5d%5d\n", bankid, m_L2, twotheta, 0., 0., 0.2, 1, 1);

fprintf(pFile, "INS %2dBAKGD 1 4 Y 0 Y\n", bankid);
Expand Down

0 comments on commit c559327

Please sign in to comment.