Skip to content

Commit

Permalink
Refs #8958 Save Algorithm Written
Browse files Browse the repository at this point in the history
The algorithm outputs the same data as the python script wiht the exception of inf and nan where it prints them in a different form.

Owen has said that it should be ok and we'll get the scientists to check
  • Loading branch information
keithnbrown committed Feb 12, 2014
1 parent b922bc4 commit 357a8e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Expand Up @@ -34,8 +34,7 @@ namespace Mantid
///static reference to the logger class
static Kernel::Logger& g_log;

/// Map the separator options to their string equivalents
std::map<std::string,std::string> m_separatorIndex;
API::MatrixWorkspace_const_sptr m_ws;
};

} // namespace DataHandling
Expand Down
34 changes: 33 additions & 1 deletion Code/Mantid/Framework/DataHandling/src/SaveANSTO.cpp
Expand Up @@ -39,20 +39,52 @@ namespace Mantid
Logger& SaveANSTO::g_log = Logger::get("SaveANSTO");

/// Empty constructor
SaveANSTO::SaveANSTO() : m_separatorIndex()
SaveANSTO::SaveANSTO()
{
}

/// Initialisation method.
void SaveANSTO::init()
{
declareProperty(new WorkspaceProperty<>("InputWorkspace",
"",Direction::Input), "The name of the workspace containing the data you want to save to a ANSTO file.");

std::vector<std::string> exts;
exts.push_back(".txt");
declareProperty(new FileProperty("Filename", "", FileProperty::Save, exts),
"The filename of the output ANSTO file.");
}

/**
* Executes the algorithm.
*/
void SaveANSTO::exec()
{
std::string filename = getProperty("Filename");
std::ofstream file(filename.c_str());
m_ws = getProperty("InputWorkspace");
g_log.information("FILENAME: " + filename);
auto title ='#'+ m_ws->getTitle();
auto x1 = m_ws->readX(0);
const size_t xlength = x1.size() - 1;
std::vector<double> X1;
X1.resize(xlength, 0);
for (int i = 0; i < xlength; ++i)
{
X1[i]=(x1[i]+x1[i+1])/2.0;
}
auto y1 = m_ws->readY(0);
auto e1 = m_ws->readE(0);
char sep = '\t';
double qres = (X1[1]-X1[0])/X1[1];
g_log.information("Constant dq/q from file: " + boost::lexical_cast<std::string>(qres));
file << std::scientific;
for (int i = 0; i < xlength; ++i)
{
double dq = X1[i]*qres;
file << X1[i] << sep << y1[i] << sep << e1[i] << sep << dq << std::endl;
}
file.close();
}
} // namespace DataHandling
} // namespace Mantid

0 comments on commit 357a8e4

Please sign in to comment.