Merge pull request #2674 from rbberger/small_changes

Small code changes
This commit is contained in:
Axel Kohlmeyer
2021-03-19 20:05:41 -04:00
committed by GitHub
20 changed files with 91 additions and 174 deletions

View File

@ -48,8 +48,8 @@ Examples
fix 1 ellipsoid rigid/meso single fix 1 ellipsoid rigid/meso single
fix 1 rods rigid/meso molecule fix 1 rods rigid/meso molecule
fix 1 spheres rigid/meso single force 1 off off on fix 1 spheres rigid/meso single force 1 off off on
fix 1 particles rigid/meso molecule force 1\*5 off off off force 6\*10 off off on fix 1 particles rigid/meso molecule force 1*5 off off off force 6*10 off off on
fix 2 spheres rigid/meso group 3 sphere1 sphere2 sphere3 torque \* off off off fix 2 spheres rigid/meso group 3 sphere1 sphere2 sphere3 torque * off off off
Description Description
""""""""""" """""""""""

View File

@ -120,12 +120,12 @@ specified atom types, atom IDs, or molecule IDs into the group. These
The first format is a list of values (types or IDs). For example, the The first format is a list of values (types or IDs). For example, the
second command in the examples above puts all atoms of type 3 or 4 into second command in the examples above puts all atoms of type 3 or 4 into
the group named *water*\ . Each entry in the list can be a the group named *water*\ . Each entry in the list can be a
colon-separated sequence A:B or A:B:C, as in two of the examples colon-separated sequence ``A:B`` or ``A:B:C``, as in two of the examples
above. A "sequence" generates a sequence of values (types or IDs), above. A "sequence" generates a sequence of values (types or IDs),
with an optional increment. The first example with 500:1000 has the with an optional increment. The first example with ``500:1000`` has the
default increment of 1 and would add all atom IDs from 500 to 1000 default increment of 1 and would add all atom IDs from 500 to 1000
(inclusive) to the group sub, along with 10,25,50 since they also (inclusive) to the group sub, along with 10,25,50 since they also
appear in the list of values. The second example with 100:10000:10 appear in the list of values. The second example with ``100:10000:10``
uses an increment of 10 and would thus would add atoms IDs uses an increment of 10 and would thus would add atoms IDs
100,110,120, ... 9990,10000 to the group sub. 100,110,120, ... 9990,10000 to the group sub.
@ -269,7 +269,7 @@ group and running further.
.. code-block:: LAMMPS .. code-block:: LAMMPS
variable nsteps equal 5000 variable nsteps equal 5000
variable rad equal 18-(step/v_nsteps)\*(18-5) variable rad equal 18-(step/v_nsteps)*(18-5)
region ss sphere 20 20 0 v_rad region ss sphere 20 20 0 v_rad
group mobile dynamic all region ss group mobile dynamic all region ss
fix 1 mobile nve fix 1 mobile nve

View File

