modernize argument processing and error messages
This commit is contained in:
@ -20,6 +20,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
@ -216,46 +217,49 @@ double Timer::get_timeout_remain()
|
|||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
modify parameters of the Timer class
|
modify parameters of the Timer class
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
static const char *timer_style[] = {"off", "loop", "normal", "full"};
|
namespace {
|
||||||
static const char *timer_mode[] = {"nosync", "(dummy)", "sync"};
|
const std::array<const std::string, Timer::NUMLVL> timer_style = {"off", "loop", "normal", "full"};
|
||||||
|
const std::array<const std::string, 3> timer_mode = {"nosync", "(dummy)", "sync"};
|
||||||
|
}
|
||||||
|
|
||||||
void Timer::modify_params(int narg, char **arg)
|
void Timer::modify_params(int narg, char **arg)
|
||||||
{
|
{
|
||||||
int iarg = 0;
|
int iarg = 0;
|
||||||
while (iarg < narg) {
|
while (iarg < narg) {
|
||||||
if (strcmp(arg[iarg], timer_style[OFF]) == 0) {
|
const std::string argstr = arg[iarg];
|
||||||
|
if (timer_style[OFF] == argstr) {
|
||||||
_level = OFF;
|
_level = OFF;
|
||||||
} else if (strcmp(arg[iarg], timer_style[LOOP]) == 0) {
|
} else if (timer_style[LOOP] == argstr) {
|
||||||
_level = LOOP;
|
_level = LOOP;
|
||||||
} else if (strcmp(arg[iarg], timer_style[NORMAL]) == 0) {
|
} else if (timer_style[NORMAL] == argstr) {
|
||||||
_level = NORMAL;
|
_level = NORMAL;
|
||||||
} else if (strcmp(arg[iarg], timer_style[FULL]) == 0) {
|
} else if (timer_style[FULL] == argstr) {
|
||||||
_level = FULL;
|
_level = FULL;
|
||||||
} else if (strcmp(arg[iarg], timer_mode[OFF]) == 0) {
|
} else if (timer_mode[OFF] == argstr) {
|
||||||
_sync = OFF;
|
_sync = OFF;
|
||||||
} else if (strcmp(arg[iarg], timer_mode[NORMAL]) == 0) {
|
} else if (timer_mode[NORMAL] == argstr) {
|
||||||
_sync = NORMAL;
|
_sync = NORMAL;
|
||||||
} else if (strcmp(arg[iarg], "timeout") == 0) {
|
} else if (argstr == "timeout") {
|
||||||
++iarg;
|
++iarg;
|
||||||
if (iarg < narg) {
|
if (iarg < narg) {
|
||||||
try {
|
try {
|
||||||
_timeout = utils::timespec2seconds(arg[iarg]);
|
_timeout = utils::timespec2seconds(arg[iarg]);
|
||||||
} catch (TokenizerException &) {
|
} catch (TokenizerException &) {
|
||||||
error->all(FLERR, "Illegal timeout time: {}", arg[iarg]);
|
error->all(FLERR, iarg, "Illegal timeout time: {}", argstr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
utils::missing_cmd_args(FLERR, "timer timeout", error);
|
utils::missing_cmd_args(FLERR, "timer timeout", error);
|
||||||
}
|
}
|
||||||
} else if (strcmp(arg[iarg], "every") == 0) {
|
} else if (argstr == "every") {
|
||||||
++iarg;
|
++iarg;
|
||||||
if (iarg < narg) {
|
if (iarg < narg) {
|
||||||
_checkfreq = utils::inumeric(FLERR, arg[iarg], false, lmp);
|
_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 {
|
} else {
|
||||||
utils::missing_cmd_args(FLERR, "timer every", error);
|
utils::missing_cmd_args(FLERR, "timer every", error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error->all(FLERR, "Unknown timer keyword {}", arg[iarg]);
|
error->all(FLERR, iarg, "Unknown timer keyword {}", argstr);
|
||||||
}
|
}
|
||||||
++iarg;
|
++iarg;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class Timer : protected Pointers {
|
|||||||
REPOUT,
|
REPOUT,
|
||||||
NUM_TIMER
|
NUM_TIMER
|
||||||
};
|
};
|
||||||
enum tlevel { OFF = 0, LOOP, NORMAL, FULL };
|
enum tlevel { OFF = 0, LOOP, NORMAL, FULL, NUMLVL };
|
||||||
|
|
||||||
Timer(class LAMMPS *);
|
Timer(class LAMMPS *);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user