From c503e4d9f40eb3e0571993987285b999b4226c5d Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Wed, 3 Apr 2019 07:48:43 +0200 Subject: [PATCH] Fixed printf formats Especially when printing size_t it is better to use << operator which always uses the right size. --- src/analysis/ReadAnalysisFrames.cpp | 2 +- src/bias/MetaD.cpp | 2 +- src/colvar/PathMSDBase.cpp | 3 ++- src/generic/Debug.cpp | 4 ++-- src/isdb/Rescale.cpp | 2 +- src/mapping/AdaptivePath.cpp | 3 ++- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/analysis/ReadAnalysisFrames.cpp b/src/analysis/ReadAnalysisFrames.cpp index 46eb1382d..778fd1ebc 100644 --- a/src/analysis/ReadAnalysisFrames.cpp +++ b/src/analysis/ReadAnalysisFrames.cpp @@ -55,7 +55,7 @@ ReadAnalysisFrames::ReadAnalysisFrames( const ActionOptions& ao ): weights_calculated(false) { parse("CLEAR",clearstride); - if( clearstride!=0 ) log.printf(" clearing stored data every %d steps\n"); + if( clearstride!=0 ) log.printf(" clearing stored data every %u steps\n",clearstride); // Get the names of the argumes argument_names.resize( getNumberOfArguments() ); for(unsigned i=0; i<getNumberOfArguments(); ++i) argument_names[i]=getPntrToArgument(i)->getName(); diff --git a/src/bias/MetaD.cpp b/src/bias/MetaD.cpp index 42e66fbd3..493744f37 100644 --- a/src/bias/MetaD.cpp +++ b/src/bias/MetaD.cpp @@ -1020,7 +1020,7 @@ MetaD::MetaD(const ActionOptions& ao): log.printf(" calculation on the fly of the transition bias V*(t)\n"); addComponent("transbias"); componentIsNotPeriodic("transbias"); - log.printf(" Number of transition wells %d\n", transitionwells_.size()); + log<<" Number of transition wells "<<transitionwells_.size()<<"\n"; if (transitionwells_.size() == 0) error("Calculating the transition bias on the fly requires definition of at least one transition well"); // Check that a grid is in use. if (!grid_) error(" transition barrier finding requires a grid for the bias"); diff --git a/src/colvar/PathMSDBase.cpp b/src/colvar/PathMSDBase.cpp index 6f1753ba6..ccd9fb4c8 100644 --- a/src/colvar/PathMSDBase.cpp +++ b/src/colvar/PathMSDBase.cpp @@ -223,7 +223,8 @@ void PathMSDBase::calculate() { vector<Vector> ders; double withoutclose = opt.calculate(getPositions(), ders, true); float difference = fabs(withoutclose-withclose); - log.printf("PLUMED-CLOSE: difference original %lf - with close %lf = %lf, step %d, i %d imgVec[i].index %d \n", withoutclose, withclose, difference, getStep(), i, imgVec[i].index); + log<<"PLUMED-CLOSE: difference original "<<withoutclose; + log<<" - with close "<<withclose<<" = "<<difference<<", step "<<getStep()<<", i "<<i<<" imgVec[i].index "<<imgVec[i].index<<"\n"; } } } diff --git a/src/generic/Debug.cpp b/src/generic/Debug.cpp index 066b2c50c..6edd2ec8d 100644 --- a/src/generic/Debug.cpp +++ b/src/generic/Debug.cpp @@ -115,7 +115,7 @@ void Debug::apply() { if(p->isActive()) a++; }; if(a>0) { - ofile.printf("activity at step %i: ",getStep()); + ofile<<"activity at step "<<getStep()<<": "; for(const auto & p : actionSet) { if(dynamic_cast<Debug*>(p.get()))continue; if(p->isActive()) ofile.printf("+"); @@ -125,7 +125,7 @@ void Debug::apply() { }; }; if(logRequestedAtoms) { - ofile.printf("requested atoms at step %i: ",getStep()); + ofile<<"requested atoms at step "<<getStep()<<": "; int* l; int n; plumed.cmd("createFullList",&n); diff --git a/src/isdb/Rescale.cpp b/src/isdb/Rescale.cpp index aaa39ef96..4965ac873 100644 --- a/src/isdb/Rescale.cpp +++ b/src/isdb/Rescale.cpp @@ -278,7 +278,7 @@ Rescale::Rescale(const ActionOptions&ao): log.printf(" name of the SELECTOR use for this action %s\n",selector_.c_str()); log.printf(" number of bins in grid %u\n",nbin); log.printf(" number of arguments that will not be scaled %u\n",nores_); - if(nrep_>1) log.printf(" number of arguments that will not be summed across replicas %u\n",not_shared.size()); + if(nrep_>1) log<<" number of arguments that will not be summed across replicas "<<not_shared.size()<<"\n"; log.printf(" biasfactor %f\n",biasf_); log.printf(" initial hills height %f\n",w0_); log.printf(" stride to write bias to file %u\n",Biasstride_); diff --git a/src/mapping/AdaptivePath.cpp b/src/mapping/AdaptivePath.cpp index 546d75e57..f140c414f 100644 --- a/src/mapping/AdaptivePath.cpp +++ b/src/mapping/AdaptivePath.cpp @@ -230,7 +230,8 @@ void AdaptivePath::update() { myspacings.reparameterize( fixedn[0], fixedn[1], tolerance ); } if( (getStep()>0) && (getStep()%wstride==0) ) { - pathfile.printf("# PATH AT STEP %d TIME %f \n", getStep(), getTime() ); + pathfile<<"# PATH AT STEP "<<getStep(); + pathfile.printf(" TIME %f \n",getTime()); std::vector<std::unique_ptr<ReferenceConfiguration>>& myconfs=getAllReferenceConfigurations(); std::vector<SetupMolInfo*> moldat=plumed.getActionSet().select<SetupMolInfo*>(); if( moldat.size()>1 ) error("you should only have one MOLINFO action in your input file"); -- GitLab