@ -1205,7 +1205,7 @@ coordinates of atoms in the unit cell of the cubic crystal. In the case of,
e.g. a conventional fcc unit cell, the "source-value" key in the map associated e.g. a conventional fcc unit cell, the "source-value" key in the map associated
with this key should be assigned the following value: with this key should be assigned the following value:
.. code-block:: LAMMPS .. code-block:: text
[[0.0, 0.0, 0.0], [[0.0, 0.0, 0.0],
[0.5, 0.5, 0.0], [0.5, 0.5, 0.0],

View File

@ -40,7 +40,7 @@ class LAMMPSLexer(RegexLexer):
(r'compute\s+', Keyword, 'compute'), (r'compute\s+', Keyword, 'compute'),
(r'dump\s+', Keyword, 'dump'), (r'dump\s+', Keyword, 'dump'),
(r'region\s+', Keyword, 'region'), (r'region\s+', Keyword, 'region'),
(r'variable\s+', Keyword, 'variable'), (r'^\s*variable\s+', Keyword, 'variable_cmd'),
(r'group\s+', Keyword, 'group'), (r'group\s+', Keyword, 'group'),
(r'change_box\s+', Keyword, 'change_box'), (r'change_box\s+', Keyword, 'change_box'),
(r'uncompute\s+', Keyword, 'uncompute'), (r'uncompute\s+', Keyword, 'uncompute'),
@ -51,6 +51,7 @@ class LAMMPSLexer(RegexLexer):
(r'#.*?\n', Comment), (r'#.*?\n', Comment),
('"', String, 'string'), ('"', String, 'string'),
('\'', String, 'single_quote_string'), ('\'', String, 'single_quote_string'),
(r'[0-9]+:[0-9]+(:[0-9]+)?', Number),
(r'[0-9]+(\.[0-9]+)?([eE]\-?[0-9]+)?', Number), (r'[0-9]+(\.[0-9]+)?([eE]\-?[0-9]+)?', Number),
('\$?\(', Name.Variable, 'expression'), ('\$?\(', Name.Variable, 'expression'),
('\$\{', Name.Variable, 'variable'), ('\$\{', Name.Variable, 'variable'),
@ -58,6 +59,7 @@ class LAMMPSLexer(RegexLexer):
(r'\$[\w_]+', Name.Variable), (r'\$[\w_]+', Name.Variable),
(r'\s+', Whitespace), (r'\s+', Whitespace),
(r'[\+\-\*\^\|\/\!%&=<>]', Operator), (r'[\+\-\*\^\|\/\!%&=<>]', Operator),
(r'[\~\.\w_:,@\-\/\\0-9]+', Text),
], ],
'keywords' : [ 'keywords' : [
(words(LAMMPS_COMMANDS, suffix=r'\b', prefix=r'^'), Keyword) (words(LAMMPS_COMMANDS, suffix=r'\b', prefix=r'^'), Keyword)
@ -99,7 +101,7 @@ class LAMMPSLexer(RegexLexer):
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier), (r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
default('#pop') default('#pop')
], ],
'variable' : [ 'variable_cmd' : [
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier), (r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
default('#pop') default('#pop')
], ],

View File

@ -77,14 +77,12 @@ void DumpAtomGZ::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -76,14 +76,12 @@ void DumpAtomZstd::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -81,14 +81,12 @@ void DumpCFGGZ::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -79,14 +79,12 @@ void DumpCFGZstd::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -79,14 +79,12 @@ void DumpCustomGZ::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -76,14 +76,12 @@ void DumpCustomZstd::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -79,14 +79,12 @@ void DumpLocalGZ::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -78,14 +78,12 @@ void DumpLocalZstd::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -78,14 +78,12 @@ void DumpXYZGZ::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -76,14 +76,12 @@ void DumpXYZZstd::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }

View File

