Skip to content

Commit

Permalink
Commit 02 Refs #3493
Browse files Browse the repository at this point in the history
  • Loading branch information
Lottie Greenwood committed Nov 5, 2014
1 parent 7f171bd commit 5620652
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Expand Up @@ -89,6 +89,7 @@ namespace Mantid
bool m_writeDX;
bool m_writeID;
bool m_isHistogram;
bool m_isCommonBins;
API::MatrixWorkspace_const_sptr m_ws;
};
} // namespace DataHandling
Expand Down
27 changes: 19 additions & 8 deletions Code/Mantid/Framework/DataHandling/src/SaveAscii2.cpp
Expand Up @@ -93,6 +93,7 @@ namespace Mantid
int nSpectra = static_cast<int>(m_ws->getNumberHistograms());
m_nBins = static_cast<int>(m_ws->blocksize());
m_isHistogram = m_ws->isHistogramData();
m_isCommonBins = m_ws->isCommonBins(); //checking for ragged workspace
m_writeID = getProperty("WriteSpectrumID");
if (nSpectra != 1) m_writeID = true;

Expand All @@ -102,9 +103,8 @@ namespace Mantid
int spec_max = getProperty("WorkspaceIndexMax");
bool writeHeader = getProperty("ColumnHeader");
bool appendToFile = getProperty("AppendToFile");
//here we need to check for ragged?

// Check whether we need to write the fourth column
bool checkRagged = getProperty("RaggedWorkspace"); //in testing
m_writeDX = getProperty("WriteXError");
std::string choice = getPropertyValue("Separator");
std::string custom = getPropertyValue("CustomSeparator");
Expand Down Expand Up @@ -238,25 +238,31 @@ namespace Mantid
@param spectraItr :: a set<int> iterator pointing to a set of workspace IDs to be saved
@param file :: the file writer object
*/
void SaveAscii2::writeSpectra(const std::set<int>::const_iterator & spectraItr, std::ofstream & file)
void SaveAscii2::writeSpectra(const std::set<int>::const_iterator & spectraItr, std::ofstream & file)
{
auto spec = m_ws->getSpectrum(*spectraItr);
auto specNo = spec->getSpectrumNo();
if (m_writeID) file << specNo << std::endl;

for(int bin=0;bin<m_nBins;bin++)
{
if (!m_isCommonBins) //checking for ragged workspace
{
file << m_ws->readX(*spectraItr)[bin];
}

if (m_isHistogram) // bin centres
if (m_isHistogram & m_isCommonBins) // bin centres
{
file << ( m_ws->readX(0)[bin] + m_ws->readX(0)[bin+1] )/2;
file << ( m_ws->readX(0)[bin] + m_ws->readX(0)[bin+1] )/2;
}

else // data points
{
file << m_ws->readX(0)[bin];
}
file << m_sep;
file << m_ws->readY(*spectraItr)[bin];

file << m_sep;
file << m_ws->readE(*spectraItr)[bin];
if (m_writeDX)
Expand All @@ -280,24 +286,29 @@ namespace Mantid
@param spectraIndex :: an integer relating to a workspace ID
@param file :: the file writer object
*/
void SaveAscii2::writeSpectra(const int & spectraIndex, std::ofstream & file)
void SaveAscii2::writeSpectra(const int & spectraIndex, std::ofstream & file) //<- shouldnt be here
{
auto spec = m_ws->getSpectrum(spectraIndex);
auto specNo = spec->getSpectrumNo();
if (m_writeID) file << specNo << std::endl;

for(int bin=0;bin<m_nBins;bin++)
{
if (m_isHistogram) // bin centres
if (m_isHistogram & m_isCommonBins) // bin centres
{
file << ( m_ws->readX(0)[bin] + m_ws->readX(1)[bin+1] )/2;
}
if (!m_isCommonBins) //checking for ragged workspace
{
file << ( m_ws->readX(0)[bin] + m_ws->readX(0)[bin+1] )/2;
file << m_ws->readX(spectraIndex)[bin];
}
else // data points
{
file << m_ws->readX(0)[bin];
}
file << m_sep;
file << m_ws->readY(spectraIndex)[bin];

file << m_sep;
file << m_ws->readE(spectraIndex)[bin];
if (m_writeDX)
Expand Down

0 comments on commit 5620652

Please sign in to comment.