diff --git a/src/input.cpp b/src/input.cpp index a4cc435953..5e5f1d89c9 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -72,6 +72,7 @@ Input::Input(LAMMPS *lmp, int argc, char **argv) : Pointers(lmp) label_active = 0; labelstr = NULL; jump_skip = 0; + ifthenelse_flag = 0; if (me == 0) { nfile = maxfile = 1; @@ -682,7 +683,9 @@ void Input::ifthenelse() ncommands++; } + ifthenelse_flag = 1; for (int i = 0; i < ncommands; i++) one(commands[i]); + ifthenelse_flag = 0; for (int i = 0; i < ncommands; i++) delete [] commands[i]; delete [] commands; @@ -736,7 +739,9 @@ void Input::ifthenelse() // execute the list of commands + ifthenelse_flag = 1; for (int i = 0; i < ncommands; i++) one(commands[i]); + ifthenelse_flag = 0; // clean up @@ -753,6 +758,13 @@ void Input::include() { if (narg != 1) error->all(FLERR,"Illegal include command"); + // do not allow include inside an if command + // NOTE: this check will fail if a 2nd if command was inside the if command + // and came before the include + + if (ifthenelse_flag) + error->all(FLERR,"Cannot use include command within an if command"); + if (me == 0) { if (nfile == maxfile) { maxfile++; diff --git a/src/input.h b/src/input.h index ca59734e3c..0699cee5d3 100644 --- a/src/input.h +++ b/src/input.h @@ -45,6 +45,7 @@ class Input : protected Pointers { int label_active; // 0 = no label, 1 = looking for label char *labelstr; // label string being looked for int jump_skip; // 1 if skipping next jump, 0 otherwise + int ifthenelse_flag; // 1 if executing commands inside an if-then-else FILE **infiles; // list of open input files