remove .c_str() and simplify output in several places

This commit is contained in:
Axel Kohlmeyer
2020-06-03 16:37:30 -04:00
parent 9f3f53cc6b
commit dd11fb3964
18 changed files with 110 additions and 143 deletions

View File

@ -275,7 +275,7 @@ void KimInit::determine_model_type_and_units(char * model_name,
std::string mesg("Incompatible units for KIM Simulator Model, " std::string mesg("Incompatible units for KIM Simulator Model, "
"required units = "); "required units = ");
mesg += *model_units; mesg += *model_units;
error->all(FLERR,mesg.c_str()); error->all(FLERR,mesg);
} }
} }
} }
@ -328,8 +328,7 @@ void KimInit::do_init(char *model_name, char *user_units, char *model_units, KIM
mesg += "\n"; mesg += "\n";
mesg += "#\n"; mesg += "#\n";
if (screen) fputs(mesg.c_str(),screen); utils::logmesg(lmp,mesg);
if (logfile) fputs(mesg.c_str(),logfile);
} }
fix_store->setptr("simulator_model", (void *) simulatorModel); fix_store->setptr("simulator_model", (void *) simulatorModel);
@ -346,7 +345,7 @@ void KimInit::do_init(char *model_name, char *user_units, char *model_units, KIM
std::string cmd("units "); std::string cmd("units ");
cmd += model_units; cmd += model_units;
input->one(cmd.c_str()); input->one(cmd);
if (model_type == SM) { if (model_type == SM) {
int sim_fields, sim_lines; int sim_fields, sim_lines;
@ -519,7 +518,7 @@ void KimInit::do_variables(char *user_units, char *model_units)
"unit = " + units[i] + "; " "unit = " + units[i] + "; "
"from = " + from + "; " "from = " + from + "; "
"to = " + to + "."; "to = " + to + ".";
error->all(FLERR,err.c_str()); error->all(FLERR,err);
} }
variable->internal_set(v_unit,conversion_factor); variable->internal_set(v_unit,conversion_factor);
if (comm->me == 0) { if (comm->me == 0) {

View File

@ -192,7 +192,7 @@ void KimInteractions::do_setup(int narg, char **arg)
std::string msg("Species '"); std::string msg("Species '");
msg += strword; msg += strword;
msg += "' is not supported by this KIM Simulator Model"; msg += "' is not supported by this KIM Simulator Model";
error->all(FLERR,msg.c_str()); error->all(FLERR,msg);
} }
strword = strtok(NULL," \t"); strword = strtok(NULL," \t");
} }
@ -276,8 +276,8 @@ void KimInteractions::do_setup(int narg, char **arg)
cmd2 += " "; cmd2 += " ";
} }
input->one(cmd1.c_str()); input->one(cmd1);
input->one(cmd2.c_str()); input->one(cmd2);
} }
// End output to log file // End output to log file

View File

