diff --git a/src/atom.cpp b/src/atom.cpp index ae0968aa61..292583da87 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1198,7 +1198,6 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset, void Atom::data_vels(int n, char *buf, tagint id_offset) { int j,m; - tagint tagdata; char *next; next = strchr(buf,'\n'); @@ -1220,7 +1219,7 @@ void Atom::data_vels(int n, char *buf, tagint id_offset) if (values.size() != nwords) error->all(FLERR, "Incorrect atom format in data file: {}", utils::trim(buf)); - tagdata = utils::tnumeric(FLERR,values[0],false,lmp) + id_offset; + tagint tagdata = utils::tnumeric(FLERR,values[0],false,lmp) + id_offset; if (tagdata <= 0 || tagdata > map_tag_max) error->one(FLERR,"Invalid atom ID in Velocities section of data file"); if ((m = map(tagdata)) >= 0) avec->data_vel(m,values); @@ -1577,7 +1576,7 @@ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset, void Atom::data_bonus(int n, char *buf, AtomVec *avec_bonus, tagint id_offset) { - int j,m,tagdata; + int j,m; char *next; next = strchr(buf,'\n'); @@ -1588,35 +1587,28 @@ void Atom::data_bonus(int n, char *buf, AtomVec *avec_bonus, tagint id_offset) if (nwords != avec_bonus->size_data_bonus) error->all(FLERR,"Incorrect bonus data format in data file"); - char **values = new char*[nwords]; - // loop over lines of bonus atom data // tokenize the line into values // if I own atom tag, unpack its values for (int i = 0; i < n; i++) { next = strchr(buf,'\n'); + *next = '\0'; + auto values = Tokenizer(utils::trim_comment(buf)).as_vector(); + if (values.size() != nwords) + error->all(FLERR, "Incorrect atom format in data file: {}", utils::trim(buf)); - for (j = 0; j < nwords; j++) { - buf += strspn(buf," \t\n\r\f"); - buf[strcspn(buf," \t\n\r\f")] = '\0'; - values[j] = buf; - buf += strlen(buf)+1; - } - - tagdata = ATOTAGINT(values[0]) + id_offset; + tagint tagdata = utils::tnumeric(FLERR,values[0],false,lmp) + id_offset; if (tagdata <= 0 || tagdata > map_tag_max) error->one(FLERR,"Invalid atom ID in Bonus section of data file"); // ok to call child's data_atom_bonus() method thru parent avec_bonus, // since data_bonus() was called with child ptr, and method is virtual - if ((m = map(tagdata)) >= 0) avec_bonus->data_atom_bonus(m,&values[1]); + if ((m = map(tagdata)) >= 0) avec_bonus->data_atom_bonus(m,values); buf = next + 1; } - - delete [] values; } /* ---------------------------------------------------------------------- @@ -1628,12 +1620,13 @@ void Atom::data_bonus(int n, char *buf, AtomVec *avec_bonus, tagint id_offset) void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset) { - int j,m,nvalues,tagdata,ninteger,ndouble; + int j,m,nvalues,ninteger,ndouble; int maxint = 0; int maxdouble = 0; int *ivalues = nullptr; double *dvalues = nullptr; + char *next; if (!unique_tags) unique_tags = new std::set; @@ -1642,10 +1635,13 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset) // else skip values for (int i = 0; i < n; i++) { - buf += strspn(buf," \t\n\r\f"); - buf[strcspn(buf," \t\n\r\f")] = '\0'; - tagdata = utils::tnumeric(FLERR,buf,false,lmp) + id_offset; - buf += strlen(buf)+1; + next = strchr(buf,'\n'); + *next = '\0'; + + auto values = Tokenizer(utils::trim_comment(buf)).as_vector(); + tagint tagdata = utils::tnumeric(FLERR,values[0],false,lmp) + id_offset; + ninteger = utils::inumeric(FLERR,values[1],false,lmp); + ndouble = utils::inumeric(FLERR,values[2],false,lmp); if (tagdata <= 0 || tagdata > map_tag_max) error->one(FLERR,"Invalid atom ID in Bodies section of data file"); @@ -1655,24 +1651,21 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset) else error->one(FLERR,"Duplicate atom ID in Bodies section of data file"); - buf += strspn(buf," \t\n\r\f"); - buf[strcspn(buf," \t\n\r\f")] = '\0'; - ninteger = utils::inumeric(FLERR,buf,false,lmp); - buf += strlen(buf)+1; + if (ninteger < 0) + error->one(FLERR,"Invalid number of integers in Bodies section of data file"); + if (ndouble < 0) + error->one(FLERR,"Invalid number of doubles in Bodies section of data file"); - buf += strspn(buf," \t\n\r\f"); - buf[strcspn(buf," \t\n\r\f")] = '\0'; - ndouble = utils::inumeric(FLERR,buf,false,lmp); - buf += strlen(buf)+1; - - if ((m = map(tagdata)) >= 0) { + buf = next + 1; + m = map(tagdata); + if (m >= 0) { if (ninteger > maxint) { - delete [] ivalues; + delete[] ivalues; maxint = ninteger; ivalues = new int[maxint]; } if (ndouble > maxdouble) { - delete [] dvalues; + delete[] dvalues; maxdouble = ndouble; dvalues = new double[maxdouble]; } @@ -1703,8 +1696,8 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset) } } - delete [] ivalues; - delete [] dvalues; + delete[] ivalues; + delete[] dvalues; } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec.h b/src/atom_vec.h index 57ca96e6e4..6bc7f23532 100644 --- a/src/atom_vec.h +++ b/src/atom_vec.h @@ -126,7 +126,7 @@ class AtomVec : protected Pointers { virtual void data_atom(double *, imageint, const std::vector &); virtual void data_atom_post(int) {} - virtual void data_atom_bonus(int, char **) {} + virtual void data_atom_bonus(int, const std::vector &) {} virtual void data_body(int, int, int, int *, double *) {} virtual void data_bonds_post(int, int, tagint, tagint, tagint) {} diff --git a/src/atom_vec_ellipsoid.cpp b/src/atom_vec_ellipsoid.cpp index 38c4893f61..6c39e4cfaf 100644 --- a/src/atom_vec_ellipsoid.cpp +++ b/src/atom_vec_ellipsoid.cpp @@ -381,7 +381,7 @@ int AtomVecEllipsoid::unpack_restart_bonus(int ilocal, double *buf) unpack one line from Ellipsoids section of data file ------------------------------------------------------------------------- */ -void AtomVecEllipsoid::data_atom_bonus(int m, char **values) +void AtomVecEllipsoid::data_atom_bonus(int m, const std::vector & values) { if (ellipsoid[m]) error->one(FLERR,"Assigning ellipsoid parameters to non-ellipsoid atom"); @@ -389,17 +389,18 @@ void AtomVecEllipsoid::data_atom_bonus(int m, char **values) if (nlocal_bonus == nmax_bonus) grow_bonus(); double *shape = bonus[nlocal_bonus].shape; - shape[0] = 0.5 * utils::numeric(FLERR,values[0],true,lmp); - shape[1] = 0.5 * utils::numeric(FLERR,values[1],true,lmp); - shape[2] = 0.5 * utils::numeric(FLERR,values[2],true,lmp); + int ivalue = 1; + shape[0] = 0.5 * utils::numeric(FLERR,values[ivalue++],true,lmp); + shape[1] = 0.5 * utils::numeric(FLERR,values[ivalue++],true,lmp); + shape[2] = 0.5 * utils::numeric(FLERR,values[ivalue++],true,lmp); if (shape[0] <= 0.0 || shape[1] <= 0.0 || shape[2] <= 0.0) error->one(FLERR,"Invalid shape in Ellipsoids section of data file"); double *quat = bonus[nlocal_bonus].quat; - quat[0] = utils::numeric(FLERR,values[3],true,lmp); - quat[1] = utils::numeric(FLERR,values[4],true,lmp); - quat[2] = utils::numeric(FLERR,values[5],true,lmp); - quat[3] = utils::numeric(FLERR,values[6],true,lmp); + quat[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); + quat[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); + quat[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); + quat[3] = utils::numeric(FLERR,values[ivalue++],true,lmp); MathExtra::qnormalize(quat); // reset ellipsoid mass diff --git a/src/atom_vec_ellipsoid.h b/src/atom_vec_ellipsoid.h index 6a77d9886c..bb50944f30 100644 --- a/src/atom_vec_ellipsoid.h +++ b/src/atom_vec_ellipsoid.h @@ -48,7 +48,7 @@ class AtomVecEllipsoid : public AtomVec { int size_restart_bonus(); int pack_restart_bonus(int, double *); int unpack_restart_bonus(int, double *); - void data_atom_bonus(int, char **); + void data_atom_bonus(int, const std::vector &); double memory_usage_bonus(); void create_atom_post(int); diff --git a/src/atom_vec_line.cpp b/src/atom_vec_line.cpp index bfc6c7e6d7..e15bc61f2f 100644 --- a/src/atom_vec_line.cpp +++ b/src/atom_vec_line.cpp @@ -337,16 +337,17 @@ int AtomVecLine::unpack_restart_bonus(int ilocal, double *buf) unpack one line from Lines section of data file ------------------------------------------------------------------------- */ -void AtomVecLine::data_atom_bonus(int m, char **values) +void AtomVecLine::data_atom_bonus(int m, const std::vector &values) { if (line[m]) error->one(FLERR,"Assigning line parameters to non-line atom"); if (nlocal_bonus == nmax_bonus) grow_bonus(); - double x1 = utils::numeric(FLERR,values[0],true,lmp); - double y1 = utils::numeric(FLERR,values[1],true,lmp); - double x2 = utils::numeric(FLERR,values[2],true,lmp); - double y2 = utils::numeric(FLERR,values[3],true,lmp); + int ivalue = 1; + double x1 = utils::numeric(FLERR,values[ivalue++],true,lmp); + double y1 = utils::numeric(FLERR,values[ivalue++],true,lmp); + double x2 = utils::numeric(FLERR,values[ivalue++],true,lmp); + double y2 = utils::numeric(FLERR,values[ivalue++],true,lmp); double dx = x2 - x1; double dy = y2 - y1; double length = sqrt(dx*dx + dy*dy); diff --git a/src/atom_vec_line.h b/src/atom_vec_line.h index 176cfc0dd9..5903349700 100644 --- a/src/atom_vec_line.h +++ b/src/atom_vec_line.h @@ -48,7 +48,7 @@ class AtomVecLine : public AtomVec { int size_restart_bonus(); int pack_restart_bonus(int, double *); int unpack_restart_bonus(int, double *); - void data_atom_bonus(int, char **); + void data_atom_bonus(int, const std::vector &); double memory_usage_bonus(); void create_atom_post(int); diff --git a/src/atom_vec_tri.cpp b/src/atom_vec_tri.cpp index 6a1cad5f5c..4b1ee0d921 100644 --- a/src/atom_vec_tri.cpp +++ b/src/atom_vec_tri.cpp @@ -470,22 +470,23 @@ int AtomVecTri::unpack_restart_bonus(int ilocal, double *buf) unpack one line from Tris section of data file ------------------------------------------------------------------------- */ -void AtomVecTri::data_atom_bonus(int m, char **values) +void AtomVecTri::data_atom_bonus(int m, const std::vector &values) { if (tri[m]) error->one(FLERR,"Assigning tri parameters to non-tri atom"); if (nlocal_bonus == nmax_bonus) grow_bonus(); double c1[3],c2[3],c3[3]; - c1[0] = utils::numeric(FLERR,values[0],true,lmp); - c1[1] = utils::numeric(FLERR,values[1],true,lmp); - c1[2] = utils::numeric(FLERR,values[2],true,lmp); - c2[0] = utils::numeric(FLERR,values[3],true,lmp); - c2[1] = utils::numeric(FLERR,values[4],true,lmp); - c2[2] = utils::numeric(FLERR,values[5],true,lmp); - c3[0] = utils::numeric(FLERR,values[6],true,lmp); - c3[1] = utils::numeric(FLERR,values[7],true,lmp); - c3[2] = utils::numeric(FLERR,values[8],true,lmp); + int ivalue = 1; + c1[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c1[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c1[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c2[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c2[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c2[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c3[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c3[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c3[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); // check for duplicate points diff --git a/src/atom_vec_tri.h b/src/atom_vec_tri.h index 36ec8d6948..f9f0bae386 100644 --- a/src/atom_vec_tri.h +++ b/src/atom_vec_tri.h @@ -50,7 +50,7 @@ class AtomVecTri : public AtomVec { int size_restart_bonus(); int pack_restart_bonus(int, double *); int unpack_restart_bonus(int, double *); - void data_atom_bonus(int, char **); + void data_atom_bonus(int, const std::vector &); double memory_usage_bonus(); void create_atom_post(int);