diff --git a/src/compute_chunk_spread_atom.cpp b/src/compute_chunk_spread_atom.cpp index 41dbf2d5cb..579b194b9f 100644 --- a/src/compute_chunk_spread_atom.cpp +++ b/src/compute_chunk_spread_atom.cpp @@ -54,7 +54,7 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) : int iarg = 4; int expand = 0; char **earg; - int nargnew = input->expand_args(narg-iarg,&arg[iarg],1,earg); + int nargnew = utils::expand_args(FLERR,narg-iarg,&arg[iarg],1,earg,lmp); if (earg != &arg[iarg]) expand = 1; arg = earg; diff --git a/src/compute_global_atom.cpp b/src/compute_global_atom.cpp index f015ec910a..0c0e34fa0c 100644 --- a/src/compute_global_atom.cpp +++ b/src/compute_global_atom.cpp @@ -22,6 +22,7 @@ #include "variable.h" #include "memory.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; @@ -80,7 +81,7 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - int nargnew = input->expand_args(narg-iarg,&arg[iarg],1,earg); + int nargnew = utils::expand_args(FLERR,narg-iarg,&arg[iarg],1,earg,lmp); if (earg != &arg[iarg]) expand = 1; arg = earg; diff --git a/src/compute_reduce.cpp b/src/compute_reduce.cpp index 8467554faa..d4730c1de0 100644 --- a/src/compute_reduce.cpp +++ b/src/compute_reduce.cpp @@ -25,6 +25,7 @@ #include "variable.h" #include "memory.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; @@ -78,7 +79,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - int nargnew = input->expand_args(narg-iarg,&arg[iarg],1,earg); + int nargnew = utils::expand_args(FLERR,narg-iarg,&arg[iarg],1,earg,lmp); if (earg != &arg[iarg]) expand = 1; arg = earg; diff --git a/src/compute_reduce_chunk.cpp b/src/compute_reduce_chunk.cpp index 3b68e20fcb..cd64c8cb1b 100644 --- a/src/compute_reduce_chunk.cpp +++ b/src/compute_reduce_chunk.cpp @@ -25,6 +25,7 @@ #include "variable.h" #include "memory.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; @@ -64,7 +65,7 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - int nargnew = input->expand_args(narg-iarg,&arg[iarg],1,earg); + int nargnew = utils::expand_args(FLERR,narg-iarg,&arg[iarg],1,earg,lmp); if (earg != &arg[iarg]) expand = 1; arg = earg; diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 3297ecb4e7..33b7c4603b 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -29,6 +29,7 @@ #include "error.h" #include "update.h" #include "variable.h" +#include "utils.h" #include "fmt/format.h" using namespace LAMMPS_NS; @@ -76,7 +77,7 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : // nfield may be shrunk below if extra optional args exist expand = 0; - nfield = nargnew = input->expand_args(narg-5,&arg[5],1,earg); + nfield = nargnew = utils::expand_args(FLERR,narg-5,&arg[5],1,earg,lmp); if (earg != &arg[5]) expand = 1; // allocate field vectors diff --git a/src/dump_local.cpp b/src/dump_local.cpp index 21a96d1e8a..85fb5dff14 100644 --- a/src/dump_local.cpp +++ b/src/dump_local.cpp @@ -24,6 +24,7 @@ #include "memory.h" #include "error.h" #include "force.h" +#include "utils.h" using namespace LAMMPS_NS; @@ -57,7 +58,7 @@ DumpLocal::DumpLocal(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - nfield = input->expand_args(nfield,&arg[5],1,earg); + nfield = utils::expand_args(FLERR,nfield,&arg[5],1,earg,lmp); if (earg != &arg[5]) expand = 1; diff --git a/src/fix_ave_atom.cpp b/src/fix_ave_atom.cpp index 694df2bcf7..710aec1ef8 100644 --- a/src/fix_ave_atom.cpp +++ b/src/fix_ave_atom.cpp @@ -23,6 +23,7 @@ #include "memory.h" #include "error.h" #include "force.h" +#include "utils.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -51,7 +52,7 @@ FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - nvalues = input->expand_args(nvalues,&arg[6],1,earg); + nvalues = utils::expand_args(FLERR,nvalues,&arg[6],1,earg,lmp); if (earg != &arg[6]) expand = 1; arg = earg; diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 2987783b2a..a5730c6e60 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -72,7 +72,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - int nargnew = input->expand_args(narg-7,&arg[7],1,earg); + int nargnew = utils::expand_args(FLERR,narg-7,&arg[7],1,earg,lmp); if (earg != &arg[7]) expand = 1; arg = earg; diff --git a/src/fix_ave_correlate.cpp b/src/fix_ave_correlate.cpp index 2231611d1e..510b7ca769 100644 --- a/src/fix_ave_correlate.cpp +++ b/src/fix_ave_correlate.cpp @@ -65,7 +65,7 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): int expand = 0; char **earg; - int nargnew = input->expand_args(narg-6,&arg[6],0,earg); + int nargnew = utils::expand_args(FLERR,narg-6,&arg[6],0,earg,lmp); if (earg != &arg[6]) expand = 1; arg = earg; diff --git a/src/fix_ave_histo.cpp b/src/fix_ave_histo.cpp index d0bedba34a..a07da83ed9 100644 --- a/src/fix_ave_histo.cpp +++ b/src/fix_ave_histo.cpp @@ -107,7 +107,7 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - nvalues = input->expand_args(nvalues,&arg[9],mode,earg); + nvalues = utils::expand_args(FLERR,nvalues,&arg[9],mode,earg,lmp); if (earg != &arg[9]) expand = 1; arg = earg; diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index 84c5c04f11..a2c18361f6 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -88,7 +88,7 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : int expand = 0; char **earg; - nvalues = input->expand_args(nvalues,&arg[6],mode,earg); + nvalues = utils::expand_args(FLERR,nvalues,&arg[6],mode,earg,lmp); if (earg != &arg[6]) expand = 1; arg = earg; diff --git a/src/input.cpp b/src/input.cpp index dd640f18b0..a26bab5a0c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -599,141 +599,6 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) strcpy(str,str2); } -/* ---------------------------------------------------------------------- - expand arg to earg, for arguments with syntax c_ID[*] or f_ID[*] - fields to consider in input arg range from iarg to narg - return new expanded # of values, and copy them w/out "*" into earg - if any expansion occurs, earg is new allocation, must be freed by caller - if no expansion occurs, earg just points to arg, caller need not free -------------------------------------------------------------------------- */ - -int Input::expand_args(int narg, char **arg, int mode, char **&earg) -{ - int n,iarg,index,nlo,nhi,nmax,expandflag,icompute,ifix; - char *ptr1,*ptr2,*str; - - ptr1 = NULL; - for (iarg = 0; iarg < narg; iarg++) { - ptr1 = strchr(arg[iarg],'*'); - if (ptr1) break; - } - - if (!ptr1) { - earg = arg; - return narg; - } - - // maxarg should always end up equal to newarg, so caller can free earg - - int maxarg = narg-iarg; - earg = (char **) memory->smalloc(maxarg*sizeof(char *),"input:earg"); - - int newarg = 0; - for (iarg = 0; iarg < narg; iarg++) { - expandflag = 0; - - if (strncmp(arg[iarg],"c_",2) == 0 || - strncmp(arg[iarg],"f_",2) == 0) { - - ptr1 = strchr(&arg[iarg][2],'['); - if (ptr1) { - ptr2 = strchr(ptr1,']'); - if (ptr2) { - *ptr2 = '\0'; - if (strchr(ptr1,'*')) { - if (arg[iarg][0] == 'c') { - *ptr1 = '\0'; - icompute = modify->find_compute(&arg[iarg][2]); - *ptr1 = '['; - - // check for global vector/array, peratom array, local array - - if (icompute >= 0) { - if (mode == 0 && modify->compute[icompute]->vector_flag) { - nmax = modify->compute[icompute]->size_vector; - expandflag = 1; - } else if (mode == 1 && modify->compute[icompute]->array_flag) { - nmax = modify->compute[icompute]->size_array_cols; - expandflag = 1; - } else if (modify->compute[icompute]->peratom_flag && - modify->compute[icompute]->size_peratom_cols) { - nmax = modify->compute[icompute]->size_peratom_cols; - expandflag = 1; - } else if (modify->compute[icompute]->local_flag && - modify->compute[icompute]->size_local_cols) { - nmax = modify->compute[icompute]->size_local_cols; - expandflag = 1; - } - } - } else if (arg[iarg][0] == 'f') { - *ptr1 = '\0'; - ifix = modify->find_fix(&arg[iarg][2]); - *ptr1 = '['; - - // check for global vector/array, peratom array, local array - - if (ifix >= 0) { - if (mode == 0 && modify->fix[ifix]->vector_flag) { - nmax = modify->fix[ifix]->size_vector; - expandflag = 1; - } else if (mode == 1 && modify->fix[ifix]->array_flag) { - nmax = modify->fix[ifix]->size_array_cols; - expandflag = 1; - } else if (modify->fix[ifix]->peratom_flag && - modify->fix[ifix]->size_peratom_cols) { - nmax = modify->fix[ifix]->size_peratom_cols; - expandflag = 1; - } else if (modify->fix[ifix]->local_flag && - modify->fix[ifix]->size_local_cols) { - nmax = modify->fix[ifix]->size_local_cols; - expandflag = 1; - } - } - } - } - *ptr2 = ']'; - } - } - } - - if (expandflag) { - *ptr2 = '\0'; - force->bounds(FLERR,ptr1+1,nmax,nlo,nhi); - *ptr2 = ']'; - if (newarg+nhi-nlo+1 > maxarg) { - maxarg += nhi-nlo+1; - earg = (char **) - memory->srealloc(earg,maxarg*sizeof(char *),"input:earg"); - } - for (index = nlo; index <= nhi; index++) { - n = strlen(arg[iarg]) + 16; // 16 = space for large inserted integer - str = earg[newarg] = new char[n]; - strncpy(str,arg[iarg],ptr1+1-arg[iarg]); - sprintf(&str[ptr1+1-arg[iarg]],"%d",index); - strcat(str,ptr2); - newarg++; - } - - } else { - if (newarg == maxarg) { - maxarg++; - earg = (char **) - memory->srealloc(earg,maxarg*sizeof(char *),"input:earg"); - } - n = strlen(arg[iarg]) + 1; - earg[newarg] = new char[n]; - strcpy(earg[newarg],arg[iarg]); - newarg++; - } - } - - //printf("NEWARG %d\n",newarg); - //for (int i = 0; i < newarg; i++) - // printf(" arg %d: %s\n",i,earg[i]); - - return newarg; -} - /* ---------------------------------------------------------------------- return number of triple quotes in line ------------------------------------------------------------------------- */ @@ -1139,7 +1004,7 @@ void Input::partition() else error->all(FLERR,"Illegal partition command"); int ilo,ihi; - force->bounds(FLERR,arg[1],universe->nworlds,ilo,ihi); + utils::bounds(FLERR,arg[1],1,universe->nworlds,ilo,ihi,error); // copy original line to copy, since will use strtok() on it // ptr = start of 4th word diff --git a/src/input.h b/src/input.h index a50f769561..48caa13fde 100644 --- a/src/input.h +++ b/src/input.h @@ -38,7 +38,6 @@ class Input : protected Pointers { char *one(const std::string&); // process a single command void substitute(char *&, char *&, int &, int &, int); // substitute for variables in a string - int expand_args(int, char **, int, char **&); // expand args due to wildcard void write_echo(const std::string &); // send text to active echo file pointers protected: diff --git a/src/thermo.cpp b/src/thermo.cpp index 547d363285..f608b25016 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -126,7 +126,7 @@ Thermo::Thermo(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) int expand = 0; char **earg; - int nvalues = input->expand_args(narg-1,&arg[1],0,earg); + int nvalues = utils::expand_args(FLERR,narg-1,&arg[1],0,earg,lmp); if (earg != &arg[1]) expand = 1; line = new char[256+nvalues*64];