git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8226 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
150
src/input.cpp
150
src/input.cpp
@ -5,7 +5,7 @@
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
@ -93,8 +93,8 @@ Input::Input(LAMMPS *lmp, int argc, char **argv) : Pointers(lmp)
|
||||
while (jarg < argc && argv[jarg][0] != '-') jarg++;
|
||||
variable->set(argv[iarg+1],jarg-iarg-2,&argv[iarg+2]);
|
||||
iarg = jarg;
|
||||
} else if (strcmp(argv[iarg],"-echo") == 0 ||
|
||||
strcmp(argv[iarg],"-e") == 0) {
|
||||
} else if (strcmp(argv[iarg],"-echo") == 0 ||
|
||||
strcmp(argv[iarg],"-e") == 0) {
|
||||
narg = 1;
|
||||
char **tmp = arg; // trick echo() into using argv instead of arg
|
||||
arg = &argv[iarg+1];
|
||||
@ -131,7 +131,7 @@ void Input::file()
|
||||
int m,n;
|
||||
|
||||
while (1) {
|
||||
|
||||
|
||||
// read a line from input script
|
||||
// if line ends in continuation char '&', concatenate next line(s)
|
||||
// n = length of line including str terminator, 0 if end of file
|
||||
@ -140,12 +140,12 @@ void Input::file()
|
||||
if (me == 0) {
|
||||
m = 0;
|
||||
while (1) {
|
||||
if (fgets(&line[m],MAXLINE-m,infile) == NULL) n = 0;
|
||||
else n = strlen(line) + 1;
|
||||
if (n == 0) break;
|
||||
m = n-2;
|
||||
while (m >= 0 && isspace(line[m])) m--;
|
||||
if (m < 0 || line[m] != '&') break;
|
||||
if (fgets(&line[m],MAXLINE-m,infile) == NULL) n = 0;
|
||||
else n = strlen(line) + 1;
|
||||
if (n == 0) break;
|
||||
m = n-2;
|
||||
while (m >= 0 && isspace(line[m])) m--;
|
||||
if (m < 0 || line[m] != '&') break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,8 +159,8 @@ void Input::file()
|
||||
if (n == 0) {
|
||||
if (label_active) error->all(FLERR,"Label wasn't found in input script");
|
||||
if (me == 0) {
|
||||
if (infile != stdin) fclose(infile);
|
||||
nfile--;
|
||||
if (infile != stdin) fclose(infile);
|
||||
nfile--;
|
||||
}
|
||||
MPI_Bcast(&nfile,1,MPI_INT,0,world);
|
||||
if (nfile == 0) break;
|
||||
@ -181,7 +181,7 @@ void Input::file()
|
||||
// echo the command unless scanning for label
|
||||
|
||||
if (me == 0 && label_active == 0) {
|
||||
if (echo_screen && screen) fprintf(screen,"%s",line);
|
||||
if (echo_screen && screen) fprintf(screen,"%s",line);
|
||||
if (echo_log && logfile) fprintf(logfile,"%s",line);
|
||||
}
|
||||
|
||||
@ -241,9 +241,9 @@ char *Input::one(const char *single)
|
||||
strcpy(line,single);
|
||||
|
||||
// echo the command unless scanning for label
|
||||
|
||||
|
||||
if (me == 0 && label_active == 0) {
|
||||
if (echo_screen && screen) fprintf(screen,"%s\n",line);
|
||||
if (echo_screen && screen) fprintf(screen,"%s\n",line);
|
||||
if (echo_log && logfile) fprintf(logfile,"%s\n",line);
|
||||
}
|
||||
|
||||
@ -383,17 +383,17 @@ void Input::substitute(char *str, int flag)
|
||||
while (*ptr) {
|
||||
if (*ptr == '$' && !quote) {
|
||||
if (*(ptr+1) == '{') {
|
||||
var = ptr+2;
|
||||
int i = 0;
|
||||
while (var[i] != '\0' && var[i] != '}') i++;
|
||||
if (var[i] == '\0') error->one(FLERR,"Invalid variable name");
|
||||
var[i] = '\0';
|
||||
beyond = ptr + strlen(var) + 3;
|
||||
var = ptr+2;
|
||||
int i = 0;
|
||||
while (var[i] != '\0' && var[i] != '}') i++;
|
||||
if (var[i] == '\0') error->one(FLERR,"Invalid variable name");
|
||||
var[i] = '\0';
|
||||
beyond = ptr + strlen(var) + 3;
|
||||
} else {
|
||||
var = ptr;
|
||||
var[0] = var[1];
|
||||
var[1] = '\0';
|
||||
beyond = ptr + strlen(var) + 1;
|
||||
var = ptr;
|
||||
var[0] = var[1];
|
||||
var[1] = '\0';
|
||||
beyond = ptr + strlen(var) + 1;
|
||||
}
|
||||
value = variable->retrieve(var);
|
||||
if (value == NULL) error->one(FLERR,"Substitution for illegal variable");
|
||||
@ -401,16 +401,16 @@ void Input::substitute(char *str, int flag)
|
||||
*ptr = '\0';
|
||||
strcpy(work,str);
|
||||
if (strlen(work)+strlen(value) >= MAXLINE)
|
||||
error->one(FLERR,"Input line too long after variable substitution");
|
||||
error->one(FLERR,"Input line too long after variable substitution");
|
||||
strcat(work,value);
|
||||
if (strlen(work)+strlen(beyond) >= MAXLINE)
|
||||
error->one(FLERR,"Input line too long after variable substitution");
|
||||
error->one(FLERR,"Input line too long after variable substitution");
|
||||
strcat(work,beyond);
|
||||
strcpy(str,work);
|
||||
ptr += strlen(value);
|
||||
if (flag && me == 0 && label_active == 0) {
|
||||
if (echo_screen && screen) fprintf(screen,"%s",str);
|
||||
if (echo_log && logfile) fprintf(logfile,"%s",str);
|
||||
if (echo_screen && screen) fprintf(screen,"%s",str);
|
||||
if (echo_log && logfile) fprintf(logfile,"%s",str);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -507,7 +507,7 @@ int Input::execute_command()
|
||||
#define COMMAND_CLASS
|
||||
#define CommandStyle(key,Class) \
|
||||
else if (strcmp(command,#key) == 0) { \
|
||||
Class key(lmp); \
|
||||
Class key(lmp); \
|
||||
key.command(narg,arg); \
|
||||
return 0; \
|
||||
}
|
||||
@ -578,8 +578,8 @@ void Input::ifthenelse()
|
||||
|
||||
int first = 2;
|
||||
int iarg = first;
|
||||
while (iarg < narg &&
|
||||
(strcmp(arg[iarg],"elif") != 0 && strcmp(arg[iarg],"else") != 0))
|
||||
while (iarg < narg &&
|
||||
(strcmp(arg[iarg],"elif") != 0 && strcmp(arg[iarg],"else") != 0))
|
||||
iarg++;
|
||||
int last = iarg-1;
|
||||
|
||||
@ -600,9 +600,9 @@ void Input::ifthenelse()
|
||||
strcpy(commands[ncommands],arg[i]);
|
||||
ncommands++;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < ncommands; i++) one(commands[i]);
|
||||
|
||||
|
||||
for (int i = 0; i < ncommands; i++) delete [] commands[i];
|
||||
delete [] commands;
|
||||
delete [] scopy;
|
||||
@ -635,8 +635,8 @@ void Input::ifthenelse()
|
||||
}
|
||||
|
||||
iarg = first;
|
||||
while (iarg < narg &&
|
||||
(strcmp(arg[iarg],"elif") != 0 && strcmp(arg[iarg],"else") != 0))
|
||||
while (iarg < narg &&
|
||||
(strcmp(arg[iarg],"elif") != 0 && strcmp(arg[iarg],"else") != 0))
|
||||
iarg++;
|
||||
last = iarg-1;
|
||||
|
||||
@ -654,11 +654,11 @@ void Input::ifthenelse()
|
||||
strcpy(commands[ncommands],arg[i]);
|
||||
ncommands++;
|
||||
}
|
||||
|
||||
|
||||
// execute the list of commands
|
||||
|
||||
|
||||
for (int i = 0; i < ncommands; i++) one(commands[i]);
|
||||
|
||||
|
||||
// clean up
|
||||
|
||||
for (int i = 0; i < ncommands; i++) delete [] commands[i];
|
||||
@ -678,7 +678,7 @@ void Input::include()
|
||||
if (me == 0) {
|
||||
if (nfile == maxfile) {
|
||||
maxfile++;
|
||||
infiles = (FILE **)
|
||||
infiles = (FILE **)
|
||||
memory->srealloc(infiles,maxfile*sizeof(FILE *),"input:infiles");
|
||||
}
|
||||
infile = fopen(arg[0],"r");
|
||||
@ -708,9 +708,9 @@ void Input::jump()
|
||||
if (infile != stdin) fclose(infile);
|
||||
infile = fopen(arg[0],"r");
|
||||
if (infile == NULL) {
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open input script %s",arg[0]);
|
||||
error->one(FLERR,str);
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open input script %s",arg[0]);
|
||||
error->one(FLERR,str);
|
||||
}
|
||||
infiles[nfile-1] = infile;
|
||||
}
|
||||
@ -745,9 +745,9 @@ void Input::log()
|
||||
else {
|
||||
logfile = fopen(arg[0],"w");
|
||||
if (logfile == NULL) {
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open logfile %s",arg[0]);
|
||||
error->one(FLERR,str);
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open logfile %s",arg[0]);
|
||||
error->one(FLERR,str);
|
||||
}
|
||||
}
|
||||
if (universe->nworlds == 1) universe->ulogfile = logfile;
|
||||
@ -830,10 +830,10 @@ void Input::shell()
|
||||
|
||||
} else if (strcmp(arg[0],"mkdir") == 0) {
|
||||
if (narg < 2) error->all(FLERR,"Illegal shell command");
|
||||
#if !defined(WINDOWS) && !defined(__MINGW32_VERSION)
|
||||
#if !defined(WINDOWS) && !defined(__MINGW32_VERSION)
|
||||
if (me == 0)
|
||||
for (int i = 1; i < narg; i++)
|
||||
mkdir(arg[i], S_IRWXU | S_IRGRP | S_IXGRP);
|
||||
mkdir(arg[i], S_IRWXU | S_IRGRP | S_IXGRP);
|
||||
#endif
|
||||
|
||||
} else if (strcmp(arg[0],"mv") == 0) {
|
||||
@ -884,9 +884,9 @@ void Input::angle_coeff()
|
||||
{
|
||||
if (domain->box_exist == 0)
|
||||
error->all(FLERR,"Angle_coeff command before simulation box is defined");
|
||||
if (force->angle == NULL)
|
||||
if (force->angle == NULL)
|
||||
error->all(FLERR,"Angle_coeff command before angle_style is defined");
|
||||
if (atom->avec->angles_allow == 0)
|
||||
if (atom->avec->angles_allow == 0)
|
||||
error->all(FLERR,"Angle_coeff command when no angles allowed");
|
||||
force->angle->coeff(narg,arg);
|
||||
}
|
||||
@ -896,7 +896,7 @@ void Input::angle_coeff()
|
||||
void Input::angle_style()
|
||||
{
|
||||
if (narg < 1) error->all(FLERR,"Illegal angle_style command");
|
||||
if (atom->avec->angles_allow == 0)
|
||||
if (atom->avec->angles_allow == 0)
|
||||
error->all(FLERR,"Angle_style command when no angles allowed");
|
||||
force->create_angle(arg[0],lmp->suffix);
|
||||
if (force->angle) force->angle->settings(narg-1,&arg[1]);
|
||||
@ -914,7 +914,7 @@ void Input::atom_modify()
|
||||
void Input::atom_style()
|
||||
{
|
||||
if (narg < 1) error->all(FLERR,"Illegal atom_style command");
|
||||
if (domain->box_exist)
|
||||
if (domain->box_exist)
|
||||
error->all(FLERR,"Atom_style command after simulation box is defined");
|
||||
atom->create_avec(arg[0],narg-1,&arg[1],lmp->suffix);
|
||||
}
|
||||
@ -925,9 +925,9 @@ void Input::bond_coeff()
|
||||
{
|
||||
if (domain->box_exist == 0)
|
||||
error->all(FLERR,"Bond_coeff command before simulation box is defined");
|
||||
if (force->bond == NULL)
|
||||
if (force->bond == NULL)
|
||||
error->all(FLERR,"Bond_coeff command before bond_style is defined");
|
||||
if (atom->avec->bonds_allow == 0)
|
||||
if (atom->avec->bonds_allow == 0)
|
||||
error->all(FLERR,"Bond_coeff command when no bonds allowed");
|
||||
force->bond->coeff(narg,arg);
|
||||
}
|
||||
@ -937,7 +937,7 @@ void Input::bond_coeff()
|
||||
void Input::bond_style()
|
||||
{
|
||||
if (narg < 1) error->all(FLERR,"Illegal bond_style command");
|
||||
if (atom->avec->bonds_allow == 0)
|
||||
if (atom->avec->bonds_allow == 0)
|
||||
error->all(FLERR,"Bond_style command when no bonds allowed");
|
||||
force->create_bond(arg[0],lmp->suffix);
|
||||
if (force->bond) force->bond->settings(narg-1,&arg[1]);
|
||||
@ -987,9 +987,9 @@ void Input::dihedral_coeff()
|
||||
{
|
||||
if (domain->box_exist == 0)
|
||||
error->all(FLERR,"Dihedral_coeff command before simulation box is defined");
|
||||
if (force->dihedral == NULL)
|
||||
if (force->dihedral == NULL)
|
||||
error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined");
|
||||
if (atom->avec->dihedrals_allow == 0)
|
||||
if (atom->avec->dihedrals_allow == 0)
|
||||
error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed");
|
||||
force->dihedral->coeff(narg,arg);
|
||||
}
|
||||
@ -999,7 +999,7 @@ void Input::dihedral_coeff()
|
||||
void Input::dihedral_style()
|
||||
{
|
||||
if (narg < 1) error->all(FLERR,"Illegal dihedral_style command");
|
||||
if (atom->avec->dihedrals_allow == 0)
|
||||
if (atom->avec->dihedrals_allow == 0)
|
||||
error->all(FLERR,"Dihedral_style command when no dihedrals allowed");
|
||||
force->create_dihedral(arg[0],lmp->suffix);
|
||||
if (force->dihedral) force->dihedral->settings(narg-1,&arg[1]);
|
||||
@ -1010,7 +1010,7 @@ void Input::dihedral_style()
|
||||
void Input::dimension()
|
||||
{
|
||||
if (narg != 1) error->all(FLERR,"Illegal dimension command");
|
||||
if (domain->box_exist)
|
||||
if (domain->box_exist)
|
||||
error->all(FLERR,"Dimension command after simulation box is defined");
|
||||
domain->dimension = atoi(arg[0]);
|
||||
if (domain->dimension != 2 && domain->dimension != 3)
|
||||
@ -1064,9 +1064,9 @@ void Input::improper_coeff()
|
||||
{
|
||||
if (domain->box_exist == 0)
|
||||
error->all(FLERR,"Improper_coeff command before simulation box is defined");
|
||||
if (force->improper == NULL)
|
||||
if (force->improper == NULL)
|
||||
error->all(FLERR,"Improper_coeff command before improper_style is defined");
|
||||
if (atom->avec->impropers_allow == 0)
|
||||
if (atom->avec->impropers_allow == 0)
|
||||
error->all(FLERR,"Improper_coeff command when no impropers allowed");
|
||||
force->improper->coeff(narg,arg);
|
||||
}
|
||||
@ -1076,7 +1076,7 @@ void Input::improper_coeff()
|
||||
void Input::improper_style()
|
||||
{
|
||||
if (narg < 1) error->all(FLERR,"Illegal improper_style command");
|
||||
if (atom->avec->impropers_allow == 0)
|
||||
if (atom->avec->impropers_allow == 0)
|
||||
error->all(FLERR,"Improper_style command when no impropers allowed");
|
||||
force->create_improper(arg[0],lmp->suffix);
|
||||
if (force->improper) force->improper->settings(narg-1,&arg[1]);
|
||||
@ -1086,7 +1086,7 @@ void Input::improper_style()
|
||||
|
||||
void Input::kspace_modify()
|
||||
{
|
||||
if (force->kspace == NULL)
|
||||
if (force->kspace == NULL)
|
||||
error->all(FLERR,"KSpace style has not yet been set");
|
||||
force->kspace->modify_params(narg,arg);
|
||||
}
|
||||
@ -1167,11 +1167,11 @@ void Input::newton()
|
||||
force->newton_pair = newton_pair;
|
||||
|
||||
if (newton_bond == 0) {
|
||||
if (domain->box_exist && force->newton_bond == 1)
|
||||
if (domain->box_exist && force->newton_bond == 1)
|
||||
error->all(FLERR,"Newton bond change after simulation box is defined");
|
||||
force->newton_bond = 0;
|
||||
} else {
|
||||
if (domain->box_exist && force->newton_bond == 0)
|
||||
if (domain->box_exist && force->newton_bond == 0)
|
||||
error->all(FLERR,"Newton bond change after simulation box is defined");
|
||||
force->newton_bond = 1;
|
||||
}
|
||||
@ -1184,7 +1184,7 @@ void Input::newton()
|
||||
|
||||
void Input::package()
|
||||
{
|
||||
if (domain->box_exist)
|
||||
if (domain->box_exist)
|
||||
error->all(FLERR,"Package command after simulation box is defined");
|
||||
if (narg < 1) error->all(FLERR,"Illegal package command");
|
||||
|
||||
@ -1220,7 +1220,7 @@ void Input::pair_coeff()
|
||||
{
|
||||
if (domain->box_exist == 0)
|
||||
error->all(FLERR,"Pair_coeff command before simulation box is defined");
|
||||
if (force->pair == NULL)
|
||||
if (force->pair == NULL)
|
||||
error->all(FLERR,"Pair_coeff command before pair_style is defined");
|
||||
force->pair->coeff(narg,arg);
|
||||
}
|
||||
@ -1229,7 +1229,7 @@ void Input::pair_coeff()
|
||||
|
||||
void Input::pair_modify()
|
||||
{
|
||||
if (force->pair == NULL)
|
||||
if (force->pair == NULL)
|
||||
error->all(FLERR,"Pair_modify command before pair_style is defined");
|
||||
force->pair->modify_params(narg,arg);
|
||||
}
|
||||
@ -1254,7 +1254,7 @@ void Input::pair_style()
|
||||
|
||||
void Input::pair_write()
|
||||
{
|
||||
if (force->pair == NULL)
|
||||
if (force->pair == NULL)
|
||||
error->all(FLERR,"Pair_write command before pair_style is defined");
|
||||
force->pair->write_file(narg,arg);
|
||||
}
|
||||
@ -1319,10 +1319,10 @@ void Input::special_bonds()
|
||||
|
||||
if (domain->box_exist && atom->molecular) {
|
||||
if (lj2 != force->special_lj[2] || lj3 != force->special_lj[3] ||
|
||||
coul2 != force->special_coul[2] || coul3 != force->special_coul[3] ||
|
||||
angle != force->special_angle ||
|
||||
dihedral != force->special_dihedral ||
|
||||
extra != force->special_extra) {
|
||||
coul2 != force->special_coul[2] || coul3 != force->special_coul[3] ||
|
||||
angle != force->special_angle ||
|
||||
dihedral != force->special_dihedral ||
|
||||
extra != force->special_extra) {
|
||||
Special special(lmp);
|
||||
special.build();
|
||||
}
|
||||
@ -1334,7 +1334,7 @@ void Input::special_bonds()
|
||||
void Input::suffix()
|
||||
{
|
||||
if (narg != 1) error->all(FLERR,"Illegal suffix command");
|
||||
|
||||
|
||||
if (strcmp(arg[0],"off") == 0) lmp->suffix_enable = 0;
|
||||
else if (strcmp(arg[0],"on") == 0) lmp->suffix_enable = 1;
|
||||
else {
|
||||
@ -1407,7 +1407,7 @@ void Input::unfix()
|
||||
void Input::units()
|
||||
{
|
||||
if (narg != 1) error->all(FLERR,"Illegal units command");
|
||||
if (domain->box_exist)
|
||||
if (domain->box_exist)
|
||||
error->all(FLERR,"Units command after simulation box is defined");
|
||||
update->set_units(arg[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user