@ -163,7 +163,7 @@ void KimParam::command(int narg, char **arg)
if (!kim_param_get && !kim_param_set) { if (!kim_param_get && !kim_param_set) {
std::string msg("Incorrect arguments in kim_param command.\n"); std::string msg("Incorrect arguments in kim_param command.\n");
msg += "'kim_param get/set' is mandatory."; msg += "'kim_param get/set' is mandatory.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
// Check if we called a kim_init command // Check if we called a kim_init command
@ -225,7 +225,7 @@ void KimParam::command(int narg, char **arg)
msg += "To set the new parameter values, pair style must be assigned.\n"; msg += "To set the new parameter values, pair style must be assigned.\n";
msg += "Must use 'kim_interactions' or"; msg += "Must use 'kim_interactions' or";
msg += "'pair_style kim ' before 'kim_param set'"; msg += "'pair_style kim ' before 'kim_param set'";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} else { } else {
KIM_LengthUnit lengthUnit; KIM_LengthUnit lengthUnit;
KIM_EnergyUnit energyUnit; KIM_EnergyUnit energyUnit;
@ -296,7 +296,7 @@ void KimParam::command(int narg, char **arg)
msg += "This Model does not have the requested '"; msg += "This Model does not have the requested '";
msg += paramname; msg += paramname;
msg += "' parameter."; msg += "' parameter.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
// Get the index_range for the requested parameter // Get the index_range for the requested parameter
@ -313,7 +313,7 @@ void KimParam::command(int narg, char **arg)
msg += "Expected integer parameter(s) instead of '"; msg += "Expected integer parameter(s) instead of '";
msg += argtostr; msg += argtostr;
msg += "' in index_range."; msg += "' in index_range.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
std::string::size_type npos = argtostr.find(':'); std::string::size_type npos = argtostr.find(':');
@ -330,7 +330,7 @@ void KimParam::command(int narg, char **arg)
msg += "' parameter with extent of '"; msg += "' parameter with extent of '";
msg += SNUM(extent); msg += SNUM(extent);
msg += "' ."; msg += "' .";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
} else { } else {
std::stringstream str(argtostr); std::stringstream str(argtostr);
@ -342,7 +342,7 @@ void KimParam::command(int narg, char **arg)
msg += "' with the extent of '"; msg += "' with the extent of '";
msg += SNUM(extent); msg += SNUM(extent);
msg += "' ."; msg += "' .";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
nubound = nlbound; nubound = nlbound;
} }
@ -350,7 +350,7 @@ void KimParam::command(int narg, char **arg)
std::string msg("Wrong number of arguments in "); std::string msg("Wrong number of arguments in ");
msg += "kim_param get command.\n"; msg += "kim_param get command.\n";
msg += "Index range after parameter name is mandatory."; msg += "Index range after parameter name is mandatory.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
int const nvars = nubound - nlbound + 1; int const nvars = nubound - nlbound + 1;
@ -363,7 +363,7 @@ void KimParam::command(int narg, char **arg)
std::string msg("Wrong number of arguments in "); std::string msg("Wrong number of arguments in ");
msg += "kim_param get command.\n"; msg += "kim_param get command.\n";
msg += "The LAMMPS variable name is mandatory."; msg += "The LAMMPS variable name is mandatory.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
// indicator flag for list request // indicator flag for list request
@ -400,7 +400,7 @@ void KimParam::command(int narg, char **arg)
msg += "' variable names or '"; msg += "' variable names or '";
msg += varname; msg += varname;
msg += " split' is mandatory."; msg += " split' is mandatory.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
} else { } else {
std::string msg("Wrong number of arguments in "); std::string msg("Wrong number of arguments in ");
@ -410,7 +410,7 @@ void KimParam::command(int narg, char **arg)
msg += "' variable names or '"; msg += "' variable names or '";
msg += varname; msg += varname;
msg += " split/list' is mandatory."; msg += " split/list' is mandatory.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
} else { } else {
varsname = new char *[1]; varsname = new char *[1];
@ -524,7 +524,7 @@ void KimParam::command(int narg, char **arg)
set_cmd += " "; set_cmd += " ";
set_cmd += arg[i]; set_cmd += arg[i];
} }
input->one(set_cmd.c_str()); input->one(set_cmd);
} }
} else } else
error->all(FLERR, "This model has No mutable parameters."); error->all(FLERR, "This model has No mutable parameters.");

View File

@ -100,13 +100,13 @@ void kimProperty::command(int narg, char **arg)
std::string msg("Error incorrect arguments in kim_property command.\n"); std::string msg("Error incorrect arguments in kim_property command.\n");
msg += "`kim_property create/destroy/modify/remove/dump` "; msg += "`kim_property create/destroy/modify/remove/dump` ";
msg += "is mandatory."; msg += "is mandatory.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
if (comm->me == 0) { if (comm->me == 0) {
std::string msg; std::string msg;
msg = "#=== kim-property ===========================================\n"; msg = "#=== kim-property ===========================================\n";
input->write_echo(msg.c_str()); input->write_echo(msg);
} }
// Get the kim_str ptr to the data associated with a kim_property_str // Get the kim_str ptr to the data associated with a kim_property_str

View File

