From 576e7878399c02caeb426fca26be32ff27b32f3f Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Tue, 21 Dec 2021 12:18:26 -0700 Subject: [PATCH] make xyz dumps print out current simulation time --- src/COMPRESS/dump_xyz_gz.cpp | 11 +++++++---- src/COMPRESS/dump_xyz_zstd.cpp | 15 ++++++++++----- src/dump_xyz.cpp | 9 ++++++--- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/COMPRESS/dump_xyz_gz.cpp b/src/COMPRESS/dump_xyz_gz.cpp index cec32090cb..a43a27ca7d 100644 --- a/src/COMPRESS/dump_xyz_gz.cpp +++ b/src/COMPRESS/dump_xyz_gz.cpp @@ -94,11 +94,14 @@ void DumpXYZGZ::write_header(bigint ndump) { if (me == 0) { std::string header = fmt::format("{}\n", ndump); - if (time_flag) - header += fmt::format("Atoms. Timestep: {} Time: {:.6f}\n", - update->ntimestep, update->atime); - else + if (time_flag) { + double tcurrent = update->atime + + (update->ntimestep-update->atimestep) + update->dt; + fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT " Time: %f\n", + update->ntimestep, tcurrent); + } else { header += fmt::format("Atoms. Timestep: {}\n", update->ntimestep); + } writer.write(header.c_str(), header.length()); } } diff --git a/src/COMPRESS/dump_xyz_zstd.cpp b/src/COMPRESS/dump_xyz_zstd.cpp index 24d31fe671..e955a0e3ba 100644 --- a/src/COMPRESS/dump_xyz_zstd.cpp +++ b/src/COMPRESS/dump_xyz_zstd.cpp @@ -96,15 +96,20 @@ void DumpXYZZstd::openfile() if (multifile) delete[] filecurrent; } +/* ---------------------------------------------------------------------- */ + void DumpXYZZstd::write_header(bigint ndump) { if (me == 0) { std::string header = fmt::format("{}\n", ndump); - if (time_flag) - header += fmt::format("Atoms. Timestep: {} Time: {:.6f}\n", - update->ntimestep, update->atime); - else - header += fmt::format("Atoms. Timestep: {}\n", update->ntimestep); + if (time_flag) { + double tcurrent = update->atime + + (update->ntimestep-update->atimestep) + update->dt; + fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT " Time: %f\n", + update->ntimestep, tcurrent); + } else { + fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT "\n",update->ntimestep); + } writer.write(header.c_str(), header.length()); } } diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index db929f9d6e..26e84d145d 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -131,11 +131,14 @@ void DumpXYZ::write_header(bigint n) { if (me == 0) { fprintf(fp,BIGINT_FORMAT "\n",n); - if (time_flag) + if (time_flag) { + double tcurrent = update->atime + + (update->ntimestep-update->atimestep) + update->dt; fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT " Time: %f\n", - update->ntimestep, update->atime); - else + update->ntimestep, tcurrent); + } else { fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT "\n",update->ntimestep); + } } }