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

This commit is contained in:
sjplimp
2013-11-02 00:02:37 +00:00
parent 22c1957a2c
commit 29f515735a
5 changed files with 176 additions and 9 deletions

View File

@ -978,11 +978,11 @@ void Input::shell()
if (narg < 1) error->all(FLERR,"Illegal shell command");
if (strcmp(arg[0],"cd") == 0) {
if (narg != 2) error->all(FLERR,"Illegal shell command");
if (narg != 2) error->all(FLERR,"Illegal shell cd command");
chdir(arg[1]);
} else if (strcmp(arg[0],"mkdir") == 0) {
if (narg < 2) error->all(FLERR,"Illegal shell command");
if (narg < 2) error->all(FLERR,"Illegal shell mkdir command");
#if !defined(WINDOWS) && !defined(__MINGW32__)
if (me == 0)
for (int i = 1; i < narg; i++)
@ -990,19 +990,30 @@ void Input::shell()
#endif
} else if (strcmp(arg[0],"mv") == 0) {
if (narg != 3) error->all(FLERR,"Illegal shell command");
if (narg != 3) error->all(FLERR,"Illegal shell mv command");
if (me == 0) rename(arg[1],arg[2]);
} else if (strcmp(arg[0],"rm") == 0) {
if (narg < 2) error->all(FLERR,"Illegal shell command");
if (narg < 2) error->all(FLERR,"Illegal shell rm command");
if (me == 0)
for (int i = 1; i < narg; i++) unlink(arg[i]);
} else if (strcmp(arg[0],"rmdir") == 0) {
if (narg < 2) error->all(FLERR,"Illegal shell command");
if (narg < 2) error->all(FLERR,"Illegal shell rmdir command");
if (me == 0)
for (int i = 1; i < narg; i++) rmdir(arg[i]);
} else if (strcmp(arg[0],"putenv") == 0) {
if (narg < 2) error->all(FLERR,"Illegal shell putenv command");
for (int i = 1; i < narg; i++) {
char *ptr = strdup(arg[i]);
#ifdef _WIN32
if (ptr != NULL) _putenv(ptr);
#else
if (ptr != NULL) putenv(ptr);
#endif
}
// use work string to concat args back into one string separated by spaces
// invoke string in shell via system()

View File

@ -544,7 +544,8 @@ void Output::add_dump(int narg, char **arg)
error->all(FLERR,"Reuse of dump ID");
int igroup = group->find(arg[1]);
if (igroup == -1) error->all(FLERR,"Could not find dump group ID");
if (force->inumeric(FLERR,arg[3]) <= 0) error->all(FLERR,"Invalid dump frequency");
if (force->inumeric(FLERR,arg[3]) <= 0)
error->all(FLERR,"Invalid dump frequency");
// extend Dump list if necessary

View File

@ -47,7 +47,7 @@ using namespace MathConst;
#define MYROUND(a) (( a-floor(a) ) >= .5) ? ceil(a) : floor(a)
enum{INDEX,LOOP,WORLD,UNIVERSE,ULOOP,STRING,SCALARFILE,ATOMFILE,EQUAL,ATOM};
enum{INDEX,LOOP,WORLD,UNIVERSE,ULOOP,STRING,GETENV,SCALARFILE,ATOMFILE,EQUAL,ATOM};
enum{ARG,OP};
// customize by adding a function
@ -280,6 +280,27 @@ void Variable::set(int narg, char **arg)
data[nvar] = new char*[num[nvar]];
copy(1,&arg[2],data[nvar]);
// GETENV
// remove pre-existing var if also style GETENV (allows it to be reset)
// num = 1, which = 1st value
// data = 1 value, string to eval
} else if (strcmp(arg[1],"getenv") == 0) {
if (narg != 3) error->all(FLERR,"Illegal variable command");
if (find(arg[0]) >= 0) {
if (style[find(arg[0])] != GETENV)
error->all(FLERR,"Cannot redefine variable as a different style");
remove(find(arg[0]));
}
if (nvar == maxvar) grow();
style[nvar] = GETENV;
num[nvar] = 1;
which[nvar] = 0;
pad[nvar] = 0;
data[nvar] = new char*[num[nvar]];
copy(1,&arg[2],data[nvar]);
data[nvar][1] = NULL;
// SCALARFILE for strings or numbers
// which = 1st value
// data = 1 value, string to eval
@ -413,10 +434,11 @@ int Variable::next(int narg, char **arg)
error->all(FLERR,"All variables in next command must be same style");
}
// invalid styles STRING or EQUAL or WORLD or ATOM
// invalid styles STRING or EQUAL or WORLD or ATOM or GETENV
int istyle = style[find(arg[0])];
if (istyle == STRING || istyle == EQUAL || istyle == WORLD || istyle == ATOM)
if (istyle == STRING || istyle == EQUAL || istyle == WORLD
|| istyle == GETENV || istyle == ATOM)
error->all(FLERR,"Invalid variable style with next command");
// increment all variables in list
@ -505,6 +527,7 @@ int Variable::next(int narg, char **arg)
return ptr to stored string
if LOOP or ULOOP var, write int to data[0] and return ptr to string
if EQUAL var, evaluate variable and put result in str
if GETENV var, query environment and put result in str
if ATOM or ATOMFILE var, return NULL
return NULL if no variable with name or which value is bad,
caller must respond
@ -543,6 +566,14 @@ char *Variable::retrieve(char *name)
data[ivar][1] = new char[n];
strcpy(data[ivar][1],result);
str = data[ivar][1];
} else if (style[ivar] == GETENV) {
const char *result = getenv(data[ivar][0]);
if (data[ivar][1]) delete [] data[ivar][1];
if (result == NULL) result = (const char *)"";
int n = strlen(result) + 1;
data[ivar][1] = new char[n];
strcpy(data[ivar][1],result);
str = data[ivar][1];
} else if (style[ivar] == ATOM || style[ivar] == ATOMFILE) return NULL;
return str;

