From 417f97b8cea5ae29c3bb06f66f5d4b331650e4e2 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Wed, 2 Mar 2016 09:30:59 +0100 Subject: [PATCH] cppheck I cleaned up some of the (innocuous) warnings --- src/analysis/Analysis.cpp | 3 ++- src/bias/MetaD.cpp | 2 +- src/bias/PBMetaD.cpp | 4 ++-- src/core/ActionWithArguments.cpp | 5 +---- src/core/MDAtoms.cpp | 6 ++---- src/core/SetupMolInfo.cpp | 2 +- src/function/FuncPathMSD.cpp | 3 +-- src/generic/DumpAtoms.cpp | 2 +- src/tools/Grid.cpp | 4 ++-- src/tools/RMSD.cpp | 3 --- 10 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/analysis/Analysis.cpp b/src/analysis/Analysis.cpp index cedef3453..272ed5f1f 100644 --- a/src/analysis/Analysis.cpp +++ b/src/analysis/Analysis.cpp @@ -222,8 +222,9 @@ argument_names(getNumberOfArguments()) } void Analysis::readDataFromFile( const std::string& filename ){ - FILE* fp=fopen(filename.c_str(),"r"); double tstep, oldtstep; + FILE* fp=fopen(filename.c_str(),"r"); if(fp!=NULL){ + double tstep, oldtstep; bool do_read=true, first=true; while (do_read) { PDB mypdb; diff --git a/src/bias/MetaD.cpp b/src/bias/MetaD.cpp index d6e06289a..b9e92fa81 100644 --- a/src/bias/MetaD.cpp +++ b/src/bias/MetaD.cpp @@ -1056,10 +1056,10 @@ double MetaD::evaluateGaussian if(cv.size()>0) pcv=&cv[0]; if(doInt_){ plumed_dbg_assert(cv.size()==1); - pcv=&(tmpcv[0]); tmpcv[0]=cv[0]; if(cv[0]<lowI_) tmpcv[0]=lowI_; if(cv[0]>uppI_) tmpcv[0]=uppI_; + pcv=&(tmpcv[0]); } if(hill.multivariate){ unsigned k=0; diff --git a/src/bias/PBMetaD.cpp b/src/bias/PBMetaD.cpp index 66ae2e20a..9606572ca 100644 --- a/src/bias/PBMetaD.cpp +++ b/src/bias/PBMetaD.cpp @@ -219,7 +219,7 @@ private: std::string fmt; public: - PBMetaD(const ActionOptions&); + explicit PBMetaD(const ActionOptions&); ~PBMetaD(); void calculate(); void update(); @@ -633,10 +633,10 @@ double PBMetaD::evaluateGaussian if(cv.size()>0) pcv=&cv[0]; if(doInt_){ plumed_assert(cv.size()==1); - pcv=&(tmpcv[0]); tmpcv[0]=cv[0]; if(cv[0]<lowI_[iarg]) tmpcv[0]=lowI_[iarg]; if(cv[0]>uppI_[iarg]) tmpcv[0]=uppI_[iarg]; + pcv=&(tmpcv[0]); } double dp = difference(0,hill.center[0],pcv[0]) / hill.sigma[0]; double dp2 = 0.5 * dp * dp; diff --git a/src/core/ActionWithArguments.cpp b/src/core/ActionWithArguments.cpp index ed99a28a2..6010bf054 100644 --- a/src/core/ActionWithArguments.cpp +++ b/src/core/ActionWithArguments.cpp @@ -55,9 +55,8 @@ void ActionWithArguments::interpretArgumentList(const std::vector<std::string>& for(unsigned i=0;i<c.size();i++){ // is a regex? then just interpret it. The signal is () std::size_t found1 = c[i].find("("); - std::size_t found2 ; if(found1!=std::string::npos){ - found2=c[i].find(")",found1+1,1); // find it again + std::size_t found2=c[i].find(")",found1+1,1); // find it again if(found2!=std::string::npos){ // start regex parsing #ifdef __PLUMED_HAS_CREGEX @@ -84,10 +83,8 @@ void ActionWithArguments::interpretArgumentList(const std::vector<std::string>& std::vector<ActionWithValue*> all=plumed.getActionSet().select<ActionWithValue*>(); if( all.empty() ) error("your input file is not telling plumed to calculate anything"); for(unsigned j=0;j<all.size();j++){ - std::string thisargument=all[j]->getLabel(); std::vector<std::string> ss=all[j]->getComponentsVector(); for(unsigned k=0;k<ss.size();++k){ - thisargument=ss[k]; unsigned ll=strlen(ss[k].c_str())+1; char*str; str=new char [ll]; diff --git a/src/core/MDAtoms.cpp b/src/core/MDAtoms.cpp index c9f564e2b..e4cff7366 100644 --- a/src/core/MDAtoms.cpp +++ b/src/core/MDAtoms.cpp @@ -144,8 +144,7 @@ void MDAtomsTyped<T>::updateVirial(const Tensor&virial)const{ template <class T> void MDAtomsTyped<T>::updateForces(const vector<int>&index,const vector<Vector>&forces){ - unsigned nt=OpenMP::getGoodNumThreads(fx,stride*index.size()); -#pragma omp parallel for num_threads(nt) +#pragma omp parallel for num_threads(OpenMP::getGoodNumThreads(fx,stride*index.size())) for(unsigned i=0;i<index.size();++i){ fx[stride*i]+=scalef*T(forces[index[i]][0]); fy[stride*i]+=scalef*T(forces[index[i]][1]); @@ -156,8 +155,7 @@ void MDAtomsTyped<T>::updateForces(const vector<int>&index,const vector<Vector>& template <class T> void MDAtomsTyped<T>::rescaleForces(const vector<int>&index,double factor){ if(virial) for(unsigned i=0;i<3;i++)for(unsigned j=0;j<3;j++) virial[3*i+j]*=T(factor); - unsigned nt=OpenMP::getGoodNumThreads(fx,stride*index.size()); -#pragma omp parallel for num_threads(nt) +#pragma omp parallel for num_threads(OpenMP::getGoodNumThreads(fx,stride*index.size())) for(unsigned i=0;i<index.size();++i){ fx[stride*i]*=T(factor); fy[stride*i]*=T(factor); diff --git a/src/core/SetupMolInfo.cpp b/src/core/SetupMolInfo.cpp index 13b33234a..af6a4d513 100644 --- a/src/core/SetupMolInfo.cpp +++ b/src/core/SetupMolInfo.cpp @@ -97,7 +97,6 @@ pdb(*new(PDB)) void SetupMolInfo::getBackbone( std::vector<std::string>& restrings, const std::string& fortype, std::vector< std::vector<AtomNumber> >& backbone ){ if( fortype!=mytype ) error("cannot calculate a variable designed for " + fortype + " molecules for molecule type " + mytype ); if( MolDataClass::numberOfAtomsPerResidueInBackbone( mytype )==0 ) error("backbone is not defined for molecule type " + mytype ); - bool useter=false; // This is used to deal with terminal groups in WHOLEMOLECULES if( read_backbone.size()!=0 ){ if( restrings.size()!=1 ) error("cannot interpret anything other than all for residues when using CHAIN keywords"); @@ -108,6 +107,7 @@ void SetupMolInfo::getBackbone( std::vector<std::string>& restrings, const std:: for(unsigned j=0;j<read_backbone[i].size();++j) backbone[i][j]=read_backbone[i][j]; } } else { + bool useter=false; // This is used to deal with terminal groups in WHOLEMOLECULES if( restrings.size()==1 ){ useter=( restrings[0].find("ter")!=std::string::npos ); if( restrings[0].find("all")!=std::string::npos ){ diff --git a/src/function/FuncPathMSD.cpp b/src/function/FuncPathMSD.cpp index ec1392aed..193fb149c 100644 --- a/src/function/FuncPathMSD.cpp +++ b/src/function/FuncPathMSD.cpp @@ -208,7 +208,6 @@ void FuncPathMSD::calculate(){ // log.printf("NOW CALCULATE! \n"); double s_path=0.; double partition=0.; - double tmp; if(neighpair.empty()){ // at first step, resize it neighpair.resize(allArguments.size()); for(unsigned i=0;i<allArguments.size();i++)neighpair[i].first=allArguments[i]; @@ -229,7 +228,7 @@ void FuncPathMSD::calculate(){ int n=0; for(pairiter it=neighpair.begin();it!=neighpair.end();++it){ double expval=(*it).second; - tmp=lambda*expval*(s_path-(indexmap[(*it).first]))/partition; + double tmp=lambda*expval*(s_path-(indexmap[(*it).first]))/partition; setDerivative(val_s_path,n,tmp); setDerivative(val_z_path,n,expval/partition); n++; diff --git a/src/generic/DumpAtoms.cpp b/src/generic/DumpAtoms.cpp index e70daee11..a7c87a184 100644 --- a/src/generic/DumpAtoms.cpp +++ b/src/generic/DumpAtoms.cpp @@ -208,9 +208,9 @@ DumpAtoms::DumpAtoms(const ActionOptions&ao): of.link(*this); of.open(file); std::string path=of.getPath(); - std::string mode=of.getMode(); log<<" Writing on file "<<path<<"\n"; #ifdef __PLUMED_HAS_XDRFILE + std::string mode=of.getMode(); if(type=="xtc"){ of.close(); xd=xdrfile_open(path.c_str(),mode.c_str()); diff --git a/src/tools/Grid.cpp b/src/tools/Grid.cpp index 1fe6d0e62..52b97fe9b 100644 --- a/src/tools/Grid.cpp +++ b/src/tools/Grid.cpp @@ -338,12 +338,12 @@ void Grid::addKernel( const KernelFunctions& kernel ){ } } - double newval; std::vector<double> der( dimension_ ); + std::vector<double> der( dimension_ ); for(unsigned i=0;i<neighbors.size();++i){ index_t ineigh=neighbors[i]; getPoint( ineigh, xx ); for(unsigned j=0;j<dimension_;++j) vv[j]->set(xx[j]); - newval = kernel.evaluate( vv, der, usederiv_ ); + double newval = kernel.evaluate( vv, der, usederiv_ ); if( usederiv_ ) addValueAndDerivatives( ineigh, newval, der ); else addValue( ineigh, newval ); } diff --git a/src/tools/RMSD.cpp b/src/tools/RMSD.cpp index 5cd3197c8..b5cad4168 100644 --- a/src/tools/RMSD.cpp +++ b/src/tools/RMSD.cpp @@ -970,7 +970,6 @@ std::vector<Vector> RMSDCoreData::getDDistanceDPositions(){ plumed_massert(!retrieve_only_rotation,"You used only_rotation=true in doCoreCalc therefore you cannot retrieve this information now"); if(!hasDistance)plumed_merror("getDPositionsDerivatives needs to calculate the distance via getDistance first !"); if(!isInitialized)plumed_merror("getDPositionsDerivatives needs to initialize the coreData first!"); - vector<Vector> ddist_tmp(n); Vector csum; Vector tmp1,tmp2; for(unsigned iat=0;iat<n;iat++){ @@ -1003,7 +1002,6 @@ std::vector<Vector> RMSDCoreData::getDDistanceDReference(){ derivatives.resize(n); double prefactor=1.0; if(!distanceIsMSD) prefactor*=0.5/dist; - vector<Vector> ddist_tmp(n); Vector csum,tmp1,tmp2; plumed_massert(!retrieve_only_rotation,"You used only_rotation=true in doCoreCalc therefore you cannot retrieve this information now"); @@ -1046,7 +1044,6 @@ std::vector<Vector> RMSDCoreData::getDDistanceDReferenceSOMA(){ derivatives.resize(n); double prefactor=1.0; if(!distanceIsMSD) prefactor*=0.5/dist; - vector<Vector> ddist_tmp(n); Vector csum,tmp1,tmp2; plumed_massert(!retrieve_only_rotation,"You used only_rotation=true in doCoreCalc therefore you cannot retrieve this information now"); -- GitLab