Skip to content

Commit

Permalink
Refs #7832 specify path for saving Lauenorm files
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Aug 3, 2014
1 parent 1fe9795 commit 22f97f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
21 changes: 13 additions & 8 deletions Code/Mantid/Framework/Crystal/src/SaveLauenorm.cpp
Expand Up @@ -14,7 +14,8 @@
#include "MantidCrystal/AnvredCorrection.h"
#include <boost/math/special_functions/fpclassify.hpp>
#include <fstream>
#include "Poco/File.h"
#include <Poco/File.h>
#include <Poco/Path.h>
#include "boost/assign.hpp"

using namespace Mantid::Geometry;
Expand Down Expand Up @@ -57,17 +58,15 @@ namespace Crystal
{
declareProperty(new WorkspaceProperty<PeaksWorkspace>("InputWorkspace","",Direction::Input),
"An input PeaksWorkspace.");

declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Save),
"The filename to use for the saved data");
auto mustBePositive = boost::make_shared<BoundedValidator<double> >();
mustBePositive->setLower(0.0);
declareProperty("ScalePeaks", 1.0, mustBePositive,
"Multiply FSQ and sig(FSQ) by scaleFactor");
declareProperty("MinDSpacing", 0.0, "Minimum d-spacing (Angstroms)");
declareProperty("MinWavelength", 0.0, "Minimum wavelength (Angstroms)");
declareProperty("MaxWavelength", EMPTY_DBL(), "Maximum wavelength (Angstroms)");
declareProperty(new PropertyWithValue<std::string>("FilenamePrefix","LAUE",Direction::Input),
"String at beginning of name of output files in default save directory.");

std::vector<std::string> histoTypes;
histoTypes.push_back("Bank" );
histoTypes.push_back("RunNumber" );
Expand All @@ -87,7 +86,7 @@ namespace Crystal
void SaveLauenorm::exec()
{

std::string filename = Kernel::ConfigService::Instance().getString("defaultsave.directory") + getPropertyValue("FilenamePrefix");
std::string filename = getProperty("Filename");
ws = getProperty("InputWorkspace");
double scaleFactor = getProperty("ScalePeaks");
double dMin = getProperty("MinDSpacing");
Expand Down Expand Up @@ -162,8 +161,14 @@ namespace Crystal
ss.str("");
ss.clear();
ss << std::setw(3) << std::setfill('0') << sequenceNo;
std::string bankfile = filename + ss.str();
out.open( bankfile.c_str(), std::ios::out);

Poco::Path path(filename);
std::string basename = path.getBaseName(); // Filename minus extension
// Chop off filename
path.makeParent();
path.append(basename + ss.str() );
Poco::File fileobj(path);
out.open(path.toString().c_str(), std::ios::out);
}
// h k l lambda theta intensity and sig(intensity) in format (3I5,2F10.5,2I10)
// HKL is flipped by -1 due to different q convention in ISAW vs mantid.
Expand Down
9 changes: 3 additions & 6 deletions Code/Mantid/Framework/Crystal/test/SaveLauenormTest.h
Expand Up @@ -54,20 +54,17 @@ class SaveLauenormTest : public CxxTest::TestSuite
ws->addPeak(p);
}

std::string outfile = "SaveLauenormTest";
std::string outfile = "./LAUE";
SaveLauenorm alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("InputWorkspace", ws) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("FilenamePrefix", outfile) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Filename", outfile) );
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );

// Get the file
outfile = Kernel::ConfigService::Instance().getString("defaultsave.directory") + alg.getPropertyValue("FilenamePrefix");
std::ostringstream ss;
ss << std::setw(3) << std::setfill('0') << 1;
outfile =outfile.c_str() + ss.str();
outfile = alg.getPropertyValue("Filename")+"001";
bool fileExists = false;
TS_ASSERT( fileExists = Poco::File(outfile).exists() );
if ( fileExists )
Expand Down
24 changes: 10 additions & 14 deletions Code/Mantid/docs/source/algorithms/SaveLauenorm-v1.rst
Expand Up @@ -31,15 +31,14 @@ Usage

import os

prefix = "MyPeaks"
file = prefix + "001"
path = os.path.join(config["defaultsave.directory"], file)
prefix = "./MyPeaks"
file = os.path.join(os.path.expanduser("~"), "MyPeaks001")

#load a peaks workspace from file
peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate')
SaveLauenorm(InputWorkspace=peaks, FilenamePrefix=prefix)
SaveLauenorm(InputWorkspace=peaks, Filename=prefix)

print os.path.isfile(path)
print os.path.isfile(file)

Output:

Expand All @@ -53,8 +52,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config["defaultsave.directory"], ws)
os.remove(path)
os.remove(file)
except:
pass

Expand All @@ -70,12 +68,11 @@ Output:
peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate')
print "Number of peaks in table %d" % peaks.rowCount()

prefix = "MyPeaks"
file = prefix + "009"
path = os.path.join(config["defaultsave.directory"], file)
SaveLauenorm(InputWorkspace=peaks, FilenamePrefix=prefix, MinWavelength=0.5, MaxWavelength=2,MinDSpacing=0.2, SortFilesBy='Bank')
prefix = "./MyPeaks"
file = os.path.join(os.path.expanduser("~"), "MyPeaks009")
SaveLauenorm(InputWorkspace=peaks, Filename=prefix, MinWavelength=0.5, MaxWavelength=2,MinDSpacing=0.2, SortFilesBy='Bank')

ifile = open(path, 'r')
ifile = open(file, 'r')
lines = ifile.readlines()
ifile.close()
print "Number of peaks in table %d" % len(lines)
Expand All @@ -93,8 +90,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config["defaultsave.directory"], file)
os.remove(path)
os.remove(file)
except:
pass

Expand Down

0 comments on commit 22f97f0

Please sign in to comment.