diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index a15a359881..4d65457340 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -31,6 +31,7 @@ #include "math_const.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -286,12 +287,9 @@ void FixDeposit::init() } else maxradinsert = 0.5; double separation = MAX(2.0*maxradinsert,maxradall+maxradinsert); - if (sqrt(nearsq) < separation && comm->me == 0) { - char str[128]; - sprintf(str,"Fix deposit near setting < possible overlap separation %g", - separation); - error->warning(FLERR,str); - } + if (sqrt(nearsq) < separation && comm->me == 0) + error->warning(FLERR,fmt::format("Fix deposit near setting < possible " + "overlap separation {}",separation)); } } diff --git a/src/MISC/fix_orient_bcc.cpp b/src/MISC/fix_orient_bcc.cpp index f93c7f8a6a..8548ee04cf 100644 --- a/src/MISC/fix_orient_bcc.cpp +++ b/src/MISC/fix_orient_bcc.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "atom.h" #include "update.h" #include "respa.h" @@ -35,6 +36,8 @@ #include "citeme.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -450,20 +453,12 @@ void FixOrientBCC::post_force(int /*vflag*/) MPI_Allreduce(&maxcount,&max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - if (screen) fprintf(screen, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (logfile) fprintf(logfile, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (screen) - fprintf(screen," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); - if (logfile) - fprintf(logfile," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); + std::string mesg = fmt::format("orient step {}: {} atoms have {} " + "neighbors\n", update->ntimestep, + atom->natoms,total); + mesg += fmt::format(" neighs: min = {}, max ={}, ave = {}\n", + min,max,ave); + utils::logmesg(lmp,mesg); } } } diff --git a/src/MISC/fix_orient_fcc.cpp b/src/MISC/fix_orient_fcc.cpp index 082ecaf459..97c545d189 100644 --- a/src/MISC/fix_orient_fcc.cpp +++ b/src/MISC/fix_orient_fcc.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "atom.h" #include "update.h" #include "respa.h" @@ -32,6 +33,8 @@ #include "citeme.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -448,20 +451,12 @@ void FixOrientFCC::post_force(int /*vflag*/) MPI_Allreduce(&maxcount,&max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - if (screen) fprintf(screen, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (logfile) fprintf(logfile, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (screen) - fprintf(screen," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); - if (logfile) - fprintf(logfile," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); + std::string mesg = fmt::format("orient step {}: {} atoms have {} " + "neighbors\n", update->ntimestep, + atom->natoms,total); + mesg += fmt::format(" neighs: min = {}, max ={}, ave = {}\n", + min,max,ave); + utils::logmesg(lmp,mesg); } } } diff --git a/src/MISC/fix_ttm.cpp b/src/MISC/fix_ttm.cpp index eb9eb2620d..1c27e8affe 100644 --- a/src/MISC/fix_ttm.cpp +++ b/src/MISC/fix_ttm.cpp @@ -29,6 +29,8 @@ #include "random_mars.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -66,25 +68,22 @@ FixTTM::FixTTM(LAMMPS *lmp, int narg, char **arg) : nynodes = force->inumeric(FLERR,arg[11]); nznodes = force->inumeric(FLERR,arg[12]); - fpr = fopen(arg[13],"r"); - if (fpr == NULL) { - char str[128]; - snprintf(str,128,"Cannot open file %s",arg[13]); - error->one(FLERR,str); + if (comm->me == 0) { + fpr = fopen(arg[13],"r"); + if (fpr == NULL) + error->all(FLERR,fmt::format("Cannot open input file {}: {}", + arg[13], utils::getsyserror())); } nfileevery = force->inumeric(FLERR,arg[14]); if (nfileevery) { if (narg != 16) error->all(FLERR,"Illegal fix ttm command"); - MPI_Comm_rank(world,&me); - if (me == 0) { + if (comm->me == 0) { fp = fopen(arg[15],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix ttm file %s",arg[15]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open output file {}: {}", + arg[15], utils::getsyserror())); } } diff --git a/src/MLIAP/mliap_descriptor_snap.cpp b/src/MLIAP/mliap_descriptor_snap.cpp index eedeeb4483..d23ebc93fe 100644 --- a/src/MLIAP/mliap_descriptor_snap.cpp +++ b/src/MLIAP/mliap_descriptor_snap.cpp @@ -302,11 +302,9 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) FILE *fpparam; if (comm->me == 0) { fpparam = force->open_potential(paramfilename); - if (fpparam == NULL) { - char str[128]; - snprintf(str,128,"Cannot open SNAP parameter file %s",paramfilename); - error->one(FLERR,str); - } + if (fpparam == NULL) + error->one(FLERR,fmt::format("Cannot open SNAP parameter file {}: {}", + paramfilename, utils::getsyserror())); } char line[MAXLINE],*ptr; diff --git a/src/MLIAP/mliap_model.cpp b/src/MLIAP/mliap_model.cpp index 94aafc93a8..dfe3095541 100644 --- a/src/MLIAP/mliap_model.cpp +++ b/src/MLIAP/mliap_model.cpp @@ -22,6 +22,7 @@ #include "neigh_list.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -63,11 +64,9 @@ void MLIAPModel::read_coeffs(char *coefffilename) FILE *fpcoeff; if (comm->me == 0) { fpcoeff = force->open_potential(coefffilename); - if (fpcoeff == NULL) { - char str[128]; - snprintf(str,128,"Cannot open MLIAPModel coefficient file %s",coefffilename); - error->one(FLERR,str); - } + if (fpcoeff == NULL) + error->one(FLERR,fmt::format("Cannot open MLIAPModel coeff file {}: {}", + coefffilename,utils::getsyserror())); } char line[MAXLINE],*ptr; diff --git a/src/MOLECULE/fix_cmap.cpp b/src/MOLECULE/fix_cmap.cpp index a1b4d23b05..6fbf82e4cc 100644 --- a/src/MOLECULE/fix_cmap.cpp +++ b/src/MOLECULE/fix_cmap.cpp @@ -42,6 +42,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -253,17 +254,12 @@ void FixCMAP::pre_neighbor() atom5 = atom->map(crossterm_atom5[i][m]); if (atom1 == -1 || atom2 == -1 || atom3 == -1 || - atom4 == -1 || atom5 == -1) { - char str[128]; - sprintf(str,"CMAP atoms " - TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT " " - TAGINT_FORMAT " " TAGINT_FORMAT - " missing on proc %d at step " BIGINT_FORMAT, - crossterm_atom1[i][m],crossterm_atom2[i][m], - crossterm_atom3[i][m],crossterm_atom4[i][m], - crossterm_atom5[i][m],me,update->ntimestep); - error->one(FLERR,str); - } + atom4 == -1 || atom5 == -1) + error->one(FLERR,fmt::format("CMAP atoms {} {} {} {} {} missing on " + "proc {} at step {}", + crossterm_atom1[i][m],crossterm_atom2[i][m], + crossterm_atom3[i][m],crossterm_atom4[i][m], + crossterm_atom5[i][m],me,update->ntimestep)); atom1 = domain->closest_image(i,atom1); atom2 = domain->closest_image(i,atom2); atom3 = domain->closest_image(i,atom3); @@ -638,11 +634,10 @@ void FixCMAP::read_grid_map(char *cmapfile) FILE *fp = NULL; if (comm->me == 0) { fp = force->open_potential(cmapfile); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix cmap file %s",cmapfile); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix cmap file {}: {}", + cmapfile, utils::getsyserror())); + } for (int ix1 = 0; ix1 < 6; ix1++) @@ -1070,11 +1065,8 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, int nwords = utils::count_words(utils::trim_comment(buf)); *next = '\n'; - if (nwords != 7) { - char str[128]; - snprintf(str,128,"Incorrect %s format in data file",keyword); - error->all(FLERR,str); - } + if (nwords != 7) + error->all(FLERR,fmt::format("Incorrect {} format in data file",keyword)); // loop over lines of CMAP crossterms // tokenize the line into values diff --git a/src/POEMS/fix_poems.cpp b/src/POEMS/fix_poems.cpp index c8646f5b14..b0b1287717 100644 --- a/src/POEMS/fix_poems.cpp +++ b/src/POEMS/fix_poems.cpp @@ -34,6 +34,8 @@ #include "citeme.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -275,14 +277,9 @@ FixPOEMS::FixPOEMS(LAMMPS *lmp, int narg, char **arg) : for (ibody = 0; ibody < nbody; ibody++) nsum += nrigid[ibody]; nsum -= njoint; - if (me == 0) { - if (screen) - fprintf(screen,"%d clusters, %d bodies, %d joints, %d atoms\n", - ncluster,nbody,njoint,nsum); - if (logfile) - fprintf(logfile,"%d clusters, %d bodies, %d joints, %d atoms\n", - ncluster,nbody,njoint,nsum); - } + if (me == 0) + utils::logmesg(lmp,fmt::format("{} clusters, {} bodies, {} joints, {} atoms\n", + ncluster,nbody,njoint,nsum)); } /* ---------------------------------------------------------------------- @@ -366,9 +363,9 @@ void FixPOEMS::init() if (strcmp(modify->fix[i]->style,"poems") == 0) pflag = 1; if (pflag && (modify->fmask[i] & POST_FORCE) && !modify->fix[i]->rigid_flag) { - char str[128]; - snprintf(str,128,"Fix %s alters forces after fix poems",modify->fix[i]->id); - error->warning(FLERR,str); + if (comm->me == 0) + error->warning(FLERR,std::string("Fix ") + modify->fix[i]->id + + std::string(" alters forces after fix poems")); } } }