diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 0ebdddb9df..2987783b2a 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -27,6 +27,8 @@ #include "variable.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -223,11 +225,9 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); if (me == 0) { fp = fopen(arg[iarg+1],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix ave/chunk file %s",arg[iarg+1]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix ave/chunk file {}: {}", + arg[iarg+1], utils::getsyserror())); } iarg += 2; } else if (strcmp(arg[iarg],"overwrite") == 0) { diff --git a/src/fix_ave_correlate.cpp b/src/fix_ave_correlate.cpp index 0a8a4cd17f..2231611d1e 100644 --- a/src/fix_ave_correlate.cpp +++ b/src/fix_ave_correlate.cpp @@ -30,6 +30,8 @@ #include "memory.h" #include "error.h" #include "force.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -148,11 +150,9 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); if (me == 0) { fp = fopen(arg[iarg+1],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix ave/correlate file %s",arg[iarg+1]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix ave/correlate file {}:"" {}", + arg[iarg+1], utils::getsyserror())); } iarg += 2; } else if (strcmp(arg[iarg],"overwrite") == 0) { diff --git a/src/fix_ave_histo.cpp b/src/fix_ave_histo.cpp index 1a292bf8d2..d0bedba34a 100644 --- a/src/fix_ave_histo.cpp +++ b/src/fix_ave_histo.cpp @@ -25,6 +25,8 @@ #include "memory.h" #include "error.h" #include "force.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -963,11 +965,9 @@ void FixAveHisto::options(int iarg, int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); if (me == 0) { fp = fopen(arg[iarg+1],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix ave/histo file %s",arg[iarg+1]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix ave/histo file {}: {}", + arg[iarg+1], utils::getsyserror())); } iarg += 2; } else if (strcmp(arg[iarg],"kind") == 0) { diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index 9b8dd13f05..84c5c04f11 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -28,6 +28,8 @@ #include "variable.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -1043,11 +1045,9 @@ void FixAveTime::options(int iarg, int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/time command"); if (me == 0) { fp = fopen(arg[iarg+1],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix ave/time file %s",arg[iarg+1]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix ave/time file {}: {}", + arg[iarg+1], utils::getsyserror())); } iarg += 2; } else if (strcmp(arg[iarg],"ave") == 0) { diff --git a/src/fix_enforce2d.cpp b/src/fix_enforce2d.cpp index 3edd24e9af..7dd8c08204 100644 --- a/src/fix_enforce2d.cpp +++ b/src/fix_enforce2d.cpp @@ -19,6 +19,7 @@ #include "modify.h" #include "respa.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -76,11 +77,9 @@ void FixEnforce2D::init() if (modify->fix[i]->enforce2d_flag) { if (myindex < 0) flist[nfixlist++] = modify->fix[i]; - else { - char msg[256]; - snprintf(msg,256,"Fix enforce2d must be defined after fix %s",modify->fix[i]->style); - error->all(FLERR,msg); - } + else + error->all(FLERR,fmt::format("Fix enforce2d must be defined after fix {}", + modify->fix[i]->style)); } if (modify->fix[i] == this) myindex = i; } diff --git a/src/fix_print.cpp b/src/fix_print.cpp index 54a706d24b..8a988c8dac 100644 --- a/src/fix_print.cpp +++ b/src/fix_print.cpp @@ -21,6 +21,8 @@ #include "memory.h" #include "error.h" #include "force.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -65,11 +67,9 @@ FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) : if (me == 0) { if (strcmp(arg[iarg],"file") == 0) fp = fopen(arg[iarg+1],"w"); else fp = fopen(arg[iarg+1],"a"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix print file %s",arg[iarg+1]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix print file {}: {}", + arg[iarg+1], utils::getsyserror())); } iarg += 2; } else if (strcmp(arg[iarg],"screen") == 0) { diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 5fb17ca636..aeea9a7dca 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -19,6 +19,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -221,11 +222,8 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, int nwords = utils::count_words(buf); *next = '\n'; - if (nwords != nvalue+1) { - char str[128]; - snprintf(str,128,"Incorrect %s format in data file",keyword); - error->all(FLERR,str); - } + if (nwords != nvalue+1) + error->all(FLERR,fmt::format("Incorrect {} format in data file",keyword)); char **values = new char*[nwords]; @@ -239,28 +237,21 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, next = strchr(buf,'\n'); values[0] = strtok(buf," \t\n\r\f"); - if (values[0] == NULL) { - char str[128]; - snprintf(str,128,"Too few lines in %s section of data file",keyword); - error->one(FLERR,str); - } + if (values[0] == NULL) + error->all(FLERR,fmt::format("Too few lines in {} section of data file",keyword)); + int format_ok = 1; for (j = 1; j < nwords; j++) { values[j] = strtok(NULL," \t\n\r\f"); if (values[j] == NULL) format_ok = 0; } - if (!format_ok) { - char str[128]; - snprintf(str,128,"Incorrect %s format in data file",keyword); - error->all(FLERR,str); - } + if (!format_ok) + error->all(FLERR,fmt::format("Incorrect {} format in data file",keyword)); itag = ATOTAGINT(values[0]) + id_offset; - if (itag <= 0 || itag > map_tag_max) { - char str[128]; - snprintf(str,128,"Invalid atom ID in %s section of data file",keyword); - error->one(FLERR,str); - } + if (itag <= 0 || itag > map_tag_max) + error->all(FLERR,fmt::format("Invalid atom ID {} in {} section of " + "data file",itag, keyword)); // assign words in line to per-atom vectors diff --git a/src/fix_tmd.cpp b/src/fix_tmd.cpp index 182da8ecaa..a174c2efa4 100644 --- a/src/fix_tmd.cpp +++ b/src/fix_tmd.cpp @@ -30,6 +30,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -73,11 +74,9 @@ nfileevery(0), fp(NULL), xf(NULL), xold(NULL) if (narg != 7) error->all(FLERR,"Illegal fix tmd command"); if (me == 0) { fp = fopen(arg[6],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix tmd file %s",arg[6]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix tmd file {}: {}", + arg[6], utils::getsyserror())); fprintf(fp,"%s %s\n","# Step rho_target rho_old gamma_back", "gamma_forward lambda work_lambda work_analytical"); }