pointer and style issues
This commit is contained in:
@ -662,16 +662,17 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
|
||||
/* ----------------------------------------------------------------------
|
||||
substitute type labels with numeric value
|
||||
reallocate str to hold expanded version if necessary
|
||||
if type is a valid numerical string (can include *), do not modify
|
||||
return flag if new pointer, caller will need to delete []
|
||||
if type is a valid numerical string (can include '*'), do not modify
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Input::readtype(char *&str, int mode)
|
||||
int Input::readtype(char *&str, int mode)
|
||||
{
|
||||
int numflag = 1;
|
||||
int n = strlen(str);
|
||||
for (int i = 0; i < n; i++)
|
||||
if (!isdigit(str[i]) && str[i] != '*') numflag = 0;
|
||||
if (numflag) return;
|
||||
if (numflag) return 0;
|
||||
if (!atom->labelmapflag) error->all(FLERR,fmt::format("Invalid type {}",str));
|
||||
|
||||
int type,max,max2;
|
||||
@ -685,8 +686,13 @@ void Input::readtype(char *&str, int mode)
|
||||
|
||||
max = strlen(str) + 1;
|
||||
max2 = strlen(typechar) + 1;
|
||||
if (max2 > max) reallocate(str,max,max2);
|
||||
strcpy(str,typechar);
|
||||
if (max2 > max) {
|
||||
str = new char[max2];
|
||||
strcpy(str,typechar);
|
||||
return 1;
|
||||
} else strcpy(str,typechar);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -1333,8 +1339,9 @@ void Input::angle_coeff()
|
||||
error->all(FLERR,"Angle_coeff command before angle_style is defined");
|
||||
if (atom->avec->angles_allow == 0)
|
||||
error->all(FLERR,"Angle_coeff command when no angles allowed");
|
||||
readtype(arg[0],atom->ANGLE);
|
||||
int newflag = readtype(arg[0],Atom::ANGLE);
|
||||
force->angle->coeff(narg,arg);
|
||||
if (newflag) delete [] arg[0];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -1375,8 +1382,9 @@ void Input::bond_coeff()
|
||||
error->all(FLERR,"Bond_coeff command before bond_style is defined");
|
||||
if (atom->avec->bonds_allow == 0)
|
||||
error->all(FLERR,"Bond_coeff command when no bonds allowed");
|
||||
readtype(arg[0],atom->BOND);
|
||||
int newflag = readtype(arg[0],Atom::BOND);
|
||||
force->bond->coeff(narg,arg);
|
||||
if (newflag) delete [] arg[0];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -1479,8 +1487,9 @@ void Input::dihedral_coeff()
|
||||
error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined");
|
||||
if (atom->avec->dihedrals_allow == 0)
|
||||
error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed");
|
||||
readtype(arg[0],atom->DIHEDRAL);
|
||||
int newflag = readtype(arg[0],Atom::DIHEDRAL);
|
||||
force->dihedral->coeff(narg,arg);
|
||||
if (newflag) delete [] arg[0];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -1557,8 +1566,9 @@ void Input::improper_coeff()
|
||||
error->all(FLERR,"Improper_coeff command before improper_style is defined");
|
||||
if (atom->avec->impropers_allow == 0)
|
||||
error->all(FLERR,"Improper_coeff command when no impropers allowed");
|
||||
readtype(arg[0],atom->IMPROPER);
|
||||
int newflag = readtype(arg[0],Atom::IMPROPER);
|
||||
force->improper->coeff(narg,arg);
|
||||
if (newflag) delete [] arg[0];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -1751,13 +1761,12 @@ void Input::pair_coeff()
|
||||
error->all(FLERR,"Pair_coeff command before simulation box is defined");
|
||||
if (force->pair == nullptr)
|
||||
error->all(FLERR,"Pair_coeff command before pair_style is defined");
|
||||
readtype(arg[0],atom->ATOM);
|
||||
readtype(arg[1],atom->ATOM);
|
||||
int newflag0 = readtype(arg[0],Atom::ATOM);
|
||||
int newflag1 = readtype(arg[1],Atom::ATOM);
|
||||
|
||||
// if arg[1] < arg[0], and neither contain a wildcard, reorder
|
||||
|
||||
int itype,jtype;
|
||||
int *ptr;
|
||||
int tmpflag,itype,jtype;
|
||||
char *str;
|
||||
if (strchr(arg[0],'*') == nullptr && strchr(arg[1],'*') == nullptr) {
|
||||
itype = utils::numeric(FLERR,arg[0],false,lmp);
|
||||
@ -1766,10 +1775,15 @@ void Input::pair_coeff()
|
||||
str = arg[0];
|
||||
arg[0] = arg[1];
|
||||
arg[1] = str;
|
||||
tmpflag = newflag0;
|
||||
newflag0 = newflag1;
|
||||
newflag1 = tmpflag;
|
||||
}
|
||||
}
|
||||
|
||||
force->pair->coeff(narg,arg);
|
||||
if (newflag0) delete [] arg[0];
|
||||
if (newflag1) delete [] arg[1];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -38,7 +38,7 @@ class Input : protected Pointers {
|
||||
char *one(const std::string&); // process a single command
|
||||
void substitute(char *&, char *&, int &, int &, int);
|
||||
// substitute for variables in a string
|
||||
void readtype(char *&, int); // substitute type label with numeric type
|
||||
int readtype(char *&, int); // substitute type label with numeric type
|
||||
void write_echo(const std::string &); // send text to active echo file pointers
|
||||
|
||||
protected:
|
||||
|
||||
@ -119,23 +119,23 @@ void LabelMap::modify_lmap(int narg, char **arg)
|
||||
|
||||
void LabelMap::merge_lmap(LabelMap *lmap2, int mode)
|
||||
{
|
||||
if (mode == atom->ATOM)
|
||||
if (mode == Atom::ATOM)
|
||||
for (int i = 0; i < lmap2->natomtypes; i++)
|
||||
find_or_create(lmap2->typelabel[i],typelabel,natomtypes);
|
||||
|
||||
if (mode == atom->BOND)
|
||||
if (mode == Atom::BOND)
|
||||
for (int i = 0; i < lmap2->nbondtypes; i++)
|
||||
find_or_create(lmap2->btypelabel[i],btypelabel,nbondtypes);
|
||||
|
||||
if (mode == atom->ANGLE)
|
||||
if (mode == Atom::ANGLE)
|
||||
for (int i = 0; i < lmap2->nangletypes; i++)
|
||||
find_or_create(lmap2->atypelabel[i],atypelabel,nangletypes);
|
||||
|
||||
if (mode == atom->DIHEDRAL)
|
||||
if (mode == Atom::DIHEDRAL)
|
||||
for (int i = 0; i < lmap2->ndihedraltypes; i++)
|
||||
find_or_create(lmap2->dtypelabel[i],dtypelabel,ndihedraltypes);
|
||||
|
||||
if (mode == atom->IMPROPER)
|
||||
if (mode == Atom::IMPROPER)
|
||||
for (int i = 0; i < lmap2->nimpropertypes; i++)
|
||||
find_or_create(lmap2->itypelabel[i],itypelabel,nimpropertypes);
|
||||
}
|
||||
@ -147,27 +147,27 @@ void LabelMap::merge_lmap(LabelMap *lmap2, int mode)
|
||||
|
||||
void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode)
|
||||
{
|
||||
if (mode == atom->ATOM)
|
||||
if (mode == Atom::ATOM)
|
||||
for (int i = 0; i < natomtypes; i++)
|
||||
lmap2lmap.atom[i] = search(typelabel[i],lmap2->typelabel,
|
||||
lmap2->natomtypes);
|
||||
|
||||
if (mode == atom->BOND)
|
||||
if (mode == Atom::BOND)
|
||||
for (int i = 0; i < nbondtypes; i++)
|
||||
lmap2lmap.bond[i] = search(btypelabel[i],lmap2->btypelabel,
|
||||
lmap2->nbondtypes);
|
||||
|
||||
if (mode == atom->ANGLE)
|
||||
if (mode == Atom::ANGLE)
|
||||
for (int i = 0; i < nangletypes; i++)
|
||||
lmap2lmap.angle[i] = search(atypelabel[i],lmap2->atypelabel,
|
||||
lmap2->nangletypes);
|
||||
|
||||
if (mode == atom->DIHEDRAL)
|
||||
if (mode == Atom::DIHEDRAL)
|
||||
for (int i = 0; i < ndihedraltypes; i++)
|
||||
lmap2lmap.dihedral[i] = search(dtypelabel[i],lmap2->dtypelabel,
|
||||
lmap2->ndihedraltypes);
|
||||
|
||||
if (mode == atom->IMPROPER)
|
||||
if (mode == Atom::IMPROPER)
|
||||
for (int i = 0; i < nimpropertypes; i++)
|
||||
lmap2lmap.improper[i] = search(itypelabel[i],lmap2->itypelabel,
|
||||
lmap2->nimpropertypes);
|
||||
@ -206,19 +206,19 @@ int LabelMap::find_or_create(std::string mylabel, std::vector<std::string> &labe
|
||||
|
||||
int LabelMap::find(std::string mylabel, int mode)
|
||||
{
|
||||
if (mode == atom->ATOM)
|
||||
if (mode == Atom::ATOM)
|
||||
return search(mylabel,typelabel,natomtypes);
|
||||
|
||||
if (mode == atom->BOND)
|
||||
if (mode == Atom::BOND)
|
||||
return search(mylabel,btypelabel,nbondtypes);
|
||||
|
||||
if (mode == atom->ANGLE)
|
||||
if (mode == Atom::ANGLE)
|
||||
return search(mylabel,atypelabel,nangletypes);
|
||||
|
||||
if (mode == atom->DIHEDRAL)
|
||||
if (mode == Atom::DIHEDRAL)
|
||||
return search(mylabel,dtypelabel,ndihedraltypes);
|
||||
|
||||
if (mode == atom->IMPROPER)
|
||||
if (mode == Atom::IMPROPER)
|
||||
return search(mylabel,itypelabel,nimpropertypes);
|
||||
|
||||
return -1;
|
||||
|
||||
@ -728,7 +728,7 @@ void Molecule::types(char *line)
|
||||
typestr = values.next_string();
|
||||
if (!isdigit(typestr[0])) {
|
||||
if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file");
|
||||
type[iatom] = atom->find_label(typestr,atom->ATOM);
|
||||
type[iatom] = atom->find_label(typestr,Atom::ATOM);
|
||||
if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file");
|
||||
} else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
|
||||
type[iatom] += toffset;
|
||||
@ -941,7 +941,7 @@ void Molecule::bonds(int flag, char *line)
|
||||
typestr = values.next_string();
|
||||
if (!isdigit(typestr[0])) {
|
||||
if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file");
|
||||
itype = atom->find_label(typestr,atom->BOND);
|
||||
itype = atom->find_label(typestr,Atom::BOND);
|
||||
if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file");
|
||||
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
|
||||
atom1 = values.next_tagint();
|
||||
@ -1015,7 +1015,7 @@ void Molecule::angles(int flag, char *line)
|
||||
typestr = values.next_string();
|
||||
if (!isdigit(typestr[0])) {
|
||||
if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file");
|
||||
itype = atom->find_label(typestr,atom->ANGLE);
|
||||
itype = atom->find_label(typestr,Atom::ANGLE);
|
||||
if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file");
|
||||
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
|
||||
atom1 = values.next_tagint();
|
||||
@ -1105,7 +1105,7 @@ void Molecule::dihedrals(int flag, char *line)
|
||||
typestr = values.next_string();
|
||||
if (!isdigit(typestr[0])) {
|
||||
if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file");
|
||||
itype = atom->find_label(typestr,atom->DIHEDRAL);
|
||||
itype = atom->find_label(typestr,Atom::DIHEDRAL);
|
||||
if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file");
|
||||
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
|
||||
atom1 = values.next_tagint();
|
||||
@ -1210,7 +1210,7 @@ void Molecule::impropers(int flag, char *line)
|
||||
typestr = values.next_string();
|
||||
if (!isdigit(typestr[0])) {
|
||||
if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file");
|
||||
itype = atom->find_label(typestr,atom->IMPROPER);
|
||||
itype = atom->find_label(typestr,Atom::IMPROPER);
|
||||
if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file");
|
||||
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
|
||||
atom1 = values.next_tagint();
|
||||
|
||||
@ -729,7 +729,7 @@ void ReadData::command(int narg, char **arg)
|
||||
if (firstpass) {
|
||||
if (atomflag == 1)
|
||||
error->all(FLERR,"Must read Atom Type Labels before Atoms");
|
||||
typelabels(lmap->typelabel,ntypes,atom->ATOM);
|
||||
typelabels(lmap->typelabel,ntypes,Atom::ATOM);
|
||||
} else skip_lines(ntypes);
|
||||
|
||||
} else if (strcmp(keyword,"Bond Type Labels") == 0) {
|
||||
@ -737,7 +737,7 @@ void ReadData::command(int narg, char **arg)
|
||||
if (firstpass) {
|
||||
if (bondflag == 1)
|
||||
error->all(FLERR,"Must read Bond Type Labels before Bonds");
|
||||
typelabels(lmap->btypelabel,nbondtypes,atom->BOND);
|
||||
typelabels(lmap->btypelabel,nbondtypes,Atom::BOND);
|
||||
} else skip_lines(nbondtypes);
|
||||
}
|
||||
|
||||
@ -746,7 +746,7 @@ void ReadData::command(int narg, char **arg)
|
||||
if (firstpass) {
|
||||
if (angleflag == 1)
|
||||
error->all(FLERR,"Must read Angle Type Labels before Angles");
|
||||
typelabels(lmap->atypelabel,nangletypes,atom->ANGLE);
|
||||
typelabels(lmap->atypelabel,nangletypes,Atom::ANGLE);
|
||||
} else skip_lines(nangletypes);
|
||||
}
|
||||
|
||||
@ -755,7 +755,7 @@ void ReadData::command(int narg, char **arg)
|
||||
if (firstpass) {
|
||||
if (dihedralflag == 1)
|
||||
error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals");
|
||||
typelabels(lmap->dtypelabel,ndihedraltypes,atom->DIHEDRAL);
|
||||
typelabels(lmap->dtypelabel,ndihedraltypes,Atom::DIHEDRAL);
|
||||
} else skip_lines(ndihedraltypes);
|
||||
}
|
||||
|
||||
@ -764,7 +764,7 @@ void ReadData::command(int narg, char **arg)
|
||||
if (firstpass) {
|
||||
if (improperflag == 1)
|
||||
error->all(FLERR,"Must read Improper Type Labels before Impropers");
|
||||
typelabels(lmap->itypelabel,nimpropertypes,atom->IMPROPER);
|
||||
typelabels(lmap->itypelabel,nimpropertypes,Atom::IMPROPER);
|
||||
} else skip_lines(nimpropertypes);
|
||||
}
|
||||
|
||||
|
||||
@ -4540,19 +4540,19 @@ int Variable::labelmap_function(char *word, char *contents, Tree **tree,
|
||||
std::string typestr = contents;
|
||||
|
||||
if (strcmp(word,"label") == 0) {
|
||||
value = atom->find_label(typestr,atom->ATOM);
|
||||
value = atom->find_label(typestr,Atom::ATOM);
|
||||
|
||||
} else if (strcmp(word,"blabel") == 0) {
|
||||
value = atom->find_label(typestr,atom->BOND);
|
||||
value = atom->find_label(typestr,Atom::BOND);
|
||||
|
||||
} else if (strcmp(word,"alabel") == 0) {
|
||||
value = atom->find_label(typestr,atom->ANGLE);
|
||||
value = atom->find_label(typestr,Atom::ANGLE);
|
||||
|
||||
} else if (strcmp(word,"dlabel") == 0) {
|
||||
value = atom->find_label(typestr,atom->DIHEDRAL);
|
||||
value = atom->find_label(typestr,Atom::DIHEDRAL);
|
||||
|
||||
} else if (strcmp(word,"ilabel") == 0) {
|
||||
value = atom->find_label(typestr,atom->IMPROPER);
|
||||
value = atom->find_label(typestr,Atom::IMPROPER);
|
||||
}
|
||||
|
||||
if (value == -1)
|
||||
|
||||
Reference in New Issue
Block a user