Merge branch 'fix-property-array' of github.com:lammps/lammps into fix-property-array

This commit is contained in:
Steve Plimpton
2021-08-18 16:54:02 -06:00
18 changed files with 432 additions and 567 deletions

View File

@ -214,7 +214,7 @@ char *utils::fgets_trunc(char *buf, int size, FILE *fp)
void utils::sfgets(const char *srcname, int srcline, char *s, int size, FILE *fp,
const char *filename, Error *error)
{
constexpr int MAXPATHLENBUF=1024;
constexpr int MAXPATHLENBUF = 1024;
char *rv = fgets(s, size, fp);
if (rv == nullptr) { // something went wrong
char buf[MAXPATHLENBUF];
@ -243,7 +243,7 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size, FILE *fp
void utils::sfread(const char *srcname, int srcline, void *s, size_t size, size_t num, FILE *fp,
const char *filename, Error *error)
{
constexpr int MAXPATHLENBUF=1024;
constexpr int MAXPATHLENBUF = 1024;
size_t rv = fread(s, size, num, fp);
if (rv != num) { // something went wrong
char buf[MAXPATHLENBUF];
@ -543,16 +543,21 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
std::string word(arg[iarg]);
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
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 second = word.find("]", first + 1);
id = word.substr(2, first - 2);
if (word[1] == '2')
id = word.substr(3, first - 3);
else
id = word.substr(2, first - 2);
wc = word.substr(first + 1, second - first - 1);
tail = word.substr(second + 1);
@ -580,7 +585,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
}
}
// fix
// fix
} else if (word[0] == 'f') {
int ifix = lmp->modify->find_fix(id);
@ -604,92 +609,54 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
expandflag = 1;
}
}
}
}
// only match custom array reference with a '*' wildcard
// number range in the first pair of square brackets
// OLDSTYLE code
// only match custom array reference with a '*' wildcard
// number range in the first pair of square brackets
if (strncmp(arg[iarg],"i2_",3) == 0 || strncmp(arg[iarg],"d2_",3) == 0) {
char *ptr1 = strchr(arg[iarg],'[');
if (ptr1) {
char *ptr2 = strchr(ptr1,']');
if (ptr2) {
*ptr2 = '\0';
if (strchr(ptr1,'*')) {
} else if ((word[0] == 'i') || (word[0] == 'd')) {
int flag, cols;
int icustom = lmp->atom->find_custom(id.c_str(), flag, cols);
if (arg[iarg][0] == 'i') {
*ptr1 = '\0';
int flag,cols;
int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols);
*ptr1 = '[';
if ((icustom >= 0) && (mode == 1) && (cols > 0)) {
// check for custom per-atom integer array
// check for custom per-atom array
if (icustom >= 0) {
if (mode == 1 && !flag && cols) {
nmax = cols;
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;
}
}
}
if (((word[0] == 'i') && (flag == 0)) || ((word[0] == 'd') && (flag == 1))) {
nmax = cols;
expandflag = 1;
}
}
}
// split off the array name ID, the wildcard and trailing text
// expansion will take place
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
// expand wild card string to nlo/nhi numbers
utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error);
if (expandflag) {
if (newarg + nhi - nlo + 1 > maxarg) {
maxarg += nhi - nlo + 1;
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
}
// expand wild card string to nlo/nhi numbers
utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error);
if (newarg + nhi - nlo + 1 > maxarg) {
maxarg += nhi - nlo + 1;
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
}
for (int index = nlo; index <= nhi; index++) {
// assemble and duplicate expanded string
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
for (int index = nlo; index <= nhi; index++) {
// 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));
newarg++;
}
} else {
// no expansion: duplicate original string
if (newarg == maxarg) {
maxarg++;
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
}
earg[newarg] = utils::strdup(word);
newarg++;
}
} else {
// no expansion: duplicate original string
if (newarg == maxarg) {
maxarg++;
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
}
earg[newarg] = utils::strdup(word);
newarg++;
}
}