write out and check for unit settings marker in data files

This commit is contained in:
Axel Kohlmeyer
2023-03-31 08:10:50 -04:00
parent 9021129799
commit 63c86ccc61
2 changed files with 10 additions and 2 deletions

View File

@ -1154,6 +1154,14 @@ void ReadData::header(int firstpass)
if (me == 0) {
char *eof = utils::fgets_trunc(line, MAXLINE, fp);
if (eof == nullptr) error->one(FLERR, "Unexpected end of data file");
// check for units keyword in first line and print warning on mismatch
auto units = Tokenizer(utils::strfind(line, "units = \\w+")).as_vector();
if (units.size() > 2) {
if (units[2] != update->unit_style)
error->warning(FLERR, "Inconsistent units in data file: current = {}, data file = {}",
update->unit_style, units[2]);
}
}
while (true) {

View File

@ -245,8 +245,8 @@ void WriteData::write(const std::string &file)
void WriteData::header()
{
fmt::print(fp,"LAMMPS data file via write_data, version {}, "
"timestep = {}\n\n",lmp->version,update->ntimestep);
fmt::print(fp,"LAMMPS data file via write_data, version {}, timestep = {}, units = {}\n\n",
lmp->version, update->ntimestep, update->unit_style);
fmt::print(fp,"{} atoms\n{} atom types\n",atom->natoms,atom->ntypes);