@ -429,7 +429,7 @@ void PairKIM::coeff(int narg, char **arg)
} else { } else {
std::string msg("create_kim_particle_codes: symbol not found: "); std::string msg("create_kim_particle_codes: symbol not found: ");
msg += lmps_unique_elements[i]; msg += lmps_unique_elements[i];
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
} }
// Set the new values for PM parameters // Set the new values for PM parameters
@ -441,7 +441,7 @@ void PairKIM::coeff(int narg, char **arg)
if (!numberOfParameters) { if (!numberOfParameters) {
std::string msg("Incorrect args for pair coefficients \n"); std::string msg("Incorrect args for pair coefficients \n");
msg += "This model has No mutable parameters."; msg += "This model has No mutable parameters.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
int kimerror; int kimerror;
@ -477,7 +477,7 @@ void PairKIM::coeff(int narg, char **arg)
msg += "This Model does not have the requested '"; msg += "This Model does not have the requested '";
msg += paramname; msg += paramname;
msg += "' parameter."; msg += "' parameter.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
// Get the index_range for the requested parameter // Get the index_range for the requested parameter
@ -493,7 +493,7 @@ void PairKIM::coeff(int narg, char **arg)
msg += "Expected integer parameter(s) instead of '"; msg += "Expected integer parameter(s) instead of '";
msg += argtostr; msg += argtostr;
msg += "' in index_range."; msg += "' in index_range.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
std::string::size_type npos = argtostr.find(':'); std::string::size_type npos = argtostr.find(':');
@ -510,7 +510,7 @@ void PairKIM::coeff(int narg, char **arg)
msg += "' parameter with extent of '"; msg += "' parameter with extent of '";
msg += SNUM(extent); msg += SNUM(extent);
msg += "' ."; msg += "' .";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
} else { } else {
std::stringstream str(argtostr); std::stringstream str(argtostr);
@ -522,7 +522,7 @@ void PairKIM::coeff(int narg, char **arg)
msg += "' parameter with extent of '"; msg += "' parameter with extent of '";
msg += SNUM(extent); msg += SNUM(extent);
msg += "' ."; msg += "' .";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
nubound = nlbound; nubound = nlbound;
} }
@ -530,7 +530,7 @@ void PairKIM::coeff(int narg, char **arg)
std::string msg = std::string msg =
"Wrong number of arguments for pair coefficients.\n"; "Wrong number of arguments for pair coefficients.\n";
msg += "Index range after parameter name is mandatory."; msg += "Index range after parameter name is mandatory.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
// Parameter values // Parameter values
@ -561,7 +561,7 @@ void PairKIM::coeff(int narg, char **arg)
msg += "' values are requested for '"; msg += "' values are requested for '";
msg += paramname; msg += paramname;
msg += "' parameter."; msg += "' parameter.";
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
} }
@ -1122,7 +1122,7 @@ void PairKIM::set_kim_model_has_flags()
KIM_SUPPORT_STATUS_required)) { KIM_SUPPORT_STATUS_required)) {
std::string msg("KIM Model requires unsupported compute argument: "); std::string msg("KIM Model requires unsupported compute argument: ");
msg += KIM_ComputeArgumentName_ToString(computeArgumentName); msg += KIM_ComputeArgumentName_ToString(computeArgumentName);
error->all(FLERR, msg.c_str()); error->all(FLERR, msg);
} }
} }

View File

@ -124,7 +124,7 @@ FixRX::FixRX(LAMMPS *lmp, int narg, char **arg) :
else { else {
std::string errmsg = "Illegal command " + std::string(word) std::string errmsg = "Illegal command " + std::string(word)
+ " expected \"sparse\" or \"dense\"\n"; + " expected \"sparse\" or \"dense\"\n";
error->all(FLERR, errmsg.c_str()); error->all(FLERR, errmsg);
} }
if (comm->me == 0 and Verbosity > 1){ if (comm->me == 0 and Verbosity > 1){
@ -134,7 +134,7 @@ FixRX::FixRX(LAMMPS *lmp, int narg, char **arg) :
else else
msg += std::string("dense"); msg += std::string("dense");
error->message(FLERR, msg.c_str()); error->message(FLERR, msg);
} }
} }
@ -149,7 +149,7 @@ FixRX::FixRX(LAMMPS *lmp, int narg, char **arg) :
odeIntegrationFlag = ODE_LAMMPS_RKF45; odeIntegrationFlag = ODE_LAMMPS_RKF45;
else { else {
std::string errmsg = "Illegal ODE integration type: " + std::string(word); std::string errmsg = "Illegal ODE integration type: " + std::string(word);
error->all(FLERR, errmsg.c_str()); error->all(FLERR, errmsg);
} }
} }

View File

