Error when passing negative values through command line

We have a number of LAMMPS scripts where we pass variable values through the command line, i.e.,

lammps_executable -var xposition -10 < lammps_input_file

In the newer version (September 2011), we noticed that we are now getting an error when we try to do this. Is this a bug? Has this been intentionally done for some reason? If it is not intentional, is there a way to correct this either in future versions or for individual users to modify LAMMPS to allow this? I wasn’t quite sure when this problem arose, since we haven’t updated our LAMMPS version in a while.

Thank you for your time,
Mark

mtschopp@…1024…

We have a number of LAMMPS scripts where we pass variable values through the
command line, i.e.,

lammps_executable -var xposition -10 < lammps_input_file

In the newer version (September 2011), we noticed that we are now getting an
error when we try to do this. Is this a bug? Has this been intentionally

yes. this is a bug.

done for some reason? If it is not intentional, is there a way to correct
this either in future versions or for individual users to modify LAMMPS to

the modification is trivial and fairly obvious.
you need to change the iarg += 2; in line 108 of lammps.cpp
into an iarg += 3; as shown in the patch file below.

allow this? I wasn't quite sure when this problem arose, since we haven't
updated our LAMMPS version in a while.

according to git blame, the change goes back to february 2011.
looks like there are not many people assigning negative values
to variables that also use an up-to-date lammps binary. :wink:

cheers,
    axel.

diff --git a/src/lammps.cpp b/src/lammps.cpp
index 09b6a48..2aaf0ea 100644
--- a/src/lammps.cpp
+++ b/src/lammps.cpp
@@ -105,7 +105,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
     } else if (strcmp(arg[iarg],"-var") == 0 ||
               strcmp(arg[iarg],"-v") == 0) {
       if (iarg+3 > narg) error->universe_all(FLERR,"Invalid
command-line argument");
- iarg += 2;
+ iarg += 3;
       while (iarg < narg && arg[iarg][0] != '-') iarg++;
     } else if (strcmp(arg[iarg],"-echo") == 0 ||
               strcmp(arg[iarg],"-e") == 0) {

I'll post a patch for this today. There is a similar change needed
in input.cpp. This still won't work if there are multiple args to
the -var, each with a leading "-" sign. Probably need to make
the syntax require one arg enclosed in quotes.

Steve