update utils::expand_args
This commit is contained in:
@ -543,16 +543,21 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
|||||||
std::string word(arg[iarg]);
|
std::string word(arg[iarg]);
|
||||||
expandflag = 0;
|
expandflag = 0;
|
||||||
|
|
||||||
// only match compute/fix reference with a '*' wildcard
|
// match compute, fix, or custom property array reference with a '*' wildcard
|
||||||
// number range in the first pair of square brackets
|
// number range in the first pair of square brackets
|
||||||
|
|
||||||
if (strmatch(word, "^[cf]_\\w+\\[\\d*\\*\\d*\\]")) {
|
if (strmatch(word, "^[cf]_\\w+\\[\\d*\\*\\d*\\]") ||
|
||||||
|
strmatch(word, "^[id]2_\\w+\\[\\d*\\*\\d*\\]")) {
|
||||||
|
|
||||||
// split off the compute/fix ID, the wildcard and trailing text
|
// split off the compute/fix/property ID, the wildcard and trailing text
|
||||||
|
|
||||||
size_t first = word.find("[");
|
size_t first = word.find("[");
|
||||||
size_t second = word.find("]", first + 1);
|
size_t second = word.find("]", first + 1);
|
||||||
|
if (word[1] == '2')
|
||||||
|
id = word.substr(3, first - 3);
|
||||||
|
else
|
||||||
id = word.substr(2, first - 2);
|
id = word.substr(2, first - 2);
|
||||||
|
|
||||||
wc = word.substr(first + 1, second - first - 1);
|
wc = word.substr(first + 1, second - first - 1);
|
||||||
tail = word.substr(second + 1);
|
tail = word.substr(second + 1);
|
||||||
|
|
||||||
@ -609,59 +614,20 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
|||||||
|
|
||||||
// only match custom array reference with a '*' wildcard
|
// only match custom array reference with a '*' wildcard
|
||||||
// number range in the first pair of square brackets
|
// number range in the first pair of square brackets
|
||||||
// OLDSTYLE code
|
|
||||||
|
|
||||||
if (strncmp(arg[iarg],"i2_",3) == 0 || strncmp(arg[iarg],"d2_",3) == 0) {
|
if ((word[0] == 'i') || (word[0] == 'd')) {
|
||||||
char *ptr1 = strchr(arg[iarg],'[');
|
|
||||||
if (ptr1) {
|
|
||||||
char *ptr2 = strchr(ptr1,']');
|
|
||||||
if (ptr2) {
|
|
||||||
*ptr2 = '\0';
|
|
||||||
if (strchr(ptr1,'*')) {
|
|
||||||
|
|
||||||
if (arg[iarg][0] == 'i') {
|
|
||||||
*ptr1 = '\0';
|
|
||||||
int flag, cols;
|
int flag, cols;
|
||||||
int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols);
|
int icustom = lmp->atom->find_custom(id.c_str(), flag, cols);
|
||||||
*ptr1 = '[';
|
|
||||||
|
|
||||||
// check for custom per-atom integer array
|
if ((icustom >= 0) && (mode == 1) && (cols > 0)) {
|
||||||
|
|
||||||
if (icustom >= 0) {
|
// check for custom per-atom array
|
||||||
if (mode == 1 && !flag && cols) {
|
|
||||||
|
if (((word[0] == 'i') && (flag == 0)) || ((word[0] == 'i') && (flag == 1))) {
|
||||||
nmax = cols;
|
nmax = cols;
|
||||||
expandflag = 1;
|
expandflag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (arg[iarg][0] == 'd') {
|
|
||||||
*ptr1 = '\0';
|
|
||||||
int flag,cols;
|
|
||||||
int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols);
|
|
||||||
*ptr1 = '[';
|
|
||||||
|
|
||||||
// check for custom per-atom floating point array
|
|
||||||
|
|
||||||
if (icustom >= 0) {
|
|
||||||
if (mode == 1 && flag && cols) {
|
|
||||||
nmax = cols;
|
|
||||||
expandflag = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// split off the array name ID, the wildcard and trailing text
|
|
||||||
|
|
||||||
if (expandflag) {
|
|
||||||
size_t first = word.find("[");
|
|
||||||
size_t second = word.find("]", first + 1);
|
|
||||||
id = word.substr(2, first - 2);
|
|
||||||
wc = word.substr(first + 1, second - first - 1);
|
|
||||||
tail = word.substr(second + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// expansion will take place
|
// expansion will take place
|
||||||
@ -678,6 +644,9 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
|||||||
|
|
||||||
for (int index = nlo; index <= nhi; index++) {
|
for (int index = nlo; index <= nhi; index++) {
|
||||||
// assemble and duplicate expanded string
|
// assemble and duplicate expanded string
|
||||||
|
if (word[1] == '2')
|
||||||
|
earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail));
|
||||||
|
else
|
||||||
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
|
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
|
||||||
newarg++;
|
newarg++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user