@ -34,6 +34,7 @@
#include "error.h" #include "error.h"
#include "update.h" #include "update.h"
#include "utils.h" #include "utils.h"
#include "fmt/format.h"
#include "math_const.h" #include "math_const.h"
#include "math_extra.h" #include "math_extra.h"
@ -759,11 +760,9 @@ void PairMesoCNT::read_file()
// open file // open file
fp = force->open_potential(file); fp = force->open_potential(file);
if (fp == NULL) { if (fp == NULL)
std::string str("Cannot open mesocnt file: "); error->one(FLERR,fmt::format("Cannot open mesocnt file: {}",file));
str += file;
error->one(FLERR,str.c_str());
}
utils::sfgets(FLERR,line,MAXLINE,fp,file,error); utils::sfgets(FLERR,line,MAXLINE,fp,file,error);
// potential parameters // potential parameters
@ -771,18 +770,15 @@ void PairMesoCNT::read_file()
utils::sfgets(FLERR,line,MAXLINE,fp,file,error); utils::sfgets(FLERR,line,MAXLINE,fp,file,error);
num = sscanf(line,"%d %d %d %d", num = sscanf(line,"%d %d %d %d",
&uinf_points,&gamma_points,&phi_points,&usemi_points); &uinf_points,&gamma_points,&phi_points,&usemi_points);
if (num != 4) { if (num != 4)
std::string str("Could not correctly parse line 2 in mesocnt file: "); error->one(FLERR,fmt::format("Could not correctly parse line 2 in "
str += file; "mesocnt file: {}",file));
error->one(FLERR,str.c_str());
}
utils::sfgets(FLERR,line,MAXLINE,fp,file,error); utils::sfgets(FLERR,line,MAXLINE,fp,file,error);
num = sscanf(line,"%lg %lg %lg %lg",&r_ang,&sig_ang,&delta1,&delta2); num = sscanf(line,"%lg %lg %lg %lg",&r_ang,&sig_ang,&delta1,&delta2);
if (num != 4) { if (num != 4)
std::string str("Could not correctly parse line 3 in mesocnt file: "); error->one(FLERR,fmt::format("Could not correctly parse line 3 in "
str += file; "mesocnt file: {}",file));
error->one(FLERR,str.c_str());
}
} }
MPI_Bcast(&uinf_points,1,MPI_INT,0,world); MPI_Bcast(&uinf_points,1,MPI_INT,0,world);
@ -850,11 +846,9 @@ void PairMesoCNT::read_data(FILE *fp, double *data,
double x,xtemp,dxtemp; double x,xtemp,dxtemp;
for (int i = 0; i < ninput; i++) { for (int i = 0; i < ninput; i++) {
if (NULL == fgets(line,MAXLINE,fp)) { if (NULL == fgets(line,MAXLINE,fp))
std::string str("Premature end of file in pair table "); error->one(FLERR,fmt::format("Premature end of file in pair table: {}",file));
str += file;
error->one(FLERR,str.c_str());
}
if (i > 0) xtemp = x; if (i > 0) xtemp = x;
if (2 != sscanf(line,"%lg %lg",&x,&data[i])) cerror++; if (2 != sscanf(line,"%lg %lg",&x,&data[i])) cerror++;
if (i == 0) { if (i == 0) {
@ -869,24 +863,18 @@ void PairMesoCNT::read_data(FILE *fp, double *data,
// warn if data was read incompletely, e.g. columns were missing // warn if data was read incompletely, e.g. columns were missing
if (cerror) { if (cerror) {
char str[128]; std::string mesg = fmt::format("{} of {} lines were incomplete or could "
sprintf(str,"%d of %d lines were incomplete\n" "or could not be parsed completely in "
" or could not be parsed completely\n" " pair table: {}",cerror,ninput,file);
" in pair table ",cerror,ninput); error->warning(FLERR,mesg);
std::string errstr = str;
errstr += file;
error->warning(FLERR,errstr.c_str());
} }
// warn if spacing between data points is not constant // warn if spacing between data points is not constant
if (serror) { if (serror) {
char str[128]; std::string mesg = fmt::format("{} spacings in first column were different "
sprintf(str,"%d spacings in first column were different\n" " from first spacing in pair table: {}",serror,file);
" from first spacing in pair table ",serror); error->warning(FLERR,mesg);
std::string errstr = str;
errstr += file;
error->warning(FLERR,errstr.c_str());
} }
} }
@ -911,11 +899,9 @@ void PairMesoCNT::read_data(FILE *fp, double **data,
for (int i = 0; i < ninput; i++) { for (int i = 0; i < ninput; i++) {
if (i > 0) xtemp = x; if (i > 0) xtemp = x;
for (int j = 0; j < ninput; j++) { for (int j = 0; j < ninput; j++) {
if (NULL == fgets(line,MAXLINE,fp)) { if (NULL == fgets(line,MAXLINE,fp))
std::string str("Premature end of file in pair table "); error->one(FLERR,fmt::format("Premature end of file in pair table: {}",file));
str += file;
error->one(FLERR,str.c_str());
}
if (j > 0) ytemp = y; if (j > 0) ytemp = y;
if (3 != sscanf(line,"%lg %lg %lg",&x,&y,&data[i][j])) cerror++; if (3 != sscanf(line,"%lg %lg %lg",&x,&y,&data[i][j])) cerror++;
if (i == 0 && j == 0) ystart = y; if (i == 0 && j == 0) ystart = y;
@ -936,34 +922,21 @@ void PairMesoCNT::read_data(FILE *fp, double **data,
// warn if data was read incompletely, e.g. columns were missing // warn if data was read incompletely, e.g. columns were missing
if (cerror) { if (cerror)
char str[128]; error->warning(FLERR,fmt::format("{} of {} lines were incomplete or could "
sprintf(str,"%d of %d lines were incomplete\n" "not be parsed completely in pair table: {}",
" or could not be parsed completely\n" cerror,ninput*ninput,file));
" in pair table ",cerror,ninput*ninput);
std::string errstr = str;
errstr += file;
error->warning(FLERR,errstr.c_str());
}
// warn if spacing between data points is not constant // warn if spacing between data points is not constant
if (sxerror) { if (sxerror)
char str[128]; error->warning(FLERR,fmt::format("{} spacings in first column were different "
sprintf(str,"%d spacings in first column were different\n" " from first spacing in pair table: {}",
" from first spacing in pair table ",sxerror); sxerror,file));
std::string errstr = str; if (syerror)
errstr += file; error->warning(FLERR,fmt::format("{} spacings in second column were different "
error->warning(FLERR,errstr.c_str()); " from first spacing in pair table: {}",
} syerror,file));
if (syerror) {
char str[128];
sprintf(str,"%d spacings in second column were different\n"
" from first spacing in pair table ",syerror);
std::string errstr = str;
errstr += file;
error->warning(FLERR,errstr.c_str());
}
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -761,7 +761,7 @@ AtomVec *Atom::new_avec(const char *style, int trysuffix, int &sflag)
return avec_creator(lmp); return avec_creator(lmp);
} }
error->all(FLERR,utils::check_packages_for_style("atom",style,lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("atom",style,lmp));
return NULL; return NULL;
} }

View File

@ -157,7 +157,7 @@ void Domain::init()
std::string mesg = "Must not have multiple fixes change box parameter "; std::string mesg = "Must not have multiple fixes change box parameter ";
#define CHECK_BOX_FIX_ERROR(par) \ #define CHECK_BOX_FIX_ERROR(par) \
if (box_change_ ## par > 1) error->all(FLERR,(mesg + #par).c_str()) if (box_change_ ## par > 1) error->all(FLERR,(mesg + #par))
CHECK_BOX_FIX_ERROR(x); CHECK_BOX_FIX_ERROR(x);
CHECK_BOX_FIX_ERROR(y); CHECK_BOX_FIX_ERROR(y);
@ -1788,7 +1788,7 @@ void Domain::add_region(int narg, char **arg)
if (region_map->find(arg[1]) != region_map->end()) { if (region_map->find(arg[1]) != region_map->end()) {
RegionCreator region_creator = (*region_map)[arg[1]]; RegionCreator region_creator = (*region_map)[arg[1]];
regions[nregion] = region_creator(lmp, narg, arg); regions[nregion] = region_creator(lmp, narg, arg);
} else error->all(FLERR,utils::check_packages_for_style("region",arg[1],lmp).c_str()); } else error->all(FLERR,utils::check_packages_for_style("region",arg[1],lmp));
// initialize any region variables via init() // initialize any region variables via init()
// in case region is used between runs, e.g. to print a variable // in case region is used between runs, e.g. to print a variable

View File

@ -284,7 +284,7 @@ Pair *Force::new_pair(const char *style, int trysuffix, int &sflag)
return pair_creator(lmp); return pair_creator(lmp);
} }
error->all(FLERR,utils::check_packages_for_style("pair",style,lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("pair",style,lmp));
return NULL; return NULL;
} }
@ -397,7 +397,7 @@ Bond *Force::new_bond(const char *style, int trysuffix, int &sflag)
return bond_creator(lmp); return bond_creator(lmp);
} }
error->all(FLERR,utils::check_packages_for_style("bond",style,lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("bond",style,lmp));
return NULL; return NULL;
} }
@ -476,7 +476,7 @@ Angle *Force::new_angle(const char *style, int trysuffix, int &sflag)
return angle_creator(lmp); return angle_creator(lmp);
} }
error->all(FLERR,utils::check_packages_for_style("angle",style,lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("angle",style,lmp));
return NULL; return NULL;
} }
@ -556,7 +556,7 @@ Dihedral *Force::new_dihedral(const char *style, int trysuffix, int &sflag)
return dihedral_creator(lmp); return dihedral_creator(lmp);
} }
error->all(FLERR,utils::check_packages_for_style("dihedral",style,lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("dihedral",style,lmp));
return NULL; return NULL;
} }
@ -635,7 +635,7 @@ Improper *Force::new_improper(const char *style, int trysuffix, int &sflag)
return improper_creator(lmp); return improper_creator(lmp);
} }
error->all(FLERR,utils::check_packages_for_style("improper",style,lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("improper",style,lmp));
return NULL; return NULL;
} }
@ -718,7 +718,7 @@ KSpace *Force::new_kspace(const char *style, int trysuffix, int &sflag)
return kspace_creator(lmp); return kspace_creator(lmp);
} }
error->all(FLERR,utils::check_packages_for_style("kspace",style,lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("kspace",style,lmp));
return NULL; return NULL;
} }
@ -947,9 +947,8 @@ double Force::numeric(const char *file, int line, char *str)
if (isdigit(str[i])) continue; if (isdigit(str[i])) continue;
if (str[i] == '-' || str[i] == '+' || str[i] == '.') continue; if (str[i] == '-' || str[i] == '+' || str[i] == '.') continue;
if (str[i] == 'e' || str[i] == 'E') continue; if (str[i] == 'e' || str[i] == 'E') continue;
std::string msg = fmt::format("Expected floating point parameter " error->all(file,line,fmt::format("Expected floating point parameter "
"instead of '{}' in input script or data file",str); "instead of '{}' in input script or data file",str));
error->all(file,line,msg.c_str());
} }
return atof(str); return atof(str);
@ -972,9 +971,8 @@ int Force::inumeric(const char *file, int line, char *str)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue; if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
std::string msg = fmt::format("Expected integer parameter instead " error->all(file,line,fmt::format("Expected integer parameter instead "
"of '{}' in input script or data file",str); "of '{}' in input script or data file",str));
error->all(file,line,msg.c_str());
} }
return atoi(str); return atoi(str);
@ -997,9 +995,8 @@ bigint Force::bnumeric(const char *file, int line, char *str)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue; if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
std::string msg = fmt::format("Expected integer parameter instead " error->all(file,line,fmt::format("Expected integer parameter instead "
"of '{}' in input script or data file",str); "of '{}' in input script or data file",str));
error->all(file,line,msg.c_str());
} }
return ATOBIGINT(str); return ATOBIGINT(str);
@ -1022,9 +1019,8 @@ tagint Force::tnumeric(const char *file, int line, char *str)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue; if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
std::string msg = fmt::format("Expected integer parameter instead " error->all(file,line,fmt::format("Expected integer parameter instead "
"of '{}' in input script or data file",str); "of '{}' in input script or data file",str));
error->all(file,line,msg.c_str());
} }
return ATOTAGINT(str); return ATOTAGINT(str);

