diff --git a/src/variable.cpp b/src/variable.cpp index 01653ef670..061c302d8b 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -540,6 +540,22 @@ void Variable::set(int narg, char **arg) nvar++; } +/* ---------------------------------------------------------------------- + convenience function to allow defining a variable from a single string +------------------------------------------------------------------------- */ + +void Variable::set(const std::string &setcmd) +{ + std::vector args = utils::split_words(setcmd); + char **newarg = new char*[args.size()]; + int i=0; + for (const auto &arg : args) { + newarg[i++] = (char *)arg.c_str(); + } + set(args.size(),newarg); + delete[] newarg; +} + /* ---------------------------------------------------------------------- INDEX variable created by command-line argument make it INDEX rather than STRING so cannot be re-defined in input script diff --git a/src/variable.h b/src/variable.h index fbeff40ac1..066372648f 100644 --- a/src/variable.h +++ b/src/variable.h @@ -24,6 +24,7 @@ class Variable : protected Pointers { public: Variable(class LAMMPS *); ~Variable(); + void set(const std::string &); void set(int, char **); void set(char *, int, char **); int set_string(char *, char *);