simplify parsing numbers and reduce usage of BIGINT_FORMAT
This commit is contained in:
@ -1013,114 +1013,80 @@ void ReadData::header(int firstpass)
|
||||
|
||||
// search line for header keyword and set corresponding variable
|
||||
// customize for new header lines
|
||||
// check for triangles before angles so "triangles" not matched as "angles"
|
||||
|
||||
int extra_flag_value = 0;
|
||||
int rv;
|
||||
auto words = utils::split_words(line);
|
||||
|
||||
if (utils::strmatch(line,"^\\s*\\d+\\s+atoms\\s")) {
|
||||
rv = sscanf(line,BIGINT_FORMAT,&natoms);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'atoms' line in data file header");
|
||||
natoms = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->natoms = natoms;
|
||||
else if (firstpass) atom->natoms += natoms;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+ellipsoids\\s")) {
|
||||
if (!avec_ellipsoid)
|
||||
error->all(FLERR,"No ellipsoids allowed with this atom style");
|
||||
rv = sscanf(line,BIGINT_FORMAT,&nellipsoids);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'ellipsoids' line in data file header");
|
||||
if (!avec_ellipsoid) error->all(FLERR,"No ellipsoids allowed with this atom style");
|
||||
nellipsoids = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nellipsoids = nellipsoids;
|
||||
else if (firstpass) atom->nellipsoids += nellipsoids;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+lines\\s")) {
|
||||
if (!avec_line)
|
||||
error->all(FLERR,"No lines allowed with this atom style");
|
||||
rv = sscanf(line,BIGINT_FORMAT,&nlines);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'lines' line in data file header");
|
||||
if (!avec_line) error->all(FLERR,"No lines allowed with this atom style");
|
||||
nlines = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nlines = nlines;
|
||||
else if (firstpass) atom->nlines += nlines;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+triangles\\s")) {
|
||||
if (!avec_tri)
|
||||
error->all(FLERR,"No triangles allowed with this atom style");
|
||||
rv = sscanf(line,BIGINT_FORMAT,&ntris);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'triangles' line in data file header");
|
||||
if (!avec_tri) error->all(FLERR,"No triangles allowed with this atom style");
|
||||
ntris = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->ntris = ntris;
|
||||
else if (firstpass) atom->ntris += ntris;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+bodies\\s")) {
|
||||
if (!avec_body)
|
||||
error->all(FLERR,"No bodies allowed with this atom style");
|
||||
rv = sscanf(line,BIGINT_FORMAT,&nbodies);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'bodies' line in data file header");
|
||||
if (!avec_body) error->all(FLERR,"No bodies allowed with this atom style");
|
||||
nbodies = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nbodies = nbodies;
|
||||
else if (firstpass) atom->nbodies += nbodies;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+bonds\\s")) {
|
||||
rv = sscanf(line,BIGINT_FORMAT,&nbonds);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'bonds' line in data file header");
|
||||
nbonds = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nbonds = nbonds;
|
||||
else if (firstpass) atom->nbonds += nbonds;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+angles\\s")) {
|
||||
rv = sscanf(line,BIGINT_FORMAT,&nangles);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'angles' line in data file header");
|
||||
nangles = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nangles = nangles;
|
||||
else if (firstpass) atom->nangles += nangles;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+dihedrals\\s")) {
|
||||
rv = sscanf(line,BIGINT_FORMAT,&ndihedrals);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'dihedrals' line in data file header");
|
||||
ndihedrals = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->ndihedrals = ndihedrals;
|
||||
else if (firstpass) atom->ndihedrals += ndihedrals;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+impropers\\s")) {
|
||||
rv = sscanf(line,BIGINT_FORMAT,&nimpropers);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'impropers' line in data file header");
|
||||
nimpropers = utils::bnumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nimpropers = nimpropers;
|
||||
else if (firstpass) atom->nimpropers += nimpropers;
|
||||
|
||||
// Atom class type settings are only set by first data file
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+atom\\s+types\\s")) {
|
||||
rv = sscanf(line,"%d",&ntypes);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'atom types' line in data file header");
|
||||
ntypes = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->ntypes = ntypes + extra_atom_types;
|
||||
|
||||
} else if (utils::strmatch(line,"\\s*\\d+\\s+bond\\s+types\\s")) {
|
||||
rv = sscanf(line,"%d",&nbondtypes);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'bond types' line in data file header");
|
||||
nbondtypes = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nbondtypes = nbondtypes + extra_bond_types;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+angle\\s+types\\s")) {
|
||||
rv = sscanf(line,"%d",&nangletypes);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'angle types' line in data file header");
|
||||
nangletypes = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nangletypes = nangletypes + extra_angle_types;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+dihedral\\s+types\\s")) {
|
||||
rv = sscanf(line,"%d",&ndihedraltypes);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'dihedral types' line in data file header");
|
||||
if (addflag == NONE)
|
||||
atom->ndihedraltypes = ndihedraltypes + extra_dihedral_types;
|
||||
ndihedraltypes = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->ndihedraltypes = ndihedraltypes + extra_dihedral_types;
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\d+\\s+improper\\s+types\\s")) {
|
||||
rv = sscanf(line,"%d",&nimpropertypes);
|
||||
if (rv != 1)
|
||||
error->all(FLERR,"Could not parse 'improper types' line in data file header");
|
||||
if (addflag == NONE)
|
||||
atom->nimpropertypes = nimpropertypes + extra_improper_types;
|
||||
nimpropertypes = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
if (addflag == NONE) atom->nimpropertypes = nimpropertypes + extra_improper_types;
|
||||
|
||||
// these settings only used by first data file
|
||||
// also, these are obsolescent. we parse them to maintain backward
|
||||
@ -1129,45 +1095,41 @@ void ReadData::header(int firstpass)
|
||||
// the input and the data file, we use the larger of the two.
|
||||
|
||||
} else if (strstr(line,"extra bond per atom")) {
|
||||
if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
|
||||
if (addflag == NONE) extra_flag_value = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
atom->extra_bond_per_atom = MAX(atom->extra_bond_per_atom,extra_flag_value);
|
||||
} else if (strstr(line,"extra angle per atom")) {
|
||||
if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
|
||||
if (addflag == NONE) extra_flag_value = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
atom->extra_angle_per_atom = MAX(atom->extra_angle_per_atom,extra_flag_value);
|
||||
} else if (strstr(line,"extra dihedral per atom")) {
|
||||
if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
|
||||
if (addflag == NONE) extra_flag_value = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
atom->extra_dihedral_per_atom = MAX(atom->extra_dihedral_per_atom,extra_flag_value);
|
||||
} else if (strstr(line,"extra improper per atom")) {
|
||||
if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
|
||||
if (addflag == NONE) extra_flag_value = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
atom->extra_improper_per_atom = MAX(atom->extra_improper_per_atom,extra_flag_value);
|
||||
} else if (strstr(line,"extra special per atom")) {
|
||||
if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
|
||||
if (addflag == NONE) extra_flag_value = utils::inumeric(FLERR, words[0], false, lmp);
|
||||
force->special_extra = MAX(force->special_extra,extra_flag_value);
|
||||
|
||||
// local copy of box info
|
||||
// so can treat differently for first vs subsequent data files
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\f+\\s+\\f+\\s+xlo\\s+xhi\\s")) {
|
||||
rv = sscanf(line,"%lg %lg",&boxlo[0],&boxhi[0]);
|
||||
if (rv != 2)
|
||||
error->all(FLERR,"Could not parse 'xlo xhi' line in data file header");
|
||||
boxlo[0] = utils::numeric(FLERR, words[0], false, lmp);
|
||||
boxhi[0] = utils::numeric(FLERR, words[1], false, lmp);
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\f+\\s+\\f+\\s+ylo\\s+yhi\\s")) {
|
||||
rv = sscanf(line,"%lg %lg",&boxlo[1],&boxhi[1]);
|
||||
if (rv != 2)
|
||||
error->all(FLERR,"Could not parse 'ylo yhi' line in data file header");
|
||||
boxlo[1] = utils::numeric(FLERR, words[0], false, lmp);
|
||||
boxhi[1] = utils::numeric(FLERR, words[1], false, lmp);
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\f+\\s+\\f+\\s+zlo\\s+zhi\\s")) {
|
||||
rv = sscanf(line,"%lg %lg",&boxlo[2],&boxhi[2]);
|
||||
if (rv != 2)
|
||||
error->all(FLERR,"Could not parse 'zlo zhi' line in data file header");
|
||||
boxlo[2] = utils::numeric(FLERR, words[0], false, lmp);
|
||||
boxhi[2] = utils::numeric(FLERR, words[1], false, lmp);
|
||||
|
||||
} else if (utils::strmatch(line,"^\\s*\\f+\\s+\\f+\\s+\\f+"
|
||||
"\\s+xy\\s+xz\\s+yz\\s")) {
|
||||
} else if (utils::strmatch(line,"^\\s*\\f+\\s+\\f+\\s+\\f+\\s+xy\\s+xz\\s+yz\\s")) {
|
||||
triclinic = 1;
|
||||
rv = sscanf(line,"%lg %lg %lg",&xy,&xz,&yz);
|
||||
if (rv != 3)
|
||||
error->all(FLERR,"Could not parse 'xy xz yz' line in data file header");
|
||||
xy = utils::numeric(FLERR, words[0], false, lmp);
|
||||
xz = utils::numeric(FLERR, words[0], false, lmp);
|
||||
yz = utils::numeric(FLERR, words[0], false, lmp);
|
||||
|
||||
} else break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user