View File

@ -302,7 +302,7 @@ char *Input::one(const std::string &single)
// execute the command and return its name // execute the command and return its name
if (execute_command()) if (execute_command())
error->all(FLERR,fmt::format("Unknown command: {}",line).c_str()); error->all(FLERR,fmt::format("Unknown command: {}",line));
return command; return command;
} }

View File

@ -500,10 +500,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
} }
infile = fopen(arg[inflag],"r"); infile = fopen(arg[inflag],"r");
if (infile == NULL) { if (infile == NULL)
str = fmt::format("Cannot open input script {}",arg[inflag]); error->one(FLERR,fmt::format("Cannot open input script {}",arg[inflag]));
error->one(FLERR,str.c_str());
}
} }
// screen and logfile messages for universe and world // screen and logfile messages for universe and world
@ -614,13 +612,13 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
if (restart2data || restart2dump) { if (restart2data || restart2dump) {
std::string cmd = fmt::format("read_restart {}",restartfile); std::string cmd = fmt::format("read_restart {}",restartfile);
if (restartremap) cmd += " remap\n"; if (restartremap) cmd += " remap\n";
input->one(cmd.c_str()); input->one(cmd);
if (restart2data) cmd = "write_data "; if (restart2data) cmd = "write_data ";
else cmd = "write_dump"; else cmd = "write_dump";
for (iarg = wfirst; iarg < wlast; iarg++) for (iarg = wfirst; iarg < wlast; iarg++)
cmd += fmt::format(" {}", arg[iarg]); cmd += fmt::format(" {}", arg[iarg]);
if (restart2data) cmd += " noinit"; if (restart2data) cmd += " noinit";
input->one(cmd.c_str()); input->one(cmd);
error->done(0); error->done(0);
} }
} }

