diff --git a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp index c8196031037e277217f18df4496d1ce16f3632a3..9ddea8c26c208e5ff974ed8f0dda42b49d17186a 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp @@ -309,8 +309,6 @@ API::MatrixWorkspace_sptr LoadGSS::loadGSASFile(const std::string &filename, xPrev = -0.0; } - std::istringstream inputLine(currentLine, std::ios::in); - // It is different for the definition of X, Y, Z in SLOG and RALF format if (filetype == 'r') { // RALF @@ -318,16 +316,27 @@ API::MatrixWorkspace_sptr LoadGSS::loadGSASFile(const std::string &filename, // std::setw // For this reason we need to read the column values as string and then // convert to double - std::string xString, yString, eString; - inputLine >> std::setw(11) >> xString >> std::setw(18) >> yString >> - std::setw(18) >> eString; - xValue = boost::lexical_cast<double>(xString); - yValue = boost::lexical_cast<double>(yString); - eValue = boost::lexical_cast<double>(eString); + { + std::string str(currentLine, 15); + std::istringstream istr(str); + istr >> xValue; + } + { + std::string str(currentLine + 15, 18); + std::istringstream istr(str); + istr >> yValue; + } + { + std::string str(currentLine + 15 + 18, 18); + std::istringstream istr(str); + istr >> eValue; + } + xValue = (2 * xValue) - xPrev; } else if (filetype == 's') { // SLOG + std::istringstream inputLine(currentLine, std::ios::in); inputLine >> xValue >> yValue >> eValue; if (calslogx0) { // calculation of x0 must use the x'[0] diff --git a/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h b/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h index be74e7532776f739ab4d720f976f12463da59731..62457964d0cb2c354ced585c4c5d66d0ab0c0f4c 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h @@ -4,12 +4,11 @@ #include "cxxtest/TestSuite.h" #include "MantidDataHandling/LoadGSS.h" #include "MantidAPI/AlgorithmManager.h" -//#include "MantidAPI/AnalysisDataService.h" -//#include <Poco/File.h> -//#include <fstream> +#include "MantidTestHelpers/ScopedFileHelper.h" using namespace Mantid; using Mantid::DataHandling::LoadGSS; +using ScopedFileHelper::ScopedFile; class LoadGSSTest : public CxxTest::TestSuite { @@ -24,13 +23,54 @@ public: TS_ASSERT_EQUALS( loader.version(), 1 ) } - void test_load_gss_txt() - { + void test_load_gss_txt() { API::IAlgorithm_sptr loader = createAlgorithm(); - loader->setPropertyValue("Filename","gss.txt"); - TS_ASSERT( loader->execute() ) + loader->setPropertyValue("Filename", "gss.txt"); + TS_ASSERT(loader->execute()) + API::MatrixWorkspace_const_sptr ws = loader->getProperty("OutputWorkspace"); // Check a few things in the workspace - checkWorkspace( loader->getProperty("OutputWorkspace"), 8, 816); + checkWorkspace(ws, 8, 816); + auto x1 = ws->readX(0)[99]; + auto x2 = ws->readX(0)[100]; + auto y = ws->readY(0)[99]; + TS_ASSERT_DELTA((x1 + x2)/2, 40844.0625, 1e-6); + TS_ASSERT_DELTA(y, 145304004.625, 1e-6); + } + + void test_large_x_values() { + std::string gss = + "LuBaCo4O7 HR BS P=2GPa Tcryo=130.0K " + " \n" + "# 1 Histograms\n" + "# File generated by Mantid:\n" + "# Instrument: WISH\n" + "# From workspace named : w21552-2foc\n" + "# with Y multiplied by the bin widths.\n" + "# Primary flight path 40m \n" + "# Total flight path 42.2222m, tth 58.308deg, DIFC 10398.8\n" + "# Data for spectrum :0\n" + "BANK 1 4399 4399 RALF 166409 124 166409 0.00074 FXYE\n" + " 115202.20029 123456.00000002 0.00000000\n" + " 115206.06310 1234567.00000003 0.00000000\n" + " 115209.92877 12345678.00000004 0.00000000\n" + " 115213.79731123456789.00000005 0.00000000\n" + " 115217.66873234567890.00000006 0.00000000"; + ScopedFile file(gss,"gss_large_x.txt"); + API::IAlgorithm_sptr loader = createAlgorithm(); + loader->setPropertyValue("Filename", file.getFileName()); + TS_ASSERT(loader->execute()) + API::MatrixWorkspace_const_sptr ws = loader->getProperty("OutputWorkspace"); + auto x1 = ws->readX(0)[0]; + auto x2 = ws->readX(0)[1]; + auto dx = x2 - x1; + auto y = ws->readY(0)[0] * dx; + TS_ASSERT_DELTA((x1 + x2)/2, 115202.20029, 1e-6); + TS_ASSERT_DELTA(y, 123456.00000002, 1e-10); + x1 = ws->readX(0)[3]; + x2 = ws->readX(0)[4]; + dx = x2 - x1; + y = ws->readY(0)[3] * dx; + TS_ASSERT_DELTA(y, 123456789.00000005, 1e-10); } void test_load_gss_ExtendedHeader_gsa()