From 0c15c77a6bc7e9a43cde2f6e1b900320db847760 Mon Sep 17 00:00:00 2001 From: Nick Draper <nick.draper@stfc.ac.uk> Date: Wed, 13 Nov 2013 15:13:47 +0000 Subject: [PATCH] re #8437 lots of style issues, but not quite all --- .../API/src/IPowderDiffPeakFunction.cpp | 5 +- .../Algorithms/src/CreateWorkspace.cpp | 1 - .../Framework/Algorithms/src/FitPeak.cpp | 4 +- .../Framework/Algorithms/src/RingProfile.cpp | 13 +- Code/Mantid/Framework/Crystal/src/SaveHKL.cpp | 4 +- .../CurveFitting/src/ProcessBackground.cpp | 12 +- .../CurveFitting/src/ReflectivityMulf.cpp | 45 +- .../src/LoadDetectorsGroupingFile.cpp | 3 +- .../Framework/DataHandling/src/LoadLLB.cpp | 3 - .../DataHandling/src/LoadNexusMonitors.cpp | 3 +- .../DataHandling/src/SaveCanSAS1D.cpp | 9 +- .../DataHandling/src/SaveCanSAS1D2.cpp | 7 +- .../Framework/DataHandling/src/SaveGSS.cpp | 8 +- .../DataHandling/src/SetSampleMaterial.cpp | 477 +++++++------- .../Geometry/src/Crystal/IndexingUtils.cpp | 102 ++- .../Geometry/src/Crystal/ScalarUtils.cpp | 6 +- .../Geometry/src/Instrument/DetectorGroup.cpp | 3 +- .../Geometry/src/Instrument/Goniometer.cpp | 6 +- .../Instrument/InstrumentDefinitionParser.cpp | 12 +- .../Framework/Geometry/src/Math/Acomp.cpp | 20 +- .../Framework/Geometry/src/Objects/Object.cpp | 5 +- .../Geometry/src/Objects/ShapeFactory.cpp | 3 +- .../src/Rendering/CacheGeometryRenderer.cpp | 7 +- .../Framework/ICat/src/ICat4/ICat4Catalog.cpp | 6 +- .../Mantid/Framework/Kernel/src/BinFinder.cpp | 4 +- Code/Mantid/Framework/Kernel/src/Matrix.cpp | 30 +- .../Framework/Kernel/src/Statistics.cpp | 8 +- .../Kernel/src/TimeSeriesProperty.cpp | 10 +- .../Framework/Kernel/src/VectorHelper.cpp | 12 +- .../src/ISISLiveEventDataListener.cpp | 1 - .../MDAlgorithms/src/ConvertToMDHelper.cpp | 2 +- .../Framework/MDAlgorithms/src/DivideMD.cpp | 2 +- .../Framework/MDAlgorithms/src/LoadSQW.cpp | 5 +- .../MDEvents/src/BoxControllerNeXusIO.cpp | 3 +- .../MDEvents/src/Integrate3DEvents.cpp | 17 +- .../MDEvents/src/MDEventWorkspace.cpp | 8 +- .../Framework/Nexus/src/NexusFileIO.cpp | 3 +- .../Mantid/Framework/SINQ/src/InvertMDDim.cpp | 5 +- .../Framework/SINQ/src/LoadFlexiNexus.cpp | 607 +++++++++--------- .../SINQ/src/PoldiAutoCorrelation5.cpp | 7 +- Code/Mantid/Framework/SINQ/src/ProjectMD.cpp | 12 +- .../Framework/SINQ/src/SINQHMListener.cpp | 33 +- .../Framework/SINQ/src/SliceMDHisto.cpp | 6 +- .../src/ScriptRepositoryImpl.cpp | 3 +- .../src/WorkspaceCreationHelper.cpp | 2 +- .../src/AlignAndFocusPowder.cpp | 3 +- .../MantidPlot/src/ApplicationWindow.cpp | 4 +- Code/Mantid/MantidPlot/src/Fit.cpp | 4 +- Code/Mantid/MantidPlot/src/FunctionCurve.cpp | 1 + Code/Mantid/MantidPlot/src/FunctionDialog.cpp | 10 +- .../src/Mantid/AlgorithmHistoryWindow.cpp | 6 +- .../InstrumentWidget/UnwrappedSurface.cpp | 2 +- .../InstrumentWidget/UnwrappedSurface.h | 2 +- Code/Mantid/MantidPlot/src/NonLinearFit.cpp | 10 +- .../MantidPlot/src/OpenProjectDialog.cpp | 2 +- Code/Mantid/MantidPlot/src/Plot.cpp | 6 +- 56 files changed, 725 insertions(+), 869 deletions(-) diff --git a/Code/Mantid/Framework/API/src/IPowderDiffPeakFunction.cpp b/Code/Mantid/Framework/API/src/IPowderDiffPeakFunction.cpp index 49452fe7a7f..f6de38ca92c 100644 --- a/Code/Mantid/Framework/API/src/IPowderDiffPeakFunction.cpp +++ b/Code/Mantid/Framework/API/src/IPowderDiffPeakFunction.cpp @@ -329,8 +329,6 @@ namespace API */ std::complex<double> E1(std::complex<double> z) { - const double el = 0.5772156649015328; - std::complex<double> exp_e1; double rz = real(z); @@ -363,8 +361,8 @@ namespace API } } // ENDFOR k - // cout << "[DB] el = " << el << ", exp_e1 = " << exp_e1 << endl; + const double el = 0.5772156649015328; exp_e1 = -el - log(z) + (z*exp_e1); } else @@ -386,7 +384,6 @@ namespace API } } - // cout << "[DB] Final exp_e1 = " << exp_e1 << "\n"; return exp_e1; } diff --git a/Code/Mantid/Framework/Algorithms/src/CreateWorkspace.cpp b/Code/Mantid/Framework/Algorithms/src/CreateWorkspace.cpp index f503cfc9024..3af5e8c9a52 100644 --- a/Code/Mantid/Framework/Algorithms/src/CreateWorkspace.cpp +++ b/Code/Mantid/Framework/Algorithms/src/CreateWorkspace.cpp @@ -105,7 +105,6 @@ void CreateWorkspace::exec() const std::string xUnit = getProperty("UnitX"); const std::string vUnit = getProperty("VerticalAxisUnit"); const std::vector<std::string> vAxis = getProperty("VerticalAxisValues"); - std::string parentWorkspace = getPropertyValue("ParentWorkspace"); if ( ( vUnit != "SpectraNumber" ) && ( static_cast<int>(vAxis.size()) != nSpec ) ) { diff --git a/Code/Mantid/Framework/Algorithms/src/FitPeak.cpp b/Code/Mantid/Framework/Algorithms/src/FitPeak.cpp index 79ad8e709e1..f5bec47d6ca 100644 --- a/Code/Mantid/Framework/Algorithms/src/FitPeak.cpp +++ b/Code/Mantid/Framework/Algorithms/src/FitPeak.cpp @@ -608,7 +608,6 @@ namespace Algorithms map<string, double> errormap; push(bkgdfunc, m_bkupBkgdFunc, errormap); - std::vector<double> vec_bkgd; vector<double> vec_xmin(2); vector<double> vec_xmax(2); vec_xmin[0] = m_minFitX; @@ -761,6 +760,7 @@ namespace Algorithms push(m_bkgdFunc, m_bestBkgdFunc, m_fitErrorBkgdFunc); m_bestRwp = rwp; } + g_log.debug()<<"Failed due to: " << failreason <<std::endl; return; } @@ -947,12 +947,10 @@ namespace Algorithms { // Fit for composite function renders a better result goodness_final = goodness; - errorreason = ""; } else if (goodness_init <= goodness && goodness_init < DBL_MAX) { goodness_final = goodness_init; - errorreason = ""; g_log.information("Fit peak/background composite function FAILS to render a better solution."); pop(bkuppeakmap, peakfunc); pop(bkupbkgdmap, bkgdfunc); diff --git a/Code/Mantid/Framework/Algorithms/src/RingProfile.cpp b/Code/Mantid/Framework/Algorithms/src/RingProfile.cpp index 94af655e6b8..c13491f9b80 100644 --- a/Code/Mantid/Framework/Algorithms/src/RingProfile.cpp +++ b/Code/Mantid/Framework/Algorithms/src/RingProfile.cpp @@ -564,18 +564,13 @@ void RingProfile::getBinForPixel(const API::MatrixWorkspace_sptr ws, // the reference to X bins (the limits for each pixel in the horizontal direction) auto xvec = ws->dataX(spectrum_index); - double xpos; - double diffx; - double distance; - double angle; - // for each pixel inside this row for (size_t i = 0; i< xvec.size()-1; i++){ - xpos = (xvec[i] + xvec[i+1])/2.0; // the x position is the centre of the bins boundaries - diffx = xpos - centre_x; + double xpos = (xvec[i] + xvec[i+1])/2.0; // the x position is the centre of the bins boundaries + double diffx = xpos - centre_x; // calculate the distance => norm of pixel position - centre - distance = sqrt(pow(diffx, 2.0) + diffy_quad); + double distance = sqrt(pow(diffx, 2.0) + diffy_quad); // check if the distance is inside the ring if (distance < min_radius || distance > max_radius || distance == 0){ @@ -583,7 +578,7 @@ void RingProfile::getBinForPixel(const API::MatrixWorkspace_sptr ws, continue; } - angle = atan2(diffy, diffx); + double angle = atan2(diffy, diffx); // call fromAngleToBin (radians) bins_pos[i] = fromAngleToBin(angle, false); diff --git a/Code/Mantid/Framework/Crystal/src/SaveHKL.cpp b/Code/Mantid/Framework/Crystal/src/SaveHKL.cpp index a1a880f77c9..38da9c1d5ca 100644 --- a/Code/Mantid/Framework/Crystal/src/SaveHKL.cpp +++ b/Code/Mantid/Framework/Crystal/src/SaveHKL.cpp @@ -252,13 +252,13 @@ namespace Crystal for (int wi=0; wi < 8; wi++)getline(infile,STRING); // Saves the line in STRING. while(!infile.eof()) // To get you all the lines. { - double time0, spectra0; time.resize(a+1); spectra.resize(a+1); getline(infile,STRING); // Saves the line in STRING. std::stringstream ss(STRING); if(STRING.find("Bank") == std::string::npos) - { + { + double time0, spectra0; ss >> time0 >> spectra0; time[a].push_back(time0); spectra[a].push_back(spectra0); diff --git a/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp b/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp index 4c7331628f0..eb778d2460b 100644 --- a/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp +++ b/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp @@ -318,11 +318,11 @@ DECLARE_ALGORITHM(ProcessBackground) size_t numrows = peaktablews->rowCount(); vec_peakcentre.resize(numrows, 0.); vec_peakfwhm.resize(numrows, 0.); - double centre, fwhm; + for (size_t i = 0; i < numrows; ++i) { - centre = peaktablews->cell<double>(i, index_centre); - fwhm = peaktablews->cell<double>(i, index_fwhm); + double centre = peaktablews->cell<double>(i, index_centre); + double fwhm = peaktablews->cell<double>(i, index_fwhm); vec_peakcentre[i] = centre; vec_peakfwhm[i] = fwhm; } @@ -973,11 +973,11 @@ DECLARE_ALGORITHM(ProcessBackground) size_t numrows = peaktablews->rowCount(); vec_peakcentre.resize(numrows, 0.); vec_peakfwhm.resize(numrows, 0.); - double centre, fwhm; + for (size_t i = 0; i < numrows; ++i) { - centre = peaktablews->cell<double>(i, index_centre); - fwhm = peaktablews->cell<double>(i, index_fwhm); + double centre = peaktablews->cell<double>(i, index_centre); + double fwhm = peaktablews->cell<double>(i, index_fwhm); vec_peakcentre[i] = centre; vec_peakfwhm[i] = fwhm; } diff --git a/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp b/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp index b418c22feda..cdbf561c471 100644 --- a/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp +++ b/Code/Mantid/Framework/CurveFitting/src/ReflectivityMulf.cpp @@ -62,13 +62,10 @@ namespace CurveFitting } // 2. Calculate - double lambda,theta0,dthet,dthetr,dt,bgd,scalefac,pthet; - double tl,tlc,con; std::vector<double> dn(m_nlayer+2); std::vector<double> rnbn(m_nlayer+2); std::vector<double> zbb(m_nlayer+2); int nit=21; - int i; std::vector<double> cy(nData); std::complex<double> c0(0.0, 0.0); @@ -103,29 +100,21 @@ namespace CurveFitting std::complex<double> a321(0.0,0.0); std::complex<double> a322(0.0,0.0); - theta0=coeff[0]*PI/180.0; - scalefac=coeff[1]; + double theta0=coeff[0]*PI/180.0; + double scalefac=coeff[1]; rnbn[0]=coeff[2]; rnbn[m_nlayer+1]=coeff[3]; zbb[0]=coeff[4]*coeff[4]; zbb[m_nlayer+1]=0.0; - bgd=coeff[5]; - pthet=coeff[6]; - -/* g_log.information() << "Theta0="<< theta0 << "\n"; - g_log.information() << "scalefac="<< scalefac << "\n"; - g_log.information() << "rnbn[0]="<< rnbn[0] << "\n"; - g_log.information() << "rnbn[m_nlayer+1]="<< rnbn[m_nlayer+1] << "\n"; - g_log.information() << "zbb[0]="<< zbb[0] << "\n"; - g_log.information() << "bgd="<< bgd << "\n"; - g_log.information() << "pthet="<< pthet << "\n"; -*/ + double bgd=coeff[5]; + double pthet=coeff[6]; + dn[0]=0.0; dn[m_nlayer+1]=0.0; if(m_nlayer>0) { - for (i=0;i<m_nlayer;++i) + for (int i=0;i<m_nlayer;++i) { rnbn[i+1]=coeff[7+i*3]; dn[i+1]=coeff[8+i*3]; @@ -138,13 +127,13 @@ namespace CurveFitting std::vector<double> xnit(nit1); int ii,k; - dthet=theta0*pthet/100.0; + double dthet=theta0*pthet/100.0; dthet=dthet/2.35; - dthetr=dthet*2.51; + double dthetr=dthet*2.51; tmax=theta0+dthet*3; tmin=theta0-dthet*3; - dt=(tmax-tmin)/nit; - for (i=0;i<nit1;i++) + double dt=(tmax-tmin)/nit; + for (int i=0;i<nit1;i++) { xnit[i]=tmin+dt*i; } @@ -153,11 +142,11 @@ namespace CurveFitting for (size_t j = 0; j < nData; ++j) { - lambda=4*PI*sin(theta0)/xValues[j]; + double lambda=4*PI*sin(theta0)/xValues[j]; cy[j]=0.0; - tl=lambda*lambda; - tlc=8.0*PI*PI/tl; - con=tl/(2.0*PI); + double tl=lambda*lambda; + double tlc=8.0*PI*PI/tl; + double con=tl/(2.0*PI); for (k=0; k<m_nlayer+2; k++) { @@ -171,7 +160,7 @@ namespace CurveFitting st0=sin(x); pfn[0]=rnfn[0]*st0; - for (i=1;i<m_nlayer+1;i++) + for (int i=1;i<m_nlayer+1;i++) { rnf=(rnfn[i]*rnfn[i])*cr; rnf1=(rnfn[0]*rnfn[0])*cr; @@ -182,7 +171,7 @@ namespace CurveFitting rnf1=(rnfn[0]*rnfn[0])*cr; pfn[m_nlayer+1]=sqrt(rnf-(rnf1*ct0*ct0)); - for (i=1;i<m_nlayer+1;i++) + for (int i=1;i<m_nlayer+1;i++) { betan[i]=2.0*PI*dn[i]*pfn[i]/lambda; } @@ -199,7 +188,7 @@ namespace CurveFitting a121=a112; a122=cr; - for (i=1;i<m_nlayer+1;i++) + for (int i=1;i<m_nlayer+1;i++) { btm=betan[i]*ci; btm1=-1.0*betan[i]*ci; diff --git a/Code/Mantid/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp b/Code/Mantid/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp index d433cedda64..b5a51bd81e0 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp @@ -787,8 +787,6 @@ namespace DataHandling { std::string line; - int currentGroupNo = 1; - try { // We don't use the total number of groups report at the top of the file but we'll tell them @@ -802,6 +800,7 @@ namespace DataHandling throw std::invalid_argument("Expected a single int for the number of groups"); // Parse groups + int currentGroupNo = 1; while(true) { // Read next line ("group spectrum no.") -> ignore the number itself diff --git a/Code/Mantid/Framework/DataHandling/src/LoadLLB.cpp b/Code/Mantid/Framework/DataHandling/src/LoadLLB.cpp index 8c2624fe649..06b5a419fa3 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadLLB.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadLLB.cpp @@ -223,9 +223,6 @@ void LoadLLB::loadDataIntoTheWorkSpace(NeXus::NXEntry& entry) { int LoadLLB::getDetectorElasticPeakPosition(const NeXus::NXFloat &data) { - std::vector<int> listOfFoundEPP; - - std::vector<int> cumulatedSumOfSpectras(m_numberOfChannels, 0); for (size_t i = 0; i < m_numberOfTubes; i++) { diff --git a/Code/Mantid/Framework/DataHandling/src/LoadNexusMonitors.cpp b/Code/Mantid/Framework/DataHandling/src/LoadNexusMonitors.cpp index 193a5c51005..90fce7c24b1 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadNexusMonitors.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadNexusMonitors.cpp @@ -338,8 +338,7 @@ void LoadNexusMonitors::exec() file.openData("name"); instrumentName = file.getStrData(); g_log.debug() << "Instrument name read from NeXus file is " << instrumentName << std::endl; - if (instrumentName.compare("POWGEN3") == 0) // hack for powgen b/c of bad long name - instrumentName = "POWGEN"; + // Now let's close the file as we don't need it anymore to load the instrument. file.closeData(); file.closeGroup(); // Close the NXentry diff --git a/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp b/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp index 41e763d2837..17ceb4c2008 100644 --- a/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D.cpp @@ -256,9 +256,7 @@ bool SaveCanSAS1D::openForAppending(const std::string & filename) void SaveCanSAS1D::findEndofLastEntry() { static const int LAST_TAG_LEN = 11; - static const char LAST_TAG[LAST_TAG_LEN+1] = "</SASentry>"; - // UNCERT should be less than the length of a SASentry - static const int UNCERT = 20; + const int rootTagLen = static_cast<int>(std::string("</SASroot>").length()); try @@ -268,10 +266,13 @@ void SaveCanSAS1D::findEndofLastEntry() char test_tag[LAST_TAG_LEN+1]; m_outFile.read(test_tag, LAST_TAG_LEN); //check we're in the correct place in the file + static const char LAST_TAG[LAST_TAG_LEN+1] = "</SASentry>"; if ( std::string(test_tag,LAST_TAG_LEN)!=std::string(LAST_TAG,LAST_TAG_LEN) ) { //we'll allow some extra charaters so there is some variablity in where the tag might be found - bool tagFound(false); + bool tagFound(false); + // UNCERT should be less than the length of a SASentry + static const int UNCERT = 20; for ( int i = 1; i < UNCERT; ++i ) { //together this seek and read move the file pointer back on byte at a time and read diff --git a/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D2.cpp b/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D2.cpp index 59783466547..3dc7b073904 100644 --- a/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SaveCanSAS1D2.cpp @@ -231,15 +231,14 @@ void SaveCanSAS1D2::createSASTransElement(std::string& sasTrans, const std::stri const MantidVec& ydata = m_ws->readY(0); const MantidVec& edata = m_ws->readE(0); const bool isHistogram = m_ws->isHistogramData(); - double lambda, trans_value, trans_err; for (size_t j = 0; j < m_ws->blocksize(); ++j) { // x data is the Lambda in xml. If histogramdata take the mean - lambda = isHistogram ? (xdata[j] + xdata[j+1])/2: xdata[j]; + double lambda = isHistogram ? (xdata[j] + xdata[j+1])/2: xdata[j]; // y data is the T in xml. - trans_value = ydata[j]; + double trans_value = ydata[j]; // e data is the Tdev in xml. - trans_err = edata[j]; + double trans_err = edata[j]; trans << "\n\t\t\t<Tdata><Lambda unit=\""<<lambda_unit <<"\">"; diff --git a/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp b/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp index dfffb3b22fe..7c6933c0e62 100644 --- a/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp @@ -488,16 +488,14 @@ namespace Mantid << std::setprecision(0) << std::setw(10) << bc2 << std::fixed << " " << std::setprecision(7) << std::setw(10) << bc3 << std::fixed << " 0 FXYE" << std::endl; - double delta, y, e; - for (size_t i = 0; i < datasize; i++) { - y = Y[i]; - e = E[i]; + double y = Y[i]; + double e = E[i]; if (MultiplyByBinWidth) { // Multiple by bin width as - delta = X[i + 1] - X[i]; + double delta = X[i + 1] - X[i]; y *= delta; e *= delta; } diff --git a/Code/Mantid/Framework/DataHandling/src/SetSampleMaterial.cpp b/Code/Mantid/Framework/DataHandling/src/SetSampleMaterial.cpp index 99586272400..8f842fca519 100644 --- a/Code/Mantid/Framework/DataHandling/src/SetSampleMaterial.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SetSampleMaterial.cpp @@ -6,30 +6,30 @@ If you decide to provide specific values you must give values for all three (att If you miss any of the three specific values then the other will be ignored. Neutron scattering lengths and cross sections of the elements and their isotopes have been taken from [http://www.ncnr.nist.gov/resources/n-lengths/list.html]. - *WIKI*/ +*WIKI*/ /*WIKI_USAGE* =====Setting the sample by simple formula===== - SetSampleMaterial(InputWorkspace='IRS26173',ChemicalFormula='Fe') - +SetSampleMaterial(InputWorkspace='IRS26173',ChemicalFormula='Fe') + =====Setting the sample by a more complex formula===== - SetSampleMaterial(InputWorkspace='IRS26173',ChemicalFormula='Al2-O3', UnitCellVolume='253.54', ZParameter='6') +SetSampleMaterial(InputWorkspace='IRS26173',ChemicalFormula='Al2-O3', UnitCellVolume='253.54', ZParameter='6') =====Setting the sample by specific values===== - SetSampleMaterial(InputWorkspace='IRS26173',AtomicNumber=26,AttenuationXSection=2.56,ScatteringXSection=11.62,SampleNumberDensity=0.0849106) +SetSampleMaterial(InputWorkspace='IRS26173',AtomicNumber=26,AttenuationXSection=2.56,ScatteringXSection=11.62,SampleNumberDensity=0.0849106) =====Extracting the set values out by python===== - sam = ws.sample() - mat = sam.getMaterial() - print mat.absorbXSection() - 1.3374 - print mat.cohScatterXSection() - 339.1712 - print mat.name() - C2 H4 - print mat.totalScatterXSection() - 339.1712 - - *WIKI_USAGE*/ +sam = ws.sample() +mat = sam.getMaterial() +print mat.absorbXSection() +1.3374 +print mat.cohScatterXSection() +339.1712 +print mat.name() +C2 H4 +print mat.totalScatterXSection() +339.1712 + +*WIKI_USAGE*/ //-------------------------------- // Includes //-------------------------------- @@ -49,49 +49,49 @@ using namespace Mantid::PhysicalConstants; namespace Mantid { -namespace DataHandling -{ - // Register the algorithm into the AlgorithmFactory - DECLARE_ALGORITHM(SetSampleMaterial) - - SetSampleMaterial::SetSampleMaterial() : Mantid::API::Algorithm() {} - SetSampleMaterial::~SetSampleMaterial() {} - const std::string SetSampleMaterial::name() const + namespace DataHandling { - return "SetSampleMaterial"; - } + // Register the algorithm into the AlgorithmFactory + DECLARE_ALGORITHM(SetSampleMaterial) - int SetSampleMaterial::version() const - { - return (1); - } + SetSampleMaterial::SetSampleMaterial() : Mantid::API::Algorithm() {} + SetSampleMaterial::~SetSampleMaterial() {} + const std::string SetSampleMaterial::name() const + { + return "SetSampleMaterial"; + } - const std::string SetSampleMaterial::category() const - { - return "Sample;DataHandling"; - } + int SetSampleMaterial::version() const + { + return (1); + } - /// Sets documentation strings for this algorithm - void SetSampleMaterial::initDocs() - { - this->setWikiSummary("Sets the neutrons information in the sample."); - this->setOptionalMessage("Sets the neutrons information in the sample."); - } + const std::string SetSampleMaterial::category() const + { + return "Sample;DataHandling"; + } - using namespace Mantid::DataHandling; - using namespace Mantid::API; - using namespace Kernel; + /// Sets documentation strings for this algorithm + void SetSampleMaterial::initDocs() + { + this->setWikiSummary("Sets the neutrons information in the sample."); + this->setOptionalMessage("Sets the neutrons information in the sample."); + } - /** - * Initialize the algorithm - */ - void SetSampleMaterial::init() - { - using namespace Mantid::Kernel; - declareProperty( + using namespace Mantid::DataHandling; + using namespace Mantid::API; + using namespace Kernel; + + /** + * Initialize the algorithm + */ + void SetSampleMaterial::init() + { + using namespace Mantid::Kernel; + declareProperty( new WorkspaceProperty<Workspace>("InputWorkspace","",Direction::InOut), "The workspace with which to associate the sample "); - declareProperty("ChemicalFormula", "", "ChemicalFormula or AtomicNumber must be given. " + declareProperty("ChemicalFormula", "", "ChemicalFormula or AtomicNumber must be given. " "Enter a composition as a molecular formula of \n" "elements or isotopes. For example, basic " "elements might be \"H\", \"Fe\" or \"Si\", etc. \n" @@ -116,225 +116,226 @@ namespace DataHandling "by parenthesis, except for two special " "cases, D and T, which stand for H2 and H3, \n" "respectively."); - declareProperty("AtomicNumber", 0, "ChemicalFormula or AtomicNumber must be given"); - declareProperty("MassNumber", 0, "Mass number if ion (default is 0)"); - auto mustBePositive = boost::make_shared<BoundedValidator<double> >(); - mustBePositive->setLower(0.0); - declareProperty("SampleNumberDensity", EMPTY_DBL(), mustBePositive, + declareProperty("AtomicNumber", 0, "ChemicalFormula or AtomicNumber must be given"); + declareProperty("MassNumber", 0, "Mass number if ion (default is 0)"); + auto mustBePositive = boost::make_shared<BoundedValidator<double> >(); + mustBePositive->setLower(0.0); + declareProperty("SampleNumberDensity", EMPTY_DBL(), mustBePositive, "Optional: This number density of the sample in number of atoms per cubic angstrom will be used instead of calculated"); - declareProperty("ZParameter", EMPTY_DBL(), mustBePositive, + declareProperty("ZParameter", EMPTY_DBL(), mustBePositive, "Number of formulas in the unit cell needed for chemical formulas with more than 1 atom"); - declareProperty("UnitCellVolume", EMPTY_DBL(), mustBePositive, + declareProperty("UnitCellVolume", EMPTY_DBL(), mustBePositive, "Unit cell volume in Angstoms^3 needed for chemical formulas with more than 1 atom"); - declareProperty("CoherentXSection", EMPTY_DBL(), mustBePositive, + declareProperty("CoherentXSection", EMPTY_DBL(), mustBePositive, "Optional: This coherent cross-section for the sample material in barns will be used instead of tabulated"); - declareProperty("IncoherentXSection", EMPTY_DBL(), mustBePositive, + declareProperty("IncoherentXSection", EMPTY_DBL(), mustBePositive, "Optional: This incoherent cross-section for the sample material in barns will be used instead of tabulated"); - declareProperty("AttenuationXSection", EMPTY_DBL(), mustBePositive, + declareProperty("AttenuationXSection", EMPTY_DBL(), mustBePositive, "Optional: This absorption cross-section for the sample material in barns will be used instead of tabulated"); - declareProperty("ScatteringXSection", EMPTY_DBL(), mustBePositive, + declareProperty("ScatteringXSection", EMPTY_DBL(), mustBePositive, "Optional: This total scattering cross-section (coherent + incoherent) for the sample material in barns will be used instead of tabulated"); - - // Perform Group Associations. - std::string formulaGrp("By Formula or Atomic Number"); - setPropertyGroup("ChemicalFormula", formulaGrp); - setPropertyGroup("AtomicNumber", formulaGrp); - setPropertyGroup("MassNumber", formulaGrp); - - std::string densityGrp("Sample Density"); - setPropertyGroup("SampleNumberDensity", densityGrp); - setPropertyGroup("ZParameter", densityGrp); - setPropertyGroup("UnitCellVolume", densityGrp); - - std::string specificValuesGrp("Override Cross Section Values"); - setPropertyGroup("CoherentXSection", specificValuesGrp); - setPropertyGroup("IncoherentXSection", specificValuesGrp); - setPropertyGroup("AttenuationXSection", specificValuesGrp); - setPropertyGroup("ScatteringXSection", specificValuesGrp); - - // Extra property settings - setPropertySettings("AtomicNumber", new Kernel::EnabledWhenProperty("ChemicalFormula", Kernel::IS_DEFAULT)); - setPropertySettings("MassNumber", new Kernel::EnabledWhenProperty("ChemicalFormula", Kernel::IS_DEFAULT)); - - setPropertySettings("UnitCellVolume", new Kernel::EnabledWhenProperty("SampleNumberDensity", Kernel::IS_DEFAULT)); - setPropertySettings("ZParameter", new Kernel::EnabledWhenProperty("SampleNumberDensity", Kernel::IS_DEFAULT)); - - //output properties - declareProperty("SampleNumberDensityResult", EMPTY_DBL(), "The provided or calculated sample number density in atoms/Angstrom^3", Direction::Output); - declareProperty("ReferenceWavelength", EMPTY_DBL(), "The reference wavelength in Angstroms", Direction::Output); - declareProperty("TotalXSectionResult", EMPTY_DBL(), "The provided or calculated total cross-section for the sample material in barns.", Direction::Output); - declareProperty("IncoherentXSectionResult", EMPTY_DBL(), "The provided or calculated incoherent cross-section for the sample material in barns.", Direction::Output); - declareProperty("CoherentXSectionResult", EMPTY_DBL(), "The provided or calculated coherent cross-section for the sample material in barns.", Direction::Output); - declareProperty("AbsorptionXSectionResult", EMPTY_DBL(),"The provided or calculated Absorption cross-section for the sample material in barns.", Direction::Output); - - } - std::map<std::string, std::string> SetSampleMaterial::validateInputs() - { - std::map<std::string, std::string> result; - const std::string chemicalSymbol = getProperty("ChemicalFormula"); - const int z_number = getProperty("AtomicNumber"); - const int a_number = getProperty("MassNumber"); - if (chemicalSymbol.empty()) - { - if (z_number <= 0) - { - result["ChemicalFormula"] = "Need to specify the material"; + // Perform Group Associations. + std::string formulaGrp("By Formula or Atomic Number"); + setPropertyGroup("ChemicalFormula", formulaGrp); + setPropertyGroup("AtomicNumber", formulaGrp); + setPropertyGroup("MassNumber", formulaGrp); + + std::string densityGrp("Sample Density"); + setPropertyGroup("SampleNumberDensity", densityGrp); + setPropertyGroup("ZParameter", densityGrp); + setPropertyGroup("UnitCellVolume", densityGrp); + + std::string specificValuesGrp("Override Cross Section Values"); + setPropertyGroup("CoherentXSection", specificValuesGrp); + setPropertyGroup("IncoherentXSection", specificValuesGrp); + setPropertyGroup("AttenuationXSection", specificValuesGrp); + setPropertyGroup("ScatteringXSection", specificValuesGrp); + + // Extra property settings + setPropertySettings("AtomicNumber", new Kernel::EnabledWhenProperty("ChemicalFormula", Kernel::IS_DEFAULT)); + setPropertySettings("MassNumber", new Kernel::EnabledWhenProperty("ChemicalFormula", Kernel::IS_DEFAULT)); + + setPropertySettings("UnitCellVolume", new Kernel::EnabledWhenProperty("SampleNumberDensity", Kernel::IS_DEFAULT)); + setPropertySettings("ZParameter", new Kernel::EnabledWhenProperty("SampleNumberDensity", Kernel::IS_DEFAULT)); + + //output properties + declareProperty("SampleNumberDensityResult", EMPTY_DBL(), "The provided or calculated sample number density in atoms/Angstrom^3", Direction::Output); + declareProperty("ReferenceWavelength", EMPTY_DBL(), "The reference wavelength in Angstroms", Direction::Output); + declareProperty("TotalXSectionResult", EMPTY_DBL(), "The provided or calculated total cross-section for the sample material in barns.", Direction::Output); + declareProperty("IncoherentXSectionResult", EMPTY_DBL(), "The provided or calculated incoherent cross-section for the sample material in barns.", Direction::Output); + declareProperty("CoherentXSectionResult", EMPTY_DBL(), "The provided or calculated coherent cross-section for the sample material in barns.", Direction::Output); + declareProperty("AbsorptionXSectionResult", EMPTY_DBL(),"The provided or calculated Absorption cross-section for the sample material in barns.", Direction::Output); - } } - else + + std::map<std::string, std::string> SetSampleMaterial::validateInputs() { - if (z_number > 0) - result["AtomicNumber"] = "Cannot specify both ChemicalFormula and AtomicNumber"; - } + std::map<std::string, std::string> result; + const std::string chemicalSymbol = getProperty("ChemicalFormula"); + const int z_number = getProperty("AtomicNumber"); + const int a_number = getProperty("MassNumber"); + if (chemicalSymbol.empty()) + { + if (z_number <= 0) + { + result["ChemicalFormula"] = "Need to specify the material"; - if (a_number > 0 && z_number <= 0) - result["AtomicNumber"] = "Specified MassNumber without AtomicNumber"; + } + } + else + { + if (z_number > 0) + result["AtomicNumber"] = "Cannot specify both ChemicalFormula and AtomicNumber"; + } - return result; - } + if (a_number > 0 && z_number <= 0) + result["AtomicNumber"] = "Specified MassNumber without AtomicNumber"; - /** - * Add the cross sections to the neutron atom if they are not-empty - * numbers. All values are in barns. - * - * @param neutron The neutron to update - * @param coh_xs Coherent cross section - * @param inc_xs Incoherent cross section - * @param abs_xs Absorption cross section - * @param tot_xs Total scattering cross section - */ - void SetSampleMaterial::fixNeutron(NeutronAtom &neutron, - double coh_xs, double inc_xs, - double abs_xs, double tot_xs) - { - if (!isEmpty(coh_xs)) - neutron.coh_scatt_xs = coh_xs; - if (!isEmpty(inc_xs)) - neutron.inc_scatt_xs = inc_xs; - if (!isEmpty(abs_xs)) - neutron.abs_scatt_xs = abs_xs; - if (!isEmpty(tot_xs)) - neutron.tot_scatt_xs = tot_xs; - } + return result; + } - /** - * Execute the algorithm - */ - void SetSampleMaterial::exec() - { - // Get the input workspace - Workspace_sptr workspace = getProperty("InputWorkspace"); - // an ExperimentInfo object has a sample - ExperimentInfo_sptr expInfo = boost::dynamic_pointer_cast<ExperimentInfo>(workspace); - if (!bool(expInfo)) + /** + * Add the cross sections to the neutron atom if they are not-empty + * numbers. All values are in barns. + * + * @param neutron The neutron to update + * @param coh_xs Coherent cross section + * @param inc_xs Incoherent cross section + * @param abs_xs Absorption cross section + * @param tot_xs Total scattering cross section + */ + void SetSampleMaterial::fixNeutron(NeutronAtom &neutron, + double coh_xs, double inc_xs, + double abs_xs, double tot_xs) { - throw std::runtime_error("InputWorkspace does not have a sample object"); + if (!isEmpty(coh_xs)) + neutron.coh_scatt_xs = coh_xs; + if (!isEmpty(inc_xs)) + neutron.inc_scatt_xs = inc_xs; + if (!isEmpty(abs_xs)) + neutron.abs_scatt_xs = abs_xs; + if (!isEmpty(tot_xs)) + neutron.tot_scatt_xs = tot_xs; } - // determine the sample number density - double rho = getProperty("SampleNumberDensity"); // in Angstroms-3 - double zParameter = getProperty("ZParameter"); // number of atoms - if (isEmpty(rho)) + /** + * Execute the algorithm + */ + void SetSampleMaterial::exec() { - double unitCellVolume = getProperty("UnitCellVolume"); // in Angstroms^3 + // Get the input workspace + Workspace_sptr workspace = getProperty("InputWorkspace"); + // an ExperimentInfo object has a sample + ExperimentInfo_sptr expInfo = boost::dynamic_pointer_cast<ExperimentInfo>(workspace); + if (!bool(expInfo)) + { + throw std::runtime_error("InputWorkspace does not have a sample object"); + } - // get the unit cell volume from the workspace if it isn't set - if (isEmpty(unitCellVolume) && expInfo->sample().hasOrientedLattice()) + // determine the sample number density + double rho = getProperty("SampleNumberDensity"); // in Angstroms-3 + double zParameter = getProperty("ZParameter"); // number of atoms + if (isEmpty(rho)) { - unitCellVolume = expInfo->sample().getOrientedLattice().volume(); - g_log.notice() << "found unit cell volume " << unitCellVolume << " Angstrom^-3\n"; + double unitCellVolume = getProperty("UnitCellVolume"); // in Angstroms^3 + + // get the unit cell volume from the workspace if it isn't set + if (isEmpty(unitCellVolume) && expInfo->sample().hasOrientedLattice()) + { + unitCellVolume = expInfo->sample().getOrientedLattice().volume(); + g_log.notice() << "found unit cell volume " << unitCellVolume << " Angstrom^-3\n"; + } + // density is just number of atoms in the unit cell + // ...but only calculate it if you have both numbers + if ((!isEmpty(zParameter)) && (!isEmpty(unitCellVolume))) + rho = zParameter / unitCellVolume; } - // density is just number of atoms in the unit cell - // ...but only calculate it if you have both numbers - if ((!isEmpty(zParameter)) && (!isEmpty(unitCellVolume))) - rho = zParameter / unitCellVolume; - } - // get the scattering information - this will override table values - double coh_xs = getProperty("CoherentXSection"); // in barns - double inc_xs = getProperty("IncoherentXSection"); // in barns - double sigma_atten = getProperty("AttenuationXSection"); // in barns - double sigma_s = getProperty("ScatteringXSection"); // in barns + // get the scattering information - this will override table values + double coh_xs = getProperty("CoherentXSection"); // in barns + double inc_xs = getProperty("IncoherentXSection"); // in barns + double sigma_atten = getProperty("AttenuationXSection"); // in barns + double sigma_s = getProperty("ScatteringXSection"); // in barns - // determine the material - const std::string chemicalSymbol = getProperty("ChemicalFormula"); - const int z_number = getProperty("AtomicNumber"); - const int a_number = getProperty("MassNumber"); + // determine the material + const std::string chemicalSymbol = getProperty("ChemicalFormula"); + const int z_number = getProperty("AtomicNumber"); + const int a_number = getProperty("MassNumber"); - boost::scoped_ptr<Material> mat; - if (!chemicalSymbol.empty()) - { - // Use chemical formula if given by user - Material::ChemicalFormula CF = Material::parseChemicalFormula(chemicalSymbol); - g_log.notice() << "Found " << CF.atoms.size() << " types of atoms in \"" - << chemicalSymbol << "\"\n"; - - double numAtoms = 0.; // number of atoms in formula - NeutronAtom neutron(0, 0., 0., 0., 0., 0., 0.); // starting thing for neutronic information - if (CF.atoms.size() == 1 && isEmpty(zParameter) && isEmpty(rho)) + boost::scoped_ptr<Material> mat; + if (!chemicalSymbol.empty()) { - - Atom myAtom = getAtom(chemicalSymbol, CF.aNumbers[0]); - mat.reset(new Material(chemicalSymbol, myAtom.neutron, myAtom.number_density)); + // Use chemical formula if given by user + Material::ChemicalFormula CF = Material::parseChemicalFormula(chemicalSymbol); + g_log.notice() << "Found " << CF.atoms.size() << " types of atoms in \"" + << chemicalSymbol << "\"\n"; + + + NeutronAtom neutron(0, 0., 0., 0., 0., 0., 0.); // starting thing for neutronic information + if (CF.atoms.size() == 1 && isEmpty(zParameter) && isEmpty(rho)) + { + + Atom myAtom = getAtom(chemicalSymbol, CF.aNumbers[0]); + mat.reset(new Material(chemicalSymbol, myAtom.neutron, myAtom.number_density)); + } + else + { + double numAtoms = 0.; // number of atoms in formula + for (size_t i=0; i<CF.atoms.size(); i++) + { + Atom myAtom = getAtom(CF.atoms[i], CF.aNumbers[i]); + neutron = neutron + CF.numberAtoms[i] * myAtom.neutron; + + g_log.information() << myAtom << ": " << myAtom.neutron << "\n"; + numAtoms += static_cast<double>(CF.numberAtoms[i]); + } + // normalize the accumulated number by the number of atoms + neutron = (1. / numAtoms) * neutron; // funny syntax b/c of operators in neutron atom + + fixNeutron(neutron, coh_xs, inc_xs, sigma_atten, sigma_s); + + // create the material + mat.reset(new Material(chemicalSymbol, neutron, rho)); + } } else { - for (size_t i=0; i<CF.atoms.size(); i++) - { - Atom myAtom = getAtom(CF.atoms[i], CF.aNumbers[i]); - neutron = neutron + CF.numberAtoms[i] * myAtom.neutron; - - g_log.information() << myAtom << ": " << myAtom.neutron << "\n"; - numAtoms += static_cast<double>(CF.numberAtoms[i]); - } - // normalize the accumulated number by the number of atoms - neutron = (1. / numAtoms) * neutron; // funny syntax b/c of operators in neutron atom + // try using the atomic number + Atom atom = getAtom(static_cast<uint16_t>(z_number), static_cast<uint16_t>(a_number)); + NeutronAtom neutron = atom.neutron; + fixNeutron(neutron, coh_xs, inc_xs, sigma_atten, sigma_s); - fixNeutron(neutron, coh_xs, inc_xs, sigma_atten, sigma_s); - - // create the material - mat.reset(new Material(chemicalSymbol, neutron, rho)); + // create the material + mat.reset(new Material(chemicalSymbol, neutron, rho)); } - } - else - { - // try using the atomic number - Atom atom = getAtom(static_cast<uint16_t>(z_number), static_cast<uint16_t>(a_number)); - NeutronAtom neutron = atom.neutron; - fixNeutron(neutron, coh_xs, inc_xs, sigma_atten, sigma_s); - // create the material - mat.reset(new Material(chemicalSymbol, neutron, rho)); + // set the material on workspace + expInfo->mutableSample().setMaterial(*mat); + g_log.notice() << "Sample number density "; + if (isEmpty(mat->numberDensity())) + { + g_log.notice() << "was not specified\n"; + } + else + { + g_log.notice() << "= " << mat->numberDensity() << " atoms/Angstrom^3\n"; + setProperty("SampleNumberDensityResult", mat->numberDensity()); // in atoms/Angstrom^3 + } + g_log.notice() << "Cross sections for wavelength = " << NeutronAtom::ReferenceLambda << "Angstroms\n" + << " Coherent " << mat->cohScatterXSection() << " barns\n" + << " Incoherent " << mat->incohScatterXSection() << " barns\n" + << " Total " << mat->totalScatterXSection() << " barns\n" + << " Absorption " << mat->absorbXSection() << " barns\n"; + setProperty("CoherentXSectionResult", mat->cohScatterXSection()); // in barns + setProperty("IncoherentXSectionResult", mat->incohScatterXSection()); // in barns + setProperty("TotalXSectionResult",mat->totalScatterXSection()); // in barns + setProperty("AbsorptionXSectionResult",mat->absorbXSection()); // in barns + setProperty("ReferenceWavelength",NeutronAtom::ReferenceLambda); // in Angstroms + + // Done! + progress(1); } - // set the material on workspace - expInfo->mutableSample().setMaterial(*mat); - g_log.notice() << "Sample number density "; - if (isEmpty(mat->numberDensity())) - { - g_log.notice() << "was not specified\n"; - } - else - { - g_log.notice() << "= " << mat->numberDensity() << " atoms/Angstrom^3\n"; - setProperty("SampleNumberDensityResult", mat->numberDensity()); // in atoms/Angstrom^3 - } - g_log.notice() << "Cross sections for wavelength = " << NeutronAtom::ReferenceLambda << "Angstroms\n" - << " Coherent " << mat->cohScatterXSection() << " barns\n" - << " Incoherent " << mat->incohScatterXSection() << " barns\n" - << " Total " << mat->totalScatterXSection() << " barns\n" - << " Absorption " << mat->absorbXSection() << " barns\n"; - setProperty("CoherentXSectionResult", mat->cohScatterXSection()); // in barns - setProperty("IncoherentXSectionResult", mat->incohScatterXSection()); // in barns - setProperty("TotalXSectionResult",mat->totalScatterXSection()); // in barns - setProperty("AbsorptionXSectionResult",mat->absorbXSection()); // in barns - setProperty("ReferenceWavelength",NeutronAtom::ReferenceLambda); // in Angstroms - - // Done! - progress(1); } - -} } diff --git a/Code/Mantid/Framework/Geometry/src/Crystal/IndexingUtils.cpp b/Code/Mantid/Framework/Geometry/src/Crystal/IndexingUtils.cpp index 3235ed04917..a5afbf086a6 100644 --- a/Code/Mantid/Framework/Geometry/src/Crystal/IndexingUtils.cpp +++ b/Code/Mantid/Framework/Geometry/src/Crystal/IndexingUtils.cpp @@ -1407,11 +1407,11 @@ size_t IndexingUtils::FFTScanFor_Directions( std::vector<V3D> & directions, std::vector<V3D> full_list = MakeHemisphereDirections( num_steps ); // find the maximum magnitude of Q to set range - double mag_Q; // needed for FFT + // needed for FFT double max_mag_Q = 0; for ( size_t q_num = 1; q_num < q_vectors.size(); q_num++ ) { - mag_Q = q_vectors[ q_num ].norm() / (2.0 * M_PI); + double mag_Q = q_vectors[ q_num ].norm() / (2.0 * M_PI); if ( mag_Q > max_mag_Q ) max_mag_Q = mag_Q; } @@ -1482,12 +1482,12 @@ size_t IndexingUtils::FFTScanFor_Directions( std::vector<V3D> & directions, for ( size_t i = 0; i < temp_dirs.size(); i++ ) { - max_mag_fft = GetMagFFT( q_vectors, - temp_dirs[i], - N_FFT_STEPS, - projections, - index_factor, - magnitude_fft ); + GetMagFFT( q_vectors, + temp_dirs[i], + N_FFT_STEPS, + projections, + index_factor, + magnitude_fft ); double position = GetFirstMaxIndex(magnitude_fft, N_FFT_STEPS, threshold); if ( position > 0 ) @@ -1634,13 +1634,11 @@ double IndexingUtils::GetMagFFT( const std::vector<V3D> & q_vectors, } // project onto direction V3D q_vec; - double dot_prod; - size_t index; for ( size_t q_num = 0; q_num < q_vectors.size(); q_num++ ) { q_vec = q_vectors[ q_num ] / (2.0 * M_PI); - dot_prod = current_dir.scalar_prod( q_vec ); - index = (size_t)fabs(index_factor * dot_prod); + double dot_prod = current_dir.scalar_prod( q_vec ); + size_t index = static_cast<size_t>(fabs(index_factor * dot_prod)); if ( index < N ) projections[ index ] += 1; else @@ -2033,7 +2031,6 @@ void IndexingUtils::DiscardDuplicates( std::vector<V3D> & new_list, V3D next_dir; V3D zero_vec(0,0,0); - double current_length; double next_length; double length_diff; double angle; @@ -2044,7 +2041,7 @@ void IndexingUtils::DiscardDuplicates( std::vector<V3D> & new_list, while ( dir_num < directions.size() ) // put sequence of similar vectors { // in list temp current_dir = directions[ dir_num ]; - current_length = current_dir.norm(); + double current_length = current_dir.norm(); dir_num++; if ( current_length > 0 ) // skip any zero vectors @@ -2083,11 +2080,11 @@ void IndexingUtils::DiscardDuplicates( std::vector<V3D> & new_list, } // now scan through temp list to int max_indexed = 0; // find the one that indexes most - int num_indexed; + int max_i = -1; for ( size_t i = 0; i < temp.size(); i++ ) { - num_indexed = NumberIndexed_1D( temp[i], + int num_indexed = NumberIndexed_1D( temp[i], q_vectors, required_tolerance ); if ( num_indexed > max_indexed ) @@ -2229,22 +2226,16 @@ double IndexingUtils::IndexingError( const DblMatrix & UB, "Different size hkl and q_vectors in IndexingError()"); } - double h_error; - double k_error; - double l_error; + double total_error = 0; V3D hkl; for ( size_t i = 0; i < hkls.size(); i++ ) { hkl = UB_inverse * q_vectors[i] / (2.0 * M_PI); -/* - h_error = fabs( hkl[0] - round(hkls[i][0]) ); - k_error = fabs( hkl[1] - round(hkls[i][1]) ); - l_error = fabs( hkl[2] - round(hkls[i][2]) ); -*/ - h_error = fabs( hkl[0] - round(hkl[0]) ); - k_error = fabs( hkl[1] - round(hkl[1]) ); - l_error = fabs( hkl[2] - round(hkl[2]) ); + + double h_error = fabs( hkl[0] - round(hkl[0]) ); + double k_error = fabs( hkl[1] - round(hkl[1]) ); + double l_error = fabs( hkl[2] - round(hkl[2]) ); total_error += h_error + k_error + l_error; } @@ -2373,16 +2364,13 @@ int IndexingUtils::NumberIndexed_1D( const V3D & direction, if ( direction.norm() == 0 ) return 0; - double proj_value; - double error; - int nearest_int; int count = 0; for ( size_t i = 0; i < q_vectors.size(); i++ ) { - proj_value = direction.scalar_prod( q_vectors[i] ) / (2.0 * M_PI); - nearest_int = round( proj_value ); - error = fabs( proj_value - nearest_int ); + double proj_value = direction.scalar_prod( q_vectors[i] ) / (2.0 * M_PI); + int nearest_int = round( proj_value ); + double error = fabs( proj_value - nearest_int ); if ( error <= tolerance ) { count++; @@ -2552,9 +2540,6 @@ int IndexingUtils::GetIndexedPeaks_1D( const V3D & direction, std::vector<V3D> & indexed_qs, double & fit_error ) { - int nearest_int; - double proj_value; - double error; int num_indexed = 0; index_vals.clear(); indexed_qs.clear(); @@ -2569,9 +2554,9 @@ int IndexingUtils::GetIndexedPeaks_1D( const V3D & direction, for ( size_t q_num = 0; q_num < q_vectors.size(); q_num++ ) { - proj_value = direction.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); - nearest_int = round( proj_value ); - error = fabs( proj_value - nearest_int ); + double proj_value = direction.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); + int nearest_int = round( proj_value ); + double error = fabs( proj_value - nearest_int ); if ( error < required_tolerance ) { fit_error += error * error; @@ -2629,15 +2614,6 @@ int IndexingUtils::GetIndexedPeaks_3D( const V3D & direction_1, std::vector<V3D> & indexed_qs, double & fit_error ) { - double projected_h; - double projected_k; - double projected_l; - double h_error; - double k_error; - double l_error; - int h_int; - int k_int; - int l_int; V3D hkl; int num_indexed = 0; @@ -2651,21 +2627,21 @@ int IndexingUtils::GetIndexedPeaks_3D( const V3D & direction_1, for ( size_t q_num = 0; q_num < q_vectors.size(); q_num++ ) { - projected_h = direction_1.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); - projected_k = direction_2.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); - projected_l = direction_3.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); + double projected_h = direction_1.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); + double projected_k = direction_2.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); + double projected_l = direction_3.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); hkl( projected_h, projected_k, projected_l ); if ( ValidIndex( hkl, required_tolerance ) ) { - h_int = round( projected_h ); - k_int = round( projected_k ); - l_int = round( projected_l ); + int h_int = round( projected_h ); + int k_int = round( projected_k ); + int l_int = round( projected_l ); - h_error = fabs( projected_h - h_int ); - k_error = fabs( projected_k - k_int ); - l_error = fabs( projected_l - l_int ); + double h_error = fabs( projected_h - h_int ); + double k_error = fabs( projected_k - k_int ); + double l_error = fabs( projected_l - l_int ); fit_error += h_error*h_error + k_error*k_error + l_error*l_error; @@ -2943,20 +2919,18 @@ int IndexingUtils::SelectDirection( V3D & best_direction, throw std::invalid_argument("SelectDirection(): List of possible directions has zero length"); } - double dot_product; int nearest_int; double error; - double sum_sq_error; double min_sum_sq_error = 1.0e100; for ( size_t dir_num = 0; dir_num < direction_list.size(); dir_num++ ) { - sum_sq_error = 0; + double sum_sq_error = 0; V3D direction = direction_list[ dir_num ]; direction/=plane_spacing; for ( size_t q_num = 0; q_num < q_vectors.size(); q_num++ ) { - dot_product = direction.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); + double dot_product = direction.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); nearest_int = round( dot_product ); error = fabs( dot_product - nearest_int ); sum_sq_error += error * error; @@ -2969,11 +2943,10 @@ int IndexingUtils::SelectDirection( V3D & best_direction, } } - double proj_value = 0; int num_indexed = 0; for ( size_t q_num = 0; q_num < q_vectors.size(); q_num++ ) { - proj_value = best_direction.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); + double proj_value = best_direction.scalar_prod( q_vectors[ q_num ] ) / (2.0 * M_PI); nearest_int = round( proj_value ); error = fabs( proj_value - nearest_int ); if ( error < required_tolerance ) @@ -3286,7 +3259,6 @@ bool IndexingUtils::MakeNiggliUB( const DblMatrix & UB, // some tests with 5% noise double length_tol = 0.001; double total_length; - double next_length; std::vector<DblMatrix> short_list; short_list.push_back( UB_list[0] ); @@ -3298,7 +3270,7 @@ bool IndexingUtils::MakeNiggliUB( const DblMatrix & UB, while ( i < UB_list.size() && !got_short_list ) { GetABC( UB_list[i], v1, v2, v3 ); - next_length = v1.norm() + v2.norm() + v3.norm(); + double next_length = v1.norm() + v2.norm() + v3.norm(); if ( fabs(next_length - total_length)/total_length < length_tol ) short_list.push_back( UB_list[i] ); else diff --git a/Code/Mantid/Framework/Geometry/src/Crystal/ScalarUtils.cpp b/Code/Mantid/Framework/Geometry/src/Crystal/ScalarUtils.cpp index 020bb75d45c..0f414733c5e 100644 --- a/Code/Mantid/Framework/Geometry/src/Crystal/ScalarUtils.cpp +++ b/Code/Mantid/Framework/Geometry/src/Crystal/ScalarUtils.cpp @@ -228,7 +228,6 @@ ConventionalCell ScalarUtils::GetCellForForm( const DblMatrix & UB, ReducedCell form_0; ReducedCell form; - double error; double min_error = 1e20; // errors are usually < 10, so this is big enough std::vector<double> l_params; @@ -245,7 +244,7 @@ ConventionalCell ScalarUtils::GetCellForForm( const DblMatrix & UB, form = ReducedCell( form_num, l_params[0], l_params[1], l_params[2], l_params[3], l_params[4], l_params[5] ); - error = form_0.WeightedDistance( form ); + double error = form_0.WeightedDistance( form ); if ( error < min_error ) { info = ConventionalCell( UB_list[i], form_num ); @@ -307,14 +306,13 @@ ConventionalCell ScalarUtils::GetCellBestError( ConventionalCell info = list[0]; double min_error = 1.0e20; - double error; std::string type; bool min_found = false; for ( size_t i = 0; i < list.size(); i++ ) { type = list[i].GetCellType(); - error = list[i].GetError(); + double error = list[i].GetError(); if ( ( use_triclinic || type != ReducedCell::TRICLINIC() ) && error < min_error ) { diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp index 32c1485e118..37bcd1493cf 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp @@ -144,12 +144,11 @@ namespace Mantid double DetectorGroup::getSignedTwoTheta(const Kernel::V3D& observer, const Kernel::V3D& axis, const Kernel::V3D& instrumentUp) const { double result = 0.0; - double angle = 0.0; DetCollection::const_iterator it; for (it = m_detectors.begin(); it != m_detectors.end(); ++it) { const V3D sampleDetVec = it->second->getPos() - observer; - angle = sampleDetVec.angle(axis); + double angle = sampleDetVec.angle(axis); V3D cross = axis.cross_prod(sampleDetVec); V3D normToSurface = axis.cross_prod(instrumentUp); diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp index e1838b4a0a1..d3c34281303 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp @@ -117,12 +117,11 @@ std::string Goniometer::axesInfo() } else { - double angle; info<<"Name \t Direction \t Sense \t Angle \n"; for(it=motors.begin(); it<motors.end(); ++it) { sense=((*it).sense==CCW)?strCCW:strCW; - angle=((*it).angleunit==angDegrees)?((*it).angle): ((*it).angle*rad2deg); + double angle=((*it).angleunit==angDegrees)?((*it).angle): ((*it).angle*rad2deg); info<<(*it).name<<"\t"<<(*it).rotationaxis<<"\t"<<sense<<"\t"<<angle<<std::endl; } } @@ -291,10 +290,9 @@ void Goniometer::recalculateR() std::vector<double> elements; Quat QGlobal,QCurrent; - double ang; for(it=motors.begin(); it<motors.end(); ++it) { - ang=(*it).angle; + double ang=(*it).angle; if((*it).angleunit==angRadians) ang*=rad2deg; QCurrent=Quat(ang,(*it).rotationaxis); QGlobal*=QCurrent; diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp index 6a646f4d6d6..1be030b78f6 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp @@ -2390,9 +2390,6 @@ namespace Geometry bool alongPhi = false; double x=0.0, y=0.0, z=0.0; - double x_end=0.0; - double y_end=0.0; - double z_end=0.0; bool alongX = false; bool alongY = false; bool alongZ = false; @@ -2501,7 +2498,7 @@ namespace Geometry { if ( pElem->hasAttribute("y-end") || pElem->hasAttribute("z-end") ) throwTooManyEndAttributeInLocations("x-end", "y-end or z-end"); - x_end = atof((pElem->getAttribute("x-end")).c_str()); + double x_end = atof((pElem->getAttribute("x-end")).c_str()); alongX = true; step = (x_end - x) / static_cast<double>(n_elements-1); nAlong++; @@ -2511,7 +2508,7 @@ namespace Geometry { if ( pElem->hasAttribute("x-end") || pElem->hasAttribute("z-end") ) throwTooManyEndAttributeInLocations("y-end", "x-end or z-end"); - y_end = atof((pElem->getAttribute("y-end")).c_str()); + double y_end = atof((pElem->getAttribute("y-end")).c_str()); alongY = true; step = (y_end - y) / static_cast<double>(n_elements-1); nAlong++; @@ -2521,7 +2518,7 @@ namespace Geometry { if ( pElem->hasAttribute("x-end") || pElem->hasAttribute("y-end") ) throwTooManyEndAttributeInLocations("z-end", "x-end or y-end"); - z_end = atof((pElem->getAttribute("z-end")).c_str()); + double z_end = atof((pElem->getAttribute("z-end")).c_str()); alongZ = true; step = (z_end - z) / static_cast<double>(n_elements-1); nAlong++; @@ -2530,7 +2527,6 @@ namespace Geometry // also check if 'rot' is the one to step through double rot=0.0; - double rot_end = 0.0; bool along_rot = false; if ( pElem->hasAttribute("rot") ) { @@ -2538,7 +2534,7 @@ namespace Geometry if ( pElem->hasAttribute("rot-end") ) { - rot_end = atof((pElem->getAttribute("rot-end")).c_str()); + double rot_end = atof((pElem->getAttribute("rot-end")).c_str()); along_rot = true; step = (rot_end - rot) / static_cast<double>(n_elements-1); nAlong++; diff --git a/Code/Mantid/Framework/Geometry/src/Math/Acomp.cpp b/Code/Mantid/Framework/Geometry/src/Math/Acomp.cpp index cc4b2d45f72..6511e2493b9 100644 --- a/Code/Mantid/Framework/Geometry/src/Math/Acomp.cpp +++ b/Code/Mantid/Framework/Geometry/src/Math/Acomp.cpp @@ -623,10 +623,10 @@ namespace Mantid @param BX :: binary component */ { - int flag,S,V; + int S,V; for(int i=0;i<static_cast<int>(BX.Size());i++) { - flag=BX[i]; + int flag=BX[i]; if (flag) { split(flag,S,V); @@ -1393,7 +1393,7 @@ namespace Mantid if (retJoin!=1) // single unit is alway ok retJoin=1-Intersect; - int aimTruth,S,V; + int S,V; std::map<int,int>::const_iterator bv; std::vector<int>::const_iterator uc; // e.g. a'b 1 1 (retJoin ==1) @@ -1403,7 +1403,7 @@ namespace Mantid bv=Base.find(V); if (bv==Base.end()) throw std::runtime_error("Base unit not found"); - aimTruth= (S<0) ? 1-retJoin : retJoin; + int aimTruth= (S<0) ? 1-retJoin : retJoin; if (bv->second == aimTruth) // any true then return true return retJoin; @@ -1445,8 +1445,7 @@ namespace Mantid std::vector<Acomp> V; // Only have First level components to consider std::vector<Acomp>::const_iterator cc; - int cell; - + std::vector<Acomp> Flist,Glist; if (!getDNFpart(Flist) || !G.getDNFpart(Glist)) return std::pair<Acomp,Acomp>(Acomp(),Acomp()); @@ -1458,6 +1457,7 @@ namespace Mantid V.push_back(Acomp(0)); //intersection Unit Acomp& Uitem= U.back(); Acomp& Vitem= V.back(); + int cell; while( (cell = cc->itemN(itemCnt)) ) { if (Gmap.find(cell)!=Gmap.end()) @@ -1793,13 +1793,7 @@ namespace Mantid { if (!Intersect && (vc!=Comp.begin() || !Units.empty())) cx<<'+'; - // if ( join && (*vc)->type() ) - if ( !vc->Intersect ) - cx<<'('<<vc->display()<<')'; - else - cx<<'('<<vc->display()<<')'; - // cx<<vc->display(); - + cx<<'('<<vc->display()<<')'; } return cx.str(); } diff --git a/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp b/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp index 11111c6d8d9..435c672560d 100644 --- a/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp +++ b/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp @@ -882,12 +882,12 @@ namespace Mantid // angles. This could be optimised further e.g. by // using a light weight version of the interceptSurface method - this does more work // than is necessary in this application. - // Accuracy is of the order of 1% for objects with an accurate boundng box, though + // Accuracy is of the order of 1% for objects with an accurate bounding box, though // less in the case of high aspect ratios. // // resBB controls accuracy and cost - linear accuracy improvement with increasing res, // but quadratic increase in run time. If no bounding box found, resNoBB used instead. - const int resNoBB = 200, resBB = 100, resPhiMin = 10; + const int resNoBB = 200, resPhiMin = 10; int res = resNoBB, itheta, jphi, resPhi; double theta, phi, sum, dphi, dtheta; if (this->isValid(observer) && !this->isOnSide(observer)) @@ -907,6 +907,7 @@ namespace Mantid useBB = usePt = true; thetaMax = boundingBox.angularWidth(observer); ptInObject = boundingBox.centrePoint(); + const int resBB = 100; res = resBB; } // Try and find a point in the object if useful bounding box not found diff --git a/Code/Mantid/Framework/Geometry/src/Objects/ShapeFactory.cpp b/Code/Mantid/Framework/Geometry/src/Objects/ShapeFactory.cpp index 1adf96a3f15..414b0355e1a 100644 --- a/Code/Mantid/Framework/Geometry/src/Objects/ShapeFactory.cpp +++ b/Code/Mantid/Framework/Geometry/src/Objects/ShapeFactory.cpp @@ -259,11 +259,10 @@ boost::shared_ptr<Object> ShapeFactory::createShape(Poco::XML::Element* pElem) //std::string algebra; // to hold algebra in a way Mantid can understand std::map<std::string,std::string>::iterator iter; - size_t found; std::map<size_t,std::string, std::greater<size_t> > allFound; for( iter = idMatching.begin(); iter != idMatching.end(); ++iter ) { - found = algebraFromUser.find(iter->first); + size_t found = algebraFromUser.find(iter->first); if (found==std::string::npos) { diff --git a/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryRenderer.cpp b/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryRenderer.cpp index 2d4c53b793a..10458816a6d 100644 --- a/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryRenderer.cpp +++ b/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryRenderer.cpp @@ -61,13 +61,12 @@ namespace Mantid { (void) noPts; //Avoid compiler warning glBegin(GL_TRIANGLES); - int index1, index2, index3; V3D normal; for (int i = 0; i < noFaces; i++) { - index1 = faces[i * 3] * 3; - index2 = faces[i * 3 + 1] * 3; - index3 = faces[i * 3 + 2] * 3; + int index1 = faces[i * 3] * 3; + int index2 = faces[i * 3 + 1] * 3; + int index3 = faces[i * 3 + 2] * 3; //Calculate normal and normalize V3D v1(points[index1], points[index1 + 1], points[index1 + 2]); V3D v2(points[index2], points[index2 + 1], points[index2 + 2]); diff --git a/Code/Mantid/Framework/ICat/src/ICat4/ICat4Catalog.cpp b/Code/Mantid/Framework/ICat/src/ICat4/ICat4Catalog.cpp index 3c1dd39967a..59cdec7fe29 100644 --- a/Code/Mantid/Framework/ICat/src/ICat4/ICat4Catalog.cpp +++ b/Code/Mantid/Framework/ICat/src/ICat4/ICat4Catalog.cpp @@ -376,7 +376,7 @@ namespace Mantid catch(std::runtime_error& exception) { g_log.information("An error occurred when saving the ICat search results data to Workspace"); - throw exception; + throw; } } else @@ -449,7 +449,7 @@ namespace Mantid catch(std::runtime_error& exception) { g_log.information("An error occurred when saving file data to workspace."); - throw exception; + throw; } } } @@ -522,7 +522,7 @@ namespace Mantid catch(std::runtime_error& exception) { g_log.information("An error occurred when saving file data to workspace."); - throw exception; + throw; } } else diff --git a/Code/Mantid/Framework/Kernel/src/BinFinder.cpp b/Code/Mantid/Framework/Kernel/src/BinFinder.cpp index f92fae943ac..464b82d30cb 100644 --- a/Code/Mantid/Framework/Kernel/src/BinFinder.cpp +++ b/Code/Mantid/Framework/Kernel/src/BinFinder.cpp @@ -117,7 +117,7 @@ namespace Kernel int BinFinder::bin(double x) { int index; - double min, max; + double min; //Too small? if (x < boundaries[0]) @@ -128,7 +128,7 @@ namespace Kernel for (i=0; i < numRegions; i++) { min = boundaries[i]; - max = boundaries[i+1]; + double max = boundaries[i+1]; if ( (x >= min) && (x < max) ) break; } diff --git a/Code/Mantid/Framework/Kernel/src/Matrix.cpp b/Code/Mantid/Framework/Kernel/src/Matrix.cpp index c62f669c42a..40837c156b5 100644 --- a/Code/Mantid/Framework/Kernel/src/Matrix.cpp +++ b/Code/Mantid/Framework/Kernel/src/Matrix.cpp @@ -1163,12 +1163,11 @@ Matrix<T>::factor() if (nx!=ny || nx<1) throw std::runtime_error("Matrix::factor Matrix is not NxN"); - double Pmax; double deter=1.0; for(int i=0;i<static_cast<int>(nx)-1;i++) //loop over each row { int jmax=i; - Pmax=fabs(V[i][i]); + double Pmax=fabs(V[i][i]); for(int j=i+1;j<static_cast<int>(nx);j++) // find max in Row i { if (fabs(V[i][j])>Pmax) @@ -1256,7 +1255,6 @@ Matrix<T>::lubcmp(int* rowperm,int& interchange) @param rowperm :: row permuations [nx values] */ { - int imax(0),j,k; double sum,dum,big,temp; if (nx!=ny || nx<2) @@ -1269,7 +1267,7 @@ Matrix<T>::lubcmp(int* rowperm,int& interchange) for(int i=0;i<static_cast<int>(nx);i++) { big=0.0; - for(j=0;j<static_cast<int>(nx);j++) + for(int j=0;j<static_cast<int>(nx);j++) if ((temp=fabs(V[i][j])) > big) big=temp; @@ -1281,21 +1279,21 @@ Matrix<T>::lubcmp(int* rowperm,int& interchange) vv[i]=1.0/big; } - for (j=0;j<static_cast<int>(nx);j++) + for (int j=0;j<static_cast<int>(nx);j++) { for(int i=0;i<j;i++) { sum=V[i][j]; - for(k=0;k<i;k++) + for(int k=0;k<i;k++) sum-= V[i][k] * V[k][j]; V[i][j]=static_cast<T>(sum); } big=0.0; - imax=j; + int imax=j; for (int i=j;i<static_cast<int>(nx);i++) { sum=V[i][j]; - for (k=0;k<j;k++) + for (int k=0;k<j;k++) sum -= V[i][k] * V[k][j]; V[i][j]=static_cast<T>(sum); if ( (dum=vv[i] * fabs(sum)) >=big) @@ -1307,7 +1305,7 @@ Matrix<T>::lubcmp(int* rowperm,int& interchange) if (j!=imax) { - for(k=0;k<static_cast<int>(nx);k++) + for(int k=0;k<static_cast<int>(nx);k++) { //Interchange rows dum=V[imax][k]; V[imax][k]=V[j][k]; @@ -1457,7 +1455,6 @@ Matrix<T>::Diagonalise(Matrix<T>& EigenVec,Matrix<T>& DiagMatrix) const @return :: 1 on success 0 on failure */ { - double theta,tresh,tanAngle,cosAngle,sinAngle; if(nx!=ny || nx<1) { std::cerr<<"Matrix not square"<<std::endl; @@ -1490,10 +1487,9 @@ Matrix<T>::Diagonalise(Matrix<T>& EigenVec,Matrix<T>& DiagMatrix) const } int iteration=0; - double sm; for(int i=0;i<100;i++) //max 50 iterations { - sm=0.0; // sum of off-diagonal terms + double sm=0.0; // sum of off-diagonal terms for(size_t ip=0;ip<nx-1;ip++) for(size_t iq=ip+1;iq<nx;iq++) sm+=fabs(A.V[ip][iq]); @@ -1508,7 +1504,7 @@ Matrix<T>::Diagonalise(Matrix<T>& EigenVec,Matrix<T>& DiagMatrix) const } // Threshold large for first 5 sweeps - tresh= (i<6) ? 0.2*sm/static_cast<int>(nx*nx) : 0.0; + double tresh= (i<6) ? 0.2*sm/static_cast<int>(nx*nx) : 0.0; for(int ip=0;ip<static_cast<int>(nx)-1;ip++) { @@ -1523,12 +1519,13 @@ Matrix<T>::Diagonalise(Matrix<T>& EigenVec,Matrix<T>& DiagMatrix) const else if (fabs(A.V[ip][iq])>tresh) { + double tanAngle,cosAngle,sinAngle; double h=Diag[iq]-Diag[ip]; if (static_cast<float>((fabs(h)+g)) == static_cast<float>(fabs(h))) tanAngle=A.V[ip][iq]/h; // tanAngle=1/(2theta) else { - theta=0.5*h/A.V[ip][iq]; + double theta=0.5*h/A.V[ip][iq]; tanAngle=1.0/(fabs(theta)+sqrt(1.0+theta*theta)); if (theta<0.0) tanAngle = -tanAngle; @@ -1620,14 +1617,13 @@ std::vector<T> Matrix<T>::toRotation() if (this->nx != this->ny) throw(std::invalid_argument("matrix is not square")); if (fabs(this->determinant()) <1e-10) throw(std::invalid_argument("Determinant is too small")); // step 1: orthogonalize the matrix - double spself,spother; for (size_t i=0; i<this->ny;++i) { - spself=0.; + double spself=0.; for (size_t j=0; j<this->nx;++j) spself+=(V[j][i]*V[j][i]); for (size_t k=i+1; k<this->ny;++k) { - spother=0; + double spother=0; for (size_t j=0; j<this->nx;++j) spother+=(V[j][i]*V[j][k]); for (size_t j=0; j<this->nx;++j) V[j][k]-=static_cast<T>(V[j][i]*spother/spself); } diff --git a/Code/Mantid/Framework/Kernel/src/Statistics.cpp b/Code/Mantid/Framework/Kernel/src/Statistics.cpp index f8cd235a50a..390dddcd348 100644 --- a/Code/Mantid/Framework/Kernel/src/Statistics.cpp +++ b/Code/Mantid/Framework/Kernel/src/Statistics.cpp @@ -104,7 +104,7 @@ namespace Mantid return Zscore; } std::vector<double> Zscore; - double tmp; + Statistics stats = getStatistics(data, sorted); if(stats.standard_deviation == 0.) { @@ -114,7 +114,7 @@ namespace Mantid typename vector<TYPE>::const_iterator it = data.begin(); for (; it != data.end(); ++it) { - tmp = static_cast<double> (*it); + double tmp = static_cast<double> (*it); Zscore.push_back(fabs((tmp - stats.mean) / stats.standard_deviation)); } return Zscore; @@ -181,11 +181,10 @@ namespace Mantid stats.minimum = stats.mean; stats.maximum = stats.mean; double stddev = 0.; - double temp; typename vector<TYPE>::const_iterator it = data.begin(); for (; it != data.end(); ++it) { - temp = static_cast<double> (*it); + double temp = static_cast<double> (*it); stddev += ((temp - stats.mean) * (temp - stats.mean)); if (temp > stats.maximum) stats.maximum = temp; @@ -280,6 +279,7 @@ namespace Mantid rfactor.Rp = (sumrpnom/sumrpdenom); rfactor.Rwp = std::sqrt(sumnom/sumdenom); + // cppcheck-suppress duplicateExpression if (rfactor.Rwp != rfactor.Rwp) std::cout << "Rwp is NaN. Denominator = " << sumnom << "; Nominator = " << sumdenom << ". \n"; diff --git a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp index 4b19661a467..05734b091e7 100644 --- a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp +++ b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp @@ -386,16 +386,12 @@ namespace Mantid // And at the same time, iterate through the splitter Kernel::TimeSplitterType::iterator itspl = splitter.begin(); - //Info of each splitter - DateAndTime start, stop; - int index; - while (itspl != splitter.end()) { //Get the splitting interval times and destination - start = itspl->start(); - stop = itspl->stop(); - index = itspl->index(); + DateAndTime start = itspl->start(); + DateAndTime stop = itspl->stop(); + int index = itspl->index(); // Skip the events before the start of the time // TODO Algorithm here can be refactored for better performance diff --git a/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp b/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp index a753e5e8962..4d87b05a376 100644 --- a/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp +++ b/Code/Mantid/Framework/Kernel/src/VectorHelper.cpp @@ -114,14 +114,14 @@ void rebin(const std::vector<double>& xold, const std::vector<double>& yold, con } size_t iold = 0, inew = 0; - double xo_low, xo_high, xn_low, xn_high, delta(0.0), width; + double width; while ((inew < size_ynew) && (iold < size_yold)) { - xo_low = xold[iold]; - xo_high = xold[iold + 1]; - xn_low = xnew[inew]; - xn_high = xnew[inew + 1]; + double xo_low = xold[iold]; + double xo_high = xold[iold + 1]; + double xn_low = xnew[inew]; + double xn_high = xnew[inew + 1]; if (xn_high <= xo_low) inew++; /* old and new bins do not overlap */ else if (xo_high <= xn_low) @@ -130,7 +130,7 @@ void rebin(const std::vector<double>& xold, const std::vector<double>& yold, con { // delta is the overlap of the bins on the x axis //delta = std::min(xo_high, xn_high) - std::max(xo_low, xn_low); - delta = xo_high < xn_high ? xo_high : xn_high; + double delta = xo_high < xn_high ? xo_high : xn_high; delta -= xo_low > xn_low ? xo_low : xn_low; width = xo_high - xo_low; if ((delta <= 0.0) || (width <= 0.0)) diff --git a/Code/Mantid/Framework/LiveData/src/ISISLiveEventDataListener.cpp b/Code/Mantid/Framework/LiveData/src/ISISLiveEventDataListener.cpp index 15ba2d75047..3289f213f67 100644 --- a/Code/Mantid/Framework/LiveData/src/ISISLiveEventDataListener.cpp +++ b/Code/Mantid/Framework/LiveData/src/ISISLiveEventDataListener.cpp @@ -230,7 +230,6 @@ void ISISLiveEventDataListener::run() if (m_isConnected == false) // sanity check { throw std::runtime_error( std::string("No connection to the DAE.")); - return; // should never be called, but here just in case exceptions are disabled } TCPStreamEventDataNeutron events; diff --git a/Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDHelper.cpp b/Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDHelper.cpp index 4c1f94cb003..b2168b3e5b7 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDHelper.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDHelper.cpp @@ -144,10 +144,10 @@ namespace MDAlgorithms MatrixWorkspace_sptr ws=getProperty("InputWorkspace"),wstemp; DataObjects::EventWorkspace_sptr evWS; - double xmin,xmax; if (QDimension=="CopyToMD") { + double xmin,xmax; ws->getXMinMax(xmin,xmax); MinValues.push_back(xmin); MaxValues.push_back(xmax); diff --git a/Code/Mantid/Framework/MDAlgorithms/src/DivideMD.cpp b/Code/Mantid/Framework/MDAlgorithms/src/DivideMD.cpp index 354a88e5adf..a90a9de831e 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/DivideMD.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/DivideMD.cpp @@ -119,9 +119,9 @@ namespace MDAlgorithms for (size_t i=0; i<boxes.size(); i++) { MDBox<MDE,nd> * box = dynamic_cast<MDBox<MDE,nd> *>(boxes[i]); - size_t ic(0); if (box) { + size_t ic(0); typename std::vector<MDE> & events = box->getEvents(); typename std::vector<MDE>::iterator it = events.begin(); typename std::vector<MDE>::iterator it_end = events.end(); diff --git a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp index 37dd44ae72a..67a24d80b5e 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp @@ -242,7 +242,7 @@ namespace Mantid declareProperty(new Kernel::PropertyWithValue<bool>("MetadataOnly", false), "Load Metadata without events."); std::vector<std::string> fileExtensions2(1); - fileExtensions[0]=".nxs"; + fileExtensions2[0]=".nxs"; declareProperty(new API::FileProperty("OutputFilename","", API::FileProperty::OptionalSave, fileExtensions2), "If the input SQW file is too large to fit in memory, specify an output NXS file.\n" "The MDEventWorkspace will be create with this file as its back-end."); @@ -1036,11 +1036,10 @@ namespace LoadSQWHelper dataStream.seekg(npax*4,std::ios_base::cur); mdImageSize = 1; - unsigned int nAxisPoints; for(unsigned int i=0;i<npax;i++){ dataStream.read(&data_buffer[0],4); - nAxisPoints = *((uint32_t*)(&data_buffer[0])); + unsigned int nAxisPoints = *((uint32_t*)(&data_buffer[0])); nBins[i] = nAxisPoints-1; mdImageSize *= nBins[i] ; dataStream.seekg(nAxisPoints*4,std::ios_base::cur); diff --git a/Code/Mantid/Framework/MDEvents/src/BoxControllerNeXusIO.cpp b/Code/Mantid/Framework/MDEvents/src/BoxControllerNeXusIO.cpp index 69a0aadc979..50f848f6968 100644 --- a/Code/Mantid/Framework/MDEvents/src/BoxControllerNeXusIO.cpp +++ b/Code/Mantid/Framework/MDEvents/src/BoxControllerNeXusIO.cpp @@ -466,8 +466,7 @@ void BoxControllerNeXusIO::loadBlock(std::vector<double> & Block, const uint64_t { std::vector<int64_t> free_dims(2,2); free_dims[0] = int64_t(freeSpaceBlocks.size()/2); - std::vector<int64_t> free_chunk(2,2); - free_chunk[0] =int64_t(m_dataChunk); + m_File->writeUpdatedData("free_space_blocks", freeSpaceBlocks, free_dims); } } diff --git a/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp b/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp index 3a1bcc73252..eda675d5692 100644 --- a/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp +++ b/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp @@ -194,15 +194,13 @@ int Integrate3DEvents::numInEllipsoid( std::vector<V3D> const & events, std::vector<V3D> const & directions, std::vector<double> const & sizes ) { - int count = 0; - double comp; - double sum; + int count = 0; for ( size_t i = 0; i < events.size(); i++ ) { - sum = 0; + double sum = 0; for ( size_t k = 0; k < 3; k++ ) { - comp = events[i].scalar_prod( directions[k] ) / sizes[k]; + double comp = events[i].scalar_prod( directions[k] ) / sizes[k]; sum += comp * comp; } if ( sum <= 1 ) @@ -312,24 +310,23 @@ double Integrate3DEvents::stdDev( std::vector<V3D> const & events, { double sum = 0; double sum_sq = 0; + double stdev = 0; int count = 0; - double dot_prod; for ( size_t i = 0; i < events.size(); i++ ) { if ( events[i].norm() <= radius ) { - dot_prod = events[i].scalar_prod( direction ); + double dot_prod = events[i].scalar_prod( direction ); sum += dot_prod; sum_sq += dot_prod * dot_prod; count++; } } - double ave = 0; - double stdev = 0; + if ( count > 1 ) { - ave = sum / count; + double ave = sum / count; stdev = sqrt( (sum_sq/count - ave*ave) * (double)count/(count-1.0) ); } diff --git a/Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp b/Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp index c1b296957cf..c90a3604c9d 100644 --- a/Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp +++ b/Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp @@ -424,21 +424,17 @@ namespace MDEvents CPUTimer tim; UNUSED_ARG(start); UNUSED_ARG(num); + // Boxes to show std::vector<API::IMDNode *> boxes; std::vector<MDBoxBase<MDE,nd>* > boxes_filtered; this->getBox()->getBoxes(boxes, 1000, false); - - bool withPointsOnly = true; boxes_filtered.reserve(boxes.size()); for (size_t i=0; i<boxes.size(); i++) { MDBoxBase<MDE,nd>* box = dynamic_cast<MDBoxBase<MDE,nd>* >(boxes[i]); - if (box->getNPoints() > 0 && withPointsOnly) - boxes_filtered.push_back(box); - else - boxes_filtered.push_back(box); + boxes_filtered.push_back(box); } diff --git a/Code/Mantid/Framework/Nexus/src/NexusFileIO.cpp b/Code/Mantid/Framework/Nexus/src/NexusFileIO.cpp index 1dc898263fd..9b67a20e615 100644 --- a/Code/Mantid/Framework/Nexus/src/NexusFileIO.cpp +++ b/Code/Mantid/Framework/Nexus/src/NexusFileIO.cpp @@ -727,8 +727,6 @@ using namespace DataObjects; * */ int NexusFileIO::writeEventList( const DataObjects::EventList & el, std::string group_name) const { - int dims_array[1]; - //write data entry NXstatus status=NXmakegroup(fileID, group_name.c_str(), "NXdata"); if(status==NX_ERROR) return(2); @@ -741,6 +739,7 @@ using namespace DataObjects; if (!dets.empty()) { std::vector<detid_t> detectorIDs(dets.begin(),dets.end()); + int dims_array[1]; NXwritedata("detector_IDs", NX_INT64, 1, dims_array, (void*)(detectorIDs.data()), false ); } diff --git a/Code/Mantid/Framework/SINQ/src/InvertMDDim.cpp b/Code/Mantid/Framework/SINQ/src/InvertMDDim.cpp index d379a3b353b..b978b140111 100644 --- a/Code/Mantid/Framework/SINQ/src/InvertMDDim.cpp +++ b/Code/Mantid/Framework/SINQ/src/InvertMDDim.cpp @@ -69,11 +69,10 @@ void InvertMDDim::recurseDim(IMDHistoWorkspace_sptr inWS, IMDHistoWorkspace_sptr { boost::shared_ptr<const IMDDimension> dimi = inWS->getDimension(currentDim); if(currentDim == rank - 1) { - unsigned int inIDX, outIDX; for(int i = 0; i < static_cast<int>(dimi->getNBins()); i++){ idx[currentDim] = i; - inIDX = calcIndex(inWS,idx); - outIDX = calcInvertedIndex(outWS,idx); + unsigned int inIDX = calcIndex(inWS,idx); + unsigned int outIDX = calcInvertedIndex(outWS,idx); outWS->setSignalAt(outIDX,inWS->signalAt(inIDX)); outWS->setErrorSquaredAt(outIDX,inWS->errorSquaredAt(inIDX)); } diff --git a/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp b/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp index bbe1669d2c9..7c5ce05a41a 100644 --- a/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp +++ b/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp @@ -62,40 +62,40 @@ using namespace::NeXus; void LoadFlexiNexus::init() { - std::vector<std::string> exts; - exts.push_back(".hdf"); - exts.push_back(".h5"); - exts.push_back(""); - - - declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts), - "A NeXus file"); - std::vector<std::string> exts2; - exts2.push_back(".txt"); - exts2.push_back(".dic"); - exts2.push_back(""); - declareProperty(new FileProperty("Dictionary", "", FileProperty::Load, exts2), - "A Dictionary for controlling NeXus loading"); - declareProperty(new WorkspaceProperty<Workspace>("OutputWorkspace","",Direction::Output)); + std::vector<std::string> exts; + exts.push_back(".hdf"); + exts.push_back(".h5"); + exts.push_back(""); + + + declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts), + "A NeXus file"); + std::vector<std::string> exts2; + exts2.push_back(".txt"); + exts2.push_back(".dic"); + exts2.push_back(""); + declareProperty(new FileProperty("Dictionary", "", FileProperty::Load, exts2), + "A Dictionary for controlling NeXus loading"); + declareProperty(new WorkspaceProperty<Workspace>("OutputWorkspace","",Direction::Output)); } void LoadFlexiNexus::exec() { - + std::string filename = getProperty("Filename"); std::string dictname = getProperty("Dictionary"); g_log.information() << "Running FlexiNexus for " << filename << " with " << dictname << std::endl; - + loadDictionary(getProperty("Dictionary")); /* print the dictionary for debugging.......... for(std::map<std::string, std::string>::const_iterator it = dictionary.begin(); - it!= dictionary.end(); it++){ - std::cout << it->first << "\t" << it->second << std::endl; + it!= dictionary.end(); it++){ + std::cout << it->first << "\t" << it->second << std::endl; } */ - + File fin(filename); readData(&fin); @@ -107,13 +107,13 @@ void LoadFlexiNexus::loadDictionary(std::string dictFile) std::string line, key, value; while(std::getline(in,line)){ - // skip comments + // skip comments if(line[0] == '#'){ continue; } // skip empty lines if(line.length() < 2){ - continue; + continue; } std::istringstream l(line); std::getline(l,key,'='); @@ -128,185 +128,167 @@ void LoadFlexiNexus::loadDictionary(std::string dictFile) void LoadFlexiNexus::readData(NeXus::File *fin) { - Mantid::DataObjects::Workspace2D_sptr ws; - std::map<std::string,std::string>::const_iterator it; - - if((it = dictionary.find("data")) == dictionary.end()){ - throw std::runtime_error("Required dictionary element data not found"); - } - - // inspect the data element and create WS matching dims - if(!safeOpenpath(fin, it->second)){ - throw std::runtime_error("data NeXus path not found!"); - } - - Info inf = fin->getInfo(); - size_t rank = inf.dims.size(); - boost::shared_array<int> data; - - if(rank <= 2){ - load2DWorkspace(fin); - } else { - loadMD(fin); - } + Mantid::DataObjects::Workspace2D_sptr ws; + std::map<std::string,std::string>::const_iterator it; + + if((it = dictionary.find("data")) == dictionary.end()){ + throw std::runtime_error("Required dictionary element data not found"); + } + + // inspect the data element and create WS matching dims + if(!safeOpenpath(fin, it->second)){ + throw std::runtime_error("data NeXus path not found!"); + } + + Info inf = fin->getInfo(); + size_t rank = inf.dims.size(); + boost::shared_array<int> data; + + if(rank <= 2){ + load2DWorkspace(fin); + } else { + loadMD(fin); + } } void LoadFlexiNexus::load2DWorkspace(NeXus::File *fin) { - Mantid::DataObjects::Workspace2D_sptr ws; - int nSpectra, spectraLength; - std::vector<int> data; - - // read the data first - fin->getDataCoerce(data); - - Info inf = fin->getInfo(); - if(inf.dims.size() == 1){ - nSpectra = 1; - spectraLength = static_cast<int>(inf.dims[0]); - } else { - nSpectra = static_cast<int>(inf.dims[0]); - spectraLength = static_cast<int>(inf.dims[1]); - } - - // need to locate x-axis data too..... - std::map<std::string,std::string>::const_iterator it; - std::vector<double> xData; - if((it = dictionary.find("x-axis")) == dictionary.end()){ - xData.reserve(spectraLength); - for(int i = 0; i < spectraLength; i++){ - xData[i] = (double)i; - } - } else { - if(safeOpenpath(fin,it->second)){ - fin->getDataCoerce(xData); - } - } - - // need to locate y-axis data too..... - std::vector<double> yData; - if((it = dictionary.find("y-axis")) == dictionary.end()){ - yData.resize(nSpectra); - for(int i = 0; i < nSpectra; i++){ - yData[i] = (double)i; - } - } else { - if(safeOpenpath(fin,it->second)){ - fin->getDataCoerce(yData); - } - } - - // fill the data....... - ws = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D> - (WorkspaceFactory::Instance().create("Workspace2D",nSpectra,spectraLength,spectraLength)); - for(int i = 0; i < nSpectra; i++){ - Mantid::MantidVec& Y = ws->dataY(i); - for(int j = 0; j < spectraLength; j++){ - Y[j] = data[spectraLength*i+j]; - } - // Create and fill another vector for the errors, containing sqrt(count) - Mantid::MantidVec& E = ws->dataE(i); - std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt); - ws->setX(i, xData); -//Xtof ws->getAxis(1)->spectraNo(i)= i; - ws->getAxis(1)->setValue(i,yData[i]); - } - ws->setYUnit("Counts"); - - - // assign an x-axis-name - if((it = dictionary.find("x-axis-name")) == dictionary.end()){ - const std::string xname("no axis name found"); - ws->getAxis(0)->title() = xname; - } else { - const std::string xname(it->second); - ws->getAxis(0)->title() = xname; - } - - addMetaData(fin,ws, (ExperimentInfo_sptr) ws); - - // assign the workspace - setProperty("OutputWorkspace",boost::dynamic_pointer_cast<Workspace>(ws)); + Mantid::DataObjects::Workspace2D_sptr ws; + int nSpectra, spectraLength; + std::vector<int> data; + + // read the data first + fin->getDataCoerce(data); + + Info inf = fin->getInfo(); + if(inf.dims.size() == 1){ + nSpectra = 1; + spectraLength = static_cast<int>(inf.dims[0]); + } else { + nSpectra = static_cast<int>(inf.dims[0]); + spectraLength = static_cast<int>(inf.dims[1]); + } + + // need to locate x-axis data too..... + std::map<std::string,std::string>::const_iterator it; + std::vector<double> xData; + if((it = dictionary.find("x-axis")) == dictionary.end()){ + xData.reserve(spectraLength); + for(int i = 0; i < spectraLength; i++){ + xData[i] = (double)i; + } + } else { + if(safeOpenpath(fin,it->second)){ + fin->getDataCoerce(xData); + } + } + + // need to locate y-axis data too..... + std::vector<double> yData; + if((it = dictionary.find("y-axis")) == dictionary.end()){ + yData.resize(nSpectra); + for(int i = 0; i < nSpectra; i++){ + yData[i] = (double)i; + } + } else { + if(safeOpenpath(fin,it->second)){ + fin->getDataCoerce(yData); + } + } + + // fill the data....... + ws = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D> + (WorkspaceFactory::Instance().create("Workspace2D",nSpectra,spectraLength,spectraLength)); + for(int i = 0; i < nSpectra; i++){ + Mantid::MantidVec& Y = ws->dataY(i); + for(int j = 0; j < spectraLength; j++){ + Y[j] = data[spectraLength*i+j]; + } + // Create and fill another vector for the errors, containing sqrt(count) + Mantid::MantidVec& E = ws->dataE(i); + std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt); + ws->setX(i, xData); + //Xtof ws->getAxis(1)->spectraNo(i)= i; + ws->getAxis(1)->setValue(i,yData[i]); + } + ws->setYUnit("Counts"); + + + // assign an x-axis-name + if((it = dictionary.find("x-axis-name")) == dictionary.end()){ + const std::string xname("no axis name found"); + ws->getAxis(0)->title() = xname; + } else { + const std::string xname(it->second); + ws->getAxis(0)->title() = xname; + } + + addMetaData(fin,ws, (ExperimentInfo_sptr) ws); + + // assign the workspace + setProperty("OutputWorkspace",boost::dynamic_pointer_cast<Workspace>(ws)); } - + void LoadFlexiNexus::loadMD(NeXus::File *fin) { - std::vector<double> data; - std::map<std::string,std::string>::const_iterator it; - - // read the data first - fin->getDataCoerce(data); - - Info inf = fin->getInfo(); -/* - std::vector<MDHistoDimension_sptr> dimensions; - for(int k = 0; k < inf.dims.size(); ++k) - { - dimensions.push_back(makeDimension(fin,k,inf.dims[k])); - } -*/ - std::vector<MDHistoDimension_sptr> dimensions; - for(int k = static_cast<int>(inf.dims.size())-1; k >=0; k--) - { - dimensions.push_back(makeDimension(fin,k,static_cast<int>(inf.dims[k]))); - } + std::vector<double> data; - MDHistoWorkspace_sptr ws (new MDHistoWorkspace(dimensions)); + // read the data first + fin->getDataCoerce(data); -// indexMaker = new size_t[inf.dims.size()]; -// size_t *shitDim = new size_t[inf.dims.size()]; -// for(int i = 0; i < inf.dims.size(); i++){ -// shitDim[i] = inf.dims[i]; -// } -// Utils::NestedForLoop::SetUpIndexMaker(inf.dims.size(), indexMaker, shitDim); -// delete shitDim; + Info inf = fin->getInfo(); - signal_t *dd = ws->getSignalArray(); - signal_t *ddE= ws->getErrorSquaredArray(); + std::vector<MDHistoDimension_sptr> dimensions; + for(int k = static_cast<int>(inf.dims.size())-1; k >=0; k--) + { + dimensions.push_back(makeDimension(fin,k,static_cast<int>(inf.dims[k]))); + } - // assign tata - for(size_t i = 0; i < data.size(); i++){ - dd[i] = data[i]; - ddE[i] = dblSqrt(data[i]); - } + MDHistoWorkspace_sptr ws (new MDHistoWorkspace(dimensions)); - if(ws->getNumExperimentInfo() == 0){ - ws->addExperimentInfo((ExperimentInfo_sptr)new ExperimentInfo()); - } - addMetaData(fin,ws,ws->getExperimentInfo(0)); - // assign the workspace - setProperty("OutputWorkspace",ws); + signal_t *dd = ws->getSignalArray(); + signal_t *ddE= ws->getErrorSquaredArray(); + + // assign data + for(size_t i = 0; i < data.size(); i++){ + dd[i] = data[i]; + ddE[i] = dblSqrt(data[i]); + } + + if(ws->getNumExperimentInfo() == 0){ + ws->addExperimentInfo((ExperimentInfo_sptr)new ExperimentInfo()); + } + addMetaData(fin,ws,ws->getExperimentInfo(0)); + + // assign the workspace + setProperty("OutputWorkspace",ws); - //delete indexMaker; } int LoadFlexiNexus::calculateCAddress(int *pos, int* dim, int rank) { - int result, mult; - int i, j; - - result = (int)pos[rank - 1]; - for(i = 0; i < rank -1; i++){ - mult = 1; - for(j = rank -1; j > i; j--){ - mult *= dim[j]; - } - if((int)pos[i] < dim[i] && (int)pos[i] > 0){ - result += mult*(int)pos[i]; - } - } - return result; + int result = (int)pos[rank - 1]; + for(int i = 0; i < rank -1; i++){ + int mult = 1; + for(int j = rank -1; j > i; j--){ + mult *= dim[j]; + } + if((int)pos[i] < dim[i] && (int)pos[i] > 0){ + result += mult*(int)pos[i]; + } + } + return result; } int LoadFlexiNexus::calculateF77Address(int *, int) { - // --- Unused code --- - // int result = 0; + // --- Unused code --- + // int result = 0; - // for(int i = 0; i < rank; i++){ - // result += pos[i]*indexMaker[i]; - // } - // return result; + // for(int i = 0; i < rank; i++){ + // result += pos[i]*indexMaker[i]; + // } + // return result; return 0; } @@ -317,150 +299,145 @@ double LoadFlexiNexus::dblSqrt(double in) MDHistoDimension_sptr LoadFlexiNexus::makeDimension(NeXus::File *fin, int index, int length) { - static char *axisNames[] = {"x","y","z"}; - std::map<std::string,std::string>::const_iterator it; - - // get a name - std::string name(axisNames[index]); - name += "axis-name"; - if((it = dictionary.find(name)) != dictionary.end() ){ - name = it->second; - } else { - name = axisNames[index]; - } - - // get axis data - std::string dataName(axisNames[index]); - dataName += "-axis"; - std::vector<double> dData; - if((it = dictionary.find(dataName)) == dictionary.end()){ - for(int i = 0; i < length; i++){ - dData.reserve(length); - dData[i] = (double)i; - } - } else { - if(safeOpenpath(fin,it->second)){ - fin->getDataCoerce(dData); - } else { - for(int i = 0; i < length; i++){ - dData.reserve(length); - dData[i] = (double)i; - } - } - } - coord_t min, max, tmp; - min = static_cast<coord_t>(dData[0]); - max = static_cast<coord_t>(dData[length-1]); - if(min > max){ - tmp = max; - max = min; - min = tmp; - g_log.notice("WARNING: swapped axis values on " + name); - } - return MDHistoDimension_sptr(new MDHistoDimension(name, name, "", min, max, length)); + static char *axisNames[] = {"x","y","z"}; + std::map<std::string,std::string>::const_iterator it; + + // get a name + std::string name(axisNames[index]); + name += "axis-name"; + if((it = dictionary.find(name)) != dictionary.end() ){ + name = it->second; + } else { + name = axisNames[index]; + } + + // get axis data + std::string dataName(axisNames[index]); + dataName += "-axis"; + std::vector<double> dData; + if((it = dictionary.find(dataName)) == dictionary.end()){ + for(int i = 0; i < length; i++){ + dData.reserve(length); + dData[i] = (double)i; + } + } else { + if(safeOpenpath(fin,it->second)){ + fin->getDataCoerce(dData); + } else { + for(int i = 0; i < length; i++){ + dData.reserve(length); + dData[i] = (double)i; + } + } + } + coord_t min, max, tmp; + min = static_cast<coord_t>(dData[0]); + max = static_cast<coord_t>(dData[length-1]); + if(min > max){ + tmp = max; + max = min; + min = tmp; + g_log.notice("WARNING: swapped axis values on " + name); + } + return MDHistoDimension_sptr(new MDHistoDimension(name, name, "", min, max, length)); +} +void LoadFlexiNexus::addMetaData(NeXus::File *fin, Workspace_sptr ws, ExperimentInfo_sptr info) +{ + std::map<std::string,std::string>::const_iterator it; + + // assign a title + if((it = dictionary.find("title")) == dictionary.end()){ + const std::string title("No title found"); + ws->setTitle(title); + } else { + if(it->second.find('/') == it->second.npos){ + const std::string title(it->second); + ws->setTitle(title); + } else { + if(safeOpenpath(fin,it->second)){ + const std::string title = fin->getStrData(); + ws->setTitle(title); + } + } + } + + // assign a sample name + std::string sample; + if((it = dictionary.find("sample")) == dictionary.end()){ + sample = "No sample found"; + } else { + if(it->second.find('/') == it->second.npos){ + sample = it->second; + } else { + if(safeOpenpath(fin,it->second)) { + sample = fin->getStrData(); + } else { + sample = "Sampe plath not found"; + } + } + } + info->mutableSample().setName(sample); + + /** + * load all the extras into the Run information + */ + Run& r = info->mutableRun(); + std::set<std::string> specialMap = populateSpecialMap(); + for(it = dictionary.begin(); it != dictionary.end(); ++it){ + if(specialMap.find(it->first) == specialMap.end()){ + // not in specials! + if(it->second.find('/') == it->second.npos){ + r.addProperty(it->first, it->second, true); + } else { + if(safeOpenpath(fin, it->second)){ + NeXus::Info inf = fin->getInfo(); + if(inf.type == ::NeXus::CHAR){ + std::string data = fin->getStrData(); + r.addProperty(it->first,data, true); + } else if(inf.type == ::NeXus::FLOAT32 || inf.type == ::NeXus::FLOAT64){ + std::vector<double> data; + fin->getDataCoerce(data); + r.addProperty(it->first,data, true); + } else { + std::vector<int> data; + fin->getDataCoerce(data); + r.addProperty(it->first,data, true); + } + } + } + } + } + + } - void LoadFlexiNexus::addMetaData(NeXus::File *fin, Workspace_sptr ws, ExperimentInfo_sptr info) - { - std::map<std::string,std::string>::const_iterator it; - - // assign a title - if((it = dictionary.find("title")) == dictionary.end()){ - const std::string title("No title found"); - ws->setTitle(title); - } else { - if(it->second.find('/') == it->second.npos){ - const std::string title(it->second); - ws->setTitle(title); - } else { - if(safeOpenpath(fin,it->second)){ - const std::string title = fin->getStrData(); - ws->setTitle(title); - } - } - } - - // assign a sample name - std::string sample; - if((it = dictionary.find("sample")) == dictionary.end()){ - sample = "No sample found"; - } else { - if(it->second.find('/') == it->second.npos){ - sample = it->second; - } else { - if(safeOpenpath(fin,it->second)) { - sample = fin->getStrData(); - } else { - sample = "Sampe plath not found"; - } - } - } - info->mutableSample().setName(sample); - - /** - * load all the extras into the Run information - */ - Run& r = info->mutableRun(); - std::set<std::string> specialMap = populateSpecialMap(); - for(it = dictionary.begin(); it != dictionary.end(); ++it){ - if(specialMap.find(it->first) == specialMap.end()){ - // not in specials! - if(it->second.find('/') == it->second.npos){ - r.addProperty(it->first, it->second, true); - } else { - if(safeOpenpath(fin, it->second)){ - NeXus::Info inf = fin->getInfo(); - if(inf.type == ::NeXus::CHAR){ - std::string data = fin->getStrData(); - r.addProperty(it->first,data, true); - } else if(inf.type == ::NeXus::FLOAT32 || inf.type == ::NeXus::FLOAT64){ - std::vector<double> data; - fin->getDataCoerce(data); - r.addProperty(it->first,data, true); - } else { - std::vector<int> data; - fin->getDataCoerce(data); - r.addProperty(it->first,data, true); - } - } - } - } - } - - // const std::vector<Kernel::Property *> props = r.getProperties(); - // for(int i = 0; i < props.size(); i++){ - // Property *prop = props[i]; - // getLogger().error("Found property: " + prop->name() + " with value: " + prop->value()); - // } - - } std::set<std::string> LoadFlexiNexus::populateSpecialMap() { - std::set<std::string> specialMap; - - specialMap.insert("title"); - specialMap.insert("data"); - specialMap.insert("sample"); - specialMap.insert("x-axis"); - specialMap.insert("x-axis-name"); - specialMap.insert("y-axis"); - specialMap.insert("y-axis-name"); - specialMap.insert("z-axis"); - specialMap.insert("z-axis-name"); - - return specialMap; + std::set<std::string> specialMap; + + specialMap.insert("title"); + specialMap.insert("data"); + specialMap.insert("sample"); + specialMap.insert("x-axis"); + specialMap.insert("x-axis-name"); + specialMap.insert("y-axis"); + specialMap.insert("y-axis-name"); + specialMap.insert("z-axis"); + specialMap.insert("z-axis-name"); + + return specialMap; } int LoadFlexiNexus::safeOpenpath(NeXus::File *fin, std::string path) { - try { - fin->openPath(path); - } catch(NeXus::Exception &){ - getLogger().error("NeXus path " + path + " kaputt"); - return 0; - } - return 1; + try { + fin->openPath(path); + } catch(NeXus::Exception &){ + getLogger().error("NeXus path " + path + " kaputt"); + return 0; + } + return 1; } void LoadFlexiNexus::initDocs() { - this->setWikiSummary("Loads a NeXus file directed by a dictionary file"); + this->setWikiSummary("Loads a NeXus file directed by a dictionary file"); } diff --git a/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp b/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp index ac95cd9a0eb..f025343fbde 100644 --- a/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp +++ b/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp @@ -441,11 +441,10 @@ void PoldiAutoCorrelation5::exec() int iicmin = static_cast<int>(int(cmin)%nb_time_elmt); // modulo for the equivalent int int iicmax = static_cast<int>(int(cmax)%nb_time_elmt); - double I(0.0), delta_q(0.0); if(iicmax>iicmin){ for(int k = iicmin; k<iicmax; k++){ - delta_q = min(k+1,icmax) - max(k,icmin); // range hight limit - range low limit - I = nhe3(static_cast<int>(wire),k); + double delta_q = min(k+1,icmax) - max(k,icmin); // range hight limit - range low limit + double I = nhe3(static_cast<int>(wire),k); cmess[slit] += I*delta_q/float(max(1.,I)); csigm[slit] += delta_q/float(max(1.,I)); } @@ -527,10 +526,8 @@ void PoldiAutoCorrelation5::exec() } g_log.debug() << "_Poldi - dint " << dint[5] << " " << dint [100] << std::endl; - vector<double> qi; qi.resize(n_d_space); vector<double> qj; qj.resize(n_d_space); for(size_t i=0; i<n_d_space; i++){ - qi[i] = 2.*M_PI/(dspace1+float(i)*dspace2); qj[n_d_space-1-i] = 2.*M_PI/(dspace1+float(i)*dspace2); } diff --git a/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp b/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp index 3c8e0fbb908..e6981ce0b09 100644 --- a/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp +++ b/Code/Mantid/Framework/SINQ/src/ProjectMD.cpp @@ -172,8 +172,7 @@ void ProjectMD::putValue(IMDHistoWorkspace_sptr ws, int dim[], double value) void ProjectMD::sumData(IMDHistoWorkspace_sptr inWS, IMDHistoWorkspace_sptr outWS, int *sourceDim, int *targetDim, int targetDimCount, int dimNo, int start, int end, int currentDim) { - int i, length; - double val, sumVal = 0; + double sumVal = 0; boost::shared_ptr<const IMDDimension> dimi; /* @@ -181,11 +180,11 @@ void ProjectMD::sumData(IMDHistoWorkspace_sptr inWS, IMDHistoWorkspace_sptr outW we actually do the sums... */ if (currentDim == static_cast<int>(inWS->getNumDims())) { - length = end - start; + int length = end - start; sumVal = getValue(outWS, targetDim); - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { sourceDim[dimNo] = start + i; - val = getValue(inWS, sourceDim); + double val = getValue(inWS, sourceDim); sumVal += val; } putValue(outWS, targetDim, sumVal); @@ -203,8 +202,7 @@ void ProjectMD::sumData(IMDHistoWorkspace_sptr inWS, IMDHistoWorkspace_sptr outW loop over all values of the non summed dimension */ dimi = inWS->getDimension(currentDim); - //std::cout << " dim " << currentDim << " val " << dimi->getNBins() << std::endl; - for (i = 0; i < static_cast<int>(dimi->getNBins()); i++) { + for (int i = 0; i < static_cast<int>(dimi->getNBins()); i++) { /* the problem here is that we have to jump over the summed dimension here. This why we have to maintain a separate diff --git a/Code/Mantid/Framework/SINQ/src/SINQHMListener.cpp b/Code/Mantid/Framework/SINQ/src/SINQHMListener.cpp index 9e09f107682..0dac9e1c7df 100644 --- a/Code/Mantid/Framework/SINQ/src/SINQHMListener.cpp +++ b/Code/Mantid/Framework/SINQ/src/SINQHMListener.cpp @@ -141,7 +141,6 @@ void SINQHMListener::loadDimensions() std::istream& istr = httpRequest("/sinqhm.xml"); std::stringstream oss; Poco::StreamCopier::copyStream(istr,oss); - //std::cout << oss.str() << std::endl; DOMParser xmlParser; Document *doc; @@ -168,25 +167,14 @@ void SINQHMListener::loadDimensions() dim[i] = atoi(sdim.c_str()); } -// std::cout << "Dims after parsing sinqhm.xml: rank = " << rank << " dims ="; -// for(int i = 0; i < rank; i++){ -// std::cout << dim[i] << ", "; -// } -// std::cout << std::endl; doSpecialDim(); -// std::cout << "Dims after doSpecialDim: rank = " << rank << " dims ="; -// for(int i = 0; i < rank; i++){ -// std::cout << dim[i] << ", "; -// } -// std::cout << std::endl; - -} + } std::istream& SINQHMListener::httpRequest(std::string path) { - std::cout << path << std::endl; + HTTPRequest req(HTTPRequest::HTTP_GET,path, HTTPMessage::HTTP_1_1); req.setKeepAlive(true); @@ -215,13 +203,10 @@ void SINQHMListener::doSpecialDim() } int SINQHMListener::calculateCAddress(coord_t *pos) { - int result, mult; - int i, j; - - result = (int)pos[rank - 1]; - for(i = 0; i < rank -1; i++){ - mult = 1; - for(j = rank -1; j > i; j--){ + int result = (int)pos[rank - 1]; + for(int i = 0; i < rank -1; i++){ + int mult = 1; + for(int j = rank -1; j > i; j--){ mult *= dim[j]; } if((int)pos[i] < dim[i] && (int)pos[i] > 0){ @@ -260,8 +245,6 @@ void SINQHMListener::readHMData(IMDHistoWorkspace_sptr ws) pathBuffer << "/admin/readhmdata.egi?bank=0&start=0&end=" << length; std::istream& istr = httpRequest(pathBuffer.str()); - //std::cout << "Content-length " << response.getContentLength() << ", Content-type: " << response.getContentType() << std::endl; - data = (int *)malloc(length*sizeof(int)); if(data == NULL){ throw std::runtime_error("Out of memory reading HM data"); @@ -272,10 +255,8 @@ void SINQHMListener::readHMData(IMDHistoWorkspace_sptr ws) } for(int i = 0; i < length ; i++){ data[i] = ntohl(data[i]); - dataSum += data[i]; } - //std::cout << "DataSum = " << dataSum << std::endl; - + /** * recurseDim also takes care of converting from C to F77 storage order. Because * Mantid MD arrays are in F77 storage order. Only the holy cucumber knows why.... diff --git a/Code/Mantid/Framework/SINQ/src/SliceMDHisto.cpp b/Code/Mantid/Framework/SINQ/src/SliceMDHisto.cpp index ff784b8423b..53162cba23f 100644 --- a/Code/Mantid/Framework/SINQ/src/SliceMDHisto.cpp +++ b/Code/Mantid/Framework/SINQ/src/SliceMDHisto.cpp @@ -108,8 +108,6 @@ void SliceMDHisto::cutData(Mantid::API::IMDHistoWorkspace_sptr inWS, std::vector<int> start, std::vector<int> end, unsigned int dim) { int length; - signal_t val; - size_t idx; boost::shared_ptr<const IMDDimension> inDim = inWS->getDimension(dim); boost::shared_ptr<const IMDDimension> outDim = outWS->getDimension(dim); @@ -118,9 +116,9 @@ void SliceMDHisto::cutData(Mantid::API::IMDHistoWorkspace_sptr inWS, MDHistoWorkspace_sptr outWSS = boost::dynamic_pointer_cast<MDHistoWorkspace>(outWS); for(int i = 0; i < length; i++){ sourceDim[dim] = inDim->getX(start[dim]+i); - val = inWS->getSignalAtCoord(sourceDim, static_cast<Mantid::API::MDNormalization>(0)); + signal_t val = inWS->getSignalAtCoord(sourceDim, static_cast<Mantid::API::MDNormalization>(0)); targetDim[dim] = outDim->getX(i); - idx = outWSS->getLinearIndexAtCoord(targetDim); + size_t idx = outWSS->getLinearIndexAtCoord(targetDim); outWS->setSignalAt(idx,val); outWS->setErrorSquaredAt(idx,val); } diff --git a/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp b/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp index 895082c0734..f3c8a1d6f5c 100644 --- a/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp +++ b/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp @@ -937,8 +937,7 @@ namespace API // analyze the answer from the server, to see if the file was removed or not. std::string info; - std::string detail; - std::string published_date; + std::string detail; ptree pt; try{ read_json(answer, pt); diff --git a/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp b/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp index 0639a060a5a..1adea60151e 100644 --- a/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp +++ b/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp @@ -527,9 +527,9 @@ namespace WorkspaceCreationHelper retVal->initialize(numPixels,1,1); //Make fake events - size_t workspaceIndex = 0; if (eventPattern) // 0 == no events { + size_t workspaceIndex = 0; for (int pix= start_at_pixelID+0; pix < start_at_pixelID+numPixels; pix++) { EventList & el = retVal->getEventList(workspaceIndex); diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp b/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp index 5cb93e86ca6..c2e62ffb74e 100644 --- a/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp +++ b/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp @@ -537,11 +537,10 @@ namespace WorkflowAlgorithms if (ews) { size_t numhighevents = ews->getNumberEvents(); - size_t numlowevents = 0; if (m_processLowResTOF) { EventWorkspace_sptr lowes = boost::dynamic_pointer_cast<EventWorkspace>(m_lowResW); - numlowevents = lowes->getNumberEvents(); + size_t numlowevents = lowes->getNumberEvents(); g_log.information() << "Number of high TOF events = " << numhighevents << "; " << "Number of low TOF events = " << numlowevents << ".\n"; } diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp index 8fa151c3cd4..5a95a7ac711 100644 --- a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp +++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp @@ -2933,7 +2933,7 @@ void ApplicationWindow::setPreferences(Graph* g) g->enableAxis(i, show); if (show) { - ScaleDraw *sd = (ScaleDraw *)g->plotWidget()->axisScaleDraw (i); + ScaleDraw *sd = static_cast<ScaleDraw *>(g->plotWidget()->axisScaleDraw (i)); sd->enableComponent(QwtAbstractScaleDraw::Labels, d_show_axes_labels[i]); sd->setSpacing(d_graph_tick_labels_dist); if (i == QwtPlot::yRight && !d_show_axes_labels[i]) @@ -11626,8 +11626,8 @@ Graph* ApplicationWindow::openGraph(ApplicationWindow* app, MultiLayer *plot, int plotType = curve[3].toInt(); Table *w = app->table(curve[2]); - PlotCurve *c = NULL; if (w){ + PlotCurve *c = NULL; if(plotType == Graph::VectXYXY || plotType == Graph::VectXYAM){ QStringList colsList; colsList<<curve[2]; colsList<<curve[20]; colsList<<curve[21]; diff --git a/Code/Mantid/MantidPlot/src/Fit.cpp b/Code/Mantid/MantidPlot/src/Fit.cpp index 64c3b9970b5..1319d10708d 100644 --- a/Code/Mantid/MantidPlot/src/Fit.cpp +++ b/Code/Mantid/MantidPlot/src/Fit.cpp @@ -155,7 +155,7 @@ gsl_multimin_fminimizer * Fit::fitSimplex(gsl_multimin_function f, int &iteratio gsl_multimin_fminimizer *s_min = gsl_multimin_fminimizer_alloc (T, f.n); status = gsl_multimin_fminimizer_set (s_min, &f, d_param_init, ss); - double size; + size_t iter = 0; bool inRange = true; for (int i=0; i<d_p; i++){ @@ -187,7 +187,7 @@ gsl_multimin_fminimizer * Fit::fitSimplex(gsl_multimin_function f, int &iteratio for (int i=0; i<d_p; i++) d_results[i] = gsl_vector_get(s_min->x, i); - size = gsl_multimin_fminimizer_size (s_min); + double size = gsl_multimin_fminimizer_size (s_min); status = gsl_multimin_test_size (size, d_tolerance); } while (inRange && status == GSL_CONTINUE && (int)iter < d_max_iterations); diff --git a/Code/Mantid/MantidPlot/src/FunctionCurve.cpp b/Code/Mantid/MantidPlot/src/FunctionCurve.cpp index de084e385d1..f38d9648ff5 100644 --- a/Code/Mantid/MantidPlot/src/FunctionCurve.cpp +++ b/Code/Mantid/MantidPlot/src/FunctionCurve.cpp @@ -247,6 +247,7 @@ void FunctionCurve::loadData(int points) for (int i = 0; i<points; i++ ){ X[i]=xparser.Eval(); Y[i]=yparser.Eval(); + //cppcheck-suppress unreadVariable par+=step; } } catch(mu::ParserError &) { diff --git a/Code/Mantid/MantidPlot/src/FunctionDialog.cpp b/Code/Mantid/MantidPlot/src/FunctionDialog.cpp index b30c9559882..0c03563e20c 100644 --- a/Code/Mantid/MantidPlot/src/FunctionDialog.cpp +++ b/Code/Mantid/MantidPlot/src/FunctionDialog.cpp @@ -308,7 +308,7 @@ void FunctionDialog::acceptFunction() parser.DefineVar("x", &x); parser.SetExpr(formula.ascii()); parser.Eval(); - + // cppcheck-suppress unreadVariable x=end; parser.Eval(); } @@ -389,7 +389,7 @@ void FunctionDialog::acceptParametric() parser.DefineVar((boxParameter->text()).ascii(), ¶meter); parser.SetExpr(xformula.ascii()); parser.Eval(); - + // cppcheck-suppress unreadVariable parameter=end; parser.Eval(); } @@ -406,7 +406,7 @@ void FunctionDialog::acceptParametric() parser.DefineVar((boxParameter->text()).ascii(), ¶meter); parser.SetExpr(yformula.ascii()); parser.Eval(); - + // cppcheck-suppress unreadVariable parameter=end; parser.Eval(); } @@ -487,7 +487,7 @@ void FunctionDialog::acceptPolar() parser.DefineVar((boxPolarParameter->text()).ascii(), ¶meter); parser.SetExpr(rformula.ascii()); parser.Eval(); - + // cppcheck-suppress unreadVariable parameter=end; parser.Eval(); } @@ -504,7 +504,7 @@ void FunctionDialog::acceptPolar() parser.DefineVar((boxPolarParameter->text()).ascii(), ¶meter); parser.SetExpr(tformula.ascii()); parser.Eval(); - + // cppcheck-suppress unreadVariable parameter=end; parser.Eval(); } diff --git a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp index 8cbcbffc34f..472f9c5d5f2 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp @@ -514,8 +514,6 @@ void AlgHistoryProperties::displayAlgHistoryProperties() { QStringList propList; std::string sProperty; - bool bisDefault; - int nDirection=0; for ( std::vector<Mantid::Kernel::PropertyHistory>::const_iterator pIter = m_Histprop.begin(); pIter != m_Histprop.end(); ++pIter ) { @@ -524,11 +522,11 @@ void AlgHistoryProperties::displayAlgHistoryProperties() sProperty=(*pIter).value(); propList.append(sProperty.c_str()); - bisDefault=(*pIter).isDefault(); + bool bisDefault=(*pIter).isDefault(); bisDefault? (sProperty="Yes"):(sProperty="No"); propList.append(sProperty.c_str()); - nDirection=(*pIter).direction(); + int nDirection=(*pIter).direction(); switch(nDirection) { case 0:{sProperty="Input";break;} diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.cpp index bcb02151a44..c5a7b27f0c4 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.cpp @@ -50,7 +50,7 @@ UnwrappedDetector::UnwrappedDetector(const UnwrappedDetector & other) } /** Assignment operator */ -const UnwrappedDetector & UnwrappedDetector::operator=(const UnwrappedDetector & other) +UnwrappedDetector & UnwrappedDetector::operator=(const UnwrappedDetector & other) { u = other.u; v = other.v; diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.h index 69e5050c1f9..b4318e0d05b 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/UnwrappedSurface.h @@ -45,7 +45,7 @@ public: boost::shared_ptr<const Mantid::Geometry::IDetector> det ); UnwrappedDetector(const UnwrappedDetector & other); - const UnwrappedDetector & operator=(const UnwrappedDetector & other); + UnwrappedDetector & operator=(const UnwrappedDetector & other); unsigned char color[3]; ///< red, green, blue colour components (0 - 255) double u; ///< horizontal "unwrapped" coordinate double v; ///< vertical "unwrapped" coordinate diff --git a/Code/Mantid/MantidPlot/src/NonLinearFit.cpp b/Code/Mantid/MantidPlot/src/NonLinearFit.cpp index a395ed0bda8..b7e433b36bf 100644 --- a/Code/Mantid/MantidPlot/src/NonLinearFit.cpp +++ b/Code/Mantid/MantidPlot/src/NonLinearFit.cpp @@ -66,7 +66,7 @@ void NonLinearFit::init() d_formula = QString::null; d_f = user_f; d_df = user_df; - d_fdf = user_fdf; + d_fdf = user_fdf; d_fsimplex = user_d; d_explanation = tr("Non-linear Fit"); d_fit_type = User; @@ -75,14 +75,14 @@ void NonLinearFit::init() void NonLinearFit::setFormula(const QString& s) { if (s.isEmpty()){ - QMessageBox::critical((ApplicationWindow *)parent(), tr("MantidPlot - Input function error"), + QMessageBox::critical(static_cast<ApplicationWindow *>(parent()), tr("MantidPlot - Input function error"), tr("Please enter a valid non-empty expression! Operation aborted!")); d_init_err = true; return; } if (!d_p){ - QMessageBox::critical((ApplicationWindow *)parent(), tr("MantidPlot - Fit Error"), + QMessageBox::critical(static_cast<ApplicationWindow *>(parent()), tr("MantidPlot - Fit Error"), tr("There are no parameters specified for this fit operation. Please define a list of parameters first!")); d_init_err = true; return; @@ -107,7 +107,7 @@ void NonLinearFit::setFormula(const QString& s) } catch(mu::ParserError &e) { - QMessageBox::critical((ApplicationWindow *)parent(), tr("MantidPlot - Input function error"), QString::fromStdString(e.GetMsg())); + QMessageBox::critical(static_cast<ApplicationWindow *>(parent()), tr("MantidPlot - Input function error"), QString::fromStdString(e.GetMsg())); d_init_err = true; return; } @@ -119,7 +119,7 @@ void NonLinearFit::setFormula(const QString& s) void NonLinearFit::setParametersList(const QStringList& lst) { if (lst.count() < 1){ - QMessageBox::critical((ApplicationWindow *)parent(), tr("MantidPlot - Fit Error"), + QMessageBox::critical(static_cast<ApplicationWindow *>(parent()), tr("MantidPlot - Fit Error"), tr("You must provide a list containing at least one parameter for this type of fit. Operation aborted!")); d_init_err = true; return; diff --git a/Code/Mantid/MantidPlot/src/OpenProjectDialog.cpp b/Code/Mantid/MantidPlot/src/OpenProjectDialog.cpp index f1ebb2efd78..b14b20e7bb4 100644 --- a/Code/Mantid/MantidPlot/src/OpenProjectDialog.cpp +++ b/Code/Mantid/MantidPlot/src/OpenProjectDialog.cpp @@ -90,7 +90,7 @@ void OpenProjectDialog::updateAdvancedOptions (const QString & filter) void OpenProjectDialog::closeEvent(QCloseEvent* e) { if (isExtendable()){ - ApplicationWindow *app = (ApplicationWindow *)this->parent(); + ApplicationWindow *app = static_cast<ApplicationWindow *>(this->parent()); if (app) app->d_extended_open_dialog = this->isExtended(); } diff --git a/Code/Mantid/MantidPlot/src/Plot.cpp b/Code/Mantid/MantidPlot/src/Plot.cpp index 190cd097e51..a4a66cbea95 100644 --- a/Code/Mantid/MantidPlot/src/Plot.cpp +++ b/Code/Mantid/MantidPlot/src/Plot.cpp @@ -186,8 +186,8 @@ void Plot::printCanvas(QPainter *painter, const QRect&, const QRect &canvasRect, // print texts QObjectList lst = children(); foreach(QObject *o, lst){ - if (o->inherits("LegendWidget") && !((QWidget *)o)->isHidden()) - ((LegendWidget *)o)->print(painter, map); + if (o->inherits("LegendWidget") && !(static_cast<QWidget *>(o))->isHidden()) + (static_cast<LegendWidget *>(o))->print(painter, map); } } @@ -207,7 +207,7 @@ void Plot::drawItems (QPainter *painter, const QRect &rect, if (!axisEnabled(i)) continue; - const ScaleEngine *sc_engine = (const ScaleEngine *)axisScaleEngine(i); + const ScaleEngine *sc_engine = static_cast<const ScaleEngine *>(axisScaleEngine(i)); /*const QwtScaleEngine *qwtsc_engine=axisScaleEngine(i); const ScaleEngine *sc_engine =dynamic_cast<const ScaleEngine*>(qwtsc_engine); if(sc_engine!=NULL) -- GitLab