View File

@ -904,7 +904,7 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
} }
if (fix[ifix] == NULL) if (fix[ifix] == NULL)
error->all(FLERR,utils::check_packages_for_style("fix",arg[2],lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("fix",arg[2],lmp));
// check if Fix is in restart_global list // check if Fix is in restart_global list
// if yes, pass state info to the Fix so it can reset itself // if yes, pass state info to the Fix so it can reset itself
@ -1243,7 +1243,7 @@ void Modify::add_compute(int narg, char **arg, int trysuffix)
} }
if (compute[ncompute] == NULL) if (compute[ncompute] == NULL)
error->all(FLERR,utils::check_packages_for_style("compute",arg[2],lmp).c_str()); error->all(FLERR,utils::check_packages_for_style("compute",arg[2],lmp));
ncompute++; ncompute++;
} }

View File

@ -584,7 +584,7 @@ void Output::add_dump(int narg, char **arg)
if (dump_map->find(arg[2]) != dump_map->end()) { if (dump_map->find(arg[2]) != dump_map->end()) {
DumpCreator dump_creator = (*dump_map)[arg[2]]; DumpCreator dump_creator = (*dump_map)[arg[2]];
dump[ndump] = dump_creator(lmp, narg, arg); dump[ndump] = dump_creator(lmp, narg, arg);
} else error->all(FLERR,utils::check_packages_for_style("dump",arg[2],lmp).c_str()); } else error->all(FLERR,utils::check_packages_for_style("dump",arg[2],lmp));
every_dump[ndump] = force->inumeric(FLERR,arg[3]); every_dump[ndump] = force->inumeric(FLERR,arg[3]);
if (every_dump[ndump] <= 0) error->all(FLERR,"Illegal dump command"); if (every_dump[ndump] <= 0) error->all(FLERR,"Illegal dump command");

