Hello,
For common tasks, I tend to write generic input scripts, which
requires frequent use of "if". Multi-line "if" statements can be ugly,
but one learns to cope.
Recently, however, the command string I wanted to conditionally
execute required quotes. But the "if" statement requires the command
string to be in quotes. To the best of my knowledge and brief
experimentation, LAMMPS doesn't handle nested quotes.
To get around this, I conceptually replaced 'if condition then "do
this" "and this"' with 'if not-condition then "jump
over-these-things"'.
Workable... except "jump" requires a script name and my generic
scripts don't generally know their final names, plus stdin redirection
(i.e. '<') would never work.
By specifying a file name of "NULL", the one-line change to
"input.cpp" shown below allows "jump" to jump ahead to a label in the
current script without closing and subsequently reopening the script
file. (Disclaimer: I'm not aware of any side-effects, but...) This
solves the limitations described above. For me the desired usage looks
like:
if not-condition then "jump NULL not_today"
...
(assorted lammps commands, maybe with "quotes")
...
label not_today
As an added bonus, the enclosed command block is easier to write,
read, and debug.
Regards,
Craig
--- make/lammps-23Sep10/src/input.cpp 2010-09-08 20:01:34.000000000 -0400
+++ dev/input.cpp 2010-09-21 22:58:07.000000000 -0400
@@ -619,13 +619,13 @@
if (jump_skip) {
jump_skip = 0;
return;
}
- if (me == 0) {
+ if (me == 0 && strcmp(arg[0],"NULL")) {
if (infile != stdin) fclose(infile);
infile = fopen(arg[0],"r");
if (infile == NULL) {
char str[128];
sprintf(str,"Cannot open input script %s",arg[0]);
error->one(str);