-
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.
This algorithm modifies the header as planned and copies all other lines. Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
- Loading branch information
1 parent
9af0254
commit 45868de
Showing
3 changed files
with
200 additions
and
0 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/DataHandling/inc/MantidDataHandling/ModifyDetectorDotDatFile.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_DATAHANDLING_MODIFYDETECTORDOTDATFILE_H_ | ||
#define MANTID_DATAHANDLING_MODIFYDETECTORDOTDATFILE_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace DataHandling | ||
{ | ||
|
||
/** Modifies an ISIS detector dot data file, so that the detector positions are as in the given workspace. | ||
@author Karl Palmen | ||
@date 2012-08-23 | ||
Copyright © 2012 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://svn.mantidproject.org/mantid/trunk/Code/Mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport ModifyDetectorDotDatFile : public API::Algorithm | ||
{ | ||
public: | ||
ModifyDetectorDotDatFile(); | ||
~ModifyDetectorDotDatFile(); | ||
|
||
/// Algorithm's name for identification | ||
virtual const std::string name() const { return "ModifyDetectorDotDatFile";}; | ||
/// Algorithm's version for identification | ||
virtual int version() const { return 1;}; | ||
/// Algorithm's category for identification | ||
virtual const std::string category() const { return "DataHandling";} | ||
|
||
private: | ||
/// Sets documentation strings for this algorithm | ||
virtual void initDocs(); | ||
/// Initialise the properties | ||
void init(); | ||
/// Run the algorithm | ||
void exec(); | ||
|
||
|
||
}; | ||
|
||
|
||
} // namespace DataHandling | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_DATAHANDLING_MODIFYDETECTORDOTDATFILE_H_ */ |
133 changes: 133 additions & 0 deletions
133
Code/Mantid/Framework/DataHandling/src/ModifyDetectorDotDatFile.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,133 @@ | ||
/*WIKI* | ||
Modifies an ISIS detector dot data file, so that the detector positions are as in the given workspace. | ||
*WIKI*/ | ||
#include "MantidAPI/FileProperty.h" | ||
#include "MantidAPI/MatrixWorkspace.h" | ||
#include "MantidDataHandling/ModifyDetectorDotDatFile.h" | ||
#include "MantidGeometry/Instrument.h" | ||
#include "MantidGeometry/Instrument/RectangularDetector.h" | ||
#include "MantidKernel/System.h" | ||
#include <fstream> | ||
#include "MantidAPI/Workspace.h" | ||
#include "MantidAPI/ExperimentInfo.h" | ||
|
||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Geometry; | ||
|
||
namespace Mantid | ||
{ | ||
namespace DataHandling | ||
{ | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(ModifyDetectorDotDatFile) | ||
|
||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
ModifyDetectorDotDatFile::ModifyDetectorDotDatFile() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
ModifyDetectorDotDatFile::~ModifyDetectorDotDatFile() | ||
{ | ||
} | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Sets documentation strings for this algorithm | ||
void ModifyDetectorDotDatFile::initDocs() | ||
{ | ||
this->setWikiSummary("Modifies an ISIS detector dot data file, so that the detector positions are as in the given workspace"); | ||
this->setOptionalMessage("Modifies an ISIS detector dot data file, so that the detector positions are as in the given workspace"); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void ModifyDetectorDotDatFile::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<Workspace>("InputWorkspace","",Direction::Input), "Workspace with detectors in the positions to be put into the detector dot dat file"); | ||
|
||
std::vector<std::string> exts; | ||
exts.push_back(".dat"); | ||
exts.push_back(".txt"); | ||
|
||
declareProperty(new FileProperty("InputFilename", "", FileProperty::Load, exts), | ||
"Path to a detector dot dat file."); | ||
|
||
declareProperty(new FileProperty("OutputFilename", "", FileProperty::Save, exts), | ||
"Path to the modified detector dot dat file."); | ||
|
||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void ModifyDetectorDotDatFile::exec() | ||
{ | ||
std::string inputFilename = getPropertyValue("InputFilename"); | ||
std::string outputFilename = getPropertyValue("OutputFilename"); | ||
|
||
Workspace_sptr ws1 = getProperty("InputWorkspace"); | ||
ExperimentInfo_sptr ws = boost::dynamic_pointer_cast<ExperimentInfo>(ws1); | ||
|
||
// Check instrument | ||
Instrument_const_sptr inst = ws->getInstrument(); | ||
if (!inst) throw std::runtime_error("No instrument in the Workspace. Cannot modify detector dot dat file"); | ||
|
||
// Open files | ||
std::ifstream in; | ||
in.open( inputFilename.c_str()); | ||
if(!in) { | ||
throw Exception::FileError("Can't open input file", inputFilename); | ||
} | ||
std::ofstream out; | ||
out.open( outputFilename.c_str()); | ||
if(!out) { | ||
in.close(); | ||
throw Exception::FileError("Can't open output file", outputFilename); | ||
} | ||
|
||
// Read first line, modify it and put into output file | ||
std::string str; | ||
getline( in, str ); | ||
out << str << " and modified by MANTID algorithm ModifyDetectorDotDatFile \n"; | ||
|
||
// Read second line to check number of detectors and columns | ||
int detectorCount, numColumns; | ||
getline( in, str ); | ||
std::istringstream header2(str); | ||
header2 >> detectorCount >> numColumns; | ||
// check that we have at least 1 detector and five columns | ||
if( detectorCount < 1 || numColumns < 5) { | ||
throw Exception::FileError("Incompatible file format found when reading line 2 in the input file", inputFilename); | ||
} | ||
out << str << "\n"; | ||
|
||
// Read input file line by line, modify line as necessary and put line into output file | ||
while( getline( in, str ) ){ | ||
// We do not yet modify | ||
out << str << "\n"; | ||
} | ||
|
||
out.close(); | ||
in.close(); | ||
|
||
} | ||
|
||
|
||
|
||
} // namespace Mantid | ||
} // namespace DataHandling | ||
|