Merge branch 'master' into improve-include-consistency
# Conflicts: # src/USER-MESO/atom_vec_tdpd.cpp
This commit is contained in:
144
src/utils.cpp
144
src/utils.cpp
@ -140,6 +140,150 @@ std::string utils::check_packages_for_style(std::string style,
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
read a floating point value from a string
|
||||
generate an error if not a legitimate floating point value
|
||||
called by various commands to check validity of their arguments
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double utils::numeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (str) n = strlen(str);
|
||||
if (n == 0) {
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,"Expected floating point parameter instead of"
|
||||
" NULL or empty string in input script or data file");
|
||||
else
|
||||
lmp->error->all(file,line,"Expected floating point parameter instead of"
|
||||
" NULL or empty string in input script or data file");
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (isdigit(str[i])) continue;
|
||||
if (str[i] == '-' || str[i] == '+' || str[i] == '.') continue;
|
||||
if (str[i] == 'e' || str[i] == 'E') continue;
|
||||
std::string msg("Expected floating point parameter instead of '");
|
||||
msg += str;
|
||||
msg += "' in input script or data file";
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,msg.c_str());
|
||||
else
|
||||
lmp->error->all(file,line,msg.c_str());
|
||||
}
|
||||
|
||||
return atof(str);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
read an integer value from a string
|
||||
generate an error if not a legitimate integer value
|
||||
called by various commands to check validity of their arguments
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int utils::inumeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (str) n = strlen(str);
|
||||
if (n == 0) {
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,"Expected integer parameter instead of "
|
||||
"NULL or empty string in input script or data file");
|
||||
else
|
||||
lmp->error->all(file,line,"Expected integer parameter instead of "
|
||||
"NULL or empty string in input script or data file");
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
|
||||
std::string msg("Expected integer parameter instead of '");
|
||||
msg += str;
|
||||
msg += "' in input script or data file";
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,msg.c_str());
|
||||
else
|
||||
lmp->error->all(file,line,msg.c_str());
|
||||
}
|
||||
|
||||
return atoi(str);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
read a big integer value from a string
|
||||
generate an error if not a legitimate integer value
|
||||
called by various commands to check validity of their arguments
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
bigint utils::bnumeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (str) n = strlen(str);
|
||||
if (n == 0) {
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,"Expected integer parameter instead of "
|
||||
"NULL or empty string in input script or data file");
|
||||
else
|
||||
lmp->error->all(file,line,"Expected integer parameter instead of "
|
||||
"NULL or empty string in input script or data file");
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
|
||||
std::string msg("Expected integer parameter instead of '");
|
||||
msg += str;
|
||||
msg += "' in input script or data file";
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,msg.c_str());
|
||||
else
|
||||
lmp->error->all(file,line,msg.c_str());
|
||||
}
|
||||
|
||||
return ATOBIGINT(str);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
read a tag integer value from a string
|
||||
generate an error if not a legitimate integer value
|
||||
called by various commands to check validity of their arguments
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
tagint utils::tnumeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (str) n = strlen(str);
|
||||
if (n == 0) {
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,"Expected integer parameter instead of "
|
||||
"NULL or empty string in input script or data file");
|
||||
else
|
||||
lmp->error->all(file,line,"Expected integer parameter instead of "
|
||||
"NULL or empty string in input script or data file");
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
|
||||
std::string msg("Expected integer parameter instead of '");
|
||||
msg += str;
|
||||
msg += "' in input script or data file";
|
||||
if (do_abort)
|
||||
lmp->error->one(file,line,msg.c_str());
|
||||
else
|
||||
lmp->error->all(file,line,msg.c_str());
|
||||
}
|
||||
|
||||
return ATOTAGINT(str);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
extern "C" {
|
||||
|
||||
Reference in New Issue
Block a user