diff --git a/src/read_data.cpp b/src/read_data.cpp index bf96fa362a..2fea75f7c0 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -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) { diff --git a/src/write_data.cpp b/src/write_data.cpp index 8410fa7e81..dd5b056ae8 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -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);