Commit 796df28d authored by Nick Draper's avatar Nick Draper
Browse files

re #8466 cppcheck warnings

parent 13a0e217
......@@ -57,6 +57,8 @@ if ( CPPCHECK_EXECUTABLE )
Framework/Kernel/src/Math/Optimization/SLSQPMinimizer.cpp
MantidPlot/src/nrutil.cpp
MantidPlot/src/origin/OPJFile.cpp
MantidPlot/src/zlib123/minigzip.c
Framework/SINQ/src/PoldiPeakFit.cpp
)
# Header files to be ignored require different handling
......@@ -114,7 +116,7 @@ if ( CPPCHECK_EXECUTABLE )
# put the finishing bits on the final command call
set (_cppcheck_xml_args)
if (CPPCHECK_GENERATE_XML)
list( APPEND _cppcheck_xml_args --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
list( APPEND _cppcheck_xml_args --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
else (CPPCHECK_GENERATE_XML)
list( APPEND _cppcheck_xml_args ${_cppcheck_source_dirs} )
endif (CPPCHECK_GENERATE_XML)
......
// suppress memleak and exceptNew errors in the file src/file1.cpp
//memleak:src/file1.cpp
//exceptNew:src/file1.cpp
// suppress in all files - BE CAREFULL not to leave trailing spaces after the rule id. or empty lines
// This finds false positives where private member variable names reused by inheriting classes
duplInheritedMember
// For a library this is not a problem per se
unusedFunction
// cppcheck has problems handling the number of pre-processor definitions used in the DLL_EXPORTs
class_X_Y
\ No newline at end of file
......@@ -29,7 +29,7 @@ endif()
find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
if(MSVC)
set(CPPCHECK_TEMPLATE_ARG --template vs)
set(CPPCHECK_TEMPLATE_ARG --template "{file}({line}): warning : ({severity}-{id}) {message}")
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
elseif(CMAKE_COMPILER_IS_GNUCXX)
......@@ -61,7 +61,7 @@ if(CPPCHECK_EXECUTABLE)
endif()
mark_as_advanced(CPPCHECK_EXECUTABLE)
set ( CPPCHECK_ARGS --enable=all --inline-suppr CACHE STRING "Arguments for running cppcheck" )
set ( CPPCHECK_ARGS --enable=all --inline-suppr CACHE STRING "Arguments for running cppcheck" --suppressions ${CMAKE_CURRENT_SOURCE_DIR}/Build/CMake/CppCheck_Suppressions.txt )
set ( CPPCHECK_NUM_THREADS 0 CACHE STRING "Number of threads to use when running cppcheck" )
set ( CPPCHECK_GENERATE_XML OFF CACHE BOOL "Generate xml output files from cppcheck" )
......
......@@ -41,7 +41,7 @@ ParamFunction::~ParamFunction()
void ParamFunction::setParameter(size_t i, const double& value, bool explicitlySet)
{
// Cppcheck confused by the check for NaN
// cppcheck-suppress duplicateExpression
if (boost::math::isnan(value))
{
// Check for NaN or -NaN
......
......@@ -179,8 +179,6 @@ namespace Mantid
MantidVec::iterator iter;
for (iter = outputWs->dataX(0).begin(); iter != outputWs->dataX(0).end(); ++iter)
{
// cppcheck cannot see that this is used by reference by muparser
// cppcheck-suppress unreadVariable
axisValue = *iter;
double result = p.Eval();
*iter = result;
......
......@@ -228,8 +228,7 @@ MantidVec DetectorEfficiencyCorUser::calculateEfficiency(double eff0,
for (; effOut_it != effOut.end(); ++xIn_it, ++effOut_it) {
if (conditionForEnergy ) {
// cppcheck cannot see that this is used by reference by muparser
// cppcheck-suppress unreadVariable
e = std::fabs(m_Ei + *xIn_it);
e = std::fabs(m_Ei + *xIn_it);
}
else {
// cppcheck cannot see that this is used by reference by muparser
......
......@@ -106,12 +106,9 @@ namespace Crystal
// Date: use the current date/time if not found
Kernel::DateAndTime C_experimentDate;
std::string date;
tag = getWord(in, false );
if(tag.empty())
date = Kernel::DateAndTime::getCurrentTime().toISO8601String();
else if(tag == "Date:")
date = getWord(in, false );
if(tag == "Date:")
getWord(in, false );
readToEndOfLine( in, true );
confidence = 95;
}
......
......@@ -11,22 +11,22 @@ when the new peaks are not created from a range of h ,k, and l values
=== Example usage ===
from mantidsimple import *
PeaksWrkSpace=mtd["PeaksQa"]
#Can be created via PredictPeaks( then do NOT use next line)
FindUBUsingFFT(PeaksWrkSpace,3,15,.12)
IndexPeaks(PeaksWrkSpace,.12,1)
PredictFractionalPeaks(PeaksWrkSpace,"FracPeaks","-.5,0,.5","-.5,.5","0")
#NOTE: There are editing options on PeaksWorkspaces, like combining 2 PeaksWorkspaces.
from mantidsimple import *
PeaksWrkSpace=mtd["PeaksQa"]
#Can be created via PredictPeaks( then do NOT use next line)
FindUBUsingFFT(PeaksWrkSpace,3,15,.12)
IndexPeaks(PeaksWrkSpace,.12,1)
PredictFractionalPeaks(PeaksWrkSpace,"FracPeaks","-.5,0,.5","-.5,.5","0")
#NOTE: There are editing options on PeaksWorkspaces, like combining 2 PeaksWorkspaces.
*WIKI*/
*WIKI*/
/*
* PredictFractionalPeaks.cpp
*
* Created on: Dec 5, 2012
* Author: ruth
*/
* PredictFractionalPeaks.cpp
*
* Created on: Dec 5, 2012
* Author: ruth
*/
#include "MantidCrystal/PredictFractionalPeaks.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidGeometry/Instrument.h"
......@@ -65,7 +65,7 @@ namespace Mantid
}
/// Sets documentation strings for this algorithm
/// Sets documentation strings for this algorithm
void PredictFractionalPeaks::initDocs()
{
this->setWikiSummary("Creates a PeaksWorkspace with peaks occurring at specific fractional h,k,or l values");
......@@ -76,10 +76,10 @@ namespace Mantid
void PredictFractionalPeaks::init()
{
declareProperty(new WorkspaceProperty<PeaksWorkspace> ("Peaks", "", Direction::Input),
"Workspace of Peaks with orientation matrix that indexed the peaks and instrument loaded");
"Workspace of Peaks with orientation matrix that indexed the peaks and instrument loaded");
declareProperty(new WorkspaceProperty<PeaksWorkspace> ("FracPeaks", "", Direction::Output),
"Workspace of Peaks with peaks with fractional h,k, and/or l values");
"Workspace of Peaks with peaks with fractional h,k, and/or l values");
declareProperty(new Kernel::ArrayProperty<double>(string("HOffset"),string("-.5,0, .5")),"Offset in the h direction");
......@@ -100,20 +100,20 @@ namespace Mantid
setPropertySettings("Hmin",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
Kernel::IS_EQUAL_TO, "1"));
Kernel::IS_EQUAL_TO, "1"));
setPropertySettings("Hmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
Kernel::IS_EQUAL_TO, "1"));
Kernel::IS_EQUAL_TO, "1"));
setPropertySettings("Kmin",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
Kernel::IS_EQUAL_TO, "1"));
Kernel::IS_EQUAL_TO, "1"));
setPropertySettings("Kmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
Kernel::IS_EQUAL_TO, "1"));
setPropertySettings("Kmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
Kernel::IS_EQUAL_TO, "1"));
setPropertySettings("Lmin",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
Kernel::IS_EQUAL_TO, "1"));
Kernel::IS_EQUAL_TO, "1"));
setPropertySettings("Lmax",new Kernel::EnabledWhenProperty(string("IncludeAllPeaksInRange"),
Kernel::IS_EQUAL_TO, "1"));
Kernel::IS_EQUAL_TO, "1"));
}
......@@ -121,173 +121,169 @@ namespace Mantid
/// Run the algorithm
void PredictFractionalPeaks::exec()
{
PeaksWorkspace_sptr Peaks=getProperty("Peaks");
vector<double> hOffsets = getProperty("HOffset");
vector<double> kOffsets = getProperty("KOffset");
vector<double> lOffsets = getProperty("LOffset");
if ( hOffsets.empty())hOffsets.push_back(0.0);
if ( kOffsets.empty())kOffsets.push_back(0.0);
if ( lOffsets.empty())lOffsets.push_back(0.0);
;
bool includePeaksInRange= getProperty("IncludeAllPeaksInRange");
if( Peaks->getNumberPeaks()<=0)
{
g_log.error()<<"There are No peaks in the input PeaksWorkspace\n";
return;
}
API::Sample samp= Peaks->sample();
Geometry::OrientedLattice &ol = samp.getOrientedLattice();
Geometry::Instrument_const_sptr Instr = Peaks->getInstrument();
boost::shared_ptr<IPeaksWorkspace> OutPeaks=WorkspaceFactory::Instance().createPeaks();
OutPeaks->setInstrument(Instr);
V3D hkl;
int peakNum =0;
int NPeaks = Peaks->getNumberPeaks();
Kernel::Matrix<double> Gon;
Gon.identityMatrix();
double Hmin= getProperty("Hmin");
double Hmax= getProperty("Hmax");
double Kmin= getProperty("Kmin");
double Kmax= getProperty("Kmax");
double Lmin= getProperty("Lmin");
double Lmax= getProperty("Lmax");
int N=NPeaks;
if( includePeaksInRange)
{
N=(int)((Hmax-Hmin+1)*(Kmax-Kmin+1)*(Lmax-Lmin+1)+.5);
N=max<int>(100,N);
}
IPeak& peak0 =Peaks->getPeak(0);
int RunNumber = peak0.getRunNumber();
Gon=peak0.getGoniometerMatrix();
Progress prog(this, 0, 1,N);
if( includePeaksInRange)
{
hkl[0]=Hmin;
hkl[1]=Kmin;
hkl[2]=Lmin;
}else
{
hkl[0]=peak0.getH();
hkl[1]=peak0.getK();
hkl[2] =peak0.getL();
}
Kernel::DblMatrix UB= ol.getUB();
vector< vector<int> > AlreadyDonePeaks;
bool done = false;
int ErrPos =1;//Used to determine position in code of a throw
while( !done)
{
for( size_t hoffset=0;hoffset<hOffsets.size();hoffset++)
for(size_t koffset=0;koffset<kOffsets.size();koffset++)
for( size_t loffset=0;loffset<lOffsets.size();loffset++)
try
{
V3D hkl1( hkl );
ErrPos = 0;
hkl1[0] += hOffsets[hoffset] ;
hkl1[1] += kOffsets[koffset] ;
hkl1[2] += lOffsets[loffset] ;
Kernel::V3D Qs = UB * hkl1 ;
Qs*= 2.0;
Qs*=M_PI;
Qs=Gon*Qs;
if( Qs[2] <= 0 )
continue;
ErrPos=1;
boost::shared_ptr<IPeak> peak( Peaks->createPeak( Qs, 1 ));
peak->setGoniometerMatrix(Gon);
if (Qs[2]>0 && peak->findDetector())
{
// cppcheck-suppress redundantAssignment
ErrPos=2;
vector<int> SavPk;
SavPk.push_back(RunNumber);
SavPk.push_back((int)floor(1000*hkl1[0]+.5));
SavPk.push_back((int)floor(1000*hkl1[1]+.5));
SavPk.push_back((int)floor(1000*hkl1[2]+.5));
//TODO keep list sorted so searching is faster?
vector<vector<int> >::iterator it = find(AlreadyDonePeaks.begin(),AlreadyDonePeaks.end(),SavPk);
// cppcheck-suppress redundantAssignment
ErrPos=3;
if( it == AlreadyDonePeaks.end())
AlreadyDonePeaks.push_back(SavPk);
else
continue;
// cppcheck-suppress redundantAssignment
ErrPos=4;
peak->setHKL(hkl1);
peak->setRunNumber(RunNumber);
OutPeaks->addPeak(*peak);
}
}catch(...)
PeaksWorkspace_sptr Peaks=getProperty("Peaks");
vector<double> hOffsets = getProperty("HOffset");
vector<double> kOffsets = getProperty("KOffset");
vector<double> lOffsets = getProperty("LOffset");
if ( hOffsets.empty())hOffsets.push_back(0.0);
if ( kOffsets.empty())kOffsets.push_back(0.0);
if ( lOffsets.empty())lOffsets.push_back(0.0);
;
bool includePeaksInRange= getProperty("IncludeAllPeaksInRange");
if( Peaks->getNumberPeaks()<=0)
{
g_log.error()<<"There are No peaks in the input PeaksWorkspace\n";
return;
}
API::Sample samp= Peaks->sample();
Geometry::OrientedLattice &ol = samp.getOrientedLattice();
Geometry::Instrument_const_sptr Instr = Peaks->getInstrument();
boost::shared_ptr<IPeaksWorkspace> OutPeaks=WorkspaceFactory::Instance().createPeaks();
OutPeaks->setInstrument(Instr);
V3D hkl;
int peakNum =0;
int NPeaks = Peaks->getNumberPeaks();
Kernel::Matrix<double> Gon;
Gon.identityMatrix();
double Hmin= getProperty("Hmin");
double Hmax= getProperty("Hmax");
double Kmin= getProperty("Kmin");
double Kmax= getProperty("Kmax");
double Lmin= getProperty("Lmin");
double Lmax= getProperty("Lmax");
int N=NPeaks;
if( includePeaksInRange)
{
N=(int)((Hmax-Hmin+1)*(Kmax-Kmin+1)*(Lmax-Lmin+1)+.5);
N=max<int>(100,N);
}
IPeak& peak0 =Peaks->getPeak(0);
int RunNumber = peak0.getRunNumber();
Gon=peak0.getGoniometerMatrix();
Progress prog(this, 0, 1,N);
if( includePeaksInRange)
{
hkl[0]=Hmin;
hkl[1]=Kmin;
hkl[2]=Lmin;
}else
{
hkl[0]=peak0.getH();
hkl[1]=peak0.getK();
hkl[2] =peak0.getL();
}
Kernel::DblMatrix UB= ol.getUB();
vector< vector<int> > AlreadyDonePeaks;
bool done = false;
int ErrPos =1;//Used to determine position in code of a throw
while( !done)
{
for( size_t hoffset=0;hoffset<hOffsets.size();hoffset++)
for(size_t koffset=0;koffset<kOffsets.size();koffset++)
for( size_t loffset=0;loffset<lOffsets.size();loffset++)
try
{
V3D hkl1( hkl );
ErrPos = 0;
hkl1[0] += hOffsets[hoffset] ;
hkl1[1] += kOffsets[koffset] ;
hkl1[2] += lOffsets[loffset] ;
Kernel::V3D Qs = UB * hkl1 ;
Qs*= 2.0;
Qs*=M_PI;
Qs=Gon*Qs;
if( Qs[2] <= 0 )
continue;
ErrPos=1;
boost::shared_ptr<IPeak> peak( Peaks->createPeak( Qs, 1 ));
peak->setGoniometerMatrix(Gon);
if (Qs[2]>0 && peak->findDetector())
{
ErrPos=2;
vector<int> SavPk;
SavPk.push_back(RunNumber);
SavPk.push_back((int)floor(1000*hkl1[0]+.5));
SavPk.push_back((int)floor(1000*hkl1[1]+.5));
SavPk.push_back((int)floor(1000*hkl1[2]+.5));
//TODO keep list sorted so searching is faster?
vector<vector<int> >::iterator it = find(AlreadyDonePeaks.begin(),AlreadyDonePeaks.end(),SavPk);
if( it == AlreadyDonePeaks.end())
AlreadyDonePeaks.push_back(SavPk);
else
continue;
peak->setHKL(hkl1);
peak->setRunNumber(RunNumber);
OutPeaks->addPeak(*peak);
}
}catch(...)
{
if( ErrPos != 1)// setQLabFrame in createPeak throws exception
throw new std::invalid_argument( "Invalid data at this point");
}
if( includePeaksInRange)
{
hkl[0]++;
if( hkl[0]>Hmax)
{
hkl[0]=Hmin;
hkl[1]++;
if( hkl[1]> Kmax)
{
if( ErrPos != 1)// setQLabFrame in createPeak throws exception
throw new std::invalid_argument( "Invalid data at this point");
hkl[1]=Kmin;
hkl[2]++;
if( hkl[2]> Lmax)
done = true;
}
if( includePeaksInRange)
{
hkl[0]++;
if( hkl[0]>Hmax)
{
hkl[0]=Hmin;
hkl[1]++;
if( hkl[1]> Kmax)
{
hkl[1]=Kmin;
hkl[2]++;
if( hkl[2]> Lmax)
done = true;
}
}
}else
{
peakNum++;
if( peakNum >= NPeaks)
done = true;
else
{// peak0= Peaks->getPeak(peakNum);
IPeak& peak1= Peaks->getPeak(peakNum);
//??? could not assign to peak0 above. Did not work
// the peak that peak0 was associated with did NOT change
hkl[0]=peak1.getH();
hkl[1]=peak1.getK();
hkl[2] =peak1.getL();
Gon=peak1.getGoniometerMatrix();
RunNumber = peak1.getRunNumber();
}
}
prog.report();
}
setProperty("FracPeaks",OutPeaks);
}
}else
{
peakNum++;
if( peakNum >= NPeaks)
done = true;
else
{// peak0= Peaks->getPeak(peakNum);
IPeak& peak1= Peaks->getPeak(peakNum);
//??? could not assign to peak0 above. Did not work
// the peak that peak0 was associated with did NOT change
hkl[0]=peak1.getH();
hkl[1]=peak1.getK();
hkl[2] =peak1.getL();
Gon=peak1.getGoniometerMatrix();
RunNumber = peak1.getRunNumber();
}
}
prog.report();
}
setProperty("FracPeaks",OutPeaks);
......@@ -295,4 +291,4 @@ namespace Mantid
}//namespace Crystal
}//namespace Mantid
}//namespace Mantid
......@@ -275,13 +275,6 @@ namespace CurveFitting
coeff[8+i*3] = 0.0;
coeff[9+i*3] = 0.0;
}
}else if(m_nlayer < m_nlayer_old){
for (int i = 0; i < m_nlayer; ++i)
{
coeff[7+i*3] = getParameter(7+i*3);
coeff[8+i*3] = getParameter(8+i*3);
coeff[9+i*3] = getParameter(9+i*3);
}
}else {
for (int i = 0; i < m_nlayer; ++i)
{
......
......@@ -608,7 +608,6 @@ FindDetectorsPar::get_ASCII_header(std::string const &fileName, std::ifstream &d
int space_to_symbol_change=count_changes(&BUF[0],BUF.size());
if(space_to_symbol_change>1){ // more then one group of symbols in the string, spe file
int nData_records(0),nData_blocks(0);
// cppcheck-suppress invalidscanf
int nDatas = sscanf(&BUF[0]," %d %d ",&nData_records,&nData_blocks);
file_descriptor.nData_records = (size_t)nData_records;
file_descriptor.nData_blocks = (size_t)nData_blocks;
......
......@@ -255,12 +255,12 @@ bool SaveCanSAS1D::openForAppending(const std::string & filename)
*/
void SaveCanSAS1D::findEndofLastEntry()
{
static const int LAST_TAG_LEN = 11;
const int rootTagLen = static_cast<int>(std::string("</SASroot>").length());
try
{
static const int LAST_TAG_LEN = 11;
//move to the place _near_ the end of the file where the data will be appended to
m_outFile.seekg(-LAST_TAG_LEN-rootTagLen, std::ios::end);
char test_tag[LAST_TAG_LEN+1];
......
......@@ -51,7 +51,6 @@ namespace Mantid
const size_t nverts_p(P.numVertices()), nverts_q(Q.numVertices());
const V2D origin(0.0,0.0);
size_t pi(0), pim1(0), qi(0), qim1(0);
size_t count_p(0), count_q(0); // Number of vertices visited
unsigned int inflag(Unknown);
bool firstPoint(true);
......@@ -65,6 +64,8 @@ namespace Mantid
Vertex2DList intersectList;
do
{
size_t pi(0), pim1(0), qi(0), qim1(0);
// Compute a vector between the previous point in the direction of the next
pim1 = (pi + nverts_p - 1) % nverts_p;
qim1 = (qi + nverts_q - 1) % nverts_q;
......
......@@ -108,7 +108,7 @@ namespace Mantid
template<typename T> int convert(const char* A,T& out);
/// Convert a number to a string
template<typename T> std::string toString(const T value);