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

This commit is contained in:
sjplimp 2007-12-13 15:19:37 +00:00
parent 4b2e7583b3
commit 24dff7064c
2 changed files with 46 additions and 10 deletions

View File

@ -29,15 +29,46 @@ using namespace LAMMPS_NS;
FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) : FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg) Fix(lmp, narg, arg)
{ {
if (narg != 5) error->all("Illegal fix print command"); if (narg < 5) error->all("Illegal fix print command");
nevery = atoi(arg[3]); nevery = atoi(arg[3]);
if (nevery <= 0) error->all("Illegal fix print command"); if (nevery <= 0) error->all("Illegal fix print command");
MPI_Comm_rank(world,&me); MPI_Comm_rank(world,&me);
int n = strlen(arg[4]) + 1; int n = strlen(arg[4]) + 1;
line = new char[n]; string = new char[n];
strcpy(line,arg[4]); strcpy(string,arg[4]);
// parse optional args
fp = NULL;
screenflag = 1;
int iarg = 5;
while (iarg < narg) {
if (strcmp(arg[iarg],"file") == 0) {
if (iarg+2 > narg) error->all("Illegal fix print command");
if (me == 0) {
fp = fopen(arg[iarg+1],"w");
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open fix print file %s",arg[iarg+1]);
error->one(str);
}
}
iarg += 2;
} else if (strcmp(arg[iarg],"screen") == 0) {
if (iarg+2 > narg) error->all("Illegal fix print command");
if (strcmp(arg[iarg+1],"yes") == 0) screenflag = 1;
else if (strcmp(arg[iarg+1],"no") == 0) screenflag = 0;
else error->all("Illegal fix print command");
iarg += 2;
} else error->all("Illegal fix print command");
}
// print header into file
if (fp && me == 0) fprintf(fp,"Fix print output for fix %s\n",id);
copy = new char[MAXLINE]; copy = new char[MAXLINE];
work = new char[MAXLINE]; work = new char[MAXLINE];
@ -47,9 +78,11 @@ FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) :
FixPrint::~FixPrint() FixPrint::~FixPrint()
{ {
delete [] line; delete [] string;
delete [] copy; delete [] copy;
delete [] work; delete [] work;
if (fp && me == 0) fclose(fp);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -65,21 +98,22 @@ int FixPrint::setmask()
void FixPrint::end_of_step() void FixPrint::end_of_step()
{ {
// make a copy of line to work on // make a copy of string to work on
// substitute for $ variables (no printing) // substitute for $ variables (no printing)
// append a newline and print final copy // append a newline and print final copy
// variable evaluation may invoke a compute that affects Verlet::eflag,vflag // variable evaluation may invoke a compute that affects Verlet::eflag,vflag
modify->clearstep_compute(); modify->clearstep_compute();
strcpy(copy,line); strcpy(copy,string);
input->substitute(copy,0); input->substitute(copy,0);
strcat(copy,"\n"); strcat(copy,"\n");
modify->addstep_compute(update->ntimestep + nevery); modify->addstep_compute(update->ntimestep + nevery);
if (me == 0) { if (me == 0) {
if (screen) fprintf(screen,copy); if (screenflag && screen) fprintf(screen,copy);
if (logfile) fprintf(logfile,copy); if (screenflag && logfile) fprintf(logfile,copy);
if (fp) fprintf(fp,copy);
} }
} }

View File

@ -14,6 +14,7 @@
#ifndef FIX_PRINT_H #ifndef FIX_PRINT_H
#define FIX_PRINT_H #define FIX_PRINT_H
#include "stdio.h"
#include "fix.h" #include "fix.h"
namespace LAMMPS_NS { namespace LAMMPS_NS {
@ -26,8 +27,9 @@ class FixPrint : public Fix {
void end_of_step(); void end_of_step();
private: private:
int me; int me,screenflag;
char *line,*copy,*work; FILE *fp;
char *string,*copy,*work;
}; };
} }