diff --git a/src/COMPRESS/dump_xyz_gz.cpp b/src/COMPRESS/dump_xyz_gz.cpp index f017cb3b3e..06561c6d9a 100644 --- a/src/COMPRESS/dump_xyz_gz.cpp +++ b/src/COMPRESS/dump_xyz_gz.cpp @@ -93,12 +93,11 @@ void DumpXYZGZ::openfile() void DumpXYZGZ::write_header(bigint ndump) { if (me == 0) { - std::string header = fmt::format("{}\n", ndump); - if (time_flag) - fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT " Time: %f\n", - update->ntimestep, compute_time()); - else - header += fmt::format("Atoms. Timestep: {}\n", update->ntimestep); + auto header = fmt::format("{}\n", ndump); + if (time_flag) { + double tcurrent = update->atime + (update->ntimestep-update->atimestep) + update->dt; + header += fmt::format(" Atoms. Timestep: {} Time: {:.6f}\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 46833f3c74..c4748b4ac3 100644 --- a/src/COMPRESS/dump_xyz_zstd.cpp +++ b/src/COMPRESS/dump_xyz_zstd.cpp @@ -101,12 +101,11 @@ void DumpXYZZstd::openfile() void DumpXYZZstd::write_header(bigint ndump) { if (me == 0) { - std::string header = fmt::format("{}\n", ndump); - if (time_flag) - fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT " Time: %f\n", - update->ntimestep, compute_time()); - else - fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT "\n",update->ntimestep); + auto header = fmt::format("{}\n", ndump); + if (time_flag) { + double tcurrent = update->atime + (update->ntimestep-update->atimestep) + update->dt; + header += fmt::format(" Atoms. Timestep: {} Time: {:.6f}\n", update->ntimestep, tcurrent); + } else header += fmt::format(" Atoms. Timestep: {}\n", update->ntimestep); writer.write(header.c_str(), header.length()); } } diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index 949ddf1a11..e90243fd1f 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -130,12 +130,10 @@ int DumpXYZ::modify_param(int narg, char **arg) void DumpXYZ::write_header(bigint n) { if (me == 0) { - fprintf(fp,BIGINT_FORMAT "\n",n); - if (time_flag) - fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT " Time: %f\n", - update->ntimestep, compute_time()); - else - fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT "\n",update->ntimestep); + if (time_flag) { + double tcurrent = update->atime + (update->ntimestep-update->atimestep) + update->dt; + fmt::print(fp,"{}\n Atoms. Timestep: {} Time: {:.6f}\n", n, update->ntimestep, tcurrent); + } else fmt::print(fp,"{}\n Atoms. Timestep: {}\n", n, update->ntimestep); } }