69
src/write_dump.cpp Normal file
View File

@ -0,0 +1,69 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
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
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Axel Kohlmeyer (Temple U)
------------------------------------------------------------------------- */
#include "write_dump.h"
#include "style_dump.h"
#include "dump.h"
#include "atom.h"
#include "group.h"
#include "error.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
void WriteDump::command(int narg, char **arg)
{
if (narg < 3) error->all(FLERR,"Illegal write_dump command");
if (atom->tag_enable == 0)
error->all(FLERR,"Must have atom IDs for write_dump command");
// modindex = index in args of "modify", narg if doesn't exist
int modindex;
for (modindex = 0; modindex < narg; modindex++)
if (strcmp(arg[modindex],"modify") == 0) break;
// create the Dump instance
Dump *dump;
if (0) return; // dummy line to enable else-if macro expansion
#define DUMP_CLASS
#define DumpStyle(key,Class) \
else if (strcmp(arg[2],#key) == 0) dump = new Class(lmp,modindex,arg);
#include "style_dump.h"
#undef DUMP_CLASS
else error->all(FLERR,"Invalid dump style");
// pass additional args to modify_params
if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]);
// write the current snapshot to dump file
dump->init();
dump->write();
// delete the Dump instance
delete dump;
}

55
src/write_dump.h Normal file
View File

@ -0,0 +1,55 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
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
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef COMMAND_CLASS
CommandStyle(write_dump,WriteDump)
#else
#ifndef LMP_WRITE_DUMP_H
#define LMP_WRITE_DUMP_H
#include "pointers.h"
namespace LAMMPS_NS {
class WriteDump : protected Pointers {
public:
WriteDump(class LAMMPS *lmp) : Pointers(lmp) {};
void command(int, char **);
};
}
#endif
#endif
/* ERROR/WARNING messages:
E: Illegal ... command
Self-explanatory. Check the input script syntax and compare to the
documentation for the command. You can use -echo screen as a
command-line option when running LAMMPS to see the offending line.
E: Must have atom IDs for group2ndx command
There are no atom IDs defined in the system, but they are required
to identify atoms in a gromacs style index file.
E: Cannot open index file for writing
Self-explanatory. Check your filename, permissions, and disk space or quota.
*/