@ -46,20 +46,14 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
MPI_Comm_rank(world,&me); MPI_Comm_rank(world,&me);
MPI_Comm_size(world,&nprocs); MPI_Comm_size(world,&nprocs);
int n = strlen(arg[0]) + 1; id = utils::strdup(arg[0]);
id = new char[n];
strcpy(id,arg[0]);
igroup = group->find(arg[1]); igroup = group->find(arg[1]);
groupbit = group->bitmask[igroup]; groupbit = group->bitmask[igroup];
n = strlen(arg[2]) + 1; style = utils::strdup(arg[2]);
style = new char[n];
strcpy(style,arg[2]);
n = strlen(arg[4]) + 1; filename = utils::strdup(arg[4]);
filename = new char[n];
strcpy(filename,arg[4]);
comm_forward = comm_reverse = 0; comm_forward = comm_reverse = 0;
@ -140,9 +134,8 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
filewriter = 1; filewriter = 1;
fileproc = me; fileproc = me;
MPI_Comm_split(world,me,0,&clustercomm); MPI_Comm_split(world,me,0,&clustercomm);
multiname = new char[strlen(filename) + 16];
*ptr = '\0'; *ptr = '\0';
sprintf(multiname,"%s%d%s",filename,me,ptr+1); multiname = utils::strdup(fmt::format("{}{}{}", filename, me, ptr+1));
*ptr = '%'; *ptr = '%';
} }
@ -573,14 +566,12 @@ void Dump::openfile()
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) { if (maxfiles > 0) {
if (numfiles < maxfiles) { if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1]; nameslist[numfiles] = utils::strdup(filecurrent);
strcpy(nameslist[numfiles],filecurrent);
++numfiles; ++numfiles;
} else { } else {
remove(nameslist[fileidx]); remove(nameslist[fileidx]);
delete[] nameslist[fileidx]; delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1]; nameslist[fileidx] = utils::strdup(filecurrent);
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles; fileidx = (fileidx + 1) % maxfiles;
} }
} }
@ -952,9 +943,7 @@ void Dump::modify_params(int narg, char **arg)
int n; int n;
if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) { if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
delete [] output->var_dump[idump]; delete [] output->var_dump[idump];
n = strlen(&arg[iarg+1][2]) + 1; output->var_dump[idump] = utils::strdup(&arg[iarg+1][2]);
output->var_dump[idump] = new char[n];
strcpy(output->var_dump[idump],&arg[iarg+1][2]);
n = 0; n = 0;
} else { } else {
n = utils::inumeric(FLERR,arg[iarg+1],false,lmp); n = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
@ -984,10 +973,9 @@ void Dump::modify_params(int narg, char **arg)
MPI_Comm_split(world,icluster,0,&clustercomm); MPI_Comm_split(world,icluster,0,&clustercomm);
delete [] multiname; delete [] multiname;
multiname = new char[strlen(filename) + 16];
char *ptr = strchr(filename,'%'); char *ptr = strchr(filename,'%');
*ptr = '\0'; *ptr = '\0';
sprintf(multiname,"%s%d%s",filename,icluster,ptr+1); multiname = utils::strdup(fmt::format("{}{}{}", filename, icluster, ptr+1));
*ptr = '%'; *ptr = '%';
iarg += 2; iarg += 2;
@ -1028,9 +1016,7 @@ void Dump::modify_params(int narg, char **arg)
if (strcmp(arg[iarg+1],"line") == 0) { if (strcmp(arg[iarg+1],"line") == 0) {
delete [] format_line_user; delete [] format_line_user;
int n = strlen(arg[iarg+2]) + 1; format_line_user = utils::strdup(arg[iarg+2]);
format_line_user = new char[n];
strcpy(format_line_user,arg[iarg+2]);
iarg += 3; iarg += 3;
} else { // pass other format options to child classes } else { // pass other format options to child classes
int n = modify_param(narg-iarg,&arg[iarg]); int n = modify_param(narg-iarg,&arg[iarg]);
@ -1085,10 +1071,9 @@ void Dump::modify_params(int narg, char **arg)
MPI_Comm_split(world,icluster,0,&clustercomm); MPI_Comm_split(world,icluster,0,&clustercomm);
delete [] multiname; delete [] multiname;
multiname = new char[strlen(filename) + 16];
char *ptr = strchr(filename,'%'); char *ptr = strchr(filename,'%');
*ptr = '\0'; *ptr = '\0';
sprintf(multiname,"%s%d%s",filename,icluster,ptr+1); multiname = utils::strdup(fmt::format("{}{}{}", filename, icluster, ptr+1));
*ptr = '%'; *ptr = '%';
iarg += 2; iarg += 2;

View File

@ -74,14 +74,10 @@ DumpCFG::DumpCFG(LAMMPS *lmp, int narg, char **arg) :
|ArgInfo::DNAME|ArgInfo::INAME); |ArgInfo::DNAME|ArgInfo::INAME);
if (argi.get_dim() == 1) { if (argi.get_dim() == 1) {
std::string newarg(std::to_string(earg[iarg][0])); std::string newarg = fmt::format("{}_{}_{}", earg[iarg][0], argi.get_name(), argi.get_index1());
newarg += std::string("_") + argi.get_name(); auxname[i] = utils::strdup(newarg);
newarg += std::string("_") + std::to_string(argi.get_index1());
auxname[i] = new char[newarg.size()+1];
strcpy(auxname[i],newarg.c_str());
} else { } else {
auxname[i] = new char[strlen(earg[iarg]) + 1]; auxname[i] = utils::strdup(earg[iarg]);
strcpy(auxname[i],earg[iarg]);
} }
} }
} }

View File

