Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/8960_SaveILLCosmos_Algor…
Browse files Browse the repository at this point in the history
…ithm'
  • Loading branch information
Samuel Jackson committed Mar 28, 2014
2 parents bb946a2 + 1514cfe commit 6585bd6
Show file tree
Hide file tree
Showing 8 changed files with 771 additions and 151 deletions.
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/DataHandling/CMakeLists.txt
@@ -1,5 +1,6 @@
set ( SRC_FILES
src/AppendGeometryToSNSNexus.cpp
src/AsciiPointBase.cpp
src/CompressEvents.cpp
src/CreateChopperModel.cpp
src/CreateModeratorModel.cpp
Expand Down Expand Up @@ -112,6 +113,7 @@ set ( SRC_FILES
src/SaveFullprofResolution.cpp
src/SaveGSS.cpp
src/SaveISISNexus.cpp
src/SaveILLCosmosAscii.cpp
src/SaveIsawDetCal.cpp
src/SaveMask.cpp
src/SaveNISTDAT.cpp
Expand All @@ -131,6 +133,7 @@ set ( SRC_FILES

set ( INC_FILES
inc/MantidDataHandling/AppendGeometryToSNSNexus.h
inc/MantidDataHandling/AsciiPointBase.h
inc/MantidDataHandling/CompressEvents.h
inc/MantidDataHandling/CreateChopperModel.h
inc/MantidDataHandling/CreateModeratorModel.h
Expand Down Expand Up @@ -238,6 +241,7 @@ set ( INC_FILES
inc/MantidDataHandling/SaveFullprofResolution.h
inc/MantidDataHandling/SaveGSS.h
inc/MantidDataHandling/SaveISISNexus.h
inc/MantidDataHandling/SaveILLCosmosAscii.h
inc/MantidDataHandling/SaveIsawDetCal.h
inc/MantidDataHandling/SaveMask.h
inc/MantidDataHandling/SaveNISTDAT.h
Expand Down Expand Up @@ -359,6 +363,7 @@ set ( TEST_FILES
SaveDspacemapTest.h
SaveFocussedXYETest.h
SaveFullprofResolutionTest.h
SaveILLCosmosAsciiTest.h
SaveIsawDetCalTest.h
SaveMaskTest.h
SaveNISTDATTest.h
Expand Down
@@ -0,0 +1,90 @@
#ifndef MANTID_DATAHANDLING_ASCIIPOINTBASE_H_
#define MANTID_DATAHANDLING_ASCIIPOINTBASE_H_

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include <fstream>

namespace Mantid
{
namespace DataHandling
{
/**
Abstract base class for some ascii format save algorithms that print point data and dq/q.
AsciiPointBase is a framework for some algorithms. It overrides exec and init and provides full
implementation for any subclasses and as such any subclasses should only provide implementations
for the additional abstract and virtual methods provided by this class.
Copyright &copy; 2007-14 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 AsciiPointBase : public API::Algorithm
{
public:
/// Default constructor
AsciiPointBase() {}
/// Destructor
~AsciiPointBase() {}
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const = 0;
/// Algorithm's version for identification overriding a virtual method
virtual int version() const = 0;
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\Text"; }

private:
/// Sets documentation strings for this algorithm
virtual void initDocs() = 0;
/// Return the file extension this algorthm should output.
virtual std::string ext() = 0;
/// return if the line should start with a separator
virtual bool leadingSep() {return true;}
/// Add extra properties
virtual void extraProps() = 0;
/// write any extra information required
virtual void extraHeaders(std::ofstream & file) = 0;
/// write the main content of the data
virtual void data(std::ofstream & file, const std::vector<double> & XData);
/// Overwrites Algorithm method.
void init();
/// Overwrites Algorithm method
void exec();
/// returns true if the value is NaN
bool checkIfNan(const double& value) const;
/// returns true if the value if + or - infinity
bool checkIfInfinite(const double& value) const;
/// print the appropriate value to file
void outputval (double val, std::ofstream & file, bool leadingSep = true);
/// write the top of the file
virtual std::vector<double> header(std::ofstream & file);
protected:
/// Return the separator character
virtual char sep() {return '\t';}
double m_qres;
size_t m_xlength;
API::MatrixWorkspace_const_sptr m_ws;
};

} // namespace DataHandling
} // namespace Mantid

#endif /* MANTID_DATAHANDLING_SAVEANSTO_H_ */
Expand Up @@ -5,42 +5,61 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidDataHandling/AsciiPointBase.h"

namespace Mantid
{
namespace DataHandling
{
class DLLExport SaveANSTOAscii : public API::Algorithm
/**
Saves a file in Ansto format and from a 2D workspace
(Workspace2D class). SaveANSTOAscii is an algorithm but inherits from the
AsciiPointBase class which provides the main implementation for the init() & exec() methods.
Output is tab delimited Ascii point data with dq/q.
Copyright &copy; 2007-14 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 SaveANSTOAscii : public DataHandling::AsciiPointBase
{
public:
/// Default constructor
SaveANSTOAscii();
SaveANSTOAscii() {}
/// Destructor
~SaveANSTOAscii() {}
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "SaveANSTOAscii"; }
/// 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 "DataHandling\\Text"; }

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
/// Overwrites Algorithm method.
void init();
/// Overwrites Algorithm method
void exec();
/// returns true if the value is NaN
bool checkIfNan(const double& value) const;
/// returns true if the value if + or - infinity
bool checkIfInfinite(const double& value) const;
/// print the appropriate value to file
void outputval (double val, std::ofstream & file, bool leadingSep = true);
///static reference to the logger class
static Kernel::Logger& g_log;
char m_sep;
API::MatrixWorkspace_const_sptr m_ws;
/// Return the file extension this algorthm should output.
virtual std::string ext() {return ".txt";}
/// return if the line should start with a separator
virtual bool leadingSep() {return false;}
/// no extra properties required so override blank
virtual void extraProps() {}
/// no extra information required so override blank
virtual void extraHeaders(std::ofstream & file);
};

} // namespace DataHandling
Expand Down
@@ -0,0 +1,66 @@
#ifndef MANTID_DATAHANDLING_SaveILLCosmosAscii_H_
#define MANTID_DATAHANDLING_SaveILLCosmosAscii_H_

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataHandling/AsciiPointBase.h"

namespace Mantid
{
namespace DataHandling
{
/**
Saves a file in ILL Cosmos format from a 2D workspace
(Workspace2D class). SaveILLCosmosAscii is an algorithm but inherits frrm the
AsciiPointBase class which provides the main implementation for the init() & exec() methods.
Output is tab delimited Ascii point data with dq/q and extra header information.
Copyright &copy; 2007-14 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 SaveILLCosmosAscii : public DataHandling::AsciiPointBase
{
public:
/// Default constructor
SaveILLCosmosAscii() {}
/// Destructor
~SaveILLCosmosAscii() {}
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "SaveILLCosmosAscii"; }
/// Algorithm's version for identification overriding a virtual method
virtual int version() const { return 1; }

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
/// Return the file extension this algorthm should output.
virtual std::string ext() {return ".mft";}
///extra properties specifically for this
virtual void extraProps();
/// write any extra information required
virtual void extraHeaders(std::ofstream & file);
};
} // namespace DataHandling
} // namespace Mantid

#endif /* MANTID_DATAHANDLING_SaveILLCosmosAscii_H_ */

0 comments on commit 6585bd6

Please sign in to comment.