diff --git a/src/run.cpp b/src/run.cpp index a026580c83..3a9a4dc32e 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -36,7 +36,7 @@ Run::Run(LAMMPS *lmp) : Command(lmp) {} void Run::command(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Illegal run command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "run", error); if (domain->box_exist == 0) error->all(FLERR,"Run command before simulation box is defined"); @@ -62,25 +62,25 @@ void Run::command(int narg, char **arg) int iarg = 1; while (iarg < narg) { if (strcmp(arg[iarg],"upto") == 0) { - if (iarg+1 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+1 > narg) utils::missing_cmd_args(FLERR, "run upto", error); uptoflag = 1; iarg += 1; } else if (strcmp(arg[iarg],"start") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run start", error); startflag = 1; start = utils::bnumeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"stop") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run stop", error); stopflag = 1; stop = utils::bnumeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"pre") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run pre", error); preflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"post") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run post", error); postflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; @@ -89,15 +89,15 @@ void Run::command(int narg, char **arg) // set ncommands = 0 if single command and it is "NULL" } else if (strcmp(arg[iarg],"every") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "run every", error); nevery = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - if (nevery <= 0) error->all(FLERR,"Illegal run command"); + if (nevery <= 0) error->all(FLERR, "Invalid run every argument: {}", nevery); first = iarg+2; last = narg-1; ncommands = last-first + 1; if (ncommands == 1 && strcmp(arg[first],"NULL") == 0) ncommands = 0; iarg = narg; - } else error->all(FLERR,"Illegal run command"); + } else error->all(FLERR,"Unknown run keyword: {}", arg[iarg]); } // set nsteps as integer, using upto value if specified @@ -105,12 +105,12 @@ void Run::command(int narg, char **arg) int nsteps; if (!uptoflag) { if (nsteps_input < 0 || nsteps_input > MAXSMALLINT) - error->all(FLERR,"Invalid run command N value"); + error->all(FLERR,"Invalid run command N value: {}", nsteps_input); nsteps = static_cast (nsteps_input); } else { bigint delta = nsteps_input - update->ntimestep; if (delta < 0 || delta > MAXSMALLINT) - error->all(FLERR,"Invalid run command upto value"); + error->all(FLERR,"Invalid run command upto value: {}", delta); nsteps = static_cast (delta); } @@ -118,13 +118,13 @@ void Run::command(int narg, char **arg) if (startflag) { if (start < 0) - error->all(FLERR,"Invalid run command start/stop value"); + error->all(FLERR,"Invalid run command start value: {}", start); if (start > update->ntimestep) error->all(FLERR,"Run command start value is after start of run"); } if (stopflag) { if (stop < 0) - error->all(FLERR,"Invalid run command start/stop value"); + error->all(FLERR,"Invalid run command stop value: {}", stop); if (stop < update->ntimestep + nsteps) error->all(FLERR,"Run command stop value is before end of run"); } diff --git a/src/variable.cpp b/src/variable.cpp index a564847b68..d6eec9eeb3 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -162,7 +162,7 @@ Variable::~Variable() void Variable::set(int narg, char **arg) { - if (narg < 2) error->all(FLERR,"Illegal variable command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "variable", error); int replaceflag = 0; @@ -170,7 +170,7 @@ void Variable::set(int narg, char **arg) // doesn't matter if variable no longer exists if (strcmp(arg[1],"delete") == 0) { - if (narg != 2) error->all(FLERR,"Illegal variable command"); + if (narg != 2) error->all(FLERR,"Illegal variable command: expected 2 argument but found {}", narg); if (find(arg[0]) >= 0) remove(find(arg[0])); return; @@ -178,7 +178,7 @@ void Variable::set(int narg, char **arg) // num = listed args, which = 1st value, data = copied args } else if (strcmp(arg[1],"index") == 0) { - if (narg < 3) error->all(FLERR,"Illegal variable command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "variable index", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = INDEX; @@ -193,6 +193,7 @@ void Variable::set(int narg, char **arg) // 2 args + pad: num = N2, which = N1, data = single string } else if (strcmp(arg[1],"loop") == 0) { + if (narg < 3) utils::missing_cmd_args(FLERR, "variable loop", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = LOOP; @@ -200,7 +201,7 @@ void Variable::set(int narg, char **arg) if (narg == 3 || (narg == 4 && strcmp(arg[3],"pad") == 0)) { nfirst = 1; nlast = utils::inumeric(FLERR,arg[2],false,lmp); - if (nlast <= 0) error->all(FLERR,"Illegal variable command"); + if (nlast <= 0) error->all(FLERR, "Invalid variable loop argument: {}", nlast); if (narg == 4 && strcmp(arg[3],"pad") == 0) { pad[nvar] = fmt::format("{}",nlast).size(); } else pad[nvar] = 0; @@ -208,11 +209,11 @@ void Variable::set(int narg, char **arg) nfirst = utils::inumeric(FLERR,arg[2],false,lmp); nlast = utils::inumeric(FLERR,arg[3],false,lmp); if (nfirst > nlast || nlast < 0) - error->all(FLERR,"Illegal variable command"); + error->all(FLERR,"Illegal variable loop command: {} > {}", nfirst,nlast); if (narg == 5 && strcmp(arg[4],"pad") == 0) { pad[nvar] = fmt::format("{}",nlast).size(); } else pad[nvar] = 0; - } else error->all(FLERR,"Illegal variable command"); + } else error->all(FLERR,"Illegal variable loop command: too much arguments"); num[nvar] = nlast; which[nvar] = nfirst-1; data[nvar] = new char*[1]; @@ -223,7 +224,7 @@ void Variable::set(int narg, char **arg) // error check that num = # of worlds in universe } else if (strcmp(arg[1],"world") == 0) { - if (narg < 3) error->all(FLERR,"Illegal variable command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "variable world", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = WORLD; @@ -244,7 +245,7 @@ void Variable::set(int narg, char **arg) } else if (strcmp(arg[1],"universe") == 0 || strcmp(arg[1],"uloop") == 0) { if (strcmp(arg[1],"universe") == 0) { - if (narg < 3) error->all(FLERR,"Illegal variable command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "variable universe", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = UNIVERSE; @@ -253,8 +254,10 @@ void Variable::set(int narg, char **arg) data[nvar] = new char*[num[nvar]]; copy(num[nvar],&arg[2],data[nvar]); } else if (strcmp(arg[1],"uloop") == 0) { - if (narg < 3 || narg > 4 || (narg == 4 && strcmp(arg[3],"pad") != 0)) - error->all(FLERR,"Illegal variable command"); + if (narg < 3 || narg > 4) + error->all(FLERR,"Illegal variable command: expected 3 or 4 arguments but found {}", narg); + if (narg == 4 && strcmp(arg[3],"pad") != 0) + error->all(FLERR, "Invalid variable uloop argument: {}", arg[3]); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = ULOOP; @@ -292,7 +295,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"string") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int maxcopy = strlen(arg[2]) + 1; int maxwork = maxcopy; @@ -326,7 +329,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"getenv") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (find(arg[0]) >= 0) { if (style[find(arg[0])] != GETENV) error->all(FLERR,"Cannot redefine variable as a different style"); @@ -346,7 +349,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"file") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = SCALARFILE; @@ -364,7 +367,7 @@ void Variable::set(int narg, char **arg) // data = nullptr } else if (strcmp(arg[1],"atomfile") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = ATOMFILE; @@ -384,7 +387,7 @@ void Variable::set(int narg, char **arg) // 3rd is filled on retrieval } else if (strcmp(arg[1],"format") == 0) { - if (narg != 4) error->all(FLERR,"Illegal variable command"); + if (narg != 4) error->all(FLERR,"Illegal variable command: expected 4 arguments but found {}", narg); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = FORMAT; @@ -404,7 +407,7 @@ void Variable::set(int narg, char **arg) // data = 2 values, 1st is string to eval, 2nd is filled on retrieval } else if (strcmp(arg[1],"equal") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != EQUAL) @@ -430,7 +433,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"atom") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != ATOM) @@ -454,7 +457,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"vector") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != VECTOR) @@ -478,7 +481,7 @@ void Variable::set(int narg, char **arg) // data = 2 values, 1st is Python func to invoke, 2nd is filled by invoke } else if (strcmp(arg[1],"python") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (!python->is_enabled()) error->all(FLERR,"LAMMPS is not built with Python embedded"); int ivar = find(arg[0]); @@ -507,7 +510,7 @@ void Variable::set(int narg, char **arg) // dvalue = numeric initialization via platform::walltime() } else if (strcmp(arg[1],"timer") == 0) { - if (narg != 2) error->all(FLERR,"Illegal variable command"); + if (narg != 2) error->all(FLERR,"Illegal variable command: expected 2 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != TIMER) @@ -531,7 +534,7 @@ void Variable::set(int narg, char **arg) // dvalue = numeric initialization from 2nd arg, reset by internal_set() } else if (strcmp(arg[1],"internal") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != INTERNAL) @@ -551,7 +554,7 @@ void Variable::set(int narg, char **arg) // unrecognized variable style - } else error->all(FLERR,"Illegal variable command"); + } else error->all(FLERR,"Unknown variable keyword: {}", arg[1]); // set name of variable, if not replacing one flagged with replaceflag // name must be all alphanumeric chars or underscores