@ -285,7 +285,7 @@ void DumpCustom::init_style()
else if (vtype[i] == Dump::DOUBLE && format_float_user) else if (vtype[i] == Dump::DOUBLE && format_float_user)
vformat[i] = utils::strdup(std::string(format_float_user) + " "); vformat[i] = utils::strdup(std::string(format_float_user) + " ");
else if (vtype[i] == Dump::BIGINT && format_bigint_user) else if (vtype[i] == Dump::BIGINT && format_bigint_user)
vformat[i] = utils::strdup(std::string(format_int_user) + " "); vformat[i] = utils::strdup(std::string(format_bigint_user) + " ");
else vformat[i] = utils::strdup(word + " "); else vformat[i] = utils::strdup(word + " ");
// remove trailing blank on last column's format // remove trailing blank on last column's format
@ -1562,9 +1562,7 @@ int DumpCustom::add_compute(const char *id)
delete [] compute; delete [] compute;
compute = new Compute*[ncompute+1]; compute = new Compute*[ncompute+1];
int n = strlen(id) + 1; id_compute[ncompute] = utils::strdup(id);
id_compute[ncompute] = new char[n];
strcpy(id_compute[ncompute],id);
ncompute++; ncompute++;
return ncompute-1; return ncompute-1;
} }
@ -1587,9 +1585,7 @@ int DumpCustom::add_fix(const char *id)
delete [] fix; delete [] fix;
fix = new Fix*[nfix+1]; fix = new Fix*[nfix+1];
int n = strlen(id) + 1; id_fix[nfix] = utils::strdup(id);
id_fix[nfix] = new char[n];
strcpy(id_fix[nfix],id);
nfix++; nfix++;
return nfix-1; return nfix-1;
} }
@ -1616,9 +1612,7 @@ int DumpCustom::add_variable(const char *id)
vbuf = new double*[nvariable+1]; vbuf = new double*[nvariable+1];
for (int i = 0; i <= nvariable; i++) vbuf[i] = nullptr; for (int i = 0; i <= nvariable; i++) vbuf[i] = nullptr;
int n = strlen(id) + 1; id_variable[nvariable] = utils::strdup(id);
id_variable[nvariable] = new char[n];
strcpy(id_variable[nvariable],id);
nvariable++; nvariable++;
return nvariable-1; return nvariable-1;
} }
@ -1642,9 +1636,7 @@ int DumpCustom::add_custom(const char *id, int flag)
flag_custom = (int *) flag_custom = (int *)
memory->srealloc(flag_custom,(ncustom+1)*sizeof(int),"dump:flag_custom"); memory->srealloc(flag_custom,(ncustom+1)*sizeof(int),"dump:flag_custom");
int n = strlen(id) + 1; id_custom[ncustom] = utils::strdup(id);
id_custom[ncustom] = new char[n];
strcpy(id_custom[ncustom],id);
flag_custom[ncustom] = flag; flag_custom[ncustom] = flag;
ncustom++; ncustom++;
@ -1663,9 +1655,7 @@ int DumpCustom::modify_param(int narg, char **arg)
if (iregion == -1) if (iregion == -1)
error->all(FLERR,"Dump_modify region ID does not exist"); error->all(FLERR,"Dump_modify region ID does not exist");
delete [] idregion; delete [] idregion;
int n = strlen(arg[1]) + 1; idregion = utils::strdup(arg[1]);
idregion = new char[n];
strcpy(idregion,arg[1]);
} }
return 2; return 2;
} }
@ -1686,11 +1676,9 @@ int DumpCustom::modify_param(int narg, char **arg)
if (strcmp(arg[1],"int") == 0) { if (strcmp(arg[1],"int") == 0) {
delete [] format_int_user; delete [] format_int_user;
int n = strlen(arg[2]) + 1; format_int_user = utils::strdup(arg[2]);
format_int_user = new char[n];
strcpy(format_int_user,arg[2]);
delete [] format_bigint_user; delete [] format_bigint_user;
n = strlen(format_int_user) + 8; int n = strlen(format_int_user) + 8;
format_bigint_user = new char[n]; format_bigint_user = new char[n];
// replace "d" in format_int_user with bigint format specifier // replace "d" in format_int_user with bigint format specifier
// use of &str[1] removes leading '%' from BIGINT_FORMAT string // use of &str[1] removes leading '%' from BIGINT_FORMAT string
@ -1706,18 +1694,14 @@ int DumpCustom::modify_param(int narg, char **arg)
} else if (strcmp(arg[1],"float") == 0) { } else if (strcmp(arg[1],"float") == 0) {
delete [] format_float_user; delete [] format_float_user;
int n = strlen(arg[2]) + 1; format_float_user = utils::strdup(arg[2]);
format_float_user = new char[n];
strcpy(format_float_user,arg[2]);
} else { } else {
int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1; int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1;
if (i < 0 || i >= nfield) if (i < 0 || i >= nfield)
error->all(FLERR,"Illegal dump_modify command"); error->all(FLERR,"Illegal dump_modify command");
if (format_column_user[i]) delete [] format_column_user[i]; if (format_column_user[i]) delete [] format_column_user[i];
int n = strlen(arg[2]) + 1; format_column_user[i] = utils::strdup(arg[2]);
format_column_user[i] = new char[n];
strcpy(format_column_user[i],arg[2]);
} }
return 3; return 3;
} }
@ -1730,9 +1714,7 @@ int DumpCustom::modify_param(int narg, char **arg)
delete [] typenames; delete [] typenames;
typenames = new char*[ntypes+1]; typenames = new char*[ntypes+1];
for (int itype = 1; itype <= ntypes; itype++) { for (int itype = 1; itype <= ntypes; itype++) {
int n = strlen(arg[itype]) + 1; typenames[itype] = utils::strdup(arg[itype]);
typenames[itype] = new char[n];
strcpy(typenames[itype],arg[itype]);
} }
return ntypes+1; return ntypes+1;
} }
@ -1998,8 +1980,7 @@ int DumpCustom::modify_param(int narg, char **arg)
memory->grow(thresh_first,(nthreshlast+1),"dump:thresh_first"); memory->grow(thresh_first,(nthreshlast+1),"dump:thresh_first");
std::string threshid = fmt::format("{}{}_DUMP_STORE",id,nthreshlast); std::string threshid = fmt::format("{}{}_DUMP_STORE",id,nthreshlast);
thresh_fixID[nthreshlast] = new char[threshid.size()+1]; thresh_fixID[nthreshlast] = utils::strdup(threshid);
strcpy(thresh_fixID[nthreshlast],threshid.c_str());
modify->add_fix(fmt::format("{} {} STORE peratom 1 1",threshid, modify->add_fix(fmt::format("{} {} STORE peratom 1 1",threshid,
group->names[igroup])); group->names[igroup]));
thresh_fix[nthreshlast] = (FixStore *) modify->fix[modify->nfix-1]; thresh_fix[nthreshlast] = (FixStore *) modify->fix[modify->nfix-1];

