use vector<string> for type label arrays
This commit is contained in:
@ -26,9 +26,6 @@ LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp)
|
|||||||
{
|
{
|
||||||
natomtypes = nbondtypes = nangletypes = 0;
|
natomtypes = nbondtypes = nangletypes = 0;
|
||||||
ndihedraltypes = nimpropertypes = 0;
|
ndihedraltypes = nimpropertypes = 0;
|
||||||
|
|
||||||
typelabel = btypelabel = atypelabel = NULL;
|
|
||||||
dtypelabel = itypelabel = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
@ -37,16 +34,11 @@ LabelMap::~LabelMap()
|
|||||||
{
|
{
|
||||||
// delete type labels
|
// delete type labels
|
||||||
|
|
||||||
for (int i = 0; i < natomtypes; i++) delete typelabel[i];
|
typelabel.clear();
|
||||||
memory->sfree(typelabel);
|
btypelabel.clear();
|
||||||
for (int i = 0; i < nbondtypes; i++) delete btypelabel[i];
|
atypelabel.clear();
|
||||||
memory->sfree(btypelabel);
|
dtypelabel.clear();
|
||||||
for (int i = 0; i < nangletypes; i++) delete atypelabel[i];
|
itypelabel.clear();
|
||||||
memory->sfree(atypelabel);
|
|
||||||
for (int i = 0; i < ndihedraltypes; i++) delete dtypelabel[i];
|
|
||||||
memory->sfree(dtypelabel);
|
|
||||||
for (int i = 0; i < nimpropertypes; i++) delete itypelabel[i];
|
|
||||||
memory->sfree(itypelabel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@ -57,57 +49,33 @@ LabelMap::~LabelMap()
|
|||||||
|
|
||||||
void LabelMap::allocate_type_labels()
|
void LabelMap::allocate_type_labels()
|
||||||
{
|
{
|
||||||
char *char_type = new char[256];
|
typelabel.resize(natomtypes);
|
||||||
|
for (int i = 0; i < natomtypes; i++)
|
||||||
|
typelabel[i] = fmt::format("{}",i);
|
||||||
|
|
||||||
typelabel = (char **) memory->srealloc(typelabel,
|
|
||||||
natomtypes*sizeof(char *),"atom:typelabel");
|
|
||||||
for (int i = 0; i < natomtypes; i++) {
|
|
||||||
sprintf(char_type,"%d",i+1);
|
|
||||||
int n = strlen(char_type) + 1;
|
|
||||||
typelabel[i] = new char[n];
|
|
||||||
strcpy(typelabel[i],char_type);
|
|
||||||
}
|
|
||||||
if (force->bond) {
|
if (force->bond) {
|
||||||
btypelabel = (char **) memory->srealloc(btypelabel,
|
btypelabel.resize(nbondtypes);
|
||||||
nbondtypes*sizeof(char *),"atom:btypelabel");
|
for (int i = 0; i < nbondtypes; i++)
|
||||||
for (int i = 0; i < nbondtypes; i++) {
|
btypelabel[i] = fmt::format("{}",i);
|
||||||
sprintf(char_type,"%d",i+1);
|
|
||||||
int n = strlen(char_type) + 1;
|
|
||||||
btypelabel[i] = new char[n];
|
|
||||||
strcpy(btypelabel[i],char_type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force->angle) {
|
if (force->angle) {
|
||||||
atypelabel = (char **) memory->srealloc(atypelabel,
|
atypelabel.resize(nangletypes);
|
||||||
nangletypes*sizeof(char *),"atom:atypelabel");
|
for (int i = 0; i < nangletypes; i++)
|
||||||
for (int i = 0; i < nangletypes; i++) {
|
atypelabel[i] = fmt::format("{}",i);
|
||||||
sprintf(char_type,"%d",i+1);
|
|
||||||
int n = strlen(char_type) + 1;
|
|
||||||
atypelabel[i] = new char[n];
|
|
||||||
strcpy(atypelabel[i],char_type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force->dihedral) {
|
if (force->dihedral) {
|
||||||
dtypelabel = (char **) memory->srealloc(dtypelabel,
|
dtypelabel.resize(ndihedraltypes);
|
||||||
ndihedraltypes*sizeof(char *),"atom:dtypelabel");
|
for (int i = 0; i < ndihedraltypes; i++)
|
||||||
for (int i = 0; i < ndihedraltypes; i++) {
|
dtypelabel[i] = fmt::format("{}",i);
|
||||||
sprintf(char_type,"%d",i+1);
|
|
||||||
int n = strlen(char_type) + 1;
|
|
||||||
dtypelabel[i] = new char[n];
|
|
||||||
strcpy(dtypelabel[i],char_type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force->improper) {
|
if (force->improper) {
|
||||||
itypelabel = (char **) memory->srealloc(itypelabel,
|
itypelabel.resize(nimpropertypes);
|
||||||
nimpropertypes*sizeof(char *),"atom:itypelabel");
|
for (int i = 0; i < nimpropertypes; i++)
|
||||||
for (int i = 0; i < nimpropertypes; i++) {
|
itypelabel[i] = fmt::format("{}",i);
|
||||||
sprintf(char_type,"%d",i+1);
|
|
||||||
int n = strlen(char_type) + 1;
|
|
||||||
itypelabel[i] = new char[n];
|
|
||||||
strcpy(itypelabel[i],char_type);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
delete [] char_type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|||||||
@ -22,8 +22,8 @@ class LabelMap : protected Pointers {
|
|||||||
public:
|
public:
|
||||||
int natomtypes,nbondtypes,nangletypes;
|
int natomtypes,nbondtypes,nangletypes;
|
||||||
int ndihedraltypes,nimpropertypes;
|
int ndihedraltypes,nimpropertypes;
|
||||||
char **typelabel,**btypelabel,**atypelabel;
|
std::vector<std::string> typelabel,btypelabel,atypelabel;
|
||||||
char **dtypelabel,**itypelabel;
|
std::vector<std::string> dtypelabel,itypelabel;
|
||||||
|
|
||||||
LabelMap(LAMMPS *lmp);
|
LabelMap(LAMMPS *lmp);
|
||||||
~LabelMap();
|
~LabelMap();
|
||||||
|
|||||||
@ -1931,7 +1931,7 @@ void ReadData::impropercoeffs(int which)
|
|||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void ReadData::typelabels(char **mytypelabel, int myntypes)
|
void ReadData::typelabels(std::vector<std::string> &mytypelabel, int myntypes)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
char *next;
|
char *next;
|
||||||
@ -1945,10 +1945,7 @@ void ReadData::typelabels(char **mytypelabel, int myntypes)
|
|||||||
next = strchr(buf,'\n');
|
next = strchr(buf,'\n');
|
||||||
*next = '\0';
|
*next = '\0';
|
||||||
sscanf(buf,"%*d %s",typelabel);
|
sscanf(buf,"%*d %s",typelabel);
|
||||||
n = strlen(typelabel) + 1;
|
mytypelabel[i] = typelabel;
|
||||||
delete [] mytypelabel[i];
|
|
||||||
mytypelabel[i] = new char[n];
|
|
||||||
strcpy(mytypelabel[i],typelabel);
|
|
||||||
buf = next + 1;
|
buf = next + 1;
|
||||||
}
|
}
|
||||||
delete [] typelabel;
|
delete [] typelabel;
|
||||||
|
|||||||
@ -106,7 +106,7 @@ class ReadData : protected Pointers {
|
|||||||
void anglecoeffs(int);
|
void anglecoeffs(int);
|
||||||
void dihedralcoeffs(int);
|
void dihedralcoeffs(int);
|
||||||
void impropercoeffs(int);
|
void impropercoeffs(int);
|
||||||
void typelabels(char **, int);
|
void typelabels(std::vector<std::string> &, int);
|
||||||
|
|
||||||
void fix(int, char *);
|
void fix(int, char *);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user