diff --git a/src/COLVARS/fix_colvars.cpp b/src/COLVARS/fix_colvars.cpp index 5ee77768c6..32211f7689 100644 --- a/src/COLVARS/fix_colvars.cpp +++ b/src/COLVARS/fix_colvars.cpp @@ -312,32 +312,26 @@ FixColvars::FixColvars(LAMMPS *lmp, int narg, char **arg) : tmp_name = nullptr; /* parse optional arguments */ - int argsdone = 4; - while (argsdone < narg) { + int iarg = 4; + while (iarg < narg) { // we have keyword/value pairs. check if value is missing - if (argsdone+1 == narg) + if (iarg+1 == narg) error->all(FLERR,"Missing argument to keyword"); - if (0 == strcmp(arg[argsdone], "input")) { - inp_name = strdup(arg[argsdone+1]); - } else if (0 == strcmp(arg[argsdone], "output")) { - out_name = strdup(arg[argsdone+1]); - } else if (0 == strcmp(arg[argsdone], "seed")) { - rng_seed = utils::inumeric(FLERR,arg[argsdone+1],false,lmp); - } else if (0 == strcmp(arg[argsdone], "unwrap")) { - if (0 == strcmp(arg[argsdone+1], "yes")) { - unwrap_flag = 1; - } else if (0 == strcmp(arg[argsdone+1], "no")) { - unwrap_flag = 0; - } else { - error->all(FLERR,"Incorrect fix colvars unwrap flag"); - } - } else if (0 == strcmp(arg[argsdone], "tstat")) { - tmp_name = strdup(arg[argsdone+1]); + if (0 == strcmp(arg[iarg], "input")) { + inp_name = strdup(arg[iarg+1]); + } else if (0 == strcmp(arg[iarg], "output")) { + out_name = strdup(arg[iarg+1]); + } else if (0 == strcmp(arg[iarg], "seed")) { + rng_seed = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + } else if (0 == strcmp(arg[iarg], "unwrap")) { + unwrap_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (0 == strcmp(arg[iarg], "tstat")) { + tmp_name = strdup(arg[iarg+1]); } else { error->all(FLERR,"Unknown fix colvars parameter"); } - ++argsdone; ++argsdone; + ++iarg; ++iarg; } if (!out_name) out_name = strdup("out"); diff --git a/src/COMPRESS/dump_atom_zstd.cpp b/src/COMPRESS/dump_atom_zstd.cpp index aa9d14b324..a23ea2025b 100644 --- a/src/COMPRESS/dump_atom_zstd.cpp +++ b/src/COMPRESS/dump_atom_zstd.cpp @@ -188,17 +188,11 @@ int DumpAtomZstd::modify_param(int narg, char **arg) try { if (strcmp(arg[0], "checksum") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - if (strcmp(arg[1], "yes") == 0) - writer.setChecksum(true); - else if (strcmp(arg[1], "no") == 0) - writer.setChecksum(false); - else - error->all(FLERR, "Illegal dump_modify command"); + writer.setChecksum(utils::logical(FLERR, arg[1], false, lmp) == 1); return 2; } else if (strcmp(arg[0], "compression_level") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - int compression_level = utils::inumeric(FLERR, arg[1], false, lmp); - writer.setCompressionLevel(compression_level); + writer.setCompressionLevel(utils::inumeric(FLERR, arg[1], false, lmp)); return 2; } } catch (FileWriterException &e) { diff --git a/src/COMPRESS/dump_cfg_zstd.cpp b/src/COMPRESS/dump_cfg_zstd.cpp index 15ea1e540c..73ee3e7e11 100644 --- a/src/COMPRESS/dump_cfg_zstd.cpp +++ b/src/COMPRESS/dump_cfg_zstd.cpp @@ -233,17 +233,11 @@ int DumpCFGZstd::modify_param(int narg, char **arg) try { if (strcmp(arg[0], "checksum") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - if (strcmp(arg[1], "yes") == 0) - writer.setChecksum(true); - else if (strcmp(arg[1], "no") == 0) - writer.setChecksum(false); - else - error->all(FLERR, "Illegal dump_modify command"); + writer.setChecksum(utils::logical(FLERR, arg[1], false, lmp) == 1); return 2; } else if (strcmp(arg[0], "compression_level") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - int compression_level = utils::inumeric(FLERR, arg[1], false, lmp); - writer.setCompressionLevel(compression_level); + writer.setCompressionLevel(utils::inumeric(FLERR, arg[1], false, lmp)); return 2; } } catch (FileWriterException &e) { diff --git a/src/COMPRESS/dump_custom_zstd.cpp b/src/COMPRESS/dump_custom_zstd.cpp index 3824709d5e..8b7d153fc4 100644 --- a/src/COMPRESS/dump_custom_zstd.cpp +++ b/src/COMPRESS/dump_custom_zstd.cpp @@ -203,16 +203,13 @@ int DumpCustomZstd::modify_param(int narg, char **arg) int consumed = DumpCustom::modify_param(narg, arg); if (consumed == 0) { try { - if (strcmp(arg[0],"checksum") == 0) { - if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - if (strcmp(arg[1],"yes") == 0) writer.setChecksum(true); - else if (strcmp(arg[1],"no") == 0) writer.setChecksum(false); - else error->all(FLERR,"Illegal dump_modify command"); + if (strcmp(arg[0], "checksum") == 0) { + if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); + writer.setChecksum(utils::logical(FLERR, arg[1], false, lmp) == 1); return 2; - } else if (strcmp(arg[0],"compression_level") == 0) { - if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - int compression_level = utils::inumeric(FLERR, arg[1], false, lmp); - writer.setCompressionLevel(compression_level); + } else if (strcmp(arg[0], "compression_level") == 0) { + if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); + writer.setCompressionLevel(utils::inumeric(FLERR, arg[1], false, lmp)); return 2; } } catch (FileWriterException &e) { diff --git a/src/COMPRESS/dump_local_zstd.cpp b/src/COMPRESS/dump_local_zstd.cpp index cf233aff19..91fb36bb6e 100644 --- a/src/COMPRESS/dump_local_zstd.cpp +++ b/src/COMPRESS/dump_local_zstd.cpp @@ -190,17 +190,11 @@ int DumpLocalZstd::modify_param(int narg, char **arg) try { if (strcmp(arg[0], "checksum") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - if (strcmp(arg[1], "yes") == 0) - writer.setChecksum(true); - else if (strcmp(arg[1], "no") == 0) - writer.setChecksum(false); - else - error->all(FLERR, "Illegal dump_modify command"); + writer.setChecksum(utils::logical(FLERR, arg[1], false, lmp) == 1); return 2; } else if (strcmp(arg[0], "compression_level") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - int compression_level = utils::inumeric(FLERR, arg[1], false, lmp); - writer.setCompressionLevel(compression_level); + writer.setCompressionLevel(utils::inumeric(FLERR, arg[1], false, lmp)); return 2; } } catch (FileWriterException &e) { diff --git a/src/COMPRESS/dump_xyz_zstd.cpp b/src/COMPRESS/dump_xyz_zstd.cpp index d5c79d181b..534bc0ee56 100644 --- a/src/COMPRESS/dump_xyz_zstd.cpp +++ b/src/COMPRESS/dump_xyz_zstd.cpp @@ -156,17 +156,11 @@ int DumpXYZZstd::modify_param(int narg, char **arg) try { if (strcmp(arg[0], "checksum") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - if (strcmp(arg[1], "yes") == 0) - writer.setChecksum(true); - else if (strcmp(arg[1], "no") == 0) - writer.setChecksum(false); - else - error->all(FLERR, "Illegal dump_modify command"); + writer.setChecksum(utils::logical(FLERR, arg[1], false, lmp) == 1); return 2; } else if (strcmp(arg[0], "compression_level") == 0) { if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); - int compression_level = utils::inumeric(FLERR, arg[1], false, lmp); - writer.setCompressionLevel(compression_level); + writer.setCompressionLevel(utils::inumeric(FLERR, arg[1], false, lmp)); return 2; } } catch (FileWriterException &e) { diff --git a/src/DIELECTRIC/fix_polarize_bem_gmres.cpp b/src/DIELECTRIC/fix_polarize_bem_gmres.cpp index 538ce15575..f5f119f686 100644 --- a/src/DIELECTRIC/fix_polarize_bem_gmres.cpp +++ b/src/DIELECTRIC/fix_polarize_bem_gmres.cpp @@ -796,12 +796,7 @@ int FixPolarizeBEMGMRES::modify_param(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg], "kspace") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix_modify command"); - if (strcmp(arg[iarg + 1], "yes") == 0) - kspaceflag = 1; - else if (strcmp(arg[iarg + 1], "no") == 0) - kspaceflag = 0; - else - error->all(FLERR, "Illegal fix_modify command for fix polarize"); + kspaceflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "dielectrics") == 0) { if (iarg + 6 > narg) error->all(FLERR, "Illegal fix_modify command"); diff --git a/src/DIELECTRIC/fix_polarize_bem_icc.cpp b/src/DIELECTRIC/fix_polarize_bem_icc.cpp index 4c137878a2..35171c0a19 100644 --- a/src/DIELECTRIC/fix_polarize_bem_icc.cpp +++ b/src/DIELECTRIC/fix_polarize_bem_icc.cpp @@ -355,12 +355,7 @@ int FixPolarizeBEMICC::modify_param(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg], "kspace") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix_modify command"); - if (strcmp(arg[iarg + 1], "yes") == 0) - kspaceflag = 1; - else if (strcmp(arg[iarg + 1], "no") == 0) - kspaceflag = 0; - else - error->all(FLERR, "Illegal fix_modify command for fix polarize"); + kspaceflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "dielectrics") == 0) { if (iarg + 6 > narg) error->all(FLERR, "Illegal fix_modify command"); diff --git a/src/DIELECTRIC/fix_polarize_functional.cpp b/src/DIELECTRIC/fix_polarize_functional.cpp index 2d67bca0a7..2e43d40ba0 100644 --- a/src/DIELECTRIC/fix_polarize_functional.cpp +++ b/src/DIELECTRIC/fix_polarize_functional.cpp @@ -478,12 +478,7 @@ int FixPolarizeFunctional::modify_param(int narg, char **arg) while (iarg < narg) { if (strcmp(arg[iarg], "kspace") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix_modify command"); - if (strcmp(arg[iarg + 1], "yes") == 0) - kspaceflag = 1; - else if (strcmp(arg[iarg + 1], "no") == 0) - kspaceflag = 0; - else - error->all(FLERR, "Illegal fix_modify command for fix polarize/functional"); + kspaceflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "dielectrics") == 0) { if (iarg + 6 > narg) error->all(FLERR, "Illegal fix_modify command"); diff --git a/src/DRUDE/fix_langevin_drude.cpp b/src/DRUDE/fix_langevin_drude.cpp index 205b36ce51..dea2f9ce62 100644 --- a/src/DRUDE/fix_langevin_drude.cpp +++ b/src/DRUDE/fix_langevin_drude.cpp @@ -91,9 +91,7 @@ FixLangevinDrude::FixLangevinDrude(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"zero") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix langevin/drude command"); - if (strcmp(arg[iarg+1],"no") == 0) zero = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) zero = 1; - else error->all(FLERR,"Illegal fix langevin/drude command"); + zero = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else error->all(FLERR,"Illegal fix langevin/drude command"); } diff --git a/src/DRUDE/fix_tgnh_drude.cpp b/src/DRUDE/fix_tgnh_drude.cpp index fe8cf448f0..eb8922d4cc 100644 --- a/src/DRUDE/fix_tgnh_drude.cpp +++ b/src/DRUDE/fix_tgnh_drude.cpp @@ -256,9 +256,7 @@ FixTGNHDrude::FixTGNHDrude(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg],"mtk") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); - if (strcmp(arg[iarg+1],"yes") == 0) mtk_flag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) mtk_flag = 0; - else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + mtk_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg],"tloop") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); @@ -277,27 +275,19 @@ FixTGNHDrude::FixTGNHDrude(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg],"scalexy") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); - if (strcmp(arg[iarg+1],"yes") == 0) scalexy = 1; - else if (strcmp(arg[iarg+1],"no") == 0) scalexy = 0; - else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + scalexy = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg],"scalexz") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); - if (strcmp(arg[iarg+1],"yes") == 0) scalexz = 1; - else if (strcmp(arg[iarg+1],"no") == 0) scalexz = 0; - else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + scalexz = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg],"scaleyz") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); - if (strcmp(arg[iarg+1],"yes") == 0) scaleyz = 1; - else if (strcmp(arg[iarg+1],"no") == 0) scaleyz = 0; - else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + scaleyz = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg],"flip") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); - if (strcmp(arg[iarg+1],"yes") == 0) flipflag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) flipflag = 0; - else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + flipflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg],"fixedpoint") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); diff --git a/src/EXTRA-COMPUTE/compute_entropy_atom.cpp b/src/EXTRA-COMPUTE/compute_entropy_atom.cpp index d0866c946c..ac53bf1e7f 100644 --- a/src/EXTRA-COMPUTE/compute_entropy_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_entropy_atom.cpp @@ -17,21 +17,23 @@ ------------------------------------------------------------------------- */ #include "compute_entropy_atom.h" -#include -#include + #include "atom.h" -#include "update.h" -#include "modify.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "force.h" -#include "pair.h" #include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" #include "math_const.h" #include "memory.h" -#include "error.h" -#include "domain.h" +#include "modify.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "pair.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace MathConst; @@ -44,8 +46,7 @@ ComputeEntropyAtom(LAMMPS *lmp, int narg, char **arg) : pair_entropy(nullptr), pair_entropy_avg(nullptr) { if (narg < 5 || narg > 10) - error->all(FLERR,"Illegal compute entropy/atom command; wrong number" - " of arguments"); + error->all(FLERR,"Illegal compute entropy/atom command; wrong number of arguments"); // Arguments are: sigma cutoff avg yes/no cutoff2 local yes/no // sigma is the gaussian width @@ -57,11 +58,9 @@ ComputeEntropyAtom(LAMMPS *lmp, int narg, char **arg) : // the g(r) sigma = utils::numeric(FLERR,arg[3],false,lmp); - if (sigma <= 0.0) error->all(FLERR,"Illegal compute entropy/atom" - " command; sigma must be positive"); + if (sigma <= 0.0) error->all(FLERR,"Illegal compute entropy/atom command; sigma must be positive"); cutoff = utils::numeric(FLERR,arg[4],false,lmp); - if (cutoff <= 0.0) error->all(FLERR,"Illegal compute entropy/atom" - " command; cutoff must be positive"); + if (cutoff <= 0.0) error->all(FLERR,"Illegal compute entropy/atom command; cutoff must be positive"); cutoff2 = 0.; avg_flag = 0; @@ -71,26 +70,17 @@ ComputeEntropyAtom(LAMMPS *lmp, int narg, char **arg) : int iarg = 5; while (iarg < narg) { if (strcmp(arg[iarg],"avg") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute entropy/atom;" - " missing arguments after avg"); - if (strcmp(arg[iarg+1],"yes") == 0) avg_flag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) avg_flag = 0; - else error->all(FLERR,"Illegal compute entropy/atom;" - " argument after avg should be yes or no"); + if (iarg+3 > narg) error->all(FLERR,"Illegal compute entropy/atom command"); + avg_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); cutoff2 = utils::numeric(FLERR,arg[iarg+2],false,lmp); - if (cutoff2 < 0.0) error->all(FLERR,"Illegal compute entropy/atom" - " command; negative cutoff2"); + if (cutoff2 < 0.0) error->all(FLERR,"Illegal compute entropy/atom command; negative cutoff2"); cutsq2 = cutoff2*cutoff2; iarg += 3; } else if (strcmp(arg[iarg],"local") == 0) { - if (strcmp(arg[iarg+1],"yes") == 0) local_flag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) local_flag = 0; - else error->all(FLERR,"Illegal compute entropy/atom;" - " argument after local should be yes or no"); + if (iarg+2 > narg) error->all(FLERR,"Illegal compute entropy/atom command"); + local_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; - } else error->all(FLERR,"Illegal compute entropy/atom; argument after" - " sigma and cutoff should be avg or local"); + } else error->all(FLERR,"Illegal compute entropy/atom command"); } diff --git a/src/EXTRA-DUMP/dump_dcd.cpp b/src/EXTRA-DUMP/dump_dcd.cpp index 97c9bec646..ec3973448a 100644 --- a/src/EXTRA-DUMP/dump_dcd.cpp +++ b/src/EXTRA-DUMP/dump_dcd.cpp @@ -258,9 +258,7 @@ int DumpDCD::modify_param(int narg, char **arg) { if (strcmp(arg[0],"unwrap") == 0) { if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - if (strcmp(arg[1],"yes") == 0) unwrap_flag = 1; - else if (strcmp(arg[1],"no") == 0) unwrap_flag = 0; - else error->all(FLERR,"Illegal dump_modify command"); + unwrap_flag = utils::logical(FLERR,arg[1],false,lmp); return 2; } return 0; diff --git a/src/EXTRA-DUMP/dump_xtc.cpp b/src/EXTRA-DUMP/dump_xtc.cpp index 7de6d03561..94846671cd 100644 --- a/src/EXTRA-DUMP/dump_xtc.cpp +++ b/src/EXTRA-DUMP/dump_xtc.cpp @@ -24,19 +24,20 @@ ------------------------------------------------------------------------- */ #include "dump_xtc.h" -#include -#include -#include -#include "domain.h" #include "atom.h" -#include "update.h" -#include "group.h" -#include "output.h" -#include "force.h" #include "comm.h" -#include "memory.h" +#include "domain.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "output.h" +#include "update.h" + +#include +#include +#include using namespace LAMMPS_NS; @@ -278,9 +279,7 @@ int DumpXTC::modify_param(int narg, char **arg) { if (strcmp(arg[0],"unwrap") == 0) { if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - if (strcmp(arg[1],"yes") == 0) unwrap_flag = 1; - else if (strcmp(arg[1],"no") == 0) unwrap_flag = 0; - else error->all(FLERR,"Illegal dump_modify command"); + unwrap_flag = utils::logical(FLERR,arg[1],false,lmp); return 2; } else if (strcmp(arg[0],"precision") == 0) { if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); diff --git a/src/EXTRA-FIX/fix_flow_gauss.cpp b/src/EXTRA-FIX/fix_flow_gauss.cpp index 415f1eecc0..2f8de2e21a 100644 --- a/src/EXTRA-FIX/fix_flow_gauss.cpp +++ b/src/EXTRA-FIX/fix_flow_gauss.cpp @@ -91,9 +91,7 @@ FixFlowGauss::FixFlowGauss(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"energy") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal energy keyword"); - if (strcmp(arg[iarg+1],"yes") == 0) workflag = true; - else if (strcmp(arg[iarg+1],"no") != 0) - error->all(FLERR,"Illegal energy keyword"); + workflag = utils::logical(FLERR,arg[iarg+1],false,lmp) == 1; iarg += 2; } else error->all(FLERR,"Illegal fix flow/gauss command"); } diff --git a/src/EXTRA-FIX/fix_gld.cpp b/src/EXTRA-FIX/fix_gld.cpp index 3f807d0f51..41585e4fd0 100644 --- a/src/EXTRA-FIX/fix_gld.cpp +++ b/src/EXTRA-FIX/fix_gld.cpp @@ -19,17 +19,18 @@ #include "fix_gld.h" +#include "atom.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "random_mars.h" +#include "respa.h" +#include "update.h" + #include #include -#include "atom.h" -#include "force.h" -#include "update.h" -#include "respa.h" -#include "comm.h" -#include "random_mars.h" -#include "memory.h" -#include "error.h" -#include "group.h" #define GLD_UNIFORM_DISTRO @@ -128,26 +129,14 @@ FixGLD::FixGLD(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"zero") == 0) { - if (iarg+2 > narg) { - error->all(FLERR, "Illegal fix gld command"); - } - if (strcmp(arg[iarg+1],"no") == 0) { - zeroflag = 0; - } else if (strcmp(arg[iarg+1],"yes") == 0) { - zeroflag = 1; - } else { - error->all(FLERR,"Illegal fix gld command"); - } + if (iarg+2 > narg) error->all(FLERR, "Illegal fix gld command"); + zeroflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"frozen") == 0) { - if (iarg+2 > narg) { - error->all(FLERR, "Illegal fix gld command"); - } - if (strcmp(arg[iarg+1],"no") == 0) { - freezeflag = 0; - } else if (strcmp(arg[iarg+1],"yes") == 0) { - freezeflag = 1; + if (iarg+2 > narg) error->all(FLERR, "Illegal fix gld command"); + freezeflag = utils::logical(FLERR,arg[iarg+1],false,lmp); + if (freezeflag) { for (int i = 0; i < atom->nlocal; i++) { if (atom->mask[i] & groupbit) { for (int k = 0; k < 3*prony_terms; k=k+3) @@ -158,8 +147,6 @@ FixGLD::FixGLD(LAMMPS *lmp, int narg, char **arg) : } } } - } else { - error->all(FLERR, "Illegal fix gld command"); } iarg += 2; } diff --git a/src/EXTRA-FIX/fix_npt_cauchy.cpp b/src/EXTRA-FIX/fix_npt_cauchy.cpp index 6a7d91dd16..07077cdabb 100644 --- a/src/EXTRA-FIX/fix_npt_cauchy.cpp +++ b/src/EXTRA-FIX/fix_npt_cauchy.cpp @@ -297,9 +297,7 @@ FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg],"mtk") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); - if (strcmp(arg[iarg+1],"yes") == 0) mtk_flag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) mtk_flag = 0; - else error->all(FLERR,"Illegal fix npt/cauchy command"); + mtk_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"tloop") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); @@ -318,27 +316,19 @@ FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg],"scalexy") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); - if (strcmp(arg[iarg+1],"yes") == 0) scalexy = 1; - else if (strcmp(arg[iarg+1],"no") == 0) scalexy = 0; - else error->all(FLERR,"Illegal fix npt/cauchy command"); + scalexy = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"scalexz") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); - if (strcmp(arg[iarg+1],"yes") == 0) scalexz = 1; - else if (strcmp(arg[iarg+1],"no") == 0) scalexz = 0; - else error->all(FLERR,"Illegal fix npt/cauchy command"); + scalexz = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"scaleyz") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); - if (strcmp(arg[iarg+1],"yes") == 0) scaleyz = 1; - else if (strcmp(arg[iarg+1],"no") == 0) scaleyz = 0; - else error->all(FLERR,"Illegal fix npt/cauchy command"); + scaleyz = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"flip") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); - if (strcmp(arg[iarg+1],"yes") == 0) flipflag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) flipflag = 0; - else error->all(FLERR,"Illegal fix npt/cauchy command"); + flipflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"update") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); @@ -352,10 +342,8 @@ FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : alpha = utils::numeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"continue") == 0) { - if (strcmp(arg[iarg+1],"yes") != 0 && strcmp(arg[iarg+1],"no") != 0) - error->all(FLERR,"Illegal cauchystat continue value. " - "Must be 'yes' or 'no'"); - restartPK = !strcmp(arg[iarg+1],"yes"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); + restartPK = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"fixedpoint") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal fix npt/cauchy command"); diff --git a/src/EXTRA-FIX/fix_pafi.cpp b/src/EXTRA-FIX/fix_pafi.cpp index 3b51906ae1..fbb6fb2971 100644 --- a/src/EXTRA-FIX/fix_pafi.cpp +++ b/src/EXTRA-FIX/fix_pafi.cpp @@ -103,16 +103,12 @@ FixPAFI::FixPAFI(LAMMPS *lmp, int narg, char **arg) : int iarg = 7; while (iarg < narg) { if (strcmp(arg[iarg],"overdamped") == 0) { - if (strcmp(arg[iarg+1],"no") == 0) od_flag = 0; - else if (strcmp(arg[iarg+1],"0") == 0) od_flag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) od_flag = 1; - else if (strcmp(arg[iarg+1],"1") == 0) od_flag = 1; + if (iarg+2 > narg) error->all(FLERR,"Illegal fix pafi command"); + od_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"com") == 0) { - if (strcmp(arg[iarg+1],"no") == 0) com_flag = 0; - else if (strcmp(arg[iarg+1],"0") == 0) com_flag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) com_flag = 1; - else if (strcmp(arg[iarg+1],"1") == 0) com_flag = 1; + if (iarg+2 > narg) error->all(FLERR,"Illegal fix pafi command"); + com_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else error->all(FLERR,"Illegal fix pafi command"); } diff --git a/src/FEP/compute_fep.cpp b/src/FEP/compute_fep.cpp index 683fbe114a..787c8a29e6 100644 --- a/src/FEP/compute_fep.cpp +++ b/src/FEP/compute_fep.cpp @@ -124,18 +124,12 @@ ComputeFEP::ComputeFEP(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"tail") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal optional keyword " - "in compute fep"); - if (strcmp(arg[iarg+1],"no") == 0) tailflag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) tailflag = 1; - else error->all(FLERR,"Illegal optional keyword in compute fep"); + if (iarg+2 > narg) error->all(FLERR,"Illegal optional keyword in compute fep"); + tailflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"volume") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal optional keyword " - "in compute fep"); - if (strcmp(arg[iarg+1],"no") == 0) volumeflag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) volumeflag = 1; - else error->all(FLERR,"Illegal optional keyword in compute fep"); + if (iarg+2 > narg) error->all(FLERR,"Illegal optional keyword in compute fep"); + volumeflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else error->all(FLERR,"Illegal optional keyword in compute fep"); diff --git a/src/FEP/fix_adapt_fep.cpp b/src/FEP/fix_adapt_fep.cpp index a6891c8742..d43c053b9a 100644 --- a/src/FEP/fix_adapt_fep.cpp +++ b/src/FEP/fix_adapt_fep.cpp @@ -138,21 +138,15 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"reset") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); - if (strcmp(arg[iarg+1],"no") == 0) resetflag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) resetflag = 1; - else error->all(FLERR,"Illegal fix adapt/fep command"); + resetflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"scale") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); - if (strcmp(arg[iarg+1],"no") == 0) scaleflag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) scaleflag = 1; - else error->all(FLERR,"Illegal fix adapt/fep command"); + scaleflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"after") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); - if (strcmp(arg[iarg+1],"no") == 0) afterflag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) afterflag = 1; - else error->all(FLERR,"Illegal fix adapt/fep command"); + afterflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else error->all(FLERR,"Illegal fix adapt/fep command"); } diff --git a/src/H5MD/dump_h5md.cpp b/src/H5MD/dump_h5md.cpp index 46c587a992..9517877053 100644 --- a/src/H5MD/dump_h5md.cpp +++ b/src/H5MD/dump_h5md.cpp @@ -16,23 +16,24 @@ Contributing author: Pierre de Buyl (KU Leuven) ------------------------------------------------------------------------- */ -#include -#include - -#include -#include -#include "ch5md.h" #include "dump_h5md.h" -#include "domain.h" + #include "atom.h" -#include "update.h" -#include "group.h" -#include "output.h" +#include "domain.h" #include "error.h" #include "force.h" +#include "group.h" #include "memory.h" +#include "output.h" +#include "update.h" #include "version.h" +#include +#include +#include + +#include "ch5md.h" + using namespace LAMMPS_NS; #define MYMIN(a,b) ((a) < (b) ? (a) : (b)) @@ -152,25 +153,14 @@ DumpH5MD::DumpH5MD(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) error->all(FLERR, "Invalid number of arguments in dump h5md"); } box_is_set = true; - if (strcmp(arg[iarg+1], "yes")==0) - do_box=true; - else if (strcmp(arg[iarg+1], "no")==0) - do_box=false; - else - error->all(FLERR, "Illegal dump h5md command"); + do_box = utils::logical(FLERR,arg[iarg+1],false,lmp) == 1; iarg+=2; } else if (strcmp(arg[iarg], "create_group")==0) { if (iarg+1>=narg) { error->all(FLERR, "Invalid number of arguments in dump h5md"); } create_group_is_set = true; - if (strcmp(arg[iarg+1], "yes")==0) - create_group=true; - else if (strcmp(arg[iarg+1], "no")==0) { - create_group=false; - } - else - error->all(FLERR, "Illegal dump h5md command"); + create_group = utils::logical(FLERR,arg[iarg+1],false,lmp) == 1; iarg+=2; } else if (strcmp(arg[iarg], "author")==0) { if (iarg+1>=narg) { diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index aa435d5b0b..be32604f94 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -381,9 +381,7 @@ void KokkosLMP::accelerator(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"newton") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command"); - if (strcmp(arg[iarg+1],"off") == 0) newtonflag = 0; - else if (strcmp(arg[iarg+1],"on") == 0) newtonflag = 1; - else error->all(FLERR,"Illegal package kokkos command"); + newtonflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"comm") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command"); @@ -459,21 +457,15 @@ void KokkosLMP::accelerator(int narg, char **arg) } else if ((strcmp(arg[iarg],"gpu/aware") == 0) || (strcmp(arg[iarg],"cuda/aware") == 0)) { if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command"); - if (strcmp(arg[iarg+1],"off") == 0) gpu_aware_flag = 0; - else if (strcmp(arg[iarg+1],"on") == 0) gpu_aware_flag = 1; - else error->all(FLERR,"Illegal package kokkos command"); + gpu_aware_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"pair/only") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command"); - if (strcmp(arg[iarg+1],"off") == 0) pair_only_flag = 0; - else if (strcmp(arg[iarg+1],"on") == 0) pair_only_flag = 1; - else error->all(FLERR,"Illegal package kokkos command"); + pair_only_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"neigh/thread") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command"); - if (strcmp(arg[iarg+1],"off") == 0) neigh_thread = 0; - else if (strcmp(arg[iarg+1],"on") == 0) neigh_thread = 1; - else error->all(FLERR,"Illegal package kokkos command"); + neigh_thread = utils::logical(FLERR,arg[iarg+1],false,lmp); neigh_thread_set = 1; iarg += 2; } else error->all(FLERR,"Illegal package kokkos command"); diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index 84c060a557..76200dc614 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -160,15 +160,11 @@ void FixAtomSwap::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"ke") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix atom/swap command"); - if (strcmp(arg[iarg+1],"no") == 0) conserve_ke_flag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) conserve_ke_flag = 1; - else error->all(FLERR,"Illegal fix atom/swap command"); + conserve_ke_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"semi-grand") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix atom/swap command"); - if (strcmp(arg[iarg+1],"no") == 0) semi_grand_flag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) semi_grand_flag = 1; - else error->all(FLERR,"Illegal fix atom/swap command"); + semi_grand_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"types") == 0) { if (iarg+3 > narg) error->all(FLERR,"Illegal fix atom/swap command"); diff --git a/src/MC/fix_charge_regulation.cpp b/src/MC/fix_charge_regulation.cpp index 2497b3d976..078e7eb9db 100644 --- a/src/MC/fix_charge_regulation.cpp +++ b/src/MC/fix_charge_regulation.cpp @@ -1180,8 +1180,8 @@ void FixChargeRegulation::setThermoTemperaturePointer() { int ifix = -1; ifix = modify->find_fix(idftemp); if (ifix == -1) { - error->all(FLERR, - "fix charge/regulation regulation could not find a temperature fix id provided by tempfixid\n"); + error->all(FLERR, "fix charge/regulation regulation could not find " + "a temperature fix id provided by tempfixid\n"); } Fix *temperature_fix = modify->fix[ifix]; int dim; @@ -1198,8 +1198,7 @@ void FixChargeRegulation::assign_tags() { for (int i = 0; i < atom->nlocal; i++) maxtag = MAX(maxtag, tag[i]); maxtag_all = maxtag; MPI_Allreduce(&maxtag, &maxtag_all, 1, MPI_LMP_TAGINT, MPI_MAX, world); - if (maxtag_all >= MAXTAGINT) - error->all(FLERR, "New atom IDs exceed maximum allowed ID"); + if (maxtag_all >= MAXTAGINT) error->all(FLERR, "New atom IDs exceed maximum allowed ID"); tagint notag = 0; tagint notag_all; @@ -1267,23 +1266,19 @@ void FixChargeRegulation::options(int narg, char **arg) { while (iarg < narg) { if (strcmp(arg[iarg], "lunit_nm") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); llength_unit_in_nm = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "acid_type") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); acid_type = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "base_type") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); base_type = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "pH") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); if (strstr(arg[iarg + 1],"v_") == arg[iarg + 1]) { pHstr = utils::strdup(&arg[iarg + 1][2]); } else { @@ -1292,45 +1287,37 @@ void FixChargeRegulation::options(int narg, char **arg) { } iarg += 2; } else if (strcmp(arg[iarg], "pIp") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); pI_plus = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "pIm") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); pI_minus = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "pKa") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); pKa = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "pKb") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); pKb = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "temp") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); reservoir_temperature = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "pKs") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); pKs = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "tempfixid") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); idftemp = utils::strdup(arg[iarg+1]); setThermoTemperaturePointer(); iarg += 2; } else if (strcmp(arg[iarg], "rxd") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); reaction_distance = utils::numeric(FLERR, arg[iarg + 1], false, lmp); if ((reaction_distance > domain->prd_half[0]) || (reaction_distance > domain->prd_half[1]) || @@ -1342,61 +1329,44 @@ void FixChargeRegulation::options(int narg, char **arg) { } iarg += 2; } else if (strcmp(arg[iarg], "nevery") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); nevery = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "nmc") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); nmc = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "pmcmoves") == 0) { - if (iarg + 4 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); pmcmoves[0] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); pmcmoves[1] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); pmcmoves[2] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; } else if (strcmp(arg[iarg], "seed") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); seed = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "tag") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); - if (strcmp(arg[iarg + 1], "yes") == 0) { - add_tags_flag = true; - } else if (strcmp(arg[iarg + 1], "no") == 0) { - add_tags_flag = false; - } else error->all(FLERR, "Illegal fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); + add_tags_flag = utils::logical(FLERR,arg[iarg+1],false,lmp) == 1; iarg += 2; } else if (strcmp(arg[iarg], "onlysalt") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); - if (strcmp(arg[iarg + 1], "yes") == 0) { - only_salt_flag = true; + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); + only_salt_flag = utils::logical(FLERR,arg[iarg+1],false,lmp) == 1; + iarg += 2; + if (only_salt_flag) { // need to specify salt charge - if (iarg + 4 > narg) - error->all(FLERR, "Illegal fix charge/regulation command"); - salt_charge[0] = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); - salt_charge[1] = utils::inumeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "no") == 0) { - only_salt_flag = false; + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix charge/regulation command"); + salt_charge[0] = utils::inumeric(FLERR, arg[iarg], false, lmp); + salt_charge[1] = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else error->all(FLERR, "Illegal fix charge/regulation command"); - + } } else if (strcmp(arg[iarg], "group") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix fix charge/regulation command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix fix charge/regulation command"); if (ngroups >= ngroupsmax) { ngroupsmax = ngroups + 1; groupstrings = (char **) - memory->srealloc(groupstrings, - ngroupsmax * sizeof(char *), - "fix_charge_regulation:groupstrings"); + memory->srealloc(groupstrings, ngroupsmax * sizeof(char *), "fix_charge_regulation:groupstrings"); } groupstrings[ngroups] = utils::strdup(arg[iarg+1]); ngroups++; diff --git a/src/MOLFILE/dump_molfile.cpp b/src/MOLFILE/dump_molfile.cpp index c1c4120405..052fb444a4 100644 --- a/src/MOLFILE/dump_molfile.cpp +++ b/src/MOLFILE/dump_molfile.cpp @@ -421,9 +421,7 @@ int DumpMolfile::modify_param(int narg, char **arg) { if (strcmp(arg[0],"unwrap") == 0) { if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - if (strcmp(arg[1],"yes") == 0) unwrap_flag = 1; - else if (strcmp(arg[1],"no") == 0) unwrap_flag = 0; - else error->all(FLERR,"Illegal dump_modify command"); + unwrap_flag = utils::logical(FLERR,arg[1],false,lmp); return 2; } else if (strcmp(arg[0],"element") == 0) { diff --git a/src/NETCDF/dump_netcdf.cpp b/src/NETCDF/dump_netcdf.cpp index cd7783a0aa..5702c94499 100644 --- a/src/NETCDF/dump_netcdf.cpp +++ b/src/NETCDF/dump_netcdf.cpp @@ -871,19 +871,13 @@ int DumpNetCDF::modify_param(int narg, char **arg) int iarg = 0; if (strcmp(arg[iarg],"double") == 0) { iarg++; - if (iarg >= narg) - error->all(FLERR,"expected 'yes' or 'no' after 'double' keyword."); - if (strcmp(arg[iarg],"yes") == 0) { - double_precision = true; - } else if (strcmp(arg[iarg],"no") == 0) { - double_precision = false; - } else error->all(FLERR,"expected 'yes' or 'no' after 'double' keyword."); + if (iarg >= narg) error->all(FLERR,"expected 'yes' or 'no' after 'double' keyword."); + double_precision = utils::logical(FLERR,arg[iarg],false,lmp) == 1; iarg++; return 2; } else if (strcmp(arg[iarg],"at") == 0) { iarg++; - if (iarg >= narg) - error->all(FLERR,"expected additional arg after 'at' keyword."); + if (iarg >= narg) error->all(FLERR,"expected additional arg after 'at' keyword."); framei = utils::inumeric(FLERR,arg[iarg],false,lmp); if (framei == 0) error->all(FLERR,"frame 0 not allowed for 'at' keyword."); else if (framei < 0) framei--; @@ -891,13 +885,8 @@ int DumpNetCDF::modify_param(int narg, char **arg) return 2; } else if (strcmp(arg[iarg],"thermo") == 0) { iarg++; - if (iarg >= narg) - error->all(FLERR,"expected 'yes' or 'no' after 'thermo' keyword."); - if (strcmp(arg[iarg],"yes") == 0) { - thermo = true; - } else if (strcmp(arg[iarg],"no") == 0) { - thermo = false; - } else error->all(FLERR,"expected 'yes' or 'no' after 'thermo' keyword."); + if (iarg >= narg) error->all(FLERR,"expected 'yes' or 'no' after 'thermo' keyword."); + thermo = utils::logical(FLERR,arg[iarg],false,lmp) == 1; iarg++; return 2; } else return 0; diff --git a/src/NETCDF/dump_netcdf_mpiio.cpp b/src/NETCDF/dump_netcdf_mpiio.cpp index 4179b362c8..a6c3c535c9 100644 --- a/src/NETCDF/dump_netcdf_mpiio.cpp +++ b/src/NETCDF/dump_netcdf_mpiio.cpp @@ -866,19 +866,13 @@ int DumpNetCDFMPIIO::modify_param(int narg, char **arg) int iarg = 0; if (strcmp(arg[iarg],"double") == 0) { iarg++; - if (iarg >= narg) - error->all(FLERR,"expected 'yes' or 'no' after 'double' keyword."); - if (strcmp(arg[iarg],"yes") == 0) { - double_precision = true; - } else if (strcmp(arg[iarg],"no") == 0) { - double_precision = false; - } else error->all(FLERR,"expected 'yes' or 'no' after 'double' keyword."); + if (iarg >= narg) error->all(FLERR,"expected 'yes' or 'no' after 'double' keyword."); + double_precision = utils::logical(FLERR,arg[iarg],false,lmp) == 1; iarg++; return 2; } else if (strcmp(arg[iarg],"at") == 0) { iarg++; - if (iarg >= narg) - error->all(FLERR,"expected additional arg after 'at' keyword."); + if (iarg >= narg) error->all(FLERR,"expected additional arg after 'at' keyword."); framei = utils::inumeric(FLERR,arg[iarg],false,lmp); if (framei == 0) error->all(FLERR,"frame 0 not allowed for 'at' keyword."); else if (framei < 0) framei--; @@ -886,13 +880,8 @@ int DumpNetCDFMPIIO::modify_param(int narg, char **arg) return 2; } else if (strcmp(arg[iarg],"thermo") == 0) { iarg++; - if (iarg >= narg) - error->all(FLERR,"expected 'yes' or 'no' after 'thermo' keyword."); - if (strcmp(arg[iarg],"yes") == 0) { - thermo = true; - } else if (strcmp(arg[iarg],"no") == 0) { - thermo = false; - } else error->all(FLERR,"expected 'yes' or 'no' after 'thermo' keyword."); + if (iarg >= narg) error->all(FLERR,"expected 'yes' or 'no' after 'thermo' keyword."); + thermo = utils::logical(FLERR,arg[iarg],false,lmp) == 1; iarg++; return 2; } else return 0; diff --git a/src/VORONOI/compute_voronoi_atom.cpp b/src/VORONOI/compute_voronoi_atom.cpp index 5808b8d17c..2be02e3d2a 100644 --- a/src/VORONOI/compute_voronoi_atom.cpp +++ b/src/VORONOI/compute_voronoi_atom.cpp @@ -109,15 +109,11 @@ ComputeVoronoi::ComputeVoronoi(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg], "neighbors") == 0) { if (iarg + 2 > narg) error->all(FLERR,"Illegal compute voronoi/atom command"); - if (strcmp(arg[iarg+1],"yes") == 0) faces_flag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) faces_flag = 0; - else error->all(FLERR,"Illegal compute voronoi/atom command"); + faces_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg], "peratom") == 0) { if (iarg + 2 > narg) error->all(FLERR,"Illegal compute voronoi/atom command"); - if (strcmp(arg[iarg+1],"yes") == 0) peratom_flag = 1; - else if (strcmp(arg[iarg+1],"no") == 0) peratom_flag = 0; - else error->all(FLERR,"Illegal compute voronoi/atom command"); + peratom_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else error->all(FLERR,"Illegal compute voronoi/atom command"); diff --git a/src/VTK/dump_vtk.cpp b/src/VTK/dump_vtk.cpp index f323ce820f..a7aabe3f51 100644 --- a/src/VTK/dump_vtk.cpp +++ b/src/VTK/dump_vtk.cpp @@ -2070,9 +2070,7 @@ int DumpVTK::modify_param(int narg, char **arg) if (strcmp(arg[0],"binary") == 0) { if (narg < 2) error->all(FLERR,"Illegal dump_modify command [binary]"); - if (strcmp(arg[1],"yes") == 0) binary = 1; - else if (strcmp(arg[1],"no") == 0) binary = 0; - else error->all(FLERR,"Illegal dump_modify command [binary]"); + binary = utils::logical(FLERR,arg[1],false,lmp); return 2; } diff --git a/src/input.cpp b/src/input.cpp index bfd0d56632..296623932a 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1622,16 +1622,10 @@ void Input::newton() int newton_pair=1,newton_bond=1; if (narg == 1) { - if (strcmp(arg[0],"off") == 0) newton_pair = newton_bond = 0; - else if (strcmp(arg[0],"on") == 0) newton_pair = newton_bond = 1; - else error->all(FLERR,"Illegal newton command"); + newton_pair = newton_bond = utils::logical(FLERR,arg[0],false,lmp); } else if (narg == 2) { - if (strcmp(arg[0],"off") == 0) newton_pair = 0; - else if (strcmp(arg[0],"on") == 0) newton_pair= 1; - else error->all(FLERR,"Illegal newton command"); - if (strcmp(arg[1],"off") == 0) newton_bond = 0; - else if (strcmp(arg[1],"on") == 0) newton_bond = 1; - else error->all(FLERR,"Illegal newton command"); + newton_pair = utils::logical(FLERR,arg[0],false,lmp); + newton_bond = utils::logical(FLERR,arg[1],false,lmp); } else error->all(FLERR,"Illegal newton command"); force->newton_pair = newton_pair;