diff --git a/doc/src/Errors_common.txt b/doc/src/Errors_common.txt index 651040ebc9..da90aad64b 100644 --- a/doc/src/Errors_common.txt +++ b/doc/src/Errors_common.txt @@ -74,7 +74,7 @@ is an integer or floating-point number, respectively, and reject the input with an error message (for instance, when an integer is required, but a floating-point number 1.0 is provided): -ERROR: Expected integer parameter in input script or data file :pre +ERROR: Expected integer parameter instead of '1.0' in input script or data file :pre Some commands allow for using variable references in place of numeric constants so that the value can be evaluated and may change over the @@ -85,6 +85,9 @@ reading the input and before parsing commands, NOTE: Using a variable reference (i.e. {v_name}) is only allowed if the documentation of the corresponding command explicitly says it is. +Otherwise, you will receive an error message of this kind: + +ERROR: Expected floating point parameter instead of 'v_name' in input script or data file :pre Generally, LAMMPS will print a message to the screen and logfile and exit gracefully when it encounters a fatal error. Sometimes it will diff --git a/src/force.cpp b/src/force.cpp index 2bfd809451..567cf2c9c5 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -934,20 +934,21 @@ void Force::boundsbig(const char *file, int line, char *str, double Force::numeric(const char *file, int line, char *str) { - if (!str) - error->all(file,line,"Expected floating point parameter " - "in input script or data file"); - int n = strlen(str); + int n = 0; + + if (str) n = strlen(str); if (n == 0) - error->all(file,line,"Expected floating point parameter " - "in input script or data file"); + 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; - error->all(file,line,"Expected floating point parameter " - "in input script or data file"); + char msg[256]; + snprintf(msg,256,"Expected floating point parameter instead of " + "'%s' in input script or data file",str); + error->all(file,line,msg); } return atof(str); @@ -961,18 +962,19 @@ double Force::numeric(const char *file, int line, char *str) int Force::inumeric(const char *file, int line, char *str) { - if (!str) - error->all(file,line, - "Expected integer parameter in input script or data file"); - int n = strlen(str); + int n = 0; + + if (str) n = strlen(str); if (n == 0) - error->all(file,line, - "Expected integer parameter in input script or data file"); + 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; - error->all(file,line, - "Expected integer parameter in input script or data file"); + char msg[256]; + snprintf(msg,256,"Expected integer parameter instead of " + "'%s' in input script or data file",str); + error->all(file,line,msg); } return atoi(str); @@ -986,18 +988,19 @@ int Force::inumeric(const char *file, int line, char *str) bigint Force::bnumeric(const char *file, int line, char *str) { - if (!str) - error->all(file,line, - "Expected integer parameter in input script or data file"); - int n = strlen(str); + int n = 0; + + if (str) n = strlen(str); if (n == 0) - error->all(file,line, - "Expected integer parameter in input script or data file"); + 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; - error->all(file,line, - "Expected integer parameter in input script or data file"); + char msg[256]; + snprintf(msg,256,"Expected integer parameter instead of " + "'%s' in input script or data file",str); + error->all(file,line,msg); } return ATOBIGINT(str); @@ -1011,18 +1014,19 @@ bigint Force::bnumeric(const char *file, int line, char *str) tagint Force::tnumeric(const char *file, int line, char *str) { - if (!str) - error->all(file,line, - "Expected integer parameter in input script or data file"); - int n = strlen(str); + int n = 0; + + if (str) n = strlen(str); if (n == 0) - error->all(file,line, - "Expected integer parameter in input script or data file"); + 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; - error->all(file,line, - "Expected integer parameter in input script or data file"); + char msg[256]; + snprintf(msg,256,"Expected integer parameter instead of " + "'%s' in input script or data file",str); + error->all(file,line,msg); } return ATOTAGINT(str);