From 357a8e4a6dfd2a3e605bcb99ae97ede164f9e9f4 Mon Sep 17 00:00:00 2001 From: Keith Brown Date: Wed, 12 Feb 2014 12:24:31 +0000 Subject: [PATCH] Refs #8958 Save Algorithm Written 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 --- .../inc/MantidDataHandling/SaveANSTO.h | 3 +- .../Framework/DataHandling/src/SaveANSTO.cpp | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveANSTO.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveANSTO.h index b436dd2a3b59..9ff0a316efaf 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveANSTO.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveANSTO.h @@ -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 m_separatorIndex; + API::MatrixWorkspace_const_sptr m_ws; }; } // namespace DataHandling diff --git a/Code/Mantid/Framework/DataHandling/src/SaveANSTO.cpp b/Code/Mantid/Framework/DataHandling/src/SaveANSTO.cpp index 366f7d7c4121..ee536f79142b 100644 --- a/Code/Mantid/Framework/DataHandling/src/SaveANSTO.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SaveANSTO.cpp @@ -39,13 +39,20 @@ 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 exts; + exts.push_back(".txt"); + declareProperty(new FileProperty("Filename", "", FileProperty::Save, exts), + "The filename of the output ANSTO file."); } /** @@ -53,6 +60,31 @@ namespace Mantid */ 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 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(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