Hey,
it is possible to do
"compute ${omeg} all reduce ave c_atomprops[1]
compute ${vy} all reduce ave c_atomprops[2]
variable a string c_${omeg}
variable b string c_${vy}"
and also it is possible to give a string to the next:
"variable allresult string ${a}"
but why is it not possible to create a string out of two or more strings?
"variable allresult string ${a} ${b}"
doing so yields the following error:
ERROR: Illegal variable command (../variable.cpp:278)
in the cpp it is written:
if (narg != 3) error->all(FLERR,"Illegal variable command");
so what is the problem if narg is not equal 3?
how can I best deal with that?
Thanks
JoshuaP | Thu, 11/13/2014 - 17:24
Solved
I can use universe instead of string
richti83 | Thu, 11/13/2014 - 19:18
This is a limitation of LAMMPS
I have a hack for this problem:
in variable.cpp somewhere arround line 272 (must not exactly match)
// STRING
// remove pre-existing var if also style STRING (allows it to be reset)
// num = 1, which = 1st value
// data = 1 value, string to eval
} else if (strcmp(arg[1],"string") == 0) {
if (narg < 3) {printf("narg=%d",narg);error->all(FLERR,"Illegal variable command");}
if (find(arg[0]) >= 0) {
if (style[find(arg[0])] != STRING)
error->all(FLERR,"Cannot redefine variable as a different style");
remove(find(arg[0]));
}
if (nvar == maxvar) grow();
style[nvar] = STRING;
num[nvar] = 1;
which[nvar] = 0;
pad[nvar] = 0;
data[nvar] = new char*[num[nvar]];
if (narg==3) {
int n=strlen(arg[2])+1;
data[nvar][0]=new char[n];
strcpy(data[nvar][0],arg[2]);
} else if (narg>=4) {
int n=strlen(arg[2])+1; //preserve one for \0
for (int i=3;i<narg;i++)
n+=strlen(arg[i])+1; //preserve one for each space
data[nvar][0]=new char[n];
strcpy(data[nvar][0],arg[2]);
for (int i=3;i < narg;i++) {
strcat(data[nvar][0]," "); //space between the arguments
strcat(data[nvar][0],arg[i]);
}
}
// GETENV
This add a string concatination function to variable string with a whitespace between the arguments.
Best,
Christian.
JoshuaP | Fri, 11/14/2014 - 10:14
Many thanks
that is exactly what I'm looking for! You helped me a lot.
Now I can create a long string with whitespaces in between and use this string for setting up the variablenames for the output.
Thanks