Newer
Older
Gigg, Martyn Anthony
committed
//-------------------------------------------------------
// Includes
//------------------------------------------------------
#include "MantidDataHandling/LoadSampleDetailsFromRaw.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/FileProperty.h"
Federico Montesino Pouzols
committed
#include "MantidAPI/MatrixWorkspace.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 {
Gigg, Martyn Anthony
committed
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataHandling;
Janik Zikovsky
committed
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadSampleDetailsFromRaw)
Gigg, Martyn Anthony
committed
/**
* Initialize the algorithm
*/
void LoadSampleDetailsFromRaw::init() {
declareProperty(
new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
"The sample details are attached to this workspace.");
declareProperty(
new FileProperty("Filename", "", FileProperty::Load, {"raw", ".s*"}),
"The raw file containing the sample geometry information.");
Gigg, Martyn Anthony
committed
}
/**
* Execute the algorithm
*/
void LoadSampleDetailsFromRaw::exec() {
MatrixWorkspace_sptr data_ws = getProperty("InputWorkspace");
Gigg, Martyn Anthony
committed
std::string filename = getPropertyValue("Filename");
FILE *file = fopen(filename.c_str(), "rb");
if (file == nullptr) {
Gigg, Martyn Anthony
committed
g_log.error("Unable to open file " + filename);
throw Exception::FileError("Unable to open File:", filename);
}
auto isis_raw = new ISISRAW2;
Gigg, Martyn Anthony
committed
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.);
}
Janik Zikovsky
committed
} // namespace
}