From 00fd82016cc6feffd54b746c38a7138a04d4f33b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 3 Jun 2020 22:52:49 -0400 Subject: [PATCH] simplify Domain::print_box() --- src/domain.cpp | 36 ++++++++++++------------------------ src/domain.h | 2 +- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/domain.cpp b/src/domain.cpp index e1a9744fde..9cd375de71 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -39,6 +39,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -1935,33 +1936,20 @@ void Domain::set_box(int narg, char **arg) print box info, orthogonal or triclinic ------------------------------------------------------------------------- */ -void Domain::print_box(const char *str) +void Domain::print_box(const std::string &prefix) { if (comm->me == 0) { - if (screen) { - if (triclinic == 0) - fprintf(screen,"%sorthogonal box = (%g %g %g) to (%g %g %g)\n", - str,boxlo[0],boxlo[1],boxlo[2],boxhi[0],boxhi[1],boxhi[2]); - else { - char *format = (char *) - "%striclinic box = (%g %g %g) to (%g %g %g) with tilt (%g %g %g)\n"; - fprintf(screen,format, - str,boxlo[0],boxlo[1],boxlo[2],boxhi[0],boxhi[1],boxhi[2], - xy,xz,yz); - } - } - if (logfile) { - if (triclinic == 0) - fprintf(logfile,"%sorthogonal box = (%g %g %g) to (%g %g %g)\n", - str,boxlo[0],boxlo[1],boxlo[2],boxhi[0],boxhi[1],boxhi[2]); - else { - char *format = (char *) - "%striclinic box = (%g %g %g) to (%g %g %g) with tilt (%g %g %g)\n"; - fprintf(logfile,format, - str,boxlo[0],boxlo[1],boxlo[2],boxhi[0],boxhi[1],boxhi[2], - xy,xz,yz); - } + std::string mesg = prefix; + if (triclinic == 0) { + mesg += fmt::format("orthogonal box = ({} {} {}) to ({} {} {})\n", + boxlo[0],boxlo[1],boxlo[2], + boxhi[0],boxhi[1],boxhi[2]); + } else { + mesg += fmt::format("triclinic box = ({} {} {}) to ({} {} {}) " + "with tilt ({} {} {})\n",boxlo[0],boxlo[1], + boxlo[2],boxhi[0],boxhi[1],boxhi[2],xy,xz,yz); } + utils::logmesg(lmp,mesg); } } diff --git a/src/domain.h b/src/domain.h index 0ce31a8b4a..58b935ce01 100644 --- a/src/domain.h +++ b/src/domain.h @@ -131,7 +131,7 @@ class Domain : protected Pointers { int find_region(char *); void set_boundary(int, char **, int); void set_box(int, char **); - void print_box(const char *); + void print_box(const std::string &); void boundary_string(char *); virtual void lamda2x(int);