View File

@ -472,9 +472,7 @@ int DumpLocal::add_compute(const char *id)
delete [] compute; delete [] compute;
compute = new Compute*[ncompute+1]; compute = new Compute*[ncompute+1];
int n = strlen(id) + 1; id_compute[ncompute] = utils::strdup(id);
id_compute[ncompute] = new char[n];
strcpy(id_compute[ncompute],id);
ncompute++; ncompute++;
return ncompute-1; return ncompute-1;
} }
@ -497,9 +495,7 @@ int DumpLocal::add_fix(const char *id)
delete [] fix; delete [] fix;
fix = new Fix*[nfix+1]; fix = new Fix*[nfix+1];
int n = strlen(id) + 1; id_fix[nfix] = utils::strdup(id);
id_fix[nfix] = new char[n];
strcpy(id_fix[nfix],id);
nfix++; nfix++;
return nfix-1; return nfix-1;
} }

View File

@ -40,10 +40,7 @@ DumpXYZ::DumpXYZ(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg),
if (format_default) delete [] format_default; if (format_default) delete [] format_default;
char *str = (char *) "%s %g %g %g"; format_default = utils::strdup("%s %g %g %g");
int n = strlen(str) + 1;
format_default = new char[n];
strcpy(format_default,str);
ntypes = atom->ntypes; ntypes = atom->ntypes;
typenames = nullptr; typenames = nullptr;
@ -71,14 +68,11 @@ void DumpXYZ::init_style()
// format = copy of default or user-specified line format // format = copy of default or user-specified line format
delete [] format; delete [] format;
char *str;
if (format_line_user) str = format_line_user;
else str = format_default;
int n = strlen(str) + 2; if (format_line_user)
format = new char[n]; format = utils::strdup(fmt::format("{}\n", format_line_user));
strcpy(format,str); else
strcat(format,"\n"); format = utils::strdup(fmt::format("{}\n", format_default));
// initialize typenames array to be backward compatible by default // initialize typenames array to be backward compatible by default
// a 32-bit int can be maximally 10 digits plus sign // a 32-bit int can be maximally 10 digits plus sign
@ -119,9 +113,7 @@ int DumpXYZ::modify_param(int narg, char **arg)
typenames = new char*[ntypes+1]; typenames = new char*[ntypes+1];
for (int itype = 1; itype <= ntypes; itype++) { for (int itype = 1; itype <= ntypes; itype++) {
int n = strlen(arg[itype]) + 1; typenames[itype] = utils::strdup(arg[itype]);
typenames[itype] = new char[n];
strcpy(typenames[itype],arg[itype]);
} }
return ntypes+1; return ntypes+1;

View File

