Newer
Older
Gigg, Martyn Anthony
committed
//-------------------------------------------------------
// Includes
//------------------------------------------------------
#include "MantidDataHandling/LoadSampleDetailsFromRaw.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/FileProperty.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/Sample.h"
// The isis RAW data structure
#include "LoadRaw/isisraw2.h"
#include <cstdio> //MG: Required for gcc 4.4
Gigg, Martyn Anthony
committed
namespace Mantid
{
namespace DataHandling
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadSampleDetailsFromRaw)
}
}
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataHandling;
/**
* Initialize the algorithm
*/
void LoadSampleDetailsFromRaw::init()
{
Janik Zikovsky
committed
//this->setWikiSummary("Loads the simple sample geometry that is defined within an ISIS raw file.");
//this->setOptionalMessage("Loads the simple sample geometry that is defined within an ISIS raw file.");
Gigg, Martyn Anthony
committed
declareProperty(new WorkspaceProperty<>("InputWorkspace","",Direction::Input),
"The workspace to which the information should be added");
Peterson, Peter
committed
std::vector<std::string> exts;
exts.push_back("raw");
exts.push_back(".s*");
Gigg, Martyn Anthony
committed
declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts),
Gigg, Martyn Anthony
committed
"The file from which to extract the information");
}
/**
* Execute the algorithm
*/
void LoadSampleDetailsFromRaw::exec()
{
MatrixWorkspace_sptr data_ws = getProperty("InputWorkspace");
if( !data_ws.get() )
{
g_log.error() << "Cannot retrieve InputWorkspace " << getPropertyValue("InputWorkspace");
throw Exception::NotFoundError("Cannot retrieve InputWorkspace", getPropertyValue("InputWorkspace"));
}
Gigg, Martyn Anthony
committed
std::string filename = getPropertyValue("Filename");
FILE* file = fopen(filename.c_str(), "rb");
if (file == NULL)
{
g_log.error("Unable to open file " + filename);
throw Exception::FileError("Unable to open File:", filename);
}
ISISRAW2 *isis_raw = new ISISRAW2;
isis_raw->ioRAW(file, true);
fclose(file);
Gigg, Martyn Anthony
committed
// Pick out the geometry information
data_ws->mutableSample().setGeometryFlag(isis_raw->spb.e_geom);
data_ws->mutableSample().setThickness(static_cast<double> (isis_raw->spb.e_thick));
data_ws->mutableSample().setHeight(static_cast<double> (isis_raw->spb.e_height));
data_ws->mutableSample().setWidth(static_cast<double> (isis_raw->spb.e_width));
Gigg, Martyn Anthony
committed
g_log.debug() << "Raw file sample details:\n" << "\tsample geometry flag: " << isis_raw->spb.e_geom
<< "\n" << "\tsample thickness: " << data_ws->mutableSample().getThickness() << "\n"
<< "\tsample height: " << data_ws->mutableSample().getHeight() << "\n" << "\tsample width: "
<< data_ws->mutableSample().getWidth() << std::endl;
Gigg, Martyn Anthony
committed
// Free the used memory
delete isis_raw;
// Not much happens really
progress(1.);
}