View File

@ -263,7 +263,7 @@ void ReadDump::setup_reader(int narg, char **arg)
// unrecognized style // unrecognized style
else error->all(FLERR,utils::check_packages_for_style("reader",readerstyle,lmp).c_str()); else error->all(FLERR,utils::check_packages_for_style("reader",readerstyle,lmp));
if (utils::strmatch(readerstyle,"^adios")) { if (utils::strmatch(readerstyle,"^adios")) {
// everyone is a reader with adios // everyone is a reader with adios

View File

@ -41,6 +41,7 @@
#include "info.h" #include "info.h"
#include "error.h" #include "error.h"
#include "utils.h" #include "utils.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
@ -1336,7 +1337,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
std::string mesg = "Invalid compute ID '"; std::string mesg = "Invalid compute ID '";
mesg += (word+2); mesg += (word+2);
mesg += "' in variable formula"; mesg += "' in variable formula";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
Compute *compute = modify->compute[icompute]; Compute *compute = modify->compute[icompute];
@ -1641,7 +1642,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
std::string mesg = "Invalid fix ID '"; std::string mesg = "Invalid fix ID '";
mesg += (word+2); mesg += (word+2);
mesg += "' in variable formula"; mesg += "' in variable formula";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
Fix *fix = modify->fix[ifix]; Fix *fix = modify->fix[ifix];
@ -3831,7 +3832,7 @@ int Variable::group_function(char *word, char *contents, Tree **tree,
std::string mesg = "Group ID '"; std::string mesg = "Group ID '";
mesg += args[0]; mesg += args[0];
mesg += "' in variable formula does not exist"; mesg += "' in variable formula does not exist";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
// match word to group function // match word to group function
@ -4044,7 +4045,7 @@ int Variable::region_function(char *id, int ivar)
std::string mesg = "Region ID '"; std::string mesg = "Region ID '";
mesg += id; mesg += id;
mesg += "' in variable formula does not exist"; mesg += "' in variable formula does not exist";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
// init region in case sub-regions have been deleted // init region in case sub-regions have been deleted
@ -4126,7 +4127,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
std::string mesg = "Invalid compute ID '"; std::string mesg = "Invalid compute ID '";
mesg += (args[0]+2); mesg += (args[0]+2);
mesg += "' in variable formula"; mesg += "' in variable formula";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
compute = modify->compute[icompute]; compute = modify->compute[icompute];
if (index == 0 && compute->vector_flag) { if (index == 0 && compute->vector_flag) {
@ -4171,7 +4172,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
std::string mesg = "Invalid fix ID '"; std::string mesg = "Invalid fix ID '";
mesg += (args[0]+2); mesg += (args[0]+2);
mesg += "' in variable formula"; mesg += "' in variable formula";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
fix = modify->fix[ifix]; fix = modify->fix[ifix];
if (index == 0 && fix->vector_flag) { if (index == 0 && fix->vector_flag) {
@ -4179,7 +4180,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
std::string mesg = "Fix with ID '"; std::string mesg = "Fix with ID '";
mesg += (args[0]+2); mesg += (args[0]+2);
mesg += "' in variable formula not computed at compatible time"; mesg += "' in variable formula not computed at compatible time";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
nvec = fix->size_vector; nvec = fix->size_vector;
nstride = 1; nstride = 1;
@ -4391,7 +4392,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
std::string mesg = "Variable ID '"; std::string mesg = "Variable ID '";
mesg += args[0]; mesg += args[0];
mesg += "' in variable formula does not exist"; mesg += "' in variable formula does not exist";
print_var_error(FLERR,mesg.c_str(),ivar); print_var_error(FLERR,mesg,ivar);
} }
// SCALARFILE has single current value, read next one // SCALARFILE has single current value, read next one
@ -4772,13 +4773,11 @@ char *Variable::find_next_comma(char *str)
helper routine for printing variable name with error message helper routine for printing variable name with error message
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Variable::print_var_error(const char *srcfile, int lineno, void Variable::print_var_error(const std::string &srcfile, const int lineno,
const char *errmsg, int ivar, int global) const std::string &errmsg, int ivar, int global)
{ {
if ((ivar >= 0) && (ivar < nvar)) { if ((ivar >= 0) && (ivar < nvar)) {
char msg[128]; std::string msg = fmt::format("Variable {}: ",names[ivar]) + errmsg;
snprintf(msg,128,"Variable %s: %s",names[ivar],errmsg);
if (global) if (global)
error->all(srcfile,lineno,msg); error->all(srcfile,lineno,msg);
else else

View File

@ -15,6 +15,7 @@
#define LMP_VARIABLE_H #define LMP_VARIABLE_H
#include "pointers.h" #include "pointers.h"
#include <string>
namespace LAMMPS_NS { namespace LAMMPS_NS {
@ -123,7 +124,8 @@ class Variable : protected Pointers {
double constant(char *); double constant(char *);
int parse_args(char *, char **); int parse_args(char *, char **);
char *find_next_comma(char *); char *find_next_comma(char *);
void print_var_error(const char *, int, const char *, int, int global=1); void print_var_error(const std::string &, int, const std::string &,
int, int global=1);
void print_tree(Tree *, int); void print_tree(Tree *, int);
}; };

View File

@ -63,7 +63,7 @@ void WriteDump::command(int narg, char **arg)
#include "style_dump.h" #include "style_dump.h"
#undef DUMP_CLASS #undef DUMP_CLASS
else error->all(FLERR,utils::check_packages_for_style("dump",arg[1],lmp).c_str()); else error->all(FLERR,utils::check_packages_for_style("dump",arg[1],lmp));
if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]); if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]);