@ -35,12 +35,14 @@ TokenizerException::TokenizerException(const std::string &msg, const std::string
/** Class for splitting text into words /** Class for splitting text into words
* *
* This tokenizer will break down a string into sub-strings (i.e words) * This tokenizer will break down a string into sub-strings (i.e words)
* separated by the given separator characters. * separated by the given separator characters. If the string contains
* certain known UTF-8 characters they will be replaced by their ASCII
* equivalents processing the string.
* *
\verbatim embed:rst \verbatim embed:rst
*See also* *See also*
:cpp:class:`ValueTokenizer`, :cpp:func:`utils::split_words` :cpp:class:`ValueTokenizer`, :cpp:func:`utils::split_words`, :cpp:func:`utils::utf8_subst`
\endverbatim \endverbatim
* *
@ -50,6 +52,8 @@ TokenizerException::TokenizerException(const std::string &msg, const std::string
Tokenizer::Tokenizer(const std::string &str, const std::string &separators) : Tokenizer::Tokenizer(const std::string &str, const std::string &separators) :
text(str), separators(separators), start(0), ntokens(std::string::npos) text(str), separators(separators), start(0), ntokens(std::string::npos)
{ {
// replace known UTF-8 characters with ASCII equivalents
if (utils::has_utf8(text)) text = utils::utf8_subst(text);
reset(); reset();
} }
@ -197,70 +201,51 @@ bool ValueTokenizer::contains(const std::string &value) const {
* *
* \return string with next token */ * \return string with next token */
std::string ValueTokenizer::next_string() { std::string ValueTokenizer::next_string() {
if (has_next()) { return tokens.next();
std::string value = tokens.next();
return value;
} throw TokenizerException("Not enough tokens","");
} }
/*! Retrieve next token and convert to int /*! Retrieve next token and convert to int
* *
* \return value of next token */ * \return value of next token */
int ValueTokenizer::next_int() { int ValueTokenizer::next_int() {
if (has_next()) { std::string current = tokens.next();
std::string current = tokens.next(); if (!utils::is_integer(current)) {
if (utils::has_utf8(current)) current = utils::utf8_subst(current); throw InvalidIntegerException(current);
if (!utils::is_integer(current)) { }
throw InvalidIntegerException(current); return atoi(current.c_str());
}
int value = atoi(current.c_str());
return value;
} throw TokenizerException("Not enough tokens","");
} }
/*! Retrieve next token and convert to bigint /*! Retrieve next token and convert to bigint
* *
* \return value of next token */ * \return value of next token */
bigint ValueTokenizer::next_bigint() { bigint ValueTokenizer::next_bigint() {
if (has_next()) { std::string current = tokens.next();
std::string current = tokens.next(); if (!utils::is_integer(current)) {
if (utils::has_utf8(current)) current = utils::utf8_subst(current); throw InvalidIntegerException(current);
if (!utils::is_integer(current)) { }
throw InvalidIntegerException(current); return ATOBIGINT(current.c_str());
}
bigint value = ATOBIGINT(current.c_str());
return value;
} throw TokenizerException("Not enough tokens","");
} }
/*! Retrieve next token and convert to tagint /*! Retrieve next token and convert to tagint
* *
* \return value of next token */ * \return value of next token */
tagint ValueTokenizer::next_tagint() { tagint ValueTokenizer::next_tagint() {
if (has_next()) { std::string current = tokens.next();
std::string current = tokens.next(); if (!utils::is_integer(current)) {
if (utils::has_utf8(current)) current = utils::utf8_subst(current); throw InvalidIntegerException(current);
if (!utils::is_integer(current)) { }
throw InvalidIntegerException(current); return ATOTAGINT(current.c_str());
}
tagint value = ATOTAGINT(current.c_str());
return value;
} throw TokenizerException("Not enough tokens","");
} }
/*! Retrieve next token and convert to double /*! Retrieve next token and convert to double
* *
* \return value of next token */ * \return value of next token */
double ValueTokenizer::next_double() { double ValueTokenizer::next_double() {
if (has_next()) { std::string current = tokens.next();
std::string current = tokens.next(); if (!utils::is_double(current)) {
if (utils::has_utf8(current)) current = utils::utf8_subst(current); throw InvalidFloatException(current);
if (!utils::is_double(current)) { }
throw InvalidFloatException(current); return atof(current.c_str());
}
double value = atof(current.c_str());
return value;
} throw TokenizerException("Not enough tokens","");
} }
/*! Skip over a given number of tokens /*! Skip over a given number of tokens