Commit 90e125a7 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

make error message for input parameter type mismatch more specific to show what is incorrect

parent 34e0c05b
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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
+36 −32
Original line number Diff line number Diff line
@@ -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);