implement utils::current_date() convenience function to reduce replicated code

This commit is contained in:
Axel Kohlmeyer
2021-09-18 09:05:35 -04:00
parent 5a6c1abeed
commit db76edbade
9 changed files with 64 additions and 49 deletions

View File

@ -23,9 +23,6 @@
#include "neighbor.h"
#include "suffix.h"
#include "update.h"
#include "fmt/chrono.h"
#include <ctime>
using namespace LAMMPS_NS;
@ -276,26 +273,21 @@ void Bond::write_file(int narg, char **arg)
if (utils::file_is_readable(table_file)) {
std::string units = utils::get_potential_units(table_file,"table");
if (!units.empty() && (units != update->unit_style)) {
error->one(FLERR,"Trying to append to a table file "
"with UNITS: {} while units are {}",
units, update->unit_style);
error->one(FLERR,"Trying to append to a table file with UNITS: {} while units are {}",
units, update->unit_style);
}
std::string date = utils::get_potential_date(table_file,"table");
utils::logmesg(lmp,"Appending to table file {} with "
"DATE: {}\n", table_file, date);
utils::logmesg(lmp,"Appending to table file {} with DATE: {}\n", table_file, date);
fp = fopen(table_file.c_str(),"a");
} else {
time_t tv = time(nullptr);
std::tm current_date = fmt::localtime(tv);
utils::logmesg(lmp,"Creating table file {} with "
"DATE: {:%Y-%m-%d}\n", table_file, current_date);
utils::logmesg(lmp,"Creating table file {} with DATE: {}\n",
table_file, utils::current_date());
fp = fopen(table_file.c_str(),"w");
if (fp) fmt::print(fp,"# DATE: {:%Y-%m-%d} UNITS: {} Created by bond_write\n",
current_date, update->unit_style);
if (fp) fmt::print(fp,"# DATE: {} UNITS: {} Created by bond_write\n",
utils::current_date(), update->unit_style);
}
if (fp == nullptr)
error->one(FLERR,"Cannot open bond_write file {}: {}",
arg[4], utils::getsyserror());
error->one(FLERR,"Cannot open bond_write file {}: {}", arg[4], utils::getsyserror());
}
// initialize potentials before evaluating bond potential