-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
372 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/FixGSASInstrumentFile.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
139
Code/Mantid/Framework/Algorithms/src/FixGSASInstrumentFile.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.