remove local buffers and snprintf() for file open error messages.

This commit is contained in:
Axel Kohlmeyer 2020-06-04 13:30:44 -04:00
parent 47888b587a
commit 2777d37a61
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
8 changed files with 44 additions and 55 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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) {

View File

@ -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

View File

@ -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");
}