From dd11fb3964acfbba94f19513f8d35b10b0a41e60 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 3 Jun 2020 16:37:30 -0400 Subject: [PATCH] remove .c_str() and simplify output in several places --- src/KIM/kim_init.cpp | 9 ++-- src/KIM/kim_interactions.cpp | 6 +-- src/KIM/kim_param.cpp | 22 ++++---- src/KIM/kim_property.cpp | 4 +- src/KIM/pair_kim.cpp | 18 +++---- src/USER-DPD/fix_rx.cpp | 6 +-- src/USER-MISC/pair_mesocnt.cpp | 99 +++++++++++++--------------------- src/atom.cpp | 2 +- src/domain.cpp | 4 +- src/force.cpp | 32 +++++------ src/input.cpp | 2 +- src/lammps.cpp | 10 ++-- src/modify.cpp | 4 +- src/output.cpp | 2 +- src/read_dump.cpp | 2 +- src/variable.cpp | 25 +++++---- src/variable.h | 4 +- src/write_dump.cpp | 2 +- 18 files changed, 110 insertions(+), 143 deletions(-) diff --git a/src/KIM/kim_init.cpp b/src/KIM/kim_init.cpp index 1d3830c275..5328769d22 100644 --- a/src/KIM/kim_init.cpp +++ b/src/KIM/kim_init.cpp @@ -275,7 +275,7 @@ void KimInit::determine_model_type_and_units(char * model_name, std::string mesg("Incompatible units for KIM Simulator Model, " "required 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"; - if (screen) fputs(mesg.c_str(),screen); - if (logfile) fputs(mesg.c_str(),logfile); + utils::logmesg(lmp,mesg); } 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 "); cmd += model_units; - input->one(cmd.c_str()); + input->one(cmd); if (model_type == SM) { int sim_fields, sim_lines; @@ -519,7 +518,7 @@ void KimInit::do_variables(char *user_units, char *model_units) "unit = " + units[i] + "; " "from = " + from + "; " "to = " + to + "."; - error->all(FLERR,err.c_str()); + error->all(FLERR,err); } variable->internal_set(v_unit,conversion_factor); if (comm->me == 0) { diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index d0aa0e3c4e..2167cd6069 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -192,7 +192,7 @@ void KimInteractions::do_setup(int narg, char **arg) std::string msg("Species '"); msg += strword; msg += "' is not supported by this KIM Simulator Model"; - error->all(FLERR,msg.c_str()); + error->all(FLERR,msg); } strword = strtok(NULL," \t"); } @@ -276,8 +276,8 @@ void KimInteractions::do_setup(int narg, char **arg) cmd2 += " "; } - input->one(cmd1.c_str()); - input->one(cmd2.c_str()); + input->one(cmd1); + input->one(cmd2); } // End output to log file diff --git a/src/KIM/kim_param.cpp b/src/KIM/kim_param.cpp index f5a154f2d9..ac995c8367 100644 --- a/src/KIM/kim_param.cpp +++ b/src/KIM/kim_param.cpp @@ -163,7 +163,7 @@ void KimParam::command(int narg, char **arg) if (!kim_param_get && !kim_param_set) { std::string msg("Incorrect arguments in kim_param command.\n"); 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 @@ -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 += "Must use 'kim_interactions' or"; msg += "'pair_style kim ' before 'kim_param set'"; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } else { KIM_LengthUnit lengthUnit; KIM_EnergyUnit energyUnit; @@ -296,7 +296,7 @@ void KimParam::command(int narg, char **arg) msg += "This Model does not have the requested '"; msg += paramname; msg += "' parameter."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } // 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 += argtostr; msg += "' in index_range."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } std::string::size_type npos = argtostr.find(':'); @@ -330,7 +330,7 @@ void KimParam::command(int narg, char **arg) msg += "' parameter with extent of '"; msg += SNUM(extent); msg += "' ."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } } else { std::stringstream str(argtostr); @@ -342,7 +342,7 @@ void KimParam::command(int narg, char **arg) msg += "' with the extent of '"; msg += SNUM(extent); msg += "' ."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } nubound = nlbound; } @@ -350,7 +350,7 @@ void KimParam::command(int narg, char **arg) std::string msg("Wrong number of arguments in "); msg += "kim_param get command.\n"; msg += "Index range after parameter name is mandatory."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } 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 "); msg += "kim_param get command.\n"; msg += "The LAMMPS variable name is mandatory."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } // indicator flag for list request @@ -400,7 +400,7 @@ void KimParam::command(int narg, char **arg) msg += "' variable names or '"; msg += varname; msg += " split' is mandatory."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } } else { std::string msg("Wrong number of arguments in "); @@ -410,7 +410,7 @@ void KimParam::command(int narg, char **arg) msg += "' variable names or '"; msg += varname; msg += " split/list' is mandatory."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } } else { varsname = new char *[1]; @@ -524,7 +524,7 @@ void KimParam::command(int narg, char **arg) set_cmd += " "; set_cmd += arg[i]; } - input->one(set_cmd.c_str()); + input->one(set_cmd); } } else error->all(FLERR, "This model has No mutable parameters."); diff --git a/src/KIM/kim_property.cpp b/src/KIM/kim_property.cpp index 4e63a25ffb..1020f380b7 100644 --- a/src/KIM/kim_property.cpp +++ b/src/KIM/kim_property.cpp @@ -100,13 +100,13 @@ void kimProperty::command(int narg, char **arg) std::string msg("Error incorrect arguments in kim_property command.\n"); msg += "`kim_property create/destroy/modify/remove/dump` "; msg += "is mandatory."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } if (comm->me == 0) { std::string msg; 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 diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 8ff0ddf455..76c18bb38a 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -429,7 +429,7 @@ void PairKIM::coeff(int narg, char **arg) } else { std::string msg("create_kim_particle_codes: symbol not found: "); msg += lmps_unique_elements[i]; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } } // Set the new values for PM parameters @@ -441,7 +441,7 @@ void PairKIM::coeff(int narg, char **arg) if (!numberOfParameters) { std::string msg("Incorrect args for pair coefficients \n"); msg += "This model has No mutable parameters."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } int kimerror; @@ -477,7 +477,7 @@ void PairKIM::coeff(int narg, char **arg) msg += "This Model does not have the requested '"; msg += paramname; msg += "' parameter."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } // 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 += argtostr; msg += "' in index_range."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } std::string::size_type npos = argtostr.find(':'); @@ -510,7 +510,7 @@ void PairKIM::coeff(int narg, char **arg) msg += "' parameter with extent of '"; msg += SNUM(extent); msg += "' ."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } } else { std::stringstream str(argtostr); @@ -522,7 +522,7 @@ void PairKIM::coeff(int narg, char **arg) msg += "' parameter with extent of '"; msg += SNUM(extent); msg += "' ."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } nubound = nlbound; } @@ -530,7 +530,7 @@ void PairKIM::coeff(int narg, char **arg) std::string msg = "Wrong number of arguments for pair coefficients.\n"; msg += "Index range after parameter name is mandatory."; - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } // Parameter values @@ -561,7 +561,7 @@ void PairKIM::coeff(int narg, char **arg) msg += "' values are requested for '"; msg += paramname; 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)) { std::string msg("KIM Model requires unsupported compute argument: "); msg += KIM_ComputeArgumentName_ToString(computeArgumentName); - error->all(FLERR, msg.c_str()); + error->all(FLERR, msg); } } diff --git a/src/USER-DPD/fix_rx.cpp b/src/USER-DPD/fix_rx.cpp index 07e56d9db8..cfa309d053 100644 --- a/src/USER-DPD/fix_rx.cpp +++ b/src/USER-DPD/fix_rx.cpp @@ -124,7 +124,7 @@ FixRX::FixRX(LAMMPS *lmp, int narg, char **arg) : else { std::string errmsg = "Illegal command " + std::string(word) + " expected \"sparse\" or \"dense\"\n"; - error->all(FLERR, errmsg.c_str()); + error->all(FLERR, errmsg); } if (comm->me == 0 and Verbosity > 1){ @@ -134,7 +134,7 @@ FixRX::FixRX(LAMMPS *lmp, int narg, char **arg) : else 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; else { std::string errmsg = "Illegal ODE integration type: " + std::string(word); - error->all(FLERR, errmsg.c_str()); + error->all(FLERR, errmsg); } } diff --git a/src/USER-MISC/pair_mesocnt.cpp b/src/USER-MISC/pair_mesocnt.cpp index 4864dab950..f486814feb 100644 --- a/src/USER-MISC/pair_mesocnt.cpp +++ b/src/USER-MISC/pair_mesocnt.cpp @@ -34,6 +34,7 @@ #include "error.h" #include "update.h" #include "utils.h" +#include "fmt/format.h" #include "math_const.h" #include "math_extra.h" @@ -759,11 +760,9 @@ void PairMesoCNT::read_file() // open file fp = force->open_potential(file); - if (fp == NULL) { - std::string str("Cannot open mesocnt file: "); - str += file; - error->one(FLERR,str.c_str()); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open mesocnt file: {}",file)); + utils::sfgets(FLERR,line,MAXLINE,fp,file,error); // potential parameters @@ -771,18 +770,15 @@ void PairMesoCNT::read_file() utils::sfgets(FLERR,line,MAXLINE,fp,file,error); num = sscanf(line,"%d %d %d %d", &uinf_points,&gamma_points,&phi_points,&usemi_points); - if (num != 4) { - std::string str("Could not correctly parse line 2 in mesocnt file: "); - str += file; - error->one(FLERR,str.c_str()); - } + if (num != 4) + error->one(FLERR,fmt::format("Could not correctly parse line 2 in " + "mesocnt file: {}",file)); + utils::sfgets(FLERR,line,MAXLINE,fp,file,error); num = sscanf(line,"%lg %lg %lg %lg",&r_ang,&sig_ang,&delta1,&delta2); - if (num != 4) { - std::string str("Could not correctly parse line 3 in mesocnt file: "); - str += file; - error->one(FLERR,str.c_str()); - } + if (num != 4) + error->one(FLERR,fmt::format("Could not correctly parse line 3 in " + "mesocnt file: {}",file)); } 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; for (int i = 0; i < ninput; i++) { - if (NULL == fgets(line,MAXLINE,fp)) { - std::string str("Premature end of file in pair table "); - str += file; - error->one(FLERR,str.c_str()); - } + if (NULL == fgets(line,MAXLINE,fp)) + error->one(FLERR,fmt::format("Premature end of file in pair table: {}",file)); + if (i > 0) xtemp = x; if (2 != sscanf(line,"%lg %lg",&x,&data[i])) cerror++; 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 if (cerror) { - char str[128]; - sprintf(str,"%d of %d lines were incomplete\n" - " or could not be parsed completely\n" - " in pair table ",cerror,ninput); - std::string errstr = str; - errstr += file; - error->warning(FLERR,errstr.c_str()); + std::string mesg = fmt::format("{} of {} lines were incomplete or could " + "or could not be parsed completely in " + " pair table: {}",cerror,ninput,file); + error->warning(FLERR,mesg); } // warn if spacing between data points is not constant if (serror) { - char str[128]; - sprintf(str,"%d spacings in first column were different\n" - " from first spacing in pair table ",serror); - std::string errstr = str; - errstr += file; - error->warning(FLERR,errstr.c_str()); + std::string mesg = fmt::format("{} spacings in first column were different " + " from first spacing in pair table: {}",serror,file); + error->warning(FLERR,mesg); } } @@ -911,11 +899,9 @@ void PairMesoCNT::read_data(FILE *fp, double **data, for (int i = 0; i < ninput; i++) { if (i > 0) xtemp = x; for (int j = 0; j < ninput; j++) { - if (NULL == fgets(line,MAXLINE,fp)) { - std::string str("Premature end of file in pair table "); - str += file; - error->one(FLERR,str.c_str()); - } + if (NULL == fgets(line,MAXLINE,fp)) + error->one(FLERR,fmt::format("Premature end of file in pair table: {}",file)); + if (j > 0) ytemp = y; if (3 != sscanf(line,"%lg %lg %lg",&x,&y,&data[i][j])) cerror++; 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 - if (cerror) { - char str[128]; - sprintf(str,"%d of %d lines were incomplete\n" - " or could not be parsed completely\n" - " in pair table ",cerror,ninput*ninput); - std::string errstr = str; - errstr += file; - error->warning(FLERR,errstr.c_str()); - } + if (cerror) + error->warning(FLERR,fmt::format("{} of {} lines were incomplete or could " + "not be parsed completely in pair table: {}", + cerror,ninput*ninput,file)); // warn if spacing between data points is not constant - if (sxerror) { - char str[128]; - sprintf(str,"%d spacings in first column were different\n" - " from first spacing in pair table ",sxerror); - std::string errstr = str; - errstr += file; - error->warning(FLERR,errstr.c_str()); - } - 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()); - } + if (sxerror) + error->warning(FLERR,fmt::format("{} spacings in first column were different " + " from first spacing in pair table: {}", + sxerror,file)); + if (syerror) + error->warning(FLERR,fmt::format("{} spacings in second column were different " + " from first spacing in pair table: {}", + syerror,file)); } /* ---------------------------------------------------------------------- diff --git a/src/atom.cpp b/src/atom.cpp index 134def74a3..23d196a574 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -761,7 +761,7 @@ AtomVec *Atom::new_avec(const char *style, int trysuffix, int &sflag) 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; } diff --git a/src/domain.cpp b/src/domain.cpp index e1a9744fde..2a8bc18eb1 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -157,7 +157,7 @@ void Domain::init() std::string mesg = "Must not have multiple fixes change box parameter "; #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(y); @@ -1788,7 +1788,7 @@ void Domain::add_region(int narg, char **arg) if (region_map->find(arg[1]) != region_map->end()) { RegionCreator region_creator = (*region_map)[arg[1]]; 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() // in case region is used between runs, e.g. to print a variable diff --git a/src/force.cpp b/src/force.cpp index eb288e59b4..c5b691dced 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -284,7 +284,7 @@ Pair *Force::new_pair(const char *style, int trysuffix, int &sflag) 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; } @@ -397,7 +397,7 @@ Bond *Force::new_bond(const char *style, int trysuffix, int &sflag) 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; } @@ -476,7 +476,7 @@ Angle *Force::new_angle(const char *style, int trysuffix, int &sflag) 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; } @@ -556,7 +556,7 @@ Dihedral *Force::new_dihedral(const char *style, int trysuffix, int &sflag) 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; } @@ -635,7 +635,7 @@ Improper *Force::new_improper(const char *style, int trysuffix, int &sflag) 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; } @@ -718,7 +718,7 @@ KSpace *Force::new_kspace(const char *style, int trysuffix, int &sflag) 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; } @@ -947,9 +947,8 @@ double Force::numeric(const char *file, int line, char *str) if (isdigit(str[i])) continue; if (str[i] == '-' || str[i] == '+' || str[i] == '.') continue; if (str[i] == 'e' || str[i] == 'E') continue; - std::string msg = fmt::format("Expected floating point parameter " - "instead of '{}' in input script or data file",str); - error->all(file,line,msg.c_str()); + error->all(file,line,fmt::format("Expected floating point parameter " + "instead of '{}' in input script or data file",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++) { if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue; - std::string msg = fmt::format("Expected integer parameter instead " - "of '{}' in input script or data file",str); - error->all(file,line,msg.c_str()); + error->all(file,line,fmt::format("Expected integer parameter instead " + "of '{}' in input script or data file",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++) { if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue; - std::string msg = fmt::format("Expected integer parameter instead " - "of '{}' in input script or data file",str); - error->all(file,line,msg.c_str()); + error->all(file,line,fmt::format("Expected integer parameter instead " + "of '{}' in input script or data file",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++) { if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue; - std::string msg = fmt::format("Expected integer parameter instead " - "of '{}' in input script or data file",str); - error->all(file,line,msg.c_str()); + error->all(file,line,fmt::format("Expected integer parameter instead " + "of '{}' in input script or data file",str)); } return ATOTAGINT(str); diff --git a/src/input.cpp b/src/input.cpp index cc7f036042..050b8112a9 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -302,7 +302,7 @@ char *Input::one(const std::string &single) // execute the command and return its name if (execute_command()) - error->all(FLERR,fmt::format("Unknown command: {}",line).c_str()); + error->all(FLERR,fmt::format("Unknown command: {}",line)); return command; } diff --git a/src/lammps.cpp b/src/lammps.cpp index 2768d9bfb6..f2edaef2a4 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -500,10 +500,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : } infile = fopen(arg[inflag],"r"); - if (infile == NULL) { - str = fmt::format("Cannot open input script {}",arg[inflag]); - error->one(FLERR,str.c_str()); - } + if (infile == NULL) + error->one(FLERR,fmt::format("Cannot open input script {}",arg[inflag])); } // screen and logfile messages for universe and world @@ -614,13 +612,13 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : if (restart2data || restart2dump) { std::string cmd = fmt::format("read_restart {}",restartfile); if (restartremap) cmd += " remap\n"; - input->one(cmd.c_str()); + input->one(cmd); if (restart2data) cmd = "write_data "; else cmd = "write_dump"; for (iarg = wfirst; iarg < wlast; iarg++) cmd += fmt::format(" {}", arg[iarg]); if (restart2data) cmd += " noinit"; - input->one(cmd.c_str()); + input->one(cmd); error->done(0); } } diff --git a/src/modify.cpp b/src/modify.cpp index edbcd05b45..b230cabc17 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -904,7 +904,7 @@ void Modify::add_fix(int narg, char **arg, int trysuffix) } 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 // 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) - 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++; } diff --git a/src/output.cpp b/src/output.cpp index 193db9ae2a..0ad98b5381 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -584,7 +584,7 @@ void Output::add_dump(int narg, char **arg) if (dump_map->find(arg[2]) != dump_map->end()) { DumpCreator dump_creator = (*dump_map)[arg[2]]; 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]); if (every_dump[ndump] <= 0) error->all(FLERR,"Illegal dump command"); diff --git a/src/read_dump.cpp b/src/read_dump.cpp index 816a202b9d..e91122f037 100644 --- a/src/read_dump.cpp +++ b/src/read_dump.cpp @@ -263,7 +263,7 @@ void ReadDump::setup_reader(int narg, char **arg) // 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")) { // everyone is a reader with adios diff --git a/src/variable.cpp b/src/variable.cpp index 34258522c4..fb6d2da8cc 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -41,6 +41,7 @@ #include "info.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -1336,7 +1337,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) std::string mesg = "Invalid compute ID '"; mesg += (word+2); mesg += "' in variable formula"; - print_var_error(FLERR,mesg.c_str(),ivar); + print_var_error(FLERR,mesg,ivar); } Compute *compute = modify->compute[icompute]; @@ -1641,7 +1642,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) std::string mesg = "Invalid fix ID '"; mesg += (word+2); mesg += "' in variable formula"; - print_var_error(FLERR,mesg.c_str(),ivar); + print_var_error(FLERR,mesg,ivar); } Fix *fix = modify->fix[ifix]; @@ -3831,7 +3832,7 @@ int Variable::group_function(char *word, char *contents, Tree **tree, std::string mesg = "Group ID '"; mesg += args[0]; 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 @@ -4044,7 +4045,7 @@ int Variable::region_function(char *id, int ivar) std::string mesg = "Region ID '"; mesg += id; 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 @@ -4126,7 +4127,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree, std::string mesg = "Invalid compute ID '"; mesg += (args[0]+2); mesg += "' in variable formula"; - print_var_error(FLERR,mesg.c_str(),ivar); + print_var_error(FLERR,mesg,ivar); } compute = modify->compute[icompute]; 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 '"; mesg += (args[0]+2); mesg += "' in variable formula"; - print_var_error(FLERR,mesg.c_str(),ivar); + print_var_error(FLERR,mesg,ivar); } fix = modify->fix[ifix]; 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 '"; mesg += (args[0]+2); 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; nstride = 1; @@ -4391,7 +4392,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree, std::string mesg = "Variable ID '"; mesg += args[0]; 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 @@ -4772,13 +4773,11 @@ char *Variable::find_next_comma(char *str) helper routine for printing variable name with error message ------------------------------------------------------------------------- */ -void Variable::print_var_error(const char *srcfile, int lineno, - const char *errmsg, int ivar, int global) +void Variable::print_var_error(const std::string &srcfile, const int lineno, + const std::string &errmsg, int ivar, int global) { if ((ivar >= 0) && (ivar < nvar)) { - char msg[128]; - - snprintf(msg,128,"Variable %s: %s",names[ivar],errmsg); + std::string msg = fmt::format("Variable {}: ",names[ivar]) + errmsg; if (global) error->all(srcfile,lineno,msg); else diff --git a/src/variable.h b/src/variable.h index a504da14ec..2d0a1e23a3 100644 --- a/src/variable.h +++ b/src/variable.h @@ -15,6 +15,7 @@ #define LMP_VARIABLE_H #include "pointers.h" +#include namespace LAMMPS_NS { @@ -123,7 +124,8 @@ class Variable : protected Pointers { double constant(char *); int parse_args(char *, 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); }; diff --git a/src/write_dump.cpp b/src/write_dump.cpp index 31ceb4cbbf..9b257b9ab0 100644 --- a/src/write_dump.cpp +++ b/src/write_dump.cpp @@ -63,7 +63,7 @@ void WriteDump::command(int narg, char **arg) #include "style_dump.h" #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]);