diff --git a/src/timer.cpp b/src/timer.cpp index c8869039e4..f473a6768f 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -20,6 +20,7 @@ #endif #include "tokenizer.h" +#include #include #include @@ -216,46 +217,49 @@ double Timer::get_timeout_remain() /* ---------------------------------------------------------------------- modify parameters of the Timer class ------------------------------------------------------------------------- */ -static const char *timer_style[] = {"off", "loop", "normal", "full"}; -static const char *timer_mode[] = {"nosync", "(dummy)", "sync"}; +namespace { +const std::array timer_style = {"off", "loop", "normal", "full"}; +const std::array timer_mode = {"nosync", "(dummy)", "sync"}; +} void Timer::modify_params(int narg, char **arg) { int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg], timer_style[OFF]) == 0) { + const std::string argstr = arg[iarg]; + if (timer_style[OFF] == argstr) { _level = OFF; - } else if (strcmp(arg[iarg], timer_style[LOOP]) == 0) { + } else if (timer_style[LOOP] == argstr) { _level = LOOP; - } else if (strcmp(arg[iarg], timer_style[NORMAL]) == 0) { + } else if (timer_style[NORMAL] == argstr) { _level = NORMAL; - } else if (strcmp(arg[iarg], timer_style[FULL]) == 0) { + } else if (timer_style[FULL] == argstr) { _level = FULL; - } else if (strcmp(arg[iarg], timer_mode[OFF]) == 0) { + } else if (timer_mode[OFF] == argstr) { _sync = OFF; - } else if (strcmp(arg[iarg], timer_mode[NORMAL]) == 0) { + } else if (timer_mode[NORMAL] == argstr) { _sync = NORMAL; - } else if (strcmp(arg[iarg], "timeout") == 0) { + } else if (argstr == "timeout") { ++iarg; if (iarg < narg) { try { _timeout = utils::timespec2seconds(arg[iarg]); } catch (TokenizerException &) { - error->all(FLERR, "Illegal timeout time: {}", arg[iarg]); + error->all(FLERR, iarg, "Illegal timeout time: {}", argstr); } } else { utils::missing_cmd_args(FLERR, "timer timeout", error); } - } else if (strcmp(arg[iarg], "every") == 0) { + } else if (argstr == "every") { ++iarg; if (iarg < narg) { _checkfreq = utils::inumeric(FLERR, arg[iarg], false, lmp); - if (_checkfreq <= 0) error->all(FLERR, "Illegal timer every frequency: {}", arg[iarg]); + if (_checkfreq <= 0) error->all(FLERR, iarg, "Illegal timer every frequency: {}", argstr); } else { utils::missing_cmd_args(FLERR, "timer every", error); } } else { - error->all(FLERR, "Unknown timer keyword {}", arg[iarg]); + error->all(FLERR, iarg, "Unknown timer keyword {}", argstr); } ++iarg; } diff --git a/src/timer.h b/src/timer.h index 371a895d1f..2f3ddf2a5e 100644 --- a/src/timer.h +++ b/src/timer.h @@ -41,7 +41,7 @@ class Timer : protected Pointers { REPOUT, NUM_TIMER }; - enum tlevel { OFF = 0, LOOP, NORMAL, FULL }; + enum tlevel { OFF = 0, LOOP, NORMAL, FULL, NUMLVL }; Timer(class LAMMPS *);