forked from lijiext/lammps
better error messages on accessing invalid IDs in variable expressions
This commit is contained in:
parent
25b504d4fd
commit
21f3f51ea2
|
@ -18,6 +18,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string>
|
||||||
#include "universe.h"
|
#include "universe.h"
|
||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
@ -1302,8 +1303,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
||||||
if (word[0] == 'C') lowercase = 0;
|
if (word[0] == 'C') lowercase = 0;
|
||||||
|
|
||||||
int icompute = modify->find_compute(word+2);
|
int icompute = modify->find_compute(word+2);
|
||||||
if (icompute < 0)
|
if (icompute < 0) {
|
||||||
print_var_error(FLERR,"Invalid compute ID in variable formula",ivar);
|
std::string mesg = "Invalid compute ID '";
|
||||||
|
mesg += (word+2);
|
||||||
|
mesg += "' in variable formula";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
|
}
|
||||||
Compute *compute = modify->compute[icompute];
|
Compute *compute = modify->compute[icompute];
|
||||||
|
|
||||||
// parse zero or one or two trailing brackets
|
// parse zero or one or two trailing brackets
|
||||||
|
@ -1604,9 +1609,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
||||||
|
|
||||||
int ifix = modify->find_fix(word+2);
|
int ifix = modify->find_fix(word+2);
|
||||||
if (ifix < 0) {
|
if (ifix < 0) {
|
||||||
char msg[128];
|
std::string mesg = "Invalid fix ID '";
|
||||||
snprintf(msg,128,"Invalid fix ID '%s' in variable formula",word+2);
|
mesg += (word+2);
|
||||||
print_var_error(FLERR,msg,ivar);
|
mesg += "' in variable formula";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
}
|
}
|
||||||
Fix *fix = modify->fix[ifix];
|
Fix *fix = modify->fix[ifix];
|
||||||
|
|
||||||
|
@ -3792,8 +3798,12 @@ int Variable::group_function(char *word, char *contents, Tree **tree,
|
||||||
// group to operate on
|
// group to operate on
|
||||||
|
|
||||||
int igroup = group->find(args[0]);
|
int igroup = group->find(args[0]);
|
||||||
if (igroup == -1)
|
if (igroup == -1) {
|
||||||
print_var_error(FLERR,"Group ID in variable formula does not exist",ivar);
|
std::string mesg = "Group ID '";
|
||||||
|
mesg += args[0];
|
||||||
|
mesg += "' in variable formula does not exist";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
|
}
|
||||||
|
|
||||||
// match word to group function
|
// match word to group function
|
||||||
|
|
||||||
|
@ -4001,8 +4011,12 @@ int Variable::group_function(char *word, char *contents, Tree **tree,
|
||||||
int Variable::region_function(char *id, int ivar)
|
int Variable::region_function(char *id, int ivar)
|
||||||
{
|
{
|
||||||
int iregion = domain->find_region(id);
|
int iregion = domain->find_region(id);
|
||||||
if (iregion == -1)
|
if (iregion == -1) {
|
||||||
print_var_error(FLERR,"Region ID in variable formula does not exist",ivar);
|
std::string mesg = "Region ID '";
|
||||||
|
mesg += id;
|
||||||
|
mesg += "' in variable formula does not exist";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
|
}
|
||||||
|
|
||||||
// init region in case sub-regions have been deleted
|
// init region in case sub-regions have been deleted
|
||||||
|
|
||||||
|
@ -4080,9 +4094,10 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
|
||||||
|
|
||||||
int icompute = modify->find_compute(&args[0][2]);
|
int icompute = modify->find_compute(&args[0][2]);
|
||||||
if (icompute < 0) {
|
if (icompute < 0) {
|
||||||
char msg[128];
|
std::string mesg = "Invalid compute ID '";
|
||||||
snprintf(msg,128,"Invalid compute ID '%s' in variable formula",word+2);
|
mesg += (args[0]+2);
|
||||||
print_var_error(FLERR,msg,ivar);
|
mesg += "' in variable formula";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
}
|
}
|
||||||
compute = modify->compute[icompute];
|
compute = modify->compute[icompute];
|
||||||
if (index == 0 && compute->vector_flag) {
|
if (index == 0 && compute->vector_flag) {
|
||||||
|
@ -4123,13 +4138,20 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
|
||||||
} else index = 0;
|
} else index = 0;
|
||||||
|
|
||||||
int ifix = modify->find_fix(&args[0][2]);
|
int ifix = modify->find_fix(&args[0][2]);
|
||||||
if (ifix < 0)
|
if (ifix < 0) {
|
||||||
print_var_error(FLERR,"Invalid fix ID in variable formula",ivar);
|
std::string mesg = "Invalid fix ID '";
|
||||||
|
mesg += (args[0]+2);
|
||||||
|
mesg += "' in variable formula";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
|
}
|
||||||
fix = modify->fix[ifix];
|
fix = modify->fix[ifix];
|
||||||
if (index == 0 && fix->vector_flag) {
|
if (index == 0 && fix->vector_flag) {
|
||||||
if (update->whichflag > 0 && update->ntimestep % fix->global_freq)
|
if (update->whichflag > 0 && update->ntimestep % fix->global_freq) {
|
||||||
print_var_error(FLERR,"Fix in variable not computed at "
|
std::string mesg = "Fix with ID '";
|
||||||
"compatible time",ivar);
|
mesg += (args[0]+2);
|
||||||
|
mesg += "' in variable formula not computed at compatible time";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
|
}
|
||||||
nvec = fix->size_vector;
|
nvec = fix->size_vector;
|
||||||
nstride = 1;
|
nstride = 1;
|
||||||
} else if (index && fix->array_flag) {
|
} else if (index && fix->array_flag) {
|
||||||
|
@ -4336,9 +4358,12 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
|
||||||
print_var_error(FLERR,"Invalid special function in variable formula",ivar);
|
print_var_error(FLERR,"Invalid special function in variable formula",ivar);
|
||||||
|
|
||||||
int ivar = find(args[0]);
|
int ivar = find(args[0]);
|
||||||
if (ivar < 0)
|
if (ivar < 0) {
|
||||||
print_var_error(FLERR,"Variable ID in "
|
std::string mesg = "Variable ID '";
|
||||||
"variable formula does not exist",ivar);
|
mesg += args[0];
|
||||||
|
mesg += "' in variable formula does not exist";
|
||||||
|
print_var_error(FLERR,mesg.c_str(),ivar);
|
||||||
|
}
|
||||||
|
|
||||||
// SCALARFILE has single current value, read next one
|
// SCALARFILE has single current value, read next one
|
||||||
// save value in tree or on argstack
|
// save value in tree or on argstack
|
||||||
|
|
Loading…
Reference in New Issue