git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14220 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2015-10-30 20:04:06 +00:00
parent 0aa77408f8
commit 354e20f431
1219 changed files with 10111 additions and 10111 deletions

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "mpi.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "errno.h"
#include "ctype.h"
#include "unistd.h"
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include "sys/stat.h"
#include "input.h"
#include "style_command.h"
@ -52,7 +52,7 @@
#include "memory.h"
#ifdef _OPENMP
#include "omp.h"
#include <omp.h>
#endif
#ifdef _WIN32
@ -151,13 +151,13 @@ Input::~Input()
void Input::file()
{
int m,n;
while (1) {
// read a line from input script
// n = length of line including str terminator, 0 if end of file
// if line ends in continuation char '&', concatenate next line
if (me == 0) {
m = 0;
while (1) {
@ -165,7 +165,7 @@ void Input::file()
// end of file reached, so break
// n == 0 if nothing read, else n = line with str terminator
if (fgets(&line[m],maxline-m,infile) == NULL) {
if (m) n = strlen(line) + 1;
else n = 0;
@ -195,13 +195,13 @@ void Input::file()
}
}
}
// bcast the line
// if n = 0, end-of-file
// error if label_active is set, since label wasn't encountered
// if original input file, code is done
// else go back to previous input file
MPI_Bcast(&n,1,MPI_INT,0,world);
if (n == 0) {
if (label_active) error->all(FLERR,"Label wasn't found in input script");
@ -217,29 +217,29 @@ void Input::file()
if (me == 0) infile = infiles[nfile-1];
continue;
}
if (n > maxline) reallocate(line,maxline,n);
MPI_Bcast(line,n,MPI_CHAR,0,world);
// echo the command unless scanning for label
if (me == 0 && label_active == 0) {
if (echo_screen && screen) fprintf(screen,"%s\n",line);
if (echo_log && logfile) fprintf(logfile,"%s\n",line);
}
// parse the line
// if no command, skip to next line in input script
parse();
if (command == NULL) continue;
// if scanning for label, skip command unless it's a label command
if (label_active && strcmp(command,"label") != 0) continue;
// execute the command
if (execute_command()) {
char *str = new char[maxline+32];
sprintf(str,"Unknown command: %s",line);
@ -263,7 +263,7 @@ void Input::file(const char *filename)
if (nfile > 1)
error->one(FLERR,"Invalid use of library file() function");
if (infile && infile != stdin) fclose(infile);
if (infile && infile != stdin) fclose(infile);
infile = fopen(filename,"r");
if (infile == NULL) {
char str[128];
@ -273,7 +273,7 @@ void Input::file(const char *filename)
infiles[0] = infile;
nfile = 1;
}
file();
}
@ -287,32 +287,32 @@ char *Input::one(const char *single)
int n = strlen(single) + 1;
if (n > maxline) reallocate(line,maxline,n);
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_log && logfile) fprintf(logfile,"%s\n",line);
}
// parse the line
// if no command, just return NULL
parse();
if (command == NULL) return NULL;
// if scanning for label, skip command unless it's a label command
if (label_active && strcmp(command,"label") != 0) return NULL;
// execute the command and return its name
if (execute_command()) {
char *str = new char[maxline+32];
sprintf(str,"Unknown command: %s",line);
error->all(FLERR,str);
}
return command;
}
@ -329,11 +329,11 @@ char *Input::one(const char *single)
void Input::parse()
{
// duplicate line into copy string to break into words
int n = strlen(line) + 1;
if (n > maxcopy) reallocate(copy,maxcopy,n);
strcpy(copy,line);
// strip any # comment by replacing it with 0
// do not strip from a # inside single/double/triple quotes
// quoteflag = 1,2,3 when encounter first single/double,triple quote
@ -363,22 +363,22 @@ void Input::parse()
}
ptr++;
}
// perform $ variable substitution (print changes)
// except if searching for a label since earlier variable may not be defined
if (!label_active) substitute(copy,work,maxcopy,maxwork,1);
// command = 1st arg in copy string
char *next;
command = nextword(copy,&next);
if (command == NULL) return;
// point arg[] at each subsequent arg in copy string
// nextword() inserts string terminators into copy string to delimit args
// nextword() treats text between single/double/triple quotes as one arg
narg = 0;
ptr = next;
while (ptr) {
@ -407,12 +407,12 @@ void Input::parse()
char *Input::nextword(char *str, char **next)
{
char *start,*stop;
// start = first non-whitespace char
start = &str[strspn(str," \t\n\v\f\r")];
if (*start == '\0') return NULL;
// if start is single/double/triple quote:
// start = first char beyond quote
// stop = first char of matching quote
@ -464,45 +464,45 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
// if $ is followed by '{', trailing '}' becomes NULL
// else $x becomes x followed by NULL
// beyond = points to text following variable
int i,n,paren_count;
char immediate[256];
char *var,*value,*beyond;
int quoteflag = 0;
char *ptr = str;
n = strlen(str) + 1;
if (n > max2) reallocate(str2,max2,n);
*str2 = '\0';
char *ptr2 = str2;
while (*ptr) {
// variable substitution
if (*ptr == '$' && !quoteflag) {
// value = ptr to expanded variable
// variable name between curly braces, e.g. ${a}
if (*(ptr+1) == '{') {
var = ptr+2;
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;
value = variable->retrieve(var);
// immediate variable between parenthesis, e.g. $(1/2)
} else if (*(ptr+1) == '(') {
var = ptr+2;
paren_count = 0;
i = 0;
while (var[i] != '\0' && !(var[i] == ')' && paren_count == 0)) {
switch (var[i]) {
case '(': paren_count++; break;
@ -511,15 +511,15 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
}
i++;
}
if (var[i] == '\0') error->one(FLERR,"Invalid immediate variable");
var[i] = '\0';
beyond = ptr + strlen(var) + 3;
sprintf(immediate,"%.20g",variable->compute_equal(var));
value = immediate;
// single character variable name, e.g. $a
} else {
var = ptr;
var[0] = var[1];
@ -527,25 +527,25 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
beyond = ptr + 2;
value = variable->retrieve(var);
}
if (value == NULL) error->one(FLERR,"Substitution for illegal variable");
// check if storage in str2 needs to be expanded
// re-initialize ptr and ptr2 to the point beyond the variable.
n = strlen(str2) + strlen(value) + strlen(beyond) + 1;
if (n > max2) reallocate(str2,max2,n);
strcat(str2,value);
ptr2 = str2 + strlen(str2);
ptr = beyond;
// output substitution progress if requested
if (flag && me == 0 && label_active == 0) {
if (echo_screen && screen) fprintf(screen,"%s%s\n",str2,beyond);
if (echo_log && logfile) fprintf(logfile,"%s%s\n",str2,beyond);
}
continue;
}
@ -558,7 +558,7 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
quoteflag = 3;
*ptr2++ = *ptr++;
*ptr2++ = *ptr++;
}
}
else if (*ptr == '"') quoteflag = 2;
else if (*ptr == '\'') quoteflag = 1;
} else {
@ -572,14 +572,14 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
}
// copy current character into str2
*ptr2++ = *ptr++;
*ptr2 = '\0';
}
// set length of input str to length of work str2
// copy work string back to input str
if (max2 > max) reallocate(str,max,max2);
strcpy(str,str2);
}
@ -610,7 +610,7 @@ void Input::reallocate(char *&str, int &max, int n)
if (n) {
while (n > max) max += DELTALINE;
} else max += DELTALINE;
str = (char *) memory->srealloc(str,max*sizeof(char),"input:str");
}
@ -622,7 +622,7 @@ void Input::reallocate(char *&str, int &max, int n)
int Input::execute_command()
{
int flag = 1;
if (!strcmp(command,"clear")) clear();
else if (!strcmp(command,"echo")) echo();
else if (!strcmp(command,"if")) ifthenelse();
@ -637,7 +637,7 @@ int Input::execute_command()
else if (!strcmp(command,"quit")) quit();
else if (!strcmp(command,"shell")) shell();
else if (!strcmp(command,"variable")) variable_command();
else if (!strcmp(command,"angle_coeff")) angle_coeff();
else if (!strcmp(command,"angle_style")) angle_style();
else if (!strcmp(command,"atom_modify")) atom_modify();
@ -692,23 +692,23 @@ int Input::execute_command()
else if (!strcmp(command,"undump")) undump();
else if (!strcmp(command,"unfix")) unfix();
else if (!strcmp(command,"units")) units();
else flag = 0;
// return if command was listed above
if (flag) return 0;
// invoke commands added via style_command.h
if (command_map->find(command) != command_map->end()) {
CommandCreator command_creator = (*command_map)[command];
command_creator(lmp,narg,arg);
return 0;
}
// unrecognized command
return -1;
}
@ -885,7 +885,7 @@ void Input::include()
// NOTE: this check will fail if a 2nd if command was inside the if command
// and came before the include
if (ifthenelse_flag)
if (ifthenelse_flag)
error->all(FLERR,"Cannot use include command within an if command");
if (me == 0) {
@ -1165,7 +1165,7 @@ void Input::shell()
for (int i = 1; i < narg; i++) {
char *ptr = strdup(arg[i]);
rv = 0;
#ifdef _WIN32
#ifdef _WIN32
if (ptr != NULL) rv = _putenv(ptr);
#else
if (ptr != NULL) rv = putenv(ptr);